@mparticle/web-sdk 2.56.0 → 2.58.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.common.js +39 -39
- package/dist/mparticle.esm.js +39 -39
- package/dist/mparticle.js +292 -62
- package/package.json +1 -1
- package/src/constants.ts +4 -0
- package/src/identityApiClient.ts +24 -11
- package/src/logger.ts +14 -5
- package/src/logging/reportingLogger.ts +192 -0
- package/src/logging/types.ts +32 -0
- package/src/mp-instance.ts +58 -11
- package/src/roktManager.ts +38 -6
- package/src/sdkRuntimeModels.ts +46 -17
- package/src/store.ts +31 -10
- package/src/types.ts +1 -0
- package/src/uploaders.ts +1 -0
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.
|
|
206
|
+
var version = "2.58.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,
|
|
@@ -413,6 +417,7 @@ var mParticle = (function () {
|
|
|
413
417
|
var HTTP_OK = 200;
|
|
414
418
|
var HTTP_ACCEPTED = 202;
|
|
415
419
|
var HTTP_BAD_REQUEST = 400;
|
|
420
|
+
var HTTP_SERVER_ERROR = 500;
|
|
416
421
|
|
|
417
422
|
/******************************************************************************
|
|
418
423
|
Copyright (c) Microsoft Corporation.
|
|
@@ -1214,7 +1219,8 @@ var mParticle = (function () {
|
|
|
1214
1219
|
};
|
|
1215
1220
|
var PerformanceMarkType = {
|
|
1216
1221
|
SdkStart: 'mp:sdkStart',
|
|
1217
|
-
JointSdkSelectPlacements: 'mp:jointSdkSelectPlacements'
|
|
1222
|
+
JointSdkSelectPlacements: 'mp:jointSdkSelectPlacements',
|
|
1223
|
+
JointSdkRoktKitInit: 'mp:jointSdkRoktKitInit'
|
|
1218
1224
|
};
|
|
1219
1225
|
var Types = {
|
|
1220
1226
|
MessageType: MessageType$1,
|
|
@@ -4430,6 +4436,8 @@ var mParticle = (function () {
|
|
|
4430
4436
|
for (var prop in Constants.DefaultBaseUrls) {
|
|
4431
4437
|
sdkConfig[prop] = Constants.DefaultBaseUrls[prop];
|
|
4432
4438
|
}
|
|
4439
|
+
// Always initialize flags to at least an empty object to prevent undefined access
|
|
4440
|
+
sdkConfig.flags = sdkConfig.flags || {};
|
|
4433
4441
|
return sdkConfig;
|
|
4434
4442
|
}
|
|
4435
4443
|
// TODO: Merge this with SDKStoreApi in sdkRuntimeModels
|
|
@@ -4461,6 +4469,7 @@ var mParticle = (function () {
|
|
|
4461
4469
|
context: null,
|
|
4462
4470
|
configurationLoaded: false,
|
|
4463
4471
|
identityCallInFlight: false,
|
|
4472
|
+
identityCallFailed: false,
|
|
4464
4473
|
identifyRequestCount: 0,
|
|
4465
4474
|
SDKConfig: {},
|
|
4466
4475
|
nonCurrentUserMPIDs: {},
|
|
@@ -4481,6 +4490,8 @@ var mParticle = (function () {
|
|
|
4481
4490
|
version: null,
|
|
4482
4491
|
isInfoSet: false
|
|
4483
4492
|
},
|
|
4493
|
+
roktAccountId: null,
|
|
4494
|
+
integrationName: null,
|
|
4484
4495
|
// Placeholder for in-memory persistence model
|
|
4485
4496
|
persistenceData: {
|
|
4486
4497
|
gs: {}
|
|
@@ -4497,10 +4508,6 @@ var mParticle = (function () {
|
|
|
4497
4508
|
if (!config.hasOwnProperty('flags')) {
|
|
4498
4509
|
this.SDKConfig.flags = {};
|
|
4499
4510
|
}
|
|
4500
|
-
// We process the initial config that is passed via the SDK init
|
|
4501
|
-
// and then we will reprocess the config within the processConfig
|
|
4502
|
-
// function when the config is updated from the server
|
|
4503
|
-
// https://go.mparticle.com/work/SQDSDKS-6317
|
|
4504
4511
|
this.SDKConfig.flags = processFlags(config);
|
|
4505
4512
|
if (config.deviceId) {
|
|
4506
4513
|
this.deviceId = config.deviceId;
|
|
@@ -4514,9 +4521,6 @@ var mParticle = (function () {
|
|
|
4514
4521
|
for (var baseUrlKeys in baseUrls) {
|
|
4515
4522
|
this.SDKConfig[baseUrlKeys] = baseUrls[baseUrlKeys];
|
|
4516
4523
|
}
|
|
4517
|
-
if (config.hasOwnProperty('logLevel')) {
|
|
4518
|
-
this.SDKConfig.logLevel = config.logLevel;
|
|
4519
|
-
}
|
|
4520
4524
|
this.SDKConfig.useNativeSdk = !!config.useNativeSdk;
|
|
4521
4525
|
this.SDKConfig.kits = config.kits || {};
|
|
4522
4526
|
this.SDKConfig.sideloadedKits = config.sideloadedKits || [];
|
|
@@ -4739,6 +4743,18 @@ var mParticle = (function () {
|
|
|
4739
4743
|
this.setUserIdentities = function (mpid, userIdentities) {
|
|
4740
4744
|
_this._setPersistence(mpid, 'ui', userIdentities);
|
|
4741
4745
|
};
|
|
4746
|
+
this.getRoktAccountId = function () {
|
|
4747
|
+
return _this.roktAccountId;
|
|
4748
|
+
};
|
|
4749
|
+
this.setRoktAccountId = function (accountId) {
|
|
4750
|
+
_this.roktAccountId = accountId;
|
|
4751
|
+
};
|
|
4752
|
+
this.getIntegrationName = function () {
|
|
4753
|
+
return _this.integrationName;
|
|
4754
|
+
};
|
|
4755
|
+
this.setIntegrationName = function (integrationName) {
|
|
4756
|
+
_this.integrationName = integrationName;
|
|
4757
|
+
};
|
|
4742
4758
|
this.addMpidToSessionHistory = function (mpid, previousMPID) {
|
|
4743
4759
|
var indexOfMPID = _this.currentSessionMPIDs.indexOf(mpid);
|
|
4744
4760
|
if (mpid && previousMPID !== mpid && indexOfMPID < 0) {
|
|
@@ -4763,7 +4779,10 @@ var mParticle = (function () {
|
|
|
4763
4779
|
// We should reprocess the flags and baseUrls in case they have changed when we request an updated config
|
|
4764
4780
|
// such as if the SDK is being self-hosted and the flags are different on the server config
|
|
4765
4781
|
// https://go.mparticle.com/work/SQDSDKS-6317
|
|
4766
|
-
|
|
4782
|
+
// Only update flags if the config actually has flags (don't overwrite with empty object)
|
|
4783
|
+
if (config.flags) {
|
|
4784
|
+
_this.SDKConfig.flags = processFlags(config);
|
|
4785
|
+
}
|
|
4767
4786
|
var baseUrls = processBaseUrls(config, _this.SDKConfig.flags, apiKey);
|
|
4768
4787
|
for (var baseUrlKeys in baseUrls) {
|
|
4769
4788
|
_this.SDKConfig[baseUrlKeys] = baseUrls[baseUrlKeys];
|
|
@@ -4863,7 +4882,7 @@ var mParticle = (function () {
|
|
|
4863
4882
|
for (var baseUrlKey in defaultBaseUrls) {
|
|
4864
4883
|
// Any custom endpoints passed to mpConfig will take priority over direct
|
|
4865
4884
|
// mapping to the silo. The most common use case is a customer provided CNAME.
|
|
4866
|
-
if (baseUrlKey === 'configUrl') {
|
|
4885
|
+
if (baseUrlKey === 'configUrl' || baseUrlKey === 'loggingUrl' || baseUrlKey === 'errorUrl') {
|
|
4867
4886
|
directBaseUrls[baseUrlKey] = config[baseUrlKey] || defaultBaseUrls[baseUrlKey];
|
|
4868
4887
|
continue;
|
|
4869
4888
|
}
|
|
@@ -4878,10 +4897,11 @@ var mParticle = (function () {
|
|
|
4878
4897
|
}
|
|
4879
4898
|
|
|
4880
4899
|
var Logger = /** @class */function () {
|
|
4881
|
-
function Logger(config) {
|
|
4900
|
+
function Logger(config, reportingLogger) {
|
|
4882
4901
|
var _a, _b;
|
|
4883
4902
|
this.logLevel = (_a = config.logLevel) !== null && _a !== void 0 ? _a : LogLevelType.Warning;
|
|
4884
4903
|
this.logger = (_b = config.logger) !== null && _b !== void 0 ? _b : new ConsoleLogger();
|
|
4904
|
+
this.reportingLogger = reportingLogger;
|
|
4885
4905
|
}
|
|
4886
4906
|
Logger.prototype.verbose = function (msg) {
|
|
4887
4907
|
if (this.logLevel === LogLevelType.None) return;
|
|
@@ -4895,10 +4915,14 @@ var mParticle = (function () {
|
|
|
4895
4915
|
this.logger.warning(msg);
|
|
4896
4916
|
}
|
|
4897
4917
|
};
|
|
4898
|
-
Logger.prototype.error = function (msg) {
|
|
4918
|
+
Logger.prototype.error = function (msg, codeForReporting) {
|
|
4919
|
+
var _a;
|
|
4899
4920
|
if (this.logLevel === LogLevelType.None) return;
|
|
4900
4921
|
if (this.logger.error) {
|
|
4901
4922
|
this.logger.error(msg);
|
|
4923
|
+
if (codeForReporting) {
|
|
4924
|
+
(_a = this.reportingLogger) === null || _a === void 0 ? void 0 : _a.error(msg, codeForReporting);
|
|
4925
|
+
}
|
|
4902
4926
|
}
|
|
4903
4927
|
};
|
|
4904
4928
|
Logger.prototype.setLogLevel = function (newLogLevel) {
|
|
@@ -9158,6 +9182,17 @@ var mParticle = (function () {
|
|
|
9158
9182
|
};
|
|
9159
9183
|
}
|
|
9160
9184
|
|
|
9185
|
+
var ErrorCodes = {
|
|
9186
|
+
UNKNOWN_ERROR: 'UNKNOWN_ERROR',
|
|
9187
|
+
UNHANDLED_EXCEPTION: 'UNHANDLED_EXCEPTION',
|
|
9188
|
+
IDENTITY_REQUEST: 'IDENTITY_REQUEST'
|
|
9189
|
+
};
|
|
9190
|
+
var WSDKErrorSeverity = {
|
|
9191
|
+
ERROR: 'ERROR',
|
|
9192
|
+
INFO: 'INFO',
|
|
9193
|
+
WARNING: 'WARNING'
|
|
9194
|
+
};
|
|
9195
|
+
|
|
9161
9196
|
var HTTPCodes$1 = Constants.HTTPCodes,
|
|
9162
9197
|
Messages$1 = Constants.Messages,
|
|
9163
9198
|
IdentityMethods = Constants.IdentityMethods;
|
|
@@ -9258,11 +9293,11 @@ var mParticle = (function () {
|
|
|
9258
9293
|
};
|
|
9259
9294
|
|
|
9260
9295
|
this.sendIdentityRequest = function (identityApiRequest, method, callback, originalIdentityApiData, parseIdentityResponse, mpid, knownIdentities) {
|
|
9261
|
-
var _a, _b, _c;
|
|
9296
|
+
var _a, _b, _c, _d;
|
|
9262
9297
|
return __awaiter(this, void 0, void 0, function () {
|
|
9263
|
-
var requestCount, invokeCallback, Logger, previousMPID, uploadUrl, uploader, fetchPayload, response, identityResponse, message,
|
|
9264
|
-
return __generator(this, function (
|
|
9265
|
-
switch (
|
|
9298
|
+
var requestCount, invokeCallback, Logger, previousMPID, uploadUrl, uploader, fetchPayload, response, identityResponse, message, _e, responseBody, errorResponse, errorMessage, errorMessage, requestCount, err_1, requestCount, errorMessage;
|
|
9299
|
+
return __generator(this, function (_f) {
|
|
9300
|
+
switch (_f.label) {
|
|
9266
9301
|
case 0:
|
|
9267
9302
|
if ((_a = mpInstance._RoktManager) === null || _a === void 0 ? void 0 : _a.isInitialized) {
|
|
9268
9303
|
mpInstance._Store.identifyRequestCount = (mpInstance._Store.identifyRequestCount || 0) + 1;
|
|
@@ -9296,16 +9331,16 @@ var mParticle = (function () {
|
|
|
9296
9331
|
body: JSON.stringify(identityApiRequest)
|
|
9297
9332
|
};
|
|
9298
9333
|
mpInstance._Store.identityCallInFlight = true;
|
|
9299
|
-
|
|
9334
|
+
_f.label = 1;
|
|
9300
9335
|
case 1:
|
|
9301
|
-
|
|
9336
|
+
_f.trys.push([1, 9,, 10]);
|
|
9302
9337
|
return [4 /*yield*/, uploader.upload(fetchPayload)];
|
|
9303
9338
|
case 2:
|
|
9304
|
-
response =
|
|
9339
|
+
response = _f.sent();
|
|
9305
9340
|
identityResponse = void 0;
|
|
9306
9341
|
message = void 0;
|
|
9307
|
-
|
|
9308
|
-
switch (
|
|
9342
|
+
_e = response.status;
|
|
9343
|
+
switch (_e) {
|
|
9309
9344
|
case HTTP_ACCEPTED:
|
|
9310
9345
|
return [3 /*break*/, 3];
|
|
9311
9346
|
case HTTP_OK:
|
|
@@ -9318,12 +9353,12 @@ var mParticle = (function () {
|
|
|
9318
9353
|
if (!response.json) return [3 /*break*/, 5];
|
|
9319
9354
|
return [4 /*yield*/, response.json()];
|
|
9320
9355
|
case 4:
|
|
9321
|
-
responseBody =
|
|
9356
|
+
responseBody = _f.sent();
|
|
9322
9357
|
identityResponse = this.getIdentityResponseFromFetch(response, responseBody);
|
|
9323
9358
|
return [3 /*break*/, 6];
|
|
9324
9359
|
case 5:
|
|
9325
9360
|
identityResponse = this.getIdentityResponseFromXHR(response);
|
|
9326
|
-
|
|
9361
|
+
_f.label = 6;
|
|
9327
9362
|
case 6:
|
|
9328
9363
|
if (identityResponse.status === HTTP_BAD_REQUEST) {
|
|
9329
9364
|
errorResponse = identityResponse.responseText;
|
|
@@ -9341,10 +9376,19 @@ var mParticle = (function () {
|
|
|
9341
9376
|
return [3 /*break*/, 8];
|
|
9342
9377
|
case 7:
|
|
9343
9378
|
{
|
|
9344
|
-
|
|
9379
|
+
if (response.status >= HTTP_SERVER_ERROR) {
|
|
9380
|
+
throw new Error('Received HTTP Code of ' + response.status);
|
|
9381
|
+
}
|
|
9382
|
+
mpInstance._Store.identityCallInFlight = false;
|
|
9383
|
+
mpInstance._Store.identityCallFailed = false;
|
|
9384
|
+
errorMessage = 'Received HTTP Code of ' + response.status;
|
|
9385
|
+
Logger.error('Error sending identity request to servers - ' + errorMessage);
|
|
9386
|
+
invokeCallback(callback, HTTPCodes$1.noHttpCoverage, errorMessage);
|
|
9387
|
+
return [2 /*return*/];
|
|
9345
9388
|
}
|
|
9346
9389
|
case 8:
|
|
9347
9390
|
mpInstance._Store.identityCallInFlight = false;
|
|
9391
|
+
mpInstance._Store.identityCallFailed = false;
|
|
9348
9392
|
Logger.verbose(message);
|
|
9349
9393
|
if ((_b = mpInstance._RoktManager) === null || _b === void 0 ? void 0 : _b.isInitialized) {
|
|
9350
9394
|
requestCount = mpInstance._Store.identifyRequestCount;
|
|
@@ -9353,14 +9397,16 @@ var mParticle = (function () {
|
|
|
9353
9397
|
parseIdentityResponse(identityResponse, previousMPID, callback, originalIdentityApiData, method, knownIdentities, false);
|
|
9354
9398
|
return [3 /*break*/, 10];
|
|
9355
9399
|
case 9:
|
|
9356
|
-
err_1 =
|
|
9400
|
+
err_1 = _f.sent();
|
|
9357
9401
|
mpInstance._Store.identityCallInFlight = false;
|
|
9402
|
+
mpInstance._Store.identityCallFailed = true;
|
|
9358
9403
|
if ((_c = mpInstance._RoktManager) === null || _c === void 0 ? void 0 : _c.isInitialized) {
|
|
9359
9404
|
requestCount = mpInstance._Store.identifyRequestCount;
|
|
9360
9405
|
mpInstance.captureTiming("".concat(requestCount, "-identityRequestEnd"));
|
|
9361
9406
|
}
|
|
9362
9407
|
errorMessage = err_1.message || err_1.toString();
|
|
9363
|
-
Logger.error('Error sending identity request to servers' + ' - ' + errorMessage);
|
|
9408
|
+
Logger.error('Error sending identity request to servers' + ' - ' + errorMessage, ErrorCodes.IDENTITY_REQUEST);
|
|
9409
|
+
(_d = mpInstance.processQueueOnIdentityFailure) === null || _d === void 0 ? void 0 : _d.call(mpInstance);
|
|
9364
9410
|
invokeCallback(callback, HTTPCodes$1.noHttpCoverage, errorMessage);
|
|
9365
9411
|
return [3 /*break*/, 10];
|
|
9366
9412
|
case 10:
|
|
@@ -9708,8 +9754,15 @@ var mParticle = (function () {
|
|
|
9708
9754
|
this.messageQueue = new Map();
|
|
9709
9755
|
this.sandbox = null;
|
|
9710
9756
|
this.placementAttributesMapping = [];
|
|
9757
|
+
this.onReadyCallback = null;
|
|
9711
9758
|
this.initialized = false;
|
|
9712
9759
|
}
|
|
9760
|
+
/**
|
|
9761
|
+
* Sets a callback to be invoked when RoktManager becomes ready
|
|
9762
|
+
*/
|
|
9763
|
+
RoktManager.prototype.setOnReadyCallback = function (callback) {
|
|
9764
|
+
this.onReadyCallback = callback;
|
|
9765
|
+
};
|
|
9713
9766
|
/**
|
|
9714
9767
|
* Initializes the RoktManager with configuration settings and user data.
|
|
9715
9768
|
*
|
|
@@ -9723,18 +9776,19 @@ var mParticle = (function () {
|
|
|
9723
9776
|
* @throws Logs error to console if placementAttributesMapping parsing fails
|
|
9724
9777
|
*/
|
|
9725
9778
|
RoktManager.prototype.init = function (roktConfig, filteredUser, identityService, store, logger, options, captureTiming) {
|
|
9726
|
-
var _a;
|
|
9727
|
-
var
|
|
9728
|
-
userAttributeFilters =
|
|
9729
|
-
settings =
|
|
9730
|
-
var
|
|
9731
|
-
placementAttributesMapping =
|
|
9732
|
-
hashedEmailUserIdentityType =
|
|
9779
|
+
var _a, _b;
|
|
9780
|
+
var _c = roktConfig || {},
|
|
9781
|
+
userAttributeFilters = _c.userAttributeFilters,
|
|
9782
|
+
settings = _c.settings;
|
|
9783
|
+
var _d = settings || {},
|
|
9784
|
+
placementAttributesMapping = _d.placementAttributesMapping,
|
|
9785
|
+
hashedEmailUserIdentityType = _d.hashedEmailUserIdentityType;
|
|
9733
9786
|
this.mappedEmailShaIdentityType = (_a = hashedEmailUserIdentityType === null || hashedEmailUserIdentityType === void 0 ? void 0 : hashedEmailUserIdentityType.toLowerCase()) !== null && _a !== void 0 ? _a : null;
|
|
9734
9787
|
this.identityService = identityService;
|
|
9735
9788
|
this.store = store;
|
|
9736
9789
|
this.logger = logger;
|
|
9737
9790
|
this.captureTiming = captureTiming;
|
|
9791
|
+
(_b = this.captureTiming) === null || _b === void 0 ? void 0 : _b.call(this, PerformanceMarkType.JointSdkRoktKitInit);
|
|
9738
9792
|
this.filters = {
|
|
9739
9793
|
userAttributeFilters: userAttributeFilters,
|
|
9740
9794
|
filterUserAttributes: KitFilterHelper.filterUserAttributes,
|
|
@@ -9771,8 +9825,20 @@ var mParticle = (function () {
|
|
|
9771
9825
|
configurable: true
|
|
9772
9826
|
});
|
|
9773
9827
|
RoktManager.prototype.attachKit = function (kit) {
|
|
9828
|
+
var _a, _b, _c, _d;
|
|
9774
9829
|
this.kit = kit;
|
|
9830
|
+
if ((_a = kit.settings) === null || _a === void 0 ? void 0 : _a.accountId) {
|
|
9831
|
+
this.store.setRoktAccountId(kit.settings.accountId);
|
|
9832
|
+
}
|
|
9833
|
+
if (kit.integrationName) {
|
|
9834
|
+
(_b = this.store) === null || _b === void 0 ? void 0 : _b.setIntegrationName(kit.integrationName);
|
|
9835
|
+
}
|
|
9775
9836
|
this.processMessageQueue();
|
|
9837
|
+
try {
|
|
9838
|
+
(_c = this.onReadyCallback) === null || _c === void 0 ? void 0 : _c.call(this);
|
|
9839
|
+
} catch (e) {
|
|
9840
|
+
(_d = this.logger) === null || _d === void 0 ? void 0 : _d.error('RoktManager: Error in onReadyCallback: ' + e);
|
|
9841
|
+
}
|
|
9776
9842
|
};
|
|
9777
9843
|
/**
|
|
9778
9844
|
* Renders ads based on the options provided
|
|
@@ -9790,29 +9856,27 @@ var mParticle = (function () {
|
|
|
9790
9856
|
* });
|
|
9791
9857
|
*/
|
|
9792
9858
|
RoktManager.prototype.selectPlacements = function (options) {
|
|
9793
|
-
var _a, _b, _c, _d, _e, _f;
|
|
9859
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
9794
9860
|
return __awaiter(this, void 0, void 0, function () {
|
|
9795
9861
|
var attributes, sandboxValue, mappedAttributes, currentUserIdentities_1, currentEmail, newEmail, currentHashedEmail, newHashedEmail, isValidHashedEmailIdentityType, emailChanged, hashedEmailChanged, newIdentities_1, error_1, finalUserIdentities, enrichedAttributes, hashedEmail, enrichedOptions, error_2;
|
|
9796
9862
|
var _this = this;
|
|
9797
|
-
return __generator(this, function (
|
|
9798
|
-
switch (
|
|
9863
|
+
return __generator(this, function (_h) {
|
|
9864
|
+
switch (_h.label) {
|
|
9799
9865
|
case 0:
|
|
9800
|
-
|
|
9801
|
-
this.captureTiming(PerformanceMarkType.JointSdkSelectPlacements);
|
|
9802
|
-
}
|
|
9866
|
+
(_a = this.captureTiming) === null || _a === void 0 ? void 0 : _a.call(this, PerformanceMarkType.JointSdkSelectPlacements);
|
|
9803
9867
|
// Queue if kit isn't ready OR if identity is in flight
|
|
9804
|
-
if (!this.isReady() || ((
|
|
9868
|
+
if (!this.isReady() || ((_b = this.store) === null || _b === void 0 ? void 0 : _b.identityCallInFlight)) {
|
|
9805
9869
|
return [2 /*return*/, this.deferredCall('selectPlacements', options)];
|
|
9806
9870
|
}
|
|
9807
|
-
|
|
9871
|
+
_h.label = 1;
|
|
9808
9872
|
case 1:
|
|
9809
|
-
|
|
9873
|
+
_h.trys.push([1, 6,, 7]);
|
|
9810
9874
|
attributes = options.attributes;
|
|
9811
9875
|
sandboxValue = (attributes === null || attributes === void 0 ? void 0 : attributes.sandbox) || null;
|
|
9812
9876
|
mappedAttributes = this.mapPlacementAttributes(attributes, this.placementAttributesMapping);
|
|
9813
|
-
(
|
|
9877
|
+
(_c = this.logger) === null || _c === void 0 ? void 0 : _c.verbose("mParticle.Rokt selectPlacements called with attributes:\n".concat(JSON.stringify(attributes, null, 2)));
|
|
9814
9878
|
this.currentUser = this.identityService.getCurrentUser();
|
|
9815
|
-
currentUserIdentities_1 = ((
|
|
9879
|
+
currentUserIdentities_1 = ((_e = (_d = this.currentUser) === null || _d === void 0 ? void 0 : _d.getUserIdentities()) === null || _e === void 0 ? void 0 : _e.userIdentities) || {};
|
|
9816
9880
|
currentEmail = currentUserIdentities_1.email;
|
|
9817
9881
|
newEmail = mappedAttributes.email;
|
|
9818
9882
|
currentHashedEmail = void 0;
|
|
@@ -9836,9 +9900,9 @@ var mParticle = (function () {
|
|
|
9836
9900
|
this.logger.warning("emailsha256 mismatch detected. Current mParticle hashedEmail differs from hashedEmail passed to selectPlacements call. Proceeding to call identify with hashedEmail from selectPlacements call. Please verify your implementation.");
|
|
9837
9901
|
}
|
|
9838
9902
|
if (!!isEmpty(newIdentities_1)) return [3 /*break*/, 5];
|
|
9839
|
-
|
|
9903
|
+
_h.label = 2;
|
|
9840
9904
|
case 2:
|
|
9841
|
-
|
|
9905
|
+
_h.trys.push([2, 4,, 5]);
|
|
9842
9906
|
return [4 /*yield*/, new Promise(function (resolve, reject) {
|
|
9843
9907
|
_this.identityService.identify({
|
|
9844
9908
|
userIdentities: __assign(__assign({}, currentUserIdentities_1), newIdentities_1)
|
|
@@ -9847,16 +9911,16 @@ var mParticle = (function () {
|
|
|
9847
9911
|
});
|
|
9848
9912
|
})];
|
|
9849
9913
|
case 3:
|
|
9850
|
-
|
|
9914
|
+
_h.sent();
|
|
9851
9915
|
return [3 /*break*/, 5];
|
|
9852
9916
|
case 4:
|
|
9853
|
-
error_1 =
|
|
9917
|
+
error_1 = _h.sent();
|
|
9854
9918
|
this.logger.error('Failed to identify user with new email: ' + JSON.stringify(error_1));
|
|
9855
9919
|
return [3 /*break*/, 5];
|
|
9856
9920
|
case 5:
|
|
9857
9921
|
// Refresh current user identities to ensure we have the latest values before building enrichedAttributes
|
|
9858
9922
|
this.currentUser = this.identityService.getCurrentUser();
|
|
9859
|
-
finalUserIdentities = ((
|
|
9923
|
+
finalUserIdentities = ((_g = (_f = this.currentUser) === null || _f === void 0 ? void 0 : _f.getUserIdentities()) === null || _g === void 0 ? void 0 : _g.userIdentities) || {};
|
|
9860
9924
|
this.setUserAttributes(mappedAttributes);
|
|
9861
9925
|
enrichedAttributes = __assign(__assign({}, mappedAttributes), sandboxValue !== null ? {
|
|
9862
9926
|
sandbox: sandboxValue
|
|
@@ -9878,7 +9942,7 @@ var mParticle = (function () {
|
|
|
9878
9942
|
});
|
|
9879
9943
|
return [2 /*return*/, this.kit.selectPlacements(enrichedOptions)];
|
|
9880
9944
|
case 6:
|
|
9881
|
-
error_2 =
|
|
9945
|
+
error_2 = _h.sent();
|
|
9882
9946
|
return [2 /*return*/, Promise.reject(error_2 instanceof Error ? error_2 : new Error('Unknown error occurred'))];
|
|
9883
9947
|
case 7:
|
|
9884
9948
|
return [2 /*return*/];
|
|
@@ -10213,6 +10277,138 @@ var mParticle = (function () {
|
|
|
10213
10277
|
return CookieConsentManager;
|
|
10214
10278
|
}();
|
|
10215
10279
|
|
|
10280
|
+
// Header key constants
|
|
10281
|
+
var HEADER_ACCEPT = 'Accept';
|
|
10282
|
+
var HEADER_CONTENT_TYPE = 'Content-Type';
|
|
10283
|
+
var HEADER_ROKT_LAUNCHER_VERSION = 'rokt-launcher-version';
|
|
10284
|
+
var HEADER_ROKT_LAUNCHER_INSTANCE_GUID = 'rokt-launcher-instance-guid';
|
|
10285
|
+
var HEADER_ROKT_WSDK_VERSION = 'rokt-wsdk-version';
|
|
10286
|
+
var ReportingLogger = /** @class */function () {
|
|
10287
|
+
function ReportingLogger(config, sdkVersion, store, launcherInstanceGuid, rateLimiter) {
|
|
10288
|
+
var _this = this;
|
|
10289
|
+
this.sdkVersion = sdkVersion;
|
|
10290
|
+
this.launcherInstanceGuid = launcherInstanceGuid;
|
|
10291
|
+
this.reporter = 'mp-wsdk';
|
|
10292
|
+
this.isFeatureFlagEnabled = function () {
|
|
10293
|
+
return _this.isLoggingEnabled;
|
|
10294
|
+
};
|
|
10295
|
+
this.loggingUrl = "https://".concat(config.loggingUrl || Constants.DefaultBaseUrls.loggingUrl);
|
|
10296
|
+
this.errorUrl = "https://".concat(config.errorUrl || Constants.DefaultBaseUrls.errorUrl);
|
|
10297
|
+
this.isLoggingEnabled = config.isLoggingEnabled || false;
|
|
10298
|
+
this.store = store !== null && store !== void 0 ? store : null;
|
|
10299
|
+
this.isEnabled = this.isReportingEnabled();
|
|
10300
|
+
this.rateLimiter = rateLimiter !== null && rateLimiter !== void 0 ? rateLimiter : new RateLimiter();
|
|
10301
|
+
}
|
|
10302
|
+
ReportingLogger.prototype.setStore = function (store) {
|
|
10303
|
+
this.store = store;
|
|
10304
|
+
};
|
|
10305
|
+
ReportingLogger.prototype.info = function (msg, code) {
|
|
10306
|
+
this.sendLog(WSDKErrorSeverity.INFO, msg, code);
|
|
10307
|
+
};
|
|
10308
|
+
ReportingLogger.prototype.error = function (msg, code, stackTrace) {
|
|
10309
|
+
this.sendError(WSDKErrorSeverity.ERROR, msg, code, stackTrace);
|
|
10310
|
+
};
|
|
10311
|
+
ReportingLogger.prototype.warning = function (msg, code) {
|
|
10312
|
+
this.sendError(WSDKErrorSeverity.WARNING, msg, code);
|
|
10313
|
+
};
|
|
10314
|
+
ReportingLogger.prototype.sendToServer = function (url, severity, msg, code, stackTrace) {
|
|
10315
|
+
if (!this.canSendLog(severity)) return;
|
|
10316
|
+
try {
|
|
10317
|
+
var logRequest = this.buildLogRequest(severity, msg, code, stackTrace);
|
|
10318
|
+
var uploader = new FetchUploader(url);
|
|
10319
|
+
var payload = {
|
|
10320
|
+
method: 'POST',
|
|
10321
|
+
headers: this.getHeaders(),
|
|
10322
|
+
body: JSON.stringify(logRequest)
|
|
10323
|
+
};
|
|
10324
|
+
uploader.upload(payload)["catch"](function (error) {
|
|
10325
|
+
console.error('ReportingLogger: Failed to send log', error);
|
|
10326
|
+
});
|
|
10327
|
+
} catch (error) {
|
|
10328
|
+
console.error('ReportingLogger: Failed to send log', error);
|
|
10329
|
+
}
|
|
10330
|
+
};
|
|
10331
|
+
ReportingLogger.prototype.sendLog = function (severity, msg, code, stackTrace) {
|
|
10332
|
+
this.sendToServer(this.loggingUrl, severity, msg, code, stackTrace);
|
|
10333
|
+
};
|
|
10334
|
+
ReportingLogger.prototype.sendError = function (severity, msg, code, stackTrace) {
|
|
10335
|
+
this.sendToServer(this.errorUrl, severity, msg, code, stackTrace);
|
|
10336
|
+
};
|
|
10337
|
+
ReportingLogger.prototype.buildLogRequest = function (severity, msg, code, stackTrace) {
|
|
10338
|
+
var _a, _b;
|
|
10339
|
+
return {
|
|
10340
|
+
additionalInformation: {
|
|
10341
|
+
message: msg,
|
|
10342
|
+
version: this.getVersion()
|
|
10343
|
+
},
|
|
10344
|
+
severity: severity,
|
|
10345
|
+
code: code !== null && code !== void 0 ? code : ErrorCodes.UNKNOWN_ERROR,
|
|
10346
|
+
url: this.getUrl(),
|
|
10347
|
+
deviceInfo: this.getUserAgent(),
|
|
10348
|
+
stackTrace: stackTrace,
|
|
10349
|
+
reporter: this.reporter,
|
|
10350
|
+
// Integration will be set to integrationName once the kit connects via RoktManager.attachKit()
|
|
10351
|
+
integration: (_b = (_a = this.store) === null || _a === void 0 ? void 0 : _a.getIntegrationName()) !== null && _b !== void 0 ? _b : 'mp-wsdk'
|
|
10352
|
+
};
|
|
10353
|
+
};
|
|
10354
|
+
ReportingLogger.prototype.getVersion = function () {
|
|
10355
|
+
var _a, _b, _c;
|
|
10356
|
+
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);
|
|
10357
|
+
};
|
|
10358
|
+
ReportingLogger.prototype.isReportingEnabled = function () {
|
|
10359
|
+
return this.isDebugModeEnabled() || this.isRoktDomainPresent() && this.isFeatureFlagEnabled();
|
|
10360
|
+
};
|
|
10361
|
+
ReportingLogger.prototype.isRoktDomainPresent = function () {
|
|
10362
|
+
return typeof window !== 'undefined' && Boolean(window['ROKT_DOMAIN']);
|
|
10363
|
+
};
|
|
10364
|
+
ReportingLogger.prototype.isDebugModeEnabled = function () {
|
|
10365
|
+
var _a, _b, _c, _d;
|
|
10366
|
+
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);
|
|
10367
|
+
};
|
|
10368
|
+
ReportingLogger.prototype.canSendLog = function (severity) {
|
|
10369
|
+
return this.isEnabled && !this.isRateLimited(severity);
|
|
10370
|
+
};
|
|
10371
|
+
ReportingLogger.prototype.isRateLimited = function (severity) {
|
|
10372
|
+
return this.rateLimiter.incrementAndCheck(severity);
|
|
10373
|
+
};
|
|
10374
|
+
ReportingLogger.prototype.getUrl = function () {
|
|
10375
|
+
var _a;
|
|
10376
|
+
return typeof window !== 'undefined' ? (_a = window.location) === null || _a === void 0 ? void 0 : _a.href : undefined;
|
|
10377
|
+
};
|
|
10378
|
+
ReportingLogger.prototype.getUserAgent = function () {
|
|
10379
|
+
var _a;
|
|
10380
|
+
return typeof window !== 'undefined' ? (_a = window.navigator) === null || _a === void 0 ? void 0 : _a.userAgent : undefined;
|
|
10381
|
+
};
|
|
10382
|
+
ReportingLogger.prototype.getHeaders = function () {
|
|
10383
|
+
var _a;
|
|
10384
|
+
var _b, _c;
|
|
10385
|
+
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);
|
|
10386
|
+
if (this.launcherInstanceGuid) {
|
|
10387
|
+
headers[HEADER_ROKT_LAUNCHER_INSTANCE_GUID] = this.launcherInstanceGuid;
|
|
10388
|
+
}
|
|
10389
|
+
var accountId = (_c = (_b = this.store) === null || _b === void 0 ? void 0 : _b.getRoktAccountId) === null || _c === void 0 ? void 0 : _c.call(_b);
|
|
10390
|
+
if (accountId) {
|
|
10391
|
+
headers['rokt-account-id'] = accountId;
|
|
10392
|
+
}
|
|
10393
|
+
return headers;
|
|
10394
|
+
};
|
|
10395
|
+
return ReportingLogger;
|
|
10396
|
+
}();
|
|
10397
|
+
var RateLimiter = /** @class */function () {
|
|
10398
|
+
function RateLimiter() {
|
|
10399
|
+
this.rateLimits = new Map([[WSDKErrorSeverity.ERROR, 10], [WSDKErrorSeverity.WARNING, 10], [WSDKErrorSeverity.INFO, 10]]);
|
|
10400
|
+
this.logCount = new Map();
|
|
10401
|
+
}
|
|
10402
|
+
RateLimiter.prototype.incrementAndCheck = function (severity) {
|
|
10403
|
+
var count = this.logCount.get(severity) || 0;
|
|
10404
|
+
var limit = this.rateLimits.get(severity) || 10;
|
|
10405
|
+
var newCount = count + 1;
|
|
10406
|
+
this.logCount.set(severity, newCount);
|
|
10407
|
+
return newCount > limit;
|
|
10408
|
+
};
|
|
10409
|
+
return RateLimiter;
|
|
10410
|
+
}();
|
|
10411
|
+
|
|
10216
10412
|
var Messages = Constants.Messages,
|
|
10217
10413
|
HTTPCodes = Constants.HTTPCodes,
|
|
10218
10414
|
FeatureFlags = Constants.FeatureFlags,
|
|
@@ -10254,6 +10450,22 @@ var mParticle = (function () {
|
|
|
10254
10450
|
forwarderConstructors: []
|
|
10255
10451
|
};
|
|
10256
10452
|
this._RoktManager = new RoktManager();
|
|
10453
|
+
this._RoktManager.setOnReadyCallback(function () {
|
|
10454
|
+
self.processQueueOnIdentityFailure();
|
|
10455
|
+
});
|
|
10456
|
+
/**
|
|
10457
|
+
* Processes message and ready queue when identity requests fails but Rokt is ready.
|
|
10458
|
+
*/
|
|
10459
|
+
this.processQueueOnIdentityFailure = function () {
|
|
10460
|
+
var _a, _b, _c;
|
|
10461
|
+
if ((_a = self._Store) === null || _a === void 0 ? void 0 : _a.isInitialized) {
|
|
10462
|
+
return;
|
|
10463
|
+
}
|
|
10464
|
+
if (((_b = self._Store) === null || _b === void 0 ? void 0 : _b.identityCallFailed) && ((_c = self._RoktManager) === null || _c === void 0 ? void 0 : _c.isReady())) {
|
|
10465
|
+
self._RoktManager.processMessageQueue();
|
|
10466
|
+
self._preInit.readyQueue = processReadyQueue(self._preInit.readyQueue);
|
|
10467
|
+
}
|
|
10468
|
+
};
|
|
10257
10469
|
// required for forwarders once they reference the mparticle instance
|
|
10258
10470
|
this.IdentityType = IdentityType;
|
|
10259
10471
|
this.EventType = EventType;
|
|
@@ -10321,12 +10533,14 @@ var mParticle = (function () {
|
|
|
10321
10533
|
console.error('Cannot reset mParticle', error);
|
|
10322
10534
|
}
|
|
10323
10535
|
};
|
|
10324
|
-
this._resetForTests = function (config, keepPersistence, instance) {
|
|
10536
|
+
this._resetForTests = function (config, keepPersistence, instance, reportingLogger) {
|
|
10325
10537
|
if (instance._Store) {
|
|
10326
10538
|
delete instance._Store;
|
|
10327
10539
|
}
|
|
10328
|
-
instance.Logger = new Logger(config);
|
|
10540
|
+
instance.Logger = new Logger(config, reportingLogger);
|
|
10329
10541
|
instance._Store = new Store(config, instance);
|
|
10542
|
+
// Update ReportingLogger with the new Store reference to avoid stale data
|
|
10543
|
+
reportingLogger === null || reportingLogger === void 0 ? void 0 : reportingLogger.setStore(instance._Store);
|
|
10330
10544
|
instance._Store.isLocalStorageAvailable = instance._Persistence.determineLocalStorageAvailability(window.localStorage);
|
|
10331
10545
|
instance._Events.stopTracking();
|
|
10332
10546
|
if (!keepPersistence) {
|
|
@@ -10343,12 +10557,15 @@ var mParticle = (function () {
|
|
|
10343
10557
|
};
|
|
10344
10558
|
};
|
|
10345
10559
|
/**
|
|
10346
|
-
*
|
|
10560
|
+
* Executes callback when the SDK is ready, or Rokt is ready but identify requests fail due to server errors.
|
|
10561
|
+
* This ensures Rokt methods like selectPlacements continue to work during backend outages.
|
|
10347
10562
|
* @method ready
|
|
10348
|
-
* @param {Function}
|
|
10563
|
+
* @param {Function} f Callback to execute
|
|
10349
10564
|
*/
|
|
10350
10565
|
this.ready = function (f) {
|
|
10351
|
-
|
|
10566
|
+
var _a, _b;
|
|
10567
|
+
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());
|
|
10568
|
+
if (shouldExecute) {
|
|
10352
10569
|
f();
|
|
10353
10570
|
} else {
|
|
10354
10571
|
self._preInit.readyQueue.push(f);
|
|
@@ -11140,6 +11357,9 @@ var mParticle = (function () {
|
|
|
11140
11357
|
window[launcherInstanceGuidKey] = self._Helpers.generateUniqueId();
|
|
11141
11358
|
}
|
|
11142
11359
|
};
|
|
11360
|
+
this.getLauncherInstanceGuid = function () {
|
|
11361
|
+
return window[launcherInstanceGuidKey];
|
|
11362
|
+
};
|
|
11143
11363
|
this.captureTiming = function (metricsName) {
|
|
11144
11364
|
var _a;
|
|
11145
11365
|
if (typeof window !== 'undefined' && ((_a = window.performance) === null || _a === void 0 ? void 0 : _a.mark)) {
|
|
@@ -11149,6 +11369,7 @@ var mParticle = (function () {
|
|
|
11149
11369
|
}
|
|
11150
11370
|
// Some (server) config settings need to be returned before they are set on SDKConfig in a self hosted environment
|
|
11151
11371
|
function completeSDKInitialization(apiKey, config, mpInstance) {
|
|
11372
|
+
var _a;
|
|
11152
11373
|
var kitBlocker = createKitBlocker(config, mpInstance);
|
|
11153
11374
|
var getFeatureFlag = mpInstance._Helpers.getFeatureFlag;
|
|
11154
11375
|
mpInstance._APIClient = new APIClient(mpInstance, kitBlocker);
|
|
@@ -11194,6 +11415,8 @@ var mParticle = (function () {
|
|
|
11194
11415
|
// Configure Rokt Manager with user and filtered user
|
|
11195
11416
|
var roktConfig = parseConfig(config, 'Rokt', 181);
|
|
11196
11417
|
if (roktConfig) {
|
|
11418
|
+
var accountId = (_a = roktConfig.settings) === null || _a === void 0 ? void 0 : _a.accountId;
|
|
11419
|
+
mpInstance._Store.setRoktAccountId(accountId);
|
|
11197
11420
|
var userAttributeFilters = roktConfig.userAttributeFilters;
|
|
11198
11421
|
var roktFilteredUser = filteredMparticleUser(currentUserMPID, {
|
|
11199
11422
|
userAttributeFilters: userAttributeFilters
|
|
@@ -11291,9 +11514,11 @@ var mParticle = (function () {
|
|
|
11291
11514
|
}
|
|
11292
11515
|
function runPreConfigFetchInitialization(mpInstance, apiKey, config) {
|
|
11293
11516
|
var _a;
|
|
11294
|
-
mpInstance.
|
|
11517
|
+
mpInstance._ReportingLogger = new ReportingLogger(config, Constants.sdkVersion, undefined, mpInstance.getLauncherInstanceGuid());
|
|
11518
|
+
mpInstance.Logger = new Logger(config, mpInstance._ReportingLogger);
|
|
11295
11519
|
mpInstance._Store = new Store(config, mpInstance, apiKey);
|
|
11296
11520
|
window.mParticle.Store = mpInstance._Store;
|
|
11521
|
+
mpInstance._ReportingLogger.setStore(mpInstance._Store);
|
|
11297
11522
|
mpInstance.Logger.verbose(StartingInitialization);
|
|
11298
11523
|
// Initialize CookieConsentManager with privacy flags from launcherOptions
|
|
11299
11524
|
var _b = (_a = config === null || config === void 0 ? void 0 : config.launcherOptions) !== null && _a !== void 0 ? _a : {},
|
|
@@ -11345,9 +11570,14 @@ var mParticle = (function () {
|
|
|
11345
11570
|
}
|
|
11346
11571
|
}
|
|
11347
11572
|
function queueIfNotInitialized(func, self) {
|
|
11348
|
-
|
|
11349
|
-
|
|
11350
|
-
|
|
11573
|
+
var _a;
|
|
11574
|
+
// Core SDK methods must wait for Store initialization
|
|
11575
|
+
if (!((_a = self._Store) === null || _a === void 0 ? void 0 : _a.isInitialized)) {
|
|
11576
|
+
self._preInit.readyQueue.push(function () {
|
|
11577
|
+
var _a;
|
|
11578
|
+
if ((_a = self._Store) === null || _a === void 0 ? void 0 : _a.isInitialized) {
|
|
11579
|
+
func();
|
|
11580
|
+
}
|
|
11351
11581
|
});
|
|
11352
11582
|
return true;
|
|
11353
11583
|
}
|