@mparticle/web-sdk 2.26.0 → 2.26.2
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 +98 -66
- package/dist/mparticle.esm.js +98 -66
- package/dist/mparticle.js +1158 -1090
- package/package.json +1 -1
- package/src/helpers.js +0 -1
- package/src/identity.js +158 -218
- package/src/identityApiClient.js +2 -0
- package/src/mockBatchCreator.ts +1 -2
- package/src/mp-instance.js +110 -173
- package/src/nativeSdkHelpers.js +18 -0
- package/src/persistence.interfaces.ts +1 -2
- package/src/persistence.js +17 -0
- package/src/sdkRuntimeModels.ts +14 -7
- package/src/serverModel.ts +4 -0
- package/src/sessionManager.ts +1 -0
- package/src/store.ts +94 -15
- package/src/type-utils.ts +66 -0
- package/src/types.js +3 -44
- package/src/user-utils.ts +12 -0
- package/src/utils.ts +4 -0
package/package.json
CHANGED
package/src/helpers.js
CHANGED
|
@@ -441,7 +441,6 @@ export default function Helpers(mpInstance) {
|
|
|
441
441
|
this.inArray = utils.inArray;
|
|
442
442
|
this.isObject = utils.isObject;
|
|
443
443
|
this.decoded = utils.decoded;
|
|
444
|
-
this.returnConvertedBoolean = utils.returnConvertedBoolean;
|
|
445
444
|
this.parseStringOrNumber = utils.parseStringOrNumber;
|
|
446
445
|
this.generateHash = utils.generateHash;
|
|
447
446
|
this.generateUniqueId = utils.generateUniqueId;
|
package/src/identity.js
CHANGED
|
@@ -6,32 +6,27 @@ import {
|
|
|
6
6
|
tryCacheIdentity,
|
|
7
7
|
} from './identity-utils';
|
|
8
8
|
import AudienceManager from './audienceManager';
|
|
9
|
-
|
|
10
|
-
const { Messages, HTTPCodes, FeatureFlags } = Constants;
|
|
9
|
+
const { Messages, HTTPCodes, FeatureFlags, IdentityMethods } = Constants;
|
|
11
10
|
const { ErrorMessages } = Messages;
|
|
12
|
-
|
|
13
|
-
const { Identify, Modify, Login, Logout } =
|
|
11
|
+
const { CacheIdentity } = FeatureFlags;
|
|
12
|
+
const { Identify, Modify, Login, Logout } = IdentityMethods;
|
|
13
|
+
import {
|
|
14
|
+
generateDeprecationMessage,
|
|
15
|
+
isEmpty,
|
|
16
|
+
isFunction,
|
|
17
|
+
isObject,
|
|
18
|
+
} from './utils';
|
|
19
|
+
import { didUserChange } from './user-utils';
|
|
20
|
+
import { getNewIdentitiesByName } from './type-utils';
|
|
14
21
|
|
|
15
22
|
export default function Identity(mpInstance) {
|
|
23
|
+
const { getFeatureFlag, extend } = mpInstance._Helpers;
|
|
24
|
+
|
|
16
25
|
var self = this;
|
|
17
26
|
this.idCache = null;
|
|
18
27
|
this.audienceManager = null;
|
|
19
28
|
|
|
20
|
-
|
|
21
|
-
previousMPID,
|
|
22
|
-
currentMPID,
|
|
23
|
-
currentSessionMPIDs
|
|
24
|
-
) {
|
|
25
|
-
if (previousMPID && currentMPID && previousMPID !== currentMPID) {
|
|
26
|
-
var persistence = mpInstance._Persistence.getPersistence();
|
|
27
|
-
if (persistence) {
|
|
28
|
-
persistence.cu = currentMPID;
|
|
29
|
-
persistence.gs.csm = currentSessionMPIDs;
|
|
30
|
-
mpInstance._Persistence.savePersistence(persistence);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
|
|
29
|
+
// https://go.mparticle.com/work/SQDSDKS-6353
|
|
35
30
|
this.IdentityRequest = {
|
|
36
31
|
preProcessIdentityRequest: function(identityApiData, callback, method) {
|
|
37
32
|
mpInstance.Logger.verbose(
|
|
@@ -135,9 +130,9 @@ export default function Identity(mpInstance) {
|
|
|
135
130
|
var key;
|
|
136
131
|
if (
|
|
137
132
|
newIdentities &&
|
|
138
|
-
|
|
133
|
+
isObject(newIdentities) &&
|
|
139
134
|
previousIdentities &&
|
|
140
|
-
|
|
135
|
+
isObject(previousIdentities)
|
|
141
136
|
) {
|
|
142
137
|
for (key in newIdentities) {
|
|
143
138
|
identityChanges.push({
|
|
@@ -154,11 +149,7 @@ export default function Identity(mpInstance) {
|
|
|
154
149
|
// takes 2 UI objects keyed by name, combines them, returns them keyed by type
|
|
155
150
|
combineUserIdentities: function(previousUIByName, newUIByName) {
|
|
156
151
|
var combinedUIByType = {};
|
|
157
|
-
|
|
158
|
-
var combinedUIByName = mpInstance._Helpers.extend(
|
|
159
|
-
previousUIByName,
|
|
160
|
-
newUIByName
|
|
161
|
-
);
|
|
152
|
+
var combinedUIByName = extend({}, previousUIByName, newUIByName);
|
|
162
153
|
|
|
163
154
|
for (var key in combinedUIByName) {
|
|
164
155
|
var type = Types.IdentityType.getIdentityType(key);
|
|
@@ -232,6 +223,7 @@ export default function Identity(mpInstance) {
|
|
|
232
223
|
* @param {Function} [callback] A callback function that is called when the identify request completes
|
|
233
224
|
*/
|
|
234
225
|
identify: function(identityApiData, callback) {
|
|
226
|
+
// https://go.mparticle.com/work/SQDSDKS-6337
|
|
235
227
|
var mpid,
|
|
236
228
|
currentUser = mpInstance.Identity.getCurrentUser(),
|
|
237
229
|
preProcessResult = mpInstance._Identity.IdentityRequest.preProcessIdentityRequest(
|
|
@@ -325,6 +317,7 @@ export default function Identity(mpInstance) {
|
|
|
325
317
|
* @param {Function} [callback] A callback function that is called when the logout request completes
|
|
326
318
|
*/
|
|
327
319
|
logout: function(identityApiData, callback) {
|
|
320
|
+
// https://go.mparticle.com/work/SQDSDKS-6337
|
|
328
321
|
var mpid,
|
|
329
322
|
currentUser = mpInstance.Identity.getCurrentUser(),
|
|
330
323
|
preProcessResult = mpInstance._Identity.IdentityRequest.preProcessIdentityRequest(
|
|
@@ -414,6 +407,7 @@ export default function Identity(mpInstance) {
|
|
|
414
407
|
* @param {Function} [callback] A callback function that is called when the login request completes
|
|
415
408
|
*/
|
|
416
409
|
login: function(identityApiData, callback) {
|
|
410
|
+
// https://go.mparticle.com/work/SQDSDKS-6337
|
|
417
411
|
var mpid,
|
|
418
412
|
currentUser = mpInstance.Identity.getCurrentUser(),
|
|
419
413
|
preProcessResult = mpInstance._Identity.IdentityRequest.preProcessIdentityRequest(
|
|
@@ -509,6 +503,7 @@ export default function Identity(mpInstance) {
|
|
|
509
503
|
* @param {Function} [callback] A callback function that is called when the modify request completes
|
|
510
504
|
*/
|
|
511
505
|
modify: function(identityApiData, callback) {
|
|
506
|
+
// https://go.mparticle.com/work/SQDSDKS-6337
|
|
512
507
|
var mpid,
|
|
513
508
|
currentUser = mpInstance.Identity.getCurrentUser(),
|
|
514
509
|
preProcessResult = mpInstance._Identity.IdentityRequest.preProcessIdentityRequest(
|
|
@@ -796,6 +791,7 @@ export default function Identity(mpInstance) {
|
|
|
796
791
|
},
|
|
797
792
|
};
|
|
798
793
|
|
|
794
|
+
// https://go.mparticle.com/work/SQDSDKS-6354
|
|
799
795
|
/**
|
|
800
796
|
* Invoke these methods on the mParticle.Identity.getCurrentUser() object.
|
|
801
797
|
* Example: mParticle.Identity.getCurrentUser().getAllUserAttributes()
|
|
@@ -955,7 +951,7 @@ export default function Identity(mpInstance) {
|
|
|
955
951
|
*/
|
|
956
952
|
setUserAttributes: function(userAttributes) {
|
|
957
953
|
mpInstance._SessionManager.resetSessionTimer();
|
|
958
|
-
if (
|
|
954
|
+
if (isObject(userAttributes)) {
|
|
959
955
|
if (mpInstance._Helpers.canLog()) {
|
|
960
956
|
for (var key in userAttributes) {
|
|
961
957
|
if (userAttributes.hasOwnProperty(key)) {
|
|
@@ -1480,6 +1476,7 @@ export default function Identity(mpInstance) {
|
|
|
1480
1476
|
};
|
|
1481
1477
|
};
|
|
1482
1478
|
|
|
1479
|
+
// https://go.mparticle.com/work/SQDSDKS-6355
|
|
1483
1480
|
this.parseIdentityResponse = function(
|
|
1484
1481
|
xhr,
|
|
1485
1482
|
previousMPID,
|
|
@@ -1489,64 +1486,46 @@ export default function Identity(mpInstance) {
|
|
|
1489
1486
|
knownIdentities,
|
|
1490
1487
|
parsingCachedResponse
|
|
1491
1488
|
) {
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
previousUIByName
|
|
1504
|
-
);
|
|
1489
|
+
const prevUser = mpInstance.Identity.getUser(previousMPID);
|
|
1490
|
+
const prevUserMPID = prevUser ? prevUser.getMPID() : null;
|
|
1491
|
+
const previousUIByName = prevUser
|
|
1492
|
+
? prevUser.getUserIdentities().userIdentities
|
|
1493
|
+
: {};
|
|
1494
|
+
|
|
1495
|
+
let identityApiResult;
|
|
1496
|
+
|
|
1497
|
+
let newUser;
|
|
1498
|
+
let newIdentitiesByType = {};
|
|
1499
|
+
|
|
1505
1500
|
mpInstance._Store.identityCallInFlight = false;
|
|
1506
1501
|
|
|
1507
1502
|
try {
|
|
1508
1503
|
mpInstance.Logger.verbose(
|
|
1509
1504
|
'Parsing "' + method + '" identity response from server'
|
|
1510
1505
|
);
|
|
1511
|
-
if (xhr.responseText) {
|
|
1512
|
-
identityApiResult = JSON.parse(xhr.responseText);
|
|
1513
|
-
|
|
1514
|
-
if (identityApiResult.hasOwnProperty('is_logged_in')) {
|
|
1515
|
-
mpInstance._Store.isLoggedIn =
|
|
1516
|
-
identityApiResult.is_logged_in;
|
|
1517
|
-
}
|
|
1518
|
-
}
|
|
1519
1506
|
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
(prevUser.getMPID() &&
|
|
1524
|
-
identityApiResult.mpid &&
|
|
1525
|
-
identityApiResult.mpid !== prevUser.getMPID())
|
|
1526
|
-
) {
|
|
1527
|
-
mpInstance._Store.mpid = identityApiResult.mpid;
|
|
1507
|
+
identityApiResult = xhr.responseText
|
|
1508
|
+
? JSON.parse(xhr.responseText)
|
|
1509
|
+
: null;
|
|
1528
1510
|
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1511
|
+
mpInstance._Store.isLoggedIn =
|
|
1512
|
+
identityApiResult?.is_logged_in || false;
|
|
1513
|
+
mpInstance._Store.mpid = identityApiResult.mpid;
|
|
1532
1514
|
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
)
|
|
1537
|
-
)
|
|
1538
|
-
mpidIsNotInCookies = true;
|
|
1539
|
-
mpInstance._Persistence.setFirstSeenTime(
|
|
1540
|
-
identityApiResult.mpid
|
|
1541
|
-
);
|
|
1515
|
+
if (prevUser) {
|
|
1516
|
+
// https://go.mparticle.com/work/SQDSDKS-6329
|
|
1517
|
+
mpInstance._Persistence.setLastSeenTime(previousMPID);
|
|
1542
1518
|
}
|
|
1543
1519
|
|
|
1520
|
+
const mpidIsNotInCookies = !mpInstance._Persistence.getFirstSeenTime(
|
|
1521
|
+
identityApiResult.mpid
|
|
1522
|
+
);
|
|
1523
|
+
|
|
1524
|
+
// https://go.mparticle.com/work/SQDSDKS-6329
|
|
1525
|
+
mpInstance._Persistence.setFirstSeenTime(identityApiResult.mpid);
|
|
1526
|
+
|
|
1544
1527
|
if (xhr.status === 200) {
|
|
1545
|
-
if (
|
|
1546
|
-
mpInstance._Helpers.getFeatureFlag(
|
|
1547
|
-
Constants.FeatureFlags.CacheIdentity
|
|
1548
|
-
)
|
|
1549
|
-
) {
|
|
1528
|
+
if (getFeatureFlag(CacheIdentity)) {
|
|
1550
1529
|
cacheOrClearIdCache(
|
|
1551
1530
|
method,
|
|
1552
1531
|
knownIdentities,
|
|
@@ -1556,6 +1535,14 @@ export default function Identity(mpInstance) {
|
|
|
1556
1535
|
);
|
|
1557
1536
|
}
|
|
1558
1537
|
|
|
1538
|
+
const incomingUser = self.IdentityAPI.getUser(
|
|
1539
|
+
identityApiResult.mpid
|
|
1540
|
+
);
|
|
1541
|
+
|
|
1542
|
+
const incomingMpidUIByName = incomingUser
|
|
1543
|
+
? incomingUser.getUserIdentities().userIdentities
|
|
1544
|
+
: {};
|
|
1545
|
+
|
|
1559
1546
|
if (method === Modify) {
|
|
1560
1547
|
newIdentitiesByType = mpInstance._Identity.IdentityRequest.combineUserIdentities(
|
|
1561
1548
|
previousUIByName,
|
|
@@ -1567,71 +1554,32 @@ export default function Identity(mpInstance) {
|
|
|
1567
1554
|
newIdentitiesByType
|
|
1568
1555
|
);
|
|
1569
1556
|
} else {
|
|
1570
|
-
|
|
1571
|
-
identityApiResult.mpid
|
|
1572
|
-
);
|
|
1573
|
-
|
|
1574
|
-
var incomingMpidUIByName = incomingUser
|
|
1575
|
-
? incomingUser.getUserIdentities().userIdentities
|
|
1576
|
-
: {};
|
|
1577
|
-
|
|
1578
|
-
var incomingMpidUIByNameCopy = mpInstance._Helpers.extend(
|
|
1579
|
-
{},
|
|
1580
|
-
incomingMpidUIByName
|
|
1581
|
-
);
|
|
1582
|
-
mpInstance.Logger.verbose(
|
|
1583
|
-
'Successfully parsed Identity Response'
|
|
1584
|
-
);
|
|
1585
|
-
|
|
1557
|
+
// https://go.mparticle.com/work/SQDSDKS-6356
|
|
1586
1558
|
//this covers an edge case where, users stored before "firstSeenTime" was introduced
|
|
1587
1559
|
//will not have a value for "fst" until the current MPID changes, and in some cases,
|
|
1588
1560
|
//the current MPID will never change
|
|
1589
1561
|
if (
|
|
1590
1562
|
method === Identify &&
|
|
1591
1563
|
prevUser &&
|
|
1592
|
-
identityApiResult.mpid ===
|
|
1564
|
+
identityApiResult.mpid === prevUserMPID
|
|
1593
1565
|
) {
|
|
1594
1566
|
mpInstance._Persistence.setFirstSeenTime(
|
|
1595
1567
|
identityApiResult.mpid
|
|
1596
1568
|
);
|
|
1597
1569
|
}
|
|
1598
1570
|
|
|
1599
|
-
|
|
1600
|
-
identityApiResult.mpid
|
|
1571
|
+
mpInstance._Store.addMpidToSessionHistory(
|
|
1572
|
+
identityApiResult.mpid,
|
|
1573
|
+
previousMPID
|
|
1601
1574
|
);
|
|
1602
1575
|
|
|
1603
|
-
if (
|
|
1604
|
-
mpInstance._Store.sessionId &&
|
|
1605
|
-
identityApiResult.mpid &&
|
|
1606
|
-
previousMPID !== identityApiResult.mpid &&
|
|
1607
|
-
indexOfMPID < 0
|
|
1608
|
-
) {
|
|
1609
|
-
mpInstance._Store.currentSessionMPIDs.push(
|
|
1610
|
-
identityApiResult.mpid
|
|
1611
|
-
);
|
|
1612
|
-
}
|
|
1613
|
-
|
|
1614
|
-
if (indexOfMPID > -1) {
|
|
1615
|
-
mpInstance._Store.currentSessionMPIDs = mpInstance._Store.currentSessionMPIDs
|
|
1616
|
-
.slice(0, indexOfMPID)
|
|
1617
|
-
.concat(
|
|
1618
|
-
mpInstance._Store.currentSessionMPIDs.slice(
|
|
1619
|
-
indexOfMPID + 1,
|
|
1620
|
-
mpInstance._Store.currentSessionMPIDs.length
|
|
1621
|
-
)
|
|
1622
|
-
);
|
|
1623
|
-
mpInstance._Store.currentSessionMPIDs.push(
|
|
1624
|
-
identityApiResult.mpid
|
|
1625
|
-
);
|
|
1626
|
-
}
|
|
1627
|
-
|
|
1628
1576
|
mpInstance._CookieSyncManager.attemptCookieSync(
|
|
1629
1577
|
previousMPID,
|
|
1630
1578
|
identityApiResult.mpid,
|
|
1631
1579
|
mpidIsNotInCookies
|
|
1632
1580
|
);
|
|
1633
1581
|
|
|
1634
|
-
|
|
1582
|
+
mpInstance._Persistence.swapCurrentUser(
|
|
1635
1583
|
previousMPID,
|
|
1636
1584
|
identityApiResult.mpid,
|
|
1637
1585
|
mpInstance._Store.currentSessionMPIDs
|
|
@@ -1639,8 +1587,7 @@ export default function Identity(mpInstance) {
|
|
|
1639
1587
|
|
|
1640
1588
|
if (
|
|
1641
1589
|
identityApiData &&
|
|
1642
|
-
identityApiData.userIdentities
|
|
1643
|
-
Object.keys(identityApiData.userIdentities).length
|
|
1590
|
+
!isEmpty(identityApiData.userIdentities)
|
|
1644
1591
|
) {
|
|
1645
1592
|
newIdentitiesByType = self.IdentityRequest.combineUserIdentities(
|
|
1646
1593
|
incomingMpidUIByName,
|
|
@@ -1659,112 +1606,71 @@ export default function Identity(mpInstance) {
|
|
|
1659
1606
|
identityApiData
|
|
1660
1607
|
);
|
|
1661
1608
|
|
|
1609
|
+
// https://go.mparticle.com/work/SQDSDKS-6357
|
|
1662
1610
|
mpInstance._Store.context =
|
|
1663
1611
|
identityApiResult.context || mpInstance._Store.context;
|
|
1664
1612
|
}
|
|
1665
1613
|
|
|
1666
1614
|
newUser = mpInstance.Identity.getCurrentUser();
|
|
1667
1615
|
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
)
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
'Deprecated function onUserAlias will be removed in future releases'
|
|
1678
|
-
);
|
|
1679
|
-
identityApiData.onUserAlias(prevUser, newUser);
|
|
1680
|
-
} catch (e) {
|
|
1681
|
-
mpInstance.Logger.error(
|
|
1682
|
-
'There was an error with your onUserAlias function - ' +
|
|
1683
|
-
e
|
|
1684
|
-
);
|
|
1685
|
-
}
|
|
1686
|
-
}
|
|
1687
|
-
var persistence = mpInstance._Persistence.getPersistence();
|
|
1616
|
+
// https://go.mparticle.com/work/SQDSDKS-6359
|
|
1617
|
+
tryOnUserAlias(
|
|
1618
|
+
prevUser,
|
|
1619
|
+
newUser,
|
|
1620
|
+
identityApiData,
|
|
1621
|
+
mpInstance.Logger
|
|
1622
|
+
);
|
|
1623
|
+
|
|
1624
|
+
const persistence = mpInstance._Persistence.getPersistence();
|
|
1688
1625
|
|
|
1689
1626
|
if (newUser) {
|
|
1690
1627
|
mpInstance._Persistence.storeDataInMemory(
|
|
1691
1628
|
persistence,
|
|
1692
1629
|
newUser.getMPID()
|
|
1693
1630
|
);
|
|
1694
|
-
if (
|
|
1695
|
-
!prevUser ||
|
|
1696
|
-
newUser.getMPID() !== prevUser.getMPID() ||
|
|
1697
|
-
prevUser.isLoggedIn() !== newUser.isLoggedIn()
|
|
1698
|
-
) {
|
|
1699
|
-
mpInstance._Forwarders.initForwarders(
|
|
1700
|
-
newUser.getUserIdentities().userIdentities,
|
|
1701
|
-
mpInstance._APIClient.prepareForwardingStats
|
|
1702
|
-
);
|
|
1703
|
-
}
|
|
1704
1631
|
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
newUser.getUserIdentities().userIdentities
|
|
1708
|
-
);
|
|
1709
|
-
mpInstance._Forwarders.setForwarderOnIdentityComplete(
|
|
1710
|
-
newUser,
|
|
1711
|
-
method
|
|
1712
|
-
);
|
|
1713
|
-
mpInstance._Forwarders.setForwarderOnUserIdentified(
|
|
1714
|
-
newUser
|
|
1715
|
-
);
|
|
1632
|
+
self.reinitForwardersOnUserChange(prevUser, newUser);
|
|
1633
|
+
self.setForwarderCallbacks(newUser, method);
|
|
1716
1634
|
}
|
|
1717
|
-
var newIdentitiesByName = {};
|
|
1718
1635
|
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
}
|
|
1636
|
+
const newIdentitiesByName = getNewIdentitiesByName(
|
|
1637
|
+
newIdentitiesByType
|
|
1638
|
+
);
|
|
1639
|
+
|
|
1640
|
+
const uiByName =
|
|
1641
|
+
method === Modify ? previousUIByName : incomingMpidUIByName;
|
|
1726
1642
|
|
|
1727
1643
|
self.sendUserIdentityChangeEvent(
|
|
1728
1644
|
newIdentitiesByName,
|
|
1729
|
-
method,
|
|
1730
1645
|
identityApiResult.mpid,
|
|
1731
|
-
|
|
1732
|
-
? previousUIByNameCopy
|
|
1733
|
-
: incomingMpidUIByNameCopy
|
|
1646
|
+
uiByName
|
|
1734
1647
|
);
|
|
1735
1648
|
}
|
|
1736
1649
|
|
|
1737
1650
|
if (callback) {
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
identityApiResult.errors.length
|
|
1758
|
-
) {
|
|
1759
|
-
mpInstance.Logger.error(
|
|
1760
|
-
'Received HTTP response code of ' +
|
|
1761
|
-
xhr.status +
|
|
1762
|
-
' - ' +
|
|
1763
|
-
identityApiResult.errors[0].message
|
|
1764
|
-
);
|
|
1765
|
-
}
|
|
1651
|
+
const callbackCode =
|
|
1652
|
+
xhr.status === 0 ? HTTPCodes.noHttpCoverage : xhr.status;
|
|
1653
|
+
|
|
1654
|
+
mpInstance._Helpers.invokeCallback(
|
|
1655
|
+
callback,
|
|
1656
|
+
callbackCode,
|
|
1657
|
+
identityApiResult || null,
|
|
1658
|
+
newUser
|
|
1659
|
+
);
|
|
1660
|
+
} else if (
|
|
1661
|
+
identityApiResult &&
|
|
1662
|
+
!isEmpty(identityApiResult.errors)
|
|
1663
|
+
) {
|
|
1664
|
+
mpInstance.Logger.error(
|
|
1665
|
+
'Received HTTP response code of ' +
|
|
1666
|
+
xhr.status +
|
|
1667
|
+
' - ' +
|
|
1668
|
+
identityApiResult.errors[0].message
|
|
1669
|
+
);
|
|
1766
1670
|
}
|
|
1767
1671
|
|
|
1672
|
+
mpInstance.Logger.verbose('Successfully parsed Identity Response');
|
|
1673
|
+
|
|
1768
1674
|
mpInstance._APIClient.processQueuedEvents();
|
|
1769
1675
|
} catch (e) {
|
|
1770
1676
|
if (callback) {
|
|
@@ -1786,30 +1692,28 @@ export default function Identity(mpInstance) {
|
|
|
1786
1692
|
|
|
1787
1693
|
this.sendUserIdentityChangeEvent = function(
|
|
1788
1694
|
newUserIdentities,
|
|
1789
|
-
method,
|
|
1790
1695
|
mpid,
|
|
1791
|
-
|
|
1696
|
+
currentUserIdentities
|
|
1792
1697
|
) {
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
if (!mpid) {
|
|
1796
|
-
if (method !== Modify) {
|
|
1797
|
-
return;
|
|
1798
|
-
}
|
|
1799
|
-
}
|
|
1800
|
-
|
|
1801
|
-
currentUserInMemory = this.IdentityAPI.getUser(mpid);
|
|
1698
|
+
// https://go.mparticle.com/work/SQDSDKS-6354
|
|
1699
|
+
const currentUserInMemory = this.IdentityAPI.getUser(mpid);
|
|
1802
1700
|
|
|
1803
1701
|
for (var identityType in newUserIdentities) {
|
|
1702
|
+
// Verifies a change actually happened
|
|
1804
1703
|
if (
|
|
1805
|
-
|
|
1704
|
+
currentUserIdentities[identityType] !==
|
|
1806
1705
|
newUserIdentities[identityType]
|
|
1807
1706
|
) {
|
|
1808
|
-
|
|
1809
|
-
|
|
1707
|
+
// If a new identity type was introduced when the identity changes
|
|
1708
|
+
// we need to notify the server so that it will associate the new
|
|
1709
|
+
// identity type with subsequent events
|
|
1710
|
+
const isNewUserIdentityType = !currentUserIdentities[
|
|
1711
|
+
identityType
|
|
1712
|
+
];
|
|
1713
|
+
const userIdentityChangeEvent = self.createUserIdentityChange(
|
|
1810
1714
|
identityType,
|
|
1811
1715
|
newUserIdentities[identityType],
|
|
1812
|
-
|
|
1716
|
+
currentUserIdentities[identityType],
|
|
1813
1717
|
isNewUserIdentityType,
|
|
1814
1718
|
currentUserInMemory
|
|
1815
1719
|
);
|
|
@@ -1824,7 +1728,7 @@ export default function Identity(mpInstance) {
|
|
|
1824
1728
|
identityType,
|
|
1825
1729
|
newIdentity,
|
|
1826
1730
|
oldIdentity,
|
|
1827
|
-
|
|
1731
|
+
isIdentityTypeNewToBatch,
|
|
1828
1732
|
userInMemory
|
|
1829
1733
|
) {
|
|
1830
1734
|
var userIdentityChangeEvent;
|
|
@@ -1835,7 +1739,7 @@ export default function Identity(mpInstance) {
|
|
|
1835
1739
|
New: {
|
|
1836
1740
|
IdentityType: identityType,
|
|
1837
1741
|
Identity: newIdentity,
|
|
1838
|
-
CreatedThisBatch:
|
|
1742
|
+
CreatedThisBatch: isIdentityTypeNewToBatch,
|
|
1839
1743
|
},
|
|
1840
1744
|
Old: {
|
|
1841
1745
|
IdentityType: identityType,
|
|
@@ -1899,4 +1803,40 @@ export default function Identity(mpInstance) {
|
|
|
1899
1803
|
}
|
|
1900
1804
|
return userAttributeChangeEvent;
|
|
1901
1805
|
};
|
|
1806
|
+
|
|
1807
|
+
this.reinitForwardersOnUserChange = function(prevUser, newUser) {
|
|
1808
|
+
if (didUserChange(prevUser, newUser)) {
|
|
1809
|
+
mpInstance._Forwarders.initForwarders(
|
|
1810
|
+
newUser.getUserIdentities().userIdentities,
|
|
1811
|
+
mpInstance._APIClient.prepareForwardingStats
|
|
1812
|
+
);
|
|
1813
|
+
}
|
|
1814
|
+
};
|
|
1815
|
+
|
|
1816
|
+
this.setForwarderCallbacks = function(user, method) {
|
|
1817
|
+
// https://go.mparticle.com/work/SQDSDKS-6036
|
|
1818
|
+
mpInstance._Forwarders.setForwarderUserIdentities(
|
|
1819
|
+
user.getUserIdentities().userIdentities
|
|
1820
|
+
);
|
|
1821
|
+
mpInstance._Forwarders.setForwarderOnIdentityComplete(user, method);
|
|
1822
|
+
mpInstance._Forwarders.setForwarderOnUserIdentified(user);
|
|
1823
|
+
};
|
|
1824
|
+
}
|
|
1825
|
+
|
|
1826
|
+
// https://go.mparticle.com/work/SQDSDKS-6359
|
|
1827
|
+
function tryOnUserAlias(previousUser, newUser, identityApiData, logger) {
|
|
1828
|
+
if (
|
|
1829
|
+
identityApiData &&
|
|
1830
|
+
identityApiData.onUserAlias &&
|
|
1831
|
+
isFunction(identityApiData.onUserAlias)
|
|
1832
|
+
) {
|
|
1833
|
+
try {
|
|
1834
|
+
logger.warning(generateDeprecationMessage('onUserAlias'));
|
|
1835
|
+
identityApiData.onUserAlias(previousUser, newUser);
|
|
1836
|
+
} catch (e) {
|
|
1837
|
+
logger.error(
|
|
1838
|
+
'There was an error with your onUserAlias function - ' + e
|
|
1839
|
+
);
|
|
1840
|
+
}
|
|
1841
|
+
}
|
|
1902
1842
|
}
|
package/src/identityApiClient.js
CHANGED
|
@@ -10,6 +10,7 @@ export default function IdentityAPIClient(mpInstance) {
|
|
|
10
10
|
var xhr,
|
|
11
11
|
xhrCallback = function() {
|
|
12
12
|
if (xhr.readyState === 4) {
|
|
13
|
+
// https://go.mparticle.com/work/SQDSDKS-6368
|
|
13
14
|
mpInstance.Logger.verbose(
|
|
14
15
|
'Received ' + xhr.statusText + ' from server'
|
|
15
16
|
);
|
|
@@ -73,6 +74,7 @@ export default function IdentityAPIClient(mpInstance) {
|
|
|
73
74
|
previousMPID,
|
|
74
75
|
xhrCallback = function() {
|
|
75
76
|
if (xhr.readyState === 4) {
|
|
77
|
+
// https://go.mparticle.com/work/SQDSDKS-6368
|
|
76
78
|
mpInstance.Logger.verbose(
|
|
77
79
|
'Received ' + xhr.statusText + ' from server'
|
|
78
80
|
);
|
package/src/mockBatchCreator.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { SDKEvent, BaseEvent, MParticleWebSDK } from './sdkRuntimeModels';
|
|
|
5
5
|
import { convertEvents } from './sdkToEventsApiConverter';
|
|
6
6
|
import * as EventsApi from '@mparticle/event-models';
|
|
7
7
|
import { Batch } from '@mparticle/event-models';
|
|
8
|
-
import { IMPSideloadedKit} from './sideloadedKit';
|
|
8
|
+
import { IMPSideloadedKit } from './sideloadedKit';
|
|
9
9
|
|
|
10
10
|
const mockFunction = function() {
|
|
11
11
|
return null;
|
|
@@ -27,7 +27,6 @@ export default class _BatchValidator {
|
|
|
27
27
|
createServiceUrl: mockFunction,
|
|
28
28
|
parseNumber: mockFunction,
|
|
29
29
|
isObject: mockFunction,
|
|
30
|
-
returnConvertedBoolean: mockFunction,
|
|
31
30
|
Validators: null,
|
|
32
31
|
},
|
|
33
32
|
_resetForTests: mockFunction,
|