@mparticle/web-sdk 2.26.10 → 2.28.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
@@ -393,7 +393,7 @@ var mParticle = (function () {
393
393
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
394
394
  };
395
395
 
396
- var version = "2.26.10";
396
+ var version = "2.28.0";
397
397
 
398
398
  var Constants = {
399
399
  sdkVersion: version,
@@ -2101,7 +2101,7 @@ var mParticle = (function () {
2101
2101
  return __generator(this, function (_a) {
2102
2102
  switch (_a.label) {
2103
2103
  case 0:
2104
- return [4 /*yield*/, this.makeRequest(this.url, fetchPayload.body)];
2104
+ return [4 /*yield*/, this.makeRequest(this.url, fetchPayload.body, fetchPayload.method)];
2105
2105
  case 1:
2106
2106
  response = _a.sent();
2107
2107
  return [2 /*return*/, response];
@@ -2109,7 +2109,17 @@ var mParticle = (function () {
2109
2109
  });
2110
2110
  });
2111
2111
  };
2112
- XHRUploader.prototype.makeRequest = function (url, data) {
2112
+ // XHR Ready States
2113
+ // https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/readyState
2114
+ // 0 UNSENT open() has not been called yet.
2115
+ // 1 OPENED send() has been called.
2116
+ // 2 HEADERS_RECEIVED send() has been called, and headers and status are available.
2117
+ // 3 LOADING Downloading; responseText holds partial data.
2118
+ // 4 DONE The operation is complete.
2119
+ XHRUploader.prototype.makeRequest = function (url, data, method) {
2120
+ if (method === void 0) {
2121
+ method = 'post';
2122
+ }
2113
2123
  return __awaiter(this, void 0, void 0, function () {
2114
2124
  var xhr;
2115
2125
  return __generator(this, function (_a) {
@@ -2124,7 +2134,7 @@ var mParticle = (function () {
2124
2134
  reject(xhr);
2125
2135
  }
2126
2136
  };
2127
- xhr.open('post', url);
2137
+ xhr.open(method, url);
2128
2138
  xhr.send(data);
2129
2139
  })];
2130
2140
  });
@@ -3809,12 +3819,13 @@ var mParticle = (function () {
3809
3819
  });
3810
3820
  return appEvents;
3811
3821
  };
3812
- this.createCommerceEventObject = function (customFlags) {
3822
+ this.createCommerceEventObject = function (customFlags, options) {
3813
3823
  var baseEvent;
3814
3824
  mpInstance.Logger.verbose(Messages$5.InformationMessages.StartingLogCommerceEvent);
3815
3825
  if (mpInstance._Helpers.canLog()) {
3816
3826
  baseEvent = mpInstance._ServerModel.createEventObject({
3817
- messageType: Types.MessageType.Commerce
3827
+ messageType: Types.MessageType.Commerce,
3828
+ sourceMessageId: options === null || options === void 0 ? void 0 : options.sourceMessageId
3818
3829
  });
3819
3830
  baseEvent.EventName = 'eCommerce - ';
3820
3831
  baseEvent.CurrencyCode = mpInstance._Store.currencyCode;
@@ -4178,10 +4189,14 @@ var mParticle = (function () {
4178
4189
  this.processConfig = function (config) {
4179
4190
  var workspaceToken = config.workspaceToken,
4180
4191
  requiredWebviewBridgeName = config.requiredWebviewBridgeName;
4181
- // We should reprocess the flags in case they have changed when we request an updated config
4192
+ // We should reprocess the flags and baseUrls in case they have changed when we request an updated config
4182
4193
  // such as if the SDK is being self-hosted and the flags are different on the server config
4183
4194
  // https://go.mparticle.com/work/SQDSDKS-6317
4184
4195
  _this.SDKConfig.flags = processFlags(config);
4196
+ var baseUrls = processBaseUrls(config, _this.SDKConfig.flags, apiKey);
4197
+ for (var baseUrlKeys in baseUrls) {
4198
+ _this.SDKConfig[baseUrlKeys] = baseUrls[baseUrlKeys];
4199
+ }
4185
4200
  if (workspaceToken) {
4186
4201
  _this.SDKConfig.workspaceToken = workspaceToken;
4187
4202
  } else {
@@ -5220,7 +5235,7 @@ var mParticle = (function () {
5220
5235
  }
5221
5236
  };
5222
5237
  this.logProductActionEvent = function (productActionType, product, customAttrs, customFlags, transactionAttributes, options) {
5223
- var event = mpInstance._Ecommerce.createCommerceEventObject(customFlags);
5238
+ var event = mpInstance._Ecommerce.createCommerceEventObject(customFlags, options);
5224
5239
  var productList = Array.isArray(product) ? product : [product];
5225
5240
  productList.forEach(function (product) {
5226
5241
  if (product.TotalAmount) {
@@ -7416,7 +7431,7 @@ var mParticle = (function () {
7416
7431
  var newIdentitiesByType = {};
7417
7432
  mpInstance._Store.identityCallInFlight = false;
7418
7433
  try {
7419
- var _identityApiResult;
7434
+ var _identityApiResult, _mpInstance$_APIClien;
7420
7435
  mpInstance.Logger.verbose('Parsing "' + method + '" identity response from server');
7421
7436
  identityApiResult = xhr.responseText ? JSON.parse(xhr.responseText) : null;
7422
7437
  mpInstance._Store.isLoggedIn = ((_identityApiResult = identityApiResult) === null || _identityApiResult === void 0 ? void 0 : _identityApiResult.is_logged_in) || false;
@@ -7492,7 +7507,9 @@ var mParticle = (function () {
7492
7507
  mpInstance.Logger.error('Received HTTP response code of ' + xhr.status + ' - ' + identityApiResult.errors[0].message);
7493
7508
  }
7494
7509
  mpInstance.Logger.verbose('Successfully parsed Identity Response');
7495
- mpInstance._APIClient.processQueuedEvents();
7510
+
7511
+ // https://go.mparticle.com/work/SQDSDKS-6654
7512
+ (_mpInstance$_APIClien = mpInstance._APIClient) === null || _mpInstance$_APIClien === void 0 || _mpInstance$_APIClien.processQueuedEvents();
7496
7513
  } catch (e) {
7497
7514
  if (callback) {
7498
7515
  mpInstance._Helpers.invokeCallback(callback, xhr.status, identityApiResult || null);
@@ -7517,12 +7534,13 @@ var mParticle = (function () {
7517
7534
  for (var identityType in newUserIdentities) {
7518
7535
  // Verifies a change actually happened
7519
7536
  if (prevUserIdentities[identityType] !== newUserIdentities[identityType]) {
7537
+ var _mpInstance$_APIClien2;
7520
7538
  // If a new identity type was introduced when the identity changes
7521
7539
  // we need to notify the server so that the user profile is updated in
7522
7540
  // the mParticle UI.
7523
7541
  var isNewUserIdentityType = !prevUserIdentities[identityType];
7524
7542
  var userIdentityChangeEvent = self.createUserIdentityChange(identityType, newUserIdentities[identityType], prevUserIdentities[identityType], isNewUserIdentityType, currentUserInMemory);
7525
- mpInstance._APIClient.sendEventToServer(userIdentityChangeEvent);
7543
+ (_mpInstance$_APIClien2 = mpInstance._APIClient) === null || _mpInstance$_APIClien2 === void 0 || _mpInstance$_APIClien2.sendEventToServer(userIdentityChangeEvent);
7526
7544
  }
7527
7545
  }
7528
7546
  };
@@ -7551,7 +7569,8 @@ var mParticle = (function () {
7551
7569
  this.sendUserAttributeChangeEvent = function (attributeKey, newUserAttributeValue, previousUserAttributeValue, isNewAttribute, deleted, user) {
7552
7570
  var userAttributeChangeEvent = self.createUserAttributeChange(attributeKey, newUserAttributeValue, previousUserAttributeValue, isNewAttribute, deleted, user);
7553
7571
  if (userAttributeChangeEvent) {
7554
- mpInstance._APIClient.sendEventToServer(userAttributeChangeEvent);
7572
+ var _mpInstance$_APIClien3;
7573
+ (_mpInstance$_APIClien3 = mpInstance._APIClient) === null || _mpInstance$_APIClien3 === void 0 || _mpInstance$_APIClien3.sendEventToServer(userAttributeChangeEvent);
7555
7574
  }
7556
7575
  };
7557
7576
  this.createUserAttributeChange = function (key, newValue, previousUserAttributeValue, isNewAttribute, deleted, user) {
@@ -7576,14 +7595,16 @@ var mParticle = (function () {
7576
7595
  };
7577
7596
  this.reinitForwardersOnUserChange = function (prevUser, newUser) {
7578
7597
  if (hasMPIDAndUserLoginChanged(prevUser, newUser)) {
7579
- mpInstance._Forwarders.initForwarders(newUser.getUserIdentities().userIdentities, mpInstance._APIClient.prepareForwardingStats);
7598
+ var _mpInstance$_Forwarde;
7599
+ (_mpInstance$_Forwarde = mpInstance._Forwarders) === null || _mpInstance$_Forwarde === void 0 || _mpInstance$_Forwarde.initForwarders(newUser.getUserIdentities().userIdentities, mpInstance._APIClient.prepareForwardingStats);
7580
7600
  }
7581
7601
  };
7582
7602
  this.setForwarderCallbacks = function (user, method) {
7603
+ var _mpInstance$_Forwarde2, _mpInstance$_Forwarde3, _mpInstance$_Forwarde4;
7583
7604
  // https://go.mparticle.com/work/SQDSDKS-6036
7584
- mpInstance._Forwarders.setForwarderUserIdentities(user.getUserIdentities().userIdentities);
7585
- mpInstance._Forwarders.setForwarderOnIdentityComplete(user, method);
7586
- mpInstance._Forwarders.setForwarderOnUserIdentified(user);
7605
+ (_mpInstance$_Forwarde2 = mpInstance._Forwarders) === null || _mpInstance$_Forwarde2 === void 0 || _mpInstance$_Forwarde2.setForwarderUserIdentities(user.getUserIdentities().userIdentities);
7606
+ (_mpInstance$_Forwarde3 = mpInstance._Forwarders) === null || _mpInstance$_Forwarde3 === void 0 || _mpInstance$_Forwarde3.setForwarderOnIdentityComplete(user, method);
7607
+ (_mpInstance$_Forwarde4 = mpInstance._Forwarders) === null || _mpInstance$_Forwarde4 === void 0 || _mpInstance$_Forwarde4.setForwarderOnUserIdentified(user);
7587
7608
  };
7588
7609
  }
7589
7610
 
@@ -8350,48 +8371,73 @@ var mParticle = (function () {
8350
8371
  return KitBlocker;
8351
8372
  }();
8352
8373
 
8353
- function ConfigAPIClient() {
8354
- this.getSDKConfiguration = function (apiKey, config, completeSDKInitialization, mpInstance) {
8355
- var url;
8356
- try {
8357
- var xhrCallback = function xhrCallback() {
8358
- if (xhr_1.readyState === 4) {
8359
- // when a 200 returns, merge current config with what comes back from config, prioritizing user inputted config
8360
- if (xhr_1.status === 200) {
8361
- config = mpInstance._Helpers.extend({}, config, JSON.parse(xhr_1.responseText));
8362
- completeSDKInitialization(apiKey, config, mpInstance);
8363
- mpInstance.Logger.verbose('Successfully received configuration from server');
8364
- } else {
8365
- // if for some reason a 200 doesn't return, then we initialize with the just the passed through config
8366
- completeSDKInitialization(apiKey, config, mpInstance);
8367
- mpInstance.Logger.verbose('Issue with receiving configuration from server, received HTTP Code of ' + xhr_1.status);
8368
- }
8369
- }
8370
- };
8371
- var xhr_1 = mpInstance._Helpers.createXHR(xhrCallback);
8372
- url = 'https://' + mpInstance._Store.SDKConfig.configUrl + apiKey + '/config?env=';
8373
- if (config.isDevelopmentMode) {
8374
- url = url + '1';
8375
- } else {
8376
- url = url + '0';
8377
- }
8378
- var dataPlan = config.dataPlan;
8379
- if (dataPlan) {
8380
- if (dataPlan.planId) {
8381
- url = url + '&plan_id=' + dataPlan.planId || '';
8382
- }
8383
- if (dataPlan.planVersion) {
8384
- url = url + '&plan_version=' + dataPlan.planVersion || '';
8374
+ var buildUrl = function buildUrl(configUrl, apiKey, dataPlanConfig, isDevelopmentMode) {
8375
+ var url = configUrl + apiKey + '/config';
8376
+ var env = isDevelopmentMode ? '1' : '0';
8377
+ var queryParams = ["env=".concat(env)];
8378
+ var _a = dataPlanConfig || {},
8379
+ planId = _a.planId,
8380
+ planVersion = _a.planVersion;
8381
+ if (planId) {
8382
+ queryParams.push("plan_id=".concat(planId));
8383
+ }
8384
+ if (planVersion) {
8385
+ queryParams.push("plan_version=".concat(planVersion));
8386
+ }
8387
+ return "".concat(url, "?").concat(queryParams.join('&'));
8388
+ };
8389
+ function ConfigAPIClient(apiKey, config, mpInstance) {
8390
+ var _this = this;
8391
+ var baseUrl = 'https://' + mpInstance._Store.SDKConfig.configUrl;
8392
+ var isDevelopmentMode = config.isDevelopmentMode;
8393
+ var dataPlan = config.dataPlan;
8394
+ var uploadUrl = buildUrl(baseUrl, apiKey, dataPlan, isDevelopmentMode);
8395
+ var uploader = window.fetch ? new FetchUploader(uploadUrl) : new XHRUploader(uploadUrl);
8396
+ this.getSDKConfiguration = function () {
8397
+ return __awaiter(_this, void 0, void 0, function () {
8398
+ var configResponse, fetchPayload, response, xhrResponse;
8399
+ var _a, _b, _c;
8400
+ return __generator(this, function (_d) {
8401
+ switch (_d.label) {
8402
+ case 0:
8403
+ fetchPayload = {
8404
+ method: 'get',
8405
+ headers: {
8406
+ Accept: 'text/plain;charset=UTF-8',
8407
+ 'Content-Type': 'text/plain;charset=UTF-8'
8408
+ },
8409
+ body: null
8410
+ };
8411
+ _d.label = 1;
8412
+ case 1:
8413
+ _d.trys.push([1, 6,, 7]);
8414
+ return [4 /*yield*/, uploader.upload(fetchPayload)];
8415
+ case 2:
8416
+ response = _d.sent();
8417
+ if (!(response.status === 200)) return [3 /*break*/, 5];
8418
+ (_a = mpInstance === null || mpInstance === void 0 ? void 0 : mpInstance.Logger) === null || _a === void 0 ? void 0 : _a.verbose('Successfully received configuration from server');
8419
+ if (!response.json) return [3 /*break*/, 4];
8420
+ return [4 /*yield*/, response.json()];
8421
+ case 3:
8422
+ configResponse = _d.sent();
8423
+ return [2 /*return*/, configResponse];
8424
+ case 4:
8425
+ xhrResponse = response;
8426
+ configResponse = JSON.parse(xhrResponse.responseText);
8427
+ return [2 /*return*/, configResponse];
8428
+ case 5:
8429
+ (_b = mpInstance === null || mpInstance === void 0 ? void 0 : mpInstance.Logger) === null || _b === void 0 ? void 0 : _b.verbose('Issue with receiving configuration from server, received HTTP Code of ' + response.statusText);
8430
+ return [3 /*break*/, 7];
8431
+ case 6:
8432
+ _d.sent();
8433
+ (_c = mpInstance === null || mpInstance === void 0 ? void 0 : mpInstance.Logger) === null || _c === void 0 ? void 0 : _c.error('Error getting forwarder configuration from mParticle servers.');
8434
+ return [3 /*break*/, 7];
8435
+ case 7:
8436
+ // Returns the original config object if we cannot retrieve the remote config
8437
+ return [2 /*return*/, config];
8385
8438
  }
8386
- }
8387
- if (xhr_1) {
8388
- xhr_1.open('get', url);
8389
- xhr_1.send(null);
8390
- }
8391
- } catch (e) {
8392
- completeSDKInitialization(apiKey, config, mpInstance);
8393
- mpInstance.Logger.error('Error getting forwarder configuration from mParticle servers.');
8394
- }
8439
+ });
8440
+ });
8395
8441
  };
8396
8442
  }
8397
8443
 
@@ -8534,6 +8580,7 @@ var mParticle = (function () {
8534
8580
  }
8535
8581
  }
8536
8582
  this.init = function (apiKey, config) {
8583
+ var _this = this;
8537
8584
  if (!config) {
8538
8585
  console.warn('You did not pass a config object to init(). mParticle will not initialize properly');
8539
8586
  }
@@ -8544,7 +8591,11 @@ var mParticle = (function () {
8544
8591
  // to it for it to be run after fetched
8545
8592
  if (config) {
8546
8593
  if (!config.hasOwnProperty('requestConfig') || config.requestConfig) {
8547
- new ConfigAPIClient().getSDKConfiguration(apiKey, config, completeSDKInitialization, this);
8594
+ var configApiClient = new ConfigAPIClient(apiKey, config, this);
8595
+ configApiClient.getSDKConfiguration().then(function (result) {
8596
+ var mergedConfig = _this._Helpers.extend({}, config, result);
8597
+ completeSDKInitialization(apiKey, mergedConfig, _this);
8598
+ });
8548
8599
  } else {
8549
8600
  completeSDKInitialization(apiKey, config, this);
8550
8601
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mparticle/web-sdk",
3
- "version": "2.26.10",
3
+ "version": "2.28.0",
4
4
  "description": "mParticle core SDK for web applications",
5
5
  "license": "Apache-2.0",
6
6
  "keywords": [
@@ -7,12 +7,12 @@ import {
7
7
  SDKInitConfig,
8
8
  } from './sdkRuntimeModels';
9
9
  import { Dictionary } from './utils';
10
-
11
- export type SDKCompleteInitCallback = (
12
- apiKey: string,
13
- config: SDKInitConfig,
14
- mpInstance: MParticleWebSDK
15
- ) => void;
10
+ import {
11
+ AsyncUploader,
12
+ fetchPayload,
13
+ FetchUploader,
14
+ XHRUploader,
15
+ } from './uploaders';
16
16
 
17
17
  export interface IKitConfigs extends IKitFilterSettings {
18
18
  name: string;
@@ -47,13 +47,13 @@ export interface IKitFilterSettings {
47
47
  export interface IFilteringEventAttributeValue {
48
48
  eventAttributeName: string;
49
49
  eventAttributeValue: string;
50
- includeOnMatch: boolean
50
+ includeOnMatch: boolean;
51
51
  }
52
52
 
53
53
  export interface IFilteringUserAttributeValue {
54
54
  userAttributeName: string;
55
55
  userAttributeValue: string;
56
- includeOnMatch: boolean
56
+ includeOnMatch: boolean;
57
57
  }
58
58
  export interface IFilteringConsentRuleValues {
59
59
  includeOnMatch: boolean;
@@ -62,10 +62,9 @@ export interface IFilteringConsentRuleValues {
62
62
 
63
63
  export interface IConsentRuleValue {
64
64
  consentPurpose: string;
65
- hasConsented: boolean
65
+ hasConsented: boolean;
66
66
  }
67
67
 
68
-
69
68
  export interface IPixelConfig {
70
69
  name: string;
71
70
  moduleId: number;
@@ -91,78 +90,92 @@ export interface IConfigResponse {
91
90
  }
92
91
 
93
92
  export interface IConfigAPIClient {
94
- getSDKConfiguration: (
95
- apiKey: string,
96
- config: SDKInitConfig,
97
- completeSDKInitialization: SDKCompleteInitCallback,
98
- mpInstance: MParticleWebSDK
99
- ) => void;
93
+ apiKey: string;
94
+ config: SDKInitConfig;
95
+ mpInstance: MParticleWebSDK;
96
+ getSDKConfiguration: () => Promise<IConfigResponse>;
100
97
  }
101
98
 
102
- export default function ConfigAPIClient(this: IConfigAPIClient) {
103
- this.getSDKConfiguration = (
104
- apiKey,
105
- config,
106
- completeSDKInitialization,
107
- mpInstance
108
- ): void => {
109
- let url: string;
99
+ const buildUrl = (
100
+ configUrl: string,
101
+ apiKey: string,
102
+ dataPlanConfig?: DataPlanConfig | null,
103
+ isDevelopmentMode?: boolean | null
104
+ ): string => {
105
+ const url = configUrl + apiKey + '/config';
106
+ const env = isDevelopmentMode ? '1' : '0';
107
+ const queryParams = [`env=${env}`];
108
+
109
+ const { planId, planVersion } = dataPlanConfig || {};
110
+
111
+ if (planId) {
112
+ queryParams.push(`plan_id=${planId}`);
113
+ }
114
+
115
+ if (planVersion) {
116
+ queryParams.push(`plan_version=${planVersion}`);
117
+ }
118
+
119
+ return `${url}?${queryParams.join('&')}`;
120
+ };
121
+
122
+ export default function ConfigAPIClient(
123
+ this: IConfigAPIClient,
124
+ apiKey: string,
125
+ config: SDKInitConfig,
126
+ mpInstance: MParticleWebSDK
127
+ ): void {
128
+ const baseUrl = 'https://' + mpInstance._Store.SDKConfig.configUrl;
129
+ const { isDevelopmentMode } = config;
130
+ const dataPlan = config.dataPlan as DataPlanConfig;
131
+ const uploadUrl = buildUrl(baseUrl, apiKey, dataPlan, isDevelopmentMode);
132
+ const uploader: AsyncUploader = window.fetch
133
+ ? new FetchUploader(uploadUrl)
134
+ : new XHRUploader(uploadUrl);
135
+
136
+ this.getSDKConfiguration = async (): Promise<IConfigResponse> => {
137
+ let configResponse: IConfigResponse;
138
+ const fetchPayload: fetchPayload = {
139
+ method: 'get',
140
+ headers: {
141
+ Accept: 'text/plain;charset=UTF-8',
142
+ 'Content-Type': 'text/plain;charset=UTF-8',
143
+ },
144
+ body: null,
145
+ };
146
+
110
147
  try {
111
- const xhrCallback = function() {
112
- if (xhr.readyState === 4) {
113
- // when a 200 returns, merge current config with what comes back from config, prioritizing user inputted config
114
- if (xhr.status === 200) {
115
- config = mpInstance._Helpers.extend(
116
- {},
117
- config,
118
- JSON.parse(xhr.responseText)
119
- );
120
- completeSDKInitialization(apiKey, config, mpInstance);
121
- mpInstance.Logger.verbose(
122
- 'Successfully received configuration from server'
123
- );
124
- } else {
125
- // if for some reason a 200 doesn't return, then we initialize with the just the passed through config
126
- completeSDKInitialization(apiKey, config, mpInstance);
127
- mpInstance.Logger.verbose(
128
- 'Issue with receiving configuration from server, received HTTP Code of ' +
129
- xhr.status
130
- );
131
- }
132
- }
133
- };
134
-
135
- const xhr = mpInstance._Helpers.createXHR(xhrCallback);
136
- url =
137
- 'https://' +
138
- mpInstance._Store.SDKConfig.configUrl +
139
- apiKey +
140
- '/config?env=';
141
- if (config.isDevelopmentMode) {
142
- url = url + '1';
143
- } else {
144
- url = url + '0';
145
- }
148
+ const response = await uploader.upload(fetchPayload);
149
+ if (response.status === 200) {
150
+ mpInstance?.Logger?.verbose(
151
+ 'Successfully received configuration from server'
152
+ );
146
153
 
147
- const dataPlan = config.dataPlan as DataPlanConfig;
148
- if (dataPlan) {
149
- if (dataPlan.planId) {
150
- url = url + '&plan_id=' + dataPlan.planId || '';
151
- }
152
- if (dataPlan.planVersion) {
153
- url = url + '&plan_version=' + dataPlan.planVersion || '';
154
+ // https://go.mparticle.com/work/SQDSDKS-6568
155
+ // FetchUploader returns the response as a JSON object that we have to await
156
+ if (response.json) {
157
+ configResponse = await response.json();
158
+ return configResponse;
159
+ } else {
160
+ // https://go.mparticle.com/work/SQDSDKS-6568
161
+ // XHRUploader returns the response as a string that we need to parse
162
+ const xhrResponse = response as unknown as XMLHttpRequest;
163
+ configResponse = JSON.parse(xhrResponse.responseText);
164
+ return configResponse;
154
165
  }
155
166
  }
156
167
 
157
- if (xhr) {
158
- xhr.open('get', url);
159
- xhr.send(null);
160
- }
168
+ mpInstance?.Logger?.verbose(
169
+ 'Issue with receiving configuration from server, received HTTP Code of ' +
170
+ response.statusText
171
+ );
161
172
  } catch (e) {
162
- completeSDKInitialization(apiKey, config, mpInstance);
163
- mpInstance.Logger.error(
173
+ mpInstance?.Logger?.error(
164
174
  'Error getting forwarder configuration from mParticle servers.'
165
175
  );
166
176
  }
177
+
178
+ // Returns the original config object if we cannot retrieve the remote config
179
+ return config as IConfigResponse;
167
180
  };
168
181
  }
package/src/ecommerce.js CHANGED
@@ -523,7 +523,7 @@ export default function Ecommerce(mpInstance) {
523
523
  return appEvents;
524
524
  };
525
525
 
526
- this.createCommerceEventObject = function(customFlags) {
526
+ this.createCommerceEventObject = function(customFlags, options) {
527
527
  var baseEvent;
528
528
 
529
529
  mpInstance.Logger.verbose(
@@ -533,6 +533,7 @@ export default function Ecommerce(mpInstance) {
533
533
  if (mpInstance._Helpers.canLog()) {
534
534
  baseEvent = mpInstance._ServerModel.createEventObject({
535
535
  messageType: Types.MessageType.Commerce,
536
+ sourceMessageId: options?.sourceMessageId,
536
537
  });
537
538
  baseEvent.EventName = 'eCommerce - ';
538
539
 
package/src/events.js CHANGED
@@ -129,7 +129,8 @@ export default function Events(mpInstance) {
129
129
  options
130
130
  ) {
131
131
  var event = mpInstance._Ecommerce.createCommerceEventObject(
132
- customFlags
132
+ customFlags,
133
+ options
133
134
  );
134
135
 
135
136
  var productList = Array.isArray(product) ? product : [product];
package/src/identity.js CHANGED
@@ -1665,7 +1665,8 @@ export default function Identity(mpInstance) {
1665
1665
 
1666
1666
  mpInstance.Logger.verbose('Successfully parsed Identity Response');
1667
1667
 
1668
- mpInstance._APIClient.processQueuedEvents();
1668
+ // https://go.mparticle.com/work/SQDSDKS-6654
1669
+ mpInstance._APIClient?.processQueuedEvents();
1669
1670
  } catch (e) {
1670
1671
  if (callback) {
1671
1672
  mpInstance._Helpers.invokeCallback(
@@ -1716,7 +1717,7 @@ export default function Identity(mpInstance) {
1716
1717
  isNewUserIdentityType,
1717
1718
  currentUserInMemory
1718
1719
  );
1719
- mpInstance._APIClient.sendEventToServer(
1720
+ mpInstance._APIClient?.sendEventToServer(
1720
1721
  userIdentityChangeEvent
1721
1722
  );
1722
1723
  }
@@ -1770,7 +1771,7 @@ export default function Identity(mpInstance) {
1770
1771
  user
1771
1772
  );
1772
1773
  if (userAttributeChangeEvent) {
1773
- mpInstance._APIClient.sendEventToServer(userAttributeChangeEvent);
1774
+ mpInstance._APIClient?.sendEventToServer(userAttributeChangeEvent);
1774
1775
  }
1775
1776
  };
1776
1777
 
@@ -1807,7 +1808,7 @@ export default function Identity(mpInstance) {
1807
1808
 
1808
1809
  this.reinitForwardersOnUserChange = function(prevUser, newUser) {
1809
1810
  if (hasMPIDAndUserLoginChanged(prevUser, newUser)) {
1810
- mpInstance._Forwarders.initForwarders(
1811
+ mpInstance._Forwarders?.initForwarders(
1811
1812
  newUser.getUserIdentities().userIdentities,
1812
1813
  mpInstance._APIClient.prepareForwardingStats
1813
1814
  );
@@ -1816,11 +1817,11 @@ export default function Identity(mpInstance) {
1816
1817
 
1817
1818
  this.setForwarderCallbacks = function(user, method) {
1818
1819
  // https://go.mparticle.com/work/SQDSDKS-6036
1819
- mpInstance._Forwarders.setForwarderUserIdentities(
1820
+ mpInstance._Forwarders?.setForwarderUserIdentities(
1820
1821
  user.getUserIdentities().userIdentities
1821
1822
  );
1822
- mpInstance._Forwarders.setForwarderOnIdentityComplete(user, method);
1823
- mpInstance._Forwarders.setForwarderOnUserIdentified(user);
1823
+ mpInstance._Forwarders?.setForwarderOnIdentityComplete(user, method);
1824
+ mpInstance._Forwarders?.setForwarderOnUserIdentified(user);
1824
1825
  };
1825
1826
  }
1826
1827
 
@@ -117,12 +117,21 @@ export default function mParticleInstance(instanceName) {
117
117
  !config.hasOwnProperty('requestConfig') ||
118
118
  config.requestConfig
119
119
  ) {
120
- new ConfigAPIClient().getSDKConfiguration(
120
+ const configApiClient = new ConfigAPIClient(
121
121
  apiKey,
122
122
  config,
123
- completeSDKInitialization,
124
123
  this
125
124
  );
125
+
126
+ configApiClient.getSDKConfiguration().then(result => {
127
+ const mergedConfig = this._Helpers.extend(
128
+ {},
129
+ config,
130
+ result
131
+ );
132
+
133
+ completeSDKInitialization(apiKey, mergedConfig, this);
134
+ });
126
135
  } else {
127
136
  completeSDKInitialization(apiKey, config, this);
128
137
  }
@@ -256,7 +256,7 @@ export interface SDKHelpersApi {
256
256
  canLog?(): boolean;
257
257
  createMainStorageName?(workspaceToken: string): string;
258
258
  createProductStorageName?(workspaceToken: string): string;
259
- createServiceUrl(url: string, devToken?: string): void;
259
+ createServiceUrl(url: string, devToken?: string): string;
260
260
  createXHR?(cb: () => void): XMLHttpRequest;
261
261
  extend?(...args: any[]);
262
262
  parseNumber?(value: string | number): number;
package/src/store.ts CHANGED
@@ -83,6 +83,7 @@ export interface SDKConfig {
83
83
  useNativeSdk?: boolean;
84
84
  useCookieStorage?: boolean;
85
85
  v1SecureServiceUrl?: string;
86
+ // https://go.mparticle.com/work/SQDSDKS-6618
86
87
  v2SecureServiceUrl?: string;
87
88
  v3SecureServiceUrl?: string;
88
89
  webviewBridgeName?: string;
@@ -661,11 +662,21 @@ export default function Store(
661
662
  this.processConfig = (config: SDKInitConfig) => {
662
663
  const { workspaceToken, requiredWebviewBridgeName } = config;
663
664
 
664
- // We should reprocess the flags in case they have changed when we request an updated config
665
+ // We should reprocess the flags and baseUrls in case they have changed when we request an updated config
665
666
  // such as if the SDK is being self-hosted and the flags are different on the server config
666
667
  // https://go.mparticle.com/work/SQDSDKS-6317
667
668
  this.SDKConfig.flags = processFlags(config);
668
669
 
670
+ const baseUrls: Dictionary<string> = processBaseUrls(
671
+ config,
672
+ this.SDKConfig.flags,
673
+ apiKey
674
+ );
675
+
676
+ for (const baseUrlKeys in baseUrls) {
677
+ this.SDKConfig[baseUrlKeys] = baseUrls[baseUrlKeys];
678
+ }
679
+
669
680
  if (workspaceToken) {
670
681
  this.SDKConfig.workspaceToken = workspaceToken;
671
682
  } else {