@mparticle/web-sdk 2.26.5 → 2.26.7
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 +78 -54
- package/dist/mparticle.esm.js +78 -54
- package/dist/mparticle.js +1108 -1048
- package/package.json +1 -1
- package/src/identity.interfaces.ts +0 -5
- package/src/identity.js +156 -200
- package/src/identityApiClient.js +2 -0
- package/src/persistence.interfaces.ts +5 -0
- package/src/persistence.js +17 -0
- package/src/sdkRuntimeModels.ts +4 -0
- package/src/serverModel.ts +3 -0
- package/src/store.ts +18 -0
- package/src/type-utils.ts +66 -0
- package/src/types.js +3 -44
- package/src/user-utils.ts +25 -0
- package/src/utils.ts +4 -0
package/src/sdkRuntimeModels.ts
CHANGED
|
@@ -34,7 +34,10 @@ export interface SDKEvent {
|
|
|
34
34
|
IsFirstRun: boolean;
|
|
35
35
|
EventName: string;
|
|
36
36
|
EventCategory: number;
|
|
37
|
+
|
|
38
|
+
// https://go.mparticle.com/work/SQDSDKS-5196
|
|
37
39
|
UserAttributes?: { [key: string]: string | string[] | null };
|
|
40
|
+
|
|
38
41
|
UserIdentities?: ISDKUserIdentity[];
|
|
39
42
|
SourceMessageId: string;
|
|
40
43
|
MPID: string;
|
|
@@ -177,6 +180,7 @@ export interface MParticleWebSDK {
|
|
|
177
180
|
getAppVersion(): string;
|
|
178
181
|
getDeviceId(): string;
|
|
179
182
|
setDeviceId(deviceId: string): void;
|
|
183
|
+
setSessionAttribute(key: string, value: string): void;
|
|
180
184
|
getInstance(): MParticleWebSDK; // TODO: Create a new type for MParticleWebSDKInstance
|
|
181
185
|
ServerModel();
|
|
182
186
|
upload();
|
package/src/serverModel.ts
CHANGED
|
@@ -46,7 +46,10 @@ export interface IServerV2DTO {
|
|
|
46
46
|
dp_v?: number;
|
|
47
47
|
n?: string;
|
|
48
48
|
et?: number;
|
|
49
|
+
|
|
50
|
+
// https://go.mparticle.com/work/SQDSDKS-5196
|
|
49
51
|
ua?: Dictionary<string | string[]>;
|
|
52
|
+
|
|
50
53
|
ui?: ISDKUserIdentity[];
|
|
51
54
|
ia?: Dictionary<Dictionary<string>>;
|
|
52
55
|
str?: ServerSettings;
|
package/src/store.ts
CHANGED
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
isEmpty,
|
|
26
26
|
isNumber,
|
|
27
27
|
isObject,
|
|
28
|
+
moveElementToEnd,
|
|
28
29
|
parseNumber,
|
|
29
30
|
returnConvertedBoolean,
|
|
30
31
|
} from './utils';
|
|
@@ -186,6 +187,7 @@ export interface IStore {
|
|
|
186
187
|
getLastSeenTime?(mpid: MPID): number;
|
|
187
188
|
setLastSeenTime?(mpid: MPID, time?: number): void;
|
|
188
189
|
|
|
190
|
+
addMpidToSessionHistory?(mpid: MPID, previousMpid?: MPID): void;
|
|
189
191
|
hasInvalidIdentifyRequest?: () => boolean;
|
|
190
192
|
nullifySession?: () => void;
|
|
191
193
|
processConfig(config: SDKInitConfig): void;
|
|
@@ -494,6 +496,22 @@ export default function Store(
|
|
|
494
496
|
mpInstance._Persistence.update();
|
|
495
497
|
};
|
|
496
498
|
|
|
499
|
+
this.addMpidToSessionHistory = (mpid: MPID, previousMPID?: MPID): void => {
|
|
500
|
+
const indexOfMPID = this.currentSessionMPIDs.indexOf(mpid);
|
|
501
|
+
|
|
502
|
+
if (mpid && previousMPID !== mpid && indexOfMPID < 0) {
|
|
503
|
+
this.currentSessionMPIDs.push(mpid);
|
|
504
|
+
return;
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
if (indexOfMPID >= 0) {
|
|
508
|
+
this.currentSessionMPIDs = moveElementToEnd(
|
|
509
|
+
this.currentSessionMPIDs,
|
|
510
|
+
indexOfMPID
|
|
511
|
+
);
|
|
512
|
+
}
|
|
513
|
+
};
|
|
514
|
+
|
|
497
515
|
this.getFirstSeenTime = (mpid: MPID) => {
|
|
498
516
|
if (!mpid) {
|
|
499
517
|
return null;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { IdentityType } from './types.interfaces';
|
|
2
|
+
import { parseNumber } from './utils';
|
|
3
|
+
|
|
4
|
+
export interface IIdentitiesByType {
|
|
5
|
+
[key: number]: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function getNewIdentitiesByName(newIdentitiesByType: IIdentitiesByType) {
|
|
9
|
+
const newIdentitiesByName = {};
|
|
10
|
+
|
|
11
|
+
for (var key in newIdentitiesByType) {
|
|
12
|
+
const identityNameKey = getIdentityName(parseNumber(key));
|
|
13
|
+
newIdentitiesByName[identityNameKey] = newIdentitiesByType[key];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return newIdentitiesByName;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function getIdentityName(identityType: IdentityType): string | null {
|
|
20
|
+
switch (identityType) {
|
|
21
|
+
case IdentityType.Other:
|
|
22
|
+
return 'other';
|
|
23
|
+
case IdentityType.CustomerId:
|
|
24
|
+
return 'customerid';
|
|
25
|
+
case IdentityType.Facebook:
|
|
26
|
+
return 'facebook';
|
|
27
|
+
case IdentityType.Twitter:
|
|
28
|
+
return 'twitter';
|
|
29
|
+
case IdentityType.Google:
|
|
30
|
+
return 'google';
|
|
31
|
+
case IdentityType.Microsoft:
|
|
32
|
+
return 'microsoft';
|
|
33
|
+
case IdentityType.Yahoo:
|
|
34
|
+
return 'yahoo';
|
|
35
|
+
case IdentityType.Email:
|
|
36
|
+
return 'email';
|
|
37
|
+
case IdentityType.FacebookCustomAudienceId:
|
|
38
|
+
return 'facebookcustomaudienceid';
|
|
39
|
+
case IdentityType.Other2:
|
|
40
|
+
return 'other2';
|
|
41
|
+
case IdentityType.Other3:
|
|
42
|
+
return 'other3';
|
|
43
|
+
case IdentityType.Other4:
|
|
44
|
+
return 'other4';
|
|
45
|
+
case IdentityType.Other5:
|
|
46
|
+
return 'other5';
|
|
47
|
+
case IdentityType.Other6:
|
|
48
|
+
return 'other6';
|
|
49
|
+
case IdentityType.Other7:
|
|
50
|
+
return 'other7';
|
|
51
|
+
case IdentityType.Other8:
|
|
52
|
+
return 'other8';
|
|
53
|
+
case IdentityType.Other9:
|
|
54
|
+
return 'other9';
|
|
55
|
+
case IdentityType.Other10:
|
|
56
|
+
return 'other10';
|
|
57
|
+
case IdentityType.MobileNumber:
|
|
58
|
+
return 'mobile_number';
|
|
59
|
+
case IdentityType.PhoneNumber2:
|
|
60
|
+
return 'phone_number_2';
|
|
61
|
+
case IdentityType.PhoneNumber3:
|
|
62
|
+
return 'phone_number_3';
|
|
63
|
+
default:
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
}
|
package/src/types.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { getIdentityName } from './type-utils';
|
|
2
|
+
|
|
1
3
|
var MessageType = {
|
|
2
4
|
SessionStart: 1,
|
|
3
5
|
SessionEnd: 2,
|
|
@@ -209,50 +211,7 @@ IdentityType.getIdentityType = function(identityName) {
|
|
|
209
211
|
};
|
|
210
212
|
|
|
211
213
|
IdentityType.getIdentityName = function(identityType) {
|
|
212
|
-
|
|
213
|
-
case IdentityType.Other:
|
|
214
|
-
return 'other';
|
|
215
|
-
case IdentityType.CustomerId:
|
|
216
|
-
return 'customerid';
|
|
217
|
-
case IdentityType.Facebook:
|
|
218
|
-
return 'facebook';
|
|
219
|
-
case IdentityType.Twitter:
|
|
220
|
-
return 'twitter';
|
|
221
|
-
case IdentityType.Google:
|
|
222
|
-
return 'google';
|
|
223
|
-
case IdentityType.Microsoft:
|
|
224
|
-
return 'microsoft';
|
|
225
|
-
case IdentityType.Yahoo:
|
|
226
|
-
return 'yahoo';
|
|
227
|
-
case IdentityType.Email:
|
|
228
|
-
return 'email';
|
|
229
|
-
case IdentityType.FacebookCustomAudienceId:
|
|
230
|
-
return 'facebookcustomaudienceid';
|
|
231
|
-
case IdentityType.Other2:
|
|
232
|
-
return 'other2';
|
|
233
|
-
case IdentityType.Other3:
|
|
234
|
-
return 'other3';
|
|
235
|
-
case IdentityType.Other4:
|
|
236
|
-
return 'other4';
|
|
237
|
-
case IdentityType.Other5:
|
|
238
|
-
return 'other5';
|
|
239
|
-
case IdentityType.Other6:
|
|
240
|
-
return 'other6';
|
|
241
|
-
case IdentityType.Other7:
|
|
242
|
-
return 'other7';
|
|
243
|
-
case IdentityType.Other8:
|
|
244
|
-
return 'other8';
|
|
245
|
-
case IdentityType.Other9:
|
|
246
|
-
return 'other9';
|
|
247
|
-
case IdentityType.Other10:
|
|
248
|
-
return 'other10';
|
|
249
|
-
case IdentityType.MobileNumber:
|
|
250
|
-
return 'mobile_number';
|
|
251
|
-
case IdentityType.PhoneNumber2:
|
|
252
|
-
return 'phone_number_2';
|
|
253
|
-
case IdentityType.PhoneNumber3:
|
|
254
|
-
return 'phone_number_3';
|
|
255
|
-
}
|
|
214
|
+
return getIdentityName(identityType);
|
|
256
215
|
};
|
|
257
216
|
|
|
258
217
|
var ProductActionType = {
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { IMParticleUser, IdentityResultBody } from './identity-user-interfaces';
|
|
2
|
+
|
|
3
|
+
export function hasMPIDAndUserLoginChanged(
|
|
4
|
+
previousUser: IMParticleUser,
|
|
5
|
+
newUser: IMParticleUser
|
|
6
|
+
): boolean {
|
|
7
|
+
return (
|
|
8
|
+
!previousUser ||
|
|
9
|
+
newUser.getMPID() !== previousUser.getMPID() ||
|
|
10
|
+
previousUser.isLoggedIn() !== newUser.isLoggedIn()
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// https://go.mparticle.com/work/SQDSDKS-6504
|
|
15
|
+
export function hasMPIDChanged(
|
|
16
|
+
prevUser: IMParticleUser,
|
|
17
|
+
identityApiResult: IdentityResultBody
|
|
18
|
+
): boolean {
|
|
19
|
+
return (
|
|
20
|
+
!prevUser ||
|
|
21
|
+
(prevUser.getMPID() &&
|
|
22
|
+
identityApiResult.mpid &&
|
|
23
|
+
identityApiResult.mpid !== prevUser.getMPID())
|
|
24
|
+
);
|
|
25
|
+
}
|
package/src/utils.ts
CHANGED
|
@@ -229,6 +229,9 @@ const mergeObjects = <T extends object>(...objects: T[]): T => {
|
|
|
229
229
|
return Object.assign({}, ...objects);
|
|
230
230
|
};
|
|
231
231
|
|
|
232
|
+
const moveElementToEnd = <T>(array: T[], index: number): T[] =>
|
|
233
|
+
array.slice(0, index).concat(array.slice(index + 1), array[index]);
|
|
234
|
+
|
|
232
235
|
export {
|
|
233
236
|
createCookieString,
|
|
234
237
|
revertCookieString,
|
|
@@ -258,4 +261,5 @@ export {
|
|
|
258
261
|
isEmpty,
|
|
259
262
|
isValidCustomFlagProperty,
|
|
260
263
|
mergeObjects,
|
|
264
|
+
moveElementToEnd,
|
|
261
265
|
};
|