@mparticle/web-sdk 2.66.0 → 2.68.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 +154 -69
- package/dist/mparticle.esm.js +154 -69
- package/dist/mparticle.js +425 -131
- package/dist/types/src/identity/search.d.ts +64 -0
- package/dist/types/src/identity-utils.d.ts +21 -1
- package/dist/types/src/identity.interfaces.d.ts +37 -1
- package/dist/types/src/public-types.d.ts +1 -1
- package/dist/types/src/sdkRuntimeModels.d.ts +5 -5
- package/dist/types/src/stub/mparticle.stub.d.ts +1 -0
- package/package.json +2 -2
- package/src/identity/search.ts +233 -0
- package/src/identity-utils.ts +127 -5
- package/src/identity.interfaces.ts +46 -0
- package/src/identity.js +39 -1
- package/src/mparticle-instance-manager.ts +7 -0
- package/src/public-types.ts +4 -0
- package/src/sdkRuntimeModels.ts +5 -5
- package/src/stub/mparticle.stub.js +1 -0
- package/src/types.ts +4 -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.68.0";
|
|
207
207
|
|
|
208
208
|
var Constants = {
|
|
209
209
|
sdkVersion: version,
|
|
@@ -417,6 +417,7 @@ var mParticle = (function () {
|
|
|
417
417
|
var HTTP_OK = 200;
|
|
418
418
|
var HTTP_ACCEPTED = 202;
|
|
419
419
|
var HTTP_BAD_REQUEST = 400;
|
|
420
|
+
var HTTP_NOT_FOUND = 404;
|
|
420
421
|
var HTTP_SERVER_ERROR = 500;
|
|
421
422
|
|
|
422
423
|
function _typeof$1(o) {
|
|
@@ -524,7 +525,7 @@ var mParticle = (function () {
|
|
|
524
525
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
525
526
|
};
|
|
526
527
|
|
|
527
|
-
var Messages$
|
|
528
|
+
var Messages$a = Constants.Messages;
|
|
528
529
|
var createCookieString = function createCookieString(value) {
|
|
529
530
|
return replaceCommasWithPipes(replaceQuotesWithApostrophes(value));
|
|
530
531
|
};
|
|
@@ -560,12 +561,12 @@ var mParticle = (function () {
|
|
|
560
561
|
var generateDeprecationMessage = function generateDeprecationMessage(methodName, isDeprecated, alternateMethod, docsUrl) {
|
|
561
562
|
var messageArray = [methodName];
|
|
562
563
|
if (isDeprecated) {
|
|
563
|
-
messageArray.push(Messages$
|
|
564
|
+
messageArray.push(Messages$a.DeprecationMessages.MethodHasBeenDeprecated);
|
|
564
565
|
} else {
|
|
565
|
-
messageArray.push(Messages$
|
|
566
|
+
messageArray.push(Messages$a.DeprecationMessages.MethodMarkedForDeprecationPostfix);
|
|
566
567
|
}
|
|
567
568
|
if (alternateMethod) {
|
|
568
|
-
messageArray.push(Messages$
|
|
569
|
+
messageArray.push(Messages$a.DeprecationMessages.AlternativeMethodPrefix);
|
|
569
570
|
messageArray.push(alternateMethod + ".");
|
|
570
571
|
}
|
|
571
572
|
if (docsUrl) {
|
|
@@ -1203,6 +1204,10 @@ var mParticle = (function () {
|
|
|
1203
1204
|
return IdentityType.PhoneNumber2;
|
|
1204
1205
|
case 'phone_number_3':
|
|
1205
1206
|
return IdentityType.PhoneNumber3;
|
|
1207
|
+
case 'email_sha256':
|
|
1208
|
+
return IdentityType.Other;
|
|
1209
|
+
case 'mobile_sha256':
|
|
1210
|
+
return IdentityType.Other2;
|
|
1206
1211
|
default:
|
|
1207
1212
|
return false;
|
|
1208
1213
|
}
|
|
@@ -3118,11 +3123,278 @@ var mParticle = (function () {
|
|
|
3118
3123
|
return BatchUploader;
|
|
3119
3124
|
}();
|
|
3120
3125
|
|
|
3126
|
+
var ErrorCodes = {
|
|
3127
|
+
UNKNOWN_ERROR: 'UNKNOWN_ERROR',
|
|
3128
|
+
UNHANDLED_EXCEPTION: 'UNHANDLED_EXCEPTION',
|
|
3129
|
+
IDENTITY_REQUEST: 'IDENTITY_REQUEST',
|
|
3130
|
+
IDENTITY_MISMATCH: 'IDENTITY_MISMATCH',
|
|
3131
|
+
ROKT_KIT_ATTACHED: 'ROKT_KIT_ATTACHED'
|
|
3132
|
+
};
|
|
3133
|
+
var WSDKErrorSeverity = {
|
|
3134
|
+
ERROR: 'ERROR',
|
|
3135
|
+
INFO: 'INFO',
|
|
3136
|
+
WARNING: 'WARNING'
|
|
3137
|
+
};
|
|
3138
|
+
|
|
3139
|
+
var Modify$4 = Constants.IdentityMethods.Modify;
|
|
3140
|
+
var Validators = {
|
|
3141
|
+
// From ./utils
|
|
3142
|
+
// Utility Functions for backwards compatability
|
|
3143
|
+
isNumber: isNumber,
|
|
3144
|
+
isFunction: isFunction,
|
|
3145
|
+
isStringOrNumber: isStringOrNumber,
|
|
3146
|
+
// Validator Functions
|
|
3147
|
+
isValidAttributeValue: isValidAttributeValue,
|
|
3148
|
+
// Validator Functions
|
|
3149
|
+
// Neither null nor undefined can be a valid Key
|
|
3150
|
+
isValidKeyValue: function isValidKeyValue(key) {
|
|
3151
|
+
return Boolean(key && !isObject(key) && !Array.isArray(key) && !this.isFunction(key));
|
|
3152
|
+
},
|
|
3153
|
+
removeFalsyIdentityValues: function removeFalsyIdentityValues(identityApiData, logger) {
|
|
3154
|
+
if (!identityApiData || !identityApiData.userIdentities) {
|
|
3155
|
+
return identityApiData;
|
|
3156
|
+
}
|
|
3157
|
+
var cleanedData = {};
|
|
3158
|
+
var cleanedUserIdentities = __assign({}, identityApiData.userIdentities);
|
|
3159
|
+
for (var identityType in identityApiData.userIdentities) {
|
|
3160
|
+
if (identityApiData.userIdentities.hasOwnProperty(identityType)) {
|
|
3161
|
+
var value = identityApiData.userIdentities[identityType];
|
|
3162
|
+
// Check if value is falsy (undefined, false, 0, '', etc.) but not null
|
|
3163
|
+
if (value !== null && !value) {
|
|
3164
|
+
logger.warning("Identity value for '".concat(identityType, "' is falsy (").concat(value, "). This value will be removed from the request."));
|
|
3165
|
+
delete cleanedUserIdentities[identityType];
|
|
3166
|
+
}
|
|
3167
|
+
}
|
|
3168
|
+
}
|
|
3169
|
+
cleanedData.userIdentities = cleanedUserIdentities;
|
|
3170
|
+
return cleanedData;
|
|
3171
|
+
},
|
|
3172
|
+
validateIdentities: function validateIdentities(identityApiData, method) {
|
|
3173
|
+
var validIdentityRequestKeys = {
|
|
3174
|
+
userIdentities: 1,
|
|
3175
|
+
onUserAlias: 1,
|
|
3176
|
+
copyUserAttributes: 1
|
|
3177
|
+
};
|
|
3178
|
+
if (identityApiData) {
|
|
3179
|
+
if (method === Modify$4) {
|
|
3180
|
+
if (isObject(identityApiData.userIdentities) && !Object.keys(identityApiData.userIdentities).length || !isObject(identityApiData.userIdentities)) {
|
|
3181
|
+
return {
|
|
3182
|
+
valid: false,
|
|
3183
|
+
error: Constants.Messages.ValidationMessages.ModifyIdentityRequestUserIdentitiesPresent
|
|
3184
|
+
};
|
|
3185
|
+
}
|
|
3186
|
+
}
|
|
3187
|
+
for (var key in identityApiData) {
|
|
3188
|
+
if (identityApiData.hasOwnProperty(key)) {
|
|
3189
|
+
if (!validIdentityRequestKeys[key]) {
|
|
3190
|
+
return {
|
|
3191
|
+
valid: false,
|
|
3192
|
+
error: Constants.Messages.ValidationMessages.IdentityRequesetInvalidKey
|
|
3193
|
+
};
|
|
3194
|
+
}
|
|
3195
|
+
if (key === 'onUserAlias' && !Validators.isFunction(identityApiData[key])) {
|
|
3196
|
+
return {
|
|
3197
|
+
valid: false,
|
|
3198
|
+
error: Constants.Messages.ValidationMessages.OnUserAliasType
|
|
3199
|
+
};
|
|
3200
|
+
}
|
|
3201
|
+
}
|
|
3202
|
+
}
|
|
3203
|
+
if (Object.keys(identityApiData).length === 0) {
|
|
3204
|
+
return {
|
|
3205
|
+
valid: true
|
|
3206
|
+
};
|
|
3207
|
+
} else {
|
|
3208
|
+
// identityApiData.userIdentities can't be undefined
|
|
3209
|
+
if (identityApiData.userIdentities === undefined) {
|
|
3210
|
+
return {
|
|
3211
|
+
valid: false,
|
|
3212
|
+
error: Constants.Messages.ValidationMessages.UserIdentities
|
|
3213
|
+
};
|
|
3214
|
+
// identityApiData.userIdentities can be null, but if it isn't null or undefined (above conditional), it must be an object
|
|
3215
|
+
} else if (identityApiData.userIdentities !== null && !isObject(identityApiData.userIdentities)) {
|
|
3216
|
+
return {
|
|
3217
|
+
valid: false,
|
|
3218
|
+
error: Constants.Messages.ValidationMessages.UserIdentities
|
|
3219
|
+
};
|
|
3220
|
+
}
|
|
3221
|
+
if (isObject(identityApiData.userIdentities) && Object.keys(identityApiData.userIdentities).length) {
|
|
3222
|
+
for (var identityType in identityApiData.userIdentities) {
|
|
3223
|
+
if (identityApiData.userIdentities.hasOwnProperty(identityType)) {
|
|
3224
|
+
if (Types.IdentityType.getIdentityType(identityType) === false) {
|
|
3225
|
+
return {
|
|
3226
|
+
valid: false,
|
|
3227
|
+
error: Constants.Messages.ValidationMessages.UserIdentitiesInvalidKey
|
|
3228
|
+
};
|
|
3229
|
+
}
|
|
3230
|
+
if (!(typeof identityApiData.userIdentities[identityType] === 'string' || identityApiData.userIdentities[identityType] === null)) {
|
|
3231
|
+
return {
|
|
3232
|
+
valid: false,
|
|
3233
|
+
error: Constants.Messages.ValidationMessages.UserIdentitiesInvalidValues
|
|
3234
|
+
};
|
|
3235
|
+
}
|
|
3236
|
+
}
|
|
3237
|
+
}
|
|
3238
|
+
}
|
|
3239
|
+
}
|
|
3240
|
+
}
|
|
3241
|
+
return {
|
|
3242
|
+
valid: true
|
|
3243
|
+
};
|
|
3244
|
+
}
|
|
3245
|
+
};
|
|
3246
|
+
|
|
3247
|
+
var HTTPCodes$4 = Constants.HTTPCodes;
|
|
3248
|
+
/**
|
|
3249
|
+
* Sends a POST to mParticle's IDSync Search endpoint and invokes `callback`
|
|
3250
|
+
* with the HTTP status and parsed body.
|
|
3251
|
+
*
|
|
3252
|
+
* Defensive contract:
|
|
3253
|
+
* - No identifier with a non-empty string value -> callback with
|
|
3254
|
+
* `{ httpCode: noHttpCoverage }`, no network call.
|
|
3255
|
+
* - Missing `apiKey` -> callback with `{ httpCode: noHttpCoverage }`,
|
|
3256
|
+
* no network call.
|
|
3257
|
+
* - Network/JSON-parse errors are caught and surfaced via the callback,
|
|
3258
|
+
* never thrown. Network errors are also reported through the optional
|
|
3259
|
+
* `errorReporter` so any registered IErrorReportingService can observe
|
|
3260
|
+
* them (matches the pattern used by identifyRequest in identityApiClient).
|
|
3261
|
+
*/
|
|
3262
|
+
var sendSearchRequest = function sendSearchRequest(knownIdentities, apiKey, requestBuilder, searchUrl, callback, logger, uploader, errorReporter) {
|
|
3263
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
3264
|
+
var safeInvoke, cleanedKnownIdentities, requestEnvelope, requestBody, fetchPayload, api, response, body, xhrLike, e_2, message, reportMessage;
|
|
3265
|
+
return __generator(this, function (_a) {
|
|
3266
|
+
switch (_a.label) {
|
|
3267
|
+
case 0:
|
|
3268
|
+
// Validate the callback up front. If it isn't a function we have nowhere
|
|
3269
|
+
// to deliver a result to, so log and bail out without invoking anything.
|
|
3270
|
+
if (!isFunction(callback)) {
|
|
3271
|
+
logger.error('search called without a callback function; skipping request.');
|
|
3272
|
+
return [2 /*return*/];
|
|
3273
|
+
}
|
|
3274
|
+
|
|
3275
|
+
safeInvoke = function safeInvoke(result) {
|
|
3276
|
+
try {
|
|
3277
|
+
callback(result);
|
|
3278
|
+
} catch (e) {
|
|
3279
|
+
logger.error('Error invoking search callback: ' + ((e === null || e === void 0 ? void 0 : e.message) || String(e)));
|
|
3280
|
+
}
|
|
3281
|
+
};
|
|
3282
|
+
cleanedKnownIdentities = Validators.removeFalsyIdentityValues({
|
|
3283
|
+
userIdentities: knownIdentities !== null && knownIdentities !== void 0 ? knownIdentities : {}
|
|
3284
|
+
}, logger).userIdentities;
|
|
3285
|
+
// No usable identifier -> deliver httpCode: noHttpCoverage so callers
|
|
3286
|
+
// waiting on the callback (e.g. to clear a loading state) don't hang.
|
|
3287
|
+
if (!Object.values(cleanedKnownIdentities !== null && cleanedKnownIdentities !== void 0 ? cleanedKnownIdentities : {}).some(function (v) {
|
|
3288
|
+
return typeof v === 'string' && v.length > 0;
|
|
3289
|
+
})) {
|
|
3290
|
+
logger.verbose('Identity search called with empty identifiers; skipping request.');
|
|
3291
|
+
safeInvoke({
|
|
3292
|
+
httpCode: HTTPCodes$4.noHttpCoverage
|
|
3293
|
+
});
|
|
3294
|
+
return [2 /*return*/];
|
|
3295
|
+
}
|
|
3296
|
+
// No API key -> same: deliver noHttpCoverage rather than hanging.
|
|
3297
|
+
if (!apiKey) {
|
|
3298
|
+
logger.verbose('search called without a workspace API key; skipping request.');
|
|
3299
|
+
safeInvoke({
|
|
3300
|
+
httpCode: HTTPCodes$4.noHttpCoverage
|
|
3301
|
+
});
|
|
3302
|
+
return [2 /*return*/];
|
|
3303
|
+
}
|
|
3304
|
+
|
|
3305
|
+
_a.label = 1;
|
|
3306
|
+
case 1:
|
|
3307
|
+
_a.trys.push([1, 9,, 10]);
|
|
3308
|
+
requestEnvelope = requestBuilder();
|
|
3309
|
+
requestBody = __assign(__assign({}, requestEnvelope), {
|
|
3310
|
+
known_identities: __assign({}, cleanedKnownIdentities)
|
|
3311
|
+
});
|
|
3312
|
+
fetchPayload = {
|
|
3313
|
+
method: 'post',
|
|
3314
|
+
headers: {
|
|
3315
|
+
Accept: 'application/json',
|
|
3316
|
+
'Content-Type': 'application/json',
|
|
3317
|
+
'x-mp-key': apiKey
|
|
3318
|
+
},
|
|
3319
|
+
body: JSON.stringify(requestBody)
|
|
3320
|
+
};
|
|
3321
|
+
api = uploader || (window.fetch ? new FetchUploader(searchUrl) : new XHRUploader(searchUrl));
|
|
3322
|
+
logger.verbose('Sending search request to ' + searchUrl);
|
|
3323
|
+
return [4 /*yield*/, api.upload(fetchPayload, searchUrl)];
|
|
3324
|
+
case 2:
|
|
3325
|
+
response = _a.sent();
|
|
3326
|
+
body = void 0;
|
|
3327
|
+
if (!isFunction(response.json)) return [3 /*break*/, 7];
|
|
3328
|
+
_a.label = 3;
|
|
3329
|
+
case 3:
|
|
3330
|
+
_a.trys.push([3, 5,, 6]);
|
|
3331
|
+
return [4 /*yield*/, response.json()];
|
|
3332
|
+
case 4:
|
|
3333
|
+
body = _a.sent();
|
|
3334
|
+
return [3 /*break*/, 6];
|
|
3335
|
+
case 5:
|
|
3336
|
+
_a.sent();
|
|
3337
|
+
logger.verbose('search response had no parseable JSON body.');
|
|
3338
|
+
return [3 /*break*/, 6];
|
|
3339
|
+
case 6:
|
|
3340
|
+
return [3 /*break*/, 8];
|
|
3341
|
+
case 7:
|
|
3342
|
+
xhrLike = response;
|
|
3343
|
+
if (xhrLike === null || xhrLike === void 0 ? void 0 : xhrLike.responseText) {
|
|
3344
|
+
try {
|
|
3345
|
+
body = JSON.parse(xhrLike.responseText);
|
|
3346
|
+
} catch (e) {
|
|
3347
|
+
logger.verbose('search XHR response was not valid JSON.');
|
|
3348
|
+
}
|
|
3349
|
+
}
|
|
3350
|
+
_a.label = 8;
|
|
3351
|
+
case 8:
|
|
3352
|
+
if (response.status === HTTP_OK) {
|
|
3353
|
+
logger.verbose('search received 200 OK.');
|
|
3354
|
+
} else if (response.status === HTTP_NOT_FOUND) {
|
|
3355
|
+
// 404 NOT_FOUND_ERROR is an expected steady-state outcome and is
|
|
3356
|
+
// intentionally not logged as an error.
|
|
3357
|
+
logger.verbose('search received 404 (no match).');
|
|
3358
|
+
} else {
|
|
3359
|
+
logger.verbose('search received non-success status ' + response.status);
|
|
3360
|
+
}
|
|
3361
|
+
safeInvoke({
|
|
3362
|
+
httpCode: response.status,
|
|
3363
|
+
body: body
|
|
3364
|
+
});
|
|
3365
|
+
return [3 /*break*/, 10];
|
|
3366
|
+
case 9:
|
|
3367
|
+
e_2 = _a.sent();
|
|
3368
|
+
message = (e_2 === null || e_2 === void 0 ? void 0 : e_2.message) || String(e_2);
|
|
3369
|
+
reportMessage = 'Error sending search request: ' + message;
|
|
3370
|
+
logger.error(reportMessage);
|
|
3371
|
+
// Mirror the identity-route pattern in identityApiClient.ts: log to
|
|
3372
|
+
// console AND push a structured report through the dispatcher so any
|
|
3373
|
+
// registered IErrorReportingService (e.g. the Rokt kit's) can observe
|
|
3374
|
+
// the failure.
|
|
3375
|
+
errorReporter === null || errorReporter === void 0 ? void 0 : errorReporter.report({
|
|
3376
|
+
message: reportMessage,
|
|
3377
|
+
code: ErrorCodes.IDENTITY_REQUEST,
|
|
3378
|
+
severity: WSDKErrorSeverity.ERROR
|
|
3379
|
+
});
|
|
3380
|
+
safeInvoke({
|
|
3381
|
+
httpCode: HTTPCodes$4.noHttpCoverage
|
|
3382
|
+
});
|
|
3383
|
+
return [3 /*break*/, 10];
|
|
3384
|
+
case 10:
|
|
3385
|
+
return [2 /*return*/];
|
|
3386
|
+
}
|
|
3387
|
+
});
|
|
3388
|
+
});
|
|
3389
|
+
};
|
|
3390
|
+
|
|
3121
3391
|
var _a = Constants.IdentityMethods,
|
|
3122
3392
|
Identify$2 = _a.Identify,
|
|
3123
|
-
Modify$
|
|
3393
|
+
Modify$3 = _a.Modify,
|
|
3124
3394
|
Login$2 = _a.Login,
|
|
3125
3395
|
Logout$2 = _a.Logout;
|
|
3396
|
+
var HTTPCodes$3 = Constants.HTTPCodes,
|
|
3397
|
+
Messages$9 = Constants.Messages;
|
|
3126
3398
|
var CACHE_HEADER = 'x-mp-max-age';
|
|
3127
3399
|
var cacheOrClearIdCache = function cacheOrClearIdCache(method, knownIdentities, idCache, identityResponse, parsingCachedResponse) {
|
|
3128
3400
|
// when parsing a response that has already been cached, simply return instead of attempting another cache
|
|
@@ -3136,7 +3408,7 @@ var mParticle = (function () {
|
|
|
3136
3408
|
case Identify$2:
|
|
3137
3409
|
cacheIdentityRequest(method, knownIdentities, expireTimestamp, idCache, identityResponse);
|
|
3138
3410
|
break;
|
|
3139
|
-
case Modify$
|
|
3411
|
+
case Modify$3:
|
|
3140
3412
|
case Logout$2:
|
|
3141
3413
|
idCache.purge();
|
|
3142
3414
|
break;
|
|
@@ -3267,13 +3539,40 @@ var mParticle = (function () {
|
|
|
3267
3539
|
var parseIdentityResponse = function parseIdentityResponse(responseText) {
|
|
3268
3540
|
return responseText ? JSON.parse(responseText) : {};
|
|
3269
3541
|
};
|
|
3542
|
+
var SHA256_IDENTITY_ALIASES = {
|
|
3543
|
+
email_sha256: 'other',
|
|
3544
|
+
mobile_sha256: 'other2'
|
|
3545
|
+
};
|
|
3546
|
+
var normalizeUserIdentityKeys = function normalizeUserIdentityKeys(userIdentities) {
|
|
3547
|
+
var normalized = __assign({}, userIdentities);
|
|
3548
|
+
Object.keys(SHA256_IDENTITY_ALIASES).forEach(function (alias) {
|
|
3549
|
+
if (alias in normalized) {
|
|
3550
|
+
var value = normalized[alias];
|
|
3551
|
+
delete normalized[alias];
|
|
3552
|
+
normalized[SHA256_IDENTITY_ALIASES[alias]] = value;
|
|
3553
|
+
}
|
|
3554
|
+
});
|
|
3555
|
+
return normalized;
|
|
3556
|
+
};
|
|
3557
|
+
// Compare two identity objects by key and value, independent of
|
|
3558
|
+
// object key insertion order. The two sides come from different sources
|
|
3559
|
+
// (numeric IdentityType iteration vs. partner-provided / alias-normalized
|
|
3560
|
+
// order)
|
|
3561
|
+
var identitiesEqual = function identitiesEqual(a, b) {
|
|
3562
|
+
var aKeys = Object.keys(a !== null && a !== void 0 ? a : {});
|
|
3563
|
+
var bKeys = Object.keys(b !== null && b !== void 0 ? b : {});
|
|
3564
|
+
if (aKeys.length !== bKeys.length) return false;
|
|
3565
|
+
return aKeys.every(function (key) {
|
|
3566
|
+
return a[key] === b[key];
|
|
3567
|
+
});
|
|
3568
|
+
};
|
|
3270
3569
|
var hasIdentityRequestChanged = function hasIdentityRequestChanged(currentUser, newIdentityRequest) {
|
|
3271
3570
|
if (!currentUser || !(newIdentityRequest === null || newIdentityRequest === void 0 ? void 0 : newIdentityRequest.userIdentities)) {
|
|
3272
3571
|
return false;
|
|
3273
3572
|
}
|
|
3274
3573
|
var currentUserIdentities = currentUser.getUserIdentities().userIdentities;
|
|
3275
|
-
var newIdentities = newIdentityRequest.userIdentities;
|
|
3276
|
-
return
|
|
3574
|
+
var newIdentities = normalizeUserIdentityKeys(newIdentityRequest.userIdentities);
|
|
3575
|
+
return !identitiesEqual(currentUserIdentities, newIdentities);
|
|
3277
3576
|
};
|
|
3278
3577
|
/**
|
|
3279
3578
|
* Checks if deviceId or other user identifiers (like email) were explicitly provided
|
|
@@ -3292,6 +3591,61 @@ var mParticle = (function () {
|
|
|
3292
3591
|
}
|
|
3293
3592
|
return !!((_c = store === null || store === void 0 ? void 0 : store.SDKConfig) === null || _c === void 0 ? void 0 : _c.deviceId);
|
|
3294
3593
|
};
|
|
3594
|
+
/**
|
|
3595
|
+
* Builds the /v1/identify-style envelope (client_sdk, environment,
|
|
3596
|
+
* request_id, request_timestamp_ms) used to correlate IDSync requests
|
|
3597
|
+
* across endpoints. `known_identities` is omitted so the caller can
|
|
3598
|
+
* fold in the search-specific identifiers alongside the envelope.
|
|
3599
|
+
*/
|
|
3600
|
+
var buildIdentitySearchEnvelope = function buildIdentitySearchEnvelope(environment) {
|
|
3601
|
+
return {
|
|
3602
|
+
client_sdk: {
|
|
3603
|
+
platform: Constants.platform,
|
|
3604
|
+
sdk_vendor: Constants.sdkVendor,
|
|
3605
|
+
sdk_version: Constants.sdkVersion
|
|
3606
|
+
},
|
|
3607
|
+
environment: environment,
|
|
3608
|
+
request_id: generateUniqueId(),
|
|
3609
|
+
request_timestamp_ms: Date.now()
|
|
3610
|
+
};
|
|
3611
|
+
};
|
|
3612
|
+
/**
|
|
3613
|
+
* Wires the SDK instance into `sendSearchRequest`: gates on `canLog`,
|
|
3614
|
+
* builds the `/v1/search` URL and request envelope, and dispatches.
|
|
3615
|
+
* Lives here so the SDK glue (URL building, opt-out gate, dispatcher
|
|
3616
|
+
* plumbing) is type-checked instead of being expressed in plain JS.
|
|
3617
|
+
*/
|
|
3618
|
+
var executeSearchRequest = function executeSearchRequest(mpInstance, workspaceApiKey, knownIdentities, callback) {
|
|
3619
|
+
var _Helpers = mpInstance._Helpers,
|
|
3620
|
+
_Store = mpInstance._Store,
|
|
3621
|
+
Logger = mpInstance.Logger,
|
|
3622
|
+
_ErrorReportingDispatcher = mpInstance._ErrorReportingDispatcher;
|
|
3623
|
+
var _a = _Store.SDKConfig,
|
|
3624
|
+
identityUrl = _a.identityUrl,
|
|
3625
|
+
isDevelopmentMode = _a.isDevelopmentMode;
|
|
3626
|
+
if (!_Helpers.canLog()) {
|
|
3627
|
+
Logger.verbose(Messages$9.InformationMessages.AbandonLogEvent);
|
|
3628
|
+
if (isFunction(callback)) {
|
|
3629
|
+
try {
|
|
3630
|
+
callback({
|
|
3631
|
+
httpCode: HTTPCodes$3.loggingDisabledOrMissingAPIKey
|
|
3632
|
+
});
|
|
3633
|
+
} catch (e) {
|
|
3634
|
+
Logger.error('Error invoking search callback: ' + ((e === null || e === void 0 ? void 0 : e.message) || String(e)));
|
|
3635
|
+
}
|
|
3636
|
+
}
|
|
3637
|
+
return;
|
|
3638
|
+
}
|
|
3639
|
+
// The Search endpoint is colocated with /v1/identify under
|
|
3640
|
+
// identityUrl, so we reuse the same service URL builder. We do
|
|
3641
|
+
// NOT append the apiKey to the URL — auth is done via x-mp-key.
|
|
3642
|
+
var serviceUrl = _Helpers.createServiceUrl(identityUrl);
|
|
3643
|
+
var searchUrl = serviceUrl + 'search?cb=1';
|
|
3644
|
+
var environment = isDevelopmentMode ? 'development' : 'production';
|
|
3645
|
+
sendSearchRequest(knownIdentities, workspaceApiKey, function () {
|
|
3646
|
+
return buildIdentitySearchEnvelope(environment);
|
|
3647
|
+
}, searchUrl, callback, Logger, undefined, _ErrorReportingDispatcher);
|
|
3648
|
+
};
|
|
3295
3649
|
|
|
3296
3650
|
function APIClient(mpInstance, kitBlocker) {
|
|
3297
3651
|
this.uploader = null;
|
|
@@ -3454,114 +3808,6 @@ var mParticle = (function () {
|
|
|
3454
3808
|
};
|
|
3455
3809
|
}
|
|
3456
3810
|
|
|
3457
|
-
var Modify$3 = Constants.IdentityMethods.Modify;
|
|
3458
|
-
var Validators = {
|
|
3459
|
-
// From ./utils
|
|
3460
|
-
// Utility Functions for backwards compatability
|
|
3461
|
-
isNumber: isNumber,
|
|
3462
|
-
isFunction: isFunction,
|
|
3463
|
-
isStringOrNumber: isStringOrNumber,
|
|
3464
|
-
// Validator Functions
|
|
3465
|
-
isValidAttributeValue: isValidAttributeValue,
|
|
3466
|
-
// Validator Functions
|
|
3467
|
-
// Neither null nor undefined can be a valid Key
|
|
3468
|
-
isValidKeyValue: function isValidKeyValue(key) {
|
|
3469
|
-
return Boolean(key && !isObject(key) && !Array.isArray(key) && !this.isFunction(key));
|
|
3470
|
-
},
|
|
3471
|
-
removeFalsyIdentityValues: function removeFalsyIdentityValues(identityApiData, logger) {
|
|
3472
|
-
if (!identityApiData || !identityApiData.userIdentities) {
|
|
3473
|
-
return identityApiData;
|
|
3474
|
-
}
|
|
3475
|
-
var cleanedData = {};
|
|
3476
|
-
var cleanedUserIdentities = __assign({}, identityApiData.userIdentities);
|
|
3477
|
-
for (var identityType in identityApiData.userIdentities) {
|
|
3478
|
-
if (identityApiData.userIdentities.hasOwnProperty(identityType)) {
|
|
3479
|
-
var value = identityApiData.userIdentities[identityType];
|
|
3480
|
-
// Check if value is falsy (undefined, false, 0, '', etc.) but not null
|
|
3481
|
-
if (value !== null && !value) {
|
|
3482
|
-
logger.warning("Identity value for '".concat(identityType, "' is falsy (").concat(value, "). This value will be removed from the request."));
|
|
3483
|
-
delete cleanedUserIdentities[identityType];
|
|
3484
|
-
}
|
|
3485
|
-
}
|
|
3486
|
-
}
|
|
3487
|
-
cleanedData.userIdentities = cleanedUserIdentities;
|
|
3488
|
-
return cleanedData;
|
|
3489
|
-
},
|
|
3490
|
-
validateIdentities: function validateIdentities(identityApiData, method) {
|
|
3491
|
-
var validIdentityRequestKeys = {
|
|
3492
|
-
userIdentities: 1,
|
|
3493
|
-
onUserAlias: 1,
|
|
3494
|
-
copyUserAttributes: 1
|
|
3495
|
-
};
|
|
3496
|
-
if (identityApiData) {
|
|
3497
|
-
if (method === Modify$3) {
|
|
3498
|
-
if (isObject(identityApiData.userIdentities) && !Object.keys(identityApiData.userIdentities).length || !isObject(identityApiData.userIdentities)) {
|
|
3499
|
-
return {
|
|
3500
|
-
valid: false,
|
|
3501
|
-
error: Constants.Messages.ValidationMessages.ModifyIdentityRequestUserIdentitiesPresent
|
|
3502
|
-
};
|
|
3503
|
-
}
|
|
3504
|
-
}
|
|
3505
|
-
for (var key in identityApiData) {
|
|
3506
|
-
if (identityApiData.hasOwnProperty(key)) {
|
|
3507
|
-
if (!validIdentityRequestKeys[key]) {
|
|
3508
|
-
return {
|
|
3509
|
-
valid: false,
|
|
3510
|
-
error: Constants.Messages.ValidationMessages.IdentityRequesetInvalidKey
|
|
3511
|
-
};
|
|
3512
|
-
}
|
|
3513
|
-
if (key === 'onUserAlias' && !Validators.isFunction(identityApiData[key])) {
|
|
3514
|
-
return {
|
|
3515
|
-
valid: false,
|
|
3516
|
-
error: Constants.Messages.ValidationMessages.OnUserAliasType
|
|
3517
|
-
};
|
|
3518
|
-
}
|
|
3519
|
-
}
|
|
3520
|
-
}
|
|
3521
|
-
if (Object.keys(identityApiData).length === 0) {
|
|
3522
|
-
return {
|
|
3523
|
-
valid: true
|
|
3524
|
-
};
|
|
3525
|
-
} else {
|
|
3526
|
-
// identityApiData.userIdentities can't be undefined
|
|
3527
|
-
if (identityApiData.userIdentities === undefined) {
|
|
3528
|
-
return {
|
|
3529
|
-
valid: false,
|
|
3530
|
-
error: Constants.Messages.ValidationMessages.UserIdentities
|
|
3531
|
-
};
|
|
3532
|
-
// identityApiData.userIdentities can be null, but if it isn't null or undefined (above conditional), it must be an object
|
|
3533
|
-
} else if (identityApiData.userIdentities !== null && !isObject(identityApiData.userIdentities)) {
|
|
3534
|
-
return {
|
|
3535
|
-
valid: false,
|
|
3536
|
-
error: Constants.Messages.ValidationMessages.UserIdentities
|
|
3537
|
-
};
|
|
3538
|
-
}
|
|
3539
|
-
if (isObject(identityApiData.userIdentities) && Object.keys(identityApiData.userIdentities).length) {
|
|
3540
|
-
for (var identityType in identityApiData.userIdentities) {
|
|
3541
|
-
if (identityApiData.userIdentities.hasOwnProperty(identityType)) {
|
|
3542
|
-
if (Types.IdentityType.getIdentityType(identityType) === false) {
|
|
3543
|
-
return {
|
|
3544
|
-
valid: false,
|
|
3545
|
-
error: Constants.Messages.ValidationMessages.UserIdentitiesInvalidKey
|
|
3546
|
-
};
|
|
3547
|
-
}
|
|
3548
|
-
if (!(typeof identityApiData.userIdentities[identityType] === 'string' || identityApiData.userIdentities[identityType] === null)) {
|
|
3549
|
-
return {
|
|
3550
|
-
valid: false,
|
|
3551
|
-
error: Constants.Messages.ValidationMessages.UserIdentitiesInvalidValues
|
|
3552
|
-
};
|
|
3553
|
-
}
|
|
3554
|
-
}
|
|
3555
|
-
}
|
|
3556
|
-
}
|
|
3557
|
-
}
|
|
3558
|
-
}
|
|
3559
|
-
return {
|
|
3560
|
-
valid: true
|
|
3561
|
-
};
|
|
3562
|
-
}
|
|
3563
|
-
};
|
|
3564
|
-
|
|
3565
3811
|
var KitFilterHelper = /** @class */function () {
|
|
3566
3812
|
function KitFilterHelper() {}
|
|
3567
3813
|
KitFilterHelper.hashEventType = function (eventType) {
|
|
@@ -7616,6 +7862,37 @@ var mParticle = (function () {
|
|
|
7616
7862
|
}
|
|
7617
7863
|
}
|
|
7618
7864
|
|
|
7865
|
+
function _toPrimitive(input, hint) {
|
|
7866
|
+
if (_typeof$1(input) !== "object" || input === null) return input;
|
|
7867
|
+
var prim = input[Symbol.toPrimitive];
|
|
7868
|
+
if (prim !== undefined) {
|
|
7869
|
+
var res = prim.call(input, hint || "default");
|
|
7870
|
+
if (_typeof$1(res) !== "object") return res;
|
|
7871
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
7872
|
+
}
|
|
7873
|
+
return (hint === "string" ? String : Number)(input);
|
|
7874
|
+
}
|
|
7875
|
+
|
|
7876
|
+
function _toPropertyKey(arg) {
|
|
7877
|
+
var key = _toPrimitive(arg, "string");
|
|
7878
|
+
return _typeof$1(key) === "symbol" ? key : String(key);
|
|
7879
|
+
}
|
|
7880
|
+
|
|
7881
|
+
function _defineProperty(obj, key, value) {
|
|
7882
|
+
key = _toPropertyKey(key);
|
|
7883
|
+
if (key in obj) {
|
|
7884
|
+
Object.defineProperty(obj, key, {
|
|
7885
|
+
value: value,
|
|
7886
|
+
enumerable: true,
|
|
7887
|
+
configurable: true,
|
|
7888
|
+
writable: true
|
|
7889
|
+
});
|
|
7890
|
+
} else {
|
|
7891
|
+
obj[key] = value;
|
|
7892
|
+
}
|
|
7893
|
+
return obj;
|
|
7894
|
+
}
|
|
7895
|
+
|
|
7619
7896
|
var AudienceManager = /** @class */function () {
|
|
7620
7897
|
function AudienceManager(userAudienceUrl, apiKey, logger) {
|
|
7621
7898
|
this.url = '';
|
|
@@ -7720,6 +7997,8 @@ var mParticle = (function () {
|
|
|
7720
7997
|
}
|
|
7721
7998
|
};
|
|
7722
7999
|
|
|
8000
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
8001
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
7723
8002
|
var Messages$2 = Constants.Messages,
|
|
7724
8003
|
HTTPCodes$2 = Constants.HTTPCodes,
|
|
7725
8004
|
FeatureFlags$1 = Constants.FeatureFlags,
|
|
@@ -7744,7 +8023,12 @@ var mParticle = (function () {
|
|
|
7744
8023
|
mpInstance.Logger.verbose(Messages$2.InformationMessages.StartingLogEvent + ': ' + method);
|
|
7745
8024
|
|
|
7746
8025
|
// First, remove any falsy identity values and warn about them
|
|
7747
|
-
var
|
|
8026
|
+
var removedFalsyIdentityData = mpInstance._Helpers.Validators.removeFalsyIdentityValues(identityApiData, mpInstance.Logger);
|
|
8027
|
+
|
|
8028
|
+
// Normalize convenience aliases (email_sha256 → other, mobile_sha256 → other2)
|
|
8029
|
+
var cleanedIdentityApiData = removedFalsyIdentityData !== null && removedFalsyIdentityData !== void 0 && removedFalsyIdentityData.userIdentities ? _objectSpread(_objectSpread({}, removedFalsyIdentityData), {}, {
|
|
8030
|
+
userIdentities: normalizeUserIdentityKeys(removedFalsyIdentityData.userIdentities)
|
|
8031
|
+
}) : removedFalsyIdentityData;
|
|
7748
8032
|
var identityValidationResult = mpInstance._Helpers.Validators.validateIdentities(cleanedIdentityApiData, method);
|
|
7749
8033
|
if (!identityValidationResult.valid) {
|
|
7750
8034
|
mpInstance.Logger.error('ERROR: ' + identityValidationResult.error);
|
|
@@ -8130,6 +8414,26 @@ var mParticle = (function () {
|
|
|
8130
8414
|
mpInstance.Logger.verbose(Messages$2.InformationMessages.AbandonAliasUsers);
|
|
8131
8415
|
}
|
|
8132
8416
|
},
|
|
8417
|
+
/**
|
|
8418
|
+
* Search the IDSync Workspace endpoint for a known identity.
|
|
8419
|
+
*
|
|
8420
|
+
* POSTs to mParticle's `/v1/search` endpoint and invokes `callback`
|
|
8421
|
+
* with `{ httpCode, body? }`.
|
|
8422
|
+
*
|
|
8423
|
+
* The `workspaceApiKey` is a workspace-specific API key supplied by
|
|
8424
|
+
* the caller (passed in from a kit's settings). It is intentionally
|
|
8425
|
+
* NOT read from the SDK's own workspace token, so that workspace
|
|
8426
|
+
* searches can be authorised independently of the host SDK's
|
|
8427
|
+
* workspace.
|
|
8428
|
+
*
|
|
8429
|
+
* @method search
|
|
8430
|
+
* @param {String} workspaceApiKey Workspace API key (sent as x-mp-key).
|
|
8431
|
+
* @param {Object} knownIdentities A `UserIdentities` map.
|
|
8432
|
+
* @param {Function} callback Invoked with the `IIdentitySearchResult`.
|
|
8433
|
+
*/
|
|
8434
|
+
search: function search(workspaceApiKey, knownIdentities, callback) {
|
|
8435
|
+
executeSearchRequest(mpInstance, workspaceApiKey, knownIdentities, callback);
|
|
8436
|
+
},
|
|
8133
8437
|
/**
|
|
8134
8438
|
Create a default AliasRequest for 2 MParticleUsers. This will construct the request
|
|
8135
8439
|
using the sourceUser's firstSeenTime as the startTime, and its lastSeenTime as the endTime.
|
|
@@ -9599,19 +9903,6 @@ var mParticle = (function () {
|
|
|
9599
9903
|
};
|
|
9600
9904
|
}
|
|
9601
9905
|
|
|
9602
|
-
var ErrorCodes = {
|
|
9603
|
-
UNKNOWN_ERROR: 'UNKNOWN_ERROR',
|
|
9604
|
-
UNHANDLED_EXCEPTION: 'UNHANDLED_EXCEPTION',
|
|
9605
|
-
IDENTITY_REQUEST: 'IDENTITY_REQUEST',
|
|
9606
|
-
IDENTITY_MISMATCH: 'IDENTITY_MISMATCH',
|
|
9607
|
-
ROKT_KIT_ATTACHED: 'ROKT_KIT_ATTACHED'
|
|
9608
|
-
};
|
|
9609
|
-
var WSDKErrorSeverity = {
|
|
9610
|
-
ERROR: 'ERROR',
|
|
9611
|
-
INFO: 'INFO',
|
|
9612
|
-
WARNING: 'WARNING'
|
|
9613
|
-
};
|
|
9614
|
-
|
|
9615
9906
|
var HTTPCodes$1 = Constants.HTTPCodes,
|
|
9616
9907
|
Messages$1 = Constants.Messages,
|
|
9617
9908
|
IdentityMethods = Constants.IdentityMethods;
|
|
@@ -12446,6 +12737,9 @@ var mParticle = (function () {
|
|
|
12446
12737
|
},
|
|
12447
12738
|
modify: function modify(identityApiData, callback) {
|
|
12448
12739
|
self.getInstance().Identity.modify(identityApiData, callback);
|
|
12740
|
+
},
|
|
12741
|
+
search: function search(workspaceApiKey, knownIdentities, callback) {
|
|
12742
|
+
self.getInstance().Identity.search(workspaceApiKey, knownIdentities, callback);
|
|
12449
12743
|
}
|
|
12450
12744
|
};
|
|
12451
12745
|
this.sessionManager = {
|