@mparticle/web-sdk 2.22.0 → 2.23.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mparticle/web-sdk",
3
- "version": "2.22.0",
3
+ "version": "2.23.0",
4
4
  "description": "mParticle core SDK for web applications",
5
5
  "license": "Apache-2.0",
6
6
  "keywords": [
@@ -82,12 +82,12 @@
82
82
  "@babel/preset-env": "^7.6.0",
83
83
  "@babel/preset-typescript": "^7.6.0",
84
84
  "@mparticle/data-planning-models": "^0.1.0",
85
- "@mparticle/event-models": "^1.1.6",
85
+ "@mparticle/event-models": "^1.1.7",
86
86
  "@rollup/plugin-babel": "6.0.3",
87
- "@rollup/plugin-commonjs": "22.0.2",
87
+ "@rollup/plugin-commonjs": "24.1.0",
88
88
  "@rollup/plugin-json": "^4.1.0",
89
- "@rollup/plugin-node-resolve": "13.3.0",
90
- "@rollup/plugin-typescript": "^8.3.3",
89
+ "@rollup/plugin-node-resolve": "15.1.0",
90
+ "@rollup/plugin-typescript": "^11.1.0",
91
91
  "@semantic-release/changelog": "^5.0.1",
92
92
  "@semantic-release/exec": "^5.0.0",
93
93
  "@semantic-release/git": "^9.0.0",
@@ -96,7 +96,7 @@
96
96
  "@types/jest-expect-message": "^1.1.0",
97
97
  "@types/mocha": "^9.0.0",
98
98
  "@types/mparticle__web-sdk": "^2.16.1",
99
- "@types/node": "^18.7.11",
99
+ "@types/node": "^20.1.0",
100
100
  "babel-preset-minify": "^0.5.1",
101
101
  "browser-sync": "^2.26.3",
102
102
  "browserify": "^17.0.0",
@@ -131,7 +131,7 @@
131
131
  "typescript": "^5.0.2",
132
132
  "uglify-js": "^3.4.9",
133
133
  "webpack": "^5.36.2",
134
- "webpack-cli": "^4.6.0"
134
+ "webpack-cli": "^5.0.2"
135
135
  },
136
136
  "dependencies": {
137
137
  "@babel/runtime": "^7.6.0",
@@ -16,6 +16,7 @@ export type SDKCompleteInitCallback = (
16
16
 
17
17
  export interface IKitConfigs extends IKitFilterSettings {
18
18
  name: string;
19
+ suffix?: string;
19
20
  moduleId: number;
20
21
  isDebug: boolean;
21
22
  isVisible: boolean;
package/src/forwarders.js CHANGED
@@ -557,10 +557,12 @@ export default function Forwarders(mpInstance, kitBlocker) {
557
557
  // if there is a match before being initialized.
558
558
  // Only kits that are configured properly can be active and used for kit forwarding.
559
559
  this.processUIEnabledKits = function(config) {
560
+ let kits = this.returnKitConstructors();
561
+
560
562
  try {
561
563
  if (Array.isArray(config.kitConfigs) && config.kitConfigs.length) {
562
564
  config.kitConfigs.forEach(function(kitConfig) {
563
- self.configureUIEnabledKit(kitConfig);
565
+ self.configureUIEnabledKit(kitConfig, kits);
564
566
  });
565
567
  }
566
568
  } catch (e) {
@@ -571,37 +573,56 @@ export default function Forwarders(mpInstance, kitBlocker) {
571
573
  }
572
574
  };
573
575
 
574
- this.configureUIEnabledKit = function(configuration) {
575
- var newForwarder = null,
576
- config = configuration,
577
- forwarders = {};
578
-
576
+ this.returnKitConstructors = function() {
577
+ let kits = {};
579
578
  // If there are kits inside of mpInstance._Store.SDKConfig.kits, then mParticle is self hosted
580
579
  if (!isEmpty(mpInstance._Store.SDKConfig.kits)) {
581
- forwarders = mpInstance._Store.SDKConfig.kits;
580
+ kits = mpInstance._Store.SDKConfig.kits;
582
581
  // otherwise mParticle is loaded via script tag
583
582
  } else if (!isEmpty(mpInstance._preInit.forwarderConstructors)) {
584
583
  mpInstance._preInit.forwarderConstructors.forEach(function(
585
- forwarder
584
+ kitConstructor
586
585
  ) {
587
- forwarders[forwarder.name] = forwarder;
586
+ // A suffix is added to a kitConstructor and kit config if there are multiple different
587
+ // versions of a client kit. This matches the suffix in the DB. As an example
588
+ // the GA4 kit has a client kit and a server side kit which has a client side
589
+ // component. They share the same name/module ID in the DB, so we include a
590
+ // suffix to distinguish them in the kits object.
591
+ // If a customer wanted simultaneous GA4 client and server connections,
592
+ // a suffix allows the SDK to distinguish the two.
593
+ if (kitConstructor.suffix) {
594
+ const kitNameWithConstructorSuffix = `${kitConstructor.name}-${kitConstructor.suffix}`;
595
+ kits[kitNameWithConstructorSuffix] = kitConstructor;
596
+ } else {
597
+ kits[kitConstructor.name] = kitConstructor;
598
+ }
588
599
  });
589
600
  }
601
+ return kits;
602
+ };
603
+
604
+ this.configureUIEnabledKit = function(configuration, kits) {
605
+ let newKit = null;
606
+ const config = configuration;
590
607
 
591
- for (var name in forwarders) {
592
- if (name === config.name) {
608
+ for (let name in kits) {
609
+ // Configs are returned with suffixes also. We need to consider the
610
+ // config suffix here to match the constructor suffix
611
+ let kitNameWithConfigSuffix;
612
+ if (config.suffix) {
613
+ kitNameWithConfigSuffix = `${config.name}-${config.suffix}`;
614
+ }
615
+
616
+ if (name === kitNameWithConfigSuffix || name === config.name) {
593
617
  if (
594
618
  config.isDebug ===
595
619
  mpInstance._Store.SDKConfig.isDevelopmentMode ||
596
620
  config.isSandbox ===
597
621
  mpInstance._Store.SDKConfig.isDevelopmentMode
598
622
  ) {
599
- newForwarder = this.returnConfiguredKit(
600
- forwarders[name],
601
- config
602
- );
623
+ newKit = this.returnConfiguredKit(kits[name], config);
603
624
 
604
- mpInstance._Store.configuredForwarders.push(newForwarder);
625
+ mpInstance._Store.configuredForwarders.push(newKit);
605
626
  break;
606
627
  }
607
628
  }
@@ -640,6 +661,12 @@ export default function Forwarders(mpInstance, kitBlocker) {
640
661
  sideloadedKits.kits[registeredKitKey];
641
662
  self.configureSideloadedKit(kitConstructor);
642
663
  }
664
+
665
+ // If Sideloaded Kits are successfully registered,
666
+ // record this in the Store.
667
+ if (!isEmpty(sideloadedKits.kits)) {
668
+ mpInstance._Store.isUsingSideloadedKits = true;
669
+ }
643
670
  }
644
671
  } catch (e) {
645
672
  mpInstance.Logger.error(
@@ -111,6 +111,7 @@ export default class _BatchValidator {
111
111
  getAppVersion: mockFunction,
112
112
  getAppName: mockFunction,
113
113
  getInstance: mockFunction,
114
+ getDeviceId: mockFunction,
114
115
  init: mockFunction,
115
116
  logBaseEvent: mockFunction,
116
117
  logEvent: mockFunction,
@@ -194,10 +194,18 @@ export default function _Persistence(mpInstance) {
194
194
  obj.gs.cgid ||
195
195
  mpInstance._Store.clientId ||
196
196
  mpInstance._Helpers.generateUniqueId();
197
+
198
+ // For most persistence values, we prioritize localstorage/cookie values over
199
+ // Store. However, we allow device ID to be overriden via a config value and
200
+ // thus the priority of the deviceId value is
201
+ // 1. value passed via config.deviceId
202
+ // 2. previous value in persistence
203
+ // 3. generate new guid
197
204
  mpInstance._Store.deviceId =
198
- obj.gs.das ||
199
205
  mpInstance._Store.deviceId ||
206
+ obj.gs.das ||
200
207
  mpInstance._Helpers.generateUniqueId();
208
+
201
209
  mpInstance._Store.integrationAttributes = obj.gs.ia || {};
202
210
  mpInstance._Store.context =
203
211
  obj.gs.c || mpInstance._Store.context;
@@ -151,6 +151,7 @@ export interface MParticleWebSDK {
151
151
  init(apiKey: string, config: SDKInitConfig, instanceName?: string): void;
152
152
  getAppName(): string;
153
153
  getAppVersion(): string;
154
+ getDeviceId(): string;
154
155
  getInstance(): MParticleWebSDK; // TODO: Create a new type for MParticleWebSDKInstance
155
156
  ServerModel();
156
157
  upload();
@@ -66,11 +66,16 @@ export function convertEvents(
66
66
  events: uploadEvents,
67
67
  mp_deviceid: lastEvent.DeviceId,
68
68
  sdk_version: lastEvent.SDKVersion,
69
+
70
+ // TODO: Refactor this to read from _Store or a global config
69
71
  application_info: {
70
72
  application_version: lastEvent.AppVersion,
71
73
  application_name: lastEvent.AppName,
72
74
  package: lastEvent.Package,
75
+ is_using_sideloaded_kits:
76
+ mpInstance._Store.isUsingSideloadedKits || undefined,
73
77
  },
78
+
74
79
  device_info: {
75
80
  platform: EventsApi.DeviceInformationPlatformEnum.web,
76
81
  screen_width: window.screen.width,
package/src/store.ts CHANGED
@@ -139,6 +139,7 @@ export interface IStore {
139
139
  nonCurrentUserMPIDs: Record<MPID, Dictionary>;
140
140
  identifyCalled: boolean;
141
141
  isLoggedIn: boolean;
142
+ isUsingSideloadedKits?: boolean;
142
143
  cookieSyncDates: Dictionary<number>;
143
144
  integrationAttributes: IntegrationAttributes;
144
145
  requireDelay: boolean;