@mparticle/web-sdk 2.57.0 → 2.59.0

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.js CHANGED
@@ -203,7 +203,7 @@ var mParticle = (function () {
203
203
  Base64: Base64$1
204
204
  };
205
205
 
206
- var version = "2.57.0";
206
+ var version = "2.59.0";
207
207
 
208
208
  var Constants = {
209
209
  sdkVersion: version,
@@ -328,7 +328,9 @@ var mParticle = (function () {
328
328
  configUrl: 'jssdkcdns.mparticle.com/JS/v2/',
329
329
  identityUrl: 'identity.mparticle.com/v1/',
330
330
  aliasUrl: 'jssdks.mparticle.com/v1/identity/',
331
- userAudienceUrl: 'nativesdks.mparticle.com/v1/'
331
+ userAudienceUrl: 'nativesdks.mparticle.com/v1/',
332
+ loggingUrl: 'apps.rokt-api.com/v1/log',
333
+ errorUrl: 'apps.rokt-api.com/v1/errors'
332
334
  },
333
335
  // These are the paths that are used to construct the CNAME urls
334
336
  CNAMEUrlPaths: {
@@ -337,7 +339,9 @@ var mParticle = (function () {
337
339
  v3SecureServiceUrl: '/webevents/v3/JS/',
338
340
  configUrl: '/tags/JS/v2/',
339
341
  identityUrl: '/identity/v1/',
340
- aliasUrl: '/webevents/v1/identity/'
342
+ aliasUrl: '/webevents/v1/identity/',
343
+ loggingUrl: '/v1/log',
344
+ errorUrl: '/v1/errors'
341
345
  },
342
346
  Base64CookieKeys: {
343
347
  csm: 1,
@@ -2208,6 +2212,26 @@ var mParticle = (function () {
2208
2212
  }
2209
2213
  return SessionStorageVault;
2210
2214
  }(BaseVault);
2215
+ // DisabledVault is used when persistence is disabled by privacy flags.
2216
+ var DisabledVault = /** @class */function (_super) {
2217
+ __extends(DisabledVault, _super);
2218
+ function DisabledVault(storageKey, options) {
2219
+ var _this = _super.call(this, storageKey, window.localStorage, options) || this;
2220
+ _this.contents = null;
2221
+ _this.storageObject.removeItem(_this._storageKey);
2222
+ return _this;
2223
+ }
2224
+ DisabledVault.prototype.store = function (_item) {
2225
+ this.contents = null;
2226
+ };
2227
+ DisabledVault.prototype.retrieve = function () {
2228
+ return this.contents;
2229
+ };
2230
+ DisabledVault.prototype.purge = function () {
2231
+ this.contents = null;
2232
+ };
2233
+ return DisabledVault;
2234
+ }(BaseVault);
2211
2235
 
2212
2236
  var AsyncUploader = /** @class */function () {
2213
2237
  function AsyncUploader(url) {
@@ -2370,6 +2394,7 @@ var mParticle = (function () {
2370
2394
  */
2371
2395
  function BatchUploader(mpInstance, uploadInterval) {
2372
2396
  var _a;
2397
+ var _b;
2373
2398
  this.offlineStorageEnabled = false;
2374
2399
  this.lastASTEventTime = 0;
2375
2400
  this.AST_DEBOUNCE_MS = 1000; // 1 second debounce
@@ -2388,7 +2413,9 @@ var mParticle = (function () {
2388
2413
  // Cache Offline Storage Availability boolean
2389
2414
  // so that we don't have to check it every time
2390
2415
  this.offlineStorageEnabled = this.isOfflineStorageAvailable();
2391
- if (this.offlineStorageEnabled) {
2416
+ // When noFunctional is true, prevent events/batches storage
2417
+ var noFunctional = (_b = mpInstance._CookieConsentManager) === null || _b === void 0 ? void 0 : _b.getNoFunctional();
2418
+ if (this.offlineStorageEnabled && !noFunctional) {
2392
2419
  this.eventVault = new SessionStorageVault("".concat(mpInstance._Store.storageName, "-events"), {
2393
2420
  logger: mpInstance.Logger
2394
2421
  });
@@ -2398,9 +2425,9 @@ var mParticle = (function () {
2398
2425
  // Load Events from Session Storage in case we have any in storage
2399
2426
  (_a = this.eventsQueuedForProcessing).push.apply(_a, this.eventVault.retrieve());
2400
2427
  }
2401
- var _b = this.mpInstance._Store,
2402
- SDKConfig = _b.SDKConfig,
2403
- devToken = _b.devToken;
2428
+ var _c = this.mpInstance._Store,
2429
+ SDKConfig = _c.SDKConfig,
2430
+ devToken = _c.devToken;
2404
2431
  var baseUrl = this.mpInstance._Helpers.createServiceUrl(SDKConfig.v3SecureServiceUrl, devToken);
2405
2432
  this.uploadUrl = "".concat(baseUrl, "/events");
2406
2433
  this.uploader = window.fetch ? new FetchUploader(this.uploadUrl) : new XHRUploader(this.uploadUrl);
@@ -2763,6 +2790,181 @@ var mParticle = (function () {
2763
2790
  return BatchUploader;
2764
2791
  }();
2765
2792
 
2793
+ var _a = Constants.IdentityMethods,
2794
+ Identify$2 = _a.Identify,
2795
+ Modify$4 = _a.Modify,
2796
+ Login$2 = _a.Login,
2797
+ Logout$2 = _a.Logout;
2798
+ var CACHE_HEADER = 'x-mp-max-age';
2799
+ var cacheOrClearIdCache = function cacheOrClearIdCache(method, knownIdentities, idCache, identityResponse, parsingCachedResponse) {
2800
+ // when parsing a response that has already been cached, simply return instead of attempting another cache
2801
+ if (parsingCachedResponse) {
2802
+ return;
2803
+ }
2804
+ // default the expire timestamp to one day in milliseconds unless a header comes back
2805
+ var expireTimestamp = getExpireTimestamp(identityResponse === null || identityResponse === void 0 ? void 0 : identityResponse.cacheMaxAge);
2806
+ switch (method) {
2807
+ case Login$2:
2808
+ case Identify$2:
2809
+ cacheIdentityRequest(method, knownIdentities, expireTimestamp, idCache, identityResponse);
2810
+ break;
2811
+ case Modify$4:
2812
+ case Logout$2:
2813
+ idCache.purge();
2814
+ break;
2815
+ }
2816
+ };
2817
+ var cacheIdentityRequest = function cacheIdentityRequest(method, identities, expireTimestamp, idCache, identityResponse) {
2818
+ var responseText = identityResponse.responseText,
2819
+ status = identityResponse.status;
2820
+ var cache = idCache.retrieve() || {};
2821
+ var cacheKey = concatenateIdentities(method, identities);
2822
+ var hashedKey = generateHash(cacheKey);
2823
+ var mpid = responseText.mpid,
2824
+ is_logged_in = responseText.is_logged_in;
2825
+ var cachedResponseBody = {
2826
+ mpid: mpid,
2827
+ is_logged_in: is_logged_in
2828
+ };
2829
+ cache[hashedKey] = {
2830
+ responseText: JSON.stringify(cachedResponseBody),
2831
+ status: status,
2832
+ expireTimestamp: expireTimestamp
2833
+ };
2834
+ idCache.store(cache);
2835
+ };
2836
+ // We need to ensure that identities are concatenated in a deterministic way, so
2837
+ // we sort the identities based on their enum.
2838
+ // we create an array, set the user identity at the index of the user identity type
2839
+ var concatenateIdentities = function concatenateIdentities(method, userIdentities) {
2840
+ var DEVICE_APPLICATION_STAMP = 'device_application_stamp';
2841
+ // set DAS first since it is not an official identity type
2842
+ var cacheKey = "".concat(method, ":").concat(DEVICE_APPLICATION_STAMP, "=").concat(userIdentities.device_application_stamp, ";");
2843
+ var idLength = Object.keys(userIdentities).length;
2844
+ var concatenatedIdentities = '';
2845
+ if (idLength) {
2846
+ var userIDArray = new Array();
2847
+ // create an array where each index is equal to the user identity type
2848
+ for (var key in userIdentities) {
2849
+ if (key === DEVICE_APPLICATION_STAMP) {
2850
+ continue;
2851
+ } else {
2852
+ userIDArray[Types.IdentityType.getIdentityType(key)] = userIdentities[key];
2853
+ }
2854
+ }
2855
+ concatenatedIdentities = userIDArray.reduce(function (prevValue, currentValue, index) {
2856
+ var idName = Types.IdentityType.getIdentityName(index);
2857
+ return "".concat(prevValue).concat(idName, "=").concat(currentValue, ";");
2858
+ }, cacheKey);
2859
+ }
2860
+ return concatenatedIdentities;
2861
+ };
2862
+ var hasValidCachedIdentity = function hasValidCachedIdentity(method, proposedUserIdentities, idCache) {
2863
+ // There is an edge case where multiple identity calls are taking place
2864
+ // before identify fires, so there may not be a cache. See what happens when
2865
+ // the ? in idCache is removed to the following test
2866
+ // "queued events contain login mpid instead of identify mpid when calling
2867
+ // login immediately after mParticle initializes"
2868
+ var cache = idCache === null || idCache === void 0 ? void 0 : idCache.retrieve();
2869
+ // if there is no cache, then there is no valid cached identity
2870
+ if (!cache) {
2871
+ return false;
2872
+ }
2873
+ var cacheKey = concatenateIdentities(method, proposedUserIdentities);
2874
+ var hashedKey = generateHash(cacheKey);
2875
+ // if cache doesn't have the cacheKey, there is no valid cached identity
2876
+ if (!cache.hasOwnProperty(hashedKey)) {
2877
+ return false;
2878
+ }
2879
+ // If there is a valid cache key, compare the expireTimestamp to the current time.
2880
+ // If the current time is greater than the expireTimestamp, it is not a valid
2881
+ // cached identity.
2882
+ var expireTimestamp = cache[hashedKey].expireTimestamp;
2883
+ if (expireTimestamp < new Date().getTime()) {
2884
+ return false;
2885
+ } else {
2886
+ return true;
2887
+ }
2888
+ };
2889
+ var getCachedIdentity = function getCachedIdentity(method, proposedUserIdentities, idCache) {
2890
+ var cacheKey = concatenateIdentities(method, proposedUserIdentities);
2891
+ var hashedKey = generateHash(cacheKey);
2892
+ var cache = idCache.retrieve();
2893
+ var cachedIdentity = cache ? cache[hashedKey] : null;
2894
+ return {
2895
+ responseText: parseIdentityResponse(cachedIdentity.responseText),
2896
+ expireTimestamp: cachedIdentity.expireTimestamp,
2897
+ status: cachedIdentity.status
2898
+ };
2899
+ };
2900
+ // https://go.mparticle.com/work/SQDSDKS-6079
2901
+ var createKnownIdentities = function createKnownIdentities(identityApiData, deviceId) {
2902
+ var identitiesResult = {};
2903
+ if (isObject(identityApiData === null || identityApiData === void 0 ? void 0 : identityApiData.userIdentities)) {
2904
+ for (var identity in identityApiData.userIdentities) {
2905
+ identitiesResult[identity] = identityApiData.userIdentities[identity];
2906
+ }
2907
+ }
2908
+ identitiesResult.device_application_stamp = deviceId;
2909
+ return identitiesResult;
2910
+ };
2911
+ var removeExpiredIdentityCacheDates = function removeExpiredIdentityCacheDates(idCache) {
2912
+ var cache = idCache.retrieve() || {};
2913
+ var currentTime = new Date().getTime();
2914
+ // Iterate over the cache and remove any key/value pairs that are expired
2915
+ for (var key in cache) {
2916
+ if (cache[key].expireTimestamp < currentTime) {
2917
+ delete cache[key];
2918
+ }
2919
+ }
2920
+ idCache.store(cache);
2921
+ };
2922
+ var tryCacheIdentity = function tryCacheIdentity(knownIdentities, idCache, parseIdentityResponse, mpid, callback, identityApiData, identityMethod) {
2923
+ // https://go.mparticle.com/work/SQDSDKS-6095
2924
+ var shouldReturnCachedIdentity = hasValidCachedIdentity(identityMethod, knownIdentities, idCache);
2925
+ // If Identity is cached, then immediately parse the identity response
2926
+ if (shouldReturnCachedIdentity) {
2927
+ var cachedIdentity = getCachedIdentity(identityMethod, knownIdentities, idCache);
2928
+ parseIdentityResponse(cachedIdentity, mpid, callback, identityApiData, identityMethod, knownIdentities, true);
2929
+ return true;
2930
+ }
2931
+ return false;
2932
+ };
2933
+ var getExpireTimestamp = function getExpireTimestamp(maxAge) {
2934
+ if (maxAge === void 0) {
2935
+ maxAge = ONE_DAY_IN_SECONDS;
2936
+ }
2937
+ return new Date().getTime() + maxAge * MILLIS_IN_ONE_SEC;
2938
+ };
2939
+ var parseIdentityResponse = function parseIdentityResponse(responseText) {
2940
+ return responseText ? JSON.parse(responseText) : {};
2941
+ };
2942
+ var hasIdentityRequestChanged = function hasIdentityRequestChanged(currentUser, newIdentityRequest) {
2943
+ if (!currentUser || !(newIdentityRequest === null || newIdentityRequest === void 0 ? void 0 : newIdentityRequest.userIdentities)) {
2944
+ return false;
2945
+ }
2946
+ var currentUserIdentities = currentUser.getUserIdentities().userIdentities;
2947
+ var newIdentities = newIdentityRequest.userIdentities;
2948
+ return JSON.stringify(currentUserIdentities) !== JSON.stringify(newIdentities);
2949
+ };
2950
+ /**
2951
+ * Checks if deviceId or other user identifiers (like email) were explicitly provided
2952
+ * by the partner via config.deviceId or config.identifyRequest.userIdentities.
2953
+ * When noFunctional is true, then cookies are blocked, so the partner must explicitly
2954
+ * pass deviceId or other identifiers to prevent new users from being created on each page load.
2955
+ *
2956
+ * @param store - The SDK store (provides SDKConfig.deviceId and SDKConfig.identifyRequest.userIdentities)
2957
+ * @returns true if deviceId or other identifiers were explicitly provided in config, false otherwise
2958
+ */
2959
+ var hasExplicitIdentifier = function hasExplicitIdentifier(store) {
2960
+ var _a, _b, _c;
2961
+ var userIdentities = (_b = (_a = store === null || store === void 0 ? void 0 : store.SDKConfig) === null || _a === void 0 ? void 0 : _a.identifyRequest) === null || _b === void 0 ? void 0 : _b.userIdentities;
2962
+ if (userIdentities && isObject(userIdentities) && !isEmpty(userIdentities) && Object.values(userIdentities).some(Boolean)) {
2963
+ return true;
2964
+ }
2965
+ return !!((_c = store === null || store === void 0 ? void 0 : store.SDKConfig) === null || _c === void 0 ? void 0 : _c.deviceId);
2966
+ };
2967
+
2766
2968
  function APIClient(mpInstance, kitBlocker) {
2767
2969
  this.uploader = null;
2768
2970
  var self = this;
@@ -2798,6 +3000,28 @@ var mParticle = (function () {
2798
3000
  }
2799
3001
  });
2800
3002
  };
3003
+ // When noFunctional is set and there are no identities passed, the SDK will not fully initialize.
3004
+ // In this case, there will be no MPID, but we still want kits to initialize and forward the event to kits.
3005
+ // The original event is queued for the MP server upload path so it can be sent once an MPID is returned.
3006
+ // Returns true if the event was handled by this path (caller should return early).
3007
+ var handleNoFunctionalPreMpidEvent = function handleNoFunctionalPreMpidEvent(event, mpid) {
3008
+ var _a;
3009
+ var noFunctionalWithoutId = ((_a = mpInstance._CookieConsentManager) === null || _a === void 0 ? void 0 : _a.getNoFunctional()) && !hasExplicitIdentifier(mpInstance._Store);
3010
+ if (!noFunctionalWithoutId || mpid || !mpInstance._Store.configurationLoaded || mpInstance._Store.requireDelay) {
3011
+ return false;
3012
+ }
3013
+ var forwarderEvent = event;
3014
+ if (kitBlocker === null || kitBlocker === void 0 ? void 0 : kitBlocker.kitBlockingEnabled) {
3015
+ forwarderEvent = kitBlocker.createBlockedEvent(event);
3016
+ }
3017
+ if (forwarderEvent) {
3018
+ mpInstance._Forwarders.sendEventToForwarders(forwarderEvent);
3019
+ event.AlreadySentToForwarders = true;
3020
+ }
3021
+ mpInstance.Logger.verbose('noFunctional event forwarded to kits and queued for MP server upload when MPID is available.');
3022
+ mpInstance._Store.eventQueue.push(event);
3023
+ return true;
3024
+ };
2801
3025
  this.sendEventToServer = function (event, _options) {
2802
3026
  var defaultOptions = {
2803
3027
  shouldUploadEvent: true
@@ -2813,8 +3037,12 @@ var mParticle = (function () {
2813
3037
  mpid = currentUser.getMPID();
2814
3038
  }
2815
3039
  mpInstance._Store.requireDelay = mpInstance._Helpers.isDelayedByIntegration(mpInstance._preInit.integrationDelays, mpInstance._Store.integrationDelayTimeoutStart, Date.now());
2816
- // We queue events if there is no MPID (MPID is null, or === 0), or there are integrations that that require this to stall because integration attributes
2817
- // need to be set, or if we are still fetching the config (self hosted only), and so require delaying events
3040
+ if (handleNoFunctionalPreMpidEvent(event, mpid)) {
3041
+ return;
3042
+ }
3043
+ // We queue events if there is no MPID (MPID is null, or === 0), or there are integrations that
3044
+ // require this to stall because integration attributes need to be set, or if we are still
3045
+ // fetching the config (self hosted only), and so require delaying events
2818
3046
  if (!mpid || mpInstance._Store.requireDelay || !mpInstance._Store.configurationLoaded) {
2819
3047
  mpInstance.Logger.verbose('Event was added to eventQueue. eventQueue will be processed once a valid MPID is returned or there is no more integration imposed delay.');
2820
3048
  mpInstance._Store.eventQueue.push(event);
@@ -2836,8 +3064,10 @@ var mParticle = (function () {
2836
3064
  event = kitBlocker.createBlockedEvent(event);
2837
3065
  }
2838
3066
  // We need to check event again, because kitblocking
2839
- // can nullify the event
2840
- if (event) {
3067
+ // can nullify the event.
3068
+ // Skip if forwarders were already called in the noFunctional pre-MPID path
3069
+ // to prevent double-sending when the event queue is later flushed.
3070
+ if (event && !event.AlreadySentToForwarders) {
2841
3071
  mpInstance._Forwarders.sendEventToForwarders(event);
2842
3072
  }
2843
3073
  }
@@ -2896,7 +3126,7 @@ var mParticle = (function () {
2896
3126
  };
2897
3127
  }
2898
3128
 
2899
- var Modify$4 = Constants.IdentityMethods.Modify;
3129
+ var Modify$3 = Constants.IdentityMethods.Modify;
2900
3130
  var Validators = {
2901
3131
  // From ./utils
2902
3132
  // Utility Functions for backwards compatability
@@ -2936,7 +3166,7 @@ var mParticle = (function () {
2936
3166
  copyUserAttributes: 1
2937
3167
  };
2938
3168
  if (identityApiData) {
2939
- if (method === Modify$4) {
3169
+ if (method === Modify$3) {
2940
3170
  if (isObject(identityApiData.userIdentities) && !Object.keys(identityApiData.userIdentities).length || !isObject(identityApiData.userIdentities)) {
2941
3171
  return {
2942
3172
  valid: false,
@@ -3502,12 +3732,18 @@ var mParticle = (function () {
3502
3732
  var self = this;
3503
3733
  // Public
3504
3734
  this.attemptCookieSync = function (mpid, mpidIsNotInCookies) {
3505
- var _a = mpInstance._Store,
3506
- pixelConfigurations = _a.pixelConfigurations,
3507
- webviewBridgeEnabled = _a.webviewBridgeEnabled;
3735
+ var _a;
3736
+ var _b = mpInstance._Store,
3737
+ pixelConfigurations = _b.pixelConfigurations,
3738
+ webviewBridgeEnabled = _b.webviewBridgeEnabled;
3508
3739
  if (!mpid || webviewBridgeEnabled) {
3509
3740
  return;
3510
3741
  }
3742
+ // When noFunctional is true, persistence is not saved, so we cannot track cookie sync
3743
+ // dates. Skip cookie sync to avoid running it on every page load.
3744
+ if ((_a = mpInstance._CookieConsentManager) === null || _a === void 0 ? void 0 : _a.getNoFunctional()) {
3745
+ return;
3746
+ }
3511
3747
  var persistence = mpInstance._Persistence.getPersistence();
3512
3748
  if (isEmpty(persistence)) {
3513
3749
  return;
@@ -3579,172 +3815,15 @@ var mParticle = (function () {
3579
3815
  return new Date().getTime() > new Date(lastSyncDate).getTime() + frequencyCap * DAYS_IN_MILLISECONDS;
3580
3816
  };
3581
3817
 
3582
- var _a = Constants.IdentityMethods,
3583
- Identify$2 = _a.Identify,
3584
- Modify$3 = _a.Modify,
3585
- Login$2 = _a.Login,
3586
- Logout$2 = _a.Logout;
3587
- var CACHE_HEADER = 'x-mp-max-age';
3588
- var cacheOrClearIdCache = function cacheOrClearIdCache(method, knownIdentities, idCache, identityResponse, parsingCachedResponse) {
3589
- // when parsing a response that has already been cached, simply return instead of attempting another cache
3590
- if (parsingCachedResponse) {
3591
- return;
3592
- }
3593
- // default the expire timestamp to one day in milliseconds unless a header comes back
3594
- var expireTimestamp = getExpireTimestamp(identityResponse === null || identityResponse === void 0 ? void 0 : identityResponse.cacheMaxAge);
3595
- switch (method) {
3596
- case Login$2:
3597
- case Identify$2:
3598
- cacheIdentityRequest(method, knownIdentities, expireTimestamp, idCache, identityResponse);
3599
- break;
3600
- case Modify$3:
3601
- case Logout$2:
3602
- idCache.purge();
3603
- break;
3604
- }
3605
- };
3606
- var cacheIdentityRequest = function cacheIdentityRequest(method, identities, expireTimestamp, idCache, identityResponse) {
3607
- var responseText = identityResponse.responseText,
3608
- status = identityResponse.status;
3609
- var cache = idCache.retrieve() || {};
3610
- var cacheKey = concatenateIdentities(method, identities);
3611
- var hashedKey = generateHash(cacheKey);
3612
- var mpid = responseText.mpid,
3613
- is_logged_in = responseText.is_logged_in;
3614
- var cachedResponseBody = {
3615
- mpid: mpid,
3616
- is_logged_in: is_logged_in
3617
- };
3618
- cache[hashedKey] = {
3619
- responseText: JSON.stringify(cachedResponseBody),
3620
- status: status,
3621
- expireTimestamp: expireTimestamp
3622
- };
3623
- idCache.store(cache);
3624
- };
3625
- // We need to ensure that identities are concatenated in a deterministic way, so
3626
- // we sort the identities based on their enum.
3627
- // we create an array, set the user identity at the index of the user identity type
3628
- var concatenateIdentities = function concatenateIdentities(method, userIdentities) {
3629
- var DEVICE_APPLICATION_STAMP = 'device_application_stamp';
3630
- // set DAS first since it is not an official identity type
3631
- var cacheKey = "".concat(method, ":").concat(DEVICE_APPLICATION_STAMP, "=").concat(userIdentities.device_application_stamp, ";");
3632
- var idLength = Object.keys(userIdentities).length;
3633
- var concatenatedIdentities = '';
3634
- if (idLength) {
3635
- var userIDArray = new Array();
3636
- // create an array where each index is equal to the user identity type
3637
- for (var key in userIdentities) {
3638
- if (key === DEVICE_APPLICATION_STAMP) {
3639
- continue;
3640
- } else {
3641
- userIDArray[Types.IdentityType.getIdentityType(key)] = userIdentities[key];
3642
- }
3643
- }
3644
- concatenatedIdentities = userIDArray.reduce(function (prevValue, currentValue, index) {
3645
- var idName = Types.IdentityType.getIdentityName(index);
3646
- return "".concat(prevValue).concat(idName, "=").concat(currentValue, ";");
3647
- }, cacheKey);
3648
- }
3649
- return concatenatedIdentities;
3650
- };
3651
- var hasValidCachedIdentity = function hasValidCachedIdentity(method, proposedUserIdentities, idCache) {
3652
- // There is an edge case where multiple identity calls are taking place
3653
- // before identify fires, so there may not be a cache. See what happens when
3654
- // the ? in idCache is removed to the following test
3655
- // "queued events contain login mpid instead of identify mpid when calling
3656
- // login immediately after mParticle initializes"
3657
- var cache = idCache === null || idCache === void 0 ? void 0 : idCache.retrieve();
3658
- // if there is no cache, then there is no valid cached identity
3659
- if (!cache) {
3660
- return false;
3661
- }
3662
- var cacheKey = concatenateIdentities(method, proposedUserIdentities);
3663
- var hashedKey = generateHash(cacheKey);
3664
- // if cache doesn't have the cacheKey, there is no valid cached identity
3665
- if (!cache.hasOwnProperty(hashedKey)) {
3666
- return false;
3667
- }
3668
- // If there is a valid cache key, compare the expireTimestamp to the current time.
3669
- // If the current time is greater than the expireTimestamp, it is not a valid
3670
- // cached identity.
3671
- var expireTimestamp = cache[hashedKey].expireTimestamp;
3672
- if (expireTimestamp < new Date().getTime()) {
3673
- return false;
3674
- } else {
3675
- return true;
3676
- }
3677
- };
3678
- var getCachedIdentity = function getCachedIdentity(method, proposedUserIdentities, idCache) {
3679
- var cacheKey = concatenateIdentities(method, proposedUserIdentities);
3680
- var hashedKey = generateHash(cacheKey);
3681
- var cache = idCache.retrieve();
3682
- var cachedIdentity = cache ? cache[hashedKey] : null;
3683
- return {
3684
- responseText: parseIdentityResponse(cachedIdentity.responseText),
3685
- expireTimestamp: cachedIdentity.expireTimestamp,
3686
- status: cachedIdentity.status
3687
- };
3688
- };
3689
- // https://go.mparticle.com/work/SQDSDKS-6079
3690
- var createKnownIdentities = function createKnownIdentities(identityApiData, deviceId) {
3691
- var identitiesResult = {};
3692
- if (isObject(identityApiData === null || identityApiData === void 0 ? void 0 : identityApiData.userIdentities)) {
3693
- for (var identity in identityApiData.userIdentities) {
3694
- identitiesResult[identity] = identityApiData.userIdentities[identity];
3695
- }
3696
- }
3697
- identitiesResult.device_application_stamp = deviceId;
3698
- return identitiesResult;
3699
- };
3700
- var removeExpiredIdentityCacheDates = function removeExpiredIdentityCacheDates(idCache) {
3701
- var cache = idCache.retrieve() || {};
3702
- var currentTime = new Date().getTime();
3703
- // Iterate over the cache and remove any key/value pairs that are expired
3704
- for (var key in cache) {
3705
- if (cache[key].expireTimestamp < currentTime) {
3706
- delete cache[key];
3707
- }
3708
- }
3709
- idCache.store(cache);
3710
- };
3711
- var tryCacheIdentity = function tryCacheIdentity(knownIdentities, idCache, parseIdentityResponse, mpid, callback, identityApiData, identityMethod) {
3712
- // https://go.mparticle.com/work/SQDSDKS-6095
3713
- var shouldReturnCachedIdentity = hasValidCachedIdentity(identityMethod, knownIdentities, idCache);
3714
- // If Identity is cached, then immediately parse the identity response
3715
- if (shouldReturnCachedIdentity) {
3716
- var cachedIdentity = getCachedIdentity(identityMethod, knownIdentities, idCache);
3717
- parseIdentityResponse(cachedIdentity, mpid, callback, identityApiData, identityMethod, knownIdentities, true);
3718
- return true;
3719
- }
3720
- return false;
3721
- };
3722
- var getExpireTimestamp = function getExpireTimestamp(maxAge) {
3723
- if (maxAge === void 0) {
3724
- maxAge = ONE_DAY_IN_SECONDS;
3725
- }
3726
- return new Date().getTime() + maxAge * MILLIS_IN_ONE_SEC;
3727
- };
3728
- var parseIdentityResponse = function parseIdentityResponse(responseText) {
3729
- return responseText ? JSON.parse(responseText) : {};
3730
- };
3731
- var hasIdentityRequestChanged = function hasIdentityRequestChanged(currentUser, newIdentityRequest) {
3732
- if (!currentUser || !(newIdentityRequest === null || newIdentityRequest === void 0 ? void 0 : newIdentityRequest.userIdentities)) {
3733
- return false;
3734
- }
3735
- var currentUserIdentities = currentUser.getUserIdentities().userIdentities;
3736
- var newIdentities = newIdentityRequest.userIdentities;
3737
- return JSON.stringify(currentUserIdentities) !== JSON.stringify(newIdentities);
3738
- };
3739
-
3740
3818
  var Messages$6 = Constants.Messages;
3741
3819
  function SessionManager(mpInstance) {
3742
3820
  var self = this;
3743
3821
  this.initialize = function () {
3822
+ var _a;
3744
3823
  if (mpInstance._Store.sessionId) {
3745
- var _a = mpInstance._Store,
3746
- dateLastEventSent = _a.dateLastEventSent,
3747
- SDKConfig = _a.SDKConfig;
3824
+ var _b = mpInstance._Store,
3825
+ dateLastEventSent = _b.dateLastEventSent,
3826
+ SDKConfig = _b.SDKConfig;
3748
3827
  var sessionTimeout = SDKConfig.sessionTimeout;
3749
3828
  if (hasSessionTimedOut(dateLastEventSent === null || dateLastEventSent === void 0 ? void 0 : dateLastEventSent.getTime(), sessionTimeout)) {
3750
3829
  self.endSession();
@@ -3754,7 +3833,8 @@ var mParticle = (function () {
3754
3833
  // https://go.mparticle.com/work/SQDSDKS-6323
3755
3834
  var currentUser = mpInstance.Identity.getCurrentUser();
3756
3835
  var sdkIdentityRequest = SDKConfig.identifyRequest;
3757
- if (hasIdentityRequestChanged(currentUser, sdkIdentityRequest)) {
3836
+ var shouldSuppressIdentify = ((_a = mpInstance._CookieConsentManager) === null || _a === void 0 ? void 0 : _a.getNoFunctional()) && !hasExplicitIdentifier(mpInstance._Store);
3837
+ if (!shouldSuppressIdentify && hasIdentityRequestChanged(currentUser, sdkIdentityRequest)) {
3758
3838
  mpInstance.Identity.identify(sdkIdentityRequest, SDKConfig.identityCallback);
3759
3839
  mpInstance._Store.identifyCalled = true;
3760
3840
  mpInstance._Store.SDKConfig.identityCallback = null;
@@ -3772,6 +3852,7 @@ var mParticle = (function () {
3772
3852
  return mpInstance._Store.sessionId;
3773
3853
  };
3774
3854
  this.startNewSession = function () {
3855
+ var _a;
3775
3856
  mpInstance.Logger.verbose(Messages$6.InformationMessages.StartingNewSession);
3776
3857
  if (mpInstance._Helpers.canLog()) {
3777
3858
  mpInstance._Store.sessionId = mpInstance._Helpers.generateUniqueId().toUpperCase();
@@ -3786,7 +3867,8 @@ var mParticle = (function () {
3786
3867
  mpInstance._Store.dateLastEventSent = date;
3787
3868
  }
3788
3869
  self.setSessionTimer();
3789
- if (!mpInstance._Store.identifyCalled) {
3870
+ var shouldSuppressIdentify = ((_a = mpInstance._CookieConsentManager) === null || _a === void 0 ? void 0 : _a.getNoFunctional()) && !hasExplicitIdentifier(mpInstance._Store);
3871
+ if (!mpInstance._Store.identifyCalled && !shouldSuppressIdentify) {
3790
3872
  mpInstance.Identity.identify(mpInstance._Store.SDKConfig.identifyRequest, mpInstance._Store.SDKConfig.identityCallback);
3791
3873
  mpInstance._Store.identifyCalled = true;
3792
3874
  mpInstance._Store.SDKConfig.identityCallback = null;
@@ -4312,14 +4394,20 @@ var mParticle = (function () {
4312
4394
  }
4313
4395
 
4314
4396
  var ForegroundTimeTracker = /** @class */function () {
4315
- function ForegroundTimeTracker(timerKey) {
4397
+ function ForegroundTimeTracker(timerKey, noFunctional) {
4398
+ if (noFunctional === void 0) {
4399
+ noFunctional = false;
4400
+ }
4401
+ this.noFunctional = noFunctional;
4316
4402
  this.isTrackerActive = false;
4317
4403
  this.localStorageName = '';
4318
4404
  this.startTime = 0;
4319
4405
  this.totalTime = 0;
4320
4406
  this.localStorageName = "mprtcl-tos-".concat(timerKey);
4321
4407
  this.timerVault = new LocalStorageVault(this.localStorageName);
4322
- this.loadTimeFromStorage();
4408
+ if (!this.noFunctional) {
4409
+ this.loadTimeFromStorage();
4410
+ }
4323
4411
  this.addHandlers();
4324
4412
  if (document.hidden === false) {
4325
4413
  this.startTracking();
@@ -4372,7 +4460,7 @@ var mParticle = (function () {
4372
4460
  }
4373
4461
  };
4374
4462
  ForegroundTimeTracker.prototype.updateTimeInPersistence = function () {
4375
- if (this.isTrackerActive) {
4463
+ if (this.isTrackerActive && !this.noFunctional) {
4376
4464
  this.timerVault.store(Math.round(this.totalTime));
4377
4465
  }
4378
4466
  };
@@ -4432,6 +4520,8 @@ var mParticle = (function () {
4432
4520
  for (var prop in Constants.DefaultBaseUrls) {
4433
4521
  sdkConfig[prop] = Constants.DefaultBaseUrls[prop];
4434
4522
  }
4523
+ // Always initialize flags to at least an empty object to prevent undefined access
4524
+ sdkConfig.flags = sdkConfig.flags || {};
4435
4525
  return sdkConfig;
4436
4526
  }
4437
4527
  // TODO: Merge this with SDKStoreApi in sdkRuntimeModels
@@ -4484,6 +4574,8 @@ var mParticle = (function () {
4484
4574
  version: null,
4485
4575
  isInfoSet: false
4486
4576
  },
4577
+ roktAccountId: null,
4578
+ integrationName: null,
4487
4579
  // Placeholder for in-memory persistence model
4488
4580
  persistenceData: {
4489
4581
  gs: {}
@@ -4500,10 +4592,6 @@ var mParticle = (function () {
4500
4592
  if (!config.hasOwnProperty('flags')) {
4501
4593
  this.SDKConfig.flags = {};
4502
4594
  }
4503
- // We process the initial config that is passed via the SDK init
4504
- // and then we will reprocess the config within the processConfig
4505
- // function when the config is updated from the server
4506
- // https://go.mparticle.com/work/SQDSDKS-6317
4507
4595
  this.SDKConfig.flags = processFlags(config);
4508
4596
  if (config.deviceId) {
4509
4597
  this.deviceId = config.deviceId;
@@ -4517,9 +4605,6 @@ var mParticle = (function () {
4517
4605
  for (var baseUrlKeys in baseUrls) {
4518
4606
  this.SDKConfig[baseUrlKeys] = baseUrls[baseUrlKeys];
4519
4607
  }
4520
- if (config.hasOwnProperty('logLevel')) {
4521
- this.SDKConfig.logLevel = config.logLevel;
4522
- }
4523
4608
  this.SDKConfig.useNativeSdk = !!config.useNativeSdk;
4524
4609
  this.SDKConfig.kits = config.kits || {};
4525
4610
  this.SDKConfig.sideloadedKits = config.sideloadedKits || [];
@@ -4742,6 +4827,18 @@ var mParticle = (function () {
4742
4827
  this.setUserIdentities = function (mpid, userIdentities) {
4743
4828
  _this._setPersistence(mpid, 'ui', userIdentities);
4744
4829
  };
4830
+ this.getRoktAccountId = function () {
4831
+ return _this.roktAccountId;
4832
+ };
4833
+ this.setRoktAccountId = function (accountId) {
4834
+ _this.roktAccountId = accountId;
4835
+ };
4836
+ this.getIntegrationName = function () {
4837
+ return _this.integrationName;
4838
+ };
4839
+ this.setIntegrationName = function (integrationName) {
4840
+ _this.integrationName = integrationName;
4841
+ };
4745
4842
  this.addMpidToSessionHistory = function (mpid, previousMPID) {
4746
4843
  var indexOfMPID = _this.currentSessionMPIDs.indexOf(mpid);
4747
4844
  if (mpid && previousMPID !== mpid && indexOfMPID < 0) {
@@ -4761,19 +4858,24 @@ var mParticle = (function () {
4761
4858
  mpInstance._Persistence.update();
4762
4859
  };
4763
4860
  this.processConfig = function (config) {
4861
+ var _a;
4764
4862
  var workspaceToken = config.workspaceToken,
4765
4863
  requiredWebviewBridgeName = config.requiredWebviewBridgeName;
4766
4864
  // We should reprocess the flags and baseUrls in case they have changed when we request an updated config
4767
4865
  // such as if the SDK is being self-hosted and the flags are different on the server config
4768
4866
  // https://go.mparticle.com/work/SQDSDKS-6317
4769
- _this.SDKConfig.flags = processFlags(config);
4867
+ // Only update flags if the config actually has flags (don't overwrite with empty object)
4868
+ if (config.flags) {
4869
+ _this.SDKConfig.flags = processFlags(config);
4870
+ }
4770
4871
  var baseUrls = processBaseUrls(config, _this.SDKConfig.flags, apiKey);
4771
4872
  for (var baseUrlKeys in baseUrls) {
4772
4873
  _this.SDKConfig[baseUrlKeys] = baseUrls[baseUrlKeys];
4773
4874
  }
4774
4875
  if (workspaceToken) {
4775
4876
  _this.SDKConfig.workspaceToken = workspaceToken;
4776
- mpInstance._timeOnSiteTimer = new ForegroundTimeTracker(workspaceToken);
4877
+ var noFunctional = ((_a = config === null || config === void 0 ? void 0 : config.launcherOptions) === null || _a === void 0 ? void 0 : _a.noFunctional) === true;
4878
+ mpInstance._timeOnSiteTimer = new ForegroundTimeTracker(workspaceToken, noFunctional);
4777
4879
  } else {
4778
4880
  mpInstance.Logger.warning('You should have a workspaceToken on your config object for security purposes.');
4779
4881
  }
@@ -4866,7 +4968,7 @@ var mParticle = (function () {
4866
4968
  for (var baseUrlKey in defaultBaseUrls) {
4867
4969
  // Any custom endpoints passed to mpConfig will take priority over direct
4868
4970
  // mapping to the silo. The most common use case is a customer provided CNAME.
4869
- if (baseUrlKey === 'configUrl') {
4971
+ if (baseUrlKey === 'configUrl' || baseUrlKey === 'loggingUrl' || baseUrlKey === 'errorUrl') {
4870
4972
  directBaseUrls[baseUrlKey] = config[baseUrlKey] || defaultBaseUrls[baseUrlKey];
4871
4973
  continue;
4872
4974
  }
@@ -4881,10 +4983,11 @@ var mParticle = (function () {
4881
4983
  }
4882
4984
 
4883
4985
  var Logger = /** @class */function () {
4884
- function Logger(config) {
4986
+ function Logger(config, reportingLogger) {
4885
4987
  var _a, _b;
4886
4988
  this.logLevel = (_a = config.logLevel) !== null && _a !== void 0 ? _a : LogLevelType.Warning;
4887
4989
  this.logger = (_b = config.logger) !== null && _b !== void 0 ? _b : new ConsoleLogger();
4990
+ this.reportingLogger = reportingLogger;
4888
4991
  }
4889
4992
  Logger.prototype.verbose = function (msg) {
4890
4993
  if (this.logLevel === LogLevelType.None) return;
@@ -4898,10 +5001,14 @@ var mParticle = (function () {
4898
5001
  this.logger.warning(msg);
4899
5002
  }
4900
5003
  };
4901
- Logger.prototype.error = function (msg) {
5004
+ Logger.prototype.error = function (msg, codeForReporting) {
5005
+ var _a;
4902
5006
  if (this.logLevel === LogLevelType.None) return;
4903
5007
  if (this.logger.error) {
4904
5008
  this.logger.error(msg);
5009
+ if (codeForReporting) {
5010
+ (_a = this.reportingLogger) === null || _a === void 0 ? void 0 : _a.error(msg, codeForReporting);
5011
+ }
4905
5012
  }
4906
5013
  };
4907
5014
  Logger.prototype.setLogLevel = function (newLogLevel) {
@@ -5102,9 +5209,15 @@ var mParticle = (function () {
5102
5209
 
5103
5210
  // https://go.mparticle.com/work/SQDSDKS-6021
5104
5211
  this.setLocalStorage = function () {
5212
+ var _mpInstance$_CookieCo;
5105
5213
  if (!mpInstance._Store.isLocalStorageAvailable) {
5106
5214
  return;
5107
5215
  }
5216
+
5217
+ // Block mprtcl-v4 localStorage when noFunctional is true
5218
+ if ((_mpInstance$_CookieCo = mpInstance._CookieConsentManager) !== null && _mpInstance$_CookieCo !== void 0 && _mpInstance$_CookieCo.getNoFunctional()) {
5219
+ return;
5220
+ }
5108
5221
  var key = mpInstance._Store.storageName,
5109
5222
  localStorageData = self.getLocalStorage() || {},
5110
5223
  currentUser = mpInstance.Identity.getCurrentUser(),
@@ -5230,6 +5343,11 @@ var mParticle = (function () {
5230
5343
  // https://go.mparticle.com/work/SQDSDKS-5022
5231
5344
  // https://go.mparticle.com/work/SQDSDKS-6021
5232
5345
  this.setCookie = function () {
5346
+ var _mpInstance$_CookieCo2;
5347
+ // Block mprtcl-v4 cookies when noFunctional is true
5348
+ if ((_mpInstance$_CookieCo2 = mpInstance._CookieConsentManager) !== null && _mpInstance$_CookieCo2 !== void 0 && _mpInstance$_CookieCo2.getNoFunctional()) {
5349
+ return;
5350
+ }
5233
5351
  var mpid,
5234
5352
  currentUser = mpInstance.Identity.getCurrentUser();
5235
5353
  if (currentUser) {
@@ -5505,6 +5623,11 @@ var mParticle = (function () {
5505
5623
 
5506
5624
  // https://go.mparticle.com/work/SQDSDKS-6021
5507
5625
  this.savePersistence = function (persistence) {
5626
+ var _mpInstance$_CookieCo3;
5627
+ // Block mprtcl-v4 persistence when noFunctional is true
5628
+ if ((_mpInstance$_CookieCo3 = mpInstance._CookieConsentManager) !== null && _mpInstance$_CookieCo3 !== void 0 && _mpInstance$_CookieCo3.getNoFunctional()) {
5629
+ return;
5630
+ }
5508
5631
  var encodedPersistence = self.encodePersistence(JSON.stringify(persistence)),
5509
5632
  date = new Date(),
5510
5633
  key = mpInstance._Store.storageName,
@@ -9161,6 +9284,17 @@ var mParticle = (function () {
9161
9284
  };
9162
9285
  }
9163
9286
 
9287
+ var ErrorCodes = {
9288
+ UNKNOWN_ERROR: 'UNKNOWN_ERROR',
9289
+ UNHANDLED_EXCEPTION: 'UNHANDLED_EXCEPTION',
9290
+ IDENTITY_REQUEST: 'IDENTITY_REQUEST'
9291
+ };
9292
+ var WSDKErrorSeverity = {
9293
+ ERROR: 'ERROR',
9294
+ INFO: 'INFO',
9295
+ WARNING: 'WARNING'
9296
+ };
9297
+
9164
9298
  var HTTPCodes$1 = Constants.HTTPCodes,
9165
9299
  Messages$1 = Constants.Messages,
9166
9300
  IdentityMethods = Constants.IdentityMethods;
@@ -9373,7 +9507,7 @@ var mParticle = (function () {
9373
9507
  mpInstance.captureTiming("".concat(requestCount, "-identityRequestEnd"));
9374
9508
  }
9375
9509
  errorMessage = err_1.message || err_1.toString();
9376
- Logger.error('Error sending identity request to servers - ' + errorMessage);
9510
+ Logger.error('Error sending identity request to servers' + ' - ' + errorMessage, ErrorCodes.IDENTITY_REQUEST);
9377
9511
  (_d = mpInstance.processQueueOnIdentityFailure) === null || _d === void 0 ? void 0 : _d.call(mpInstance);
9378
9512
  invokeCallback(callback, HTTPCodes$1.noHttpCoverage, errorMessage);
9379
9513
  return [3 /*break*/, 10];
@@ -9793,13 +9927,19 @@ var mParticle = (function () {
9793
9927
  configurable: true
9794
9928
  });
9795
9929
  RoktManager.prototype.attachKit = function (kit) {
9796
- var _a, _b;
9930
+ var _a, _b, _c, _d;
9797
9931
  this.kit = kit;
9932
+ if ((_a = kit.settings) === null || _a === void 0 ? void 0 : _a.accountId) {
9933
+ this.store.setRoktAccountId(kit.settings.accountId);
9934
+ }
9935
+ if (kit.integrationName) {
9936
+ (_b = this.store) === null || _b === void 0 ? void 0 : _b.setIntegrationName(kit.integrationName);
9937
+ }
9798
9938
  this.processMessageQueue();
9799
9939
  try {
9800
- (_a = this.onReadyCallback) === null || _a === void 0 ? void 0 : _a.call(this);
9940
+ (_c = this.onReadyCallback) === null || _c === void 0 ? void 0 : _c.call(this);
9801
9941
  } catch (e) {
9802
- (_b = this.logger) === null || _b === void 0 ? void 0 : _b.error('RoktManager: Error in onReadyCallback: ' + e);
9942
+ (_d = this.logger) === null || _d === void 0 ? void 0 : _d.error('RoktManager: Error in onReadyCallback: ' + e);
9803
9943
  }
9804
9944
  };
9805
9945
  /**
@@ -10239,6 +10379,138 @@ var mParticle = (function () {
10239
10379
  return CookieConsentManager;
10240
10380
  }();
10241
10381
 
10382
+ // Header key constants
10383
+ var HEADER_ACCEPT = 'Accept';
10384
+ var HEADER_CONTENT_TYPE = 'Content-Type';
10385
+ var HEADER_ROKT_LAUNCHER_VERSION = 'rokt-launcher-version';
10386
+ var HEADER_ROKT_LAUNCHER_INSTANCE_GUID = 'rokt-launcher-instance-guid';
10387
+ var HEADER_ROKT_WSDK_VERSION = 'rokt-wsdk-version';
10388
+ var ReportingLogger = /** @class */function () {
10389
+ function ReportingLogger(config, sdkVersion, store, launcherInstanceGuid, rateLimiter) {
10390
+ var _this = this;
10391
+ this.sdkVersion = sdkVersion;
10392
+ this.launcherInstanceGuid = launcherInstanceGuid;
10393
+ this.reporter = 'mp-wsdk';
10394
+ this.isFeatureFlagEnabled = function () {
10395
+ return _this.isLoggingEnabled;
10396
+ };
10397
+ this.loggingUrl = "https://".concat(config.loggingUrl || Constants.DefaultBaseUrls.loggingUrl);
10398
+ this.errorUrl = "https://".concat(config.errorUrl || Constants.DefaultBaseUrls.errorUrl);
10399
+ this.isLoggingEnabled = config.isLoggingEnabled || false;
10400
+ this.store = store !== null && store !== void 0 ? store : null;
10401
+ this.isEnabled = this.isReportingEnabled();
10402
+ this.rateLimiter = rateLimiter !== null && rateLimiter !== void 0 ? rateLimiter : new RateLimiter();
10403
+ }
10404
+ ReportingLogger.prototype.setStore = function (store) {
10405
+ this.store = store;
10406
+ };
10407
+ ReportingLogger.prototype.info = function (msg, code) {
10408
+ this.sendLog(WSDKErrorSeverity.INFO, msg, code);
10409
+ };
10410
+ ReportingLogger.prototype.error = function (msg, code, stackTrace) {
10411
+ this.sendError(WSDKErrorSeverity.ERROR, msg, code, stackTrace);
10412
+ };
10413
+ ReportingLogger.prototype.warning = function (msg, code) {
10414
+ this.sendError(WSDKErrorSeverity.WARNING, msg, code);
10415
+ };
10416
+ ReportingLogger.prototype.sendToServer = function (url, severity, msg, code, stackTrace) {
10417
+ if (!this.canSendLog(severity)) return;
10418
+ try {
10419
+ var logRequest = this.buildLogRequest(severity, msg, code, stackTrace);
10420
+ var uploader = new FetchUploader(url);
10421
+ var payload = {
10422
+ method: 'POST',
10423
+ headers: this.getHeaders(),
10424
+ body: JSON.stringify(logRequest)
10425
+ };
10426
+ uploader.upload(payload)["catch"](function (error) {
10427
+ console.error('ReportingLogger: Failed to send log', error);
10428
+ });
10429
+ } catch (error) {
10430
+ console.error('ReportingLogger: Failed to send log', error);
10431
+ }
10432
+ };
10433
+ ReportingLogger.prototype.sendLog = function (severity, msg, code, stackTrace) {
10434
+ this.sendToServer(this.loggingUrl, severity, msg, code, stackTrace);
10435
+ };
10436
+ ReportingLogger.prototype.sendError = function (severity, msg, code, stackTrace) {
10437
+ this.sendToServer(this.errorUrl, severity, msg, code, stackTrace);
10438
+ };
10439
+ ReportingLogger.prototype.buildLogRequest = function (severity, msg, code, stackTrace) {
10440
+ var _a, _b;
10441
+ return {
10442
+ additionalInformation: {
10443
+ message: msg,
10444
+ version: this.getVersion()
10445
+ },
10446
+ severity: severity,
10447
+ code: code !== null && code !== void 0 ? code : ErrorCodes.UNKNOWN_ERROR,
10448
+ url: this.getUrl(),
10449
+ deviceInfo: this.getUserAgent(),
10450
+ stackTrace: stackTrace,
10451
+ reporter: this.reporter,
10452
+ // Integration will be set to integrationName once the kit connects via RoktManager.attachKit()
10453
+ integration: (_b = (_a = this.store) === null || _a === void 0 ? void 0 : _a.getIntegrationName()) !== null && _b !== void 0 ? _b : 'mp-wsdk'
10454
+ };
10455
+ };
10456
+ ReportingLogger.prototype.getVersion = function () {
10457
+ var _a, _b, _c;
10458
+ return (_c = (_b = (_a = this.store) === null || _a === void 0 ? void 0 : _a.getIntegrationName) === null || _b === void 0 ? void 0 : _b.call(_a)) !== null && _c !== void 0 ? _c : "mParticle_wsdkv_".concat(this.sdkVersion);
10459
+ };
10460
+ ReportingLogger.prototype.isReportingEnabled = function () {
10461
+ return this.isDebugModeEnabled() || this.isRoktDomainPresent() && this.isFeatureFlagEnabled();
10462
+ };
10463
+ ReportingLogger.prototype.isRoktDomainPresent = function () {
10464
+ return typeof window !== 'undefined' && Boolean(window['ROKT_DOMAIN']);
10465
+ };
10466
+ ReportingLogger.prototype.isDebugModeEnabled = function () {
10467
+ var _a, _b, _c, _d;
10468
+ return typeof window !== 'undefined' && ((_d = (_c = (_b = (_a = window.location) === null || _a === void 0 ? void 0 : _a.search) === null || _b === void 0 ? void 0 : _b.toLowerCase()) === null || _c === void 0 ? void 0 : _c.includes('mp_enable_logging=true')) !== null && _d !== void 0 ? _d : false);
10469
+ };
10470
+ ReportingLogger.prototype.canSendLog = function (severity) {
10471
+ return this.isEnabled && !this.isRateLimited(severity);
10472
+ };
10473
+ ReportingLogger.prototype.isRateLimited = function (severity) {
10474
+ return this.rateLimiter.incrementAndCheck(severity);
10475
+ };
10476
+ ReportingLogger.prototype.getUrl = function () {
10477
+ var _a;
10478
+ return typeof window !== 'undefined' ? (_a = window.location) === null || _a === void 0 ? void 0 : _a.href : undefined;
10479
+ };
10480
+ ReportingLogger.prototype.getUserAgent = function () {
10481
+ var _a;
10482
+ return typeof window !== 'undefined' ? (_a = window.navigator) === null || _a === void 0 ? void 0 : _a.userAgent : undefined;
10483
+ };
10484
+ ReportingLogger.prototype.getHeaders = function () {
10485
+ var _a;
10486
+ var _b, _c;
10487
+ var headers = (_a = {}, _a[HEADER_ACCEPT] = 'text/plain;charset=UTF-8', _a[HEADER_CONTENT_TYPE] = 'application/json', _a[HEADER_ROKT_LAUNCHER_VERSION] = this.getVersion(), _a[HEADER_ROKT_WSDK_VERSION] = 'joint', _a);
10488
+ if (this.launcherInstanceGuid) {
10489
+ headers[HEADER_ROKT_LAUNCHER_INSTANCE_GUID] = this.launcherInstanceGuid;
10490
+ }
10491
+ var accountId = (_c = (_b = this.store) === null || _b === void 0 ? void 0 : _b.getRoktAccountId) === null || _c === void 0 ? void 0 : _c.call(_b);
10492
+ if (accountId) {
10493
+ headers['rokt-account-id'] = accountId;
10494
+ }
10495
+ return headers;
10496
+ };
10497
+ return ReportingLogger;
10498
+ }();
10499
+ var RateLimiter = /** @class */function () {
10500
+ function RateLimiter() {
10501
+ this.rateLimits = new Map([[WSDKErrorSeverity.ERROR, 10], [WSDKErrorSeverity.WARNING, 10], [WSDKErrorSeverity.INFO, 10]]);
10502
+ this.logCount = new Map();
10503
+ }
10504
+ RateLimiter.prototype.incrementAndCheck = function (severity) {
10505
+ var count = this.logCount.get(severity) || 0;
10506
+ var limit = this.rateLimits.get(severity) || 10;
10507
+ var newCount = count + 1;
10508
+ this.logCount.set(severity, newCount);
10509
+ return newCount > limit;
10510
+ };
10511
+ return RateLimiter;
10512
+ }();
10513
+
10242
10514
  var Messages = Constants.Messages,
10243
10515
  HTTPCodes = Constants.HTTPCodes,
10244
10516
  FeatureFlags = Constants.FeatureFlags,
@@ -10296,6 +10568,19 @@ var mParticle = (function () {
10296
10568
  self._preInit.readyQueue = processReadyQueue(self._preInit.readyQueue);
10297
10569
  }
10298
10570
  };
10571
+ /**
10572
+ * Drains the ready queue for noFunctional sessions with no explicit identity.
10573
+ */
10574
+ this.processQueueOnNoFunctional = function () {
10575
+ var _a, _b;
10576
+ if ((_a = self._Store) === null || _a === void 0 ? void 0 : _a.isInitialized) {
10577
+ return;
10578
+ }
10579
+ var noFunctionalWithoutId = ((_b = self._CookieConsentManager) === null || _b === void 0 ? void 0 : _b.getNoFunctional()) && !hasExplicitIdentifier(self._Store);
10580
+ if (noFunctionalWithoutId) {
10581
+ self._preInit.readyQueue = processReadyQueue(self._preInit.readyQueue);
10582
+ }
10583
+ };
10299
10584
  // required for forwarders once they reference the mparticle instance
10300
10585
  this.IdentityType = IdentityType;
10301
10586
  this.EventType = EventType;
@@ -10363,12 +10648,14 @@ var mParticle = (function () {
10363
10648
  console.error('Cannot reset mParticle', error);
10364
10649
  }
10365
10650
  };
10366
- this._resetForTests = function (config, keepPersistence, instance) {
10651
+ this._resetForTests = function (config, keepPersistence, instance, reportingLogger) {
10367
10652
  if (instance._Store) {
10368
10653
  delete instance._Store;
10369
10654
  }
10370
- instance.Logger = new Logger(config);
10655
+ instance.Logger = new Logger(config, reportingLogger);
10371
10656
  instance._Store = new Store(config, instance);
10657
+ // Update ReportingLogger with the new Store reference to avoid stale data
10658
+ reportingLogger === null || reportingLogger === void 0 ? void 0 : reportingLogger.setStore(instance._Store);
10372
10659
  instance._Store.isLocalStorageAvailable = instance._Persistence.determineLocalStorageAvailability(window.localStorage);
10373
10660
  instance._Events.stopTracking();
10374
10661
  if (!keepPersistence) {
@@ -10391,8 +10678,9 @@ var mParticle = (function () {
10391
10678
  * @param {Function} f Callback to execute
10392
10679
  */
10393
10680
  this.ready = function (f) {
10394
- var _a, _b;
10395
- var shouldExecute = isFunction(f) && (((_a = self._Store) === null || _a === void 0 ? void 0 : _a.isInitialized) || ((_b = self._Store) === null || _b === void 0 ? void 0 : _b.identityCallFailed) && self._RoktManager.isReady());
10681
+ var _a, _b, _c;
10682
+ var noFunctionalWithoutId = ((_a = self._CookieConsentManager) === null || _a === void 0 ? void 0 : _a.getNoFunctional()) && !hasExplicitIdentifier(self._Store);
10683
+ var shouldExecute = isFunction(f) && (((_b = self._Store) === null || _b === void 0 ? void 0 : _b.isInitialized) || ((_c = self._Store) === null || _c === void 0 ? void 0 : _c.identityCallFailed) && self._RoktManager.isReady() || noFunctionalWithoutId);
10396
10684
  if (shouldExecute) {
10397
10685
  f();
10398
10686
  } else {
@@ -10996,10 +11284,14 @@ var mParticle = (function () {
10996
11284
  * @param {String or Number} value value for session attribute
10997
11285
  */
10998
11286
  this.setSessionAttribute = function (key, value) {
10999
- var queued = queueIfNotInitialized(function () {
11000
- self.setSessionAttribute(key, value);
11001
- }, self);
11002
- if (queued) return;
11287
+ var _a;
11288
+ var skipQueue = ((_a = self._CookieConsentManager) === null || _a === void 0 ? void 0 : _a.getNoFunctional()) && !hasExplicitIdentifier(self._Store);
11289
+ if (!skipQueue) {
11290
+ var queued = queueIfNotInitialized(function () {
11291
+ self.setSessionAttribute(key, value);
11292
+ }, self);
11293
+ if (queued) return;
11294
+ }
11003
11295
  // Logs to cookie
11004
11296
  // And logs to in-memory object
11005
11297
  // Example: mParticle.setSessionAttribute('location', '33431');
@@ -11185,6 +11477,9 @@ var mParticle = (function () {
11185
11477
  window[launcherInstanceGuidKey] = self._Helpers.generateUniqueId();
11186
11478
  }
11187
11479
  };
11480
+ this.getLauncherInstanceGuid = function () {
11481
+ return window[launcherInstanceGuidKey];
11482
+ };
11188
11483
  this.captureTiming = function (metricsName) {
11189
11484
  var _a;
11190
11485
  if (typeof window !== 'undefined' && ((_a = window.performance) === null || _a === void 0 ? void 0 : _a.mark)) {
@@ -11194,6 +11489,7 @@ var mParticle = (function () {
11194
11489
  }
11195
11490
  // Some (server) config settings need to be returned before they are set on SDKConfig in a self hosted environment
11196
11491
  function completeSDKInitialization(apiKey, config, mpInstance) {
11492
+ var _a, _b;
11197
11493
  var kitBlocker = createKitBlocker(config, mpInstance);
11198
11494
  var getFeatureFlag = mpInstance._Helpers.getFeatureFlag;
11199
11495
  mpInstance._APIClient = new APIClient(mpInstance, kitBlocker);
@@ -11239,6 +11535,8 @@ var mParticle = (function () {
11239
11535
  // Configure Rokt Manager with user and filtered user
11240
11536
  var roktConfig = parseConfig(config, 'Rokt', 181);
11241
11537
  if (roktConfig) {
11538
+ var accountId = (_a = roktConfig.settings) === null || _a === void 0 ? void 0 : _a.accountId;
11539
+ mpInstance._Store.setRoktAccountId(accountId);
11242
11540
  var userAttributeFilters = roktConfig.userAttributeFilters;
11243
11541
  var roktFilteredUser = filteredMparticleUser(currentUserMPID, {
11244
11542
  userAttributeFilters: userAttributeFilters
@@ -11265,6 +11563,9 @@ var mParticle = (function () {
11265
11563
  mpInstance._Store.isInitialized = true;
11266
11564
  mpInstance._preInit.readyQueue = processReadyQueue(mpInstance._preInit.readyQueue);
11267
11565
  }
11566
+ // For noFunctional sessions with no identity, drain any pre-init ready callbacks
11567
+ // that were queued before _CookieConsentManager was available to evaluate the condition.
11568
+ (_b = mpInstance.processQueueOnNoFunctional) === null || _b === void 0 ? void 0 : _b.call(mpInstance);
11268
11569
  // https://go.mparticle.com/work/SQDSDKS-6040
11269
11570
  if (mpInstance._Store.isFirstRun) {
11270
11571
  mpInstance._Store.isFirstRun = false;
@@ -11330,15 +11631,25 @@ var mParticle = (function () {
11330
11631
  return kitBlocker;
11331
11632
  }
11332
11633
  function createIdentityCache(mpInstance) {
11634
+ var _a;
11635
+ // Identity expects mpInstance._Identity.idCache to always exist. DisabledVault
11636
+ // ensures no identity response data is written to localStorage when noFunctional is true
11637
+ if ((_a = mpInstance._CookieConsentManager) === null || _a === void 0 ? void 0 : _a.getNoFunctional()) {
11638
+ return new DisabledVault("".concat(mpInstance._Store.storageName, "-id-cache"), {
11639
+ logger: mpInstance.Logger
11640
+ });
11641
+ }
11333
11642
  return new LocalStorageVault("".concat(mpInstance._Store.storageName, "-id-cache"), {
11334
11643
  logger: mpInstance.Logger
11335
11644
  });
11336
11645
  }
11337
11646
  function runPreConfigFetchInitialization(mpInstance, apiKey, config) {
11338
11647
  var _a;
11339
- mpInstance.Logger = new Logger(config);
11648
+ mpInstance._ReportingLogger = new ReportingLogger(config, Constants.sdkVersion, undefined, mpInstance.getLauncherInstanceGuid());
11649
+ mpInstance.Logger = new Logger(config, mpInstance._ReportingLogger);
11340
11650
  mpInstance._Store = new Store(config, mpInstance, apiKey);
11341
11651
  window.mParticle.Store = mpInstance._Store;
11652
+ mpInstance._ReportingLogger.setStore(mpInstance._Store);
11342
11653
  mpInstance.Logger.verbose(StartingInitialization);
11343
11654
  // Initialize CookieConsentManager with privacy flags from launcherOptions
11344
11655
  var _b = (_a = config === null || config === void 0 ? void 0 : config.launcherOptions) !== null && _a !== void 0 ? _a : {},
@@ -11390,18 +11701,21 @@ var mParticle = (function () {
11390
11701
  }
11391
11702
  }
11392
11703
  function queueIfNotInitialized(func, self) {
11393
- var _a;
11394
- // Core SDK methods must wait for Store initialization
11395
- if (!((_a = self._Store) === null || _a === void 0 ? void 0 : _a.isInitialized)) {
11396
- self._preInit.readyQueue.push(function () {
11397
- var _a;
11398
- if ((_a = self._Store) === null || _a === void 0 ? void 0 : _a.isInitialized) {
11399
- func();
11400
- }
11401
- });
11402
- return true;
11704
+ var _a, _b;
11705
+ // When noFunctional is true with no explicit identifier, the SDK will never
11706
+ // receive an MPID. Let these calls through so events can still reach forwarders immediately.
11707
+ // sendEventToServer handles queuing for the MP server upload path separately.
11708
+ var noFunctionalWithoutId = ((_a = self._CookieConsentManager) === null || _a === void 0 ? void 0 : _a.getNoFunctional()) && !hasExplicitIdentifier(self._Store);
11709
+ if (((_b = self._Store) === null || _b === void 0 ? void 0 : _b.isInitialized) || noFunctionalWithoutId) {
11710
+ return false;
11403
11711
  }
11404
- return false;
11712
+ self._preInit.readyQueue.push(function () {
11713
+ var _a;
11714
+ if ((_a = self._Store) === null || _a === void 0 ? void 0 : _a.isInitialized) {
11715
+ func();
11716
+ }
11717
+ });
11718
+ return true;
11405
11719
  }
11406
11720
 
11407
11721
  // This file is used ONLY for the mParticle ESLint plugin. It should NOT be used otherwise!