@mparticle/web-sdk 3.12.1 → 3.14.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.
@@ -20,6 +20,7 @@ interface IntegrationMappingItem {
20
20
  interface IntegrationIdMapping {
21
21
  [key: string]: IntegrationMappingItem;
22
22
  }
23
+ export declare function isIntegrationCaptureEnabled(getFeatureFlag: (feature: string) => unknown): boolean;
23
24
  export default class IntegrationCapture {
24
25
  clickIds: Dictionary<string>;
25
26
  readonly initialTimestamp: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mparticle/web-sdk",
3
- "version": "3.12.1",
3
+ "version": "3.14.0",
4
4
  "description": "mParticle core SDK for web applications",
5
5
  "license": "Apache-2.0",
6
6
  "keywords": [
@@ -15,6 +15,7 @@ import { IMParticleUser } from './identity-user-interfaces';
15
15
  import { IMParticleWebSDKInstance } from './mp-instance';
16
16
  import { appendUserInfo } from './user-utils';
17
17
  import { IntegrationAttributes } from './store';
18
+ import { isIntegrationCaptureEnabled } from './integrationCapture';
18
19
  /**
19
20
  * BatchUploader contains all the logic to store/retrieve events and batches
20
21
  * to/from persistence, and upload batches to mParticle.
@@ -205,12 +206,9 @@ export class BatchUploader {
205
206
 
206
207
  let customFlags: SDKEventCustomFlags = {...event.CustomFlags};
207
208
  let integrationAttributes: IntegrationAttributes = _Store.integrationAttributes;
208
- const integrationSpecificIds = getFeatureFlag(Constants.FeatureFlags.CaptureIntegrationSpecificIds) as boolean;
209
- const integrationSpecificIdsV2 = getFeatureFlag(Constants.FeatureFlags.CaptureIntegrationSpecificIdsV2) as string || '';
210
- const isIntegrationCaptureEnabled = (integrationSpecificIdsV2 && integrationSpecificIdsV2 !== Constants.CaptureIntegrationSpecificIdsV2Modes.None) || integrationSpecificIds === true;
211
209
 
212
210
  // https://go.mparticle.com/work/SQDSDKS-5053
213
- if (isIntegrationCaptureEnabled) {
211
+ if (isIntegrationCaptureEnabled(getFeatureFlag)) {
214
212
 
215
213
  // Attempt to recapture click IDs in case a third party integration
216
214
  // has added or updated new click IDs since the last event was sent.
package/src/consent.ts CHANGED
@@ -182,7 +182,15 @@ export default function Consent(this: IConsent, mpInstance: IMParticleWebSDKInst
182
182
  );
183
183
  return null;
184
184
  }
185
- if (timestamp && isNaN(timestamp)) {
185
+ const isDate = (timestamp as unknown) instanceof Date;
186
+ if (isDate) {
187
+ timestamp = ((timestamp as unknown) as Date).getTime();
188
+ }
189
+ if (
190
+ (timestamp || isDate) &&
191
+ ((typeof timestamp !== 'number' && typeof timestamp !== 'string') ||
192
+ isNaN(timestamp))
193
+ ) {
186
194
  mpInstance.Logger.error(
187
195
  'Timestamp must be a valid number when constructing a Consent object.'
188
196
  );
@@ -316,12 +324,6 @@ export default function Consent(this: IConsent, mpInstance: IMParticleWebSDKInst
316
324
  if (!isObject(minifiedConsent)) {
317
325
  return null;
318
326
  }
319
- const timestampIsObject =
320
- typeof minifiedConsent.ts === 'object' &&
321
- minifiedConsent.ts !== null;
322
- if (timestampIsObject) {
323
- return null;
324
- }
325
327
  return self.createPrivacyConsent(
326
328
  minifiedConsent.c,
327
329
  minifiedConsent.ts,
@@ -160,6 +160,26 @@ const integrationMappingRokt: IntegrationIdMapping = {
160
160
  },
161
161
  };
162
162
 
163
+ export function isIntegrationCaptureEnabled(
164
+ getFeatureFlag: (feature: string) => unknown
165
+ ): boolean {
166
+ if (!getFeatureFlag) {
167
+ return false;
168
+ }
169
+ const integrationSpecificIds = getFeatureFlag(
170
+ Constants.FeatureFlags.CaptureIntegrationSpecificIds
171
+ );
172
+ const integrationSpecificIdsV2 = getFeatureFlag(
173
+ Constants.FeatureFlags.CaptureIntegrationSpecificIdsV2
174
+ );
175
+ return (
176
+ (!!integrationSpecificIdsV2 &&
177
+ integrationSpecificIdsV2 !==
178
+ Constants.CaptureIntegrationSpecificIdsV2Modes.None) ||
179
+ integrationSpecificIds === true
180
+ );
181
+ }
182
+
163
183
  export default class IntegrationCapture {
164
184
  public clickIds: Dictionary<string>;
165
185
  public readonly initialTimestamp: number;
@@ -390,10 +390,14 @@ export default class KitBlocker {
390
390
  return clonedEvent;
391
391
  }
392
392
  if (matchedEvent) {
393
- for (const key of Object.keys(clonedEvent.EventAttributes ?? {})) {
394
- if (!matchedEvent[key]) {
395
- delete clonedEvent.EventAttributes[key];
393
+ if (clonedEvent.EventAttributes) {
394
+ const plannedEventAttributes = {};
395
+ for (const key of Object.keys(clonedEvent.EventAttributes)) {
396
+ if (matchedEvent[key] === true) {
397
+ plannedEventAttributes[key] = clonedEvent.EventAttributes[key];
398
+ }
396
399
  }
400
+ clonedEvent.EventAttributes = plannedEventAttributes;
397
401
  }
398
402
  return clonedEvent;
399
403
  } else {
@@ -42,7 +42,7 @@ import IdentityAPIClient, { IIdentityApiClient } from './identityApiClient';
42
42
  import { isFunction, parseConfig, valueof, generateDeprecationMessage, extend } from './utils';
43
43
  import { DisabledVault, LocalStorageVault } from './vault';
44
44
  import { removeExpiredIdentityCacheDates, hasExplicitIdentifier } from './identity-utils';
45
- import IntegrationCapture from './integrationCapture';
45
+ import IntegrationCapture, { isIntegrationCaptureEnabled } from './integrationCapture';
46
46
  import { IPreInit, processReadyQueue } from './pre-init-utils';
47
47
  import { BaseEvent, MParticleWebSDK, SDKHelpersApi } from './sdkRuntimeModels';
48
48
  import { Dictionary, SDKEventAttrs } from '@mparticle/web-sdk';
@@ -1389,11 +1389,9 @@ function completeSDKInitialization(apiKey, config, mpInstance) {
1389
1389
  mpInstance._ForwardingStatsUploader.startForwardingStatsTimer();
1390
1390
  }
1391
1391
  // https://go.mparticle.com/work/SQDSDKS-7639
1392
- const integrationSpecificIds = getFeatureFlag(CaptureIntegrationSpecificIds) as boolean;
1393
- const integrationSpecificIdsV2 = getFeatureFlag(CaptureIntegrationSpecificIdsV2) as string;
1394
-
1395
- const isIntegrationCaptureEnabled = (integrationSpecificIdsV2 && integrationSpecificIdsV2 !== CaptureIntegrationSpecificIdsV2Modes.None) || integrationSpecificIds === true;
1396
- if (isIntegrationCaptureEnabled) {
1392
+ if (isIntegrationCaptureEnabled(getFeatureFlag)) {
1393
+ const integrationSpecificIds = getFeatureFlag(CaptureIntegrationSpecificIds) as boolean;
1394
+ const integrationSpecificIdsV2 = getFeatureFlag(CaptureIntegrationSpecificIdsV2) as string;
1397
1395
  let captureMode: valueof<typeof CaptureIntegrationSpecificIdsV2Modes> | undefined;
1398
1396
  if (integrationSpecificIds || integrationSpecificIdsV2 === CaptureIntegrationSpecificIdsV2Modes.All) {
1399
1397
  captureMode = 'all';
@@ -362,36 +362,28 @@ export default function _Persistence(
362
362
  return data;
363
363
  }
364
364
 
365
- this.getLocalStorage = function(): IPersistenceMinified | null {
366
- if (!mpInstance._Store.isLocalStorageAvailable) {
365
+ function parsePersistenceRecord(
366
+ raw: string | null
367
+ ): IPersistenceMinified | null {
368
+ const decoded = self.decodePersistence(raw);
369
+ if (!decoded) {
367
370
  return null;
368
371
  }
372
+ const record = JSON.parse(decoded);
373
+ return mpInstance._Helpers.isObject(record) &&
374
+ Object.keys(record).length
375
+ ? (record as IPersistenceMinified)
376
+ : null;
377
+ }
369
378
 
370
- const key = mpInstance._Store.storageName;
371
- const decodedPersistence = self.decodePersistence(
372
- window.localStorage.getItem(key)
373
- );
374
-
375
- if (!decodedPersistence) {
379
+ this.getLocalStorage = function(): IPersistenceMinified | null {
380
+ if (!mpInstance._Store.isLocalStorageAvailable) {
376
381
  return null;
377
382
  }
378
383
 
379
- const parsedPersistence = JSON.parse(
380
- decodedPersistence
381
- ) as IPersistenceMinified;
382
- const obj: IPersistenceMinified = {} as IPersistenceMinified;
383
-
384
- for (const key in parsedPersistence) {
385
- if (parsedPersistence.hasOwnProperty(key)) {
386
- obj[key] = parsedPersistence[key];
387
- }
388
- }
389
-
390
- if (Object.keys(obj).length) {
391
- return obj;
392
- }
393
-
394
- return null;
384
+ return parsePersistenceRecord(
385
+ window.localStorage.getItem(mpInstance._Store.storageName)
386
+ );
395
387
  };
396
388
 
397
389
  this.expireCookies = function(cookieName: string): void {
@@ -443,14 +435,11 @@ export default function _Persistence(
443
435
  }
444
436
 
445
437
  if (key && key === name) {
446
- const decodedPersistence = self.decodePersistence(
438
+ const persistence = parsePersistenceRecord(
447
439
  (mpInstance._Helpers as Dictionary).converted(cookie)
448
440
  );
449
- const persistence = decodedPersistence
450
- ? JSON.parse(decodedPersistence)
451
- : null;
452
441
 
453
- if (mpInstance._Helpers.isObject(persistence)) {
442
+ if (persistence) {
454
443
  mpInstance.Logger.verbose(
455
444
  Messages.InformationMessages.CookieFound
456
445
  );
@@ -15,14 +15,8 @@ import Types, { getEventCategoryFromCustomEventType } from './types';
15
15
  import { Dictionary, isEmpty } from './utils';
16
16
  import { ISDKUserIdentity } from './identity-user-interfaces';
17
17
  import { SDKIdentityTypeEnum } from './identity.interfaces';
18
- import Constants from './constants';
19
18
  import { IMParticleWebSDKInstance } from './mp-instance';
20
-
21
- const { FeatureFlags } = Constants;
22
- const {
23
- CaptureIntegrationSpecificIds,
24
- CaptureIntegrationSpecificIdsV2,
25
- } = FeatureFlags;
19
+ import { isIntegrationCaptureEnabled } from './integrationCapture';
26
20
 
27
21
  type PartnerIdentities = Dictionary<string>;
28
22
 
@@ -127,12 +121,7 @@ export function convertEvents(
127
121
  };
128
122
  }
129
123
  // https://go.mparticle.com/work/SQDSDKS-7639
130
- const integrationSpecificIds = getFeatureFlag && Boolean(getFeatureFlag(CaptureIntegrationSpecificIds));
131
- const integrationSpecificIdsV2 = getFeatureFlag && (getFeatureFlag(CaptureIntegrationSpecificIdsV2) as string);
132
-
133
- const isIntegrationCaptureEnabled = (integrationSpecificIdsV2 && integrationSpecificIdsV2 !== Constants.CaptureIntegrationSpecificIdsV2Modes.None) || integrationSpecificIds === true;
134
-
135
- if (isIntegrationCaptureEnabled) {
124
+ if (isIntegrationCaptureEnabled(getFeatureFlag)) {
136
125
  _IntegrationCapture?.capture();
137
126
  const capturedPartnerIdentities: PartnerIdentities = _IntegrationCapture?.getClickIdsAsPartnerIdentities();
138
127
  if (!isEmpty(capturedPartnerIdentities)) {
@@ -30,6 +30,7 @@ import {
30
30
  import { IMParticleUser, ISDKUserIdentity } from './identity-user-interfaces';
31
31
  import { IMParticleWebSDKInstance } from './mp-instance';
32
32
  import { appendUserInfo } from './user-utils';
33
+ import { isIntegrationCaptureEnabled } from './integrationCapture';
33
34
 
34
35
  const MessageType = Types.MessageType;
35
36
  const ApplicationTransitionType = Types.ApplicationTransitionType;
@@ -281,10 +282,7 @@ export default function ServerModel(
281
282
  const { getFeatureFlag } = mpInstance._Helpers;
282
283
  // https://go.mparticle.com/work/SQDSDKS-5053
283
284
  // https://go.mparticle.com/work/SQDSDKS-7639
284
- const integrationSpecificIds = getFeatureFlag && (getFeatureFlag(Constants.FeatureFlags.CaptureIntegrationSpecificIds) as boolean);
285
- const integrationSpecificIdsV2 = getFeatureFlag && ((getFeatureFlag(Constants.FeatureFlags.CaptureIntegrationSpecificIdsV2) as string) || '');
286
- const isIntegrationCaptureEnabled = (integrationSpecificIdsV2 && integrationSpecificIdsV2 !== Constants.CaptureIntegrationSpecificIdsV2Modes.None) || integrationSpecificIds === true;
287
- if (isIntegrationCaptureEnabled) {
285
+ if (isIntegrationCaptureEnabled(getFeatureFlag)) {
288
286
  // Attempt to recapture click IDs in case a third party integration
289
287
  // has added or updated new click IDs since the last event was sent.
290
288
  mpInstance._IntegrationCapture.capture();