@mparticle/web-sdk 2.32.3 → 2.32.5

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.
@@ -115,10 +115,10 @@ export interface IdentityModifyResultBody {
115
115
  }
116
116
 
117
117
  export interface mParticleUserCart {
118
- add(product: Product, logEvent: boolean): void;
119
- remove(product: Product, logEvent: boolean): void;
118
+ add(product: SDKProduct | SDKProduct[], logEvent: boolean): void;
119
+ remove(product: SDKProduct | SDKProduct[], logEvent: boolean): void;
120
120
  clear(): void;
121
- getCartProducts(): Product[];
121
+ getCartProducts(): SDKProduct[];
122
122
  }
123
123
 
124
124
  // https://go.mparticle.com/work/SQDSDKS-5196
@@ -24,7 +24,7 @@ import {
24
24
  IdentityResultBody,
25
25
  IIdentityResponse,
26
26
  } from './identity-user-interfaces';
27
- import { MParticleWebSDK } from './sdkRuntimeModels';
27
+ import { IMParticleWebSDKInstance } from './mp-instance';
28
28
 
29
29
  const { HTTPCodes, Messages, IdentityMethods } = Constants;
30
30
 
@@ -82,7 +82,7 @@ interface IAliasErrorResponse extends IdentityApiError {}
82
82
 
83
83
  export default function IdentityAPIClient(
84
84
  this: IIdentityApiClient,
85
- mpInstance: MParticleWebSDK
85
+ mpInstance: IMParticleWebSDKInstance
86
86
  ) {
87
87
  this.sendAliasRequest = async function(
88
88
  aliasRequest: IAliasRequest,
@@ -190,10 +190,13 @@ export default class IntegrationCapture {
190
190
  return mappedClickIds;
191
191
  }
192
192
 
193
- for (const [key, value] of Object.entries(clickIds)) {
194
- const mappedKey = mappingList[key]?.mappedKey;
195
- if (!isEmpty(mappedKey)) {
196
- mappedClickIds[mappedKey] = value;
193
+ for (const key in clickIds) {
194
+ if (clickIds.hasOwnProperty(key)) {
195
+ const value = clickIds[key];
196
+ const mappedKey = mappingList[key]?.mappedKey;
197
+ if (!isEmpty(mappedKey)) {
198
+ mappedClickIds[mappedKey] = value;
199
+ }
197
200
  }
198
201
  }
199
202
 
@@ -207,12 +210,11 @@ export default class IntegrationCapture {
207
210
  ): Dictionary<string> {
208
211
  const processedClickIds: Dictionary<string> = {};
209
212
 
210
- for (const [key, value] of Object.entries(clickIds)) {
211
- const processor = integrationMapping[key]?.processor;
212
- if (processor) {
213
- processedClickIds[key] = processor(value, url, timestamp);
214
- } else {
215
- processedClickIds[key] = value;
213
+ for (const key in clickIds) {
214
+ if (clickIds.hasOwnProperty(key)) {
215
+ const value = clickIds[key];
216
+ const processor = integrationMapping[key]?.processor;
217
+ processedClickIds[key] = processor ? processor(value, url, timestamp) : value;
216
218
  }
217
219
  }
218
220
 
@@ -3,6 +3,7 @@ import { SDKEvent, MParticleWebSDK, KitBlockerDataPlan, SDKProduct } from './sdk
3
3
  import { BaseEvent, EventTypeEnum, CommerceEvent, ScreenViewEvent, CustomEvent } from '@mparticle/event-models';
4
4
  import Types from './types'
5
5
  import { DataPlanPoint } from '@mparticle/data-planning-models';
6
+ import { IMParticleWebSDKInstance } from './mp-instance';
6
7
 
7
8
  /*
8
9
  TODO: Including this as a workaround because attempting to import it from
@@ -41,9 +42,9 @@ export default class KitBlocker {
41
42
  blockUserAttributes = false;
42
43
  blockUserIdentities = false;
43
44
  kitBlockingEnabled = false;
44
- mpInstance: MParticleWebSDK;
45
+ mpInstance: IMParticleWebSDKInstance;
45
46
 
46
- constructor(dataPlan: KitBlockerDataPlan, mpInstance: MParticleWebSDK) {
47
+ constructor(dataPlan: KitBlockerDataPlan, mpInstance: IMParticleWebSDKInstance) {
47
48
  // if data plan is not requested, the data plan is {document: null}
48
49
  if (dataPlan && !dataPlan.document) {
49
50
  this.kitBlockingEnabled = false;
@@ -1,11 +1,10 @@
1
1
  // This file is used ONLY for the mParticle ESLint plugin. It should NOT be used otherwise!
2
2
 
3
3
  import ServerModel from './serverModel';
4
- import { SDKEvent, BaseEvent, MParticleWebSDK } from './sdkRuntimeModels';
4
+ import { SDKEvent, BaseEvent } from './sdkRuntimeModels';
5
5
  import { convertEvents } from './sdkToEventsApiConverter';
6
- import * as EventsApi from '@mparticle/event-models';
7
6
  import { Batch } from '@mparticle/event-models';
8
- import { IMPSideloadedKit } from './sideloadedKit';
7
+ import { IMParticleWebSDKInstance } from './mp-instance';
9
8
 
10
9
  const mockFunction = function() {
11
10
  return null;
@@ -15,7 +14,7 @@ export default class _BatchValidator {
15
14
  return ({
16
15
  // Certain Helper, Store, and Identity properties need to be mocked to be used in the `returnBatch` method
17
16
  _Helpers: {
18
- sanitizeAttributes: window.mParticle.getInstance()._Helpers
17
+ sanitizeAttributes: (window.mParticle.getInstance() as unknown as IMParticleWebSDKInstance)._Helpers
19
18
  .sanitizeAttributes,
20
19
  generateHash: function() {
21
20
  return 'mockHash';
@@ -23,7 +22,7 @@ export default class _BatchValidator {
23
22
  generateUniqueId: function() {
24
23
  return 'mockId';
25
24
  },
26
- extend: window.mParticle.getInstance()._Helpers.extend,
25
+ extend: (window.mParticle.getInstance() as unknown as IMParticleWebSDKInstance)._Helpers.extend,
27
26
  createServiceUrl: mockFunction,
28
27
  parseNumber: mockFunction,
29
28
  isObject: mockFunction,
@@ -118,7 +117,7 @@ export default class _BatchValidator {
118
117
  logLevel: 'none',
119
118
  setPosition: mockFunction,
120
119
  upload: mockFunction,
121
- } as unknown) as MParticleWebSDK;
120
+ } as unknown) as IMParticleWebSDKInstance;
122
121
  }
123
122
 
124
123
  private createSDKEventFunction(event): SDKEvent {
@@ -16,31 +16,75 @@
16
16
  // Uses portions of code from jQuery
17
17
  // jQuery v1.10.2 | (c) 2005, 2013 jQuery Foundation, Inc. | jquery.org/license
18
18
 
19
- import Types from './types';
19
+ import { EventType, IdentityType, CommerceEventType, PromotionActionType, ProductActionType, MessageType } from './types';
20
20
  import Constants from './constants';
21
- import APIClient from './apiClient';
21
+ import APIClient, { IAPIClient } from './apiClient';
22
22
  import Helpers from './helpers';
23
23
  import NativeSdkHelpers from './nativeSdkHelpers';
24
- import CookieSyncManager from './cookieSyncManager';
25
- import SessionManager from './sessionManager';
24
+ import CookieSyncManager, { ICookieSyncManager } from './cookieSyncManager';
25
+ import SessionManager, { ISessionManager } from './sessionManager';
26
26
  import Ecommerce from './ecommerce';
27
- import Store from './store';
27
+ import Store, { IStore } from './store';
28
28
  import Logger from './logger';
29
29
  import Persistence from './persistence';
30
30
  import Events from './events';
31
31
  import Forwarders from './forwarders';
32
- import ServerModel from './serverModel';
32
+ import ServerModel, { IServerModel } from './serverModel';
33
33
  import ForwardingStatsUploader from './forwardingStatsUploader';
34
34
  import Identity from './identity';
35
- import Consent from './consent';
35
+ import Consent, { IConsent } from './consent';
36
36
  import KitBlocker from './kitBlocking';
37
37
  import ConfigAPIClient from './configAPIClient';
38
38
  import IdentityAPIClient from './identityApiClient';
39
- import { isFunction } from './utils';
39
+ import { isFunction, valueof } from './utils';
40
40
  import { LocalStorageVault } from './vault';
41
41
  import { removeExpiredIdentityCacheDates } from './identity-utils';
42
42
  import IntegrationCapture from './integrationCapture';
43
- import { processReadyQueue } from './pre-init-utils';
43
+ import { IPreInit, processReadyQueue } from './pre-init-utils';
44
+ import { BaseEvent, MParticleWebSDK, SDKHelpersApi } from './sdkRuntimeModels';
45
+ import { Dictionary, SDKEventAttrs } from '@mparticle/web-sdk';
46
+ import { IIdentity } from './identity.interfaces';
47
+ import { IEvents } from './events.interfaces';
48
+ import { IECommerce } from './ecommerce.interfaces';
49
+ import { INativeSdkHelpers } from './nativeSdkHelpers.interfaces';
50
+ import { IPersistence } from './persistence.interfaces';
51
+
52
+ export interface IErrorLogMessage {
53
+ message?: string;
54
+ name?: string;
55
+ stack?: string;
56
+ }
57
+
58
+ export interface IErrorLogMessageMinified {
59
+ m?: string;
60
+ s?: string;
61
+ t?: string;
62
+ }
63
+
64
+ export type IntegrationDelays = Dictionary<boolean>;
65
+
66
+ // https://go.mparticle.com/work/SQDSDKS-6949
67
+ export interface IMParticleWebSDKInstance extends MParticleWebSDK {
68
+ // Private Properties
69
+ _APIClient: IAPIClient;
70
+ _Consent: IConsent;
71
+ _CookieSyncManager: ICookieSyncManager;
72
+ _Ecommerce: IECommerce;
73
+ _Events: IEvents;
74
+ _Forwarders: any; // https://go.mparticle.com/work/SQDSDKS-5767
75
+ _ForwardingStatsUploader: ForwardingStatsUploader;
76
+ _Helpers: SDKHelpersApi;
77
+ _Identity: IIdentity;
78
+ _IdentityAPIClient: typeof IdentityAPIClient;
79
+ _IntegrationCapture: IntegrationCapture;
80
+ _NativeSdkHelpers: INativeSdkHelpers;
81
+ _Persistence: IPersistence;
82
+ _SessionManager: ISessionManager;
83
+ _ServerModel: IServerModel;
84
+ _Store: IStore;
85
+ _instanceName: string;
86
+ _preInit: IPreInit;
87
+ }
44
88
 
45
89
  const { Messages, HTTPCodes, FeatureFlags } = Constants;
46
90
  const { ReportBatching, CaptureIntegrationSpecificIds } = FeatureFlags;
@@ -59,8 +103,8 @@ const { StartingInitialization } = Messages.InformationMessages;
59
103
  * @class mParticle & mParticleInstance
60
104
  */
61
105
 
62
- export default function mParticleInstance(instanceName) {
63
- var self = this;
106
+ export default function mParticleInstance(this: IMParticleWebSDKInstance, instanceName: string) {
107
+ const self = this;
64
108
  // These classes are for internal use only. Not documented for public consumption
65
109
  this._instanceName = instanceName;
66
110
  this._NativeSdkHelpers = new NativeSdkHelpers(this);
@@ -82,11 +126,12 @@ export default function mParticleInstance(instanceName) {
82
126
  this._IntegrationCapture = new IntegrationCapture();
83
127
 
84
128
  // required for forwarders once they reference the mparticle instance
85
- this.IdentityType = Types.IdentityType;
86
- this.EventType = Types.EventType;
87
- this.CommerceEventType = Types.CommerceEventType;
88
- this.PromotionType = Types.PromotionActionType;
89
- this.ProductActionType = Types.ProductActionType;
129
+ this.IdentityType = IdentityType;
130
+ this.EventType = EventType as unknown as valueof<typeof EventType>;
131
+ this.CommerceEventType = CommerceEventType as unknown as valueof<typeof CommerceEventType>;
132
+ this.PromotionType = PromotionActionType as unknown as valueof<typeof PromotionActionType>;
133
+ this.ProductActionType = ProductActionType as unknown as valueof<typeof ProductActionType>;
134
+
90
135
 
91
136
  this._Identity = new Identity(this);
92
137
  this.Identity = this._Identity.IdentityAPI;
@@ -229,7 +274,7 @@ export default function mParticleInstance(instanceName) {
229
274
  * @param {String} version version number
230
275
  */
231
276
  this.setAppVersion = function(version) {
232
- var queued = queueIfNotInitialized(function() {
277
+ const queued = queueIfNotInitialized(function() {
233
278
  self.setAppVersion(version);
234
279
  }, self);
235
280
 
@@ -244,7 +289,7 @@ export default function mParticleInstance(instanceName) {
244
289
  * @param {String} name device ID (UUIDv4-formatted string)
245
290
  */
246
291
  this.setDeviceId = function(guid) {
247
- var queued = queueIfNotInitialized(function() {
292
+ const queued = queueIfNotInitialized(function() {
248
293
  self.setDeviceId(guid);
249
294
  }, self);
250
295
  if (queued) return;
@@ -273,7 +318,7 @@ export default function mParticleInstance(instanceName) {
273
318
  * @param {String} name App Name
274
319
  */
275
320
  this.setAppName = function(name) {
276
- var queued = queueIfNotInitialized(function() {
321
+ const queued = queueIfNotInitialized(function() {
277
322
  self.setAppName(name);
278
323
  }, self);
279
324
 
@@ -319,7 +364,7 @@ export default function mParticleInstance(instanceName) {
319
364
  * @param {Number} longitude longitude digit
320
365
  */
321
366
  this.setPosition = function(lat, lng) {
322
- var queued = queueIfNotInitialized(function() {
367
+ const queued = queueIfNotInitialized(function() {
323
368
  self.setPosition(lat, lng);
324
369
  }, self);
325
370
 
@@ -359,7 +404,7 @@ export default function mParticleInstance(instanceName) {
359
404
  * @param {Object} [eventOptions] For Event-level Configuration Options
360
405
  */
361
406
  this.logBaseEvent = function(event, eventOptions) {
362
- var queued = queueIfNotInitialized(function() {
407
+ const queued = queueIfNotInitialized(function() {
363
408
  self.logBaseEvent(event, eventOptions);
364
409
  }, self);
365
410
 
@@ -372,7 +417,7 @@ export default function mParticleInstance(instanceName) {
372
417
  }
373
418
 
374
419
  if (!event.eventType) {
375
- event.eventType = Types.EventType.Unknown;
420
+ event.eventType = EventType.Unknown;
376
421
  }
377
422
 
378
423
  if (!self._Helpers.canLog()) {
@@ -398,7 +443,7 @@ export default function mParticleInstance(instanceName) {
398
443
  customFlags,
399
444
  eventOptions
400
445
  ) {
401
- var queued = queueIfNotInitialized(function() {
446
+ const queued = queueIfNotInitialized(function() {
402
447
  self.logEvent(
403
448
  eventName,
404
449
  eventType,
@@ -417,7 +462,7 @@ export default function mParticleInstance(instanceName) {
417
462
  }
418
463
 
419
464
  if (!eventType) {
420
- eventType = Types.EventType.Unknown;
465
+ eventType = EventType.Unknown;
421
466
  }
422
467
 
423
468
  if (!self._Helpers.isEventType(eventType)) {
@@ -425,7 +470,7 @@ export default function mParticleInstance(instanceName) {
425
470
  'Invalid event type: ' +
426
471
  eventType +
427
472
  ', must be one of: \n' +
428
- JSON.stringify(Types.EventType)
473
+ JSON.stringify(EventType)
429
474
  );
430
475
  return;
431
476
  }
@@ -437,12 +482,12 @@ export default function mParticleInstance(instanceName) {
437
482
 
438
483
  self._Events.logEvent(
439
484
  {
440
- messageType: Types.MessageType.PageEvent,
485
+ messageType: MessageType.PageEvent,
441
486
  name: eventName,
442
487
  data: eventInfo,
443
488
  eventType: eventType,
444
489
  customFlags: customFlags,
445
- },
490
+ } as BaseEvent,
446
491
  eventOptions
447
492
  );
448
493
  };
@@ -454,7 +499,7 @@ export default function mParticleInstance(instanceName) {
454
499
  * @param {Object} [attrs] Custom attrs to be passed along with the error event; values must be string, number, or boolean
455
500
  */
456
501
  this.logError = function(error, attrs) {
457
- var queued = queueIfNotInitialized(function() {
502
+ const queued = queueIfNotInitialized(function() {
458
503
  self.logError(error, attrs);
459
504
  }, self);
460
505
 
@@ -471,24 +516,24 @@ export default function mParticleInstance(instanceName) {
471
516
  };
472
517
  }
473
518
 
474
- var data = {
475
- m: error.message ? error.message : error,
519
+ const data: IErrorLogMessageMinified = {
520
+ m: error.message ? error.message : error as string,
476
521
  s: 'Error',
477
522
  t: error.stack || null,
478
523
  };
479
524
 
480
525
  if (attrs) {
481
- var sanitized = self._Helpers.sanitizeAttributes(attrs, data.m);
482
- for (var prop in sanitized) {
526
+ const sanitized = self._Helpers.sanitizeAttributes(attrs, data.m);
527
+ for (const prop in sanitized) {
483
528
  data[prop] = sanitized[prop];
484
529
  }
485
530
  }
486
531
 
487
532
  self._Events.logEvent({
488
- messageType: Types.MessageType.CrashReport,
533
+ messageType: MessageType.CrashReport,
489
534
  name: error.name ? error.name : 'Error',
490
- data: data,
491
- eventType: Types.EventType.Other,
535
+ eventType: EventType.Other,
536
+ data: data as SDKEventAttrs,
492
537
  });
493
538
  };
494
539
  /**
@@ -534,7 +579,7 @@ export default function mParticleInstance(instanceName) {
534
579
  * @param {Object} [eventOptions] For Event-level Configuration Options
535
580
  */
536
581
  this.logPageView = function(eventName, attrs, customFlags, eventOptions) {
537
- var queued = queueIfNotInitialized(function() {
582
+ const queued = queueIfNotInitialized(function() {
538
583
  self.logPageView(eventName, attrs, customFlags, eventOptions);
539
584
  }, self);
540
585
 
@@ -571,10 +616,10 @@ export default function mParticleInstance(instanceName) {
571
616
 
572
617
  self._Events.logEvent(
573
618
  {
574
- messageType: Types.MessageType.PageView,
619
+ messageType: MessageType.PageView,
575
620
  name: eventName,
576
- data: attrs,
577
- eventType: Types.EventType.Unknown,
621
+ data: attrs as SDKEventAttrs,
622
+ eventType: EventType.Unknown,
578
623
  customFlags: customFlags,
579
624
  },
580
625
  eventOptions
@@ -658,8 +703,8 @@ export default function mParticleInstance(instanceName) {
658
703
  self.Logger.warning(
659
704
  'Deprecated function eCommerce.Cart.add() will be removed in future releases'
660
705
  );
661
- var mpid,
662
- currentUser = self.Identity.getCurrentUser();
706
+ let mpid;
707
+ const currentUser = self.Identity.getCurrentUser();
663
708
  if (currentUser) {
664
709
  mpid = currentUser.getMPID();
665
710
  }
@@ -678,8 +723,8 @@ export default function mParticleInstance(instanceName) {
678
723
  self.Logger.warning(
679
724
  'Deprecated function eCommerce.Cart.remove() will be removed in future releases'
680
725
  );
681
- var mpid,
682
- currentUser = self.Identity.getCurrentUser();
726
+ let mpid;
727
+ const currentUser = self.Identity.getCurrentUser();
683
728
  if (currentUser) {
684
729
  mpid = currentUser.getMPID();
685
730
  }
@@ -696,8 +741,8 @@ export default function mParticleInstance(instanceName) {
696
741
  self.Logger.warning(
697
742
  'Deprecated function eCommerce.Cart.clear() will be removed in future releases'
698
743
  );
699
- var mpid,
700
- currentUser = self.Identity.getCurrentUser();
744
+ let mpid;
745
+ const currentUser = self.Identity.getCurrentUser();
701
746
  if (currentUser) {
702
747
  mpid = currentUser.getMPID();
703
748
  }
@@ -711,7 +756,7 @@ export default function mParticleInstance(instanceName) {
711
756
  * @param {String} code The currency code
712
757
  */
713
758
  setCurrencyCode: function(code) {
714
- var queued = queueIfNotInitialized(function() {
759
+ const queued = queueIfNotInitialized(function() {
715
760
  self.eCommerce.setCurrencyCode(code);
716
761
  }, self);
717
762
 
@@ -869,7 +914,7 @@ export default function mParticleInstance(instanceName) {
869
914
  transactionAttributes,
870
915
  eventOptions
871
916
  ) {
872
- var queued = queueIfNotInitialized(function() {
917
+ const queued = queueIfNotInitialized(function() {
873
918
  self.eCommerce.logProductAction(
874
919
  productActionType,
875
920
  product,
@@ -954,7 +999,7 @@ export default function mParticleInstance(instanceName) {
954
999
  customFlags,
955
1000
  eventOptions
956
1001
  ) {
957
- var queued = queueIfNotInitialized(function() {
1002
+ const queued = queueIfNotInitialized(function() {
958
1003
  self.eCommerce.logPromotion(
959
1004
  type,
960
1005
  promotion,
@@ -985,7 +1030,7 @@ export default function mParticleInstance(instanceName) {
985
1030
  * @param {Object} [eventOptions] For Event-level Configuration Options
986
1031
  */
987
1032
  logImpression: function(impression, attrs, customFlags, eventOptions) {
988
- var queued = queueIfNotInitialized(function() {
1033
+ const queued = queueIfNotInitialized(function() {
989
1034
  self.eCommerce.logImpression(
990
1035
  impression,
991
1036
  attrs,
@@ -1056,7 +1101,7 @@ export default function mParticleInstance(instanceName) {
1056
1101
  * @param {String or Number} value value for session attribute
1057
1102
  */
1058
1103
  this.setSessionAttribute = function(key, value) {
1059
- var queued = queueIfNotInitialized(function() {
1104
+ const queued = queueIfNotInitialized(function() {
1060
1105
  self.setSessionAttribute(key, value);
1061
1106
  }, self);
1062
1107
 
@@ -1082,7 +1127,7 @@ export default function mParticleInstance(instanceName) {
1082
1127
  JSON.stringify({ key: key, value: value })
1083
1128
  );
1084
1129
  } else {
1085
- var existingProp = self._Helpers.findKeyInObject(
1130
+ const existingProp = self._Helpers.findKeyInObject(
1086
1131
  self._Store.sessionAttributes,
1087
1132
  key
1088
1133
  );
@@ -1107,7 +1152,7 @@ export default function mParticleInstance(instanceName) {
1107
1152
  * @param {Boolean} isOptingOut boolean to opt out or not. When set to true, opt out of logging.
1108
1153
  */
1109
1154
  this.setOptOut = function(isOptingOut) {
1110
- var queued = queueIfNotInitialized(function() {
1155
+ const queued = queueIfNotInitialized(function() {
1111
1156
  self.setOptOut(isOptingOut);
1112
1157
  }, self);
1113
1158
 
@@ -1122,7 +1167,7 @@ export default function mParticleInstance(instanceName) {
1122
1167
  if (self._Store.activeForwarders.length) {
1123
1168
  self._Store.activeForwarders.forEach(function(forwarder) {
1124
1169
  if (forwarder.setOptOut) {
1125
- var result = forwarder.setOptOut(isOptingOut);
1170
+ const result = forwarder.setOptOut(isOptingOut);
1126
1171
 
1127
1172
  if (result) {
1128
1173
  self.Logger.verbose(result);
@@ -1145,7 +1190,7 @@ export default function mParticleInstance(instanceName) {
1145
1190
  * also pass a null or empty map here to remove all of the attributes.
1146
1191
  */
1147
1192
  this.setIntegrationAttribute = function(integrationId, attrs) {
1148
- var queued = queueIfNotInitialized(function() {
1193
+ const queued = queueIfNotInitialized(function() {
1149
1194
  self.setIntegrationAttribute(integrationId, attrs);
1150
1195
  }, self);
1151
1196
 
@@ -1161,7 +1206,7 @@ export default function mParticleInstance(instanceName) {
1161
1206
  if (Object.keys(attrs).length === 0) {
1162
1207
  self._Store.integrationAttributes[integrationId] = {};
1163
1208
  } else {
1164
- for (var key in attrs) {
1209
+ for (const key in attrs) {
1165
1210
  if (typeof key === 'string') {
1166
1211
  if (typeof attrs[key] === 'string') {
1167
1212
  if (
@@ -1281,7 +1326,7 @@ export default function mParticleInstance(instanceName) {
1281
1326
 
1282
1327
  // Internal use only. Used by our wrapper SDKs to identify themselves during initialization.
1283
1328
  this._setWrapperSDKInfo = function(name, version) {
1284
- var queued = queueIfNotInitialized(function() {
1329
+ const queued = queueIfNotInitialized(function() {
1285
1330
  self._setWrapperSDKInfo(name, version);
1286
1331
  }, self);
1287
1332
 
@@ -1302,7 +1347,7 @@ export default function mParticleInstance(instanceName) {
1302
1347
 
1303
1348
  // Some (server) config settings need to be returned before they are set on SDKConfig in a self hosted environment
1304
1349
  function completeSDKInitialization(apiKey, config, mpInstance) {
1305
- var kitBlocker = createKitBlocker(config, mpInstance);
1350
+ const kitBlocker = createKitBlocker(config, mpInstance);
1306
1351
 
1307
1352
  mpInstance._APIClient = new APIClient(mpInstance, kitBlocker);
1308
1353
  mpInstance._Forwarders = new Forwarders(mpInstance, kitBlocker);
@@ -1381,8 +1426,12 @@ function completeSDKInitialization(apiKey, config, mpInstance) {
1381
1426
  }
1382
1427
  }
1383
1428
 
1429
+ // https://go.mparticle.com/work/SQDSDKS-7061
1384
1430
  function createKitBlocker(config, mpInstance) {
1385
- var kitBlocker, dataPlanForKitBlocker, kitBlockError, kitBlockOptions;
1431
+ let kitBlocker;
1432
+ let dataPlanForKitBlocker;
1433
+ let kitBlockError;
1434
+ let kitBlockOptions;
1386
1435
 
1387
1436
  /* There are three ways a data plan object for blocking can be passed to the SDK:
1388
1437
  1. Manually via config.dataPlanOptions (this takes priority)
@@ -1,9 +1,13 @@
1
1
  import Polyfill from './polyfill';
2
- import Types from './types';
2
+ import Types, { CommerceEventType, EventType, ProductActionType, PromotionActionType } from './types';
3
3
  import Constants from './constants';
4
- import mParticleInstance from './mp-instance.js';
4
+ import mParticleInstance, { IMParticleWebSDKInstance } from './mp-instance.js';
5
5
  import _BatchValidator from './mockBatchCreator';
6
6
  import MPSideloadedKit from './sideloadedKit';
7
+ import { IMParticleInstanceManager } from './sdkRuntimeModels';
8
+ import { IStore } from './store';
9
+ import { Dictionary } from '@mparticle/web-sdk';
10
+ import { valueof } from './utils';
7
11
 
8
12
  if (!Array.prototype.forEach) {
9
13
  Array.prototype.forEach = Polyfill.forEach;
@@ -17,20 +21,23 @@ if (!Array.prototype.filter) {
17
21
  Array.prototype.filter = Polyfill.filter;
18
22
  }
19
23
 
24
+ // https://go.mparticle.com/work/SQDSDKS-6768
20
25
  if (!Array.isArray) {
26
+ // @ts-ignore
21
27
  Array.prototype.isArray = Polyfill.isArray;
22
28
  }
23
29
 
24
- function mParticle() {
25
- var self = this;
30
+ function mParticleInstanceManager(this: IMParticleInstanceManager) {
31
+ const self = this;
26
32
  // Only leaving this here in case any clients are trying to access mParticle.Store, to prevent from throwing
27
- this.Store = {};
28
- this._instances = {};
33
+ this.Store = {} as IStore;
34
+ this._instances = {} as Dictionary<IMParticleWebSDKInstance>;
29
35
  this.IdentityType = Types.IdentityType;
30
- this.EventType = Types.EventType;
31
- this.CommerceEventType = Types.CommerceEventType;
32
- this.PromotionType = Types.PromotionActionType;
33
- this.ProductActionType = Types.ProductActionType;
36
+ this.EventType = EventType as unknown as valueof<typeof EventType>;
37
+ this.CommerceEventType = CommerceEventType as unknown as valueof<typeof CommerceEventType>;
38
+ this.PromotionType = PromotionActionType as unknown as valueof<typeof PromotionActionType>;
39
+ this.ProductActionType = ProductActionType as unknown as valueof<typeof ProductActionType>;
40
+
34
41
  this.MPSideloadedKit = MPSideloadedKit;
35
42
 
36
43
  if (typeof window !== 'undefined') {
@@ -65,9 +72,9 @@ function mParticle() {
65
72
  ? Constants.DefaultInstance
66
73
  : instanceName
67
74
  ).toLowerCase();
68
- var client = self._instances[instanceName];
75
+ let client: IMParticleWebSDKInstance = self._instances[instanceName];
69
76
  if (client === undefined) {
70
- client = new mParticleInstance(apiKey, config, instanceName);
77
+ client = new mParticleInstance(instanceName);
71
78
  self._instances[instanceName] = client;
72
79
  }
73
80
 
@@ -75,7 +82,7 @@ function mParticle() {
75
82
  };
76
83
 
77
84
  this.getInstance = function getInstance(instanceName) {
78
- var client;
85
+ let client: IMParticleWebSDKInstance;
79
86
  if (!instanceName) {
80
87
  instanceName = Constants.DefaultInstance;
81
88
  client = self._instances[instanceName];
@@ -480,11 +487,17 @@ function mParticle() {
480
487
  };
481
488
  }
482
489
 
483
- var mparticleInstance = new mParticle();
490
+ const mParticleManager = new mParticleInstanceManager();
484
491
 
485
492
  if (typeof window !== 'undefined') {
486
- window.mParticle = mparticleInstance;
493
+ // mParticle is the global object used to access the SDK and predates instance manager,
494
+ // when mParticle was a singleton. We now support multiple instances. Calling methods
495
+ // on mParticle directly will access the default instance, but mParticle can also be used
496
+ // as the instance manager in self hosted mode.
497
+ window.mParticle = mParticleManager;
498
+
499
+ // https://go.mparticle.com/work/SQDSDKS-5053
487
500
  window.mParticle._BatchValidator = new _BatchValidator();
488
501
  }
489
502
 
490
- export default mparticleInstance;
503
+ export default mParticleManager;
@@ -6,7 +6,7 @@ export interface INativeSdkHelpers {
6
6
  minWebviewBridgeVersion: number
7
7
  ) => boolean;
8
8
  isBridgeV1Available: () => boolean;
9
- sendToNative: (path: string, value: string) => void;
9
+ sendToNative: (path: string, value?: string) => void;
10
10
  sendViaBridgeV1: (path: string, value: string) => void;
11
11
  sendViaIframeToIOS: (path: string, value: string) => void;
12
12
  sendViaBridgeV2: (path: string, value: string, requiredWebviewBridgeName: boolean) => void;
@@ -1,5 +1,16 @@
1
+ import { IPixelConfiguration } from './cookieSyncManager';
2
+ import { MPForwarder } from './forwarders.interfaces';
3
+ import { IntegrationDelays } from './mp-instance';
1
4
  import { isEmpty, isFunction } from './utils';
2
5
 
6
+ export interface IPreInit {
7
+ readyQueue: Function[] | any[];
8
+ integrationDelays: IntegrationDelays;
9
+ forwarderConstructors: MPForwarder[];
10
+ pixelConfigurations?: IPixelConfiguration[];
11
+ isDevelopmentMode?: boolean;
12
+ }
13
+
3
14
  export const processReadyQueue = (readyQueue): Function[] => {
4
15
  if (!isEmpty(readyQueue)) {
5
16
  readyQueue.forEach(readyQueueItem => {