@mparticle/web-sdk 2.43.0 → 2.43.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/mparticle.common.js +36 -33
- package/dist/mparticle.esm.js +36 -33
- package/dist/mparticle.js +200 -168
- package/package.json +4 -2
- package/src/identity-user-interfaces.ts +1 -1
- package/src/identity-utils.ts +20 -1
- package/src/identity.js +15 -8
- package/src/sessionManager.ts +23 -15
- package/src/validators.ts +31 -1
package/dist/mparticle.common.js
CHANGED
|
@@ -15,7 +15,7 @@ map:function map(a,b){var c,d,e;if(null===this)throw new TypeError(" this is nul
|
|
|
15
15
|
filter:function filter(a/*, thisArg*/){if(void 0===this||null===this)throw new TypeError;var b=Object(this),c=b.length>>>0;if("function"!=typeof a)throw new TypeError;for(var d=[],e=2<=arguments.length?arguments[1]:void 0,f=0;f<c;f++)if(f in b){var g=b[f];a.call(e,g,f,b)&&d.push(g);}return d},// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray
|
|
16
16
|
isArray:function isArray(a){return "[object Array]"===Object.prototype.toString.call(a)},Base64:Base64$1};
|
|
17
17
|
|
|
18
|
-
var version = "2.43.
|
|
18
|
+
var version = "2.43.1";
|
|
19
19
|
|
|
20
20
|
var Constants={sdkVersion:version,sdkVendor:"mparticle",platform:"web",Messages:{DeprecationMessages:{MethodIsDeprecatedPostfix:"is a deprecated method and will be removed in future releases",AlternativeMethodPrefix:"Please use the alternate method:"},ErrorMessages:{NoToken:"A token must be specified.",EventNameInvalidType:"Event name must be a valid string value.",EventDataInvalidType:"Event data must be a valid object hash.",LoggingDisabled:"Event logging is currently disabled.",CookieParseError:"Could not parse cookie",EventEmpty:"Event object is null or undefined, cancelling send",APIRequestEmpty:"APIRequest is null or undefined, cancelling send",NoEventType:"Event type must be specified.",TransactionIdRequired:"Transaction ID is required",TransactionRequired:"A transaction attributes object is required",PromotionIdRequired:"Promotion ID is required",BadAttribute:"Attribute value cannot be object or array",BadKey:"Key value cannot be object or array",BadLogPurchase:"Transaction attributes and a product are both required to log a purchase, https://docs.mparticle.com/?javascript#measuring-transactions",AudienceAPINotEnabled:"Your workspace is not enabled to retrieve user audiences."},InformationMessages:{CookieSearch:"Searching for cookie",CookieFound:"Cookie found, parsing values",CookieNotFound:"Cookies not found",CookieSet:"Setting cookie",CookieSync:"Performing cookie sync",SendBegin:"Starting to send event",SendIdentityBegin:"Starting to send event to identity server",SendWindowsPhone:"Sending event to Windows Phone container",SendIOS:"Calling iOS path: ",SendAndroid:"Calling Android JS interface method: ",SendHttp:"Sending event to mParticle HTTP service",SendAliasHttp:"Sending alias request to mParticle HTTP service",SendIdentityHttp:"Sending event to mParticle HTTP service",StartingNewSession:"Starting new Session",StartingLogEvent:"Starting to log event",StartingLogOptOut:"Starting to log user opt in/out",StartingEndSession:"Starting to end session",StartingInitialization:"Starting to initialize",StartingLogCommerceEvent:"Starting to log commerce event",StartingAliasRequest:"Starting to Alias MPIDs",LoadingConfig:"Loading configuration options",AbandonLogEvent:"Cannot log event, logging disabled or developer token not set",AbandonAliasUsers:"Cannot Alias Users, logging disabled or developer token not set",AbandonStartSession:"Cannot start session, logging disabled or developer token not set",AbandonEndSession:"Cannot end session, logging disabled or developer token not set",NoSessionToEnd:"Cannot end session, no active session found"},ValidationMessages:{ModifyIdentityRequestUserIdentitiesPresent:"identityRequests to modify require userIdentities to be present. Request not sent to server. Please fix and try again",IdentityRequesetInvalidKey:"There is an invalid key on your identityRequest object. It can only contain a `userIdentities` object and a `onUserAlias` function. Request not sent to server. Please fix and try again.",OnUserAliasType:"The onUserAlias value must be a function.",UserIdentities:"The userIdentities key must be an object with keys of identityTypes and values of strings. Request not sent to server. Please fix and try again.",UserIdentitiesInvalidKey:"There is an invalid identity key on your `userIdentities` object within the identityRequest. Request not sent to server. Please fix and try again.",UserIdentitiesInvalidValues:"All user identity values must be strings or null. Request not sent to server. Please fix and try again.",AliasMissingMpid:"Alias Request must contain both a destinationMpid and a sourceMpid",AliasNonUniqueMpid:"Alias Request's destinationMpid and sourceMpid must be unique",AliasMissingTime:"Alias Request must have both a startTime and an endTime",AliasStartBeforeEndTime:"Alias Request's endTime must be later than its startTime"}},NativeSdkPaths:{LogEvent:"logEvent",SetUserTag:"setUserTag",RemoveUserTag:"removeUserTag",SetUserAttribute:"setUserAttribute",RemoveUserAttribute:"removeUserAttribute",SetSessionAttribute:"setSessionAttribute",AddToCart:"addToCart",RemoveFromCart:"removeFromCart",ClearCart:"clearCart",LogOut:"logOut",SetUserAttributeList:"setUserAttributeList",RemoveAllUserAttributes:"removeAllUserAttributes",GetUserAttributesLists:"getUserAttributesLists",GetAllUserAttributes:"getAllUserAttributes",Identify:"identify",Logout:"logout",Login:"login",Modify:"modify",Alias:"aliasUsers",Upload:"upload"},StorageNames:{localStorageName:"mprtcl-api",localStorageNameV3:"mprtcl-v3",cookieName:"mprtcl-api",cookieNameV2:"mprtcl-v2",cookieNameV3:"mprtcl-v3",localStorageNameV4:"mprtcl-v4",localStorageProductsV4:"mprtcl-prodv4",cookieNameV4:"mprtcl-v4",currentStorageName:"mprtcl-v4",currentStorageProductsName:"mprtcl-prodv4"},DefaultConfig:{cookieDomain:null,cookieExpiration:365,logLevel:null,timeout:300,sessionTimeout:30,maxProducts:20,forwarderStatsTimeout:5e3,integrationDelayTimeout:5e3,maxCookieSize:3e3,aliasMaxWindow:90,uploadInterval:0// Maximum milliseconds in between batch uploads, below 500 will mean immediate upload. The server returns this as a string, but we are using it as a number internally
|
|
21
21
|
},DefaultBaseUrls:{v1SecureServiceUrl:"jssdks.mparticle.com/v1/JS/",v2SecureServiceUrl:"jssdks.mparticle.com/v2/JS/",v3SecureServiceUrl:"jssdks.mparticle.com/v3/JS/",configUrl:"jssdkcdns.mparticle.com/JS/v2/",identityUrl:"identity.mparticle.com/v1/",aliasUrl:"jssdks.mparticle.com/v1/identity/",userAudienceUrl:"nativesdks.mparticle.com/v1/"},// These are the paths that are used to construct the CNAME urls
|
|
@@ -464,7 +464,8 @@ var Modify$4=Constants.IdentityMethods.Modify,Validators={// From ./utils
|
|
|
464
464
|
isNumber:isNumber,isFunction:isFunction,isStringOrNumber:isStringOrNumber,// Validator Functions
|
|
465
465
|
isValidAttributeValue:function isValidAttributeValue(a){return a!==void 0&&!isObject(a)&&!Array.isArray(a)},// Validator Functions
|
|
466
466
|
// Neither null nor undefined can be a valid Key
|
|
467
|
-
isValidKeyValue:function isValidKeyValue(a){return !(!a||isObject(a)||Array.isArray(a)||this.isFunction(a))},
|
|
467
|
+
isValidKeyValue:function isValidKeyValue(a){return !(!a||isObject(a)||Array.isArray(a)||this.isFunction(a))},removeFalsyIdentityValues:function removeFalsyIdentityValues(a,b){if(!a||!a.userIdentities)return a;var c={},d=__assign({},a.userIdentities);for(var e in a.userIdentities)if(a.userIdentities.hasOwnProperty(e)){var f=a.userIdentities[e];// Check if value is falsy (undefined, false, 0, '', etc.) but not null
|
|
468
|
+
null===f||f||(b.warning("Identity value for '".concat(e,"' is falsy (").concat(f,"). This value will be removed from the request.")),delete d[e]);}return c.userIdentities=d,c},validateIdentities:function validateIdentities(a,b){var c={userIdentities:1,onUserAlias:1,copyUserAttributes:1};if(a){if(b===Modify$4&&(isObject(a.userIdentities)&&!Object.keys(a.userIdentities).length||!isObject(a.userIdentities)))return {valid:!1,error:Constants.Messages.ValidationMessages.ModifyIdentityRequestUserIdentitiesPresent};for(var d in a)if(a.hasOwnProperty(d)){if(!c[d])return {valid:!1,error:Constants.Messages.ValidationMessages.IdentityRequesetInvalidKey};if("onUserAlias"===d&&!Validators.isFunction(a[d]))return {valid:!1,error:Constants.Messages.ValidationMessages.OnUserAliasType}}if(0===Object.keys(a).length)return {valid:!0};// identityApiData.userIdentities can't be undefined
|
|
468
469
|
if(void 0===a.userIdentities)return {valid:!1,error:Constants.Messages.ValidationMessages.UserIdentities};// identityApiData.userIdentities can be null, but if it isn't null or undefined (above conditional), it must be an object
|
|
469
470
|
if(null!==a.userIdentities&&!isObject(a.userIdentities))return {valid:!1,error:Constants.Messages.ValidationMessages.UserIdentities};if(isObject(a.userIdentities)&&Object.keys(a.userIdentities).length)for(var e in a.userIdentities)if(a.userIdentities.hasOwnProperty(e)){if(!1===Types.IdentityType.getIdentityType(e))return {valid:!1,error:Constants.Messages.ValidationMessages.UserIdentitiesInvalidKey};if("string"!=typeof a.userIdentities[e]&&null!==a.userIdentities[e])return {valid:!1,error:Constants.Messages.ValidationMessages.UserIdentitiesInvalidValues}}}return {valid:!0}}};
|
|
470
471
|
|
|
@@ -509,8 +510,32 @@ if(!isEmpty(k)&&(isEmpty(o)||(i=!0),!(i&&d)))// If MPID is new to cookies, we sh
|
|
|
509
510
|
return !b||new Date().getTime()>new Date(b).getTime()+a*DAYS_IN_MILLISECONDS;// Otherwise, compare the last sync date to determine if it should do a cookie sync again
|
|
510
511
|
};
|
|
511
512
|
|
|
513
|
+
var _a=Constants.IdentityMethods,Identify$2=_a.Identify,Modify$3=_a.Modify,Login$2=_a.Login,Logout$2=_a.Logout;var CACHE_HEADER="x-mp-max-age";var cacheOrClearIdCache=function(a,b,c,d,e){// when parsing a response that has already been cached, simply return instead of attempting another cache
|
|
514
|
+
if(!e){// default the expire timestamp to one day in milliseconds unless a header comes back
|
|
515
|
+
var f=getExpireTimestamp(null===d||void 0===d?void 0:d.cacheMaxAge);a===Login$2||a===Identify$2?cacheIdentityRequest(a,b,f,c,d):a===Modify$3||a===Logout$2?c.purge():void 0;}};var cacheIdentityRequest=function(a,b,c,d,e){var f=e.responseText,g=e.status,h=d.retrieve()||{},i=concatenateIdentities(a,b),j=generateHash(i),k=f.mpid,l=f.is_logged_in;h[j]={responseText:JSON.stringify({mpid:k,is_logged_in:l}),status:g,expireTimestamp:c},d.store(h);};// We need to ensure that identities are concatenated in a deterministic way, so
|
|
516
|
+
// we sort the identities based on their enum.
|
|
517
|
+
// we create an array, set the user identity at the index of the user identity type
|
|
518
|
+
var concatenateIdentities=function(a,b){var c="".concat(a,":").concat("device_application_stamp","=").concat(b.device_application_stamp,";"),d=Object.keys(b).length,e="";// set DAS first since it is not an official identity type
|
|
519
|
+
if(d){var f=[];// create an array where each index is equal to the user identity type
|
|
520
|
+
for(var g in b)if(g==="device_application_stamp")continue;else f[Types.IdentityType.getIdentityType(g)]=b[g];e=f.reduce(function(a,b,c){var d=Types.IdentityType.getIdentityName(c);return "".concat(a).concat(d,"=").concat(b,";")},c);}return e};var hasValidCachedIdentity=function(a,b,c){// There is an edge case where multiple identity calls are taking place
|
|
521
|
+
// before identify fires, so there may not be a cache. See what happens when
|
|
522
|
+
// the ? in idCache is removed to the following test
|
|
523
|
+
// "queued events contain login mpid instead of identify mpid when calling
|
|
524
|
+
// login immediately after mParticle initializes"
|
|
525
|
+
var d=null===c||void 0===c?void 0:c.retrieve();// if there is no cache, then there is no valid cached identity
|
|
526
|
+
if(!d)return !1;var e=concatenateIdentities(a,b),f=generateHash(e);// if cache doesn't have the cacheKey, there is no valid cached identity
|
|
527
|
+
if(!d.hasOwnProperty(f))return !1;// If there is a valid cache key, compare the expireTimestamp to the current time.
|
|
528
|
+
// If the current time is greater than the expireTimestamp, it is not a valid
|
|
529
|
+
// cached identity.
|
|
530
|
+
var g=d[f].expireTimestamp;return !(g<new Date().getTime())};var getCachedIdentity=function(a,b,c){var d=concatenateIdentities(a,b),e=generateHash(d),f=c.retrieve(),g=f?f[e]:null;return {responseText:parseIdentityResponse(g.responseText),expireTimestamp:g.expireTimestamp,status:g.status}};// https://go.mparticle.com/work/SQDSDKS-6079
|
|
531
|
+
var createKnownIdentities=function(a,b){var c={};if(isObject(null===a||void 0===a?void 0:a.userIdentities))for(var d in a.userIdentities)c[d]=a.userIdentities[d];return c.device_application_stamp=b,c};var removeExpiredIdentityCacheDates=function(a){var b=a.retrieve()||{},c=new Date().getTime();// Iterate over the cache and remove any key/value pairs that are expired
|
|
532
|
+
for(var d in b)b[d].expireTimestamp<c&&delete b[d];a.store(b);};var tryCacheIdentity=function(a,b,c,d,e,f,g){// https://go.mparticle.com/work/SQDSDKS-6095
|
|
533
|
+
var h=hasValidCachedIdentity(g,a,b);// If Identity is cached, then immediately parse the identity response
|
|
534
|
+
if(h){var i=getCachedIdentity(g,a,b);return c(i,d,e,f,g,a,!0),!0}return !1};var getExpireTimestamp=function(a){return void 0===a&&(a=ONE_DAY_IN_SECONDS),new Date().getTime()+a*MILLIS_IN_ONE_SEC},parseIdentityResponse=function(a){return a?JSON.parse(a):{}};var hasIdentityRequestChanged=function(a,b){if(!a||!(null!==b&&void 0!==b)||!b.userIdentities)return !1;var c=a.getUserIdentities().userIdentities,d=b.userIdentities;return JSON.stringify(c)!==JSON.stringify(d)};
|
|
535
|
+
|
|
512
536
|
var Messages$6=Constants.Messages;function SessionManager(a){var b=this;this.initialize=function(){if(a._Store.sessionId){var c=6e4*a._Store.SDKConfig.sessionTimeout;if(new Date>new Date(a._Store.dateLastEventSent.getTime()+c))b.endSession(),b.startNewSession();else {// https://go.mparticle.com/work/SQDSDKS-6045
|
|
513
|
-
|
|
537
|
+
// https://go.mparticle.com/work/SQDSDKS-6323
|
|
538
|
+
var d=a.Identity.getCurrentUser(),e=a._Store.SDKConfig.identifyRequest;hasIdentityRequestChanged(d,e)&&(a.Identity.identify(a._Store.SDKConfig.identifyRequest,a._Store.SDKConfig.identityCallback),a._Store.identifyCalled=!0,a._Store.SDKConfig.identityCallback=null);}}else b.startNewSession();},this.getSession=function(){return a.Logger.warning(generateDeprecationMessage("SessionManager.getSession()","SessionManager.getSessionId()")),this.getSessionId()},this.getSessionId=function(){return a._Store.sessionId},this.startNewSession=function(){if(a.Logger.verbose(Messages$6.InformationMessages.StartingNewSession),a._Helpers.canLog()){a._Store.sessionId=a._Helpers.generateUniqueId().toUpperCase();var c=a.Identity.getCurrentUser(),d=c?c.getMPID():null;if(d&&(a._Store.currentSessionMPIDs=[d]),!a._Store.sessionStartDate){var e=new Date;a._Store.sessionStartDate=e,a._Store.dateLastEventSent=e;}b.setSessionTimer(),a._Store.identifyCalled||(a.Identity.identify(a._Store.SDKConfig.identifyRequest,a._Store.SDKConfig.identityCallback),a._Store.identifyCalled=!0,a._Store.SDKConfig.identityCallback=null),a._Events.logEvent({messageType:Types.MessageType.SessionStart});}else a.Logger.verbose(Messages$6.InformationMessages.AbandonStartSession);},this.endSession=function(c){var d,e,f,g,h;if(a.Logger.verbose(Messages$6.InformationMessages.StartingEndSession),c)return a._Events.logEvent({messageType:Types.MessageType.SessionEnd}),a._Store.nullifySession(),void(null===(d=a._timeOnSiteTimer)||void 0===d?void 0:d.resetTimer());if(!a._Helpers.canLog())return a.Logger.verbose(Messages$6.InformationMessages.AbandonEndSession),void(null===(e=a._timeOnSiteTimer)||void 0===e?void 0:e.resetTimer());var i,j,k=a._Persistence.getPersistence();if(!k||k.gs&&!k.gs.sid)return a.Logger.verbose(Messages$6.InformationMessages.NoSessionToEnd),void(null===(f=a._timeOnSiteTimer)||void 0===f?void 0:f.resetTimer());// sessionId is not equal to cookies.sid if cookies.sid is changed in another tab
|
|
514
539
|
if(k.gs.sid&&a._Store.sessionId!==k.gs.sid&&(a._Store.sessionId=k.gs.sid),null===(g=null===k||void 0===k?void 0:k.gs)||void 0===g?void 0:g.les){i=6e4*a._Store.SDKConfig.sessionTimeout;var l=new Date().getTime();j=l-k.gs.les,j<i?b.setSessionTimer():(a._Events.logEvent({messageType:Types.MessageType.SessionEnd}),a._Store.sessionStartDate=null,a._Store.nullifySession());}null===(h=a._timeOnSiteTimer)||void 0===h?void 0:h.resetTimer();},this.setSessionTimer=function(){var c=6e4*a._Store.SDKConfig.sessionTimeout;a._Store.globalTimer=window.setTimeout(function(){b.endSession();},c);},this.resetSessionTimer=function(){a._Store.webviewBridgeEnabled||(!a._Store.sessionId&&b.startNewSession(),b.clearSessionTimeout(),b.setSessionTimer()),b.startNewSessionIfNeeded();},this.clearSessionTimeout=function(){clearTimeout(a._Store.globalTimer);},this.startNewSessionIfNeeded=function(){if(!a._Store.webviewBridgeEnabled){var c=a._Persistence.getPersistence();!a._Store.sessionId&&c&&(c.sid?a._Store.sessionId=c.sid:b.startNewSession());}};}
|
|
515
540
|
|
|
516
541
|
var Messages$5=Constants.Messages;function Ecommerce(a){var b=this;// https://go.mparticle.com/work/SQDSDKS-4801
|
|
@@ -1006,7 +1031,7 @@ var _regeneratorRuntime = /*@__PURE__*/getDefaultExportFromCjs(regenerator);
|
|
|
1006
1031
|
function filteredMparticleUser(a,b,c,d){var e=this;return {getUserIdentities:function getUserIdentities(){var e={},f=c._Store.getUserIdentities(a);for(var g in f)if(f.hasOwnProperty(g)){var h=Types.IdentityType.getIdentityName(c._Helpers.parseNumber(g));d&&(!d||d.isIdentityBlocked(h))||(//if identity type is not blocked
|
|
1007
1032
|
e[h]=f[g]);}return e=c._Helpers.filterUserIdentitiesForForwarders(e,b.userIdentityFilters),{userIdentities:e}},getMPID:function getMPID(){return a},getUserAttributesLists:function getUserAttributesLists(a){var b,f={};for(var g in b=e.getAllUserAttributes(),b)b.hasOwnProperty(g)&&Array.isArray(b[g])&&(d&&(!d||d.isAttributeKeyBlocked(g))||(f[g]=b[g].slice()));return f=c._Helpers.filterUserAttributes(f,a.userAttributeFilters),f},getAllUserAttributes:function getAllUserAttributes(){var e={},f=c._Store.getUserAttributes(a);if(f)for(var g in f)f.hasOwnProperty(g)&&(d&&(!d||d.isAttributeKeyBlocked(g))||(Array.isArray(f[g])?e[g]=f[g].slice():e[g]=f[g]));return e=c._Helpers.filterUserAttributes(e,b.userAttributeFilters),e}}}
|
|
1008
1033
|
|
|
1009
|
-
var _Constants$IdentityMe=Constants.IdentityMethods,Modify$
|
|
1034
|
+
var _Constants$IdentityMe=Constants.IdentityMethods,Modify$2=_Constants$IdentityMe.Modify,Identify$1=_Constants$IdentityMe.Identify,Login$1=_Constants$IdentityMe.Login,Logout$1=_Constants$IdentityMe.Logout;function Forwarders(a,b){var c=this,d=this;this.forwarderStatsUploader=new APIClient(a,b).initializeForwarderStatsUploader();var e={setUserAttribute:"setUserAttribute",removeUserAttribute:"removeUserAttribute"};// TODO: https://go.mparticle.com/work/SQDSDKS-6036
|
|
1010
1035
|
// Processing forwarders is a 2 step process:
|
|
1011
1036
|
// 1. Configure the kit
|
|
1012
1037
|
// 2. Initialize the kit
|
|
@@ -1036,7 +1061,7 @@ if(-1<j.indexOf(b.EventDataType)&&a._Store.activeForwarders[k].filteringEventAtt
|
|
|
1036
1061
|
if(b.EventAttributes)for(var m in b.EventAttributes){var n;if(n=KitFilterHelper.hashAttributeConditionalForwarding(m),n===a._Store.activeForwarders[k].filteringEventAttributeValue.eventAttributeName&&(l={name:n,value:KitFilterHelper.hashAttributeConditionalForwarding(b.EventAttributes[m])}),l)break}var o=null!==l&&l.value===a._Store.activeForwarders[k].filteringEventAttributeValue.eventAttributeValue,p=!0===a._Store.activeForwarders[k].filteringEventAttributeValue.includeOnMatch?o:!o;if(!p)continue}// Clone the event object, as we could be sending different attributes to each forwarder
|
|
1037
1062
|
// Check event filtering rules
|
|
1038
1063
|
if(c={},c=a._Helpers.extend(!0,c,b),b.EventDataType===Types.MessageType.PageEvent&&(h(a._Store.activeForwarders[k].eventNameFilters,d)||h(a._Store.activeForwarders[k].eventTypeFilters,e)))continue;else if(b.EventDataType===Types.MessageType.Commerce&&h(a._Store.activeForwarders[k].eventTypeFilters,e))continue;else if(b.EventDataType===Types.MessageType.PageView&&h(a._Store.activeForwarders[k].screenNameFilters,d))continue;// Check attribute filtering rules
|
|
1039
|
-
if(c.EventAttributes&&(b.EventDataType===Types.MessageType.PageEvent?g(c,a._Store.activeForwarders[k].attributeFilters):b.EventDataType===Types.MessageType.PageView&&g(c,a._Store.activeForwarders[k].screenAttributeFilters)),f(c,a._Store.activeForwarders[k].userIdentityFilters),c.UserAttributes=a._Helpers.filterUserAttributes(c.UserAttributes,a._Store.activeForwarders[k].userAttributeFilters),a._Store.activeForwarders[k].process){a.Logger.verbose("Sending message to forwarder: "+a._Store.activeForwarders[k].name);var q=a._Store.activeForwarders[k].process(c);q&&a.Logger.verbose(q);}}}},this.handleForwarderUserAttributes=function(c,d,f){b&&b.isAttributeKeyBlocked(d)||!a._Store.activeForwarders.length||a._Store.activeForwarders.forEach(function(b){var g=b[c];if(g&&!KitFilterHelper.isFilteredUserAttribute(d,b.userAttributeFilters))try{var h;c===e.setUserAttribute?h=b.setUserAttribute(d,f):c===e.removeUserAttribute&&(h=b.removeUserAttribute(d)),h&&a.Logger.verbose(h);}catch(b){a.Logger.error(b);}});},this.setForwarderUserIdentities=function(b){a._Store.activeForwarders.forEach(function(c){var d=a._Helpers.filterUserIdentities(b,c.userIdentityFilters);c.setUserIdentity&&d.forEach(function(b){var d=c.setUserIdentity(b.Identity,b.Type);d&&a.Logger.verbose(d);});});},this.setForwarderOnUserIdentified=function(c){a._Store.activeForwarders.forEach(function(d){var e=filteredMparticleUser(c.getMPID(),d,a,b);if(d.onUserIdentified){var f=d.onUserIdentified(e);f&&a.Logger.verbose(f);}});},this.setForwarderOnIdentityComplete=function(c,d){var e;a._Store.activeForwarders.forEach(function(f){var g=filteredMparticleUser(c.getMPID(),f,a,b),h=g.getUserIdentities();d===Identify$
|
|
1064
|
+
if(c.EventAttributes&&(b.EventDataType===Types.MessageType.PageEvent?g(c,a._Store.activeForwarders[k].attributeFilters):b.EventDataType===Types.MessageType.PageView&&g(c,a._Store.activeForwarders[k].screenAttributeFilters)),f(c,a._Store.activeForwarders[k].userIdentityFilters),c.UserAttributes=a._Helpers.filterUserAttributes(c.UserAttributes,a._Store.activeForwarders[k].userAttributeFilters),a._Store.activeForwarders[k].process){a.Logger.verbose("Sending message to forwarder: "+a._Store.activeForwarders[k].name);var q=a._Store.activeForwarders[k].process(c);q&&a.Logger.verbose(q);}}}},this.handleForwarderUserAttributes=function(c,d,f){b&&b.isAttributeKeyBlocked(d)||!a._Store.activeForwarders.length||a._Store.activeForwarders.forEach(function(b){var g=b[c];if(g&&!KitFilterHelper.isFilteredUserAttribute(d,b.userAttributeFilters))try{var h;c===e.setUserAttribute?h=b.setUserAttribute(d,f):c===e.removeUserAttribute&&(h=b.removeUserAttribute(d)),h&&a.Logger.verbose(h);}catch(b){a.Logger.error(b);}});},this.setForwarderUserIdentities=function(b){a._Store.activeForwarders.forEach(function(c){var d=a._Helpers.filterUserIdentities(b,c.userIdentityFilters);c.setUserIdentity&&d.forEach(function(b){var d=c.setUserIdentity(b.Identity,b.Type);d&&a.Logger.verbose(d);});});},this.setForwarderOnUserIdentified=function(c){a._Store.activeForwarders.forEach(function(d){var e=filteredMparticleUser(c.getMPID(),d,a,b);if(d.onUserIdentified){var f=d.onUserIdentified(e);f&&a.Logger.verbose(f);}});},this.setForwarderOnIdentityComplete=function(c,d){var e;a._Store.activeForwarders.forEach(function(f){var g=filteredMparticleUser(c.getMPID(),f,a,b),h=g.getUserIdentities();d===Identify$1?f.onIdentifyComplete&&(e=f.onIdentifyComplete(g,h),e&&a.Logger.verbose(e)):d===Login$1?f.onLoginComplete&&(e=f.onLoginComplete(g,h),e&&a.Logger.verbose(e)):d===Logout$1?f.onLogoutComplete&&(e=f.onLogoutComplete(g,h),e&&a.Logger.verbose(e)):d===Modify$2&&f.onModifyComplete&&(e=f.onModifyComplete(g,h),e&&a.Logger.verbose(e));});},this.getForwarderStatsQueue=function(){return a._Persistence.forwardingStatsBatches.forwardingStatsEventQueue},this.setForwarderStatsQueue=function(b){a._Persistence.forwardingStatsBatches.forwardingStatsEventQueue=b;},this.processForwarders=function(b,c){b?(this.processUIEnabledKits(b),this.processSideloadedKits(b),d.initForwarders(a._Store.SDKConfig.identifyRequest.userIdentities,c)):a.Logger.warning("No config was passed. Cannot process forwarders");},this.processUIEnabledKits=function(b){var c=this.returnKitConstructors();try{Array.isArray(b.kitConfigs)&&b.kitConfigs.length&&b.kitConfigs.forEach(function(a){d.configureUIEnabledKit(a,c);});}catch(b){a.Logger.error("MP Kits not configured propertly. Kits may not be initialized. "+b);}},this.returnKitConstructors=function(){var b={};// If there are kits inside of mpInstance._Store.SDKConfig.kits, then mParticle is self hosted
|
|
1040
1065
|
return isEmpty(a._Store.SDKConfig.kits)?!isEmpty(a._preInit.forwarderConstructors)&&a._preInit.forwarderConstructors.forEach(function(a){// A suffix is added to a kitConstructor and kit config if there are multiple different
|
|
1041
1066
|
// versions of a client kit. This matches the suffix in the DB. As an example
|
|
1042
1067
|
// the GA4 kit has a client kit and a server side kit which has a client side
|
|
@@ -1068,29 +1093,6 @@ Store:a._Store.serverSettings,SDKVersion:Constants.sdkVersion,SessionId:a._Store
|
|
|
1068
1093
|
|
|
1069
1094
|
function forwardingStatsUploader(a){function b(){var b=a._Forwarders.getForwarderStatsQueue(),c=a._Persistence.forwardingStatsBatches.uploadsTable,d=Date.now();for(var e in b.length&&(c[d]={uploading:!1,data:b},a._Forwarders.setForwarderStatsQueue([])),c)(function(b){if(c.hasOwnProperty(b)&&!1===c[b].uploading){var d=function(){4===e.readyState&&(200===e.status||202===e.status?(a.Logger.verbose("Successfully sent "+e.statusText+" from server"),delete c[b]):"4"===e.status.toString()[0]?429!==e.status&&delete c[b]:c[b].uploading=!1);},e=a._Helpers.createXHR(d),f=c[b].data;c[b].uploading=!0,a._APIClient.sendBatchForwardingStatsToServer(f,e);}})(e);}this.startForwardingStatsTimer=function(){mParticle._forwardingStatsTimer=setInterval(function(){b();},a._Store.SDKConfig.forwarderStatsTimeout);};}
|
|
1070
1095
|
|
|
1071
|
-
var _a=Constants.IdentityMethods,Identify$1=_a.Identify,Modify$2=_a.Modify,Login$1=_a.Login,Logout$1=_a.Logout;var CACHE_HEADER="x-mp-max-age";var cacheOrClearIdCache=function(a,b,c,d,e){// when parsing a response that has already been cached, simply return instead of attempting another cache
|
|
1072
|
-
if(!e){// default the expire timestamp to one day in milliseconds unless a header comes back
|
|
1073
|
-
var f=getExpireTimestamp(null===d||void 0===d?void 0:d.cacheMaxAge);a===Login$1||a===Identify$1?cacheIdentityRequest(a,b,f,c,d):a===Modify$2||a===Logout$1?c.purge():void 0;}};var cacheIdentityRequest=function(a,b,c,d,e){var f=e.responseText,g=e.status,h=d.retrieve()||{},i=concatenateIdentities(a,b),j=generateHash(i),k=f.mpid,l=f.is_logged_in;h[j]={responseText:JSON.stringify({mpid:k,is_logged_in:l}),status:g,expireTimestamp:c},d.store(h);};// We need to ensure that identities are concatenated in a deterministic way, so
|
|
1074
|
-
// we sort the identities based on their enum.
|
|
1075
|
-
// we create an array, set the user identity at the index of the user identity type
|
|
1076
|
-
var concatenateIdentities=function(a,b){var c="".concat(a,":").concat("device_application_stamp","=").concat(b.device_application_stamp,";"),d=Object.keys(b).length,e="";// set DAS first since it is not an official identity type
|
|
1077
|
-
if(d){var f=[];// create an array where each index is equal to the user identity type
|
|
1078
|
-
for(var g in b)if(g==="device_application_stamp")continue;else f[Types.IdentityType.getIdentityType(g)]=b[g];e=f.reduce(function(a,b,c){var d=Types.IdentityType.getIdentityName(c);return "".concat(a).concat(d,"=").concat(b,";")},c);}return e};var hasValidCachedIdentity=function(a,b,c){// There is an edge case where multiple identity calls are taking place
|
|
1079
|
-
// before identify fires, so there may not be a cache. See what happens when
|
|
1080
|
-
// the ? in idCache is removed to the following test
|
|
1081
|
-
// "queued events contain login mpid instead of identify mpid when calling
|
|
1082
|
-
// login immediately after mParticle initializes"
|
|
1083
|
-
var d=null===c||void 0===c?void 0:c.retrieve();// if there is no cache, then there is no valid cached identity
|
|
1084
|
-
if(!d)return !1;var e=concatenateIdentities(a,b),f=generateHash(e);// if cache doesn't have the cacheKey, there is no valid cached identity
|
|
1085
|
-
if(!d.hasOwnProperty(f))return !1;// If there is a valid cache key, compare the expireTimestamp to the current time.
|
|
1086
|
-
// If the current time is greater than the expireTimestamp, it is not a valid
|
|
1087
|
-
// cached identity.
|
|
1088
|
-
var g=d[f].expireTimestamp;return !(g<new Date().getTime())};var getCachedIdentity=function(a,b,c){var d=concatenateIdentities(a,b),e=generateHash(d),f=c.retrieve(),g=f?f[e]:null;return {responseText:parseIdentityResponse(g.responseText),expireTimestamp:g.expireTimestamp,status:g.status}};// https://go.mparticle.com/work/SQDSDKS-6079
|
|
1089
|
-
var createKnownIdentities=function(a,b){var c={};if(isObject(null===a||void 0===a?void 0:a.userIdentities))for(var d in a.userIdentities)c[d]=a.userIdentities[d];return c.device_application_stamp=b,c};var removeExpiredIdentityCacheDates=function(a){var b=a.retrieve()||{},c=new Date().getTime();// Iterate over the cache and remove any key/value pairs that are expired
|
|
1090
|
-
for(var d in b)b[d].expireTimestamp<c&&delete b[d];a.store(b);};var tryCacheIdentity=function(a,b,c,d,e,f,g){// https://go.mparticle.com/work/SQDSDKS-6095
|
|
1091
|
-
var h=hasValidCachedIdentity(g,a,b);// If Identity is cached, then immediately parse the identity response
|
|
1092
|
-
if(h){var i=getCachedIdentity(g,a,b);return c(i,d,e,f,g,a,!0),!0}return !1};var getExpireTimestamp=function(a){return void 0===a&&(a=ONE_DAY_IN_SECONDS),new Date().getTime()+a*MILLIS_IN_ONE_SEC},parseIdentityResponse=function(a){return a?JSON.parse(a):{}};
|
|
1093
|
-
|
|
1094
1096
|
var AudienceManager=/** @class */function(){function a(a,b,c){this.url="",this.logger=c,this.url="https://".concat(a).concat(b,"/audience"),this.userAudienceAPI=window.fetch?new FetchUploader(this.url):new XHRUploader(this.url);}return a.prototype.sendGetUserAudienceRequest=function(a,b){return __awaiter(this,void 0,void 0,function(){var c,d,e,f,g,h;return __generator(this,function(i){switch(i.label){case 0:this.logger.verbose("Fetching user audiences from server"),c={method:"GET",headers:{Accept:"*/*"}},d="".concat(this.url,"?mpid=").concat(a),i.label=1;case 1:return i.trys.push([1,6,,7]),[4/*yield*/,this.userAudienceAPI.upload(c,d)];case 2:return (e=i.sent(),!(200<=e.status&&300>e.status))?[3/*break*/,4]:(this.logger.verbose("User Audiences successfully received"),[4/*yield*/,e.json()]);case 3:f=i.sent(),g={currentAudienceMemberships:null===f||void 0===f?void 0:f.audience_memberships};try{b(g);}catch(a){throw new Error("Error invoking callback on user audience response.")}return [3/*break*/,5];case 4:if(401===e.status)throw new Error("`HTTP error status ${userAudiencePromise.status} while retrieving User Audiences - please verify your API key.`");else if(403===e.status)throw new Error("`HTTP error status ${userAudiencePromise.status} while retrieving User Audiences - please verify your workspace is enabled for audiences.`");else// In case there is an HTTP error we did not anticipate.
|
|
1095
1097
|
throw new Error("Uncaught HTTP Error ".concat(e.status,"."));case 5:return [3/*break*/,7];case 6:return h=i.sent(),this.logger.error("Error retrieving audiences. ".concat(h)),[3/*break*/,7];case 7:return [2/*return*/]}})})},a}();
|
|
1096
1098
|
|
|
@@ -1119,7 +1121,8 @@ var Messages$2=Constants.Messages,HTTPCodes$2=Constants.HTTPCodes,FeatureFlags$1
|
|
|
1119
1121
|
// send a user identity change request on identify, login, logout, modify when any values change.
|
|
1120
1122
|
// compare what identities exist vs what is previously was for the specific user if they were in memory before.
|
|
1121
1123
|
// if it's the first time the user is logging in, send a user identity change request with
|
|
1122
|
-
this.idCache=null,this.audienceManager=null,this.IdentityRequest={preProcessIdentityRequest:function preProcessIdentityRequest(e,r,s){t.Logger.verbose(Messages$2.InformationMessages.StartingLogEvent+": "+s)
|
|
1124
|
+
this.idCache=null,this.audienceManager=null,this.IdentityRequest={preProcessIdentityRequest:function preProcessIdentityRequest(e,r,s){t.Logger.verbose(Messages$2.InformationMessages.StartingLogEvent+": "+s);// First, remove any falsy identity values and warn about them
|
|
1125
|
+
var i=t._Helpers.Validators.removeFalsyIdentityValues(e,t.Logger),n=t._Helpers.Validators.validateIdentities(i,s);if(!n.valid)return t.Logger.error("ERROR: "+n.error),{valid:!1,error:n.error};if(r&&!t._Helpers.Validators.isFunction(r)){var a="The optional callback must be a function. You tried entering a(n) "+_typeof$1(r);return t.Logger.error(a),{valid:!1,error:a}}return {valid:!0,cleanedIdentities:i}},createIdentityRequest:function createIdentityRequest(e,r,s,i,n,a,d){var o={client_sdk:{platform:r,sdk_vendor:s,sdk_version:i},context:a,environment:t._Store.SDKConfig.isDevelopmentMode?"development":"production",request_id:t._Helpers.generateUniqueId(),request_timestamp_ms:new Date().getTime(),previous_mpid:d||null,known_identities:createKnownIdentities(e,n)};return o},createModifyIdentityRequest:function createModifyIdentityRequest(e,r,s,i,n,a){return {client_sdk:{platform:s,sdk_vendor:i,sdk_version:n},context:a,environment:t._Store.SDKConfig.isDevelopmentMode?"development":"production",request_id:t._Helpers.generateUniqueId(),request_timestamp_ms:new Date().getTime(),identity_changes:this.createIdentityChanges(e,r)}},createIdentityChanges:function createIdentityChanges(e,t){var r,s=[];if(t&&isObject(t)&&e&&isObject(e))for(r in t)s.push({old_value:e[r]||null,new_value:t[r],identity_type:r});return s},// takes 2 UI objects keyed by name, combines them, returns them keyed by type
|
|
1123
1126
|
combineUserIdentities:function combineUserIdentities(e,t){var r={},s=i({},e,t);for(var n in s){var a=Types.IdentityType.getIdentityType(n);// this check removes anything that is not whitelisted as an identity type
|
|
1124
1127
|
!1!==a&&0<=a&&(r[Types.IdentityType.getIdentityType(n)]=s[n]);}return r},createAliasNetworkRequest:function createAliasNetworkRequest(e){return {request_id:t._Helpers.generateUniqueId(),request_type:"alias",environment:t._Store.SDKConfig.isDevelopmentMode?"development":"production",api_key:t._Store.devToken,data:{destination_mpid:e.destinationMpid,source_mpid:e.sourceMpid,start_unixtime_ms:e.startTime,end_unixtime_ms:e.endTime,scope:e.scope,device_application_stamp:t._Store.deviceId}}},convertAliasToNative:function convertAliasToNative(e){return {DestinationMpid:e.destinationMpid,SourceMpid:e.sourceMpid,StartUnixtimeMs:e.startTime,EndUnixtimeMs:e.endTime}},convertToNative:function convertToNative(e){var t=[];if(e&&e.userIdentities){for(var r in e.userIdentities)e.userIdentities.hasOwnProperty(r)&&t.push({Type:Types.IdentityType.getIdentityType(r),Identity:e.userIdentities[r]});return {UserIdentities:t}}}},this.IdentityAPI={HTTPCodes:HTTPCodes$2,/**
|
|
1125
1128
|
* Initiate a logout request to the mParticle server
|
|
@@ -1127,25 +1130,25 @@ combineUserIdentities:function combineUserIdentities(e,t){var r={},s=i({},e,t);f
|
|
|
1127
1130
|
* @param {Object} identityApiData The identityApiData object as indicated [here](https://github.com/mParticle/mparticle-sdk-javascript/blob/master-v2/README.md#1-customize-the-sdk)
|
|
1128
1131
|
* @param {Function} [callback] A callback function that is called when the identify request completes
|
|
1129
1132
|
*/identify:function identify(e,r){// https://go.mparticle.com/work/SQDSDKS-6337
|
|
1130
|
-
var s,i=t.Identity.getCurrentUser(),a=t._Identity.IdentityRequest.preProcessIdentityRequest(e,r,Identify);if(i&&(s=i.getMPID()),a.valid){var d=t._Identity.IdentityRequest.createIdentityRequest(
|
|
1133
|
+
var s,i=t.Identity.getCurrentUser(),a=t._Identity.IdentityRequest.preProcessIdentityRequest(e,r,Identify);if(i&&(s=i.getMPID()),a.valid){var d=t._Identity.IdentityRequest.createIdentityRequest(a.cleanedIdentities,Constants.platform,Constants.sdkVendor,Constants.sdkVersion,t._Store.deviceId,t._Store.context,s);if(t._Helpers.getFeatureFlag(Constants.FeatureFlags.CacheIdentity)){var o=tryCacheIdentity(d.known_identities,n.idCache,n.parseIdentityResponse,s,r,e,Identify);if(o)return}t._Helpers.canLog()?t._Store.webviewBridgeEnabled?(t._NativeSdkHelpers.sendToNative(Constants.NativeSdkPaths.Identify,JSON.stringify(t._Identity.IdentityRequest.convertToNative(e))),t._Helpers.invokeCallback(r,HTTPCodes$2.nativeIdentityRequest,"Identify request sent to native sdk")):t._IdentityAPIClient.sendIdentityRequest(d,Identify,r,e,n.parseIdentityResponse,s,d.known_identities):(t._Helpers.invokeCallback(r,HTTPCodes$2.loggingDisabledOrMissingAPIKey,Messages$2.InformationMessages.AbandonLogEvent),t.Logger.verbose(Messages$2.InformationMessages.AbandonLogEvent));}else t._Helpers.invokeCallback(r,HTTPCodes$2.validationIssue,a.error),t.Logger.verbose(a);},/**
|
|
1131
1134
|
* Initiate a logout request to the mParticle server
|
|
1132
1135
|
* @method logout
|
|
1133
1136
|
* @param {Object} identityApiData The identityApiData object as indicated [here](https://github.com/mParticle/mparticle-sdk-javascript/blob/master-v2/README.md#1-customize-the-sdk)
|
|
1134
1137
|
* @param {Function} [callback] A callback function that is called when the logout request completes
|
|
1135
1138
|
*/logout:function logout(e,r){// https://go.mparticle.com/work/SQDSDKS-6337
|
|
1136
|
-
var s,i=t.Identity.getCurrentUser(),a=t._Identity.IdentityRequest.preProcessIdentityRequest(e,r,Logout);if(i&&(s=i.getMPID()),a.valid){var d,o=t._Identity.IdentityRequest.createIdentityRequest(
|
|
1139
|
+
var s,i=t.Identity.getCurrentUser(),a=t._Identity.IdentityRequest.preProcessIdentityRequest(e,r,Logout);if(i&&(s=i.getMPID()),a.valid){var d,o=t._Identity.IdentityRequest.createIdentityRequest(a.cleanedIdentities,Constants.platform,Constants.sdkVendor,Constants.sdkVersion,t._Store.deviceId,t._Store.context,s);t._Helpers.canLog()?t._Store.webviewBridgeEnabled?(t._NativeSdkHelpers.sendToNative(Constants.NativeSdkPaths.Logout,JSON.stringify(t._Identity.IdentityRequest.convertToNative(e))),t._Helpers.invokeCallback(r,HTTPCodes$2.nativeIdentityRequest,"Logout request sent to native sdk")):(t._IdentityAPIClient.sendIdentityRequest(o,Logout,r,e,n.parseIdentityResponse,s),d=t._ServerModel.createEventObject({messageType:Types.MessageType.Profile}),d.ProfileMessageType=Types.ProfileMessageType.Logout,t._Store.activeForwarders.length&&t._Store.activeForwarders.forEach(function(e){e.logOut&&e.logOut(d);})):(t._Helpers.invokeCallback(r,HTTPCodes$2.loggingDisabledOrMissingAPIKey,Messages$2.InformationMessages.AbandonLogEvent),t.Logger.verbose(Messages$2.InformationMessages.AbandonLogEvent));}else t._Helpers.invokeCallback(r,HTTPCodes$2.validationIssue,a.error),t.Logger.verbose(a);},/**
|
|
1137
1140
|
* Initiate a login request to the mParticle server
|
|
1138
1141
|
* @method login
|
|
1139
1142
|
* @param {Object} identityApiData The identityApiData object as indicated [here](https://github.com/mParticle/mparticle-sdk-javascript/blob/master-v2/README.md#1-customize-the-sdk)
|
|
1140
1143
|
* @param {Function} [callback] A callback function that is called when the login request completes
|
|
1141
1144
|
*/login:function login(e,r){// https://go.mparticle.com/work/SQDSDKS-6337
|
|
1142
|
-
var s,i=t.Identity.getCurrentUser(),a=t._Identity.IdentityRequest.preProcessIdentityRequest(e,r,Login);if(i&&(s=i.getMPID()),a.valid){var d=t._Identity.IdentityRequest.createIdentityRequest(
|
|
1145
|
+
var s,i=t.Identity.getCurrentUser(),a=t._Identity.IdentityRequest.preProcessIdentityRequest(e,r,Login);if(i&&(s=i.getMPID()),a.valid){var d=t._Identity.IdentityRequest.createIdentityRequest(a.cleanedIdentities,Constants.platform,Constants.sdkVendor,Constants.sdkVersion,t._Store.deviceId,t._Store.context,s);if(t._Helpers.getFeatureFlag(Constants.FeatureFlags.CacheIdentity)){var o=tryCacheIdentity(d.known_identities,n.idCache,n.parseIdentityResponse,s,r,e,Login);if(o)return}t._Helpers.canLog()?t._Store.webviewBridgeEnabled?(t._NativeSdkHelpers.sendToNative(Constants.NativeSdkPaths.Login,JSON.stringify(t._Identity.IdentityRequest.convertToNative(e))),t._Helpers.invokeCallback(r,HTTPCodes$2.nativeIdentityRequest,"Login request sent to native sdk")):t._IdentityAPIClient.sendIdentityRequest(d,Login,r,e,n.parseIdentityResponse,s,d.known_identities):(t._Helpers.invokeCallback(r,HTTPCodes$2.loggingDisabledOrMissingAPIKey,Messages$2.InformationMessages.AbandonLogEvent),t.Logger.verbose(Messages$2.InformationMessages.AbandonLogEvent));}else t._Helpers.invokeCallback(r,HTTPCodes$2.validationIssue,a.error),t.Logger.verbose(a);},/**
|
|
1143
1146
|
* Initiate a modify request to the mParticle server
|
|
1144
1147
|
* @method modify
|
|
1145
1148
|
* @param {Object} identityApiData The identityApiData object as indicated [here](https://github.com/mParticle/mparticle-sdk-javascript/blob/master-v2/README.md#1-customize-the-sdk)
|
|
1146
1149
|
* @param {Function} [callback] A callback function that is called when the modify request completes
|
|
1147
1150
|
*/modify:function modify(e,r){// https://go.mparticle.com/work/SQDSDKS-6337
|
|
1148
|
-
var s,i=t.Identity.getCurrentUser(),a=t._Identity.IdentityRequest.preProcessIdentityRequest(e,r,Modify$1);i&&(s=i.getMPID())
|
|
1151
|
+
var s,i=t.Identity.getCurrentUser(),a=t._Identity.IdentityRequest.preProcessIdentityRequest(e,r,Modify$1);if(i&&(s=i.getMPID()),a.valid){var d=e&&e.userIdentities?a.cleanedIdentities.userIdentities:{},o=t._Identity.IdentityRequest.createModifyIdentityRequest(i?i.getUserIdentities().userIdentities:{},d,Constants.platform,Constants.sdkVendor,Constants.sdkVersion,t._Store.context);t._Helpers.canLog()?t._Store.webviewBridgeEnabled?(t._NativeSdkHelpers.sendToNative(Constants.NativeSdkPaths.Modify,JSON.stringify(t._Identity.IdentityRequest.convertToNative(e))),t._Helpers.invokeCallback(r,HTTPCodes$2.nativeIdentityRequest,"Modify request sent to native sdk")):t._IdentityAPIClient.sendIdentityRequest(o,Modify$1,r,e,n.parseIdentityResponse,s,o.known_identities):(t._Helpers.invokeCallback(r,HTTPCodes$2.loggingDisabledOrMissingAPIKey,Messages$2.InformationMessages.AbandonLogEvent),t.Logger.verbose(Messages$2.InformationMessages.AbandonLogEvent));}else t._Helpers.invokeCallback(r,HTTPCodes$2.validationIssue,a.error),t.Logger.verbose(a);},/**
|
|
1149
1152
|
* Returns a user object with methods to interact with the current user
|
|
1150
1153
|
* @method getCurrentUser
|
|
1151
1154
|
* @return {Object} the current user object
|
package/dist/mparticle.esm.js
CHANGED
|
@@ -15,7 +15,7 @@ map:function map(a,b){var c,d,e;if(null===this)throw new TypeError(" this is nul
|
|
|
15
15
|
filter:function filter(a/*, thisArg*/){if(void 0===this||null===this)throw new TypeError;var b=Object(this),c=b.length>>>0;if("function"!=typeof a)throw new TypeError;for(var d=[],e=2<=arguments.length?arguments[1]:void 0,f=0;f<c;f++)if(f in b){var g=b[f];a.call(e,g,f,b)&&d.push(g);}return d},// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray
|
|
16
16
|
isArray:function isArray(a){return "[object Array]"===Object.prototype.toString.call(a)},Base64:Base64$1};
|
|
17
17
|
|
|
18
|
-
var version = "2.43.
|
|
18
|
+
var version = "2.43.1";
|
|
19
19
|
|
|
20
20
|
var Constants={sdkVersion:version,sdkVendor:"mparticle",platform:"web",Messages:{DeprecationMessages:{MethodIsDeprecatedPostfix:"is a deprecated method and will be removed in future releases",AlternativeMethodPrefix:"Please use the alternate method:"},ErrorMessages:{NoToken:"A token must be specified.",EventNameInvalidType:"Event name must be a valid string value.",EventDataInvalidType:"Event data must be a valid object hash.",LoggingDisabled:"Event logging is currently disabled.",CookieParseError:"Could not parse cookie",EventEmpty:"Event object is null or undefined, cancelling send",APIRequestEmpty:"APIRequest is null or undefined, cancelling send",NoEventType:"Event type must be specified.",TransactionIdRequired:"Transaction ID is required",TransactionRequired:"A transaction attributes object is required",PromotionIdRequired:"Promotion ID is required",BadAttribute:"Attribute value cannot be object or array",BadKey:"Key value cannot be object or array",BadLogPurchase:"Transaction attributes and a product are both required to log a purchase, https://docs.mparticle.com/?javascript#measuring-transactions",AudienceAPINotEnabled:"Your workspace is not enabled to retrieve user audiences."},InformationMessages:{CookieSearch:"Searching for cookie",CookieFound:"Cookie found, parsing values",CookieNotFound:"Cookies not found",CookieSet:"Setting cookie",CookieSync:"Performing cookie sync",SendBegin:"Starting to send event",SendIdentityBegin:"Starting to send event to identity server",SendWindowsPhone:"Sending event to Windows Phone container",SendIOS:"Calling iOS path: ",SendAndroid:"Calling Android JS interface method: ",SendHttp:"Sending event to mParticle HTTP service",SendAliasHttp:"Sending alias request to mParticle HTTP service",SendIdentityHttp:"Sending event to mParticle HTTP service",StartingNewSession:"Starting new Session",StartingLogEvent:"Starting to log event",StartingLogOptOut:"Starting to log user opt in/out",StartingEndSession:"Starting to end session",StartingInitialization:"Starting to initialize",StartingLogCommerceEvent:"Starting to log commerce event",StartingAliasRequest:"Starting to Alias MPIDs",LoadingConfig:"Loading configuration options",AbandonLogEvent:"Cannot log event, logging disabled or developer token not set",AbandonAliasUsers:"Cannot Alias Users, logging disabled or developer token not set",AbandonStartSession:"Cannot start session, logging disabled or developer token not set",AbandonEndSession:"Cannot end session, logging disabled or developer token not set",NoSessionToEnd:"Cannot end session, no active session found"},ValidationMessages:{ModifyIdentityRequestUserIdentitiesPresent:"identityRequests to modify require userIdentities to be present. Request not sent to server. Please fix and try again",IdentityRequesetInvalidKey:"There is an invalid key on your identityRequest object. It can only contain a `userIdentities` object and a `onUserAlias` function. Request not sent to server. Please fix and try again.",OnUserAliasType:"The onUserAlias value must be a function.",UserIdentities:"The userIdentities key must be an object with keys of identityTypes and values of strings. Request not sent to server. Please fix and try again.",UserIdentitiesInvalidKey:"There is an invalid identity key on your `userIdentities` object within the identityRequest. Request not sent to server. Please fix and try again.",UserIdentitiesInvalidValues:"All user identity values must be strings or null. Request not sent to server. Please fix and try again.",AliasMissingMpid:"Alias Request must contain both a destinationMpid and a sourceMpid",AliasNonUniqueMpid:"Alias Request's destinationMpid and sourceMpid must be unique",AliasMissingTime:"Alias Request must have both a startTime and an endTime",AliasStartBeforeEndTime:"Alias Request's endTime must be later than its startTime"}},NativeSdkPaths:{LogEvent:"logEvent",SetUserTag:"setUserTag",RemoveUserTag:"removeUserTag",SetUserAttribute:"setUserAttribute",RemoveUserAttribute:"removeUserAttribute",SetSessionAttribute:"setSessionAttribute",AddToCart:"addToCart",RemoveFromCart:"removeFromCart",ClearCart:"clearCart",LogOut:"logOut",SetUserAttributeList:"setUserAttributeList",RemoveAllUserAttributes:"removeAllUserAttributes",GetUserAttributesLists:"getUserAttributesLists",GetAllUserAttributes:"getAllUserAttributes",Identify:"identify",Logout:"logout",Login:"login",Modify:"modify",Alias:"aliasUsers",Upload:"upload"},StorageNames:{localStorageName:"mprtcl-api",localStorageNameV3:"mprtcl-v3",cookieName:"mprtcl-api",cookieNameV2:"mprtcl-v2",cookieNameV3:"mprtcl-v3",localStorageNameV4:"mprtcl-v4",localStorageProductsV4:"mprtcl-prodv4",cookieNameV4:"mprtcl-v4",currentStorageName:"mprtcl-v4",currentStorageProductsName:"mprtcl-prodv4"},DefaultConfig:{cookieDomain:null,cookieExpiration:365,logLevel:null,timeout:300,sessionTimeout:30,maxProducts:20,forwarderStatsTimeout:5e3,integrationDelayTimeout:5e3,maxCookieSize:3e3,aliasMaxWindow:90,uploadInterval:0// Maximum milliseconds in between batch uploads, below 500 will mean immediate upload. The server returns this as a string, but we are using it as a number internally
|
|
21
21
|
},DefaultBaseUrls:{v1SecureServiceUrl:"jssdks.mparticle.com/v1/JS/",v2SecureServiceUrl:"jssdks.mparticle.com/v2/JS/",v3SecureServiceUrl:"jssdks.mparticle.com/v3/JS/",configUrl:"jssdkcdns.mparticle.com/JS/v2/",identityUrl:"identity.mparticle.com/v1/",aliasUrl:"jssdks.mparticle.com/v1/identity/",userAudienceUrl:"nativesdks.mparticle.com/v1/"},// These are the paths that are used to construct the CNAME urls
|
|
@@ -464,7 +464,8 @@ var Modify$4=Constants.IdentityMethods.Modify,Validators={// From ./utils
|
|
|
464
464
|
isNumber:isNumber,isFunction:isFunction,isStringOrNumber:isStringOrNumber,// Validator Functions
|
|
465
465
|
isValidAttributeValue:function isValidAttributeValue(a){return a!==void 0&&!isObject(a)&&!Array.isArray(a)},// Validator Functions
|
|
466
466
|
// Neither null nor undefined can be a valid Key
|
|
467
|
-
isValidKeyValue:function isValidKeyValue(a){return !(!a||isObject(a)||Array.isArray(a)||this.isFunction(a))},
|
|
467
|
+
isValidKeyValue:function isValidKeyValue(a){return !(!a||isObject(a)||Array.isArray(a)||this.isFunction(a))},removeFalsyIdentityValues:function removeFalsyIdentityValues(a,b){if(!a||!a.userIdentities)return a;var c={},d=__assign({},a.userIdentities);for(var e in a.userIdentities)if(a.userIdentities.hasOwnProperty(e)){var f=a.userIdentities[e];// Check if value is falsy (undefined, false, 0, '', etc.) but not null
|
|
468
|
+
null===f||f||(b.warning("Identity value for '".concat(e,"' is falsy (").concat(f,"). This value will be removed from the request.")),delete d[e]);}return c.userIdentities=d,c},validateIdentities:function validateIdentities(a,b){var c={userIdentities:1,onUserAlias:1,copyUserAttributes:1};if(a){if(b===Modify$4&&(isObject(a.userIdentities)&&!Object.keys(a.userIdentities).length||!isObject(a.userIdentities)))return {valid:!1,error:Constants.Messages.ValidationMessages.ModifyIdentityRequestUserIdentitiesPresent};for(var d in a)if(a.hasOwnProperty(d)){if(!c[d])return {valid:!1,error:Constants.Messages.ValidationMessages.IdentityRequesetInvalidKey};if("onUserAlias"===d&&!Validators.isFunction(a[d]))return {valid:!1,error:Constants.Messages.ValidationMessages.OnUserAliasType}}if(0===Object.keys(a).length)return {valid:!0};// identityApiData.userIdentities can't be undefined
|
|
468
469
|
if(void 0===a.userIdentities)return {valid:!1,error:Constants.Messages.ValidationMessages.UserIdentities};// identityApiData.userIdentities can be null, but if it isn't null or undefined (above conditional), it must be an object
|
|
469
470
|
if(null!==a.userIdentities&&!isObject(a.userIdentities))return {valid:!1,error:Constants.Messages.ValidationMessages.UserIdentities};if(isObject(a.userIdentities)&&Object.keys(a.userIdentities).length)for(var e in a.userIdentities)if(a.userIdentities.hasOwnProperty(e)){if(!1===Types.IdentityType.getIdentityType(e))return {valid:!1,error:Constants.Messages.ValidationMessages.UserIdentitiesInvalidKey};if("string"!=typeof a.userIdentities[e]&&null!==a.userIdentities[e])return {valid:!1,error:Constants.Messages.ValidationMessages.UserIdentitiesInvalidValues}}}return {valid:!0}}};
|
|
470
471
|
|
|
@@ -509,8 +510,32 @@ if(!isEmpty(k)&&(isEmpty(o)||(i=!0),!(i&&d)))// If MPID is new to cookies, we sh
|
|
|
509
510
|
return !b||new Date().getTime()>new Date(b).getTime()+a*DAYS_IN_MILLISECONDS;// Otherwise, compare the last sync date to determine if it should do a cookie sync again
|
|
510
511
|
};
|
|
511
512
|
|
|
513
|
+
var _a=Constants.IdentityMethods,Identify$2=_a.Identify,Modify$3=_a.Modify,Login$2=_a.Login,Logout$2=_a.Logout;var CACHE_HEADER="x-mp-max-age";var cacheOrClearIdCache=function(a,b,c,d,e){// when parsing a response that has already been cached, simply return instead of attempting another cache
|
|
514
|
+
if(!e){// default the expire timestamp to one day in milliseconds unless a header comes back
|
|
515
|
+
var f=getExpireTimestamp(null===d||void 0===d?void 0:d.cacheMaxAge);a===Login$2||a===Identify$2?cacheIdentityRequest(a,b,f,c,d):a===Modify$3||a===Logout$2?c.purge():void 0;}};var cacheIdentityRequest=function(a,b,c,d,e){var f=e.responseText,g=e.status,h=d.retrieve()||{},i=concatenateIdentities(a,b),j=generateHash(i),k=f.mpid,l=f.is_logged_in;h[j]={responseText:JSON.stringify({mpid:k,is_logged_in:l}),status:g,expireTimestamp:c},d.store(h);};// We need to ensure that identities are concatenated in a deterministic way, so
|
|
516
|
+
// we sort the identities based on their enum.
|
|
517
|
+
// we create an array, set the user identity at the index of the user identity type
|
|
518
|
+
var concatenateIdentities=function(a,b){var c="".concat(a,":").concat("device_application_stamp","=").concat(b.device_application_stamp,";"),d=Object.keys(b).length,e="";// set DAS first since it is not an official identity type
|
|
519
|
+
if(d){var f=[];// create an array where each index is equal to the user identity type
|
|
520
|
+
for(var g in b)if(g==="device_application_stamp")continue;else f[Types.IdentityType.getIdentityType(g)]=b[g];e=f.reduce(function(a,b,c){var d=Types.IdentityType.getIdentityName(c);return "".concat(a).concat(d,"=").concat(b,";")},c);}return e};var hasValidCachedIdentity=function(a,b,c){// There is an edge case where multiple identity calls are taking place
|
|
521
|
+
// before identify fires, so there may not be a cache. See what happens when
|
|
522
|
+
// the ? in idCache is removed to the following test
|
|
523
|
+
// "queued events contain login mpid instead of identify mpid when calling
|
|
524
|
+
// login immediately after mParticle initializes"
|
|
525
|
+
var d=null===c||void 0===c?void 0:c.retrieve();// if there is no cache, then there is no valid cached identity
|
|
526
|
+
if(!d)return !1;var e=concatenateIdentities(a,b),f=generateHash(e);// if cache doesn't have the cacheKey, there is no valid cached identity
|
|
527
|
+
if(!d.hasOwnProperty(f))return !1;// If there is a valid cache key, compare the expireTimestamp to the current time.
|
|
528
|
+
// If the current time is greater than the expireTimestamp, it is not a valid
|
|
529
|
+
// cached identity.
|
|
530
|
+
var g=d[f].expireTimestamp;return !(g<new Date().getTime())};var getCachedIdentity=function(a,b,c){var d=concatenateIdentities(a,b),e=generateHash(d),f=c.retrieve(),g=f?f[e]:null;return {responseText:parseIdentityResponse(g.responseText),expireTimestamp:g.expireTimestamp,status:g.status}};// https://go.mparticle.com/work/SQDSDKS-6079
|
|
531
|
+
var createKnownIdentities=function(a,b){var c={};if(isObject(null===a||void 0===a?void 0:a.userIdentities))for(var d in a.userIdentities)c[d]=a.userIdentities[d];return c.device_application_stamp=b,c};var removeExpiredIdentityCacheDates=function(a){var b=a.retrieve()||{},c=new Date().getTime();// Iterate over the cache and remove any key/value pairs that are expired
|
|
532
|
+
for(var d in b)b[d].expireTimestamp<c&&delete b[d];a.store(b);};var tryCacheIdentity=function(a,b,c,d,e,f,g){// https://go.mparticle.com/work/SQDSDKS-6095
|
|
533
|
+
var h=hasValidCachedIdentity(g,a,b);// If Identity is cached, then immediately parse the identity response
|
|
534
|
+
if(h){var i=getCachedIdentity(g,a,b);return c(i,d,e,f,g,a,!0),!0}return !1};var getExpireTimestamp=function(a){return void 0===a&&(a=ONE_DAY_IN_SECONDS),new Date().getTime()+a*MILLIS_IN_ONE_SEC},parseIdentityResponse=function(a){return a?JSON.parse(a):{}};var hasIdentityRequestChanged=function(a,b){if(!a||!(null!==b&&void 0!==b)||!b.userIdentities)return !1;var c=a.getUserIdentities().userIdentities,d=b.userIdentities;return JSON.stringify(c)!==JSON.stringify(d)};
|
|
535
|
+
|
|
512
536
|
var Messages$6=Constants.Messages;function SessionManager(a){var b=this;this.initialize=function(){if(a._Store.sessionId){var c=6e4*a._Store.SDKConfig.sessionTimeout;if(new Date>new Date(a._Store.dateLastEventSent.getTime()+c))b.endSession(),b.startNewSession();else {// https://go.mparticle.com/work/SQDSDKS-6045
|
|
513
|
-
|
|
537
|
+
// https://go.mparticle.com/work/SQDSDKS-6323
|
|
538
|
+
var d=a.Identity.getCurrentUser(),e=a._Store.SDKConfig.identifyRequest;hasIdentityRequestChanged(d,e)&&(a.Identity.identify(a._Store.SDKConfig.identifyRequest,a._Store.SDKConfig.identityCallback),a._Store.identifyCalled=!0,a._Store.SDKConfig.identityCallback=null);}}else b.startNewSession();},this.getSession=function(){return a.Logger.warning(generateDeprecationMessage("SessionManager.getSession()","SessionManager.getSessionId()")),this.getSessionId()},this.getSessionId=function(){return a._Store.sessionId},this.startNewSession=function(){if(a.Logger.verbose(Messages$6.InformationMessages.StartingNewSession),a._Helpers.canLog()){a._Store.sessionId=a._Helpers.generateUniqueId().toUpperCase();var c=a.Identity.getCurrentUser(),d=c?c.getMPID():null;if(d&&(a._Store.currentSessionMPIDs=[d]),!a._Store.sessionStartDate){var e=new Date;a._Store.sessionStartDate=e,a._Store.dateLastEventSent=e;}b.setSessionTimer(),a._Store.identifyCalled||(a.Identity.identify(a._Store.SDKConfig.identifyRequest,a._Store.SDKConfig.identityCallback),a._Store.identifyCalled=!0,a._Store.SDKConfig.identityCallback=null),a._Events.logEvent({messageType:Types.MessageType.SessionStart});}else a.Logger.verbose(Messages$6.InformationMessages.AbandonStartSession);},this.endSession=function(c){var d,e,f,g,h;if(a.Logger.verbose(Messages$6.InformationMessages.StartingEndSession),c)return a._Events.logEvent({messageType:Types.MessageType.SessionEnd}),a._Store.nullifySession(),void(null===(d=a._timeOnSiteTimer)||void 0===d?void 0:d.resetTimer());if(!a._Helpers.canLog())return a.Logger.verbose(Messages$6.InformationMessages.AbandonEndSession),void(null===(e=a._timeOnSiteTimer)||void 0===e?void 0:e.resetTimer());var i,j,k=a._Persistence.getPersistence();if(!k||k.gs&&!k.gs.sid)return a.Logger.verbose(Messages$6.InformationMessages.NoSessionToEnd),void(null===(f=a._timeOnSiteTimer)||void 0===f?void 0:f.resetTimer());// sessionId is not equal to cookies.sid if cookies.sid is changed in another tab
|
|
514
539
|
if(k.gs.sid&&a._Store.sessionId!==k.gs.sid&&(a._Store.sessionId=k.gs.sid),null===(g=null===k||void 0===k?void 0:k.gs)||void 0===g?void 0:g.les){i=6e4*a._Store.SDKConfig.sessionTimeout;var l=new Date().getTime();j=l-k.gs.les,j<i?b.setSessionTimer():(a._Events.logEvent({messageType:Types.MessageType.SessionEnd}),a._Store.sessionStartDate=null,a._Store.nullifySession());}null===(h=a._timeOnSiteTimer)||void 0===h?void 0:h.resetTimer();},this.setSessionTimer=function(){var c=6e4*a._Store.SDKConfig.sessionTimeout;a._Store.globalTimer=window.setTimeout(function(){b.endSession();},c);},this.resetSessionTimer=function(){a._Store.webviewBridgeEnabled||(!a._Store.sessionId&&b.startNewSession(),b.clearSessionTimeout(),b.setSessionTimer()),b.startNewSessionIfNeeded();},this.clearSessionTimeout=function(){clearTimeout(a._Store.globalTimer);},this.startNewSessionIfNeeded=function(){if(!a._Store.webviewBridgeEnabled){var c=a._Persistence.getPersistence();!a._Store.sessionId&&c&&(c.sid?a._Store.sessionId=c.sid:b.startNewSession());}};}
|
|
515
540
|
|
|
516
541
|
var Messages$5=Constants.Messages;function Ecommerce(a){var b=this;// https://go.mparticle.com/work/SQDSDKS-4801
|
|
@@ -1006,7 +1031,7 @@ var _regeneratorRuntime = /*@__PURE__*/getDefaultExportFromCjs(regenerator);
|
|
|
1006
1031
|
function filteredMparticleUser(a,b,c,d){var e=this;return {getUserIdentities:function getUserIdentities(){var e={},f=c._Store.getUserIdentities(a);for(var g in f)if(f.hasOwnProperty(g)){var h=Types.IdentityType.getIdentityName(c._Helpers.parseNumber(g));d&&(!d||d.isIdentityBlocked(h))||(//if identity type is not blocked
|
|
1007
1032
|
e[h]=f[g]);}return e=c._Helpers.filterUserIdentitiesForForwarders(e,b.userIdentityFilters),{userIdentities:e}},getMPID:function getMPID(){return a},getUserAttributesLists:function getUserAttributesLists(a){var b,f={};for(var g in b=e.getAllUserAttributes(),b)b.hasOwnProperty(g)&&Array.isArray(b[g])&&(d&&(!d||d.isAttributeKeyBlocked(g))||(f[g]=b[g].slice()));return f=c._Helpers.filterUserAttributes(f,a.userAttributeFilters),f},getAllUserAttributes:function getAllUserAttributes(){var e={},f=c._Store.getUserAttributes(a);if(f)for(var g in f)f.hasOwnProperty(g)&&(d&&(!d||d.isAttributeKeyBlocked(g))||(Array.isArray(f[g])?e[g]=f[g].slice():e[g]=f[g]));return e=c._Helpers.filterUserAttributes(e,b.userAttributeFilters),e}}}
|
|
1008
1033
|
|
|
1009
|
-
var _Constants$IdentityMe=Constants.IdentityMethods,Modify$
|
|
1034
|
+
var _Constants$IdentityMe=Constants.IdentityMethods,Modify$2=_Constants$IdentityMe.Modify,Identify$1=_Constants$IdentityMe.Identify,Login$1=_Constants$IdentityMe.Login,Logout$1=_Constants$IdentityMe.Logout;function Forwarders(a,b){var c=this,d=this;this.forwarderStatsUploader=new APIClient(a,b).initializeForwarderStatsUploader();var e={setUserAttribute:"setUserAttribute",removeUserAttribute:"removeUserAttribute"};// TODO: https://go.mparticle.com/work/SQDSDKS-6036
|
|
1010
1035
|
// Processing forwarders is a 2 step process:
|
|
1011
1036
|
// 1. Configure the kit
|
|
1012
1037
|
// 2. Initialize the kit
|
|
@@ -1036,7 +1061,7 @@ if(-1<j.indexOf(b.EventDataType)&&a._Store.activeForwarders[k].filteringEventAtt
|
|
|
1036
1061
|
if(b.EventAttributes)for(var m in b.EventAttributes){var n;if(n=KitFilterHelper.hashAttributeConditionalForwarding(m),n===a._Store.activeForwarders[k].filteringEventAttributeValue.eventAttributeName&&(l={name:n,value:KitFilterHelper.hashAttributeConditionalForwarding(b.EventAttributes[m])}),l)break}var o=null!==l&&l.value===a._Store.activeForwarders[k].filteringEventAttributeValue.eventAttributeValue,p=!0===a._Store.activeForwarders[k].filteringEventAttributeValue.includeOnMatch?o:!o;if(!p)continue}// Clone the event object, as we could be sending different attributes to each forwarder
|
|
1037
1062
|
// Check event filtering rules
|
|
1038
1063
|
if(c={},c=a._Helpers.extend(!0,c,b),b.EventDataType===Types.MessageType.PageEvent&&(h(a._Store.activeForwarders[k].eventNameFilters,d)||h(a._Store.activeForwarders[k].eventTypeFilters,e)))continue;else if(b.EventDataType===Types.MessageType.Commerce&&h(a._Store.activeForwarders[k].eventTypeFilters,e))continue;else if(b.EventDataType===Types.MessageType.PageView&&h(a._Store.activeForwarders[k].screenNameFilters,d))continue;// Check attribute filtering rules
|
|
1039
|
-
if(c.EventAttributes&&(b.EventDataType===Types.MessageType.PageEvent?g(c,a._Store.activeForwarders[k].attributeFilters):b.EventDataType===Types.MessageType.PageView&&g(c,a._Store.activeForwarders[k].screenAttributeFilters)),f(c,a._Store.activeForwarders[k].userIdentityFilters),c.UserAttributes=a._Helpers.filterUserAttributes(c.UserAttributes,a._Store.activeForwarders[k].userAttributeFilters),a._Store.activeForwarders[k].process){a.Logger.verbose("Sending message to forwarder: "+a._Store.activeForwarders[k].name);var q=a._Store.activeForwarders[k].process(c);q&&a.Logger.verbose(q);}}}},this.handleForwarderUserAttributes=function(c,d,f){b&&b.isAttributeKeyBlocked(d)||!a._Store.activeForwarders.length||a._Store.activeForwarders.forEach(function(b){var g=b[c];if(g&&!KitFilterHelper.isFilteredUserAttribute(d,b.userAttributeFilters))try{var h;c===e.setUserAttribute?h=b.setUserAttribute(d,f):c===e.removeUserAttribute&&(h=b.removeUserAttribute(d)),h&&a.Logger.verbose(h);}catch(b){a.Logger.error(b);}});},this.setForwarderUserIdentities=function(b){a._Store.activeForwarders.forEach(function(c){var d=a._Helpers.filterUserIdentities(b,c.userIdentityFilters);c.setUserIdentity&&d.forEach(function(b){var d=c.setUserIdentity(b.Identity,b.Type);d&&a.Logger.verbose(d);});});},this.setForwarderOnUserIdentified=function(c){a._Store.activeForwarders.forEach(function(d){var e=filteredMparticleUser(c.getMPID(),d,a,b);if(d.onUserIdentified){var f=d.onUserIdentified(e);f&&a.Logger.verbose(f);}});},this.setForwarderOnIdentityComplete=function(c,d){var e;a._Store.activeForwarders.forEach(function(f){var g=filteredMparticleUser(c.getMPID(),f,a,b),h=g.getUserIdentities();d===Identify$
|
|
1064
|
+
if(c.EventAttributes&&(b.EventDataType===Types.MessageType.PageEvent?g(c,a._Store.activeForwarders[k].attributeFilters):b.EventDataType===Types.MessageType.PageView&&g(c,a._Store.activeForwarders[k].screenAttributeFilters)),f(c,a._Store.activeForwarders[k].userIdentityFilters),c.UserAttributes=a._Helpers.filterUserAttributes(c.UserAttributes,a._Store.activeForwarders[k].userAttributeFilters),a._Store.activeForwarders[k].process){a.Logger.verbose("Sending message to forwarder: "+a._Store.activeForwarders[k].name);var q=a._Store.activeForwarders[k].process(c);q&&a.Logger.verbose(q);}}}},this.handleForwarderUserAttributes=function(c,d,f){b&&b.isAttributeKeyBlocked(d)||!a._Store.activeForwarders.length||a._Store.activeForwarders.forEach(function(b){var g=b[c];if(g&&!KitFilterHelper.isFilteredUserAttribute(d,b.userAttributeFilters))try{var h;c===e.setUserAttribute?h=b.setUserAttribute(d,f):c===e.removeUserAttribute&&(h=b.removeUserAttribute(d)),h&&a.Logger.verbose(h);}catch(b){a.Logger.error(b);}});},this.setForwarderUserIdentities=function(b){a._Store.activeForwarders.forEach(function(c){var d=a._Helpers.filterUserIdentities(b,c.userIdentityFilters);c.setUserIdentity&&d.forEach(function(b){var d=c.setUserIdentity(b.Identity,b.Type);d&&a.Logger.verbose(d);});});},this.setForwarderOnUserIdentified=function(c){a._Store.activeForwarders.forEach(function(d){var e=filteredMparticleUser(c.getMPID(),d,a,b);if(d.onUserIdentified){var f=d.onUserIdentified(e);f&&a.Logger.verbose(f);}});},this.setForwarderOnIdentityComplete=function(c,d){var e;a._Store.activeForwarders.forEach(function(f){var g=filteredMparticleUser(c.getMPID(),f,a,b),h=g.getUserIdentities();d===Identify$1?f.onIdentifyComplete&&(e=f.onIdentifyComplete(g,h),e&&a.Logger.verbose(e)):d===Login$1?f.onLoginComplete&&(e=f.onLoginComplete(g,h),e&&a.Logger.verbose(e)):d===Logout$1?f.onLogoutComplete&&(e=f.onLogoutComplete(g,h),e&&a.Logger.verbose(e)):d===Modify$2&&f.onModifyComplete&&(e=f.onModifyComplete(g,h),e&&a.Logger.verbose(e));});},this.getForwarderStatsQueue=function(){return a._Persistence.forwardingStatsBatches.forwardingStatsEventQueue},this.setForwarderStatsQueue=function(b){a._Persistence.forwardingStatsBatches.forwardingStatsEventQueue=b;},this.processForwarders=function(b,c){b?(this.processUIEnabledKits(b),this.processSideloadedKits(b),d.initForwarders(a._Store.SDKConfig.identifyRequest.userIdentities,c)):a.Logger.warning("No config was passed. Cannot process forwarders");},this.processUIEnabledKits=function(b){var c=this.returnKitConstructors();try{Array.isArray(b.kitConfigs)&&b.kitConfigs.length&&b.kitConfigs.forEach(function(a){d.configureUIEnabledKit(a,c);});}catch(b){a.Logger.error("MP Kits not configured propertly. Kits may not be initialized. "+b);}},this.returnKitConstructors=function(){var b={};// If there are kits inside of mpInstance._Store.SDKConfig.kits, then mParticle is self hosted
|
|
1040
1065
|
return isEmpty(a._Store.SDKConfig.kits)?!isEmpty(a._preInit.forwarderConstructors)&&a._preInit.forwarderConstructors.forEach(function(a){// A suffix is added to a kitConstructor and kit config if there are multiple different
|
|
1041
1066
|
// versions of a client kit. This matches the suffix in the DB. As an example
|
|
1042
1067
|
// the GA4 kit has a client kit and a server side kit which has a client side
|
|
@@ -1068,29 +1093,6 @@ Store:a._Store.serverSettings,SDKVersion:Constants.sdkVersion,SessionId:a._Store
|
|
|
1068
1093
|
|
|
1069
1094
|
function forwardingStatsUploader(a){function b(){var b=a._Forwarders.getForwarderStatsQueue(),c=a._Persistence.forwardingStatsBatches.uploadsTable,d=Date.now();for(var e in b.length&&(c[d]={uploading:!1,data:b},a._Forwarders.setForwarderStatsQueue([])),c)(function(b){if(c.hasOwnProperty(b)&&!1===c[b].uploading){var d=function(){4===e.readyState&&(200===e.status||202===e.status?(a.Logger.verbose("Successfully sent "+e.statusText+" from server"),delete c[b]):"4"===e.status.toString()[0]?429!==e.status&&delete c[b]:c[b].uploading=!1);},e=a._Helpers.createXHR(d),f=c[b].data;c[b].uploading=!0,a._APIClient.sendBatchForwardingStatsToServer(f,e);}})(e);}this.startForwardingStatsTimer=function(){mParticle._forwardingStatsTimer=setInterval(function(){b();},a._Store.SDKConfig.forwarderStatsTimeout);};}
|
|
1070
1095
|
|
|
1071
|
-
var _a=Constants.IdentityMethods,Identify$1=_a.Identify,Modify$2=_a.Modify,Login$1=_a.Login,Logout$1=_a.Logout;var CACHE_HEADER="x-mp-max-age";var cacheOrClearIdCache=function(a,b,c,d,e){// when parsing a response that has already been cached, simply return instead of attempting another cache
|
|
1072
|
-
if(!e){// default the expire timestamp to one day in milliseconds unless a header comes back
|
|
1073
|
-
var f=getExpireTimestamp(null===d||void 0===d?void 0:d.cacheMaxAge);a===Login$1||a===Identify$1?cacheIdentityRequest(a,b,f,c,d):a===Modify$2||a===Logout$1?c.purge():void 0;}};var cacheIdentityRequest=function(a,b,c,d,e){var f=e.responseText,g=e.status,h=d.retrieve()||{},i=concatenateIdentities(a,b),j=generateHash(i),k=f.mpid,l=f.is_logged_in;h[j]={responseText:JSON.stringify({mpid:k,is_logged_in:l}),status:g,expireTimestamp:c},d.store(h);};// We need to ensure that identities are concatenated in a deterministic way, so
|
|
1074
|
-
// we sort the identities based on their enum.
|
|
1075
|
-
// we create an array, set the user identity at the index of the user identity type
|
|
1076
|
-
var concatenateIdentities=function(a,b){var c="".concat(a,":").concat("device_application_stamp","=").concat(b.device_application_stamp,";"),d=Object.keys(b).length,e="";// set DAS first since it is not an official identity type
|
|
1077
|
-
if(d){var f=[];// create an array where each index is equal to the user identity type
|
|
1078
|
-
for(var g in b)if(g==="device_application_stamp")continue;else f[Types.IdentityType.getIdentityType(g)]=b[g];e=f.reduce(function(a,b,c){var d=Types.IdentityType.getIdentityName(c);return "".concat(a).concat(d,"=").concat(b,";")},c);}return e};var hasValidCachedIdentity=function(a,b,c){// There is an edge case where multiple identity calls are taking place
|
|
1079
|
-
// before identify fires, so there may not be a cache. See what happens when
|
|
1080
|
-
// the ? in idCache is removed to the following test
|
|
1081
|
-
// "queued events contain login mpid instead of identify mpid when calling
|
|
1082
|
-
// login immediately after mParticle initializes"
|
|
1083
|
-
var d=null===c||void 0===c?void 0:c.retrieve();// if there is no cache, then there is no valid cached identity
|
|
1084
|
-
if(!d)return !1;var e=concatenateIdentities(a,b),f=generateHash(e);// if cache doesn't have the cacheKey, there is no valid cached identity
|
|
1085
|
-
if(!d.hasOwnProperty(f))return !1;// If there is a valid cache key, compare the expireTimestamp to the current time.
|
|
1086
|
-
// If the current time is greater than the expireTimestamp, it is not a valid
|
|
1087
|
-
// cached identity.
|
|
1088
|
-
var g=d[f].expireTimestamp;return !(g<new Date().getTime())};var getCachedIdentity=function(a,b,c){var d=concatenateIdentities(a,b),e=generateHash(d),f=c.retrieve(),g=f?f[e]:null;return {responseText:parseIdentityResponse(g.responseText),expireTimestamp:g.expireTimestamp,status:g.status}};// https://go.mparticle.com/work/SQDSDKS-6079
|
|
1089
|
-
var createKnownIdentities=function(a,b){var c={};if(isObject(null===a||void 0===a?void 0:a.userIdentities))for(var d in a.userIdentities)c[d]=a.userIdentities[d];return c.device_application_stamp=b,c};var removeExpiredIdentityCacheDates=function(a){var b=a.retrieve()||{},c=new Date().getTime();// Iterate over the cache and remove any key/value pairs that are expired
|
|
1090
|
-
for(var d in b)b[d].expireTimestamp<c&&delete b[d];a.store(b);};var tryCacheIdentity=function(a,b,c,d,e,f,g){// https://go.mparticle.com/work/SQDSDKS-6095
|
|
1091
|
-
var h=hasValidCachedIdentity(g,a,b);// If Identity is cached, then immediately parse the identity response
|
|
1092
|
-
if(h){var i=getCachedIdentity(g,a,b);return c(i,d,e,f,g,a,!0),!0}return !1};var getExpireTimestamp=function(a){return void 0===a&&(a=ONE_DAY_IN_SECONDS),new Date().getTime()+a*MILLIS_IN_ONE_SEC},parseIdentityResponse=function(a){return a?JSON.parse(a):{}};
|
|
1093
|
-
|
|
1094
1096
|
var AudienceManager=/** @class */function(){function a(a,b,c){this.url="",this.logger=c,this.url="https://".concat(a).concat(b,"/audience"),this.userAudienceAPI=window.fetch?new FetchUploader(this.url):new XHRUploader(this.url);}return a.prototype.sendGetUserAudienceRequest=function(a,b){return __awaiter(this,void 0,void 0,function(){var c,d,e,f,g,h;return __generator(this,function(i){switch(i.label){case 0:this.logger.verbose("Fetching user audiences from server"),c={method:"GET",headers:{Accept:"*/*"}},d="".concat(this.url,"?mpid=").concat(a),i.label=1;case 1:return i.trys.push([1,6,,7]),[4/*yield*/,this.userAudienceAPI.upload(c,d)];case 2:return (e=i.sent(),!(200<=e.status&&300>e.status))?[3/*break*/,4]:(this.logger.verbose("User Audiences successfully received"),[4/*yield*/,e.json()]);case 3:f=i.sent(),g={currentAudienceMemberships:null===f||void 0===f?void 0:f.audience_memberships};try{b(g);}catch(a){throw new Error("Error invoking callback on user audience response.")}return [3/*break*/,5];case 4:if(401===e.status)throw new Error("`HTTP error status ${userAudiencePromise.status} while retrieving User Audiences - please verify your API key.`");else if(403===e.status)throw new Error("`HTTP error status ${userAudiencePromise.status} while retrieving User Audiences - please verify your workspace is enabled for audiences.`");else// In case there is an HTTP error we did not anticipate.
|
|
1095
1097
|
throw new Error("Uncaught HTTP Error ".concat(e.status,"."));case 5:return [3/*break*/,7];case 6:return h=i.sent(),this.logger.error("Error retrieving audiences. ".concat(h)),[3/*break*/,7];case 7:return [2/*return*/]}})})},a}();
|
|
1096
1098
|
|
|
@@ -1119,7 +1121,8 @@ var Messages$2=Constants.Messages,HTTPCodes$2=Constants.HTTPCodes,FeatureFlags$1
|
|
|
1119
1121
|
// send a user identity change request on identify, login, logout, modify when any values change.
|
|
1120
1122
|
// compare what identities exist vs what is previously was for the specific user if they were in memory before.
|
|
1121
1123
|
// if it's the first time the user is logging in, send a user identity change request with
|
|
1122
|
-
this.idCache=null,this.audienceManager=null,this.IdentityRequest={preProcessIdentityRequest:function preProcessIdentityRequest(e,r,s){t.Logger.verbose(Messages$2.InformationMessages.StartingLogEvent+": "+s)
|
|
1124
|
+
this.idCache=null,this.audienceManager=null,this.IdentityRequest={preProcessIdentityRequest:function preProcessIdentityRequest(e,r,s){t.Logger.verbose(Messages$2.InformationMessages.StartingLogEvent+": "+s);// First, remove any falsy identity values and warn about them
|
|
1125
|
+
var i=t._Helpers.Validators.removeFalsyIdentityValues(e,t.Logger),n=t._Helpers.Validators.validateIdentities(i,s);if(!n.valid)return t.Logger.error("ERROR: "+n.error),{valid:!1,error:n.error};if(r&&!t._Helpers.Validators.isFunction(r)){var a="The optional callback must be a function. You tried entering a(n) "+_typeof$1(r);return t.Logger.error(a),{valid:!1,error:a}}return {valid:!0,cleanedIdentities:i}},createIdentityRequest:function createIdentityRequest(e,r,s,i,n,a,d){var o={client_sdk:{platform:r,sdk_vendor:s,sdk_version:i},context:a,environment:t._Store.SDKConfig.isDevelopmentMode?"development":"production",request_id:t._Helpers.generateUniqueId(),request_timestamp_ms:new Date().getTime(),previous_mpid:d||null,known_identities:createKnownIdentities(e,n)};return o},createModifyIdentityRequest:function createModifyIdentityRequest(e,r,s,i,n,a){return {client_sdk:{platform:s,sdk_vendor:i,sdk_version:n},context:a,environment:t._Store.SDKConfig.isDevelopmentMode?"development":"production",request_id:t._Helpers.generateUniqueId(),request_timestamp_ms:new Date().getTime(),identity_changes:this.createIdentityChanges(e,r)}},createIdentityChanges:function createIdentityChanges(e,t){var r,s=[];if(t&&isObject(t)&&e&&isObject(e))for(r in t)s.push({old_value:e[r]||null,new_value:t[r],identity_type:r});return s},// takes 2 UI objects keyed by name, combines them, returns them keyed by type
|
|
1123
1126
|
combineUserIdentities:function combineUserIdentities(e,t){var r={},s=i({},e,t);for(var n in s){var a=Types.IdentityType.getIdentityType(n);// this check removes anything that is not whitelisted as an identity type
|
|
1124
1127
|
!1!==a&&0<=a&&(r[Types.IdentityType.getIdentityType(n)]=s[n]);}return r},createAliasNetworkRequest:function createAliasNetworkRequest(e){return {request_id:t._Helpers.generateUniqueId(),request_type:"alias",environment:t._Store.SDKConfig.isDevelopmentMode?"development":"production",api_key:t._Store.devToken,data:{destination_mpid:e.destinationMpid,source_mpid:e.sourceMpid,start_unixtime_ms:e.startTime,end_unixtime_ms:e.endTime,scope:e.scope,device_application_stamp:t._Store.deviceId}}},convertAliasToNative:function convertAliasToNative(e){return {DestinationMpid:e.destinationMpid,SourceMpid:e.sourceMpid,StartUnixtimeMs:e.startTime,EndUnixtimeMs:e.endTime}},convertToNative:function convertToNative(e){var t=[];if(e&&e.userIdentities){for(var r in e.userIdentities)e.userIdentities.hasOwnProperty(r)&&t.push({Type:Types.IdentityType.getIdentityType(r),Identity:e.userIdentities[r]});return {UserIdentities:t}}}},this.IdentityAPI={HTTPCodes:HTTPCodes$2,/**
|
|
1125
1128
|
* Initiate a logout request to the mParticle server
|
|
@@ -1127,25 +1130,25 @@ combineUserIdentities:function combineUserIdentities(e,t){var r={},s=i({},e,t);f
|
|
|
1127
1130
|
* @param {Object} identityApiData The identityApiData object as indicated [here](https://github.com/mParticle/mparticle-sdk-javascript/blob/master-v2/README.md#1-customize-the-sdk)
|
|
1128
1131
|
* @param {Function} [callback] A callback function that is called when the identify request completes
|
|
1129
1132
|
*/identify:function identify(e,r){// https://go.mparticle.com/work/SQDSDKS-6337
|
|
1130
|
-
var s,i=t.Identity.getCurrentUser(),a=t._Identity.IdentityRequest.preProcessIdentityRequest(e,r,Identify);if(i&&(s=i.getMPID()),a.valid){var d=t._Identity.IdentityRequest.createIdentityRequest(
|
|
1133
|
+
var s,i=t.Identity.getCurrentUser(),a=t._Identity.IdentityRequest.preProcessIdentityRequest(e,r,Identify);if(i&&(s=i.getMPID()),a.valid){var d=t._Identity.IdentityRequest.createIdentityRequest(a.cleanedIdentities,Constants.platform,Constants.sdkVendor,Constants.sdkVersion,t._Store.deviceId,t._Store.context,s);if(t._Helpers.getFeatureFlag(Constants.FeatureFlags.CacheIdentity)){var o=tryCacheIdentity(d.known_identities,n.idCache,n.parseIdentityResponse,s,r,e,Identify);if(o)return}t._Helpers.canLog()?t._Store.webviewBridgeEnabled?(t._NativeSdkHelpers.sendToNative(Constants.NativeSdkPaths.Identify,JSON.stringify(t._Identity.IdentityRequest.convertToNative(e))),t._Helpers.invokeCallback(r,HTTPCodes$2.nativeIdentityRequest,"Identify request sent to native sdk")):t._IdentityAPIClient.sendIdentityRequest(d,Identify,r,e,n.parseIdentityResponse,s,d.known_identities):(t._Helpers.invokeCallback(r,HTTPCodes$2.loggingDisabledOrMissingAPIKey,Messages$2.InformationMessages.AbandonLogEvent),t.Logger.verbose(Messages$2.InformationMessages.AbandonLogEvent));}else t._Helpers.invokeCallback(r,HTTPCodes$2.validationIssue,a.error),t.Logger.verbose(a);},/**
|
|
1131
1134
|
* Initiate a logout request to the mParticle server
|
|
1132
1135
|
* @method logout
|
|
1133
1136
|
* @param {Object} identityApiData The identityApiData object as indicated [here](https://github.com/mParticle/mparticle-sdk-javascript/blob/master-v2/README.md#1-customize-the-sdk)
|
|
1134
1137
|
* @param {Function} [callback] A callback function that is called when the logout request completes
|
|
1135
1138
|
*/logout:function logout(e,r){// https://go.mparticle.com/work/SQDSDKS-6337
|
|
1136
|
-
var s,i=t.Identity.getCurrentUser(),a=t._Identity.IdentityRequest.preProcessIdentityRequest(e,r,Logout);if(i&&(s=i.getMPID()),a.valid){var d,o=t._Identity.IdentityRequest.createIdentityRequest(
|
|
1139
|
+
var s,i=t.Identity.getCurrentUser(),a=t._Identity.IdentityRequest.preProcessIdentityRequest(e,r,Logout);if(i&&(s=i.getMPID()),a.valid){var d,o=t._Identity.IdentityRequest.createIdentityRequest(a.cleanedIdentities,Constants.platform,Constants.sdkVendor,Constants.sdkVersion,t._Store.deviceId,t._Store.context,s);t._Helpers.canLog()?t._Store.webviewBridgeEnabled?(t._NativeSdkHelpers.sendToNative(Constants.NativeSdkPaths.Logout,JSON.stringify(t._Identity.IdentityRequest.convertToNative(e))),t._Helpers.invokeCallback(r,HTTPCodes$2.nativeIdentityRequest,"Logout request sent to native sdk")):(t._IdentityAPIClient.sendIdentityRequest(o,Logout,r,e,n.parseIdentityResponse,s),d=t._ServerModel.createEventObject({messageType:Types.MessageType.Profile}),d.ProfileMessageType=Types.ProfileMessageType.Logout,t._Store.activeForwarders.length&&t._Store.activeForwarders.forEach(function(e){e.logOut&&e.logOut(d);})):(t._Helpers.invokeCallback(r,HTTPCodes$2.loggingDisabledOrMissingAPIKey,Messages$2.InformationMessages.AbandonLogEvent),t.Logger.verbose(Messages$2.InformationMessages.AbandonLogEvent));}else t._Helpers.invokeCallback(r,HTTPCodes$2.validationIssue,a.error),t.Logger.verbose(a);},/**
|
|
1137
1140
|
* Initiate a login request to the mParticle server
|
|
1138
1141
|
* @method login
|
|
1139
1142
|
* @param {Object} identityApiData The identityApiData object as indicated [here](https://github.com/mParticle/mparticle-sdk-javascript/blob/master-v2/README.md#1-customize-the-sdk)
|
|
1140
1143
|
* @param {Function} [callback] A callback function that is called when the login request completes
|
|
1141
1144
|
*/login:function login(e,r){// https://go.mparticle.com/work/SQDSDKS-6337
|
|
1142
|
-
var s,i=t.Identity.getCurrentUser(),a=t._Identity.IdentityRequest.preProcessIdentityRequest(e,r,Login);if(i&&(s=i.getMPID()),a.valid){var d=t._Identity.IdentityRequest.createIdentityRequest(
|
|
1145
|
+
var s,i=t.Identity.getCurrentUser(),a=t._Identity.IdentityRequest.preProcessIdentityRequest(e,r,Login);if(i&&(s=i.getMPID()),a.valid){var d=t._Identity.IdentityRequest.createIdentityRequest(a.cleanedIdentities,Constants.platform,Constants.sdkVendor,Constants.sdkVersion,t._Store.deviceId,t._Store.context,s);if(t._Helpers.getFeatureFlag(Constants.FeatureFlags.CacheIdentity)){var o=tryCacheIdentity(d.known_identities,n.idCache,n.parseIdentityResponse,s,r,e,Login);if(o)return}t._Helpers.canLog()?t._Store.webviewBridgeEnabled?(t._NativeSdkHelpers.sendToNative(Constants.NativeSdkPaths.Login,JSON.stringify(t._Identity.IdentityRequest.convertToNative(e))),t._Helpers.invokeCallback(r,HTTPCodes$2.nativeIdentityRequest,"Login request sent to native sdk")):t._IdentityAPIClient.sendIdentityRequest(d,Login,r,e,n.parseIdentityResponse,s,d.known_identities):(t._Helpers.invokeCallback(r,HTTPCodes$2.loggingDisabledOrMissingAPIKey,Messages$2.InformationMessages.AbandonLogEvent),t.Logger.verbose(Messages$2.InformationMessages.AbandonLogEvent));}else t._Helpers.invokeCallback(r,HTTPCodes$2.validationIssue,a.error),t.Logger.verbose(a);},/**
|
|
1143
1146
|
* Initiate a modify request to the mParticle server
|
|
1144
1147
|
* @method modify
|
|
1145
1148
|
* @param {Object} identityApiData The identityApiData object as indicated [here](https://github.com/mParticle/mparticle-sdk-javascript/blob/master-v2/README.md#1-customize-the-sdk)
|
|
1146
1149
|
* @param {Function} [callback] A callback function that is called when the modify request completes
|
|
1147
1150
|
*/modify:function modify(e,r){// https://go.mparticle.com/work/SQDSDKS-6337
|
|
1148
|
-
var s,i=t.Identity.getCurrentUser(),a=t._Identity.IdentityRequest.preProcessIdentityRequest(e,r,Modify$1);i&&(s=i.getMPID())
|
|
1151
|
+
var s,i=t.Identity.getCurrentUser(),a=t._Identity.IdentityRequest.preProcessIdentityRequest(e,r,Modify$1);if(i&&(s=i.getMPID()),a.valid){var d=e&&e.userIdentities?a.cleanedIdentities.userIdentities:{},o=t._Identity.IdentityRequest.createModifyIdentityRequest(i?i.getUserIdentities().userIdentities:{},d,Constants.platform,Constants.sdkVendor,Constants.sdkVersion,t._Store.context);t._Helpers.canLog()?t._Store.webviewBridgeEnabled?(t._NativeSdkHelpers.sendToNative(Constants.NativeSdkPaths.Modify,JSON.stringify(t._Identity.IdentityRequest.convertToNative(e))),t._Helpers.invokeCallback(r,HTTPCodes$2.nativeIdentityRequest,"Modify request sent to native sdk")):t._IdentityAPIClient.sendIdentityRequest(o,Modify$1,r,e,n.parseIdentityResponse,s,o.known_identities):(t._Helpers.invokeCallback(r,HTTPCodes$2.loggingDisabledOrMissingAPIKey,Messages$2.InformationMessages.AbandonLogEvent),t.Logger.verbose(Messages$2.InformationMessages.AbandonLogEvent));}else t._Helpers.invokeCallback(r,HTTPCodes$2.validationIssue,a.error),t.Logger.verbose(a);},/**
|
|
1149
1152
|
* Returns a user object with methods to interact with the current user
|
|
1150
1153
|
* @method getCurrentUser
|
|
1151
1154
|
* @return {Object} the current user object
|
package/dist/mparticle.js
CHANGED
|
@@ -203,7 +203,7 @@ var mParticle = (function () {
|
|
|
203
203
|
Base64: Base64$1
|
|
204
204
|
};
|
|
205
205
|
|
|
206
|
-
var version = "2.43.
|
|
206
|
+
var version = "2.43.1";
|
|
207
207
|
|
|
208
208
|
var Constants = {
|
|
209
209
|
sdkVersion: version,
|
|
@@ -2844,6 +2844,25 @@ var mParticle = (function () {
|
|
|
2844
2844
|
isValidKeyValue: function isValidKeyValue(key) {
|
|
2845
2845
|
return Boolean(key && !isObject(key) && !Array.isArray(key) && !this.isFunction(key));
|
|
2846
2846
|
},
|
|
2847
|
+
removeFalsyIdentityValues: function removeFalsyIdentityValues(identityApiData, logger) {
|
|
2848
|
+
if (!identityApiData || !identityApiData.userIdentities) {
|
|
2849
|
+
return identityApiData;
|
|
2850
|
+
}
|
|
2851
|
+
var cleanedData = {};
|
|
2852
|
+
var cleanedUserIdentities = __assign({}, identityApiData.userIdentities);
|
|
2853
|
+
for (var identityType in identityApiData.userIdentities) {
|
|
2854
|
+
if (identityApiData.userIdentities.hasOwnProperty(identityType)) {
|
|
2855
|
+
var value = identityApiData.userIdentities[identityType];
|
|
2856
|
+
// Check if value is falsy (undefined, false, 0, '', etc.) but not null
|
|
2857
|
+
if (value !== null && !value) {
|
|
2858
|
+
logger.warning("Identity value for '".concat(identityType, "' is falsy (").concat(value, "). This value will be removed from the request."));
|
|
2859
|
+
delete cleanedUserIdentities[identityType];
|
|
2860
|
+
}
|
|
2861
|
+
}
|
|
2862
|
+
}
|
|
2863
|
+
cleanedData.userIdentities = cleanedUserIdentities;
|
|
2864
|
+
return cleanedData;
|
|
2865
|
+
},
|
|
2847
2866
|
validateIdentities: function validateIdentities(identityApiData, method) {
|
|
2848
2867
|
var validIdentityRequestKeys = {
|
|
2849
2868
|
userIdentities: 1,
|
|
@@ -3473,6 +3492,164 @@ var mParticle = (function () {
|
|
|
3473
3492
|
return new Date().getTime() > new Date(lastSyncDate).getTime() + frequencyCap * DAYS_IN_MILLISECONDS;
|
|
3474
3493
|
};
|
|
3475
3494
|
|
|
3495
|
+
var _a = Constants.IdentityMethods,
|
|
3496
|
+
Identify$2 = _a.Identify,
|
|
3497
|
+
Modify$3 = _a.Modify,
|
|
3498
|
+
Login$2 = _a.Login,
|
|
3499
|
+
Logout$2 = _a.Logout;
|
|
3500
|
+
var CACHE_HEADER = 'x-mp-max-age';
|
|
3501
|
+
var cacheOrClearIdCache = function cacheOrClearIdCache(method, knownIdentities, idCache, identityResponse, parsingCachedResponse) {
|
|
3502
|
+
// when parsing a response that has already been cached, simply return instead of attempting another cache
|
|
3503
|
+
if (parsingCachedResponse) {
|
|
3504
|
+
return;
|
|
3505
|
+
}
|
|
3506
|
+
// default the expire timestamp to one day in milliseconds unless a header comes back
|
|
3507
|
+
var expireTimestamp = getExpireTimestamp(identityResponse === null || identityResponse === void 0 ? void 0 : identityResponse.cacheMaxAge);
|
|
3508
|
+
switch (method) {
|
|
3509
|
+
case Login$2:
|
|
3510
|
+
case Identify$2:
|
|
3511
|
+
cacheIdentityRequest(method, knownIdentities, expireTimestamp, idCache, identityResponse);
|
|
3512
|
+
break;
|
|
3513
|
+
case Modify$3:
|
|
3514
|
+
case Logout$2:
|
|
3515
|
+
idCache.purge();
|
|
3516
|
+
break;
|
|
3517
|
+
}
|
|
3518
|
+
};
|
|
3519
|
+
var cacheIdentityRequest = function cacheIdentityRequest(method, identities, expireTimestamp, idCache, identityResponse) {
|
|
3520
|
+
var responseText = identityResponse.responseText,
|
|
3521
|
+
status = identityResponse.status;
|
|
3522
|
+
var cache = idCache.retrieve() || {};
|
|
3523
|
+
var cacheKey = concatenateIdentities(method, identities);
|
|
3524
|
+
var hashedKey = generateHash(cacheKey);
|
|
3525
|
+
var mpid = responseText.mpid,
|
|
3526
|
+
is_logged_in = responseText.is_logged_in;
|
|
3527
|
+
var cachedResponseBody = {
|
|
3528
|
+
mpid: mpid,
|
|
3529
|
+
is_logged_in: is_logged_in
|
|
3530
|
+
};
|
|
3531
|
+
cache[hashedKey] = {
|
|
3532
|
+
responseText: JSON.stringify(cachedResponseBody),
|
|
3533
|
+
status: status,
|
|
3534
|
+
expireTimestamp: expireTimestamp
|
|
3535
|
+
};
|
|
3536
|
+
idCache.store(cache);
|
|
3537
|
+
};
|
|
3538
|
+
// We need to ensure that identities are concatenated in a deterministic way, so
|
|
3539
|
+
// we sort the identities based on their enum.
|
|
3540
|
+
// we create an array, set the user identity at the index of the user identity type
|
|
3541
|
+
var concatenateIdentities = function concatenateIdentities(method, userIdentities) {
|
|
3542
|
+
var DEVICE_APPLICATION_STAMP = 'device_application_stamp';
|
|
3543
|
+
// set DAS first since it is not an official identity type
|
|
3544
|
+
var cacheKey = "".concat(method, ":").concat(DEVICE_APPLICATION_STAMP, "=").concat(userIdentities.device_application_stamp, ";");
|
|
3545
|
+
var idLength = Object.keys(userIdentities).length;
|
|
3546
|
+
var concatenatedIdentities = '';
|
|
3547
|
+
if (idLength) {
|
|
3548
|
+
var userIDArray = new Array();
|
|
3549
|
+
// create an array where each index is equal to the user identity type
|
|
3550
|
+
for (var key in userIdentities) {
|
|
3551
|
+
if (key === DEVICE_APPLICATION_STAMP) {
|
|
3552
|
+
continue;
|
|
3553
|
+
} else {
|
|
3554
|
+
userIDArray[Types.IdentityType.getIdentityType(key)] = userIdentities[key];
|
|
3555
|
+
}
|
|
3556
|
+
}
|
|
3557
|
+
concatenatedIdentities = userIDArray.reduce(function (prevValue, currentValue, index) {
|
|
3558
|
+
var idName = Types.IdentityType.getIdentityName(index);
|
|
3559
|
+
return "".concat(prevValue).concat(idName, "=").concat(currentValue, ";");
|
|
3560
|
+
}, cacheKey);
|
|
3561
|
+
}
|
|
3562
|
+
return concatenatedIdentities;
|
|
3563
|
+
};
|
|
3564
|
+
var hasValidCachedIdentity = function hasValidCachedIdentity(method, proposedUserIdentities, idCache) {
|
|
3565
|
+
// There is an edge case where multiple identity calls are taking place
|
|
3566
|
+
// before identify fires, so there may not be a cache. See what happens when
|
|
3567
|
+
// the ? in idCache is removed to the following test
|
|
3568
|
+
// "queued events contain login mpid instead of identify mpid when calling
|
|
3569
|
+
// login immediately after mParticle initializes"
|
|
3570
|
+
var cache = idCache === null || idCache === void 0 ? void 0 : idCache.retrieve();
|
|
3571
|
+
// if there is no cache, then there is no valid cached identity
|
|
3572
|
+
if (!cache) {
|
|
3573
|
+
return false;
|
|
3574
|
+
}
|
|
3575
|
+
var cacheKey = concatenateIdentities(method, proposedUserIdentities);
|
|
3576
|
+
var hashedKey = generateHash(cacheKey);
|
|
3577
|
+
// if cache doesn't have the cacheKey, there is no valid cached identity
|
|
3578
|
+
if (!cache.hasOwnProperty(hashedKey)) {
|
|
3579
|
+
return false;
|
|
3580
|
+
}
|
|
3581
|
+
// If there is a valid cache key, compare the expireTimestamp to the current time.
|
|
3582
|
+
// If the current time is greater than the expireTimestamp, it is not a valid
|
|
3583
|
+
// cached identity.
|
|
3584
|
+
var expireTimestamp = cache[hashedKey].expireTimestamp;
|
|
3585
|
+
if (expireTimestamp < new Date().getTime()) {
|
|
3586
|
+
return false;
|
|
3587
|
+
} else {
|
|
3588
|
+
return true;
|
|
3589
|
+
}
|
|
3590
|
+
};
|
|
3591
|
+
var getCachedIdentity = function getCachedIdentity(method, proposedUserIdentities, idCache) {
|
|
3592
|
+
var cacheKey = concatenateIdentities(method, proposedUserIdentities);
|
|
3593
|
+
var hashedKey = generateHash(cacheKey);
|
|
3594
|
+
var cache = idCache.retrieve();
|
|
3595
|
+
var cachedIdentity = cache ? cache[hashedKey] : null;
|
|
3596
|
+
return {
|
|
3597
|
+
responseText: parseIdentityResponse(cachedIdentity.responseText),
|
|
3598
|
+
expireTimestamp: cachedIdentity.expireTimestamp,
|
|
3599
|
+
status: cachedIdentity.status
|
|
3600
|
+
};
|
|
3601
|
+
};
|
|
3602
|
+
// https://go.mparticle.com/work/SQDSDKS-6079
|
|
3603
|
+
var createKnownIdentities = function createKnownIdentities(identityApiData, deviceId) {
|
|
3604
|
+
var identitiesResult = {};
|
|
3605
|
+
if (isObject(identityApiData === null || identityApiData === void 0 ? void 0 : identityApiData.userIdentities)) {
|
|
3606
|
+
for (var identity in identityApiData.userIdentities) {
|
|
3607
|
+
identitiesResult[identity] = identityApiData.userIdentities[identity];
|
|
3608
|
+
}
|
|
3609
|
+
}
|
|
3610
|
+
identitiesResult.device_application_stamp = deviceId;
|
|
3611
|
+
return identitiesResult;
|
|
3612
|
+
};
|
|
3613
|
+
var removeExpiredIdentityCacheDates = function removeExpiredIdentityCacheDates(idCache) {
|
|
3614
|
+
var cache = idCache.retrieve() || {};
|
|
3615
|
+
var currentTime = new Date().getTime();
|
|
3616
|
+
// Iterate over the cache and remove any key/value pairs that are expired
|
|
3617
|
+
for (var key in cache) {
|
|
3618
|
+
if (cache[key].expireTimestamp < currentTime) {
|
|
3619
|
+
delete cache[key];
|
|
3620
|
+
}
|
|
3621
|
+
}
|
|
3622
|
+
idCache.store(cache);
|
|
3623
|
+
};
|
|
3624
|
+
var tryCacheIdentity = function tryCacheIdentity(knownIdentities, idCache, parseIdentityResponse, mpid, callback, identityApiData, identityMethod) {
|
|
3625
|
+
// https://go.mparticle.com/work/SQDSDKS-6095
|
|
3626
|
+
var shouldReturnCachedIdentity = hasValidCachedIdentity(identityMethod, knownIdentities, idCache);
|
|
3627
|
+
// If Identity is cached, then immediately parse the identity response
|
|
3628
|
+
if (shouldReturnCachedIdentity) {
|
|
3629
|
+
var cachedIdentity = getCachedIdentity(identityMethod, knownIdentities, idCache);
|
|
3630
|
+
parseIdentityResponse(cachedIdentity, mpid, callback, identityApiData, identityMethod, knownIdentities, true);
|
|
3631
|
+
return true;
|
|
3632
|
+
}
|
|
3633
|
+
return false;
|
|
3634
|
+
};
|
|
3635
|
+
var getExpireTimestamp = function getExpireTimestamp(maxAge) {
|
|
3636
|
+
if (maxAge === void 0) {
|
|
3637
|
+
maxAge = ONE_DAY_IN_SECONDS;
|
|
3638
|
+
}
|
|
3639
|
+
return new Date().getTime() + maxAge * MILLIS_IN_ONE_SEC;
|
|
3640
|
+
};
|
|
3641
|
+
var parseIdentityResponse = function parseIdentityResponse(responseText) {
|
|
3642
|
+
return responseText ? JSON.parse(responseText) : {};
|
|
3643
|
+
};
|
|
3644
|
+
var hasIdentityRequestChanged = function hasIdentityRequestChanged(currentUser, newIdentityRequest) {
|
|
3645
|
+
if (!currentUser || !(newIdentityRequest === null || newIdentityRequest === void 0 ? void 0 : newIdentityRequest.userIdentities)) {
|
|
3646
|
+
return false;
|
|
3647
|
+
}
|
|
3648
|
+
var currentUserIdentities = currentUser.getUserIdentities().userIdentities;
|
|
3649
|
+
var newIdentities = newIdentityRequest.userIdentities;
|
|
3650
|
+
return JSON.stringify(currentUserIdentities) !== JSON.stringify(newIdentities);
|
|
3651
|
+
};
|
|
3652
|
+
|
|
3476
3653
|
var Messages$6 = Constants.Messages;
|
|
3477
3654
|
function SessionManager(mpInstance) {
|
|
3478
3655
|
var self = this;
|
|
@@ -3484,9 +3661,10 @@ var mParticle = (function () {
|
|
|
3484
3661
|
self.startNewSession();
|
|
3485
3662
|
} else {
|
|
3486
3663
|
// https://go.mparticle.com/work/SQDSDKS-6045
|
|
3487
|
-
|
|
3488
|
-
|
|
3489
|
-
|
|
3664
|
+
// https://go.mparticle.com/work/SQDSDKS-6323
|
|
3665
|
+
var currentUser = mpInstance.Identity.getCurrentUser();
|
|
3666
|
+
var sdkIdentityRequest = mpInstance._Store.SDKConfig.identifyRequest;
|
|
3667
|
+
if (hasIdentityRequestChanged(currentUser, sdkIdentityRequest)) {
|
|
3490
3668
|
mpInstance.Identity.identify(mpInstance._Store.SDKConfig.identifyRequest, mpInstance._Store.SDKConfig.identityCallback);
|
|
3491
3669
|
mpInstance._Store.identifyCalled = true;
|
|
3492
3670
|
mpInstance._Store.SDKConfig.identityCallback = null;
|
|
@@ -6158,10 +6336,10 @@ var mParticle = (function () {
|
|
|
6158
6336
|
}
|
|
6159
6337
|
|
|
6160
6338
|
var _Constants$IdentityMe = Constants.IdentityMethods,
|
|
6161
|
-
Modify$
|
|
6162
|
-
Identify$
|
|
6163
|
-
Login$
|
|
6164
|
-
Logout$
|
|
6339
|
+
Modify$2 = _Constants$IdentityMe.Modify,
|
|
6340
|
+
Identify$1 = _Constants$IdentityMe.Identify,
|
|
6341
|
+
Login$1 = _Constants$IdentityMe.Login,
|
|
6342
|
+
Logout$1 = _Constants$IdentityMe.Logout;
|
|
6165
6343
|
function Forwarders(mpInstance, kitBlocker) {
|
|
6166
6344
|
var _this = this;
|
|
6167
6345
|
var self = this;
|
|
@@ -6425,28 +6603,28 @@ var mParticle = (function () {
|
|
|
6425
6603
|
mpInstance._Store.activeForwarders.forEach(function (forwarder) {
|
|
6426
6604
|
var filteredUser = filteredMparticleUser(user.getMPID(), forwarder, mpInstance, kitBlocker);
|
|
6427
6605
|
var filteredUserIdentities = filteredUser.getUserIdentities();
|
|
6428
|
-
if (identityMethod === Identify$
|
|
6606
|
+
if (identityMethod === Identify$1) {
|
|
6429
6607
|
if (forwarder.onIdentifyComplete) {
|
|
6430
6608
|
result = forwarder.onIdentifyComplete(filteredUser, filteredUserIdentities);
|
|
6431
6609
|
if (result) {
|
|
6432
6610
|
mpInstance.Logger.verbose(result);
|
|
6433
6611
|
}
|
|
6434
6612
|
}
|
|
6435
|
-
} else if (identityMethod === Login$
|
|
6613
|
+
} else if (identityMethod === Login$1) {
|
|
6436
6614
|
if (forwarder.onLoginComplete) {
|
|
6437
6615
|
result = forwarder.onLoginComplete(filteredUser, filteredUserIdentities);
|
|
6438
6616
|
if (result) {
|
|
6439
6617
|
mpInstance.Logger.verbose(result);
|
|
6440
6618
|
}
|
|
6441
6619
|
}
|
|
6442
|
-
} else if (identityMethod === Logout$
|
|
6620
|
+
} else if (identityMethod === Logout$1) {
|
|
6443
6621
|
if (forwarder.onLogoutComplete) {
|
|
6444
6622
|
result = forwarder.onLogoutComplete(filteredUser, filteredUserIdentities);
|
|
6445
6623
|
if (result) {
|
|
6446
6624
|
mpInstance.Logger.verbose(result);
|
|
6447
6625
|
}
|
|
6448
6626
|
}
|
|
6449
|
-
} else if (identityMethod === Modify$
|
|
6627
|
+
} else if (identityMethod === Modify$2) {
|
|
6450
6628
|
if (forwarder.onModifyComplete) {
|
|
6451
6629
|
result = forwarder.onModifyComplete(filteredUser, filteredUserIdentities);
|
|
6452
6630
|
if (result) {
|
|
@@ -6999,156 +7177,6 @@ var mParticle = (function () {
|
|
|
6999
7177
|
}
|
|
7000
7178
|
}
|
|
7001
7179
|
|
|
7002
|
-
var _a = Constants.IdentityMethods,
|
|
7003
|
-
Identify$1 = _a.Identify,
|
|
7004
|
-
Modify$2 = _a.Modify,
|
|
7005
|
-
Login$1 = _a.Login,
|
|
7006
|
-
Logout$1 = _a.Logout;
|
|
7007
|
-
var CACHE_HEADER = 'x-mp-max-age';
|
|
7008
|
-
var cacheOrClearIdCache = function cacheOrClearIdCache(method, knownIdentities, idCache, identityResponse, parsingCachedResponse) {
|
|
7009
|
-
// when parsing a response that has already been cached, simply return instead of attempting another cache
|
|
7010
|
-
if (parsingCachedResponse) {
|
|
7011
|
-
return;
|
|
7012
|
-
}
|
|
7013
|
-
// default the expire timestamp to one day in milliseconds unless a header comes back
|
|
7014
|
-
var expireTimestamp = getExpireTimestamp(identityResponse === null || identityResponse === void 0 ? void 0 : identityResponse.cacheMaxAge);
|
|
7015
|
-
switch (method) {
|
|
7016
|
-
case Login$1:
|
|
7017
|
-
case Identify$1:
|
|
7018
|
-
cacheIdentityRequest(method, knownIdentities, expireTimestamp, idCache, identityResponse);
|
|
7019
|
-
break;
|
|
7020
|
-
case Modify$2:
|
|
7021
|
-
case Logout$1:
|
|
7022
|
-
idCache.purge();
|
|
7023
|
-
break;
|
|
7024
|
-
}
|
|
7025
|
-
};
|
|
7026
|
-
var cacheIdentityRequest = function cacheIdentityRequest(method, identities, expireTimestamp, idCache, identityResponse) {
|
|
7027
|
-
var responseText = identityResponse.responseText,
|
|
7028
|
-
status = identityResponse.status;
|
|
7029
|
-
var cache = idCache.retrieve() || {};
|
|
7030
|
-
var cacheKey = concatenateIdentities(method, identities);
|
|
7031
|
-
var hashedKey = generateHash(cacheKey);
|
|
7032
|
-
var mpid = responseText.mpid,
|
|
7033
|
-
is_logged_in = responseText.is_logged_in;
|
|
7034
|
-
var cachedResponseBody = {
|
|
7035
|
-
mpid: mpid,
|
|
7036
|
-
is_logged_in: is_logged_in
|
|
7037
|
-
};
|
|
7038
|
-
cache[hashedKey] = {
|
|
7039
|
-
responseText: JSON.stringify(cachedResponseBody),
|
|
7040
|
-
status: status,
|
|
7041
|
-
expireTimestamp: expireTimestamp
|
|
7042
|
-
};
|
|
7043
|
-
idCache.store(cache);
|
|
7044
|
-
};
|
|
7045
|
-
// We need to ensure that identities are concatenated in a deterministic way, so
|
|
7046
|
-
// we sort the identities based on their enum.
|
|
7047
|
-
// we create an array, set the user identity at the index of the user identity type
|
|
7048
|
-
var concatenateIdentities = function concatenateIdentities(method, userIdentities) {
|
|
7049
|
-
var DEVICE_APPLICATION_STAMP = 'device_application_stamp';
|
|
7050
|
-
// set DAS first since it is not an official identity type
|
|
7051
|
-
var cacheKey = "".concat(method, ":").concat(DEVICE_APPLICATION_STAMP, "=").concat(userIdentities.device_application_stamp, ";");
|
|
7052
|
-
var idLength = Object.keys(userIdentities).length;
|
|
7053
|
-
var concatenatedIdentities = '';
|
|
7054
|
-
if (idLength) {
|
|
7055
|
-
var userIDArray = new Array();
|
|
7056
|
-
// create an array where each index is equal to the user identity type
|
|
7057
|
-
for (var key in userIdentities) {
|
|
7058
|
-
if (key === DEVICE_APPLICATION_STAMP) {
|
|
7059
|
-
continue;
|
|
7060
|
-
} else {
|
|
7061
|
-
userIDArray[Types.IdentityType.getIdentityType(key)] = userIdentities[key];
|
|
7062
|
-
}
|
|
7063
|
-
}
|
|
7064
|
-
concatenatedIdentities = userIDArray.reduce(function (prevValue, currentValue, index) {
|
|
7065
|
-
var idName = Types.IdentityType.getIdentityName(index);
|
|
7066
|
-
return "".concat(prevValue).concat(idName, "=").concat(currentValue, ";");
|
|
7067
|
-
}, cacheKey);
|
|
7068
|
-
}
|
|
7069
|
-
return concatenatedIdentities;
|
|
7070
|
-
};
|
|
7071
|
-
var hasValidCachedIdentity = function hasValidCachedIdentity(method, proposedUserIdentities, idCache) {
|
|
7072
|
-
// There is an edge case where multiple identity calls are taking place
|
|
7073
|
-
// before identify fires, so there may not be a cache. See what happens when
|
|
7074
|
-
// the ? in idCache is removed to the following test
|
|
7075
|
-
// "queued events contain login mpid instead of identify mpid when calling
|
|
7076
|
-
// login immediately after mParticle initializes"
|
|
7077
|
-
var cache = idCache === null || idCache === void 0 ? void 0 : idCache.retrieve();
|
|
7078
|
-
// if there is no cache, then there is no valid cached identity
|
|
7079
|
-
if (!cache) {
|
|
7080
|
-
return false;
|
|
7081
|
-
}
|
|
7082
|
-
var cacheKey = concatenateIdentities(method, proposedUserIdentities);
|
|
7083
|
-
var hashedKey = generateHash(cacheKey);
|
|
7084
|
-
// if cache doesn't have the cacheKey, there is no valid cached identity
|
|
7085
|
-
if (!cache.hasOwnProperty(hashedKey)) {
|
|
7086
|
-
return false;
|
|
7087
|
-
}
|
|
7088
|
-
// If there is a valid cache key, compare the expireTimestamp to the current time.
|
|
7089
|
-
// If the current time is greater than the expireTimestamp, it is not a valid
|
|
7090
|
-
// cached identity.
|
|
7091
|
-
var expireTimestamp = cache[hashedKey].expireTimestamp;
|
|
7092
|
-
if (expireTimestamp < new Date().getTime()) {
|
|
7093
|
-
return false;
|
|
7094
|
-
} else {
|
|
7095
|
-
return true;
|
|
7096
|
-
}
|
|
7097
|
-
};
|
|
7098
|
-
var getCachedIdentity = function getCachedIdentity(method, proposedUserIdentities, idCache) {
|
|
7099
|
-
var cacheKey = concatenateIdentities(method, proposedUserIdentities);
|
|
7100
|
-
var hashedKey = generateHash(cacheKey);
|
|
7101
|
-
var cache = idCache.retrieve();
|
|
7102
|
-
var cachedIdentity = cache ? cache[hashedKey] : null;
|
|
7103
|
-
return {
|
|
7104
|
-
responseText: parseIdentityResponse(cachedIdentity.responseText),
|
|
7105
|
-
expireTimestamp: cachedIdentity.expireTimestamp,
|
|
7106
|
-
status: cachedIdentity.status
|
|
7107
|
-
};
|
|
7108
|
-
};
|
|
7109
|
-
// https://go.mparticle.com/work/SQDSDKS-6079
|
|
7110
|
-
var createKnownIdentities = function createKnownIdentities(identityApiData, deviceId) {
|
|
7111
|
-
var identitiesResult = {};
|
|
7112
|
-
if (isObject(identityApiData === null || identityApiData === void 0 ? void 0 : identityApiData.userIdentities)) {
|
|
7113
|
-
for (var identity in identityApiData.userIdentities) {
|
|
7114
|
-
identitiesResult[identity] = identityApiData.userIdentities[identity];
|
|
7115
|
-
}
|
|
7116
|
-
}
|
|
7117
|
-
identitiesResult.device_application_stamp = deviceId;
|
|
7118
|
-
return identitiesResult;
|
|
7119
|
-
};
|
|
7120
|
-
var removeExpiredIdentityCacheDates = function removeExpiredIdentityCacheDates(idCache) {
|
|
7121
|
-
var cache = idCache.retrieve() || {};
|
|
7122
|
-
var currentTime = new Date().getTime();
|
|
7123
|
-
// Iterate over the cache and remove any key/value pairs that are expired
|
|
7124
|
-
for (var key in cache) {
|
|
7125
|
-
if (cache[key].expireTimestamp < currentTime) {
|
|
7126
|
-
delete cache[key];
|
|
7127
|
-
}
|
|
7128
|
-
}
|
|
7129
|
-
idCache.store(cache);
|
|
7130
|
-
};
|
|
7131
|
-
var tryCacheIdentity = function tryCacheIdentity(knownIdentities, idCache, parseIdentityResponse, mpid, callback, identityApiData, identityMethod) {
|
|
7132
|
-
// https://go.mparticle.com/work/SQDSDKS-6095
|
|
7133
|
-
var shouldReturnCachedIdentity = hasValidCachedIdentity(identityMethod, knownIdentities, idCache);
|
|
7134
|
-
// If Identity is cached, then immediately parse the identity response
|
|
7135
|
-
if (shouldReturnCachedIdentity) {
|
|
7136
|
-
var cachedIdentity = getCachedIdentity(identityMethod, knownIdentities, idCache);
|
|
7137
|
-
parseIdentityResponse(cachedIdentity, mpid, callback, identityApiData, identityMethod, knownIdentities, true);
|
|
7138
|
-
return true;
|
|
7139
|
-
}
|
|
7140
|
-
return false;
|
|
7141
|
-
};
|
|
7142
|
-
var getExpireTimestamp = function getExpireTimestamp(maxAge) {
|
|
7143
|
-
if (maxAge === void 0) {
|
|
7144
|
-
maxAge = ONE_DAY_IN_SECONDS;
|
|
7145
|
-
}
|
|
7146
|
-
return new Date().getTime() + maxAge * MILLIS_IN_ONE_SEC;
|
|
7147
|
-
};
|
|
7148
|
-
var parseIdentityResponse = function parseIdentityResponse(responseText) {
|
|
7149
|
-
return responseText ? JSON.parse(responseText) : {};
|
|
7150
|
-
};
|
|
7151
|
-
|
|
7152
7180
|
var AudienceManager = /** @class */function () {
|
|
7153
7181
|
function AudienceManager(userAudienceUrl, apiKey, logger) {
|
|
7154
7182
|
this.url = '';
|
|
@@ -7275,7 +7303,10 @@ var mParticle = (function () {
|
|
|
7275
7303
|
this.IdentityRequest = {
|
|
7276
7304
|
preProcessIdentityRequest: function preProcessIdentityRequest(identityApiData, callback, method) {
|
|
7277
7305
|
mpInstance.Logger.verbose(Messages$2.InformationMessages.StartingLogEvent + ': ' + method);
|
|
7278
|
-
|
|
7306
|
+
|
|
7307
|
+
// First, remove any falsy identity values and warn about them
|
|
7308
|
+
var cleanedIdentityApiData = mpInstance._Helpers.Validators.removeFalsyIdentityValues(identityApiData, mpInstance.Logger);
|
|
7309
|
+
var identityValidationResult = mpInstance._Helpers.Validators.validateIdentities(cleanedIdentityApiData, method);
|
|
7279
7310
|
if (!identityValidationResult.valid) {
|
|
7280
7311
|
mpInstance.Logger.error('ERROR: ' + identityValidationResult.error);
|
|
7281
7312
|
return {
|
|
@@ -7292,7 +7323,8 @@ var mParticle = (function () {
|
|
|
7292
7323
|
};
|
|
7293
7324
|
}
|
|
7294
7325
|
return {
|
|
7295
|
-
valid: true
|
|
7326
|
+
valid: true,
|
|
7327
|
+
cleanedIdentities: cleanedIdentityApiData
|
|
7296
7328
|
};
|
|
7297
7329
|
},
|
|
7298
7330
|
createIdentityRequest: function createIdentityRequest(identityApiData, platform, sdkVendor, sdkVersion, deviceId, context, mpid) {
|
|
@@ -7415,7 +7447,7 @@ var mParticle = (function () {
|
|
|
7415
7447
|
mpid = currentUser.getMPID();
|
|
7416
7448
|
}
|
|
7417
7449
|
if (preProcessResult.valid) {
|
|
7418
|
-
var identityApiRequest = mpInstance._Identity.IdentityRequest.createIdentityRequest(
|
|
7450
|
+
var identityApiRequest = mpInstance._Identity.IdentityRequest.createIdentityRequest(preProcessResult.cleanedIdentities, Constants.platform, Constants.sdkVendor, Constants.sdkVersion, mpInstance._Store.deviceId, mpInstance._Store.context, mpid);
|
|
7419
7451
|
if (mpInstance._Helpers.getFeatureFlag(Constants.FeatureFlags.CacheIdentity)) {
|
|
7420
7452
|
var successfullyCachedIdentity = tryCacheIdentity(identityApiRequest.known_identities, self.idCache, self.parseIdentityResponse, mpid, callback, identityApiData, Identify);
|
|
7421
7453
|
if (successfullyCachedIdentity) {
|
|
@@ -7454,7 +7486,7 @@ var mParticle = (function () {
|
|
|
7454
7486
|
}
|
|
7455
7487
|
if (preProcessResult.valid) {
|
|
7456
7488
|
var evt,
|
|
7457
|
-
identityApiRequest = mpInstance._Identity.IdentityRequest.createIdentityRequest(
|
|
7489
|
+
identityApiRequest = mpInstance._Identity.IdentityRequest.createIdentityRequest(preProcessResult.cleanedIdentities, Constants.platform, Constants.sdkVendor, Constants.sdkVersion, mpInstance._Store.deviceId, mpInstance._Store.context, mpid);
|
|
7458
7490
|
if (mpInstance._Helpers.canLog()) {
|
|
7459
7491
|
if (mpInstance._Store.webviewBridgeEnabled) {
|
|
7460
7492
|
mpInstance._NativeSdkHelpers.sendToNative(Constants.NativeSdkPaths.Logout, JSON.stringify(mpInstance._Identity.IdentityRequest.convertToNative(identityApiData)));
|
|
@@ -7497,7 +7529,7 @@ var mParticle = (function () {
|
|
|
7497
7529
|
mpid = currentUser.getMPID();
|
|
7498
7530
|
}
|
|
7499
7531
|
if (preProcessResult.valid) {
|
|
7500
|
-
var identityApiRequest = mpInstance._Identity.IdentityRequest.createIdentityRequest(
|
|
7532
|
+
var identityApiRequest = mpInstance._Identity.IdentityRequest.createIdentityRequest(preProcessResult.cleanedIdentities, Constants.platform, Constants.sdkVendor, Constants.sdkVersion, mpInstance._Store.deviceId, mpInstance._Store.context, mpid);
|
|
7501
7533
|
if (mpInstance._Helpers.getFeatureFlag(Constants.FeatureFlags.CacheIdentity)) {
|
|
7502
7534
|
var successfullyCachedIdentity = tryCacheIdentity(identityApiRequest.known_identities, self.idCache, self.parseIdentityResponse, mpid, callback, identityApiData, Login);
|
|
7503
7535
|
if (successfullyCachedIdentity) {
|
|
@@ -7534,8 +7566,8 @@ var mParticle = (function () {
|
|
|
7534
7566
|
if (currentUser) {
|
|
7535
7567
|
mpid = currentUser.getMPID();
|
|
7536
7568
|
}
|
|
7537
|
-
var newUserIdentities = identityApiData && identityApiData.userIdentities ? identityApiData.userIdentities : {};
|
|
7538
7569
|
if (preProcessResult.valid) {
|
|
7570
|
+
var newUserIdentities = identityApiData && identityApiData.userIdentities ? preProcessResult.cleanedIdentities.userIdentities : {};
|
|
7539
7571
|
var identityApiRequest = mpInstance._Identity.IdentityRequest.createModifyIdentityRequest(currentUser ? currentUser.getUserIdentities().userIdentities : {}, newUserIdentities, Constants.platform, Constants.sdkVendor, Constants.sdkVersion, mpInstance._Store.context);
|
|
7540
7572
|
if (mpInstance._Helpers.canLog()) {
|
|
7541
7573
|
if (mpInstance._Store.webviewBridgeEnabled) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mparticle/web-sdk",
|
|
3
|
-
"version": "2.43.
|
|
3
|
+
"version": "2.43.1",
|
|
4
4
|
"description": "mParticle core SDK for web applications",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"keywords": [
|
|
@@ -28,7 +28,9 @@
|
|
|
28
28
|
"build:npm": "cross-env ENVIRONMENT=prod BUILD=cjs rollup --config rollup.config.js",
|
|
29
29
|
"build:esm": "cross-env ENVIRONMENT=prod BUILD=esm rollup --config rollup.config.js",
|
|
30
30
|
"build:stub": "cross-env ENVIRONMENT=prod BUILD=stub rollup --config rollup.config.js",
|
|
31
|
-
"build:snippet": "
|
|
31
|
+
"build:snippet": "npm run build:snippet:mp && npm run build:snippet:rokt",
|
|
32
|
+
"build:snippet:mp": "uglifyjs snippet.js -m -o snippet.min.js",
|
|
33
|
+
"build:snippet:rokt": "uglifyjs snippet.rokt.js -m -o snippet.rokt.min.js",
|
|
32
34
|
"build:tests": "cross-env ENVIRONMENT=prod TESTTYPE=main rollup --config rollup.test.config.js",
|
|
33
35
|
"build:test-bundle": "cross-env TESTTYPE=main ENVIRONMENT=prod rollup --config rollup.test.config.js",
|
|
34
36
|
"build:browserify:cjs": "browserify test/integrations/cjs/browserify/index.js -o test/integrations/cjs/dist/browserify-output.js",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AllUserAttributes, MPID,
|
|
1
|
+
import { AllUserAttributes, MPID, User } from '@mparticle/web-sdk';
|
|
2
2
|
import { SDKIdentityTypeEnum } from './identity.interfaces';
|
|
3
3
|
import { MessageType } from './types';
|
|
4
4
|
import { BaseEvent, SDKProduct } from './sdkRuntimeModels';
|
package/src/identity-utils.ts
CHANGED
|
@@ -7,10 +7,11 @@ import {
|
|
|
7
7
|
UserIdentities,
|
|
8
8
|
IdentityCallback,
|
|
9
9
|
} from '@mparticle/web-sdk';
|
|
10
|
-
import { IdentityAPIMethod } from './identity.interfaces';
|
|
10
|
+
import { IdentityAPIMethod, IIdentityRequest } from './identity.interfaces';
|
|
11
11
|
import {
|
|
12
12
|
IdentityResultBody,
|
|
13
13
|
IIdentityResponse,
|
|
14
|
+
IMParticleUser,
|
|
14
15
|
} from './identity-user-interfaces';
|
|
15
16
|
|
|
16
17
|
const { Identify, Modify, Login, Logout } = Constants.IdentityMethods;
|
|
@@ -279,3 +280,21 @@ const getExpireTimestamp = (maxAge: number = ONE_DAY_IN_SECONDS): number =>
|
|
|
279
280
|
|
|
280
281
|
const parseIdentityResponse = (responseText: string): IdentityResultBody =>
|
|
281
282
|
responseText ? JSON.parse(responseText) : ({} as IdentityResultBody);
|
|
283
|
+
|
|
284
|
+
export const hasIdentityRequestChanged = (
|
|
285
|
+
currentUser: IMParticleUser,
|
|
286
|
+
newIdentityRequest: IdentityApiData
|
|
287
|
+
): boolean => {
|
|
288
|
+
if (!currentUser || !newIdentityRequest?.userIdentities) {
|
|
289
|
+
return false;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
const currentUserIdentities =
|
|
293
|
+
currentUser.getUserIdentities().userIdentities;
|
|
294
|
+
|
|
295
|
+
const newIdentities = newIdentityRequest.userIdentities;
|
|
296
|
+
|
|
297
|
+
return (
|
|
298
|
+
JSON.stringify(currentUserIdentities) !== JSON.stringify(newIdentities)
|
|
299
|
+
);
|
|
300
|
+
};
|
package/src/identity.js
CHANGED
|
@@ -33,8 +33,14 @@ export default function Identity(mpInstance) {
|
|
|
33
33
|
Messages.InformationMessages.StartingLogEvent + ': ' + method
|
|
34
34
|
);
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
// First, remove any falsy identity values and warn about them
|
|
37
|
+
const cleanedIdentityApiData = mpInstance._Helpers.Validators.removeFalsyIdentityValues(
|
|
37
38
|
identityApiData,
|
|
39
|
+
mpInstance.Logger
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
var identityValidationResult = mpInstance._Helpers.Validators.validateIdentities(
|
|
43
|
+
cleanedIdentityApiData,
|
|
38
44
|
method
|
|
39
45
|
);
|
|
40
46
|
|
|
@@ -64,6 +70,7 @@ export default function Identity(mpInstance) {
|
|
|
64
70
|
|
|
65
71
|
return {
|
|
66
72
|
valid: true,
|
|
73
|
+
cleanedIdentities: cleanedIdentityApiData,
|
|
67
74
|
};
|
|
68
75
|
},
|
|
69
76
|
|
|
@@ -237,7 +244,7 @@ export default function Identity(mpInstance) {
|
|
|
237
244
|
|
|
238
245
|
if (preProcessResult.valid) {
|
|
239
246
|
var identityApiRequest = mpInstance._Identity.IdentityRequest.createIdentityRequest(
|
|
240
|
-
|
|
247
|
+
preProcessResult.cleanedIdentities,
|
|
241
248
|
Constants.platform,
|
|
242
249
|
Constants.sdkVendor,
|
|
243
250
|
Constants.sdkVersion,
|
|
@@ -332,7 +339,7 @@ export default function Identity(mpInstance) {
|
|
|
332
339
|
if (preProcessResult.valid) {
|
|
333
340
|
var evt,
|
|
334
341
|
identityApiRequest = mpInstance._Identity.IdentityRequest.createIdentityRequest(
|
|
335
|
-
|
|
342
|
+
preProcessResult.cleanedIdentities,
|
|
336
343
|
Constants.platform,
|
|
337
344
|
Constants.sdkVendor,
|
|
338
345
|
Constants.sdkVersion,
|
|
@@ -422,7 +429,7 @@ export default function Identity(mpInstance) {
|
|
|
422
429
|
|
|
423
430
|
if (preProcessResult.valid) {
|
|
424
431
|
var identityApiRequest = mpInstance._Identity.IdentityRequest.createIdentityRequest(
|
|
425
|
-
|
|
432
|
+
preProcessResult.cleanedIdentities,
|
|
426
433
|
Constants.platform,
|
|
427
434
|
Constants.sdkVendor,
|
|
428
435
|
Constants.sdkVersion,
|
|
@@ -514,11 +521,11 @@ export default function Identity(mpInstance) {
|
|
|
514
521
|
if (currentUser) {
|
|
515
522
|
mpid = currentUser.getMPID();
|
|
516
523
|
}
|
|
517
|
-
var newUserIdentities =
|
|
518
|
-
identityApiData && identityApiData.userIdentities
|
|
519
|
-
? identityApiData.userIdentities
|
|
520
|
-
: {};
|
|
521
524
|
if (preProcessResult.valid) {
|
|
525
|
+
var newUserIdentities =
|
|
526
|
+
identityApiData && identityApiData.userIdentities
|
|
527
|
+
? preProcessResult.cleanedIdentities.userIdentities
|
|
528
|
+
: {};
|
|
522
529
|
var identityApiRequest = mpInstance._Identity.IdentityRequest.createModifyIdentityRequest(
|
|
523
530
|
currentUser
|
|
524
531
|
? currentUser.getUserIdentities().userIdentities
|
package/src/sessionManager.ts
CHANGED
|
@@ -5,6 +5,7 @@ import Types from './types';
|
|
|
5
5
|
import { generateDeprecationMessage } from './utils';
|
|
6
6
|
import { IMParticleUser } from './identity-user-interfaces';
|
|
7
7
|
import { IMParticleWebSDKInstance } from './mp-instance';
|
|
8
|
+
import { hasIdentityRequestChanged } from './identity-utils';
|
|
8
9
|
|
|
9
10
|
const { Messages } = Constants;
|
|
10
11
|
|
|
@@ -30,7 +31,7 @@ export default function SessionManager(
|
|
|
30
31
|
) {
|
|
31
32
|
const self = this;
|
|
32
33
|
|
|
33
|
-
this.initialize = function(): void {
|
|
34
|
+
this.initialize = function (): void {
|
|
34
35
|
if (mpInstance._Store.sessionId) {
|
|
35
36
|
const sessionTimeoutInMilliseconds: number =
|
|
36
37
|
mpInstance._Store.SDKConfig.sessionTimeout * 60000;
|
|
@@ -46,9 +47,14 @@ export default function SessionManager(
|
|
|
46
47
|
self.startNewSession();
|
|
47
48
|
} else {
|
|
48
49
|
// https://go.mparticle.com/work/SQDSDKS-6045
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
// https://go.mparticle.com/work/SQDSDKS-6323
|
|
51
|
+
const currentUser = mpInstance.Identity.getCurrentUser();
|
|
52
|
+
const sdkIdentityRequest =
|
|
53
|
+
mpInstance._Store.SDKConfig.identifyRequest;
|
|
54
|
+
|
|
55
|
+
if (
|
|
56
|
+
hasIdentityRequestChanged(currentUser, sdkIdentityRequest)
|
|
57
|
+
) {
|
|
52
58
|
mpInstance.Identity.identify(
|
|
53
59
|
mpInstance._Store.SDKConfig.identifyRequest,
|
|
54
60
|
mpInstance._Store.SDKConfig.identityCallback
|
|
@@ -62,7 +68,7 @@ export default function SessionManager(
|
|
|
62
68
|
}
|
|
63
69
|
};
|
|
64
70
|
|
|
65
|
-
this.getSession = function(): string {
|
|
71
|
+
this.getSession = function (): string {
|
|
66
72
|
mpInstance.Logger.warning(
|
|
67
73
|
generateDeprecationMessage(
|
|
68
74
|
'SessionManager.getSession()',
|
|
@@ -73,11 +79,11 @@ export default function SessionManager(
|
|
|
73
79
|
return this.getSessionId();
|
|
74
80
|
};
|
|
75
81
|
|
|
76
|
-
this.getSessionId = function(): string {
|
|
82
|
+
this.getSessionId = function (): string {
|
|
77
83
|
return mpInstance._Store.sessionId;
|
|
78
84
|
};
|
|
79
85
|
|
|
80
|
-
this.startNewSession = function(): void {
|
|
86
|
+
this.startNewSession = function (): void {
|
|
81
87
|
mpInstance.Logger.verbose(
|
|
82
88
|
Messages.InformationMessages.StartingNewSession
|
|
83
89
|
);
|
|
@@ -87,7 +93,8 @@ export default function SessionManager(
|
|
|
87
93
|
.generateUniqueId()
|
|
88
94
|
.toUpperCase();
|
|
89
95
|
|
|
90
|
-
const currentUser: IMParticleUser =
|
|
96
|
+
const currentUser: IMParticleUser =
|
|
97
|
+
mpInstance.Identity.getCurrentUser();
|
|
91
98
|
const mpid: MPID = currentUser ? currentUser.getMPID() : null;
|
|
92
99
|
|
|
93
100
|
if (mpid) {
|
|
@@ -121,7 +128,7 @@ export default function SessionManager(
|
|
|
121
128
|
}
|
|
122
129
|
};
|
|
123
130
|
|
|
124
|
-
this.endSession = function(override: boolean): void {
|
|
131
|
+
this.endSession = function (override: boolean): void {
|
|
125
132
|
mpInstance.Logger.verbose(
|
|
126
133
|
Messages.InformationMessages.StartingEndSession
|
|
127
134
|
);
|
|
@@ -152,9 +159,10 @@ export default function SessionManager(
|
|
|
152
159
|
let sessionTimeoutInMilliseconds: number;
|
|
153
160
|
let timeSinceLastEventSent: number;
|
|
154
161
|
|
|
155
|
-
const cookies: IPersistenceMinified =
|
|
162
|
+
const cookies: IPersistenceMinified =
|
|
163
|
+
mpInstance._Persistence.getPersistence();
|
|
156
164
|
|
|
157
|
-
if (!cookies || cookies.gs && !cookies.gs.sid) {
|
|
165
|
+
if (!cookies || (cookies.gs && !cookies.gs.sid)) {
|
|
158
166
|
mpInstance.Logger.verbose(
|
|
159
167
|
Messages.InformationMessages.NoSessionToEnd
|
|
160
168
|
);
|
|
@@ -189,16 +197,16 @@ export default function SessionManager(
|
|
|
189
197
|
mpInstance._timeOnSiteTimer?.resetTimer();
|
|
190
198
|
};
|
|
191
199
|
|
|
192
|
-
this.setSessionTimer = function(): void {
|
|
200
|
+
this.setSessionTimer = function (): void {
|
|
193
201
|
const sessionTimeoutInMilliseconds: number =
|
|
194
202
|
mpInstance._Store.SDKConfig.sessionTimeout * 60000;
|
|
195
203
|
|
|
196
|
-
mpInstance._Store.globalTimer = window.setTimeout(function() {
|
|
204
|
+
mpInstance._Store.globalTimer = window.setTimeout(function () {
|
|
197
205
|
self.endSession();
|
|
198
206
|
}, sessionTimeoutInMilliseconds);
|
|
199
207
|
};
|
|
200
208
|
|
|
201
|
-
this.resetSessionTimer = function(): void {
|
|
209
|
+
this.resetSessionTimer = function (): void {
|
|
202
210
|
if (!mpInstance._Store.webviewBridgeEnabled) {
|
|
203
211
|
if (!mpInstance._Store.sessionId) {
|
|
204
212
|
self.startNewSession();
|
|
@@ -209,7 +217,7 @@ export default function SessionManager(
|
|
|
209
217
|
self.startNewSessionIfNeeded();
|
|
210
218
|
};
|
|
211
219
|
|
|
212
|
-
this.clearSessionTimeout = function(): void {
|
|
220
|
+
this.clearSessionTimeout = function (): void {
|
|
213
221
|
clearTimeout(mpInstance._Store.globalTimer);
|
|
214
222
|
};
|
|
215
223
|
|
package/src/validators.ts
CHANGED
|
@@ -40,7 +40,37 @@ const Validators = {
|
|
|
40
40
|
);
|
|
41
41
|
},
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
removeFalsyIdentityValues: function (
|
|
44
|
+
identityApiData: IdentityApiData,
|
|
45
|
+
logger: any
|
|
46
|
+
): IdentityApiData {
|
|
47
|
+
if (!identityApiData || !identityApiData.userIdentities) {
|
|
48
|
+
return identityApiData;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const cleanedData = {} as IdentityApiData;
|
|
52
|
+
const cleanedUserIdentities = { ...identityApiData.userIdentities };
|
|
53
|
+
|
|
54
|
+
for (const identityType in identityApiData.userIdentities) {
|
|
55
|
+
if (identityApiData.userIdentities.hasOwnProperty(identityType)) {
|
|
56
|
+
const value = identityApiData.userIdentities[identityType];
|
|
57
|
+
|
|
58
|
+
// Check if value is falsy (undefined, false, 0, '', etc.) but not null
|
|
59
|
+
if (value !== null && !value) {
|
|
60
|
+
logger.warning(
|
|
61
|
+
`Identity value for '${identityType}' is falsy (${value}). This value will be removed from the request.`
|
|
62
|
+
);
|
|
63
|
+
delete cleanedUserIdentities[identityType];
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
cleanedData.userIdentities = cleanedUserIdentities;
|
|
69
|
+
|
|
70
|
+
return cleanedData;
|
|
71
|
+
},
|
|
72
|
+
|
|
73
|
+
validateIdentities: function (
|
|
44
74
|
identityApiData: IdentityApiData,
|
|
45
75
|
method?: IdentityAPIMethod
|
|
46
76
|
): ValidationIdentitiesReturn {
|