@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/src/store.ts
CHANGED
|
@@ -20,7 +20,16 @@ import {
|
|
|
20
20
|
SDKInitConfig,
|
|
21
21
|
SDKProduct,
|
|
22
22
|
} from './sdkRuntimeModels';
|
|
23
|
-
import {
|
|
23
|
+
import {
|
|
24
|
+
Dictionary,
|
|
25
|
+
isDataPlanSlug,
|
|
26
|
+
isEmpty,
|
|
27
|
+
isNumber,
|
|
28
|
+
isObject,
|
|
29
|
+
moveElementToEnd,
|
|
30
|
+
parseNumber,
|
|
31
|
+
returnConvertedBoolean,
|
|
32
|
+
} from './utils';
|
|
24
33
|
import { SDKConsentState } from './consent';
|
|
25
34
|
import { Kit, MPForwarder } from './forwarders.interfaces';
|
|
26
35
|
import { IPersistenceMinified } from './persistence.interfaces';
|
|
@@ -71,6 +80,9 @@ export interface SDKConfig {
|
|
|
71
80
|
v1SecureServiceUrl?: string;
|
|
72
81
|
v2SecureServiceUrl?: string;
|
|
73
82
|
v3SecureServiceUrl?: string;
|
|
83
|
+
webviewBridgeName?: string;
|
|
84
|
+
workspaceToken?: string;
|
|
85
|
+
requiredWebviewBridgeName?: string;
|
|
74
86
|
}
|
|
75
87
|
|
|
76
88
|
function createSDKConfig(config: SDKInitConfig): SDKConfig {
|
|
@@ -114,7 +126,7 @@ interface WrapperSDKInfo {
|
|
|
114
126
|
|
|
115
127
|
// https://go.mparticle.com/work/SQDSDKS-5954
|
|
116
128
|
export interface IFeatureFlags {
|
|
117
|
-
reportBatching?:
|
|
129
|
+
reportBatching?: boolean;
|
|
118
130
|
eventBatchingIntervalMillis?: number;
|
|
119
131
|
offlineStorage?: string;
|
|
120
132
|
directURLRouting?: boolean;
|
|
@@ -169,13 +181,15 @@ export interface IStore {
|
|
|
169
181
|
|
|
170
182
|
getDeviceId?(): string;
|
|
171
183
|
setDeviceId?(deviceId: string): void;
|
|
172
|
-
|
|
173
184
|
getFirstSeenTime?(mpid: MPID): number;
|
|
174
185
|
setFirstSeenTime?(mpid: MPID, time?: number): void;
|
|
175
186
|
getLastSeenTime?(mpid: MPID): number;
|
|
176
187
|
setLastSeenTime?(mpid: MPID, time?: number): void;
|
|
177
188
|
|
|
189
|
+
addMpidToSessionHistory?(mpid: MPID, previousMpid?: MPID): void;
|
|
190
|
+
hasInvalidIdentifyRequest?: () => boolean;
|
|
178
191
|
nullifySession?: () => void;
|
|
192
|
+
processConfig(config: SDKInitConfig): void;
|
|
179
193
|
}
|
|
180
194
|
|
|
181
195
|
// TODO: Merge this with SDKStoreApi in sdkRuntimeModels
|
|
@@ -185,6 +199,13 @@ export default function Store(
|
|
|
185
199
|
mpInstance: MParticleWebSDK,
|
|
186
200
|
apiKey?: string
|
|
187
201
|
) {
|
|
202
|
+
const {
|
|
203
|
+
createMainStorageName,
|
|
204
|
+
createProductStorageName,
|
|
205
|
+
} = mpInstance._Helpers;
|
|
206
|
+
|
|
207
|
+
const { isWebviewEnabled } = mpInstance._NativeSdkHelpers;
|
|
208
|
+
|
|
188
209
|
const defaultStore: Partial<IStore> = {
|
|
189
210
|
isEnabled: true,
|
|
190
211
|
sessionAttributes: {},
|
|
@@ -266,14 +287,17 @@ export default function Store(
|
|
|
266
287
|
this.SDKConfig.flags = {};
|
|
267
288
|
}
|
|
268
289
|
|
|
269
|
-
|
|
270
|
-
|
|
290
|
+
// We process the initial config that is passed via the SDK init
|
|
291
|
+
// and then we will reprocess the config within the processConfig
|
|
292
|
+
// function when the config is updated from the server
|
|
293
|
+
// https://go.mparticle.com/work/SQDSDKS-6317
|
|
294
|
+
this.SDKConfig.flags = processFlags(config);
|
|
271
295
|
|
|
272
296
|
if (config.deviceId) {
|
|
273
297
|
this.deviceId = config.deviceId;
|
|
274
298
|
}
|
|
275
299
|
if (config.hasOwnProperty('isDevelopmentMode')) {
|
|
276
|
-
this.SDKConfig.isDevelopmentMode =
|
|
300
|
+
this.SDKConfig.isDevelopmentMode = returnConvertedBoolean(
|
|
277
301
|
config.isDevelopmentMode
|
|
278
302
|
);
|
|
279
303
|
} else {
|
|
@@ -454,6 +478,16 @@ export default function Store(
|
|
|
454
478
|
}
|
|
455
479
|
}
|
|
456
480
|
|
|
481
|
+
this.hasInvalidIdentifyRequest = (): boolean => {
|
|
482
|
+
const { identifyRequest } = this.SDKConfig;
|
|
483
|
+
return (
|
|
484
|
+
(isObject(identifyRequest) &&
|
|
485
|
+
isObject(identifyRequest.userIdentities) &&
|
|
486
|
+
isEmpty(identifyRequest.userIdentities)) ||
|
|
487
|
+
!identifyRequest
|
|
488
|
+
);
|
|
489
|
+
};
|
|
490
|
+
|
|
457
491
|
this.getDeviceId = () => this.deviceId;
|
|
458
492
|
this.setDeviceId = (deviceId: string) => {
|
|
459
493
|
this.deviceId = deviceId;
|
|
@@ -461,11 +495,20 @@ export default function Store(
|
|
|
461
495
|
mpInstance._Persistence.update();
|
|
462
496
|
};
|
|
463
497
|
|
|
464
|
-
this.
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
498
|
+
this.addMpidToSessionHistory = (mpid: MPID, previousMPID?: MPID): void => {
|
|
499
|
+
const indexOfMPID = this.currentSessionMPIDs.indexOf(mpid);
|
|
500
|
+
|
|
501
|
+
if (mpid && previousMPID !== mpid && indexOfMPID < 0) {
|
|
502
|
+
this.currentSessionMPIDs.push(mpid);
|
|
503
|
+
return;
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
if (indexOfMPID >= 0) {
|
|
507
|
+
this.currentSessionMPIDs = moveElementToEnd(
|
|
508
|
+
this.currentSessionMPIDs,
|
|
509
|
+
indexOfMPID
|
|
510
|
+
);
|
|
511
|
+
}
|
|
469
512
|
};
|
|
470
513
|
|
|
471
514
|
this.getFirstSeenTime = (mpid: MPID) => {
|
|
@@ -539,12 +582,47 @@ export default function Store(
|
|
|
539
582
|
}
|
|
540
583
|
}
|
|
541
584
|
};
|
|
585
|
+
|
|
586
|
+
this.nullifySession = (): void => {
|
|
587
|
+
this.sessionId = null;
|
|
588
|
+
this.dateLastEventSent = null;
|
|
589
|
+
this.sessionAttributes = {};
|
|
590
|
+
mpInstance._Persistence.update();
|
|
591
|
+
};
|
|
592
|
+
|
|
593
|
+
this.processConfig = (config: SDKInitConfig) => {
|
|
594
|
+
const { workspaceToken, requiredWebviewBridgeName } = config;
|
|
595
|
+
|
|
596
|
+
// We should reprocess the flags in case they have changed when we request an updated config
|
|
597
|
+
// such as if the SDK is being self-hosted and the flags are different on the server config
|
|
598
|
+
// https://go.mparticle.com/work/SQDSDKS-6317
|
|
599
|
+
this.SDKConfig.flags = processFlags(config);
|
|
600
|
+
|
|
601
|
+
if (workspaceToken) {
|
|
602
|
+
this.SDKConfig.workspaceToken = workspaceToken;
|
|
603
|
+
} else {
|
|
604
|
+
mpInstance.Logger.warning(
|
|
605
|
+
'You should have a workspaceToken on your config object for security purposes.'
|
|
606
|
+
);
|
|
607
|
+
}
|
|
608
|
+
// add a new function to apply items to the store that require config to be returned
|
|
609
|
+
this.storageName = createMainStorageName(workspaceToken);
|
|
610
|
+
this.prodStorageName = createProductStorageName(workspaceToken);
|
|
611
|
+
|
|
612
|
+
this.SDKConfig.requiredWebviewBridgeName =
|
|
613
|
+
requiredWebviewBridgeName || workspaceToken;
|
|
614
|
+
|
|
615
|
+
this.webviewBridgeEnabled = isWebviewEnabled(
|
|
616
|
+
this.SDKConfig.requiredWebviewBridgeName,
|
|
617
|
+
this.SDKConfig.minWebviewBridgeVersion
|
|
618
|
+
);
|
|
619
|
+
|
|
620
|
+
this.configurationLoaded = true;
|
|
621
|
+
};
|
|
542
622
|
}
|
|
543
623
|
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
SDKConfig: SDKConfig
|
|
547
|
-
): IFeatureFlags {
|
|
624
|
+
// https://go.mparticle.com/work/SQDSDKS-6317
|
|
625
|
+
export function processFlags(config: SDKInitConfig): IFeatureFlags {
|
|
548
626
|
const flags: IFeatureFlags = {};
|
|
549
627
|
const {
|
|
550
628
|
ReportBatching,
|
|
@@ -559,6 +637,7 @@ export function processFlags(
|
|
|
559
637
|
return {};
|
|
560
638
|
}
|
|
561
639
|
|
|
640
|
+
// https://go.mparticle.com/work/SQDSDKS-6317
|
|
562
641
|
// Passed in config flags take priority over defaults
|
|
563
642
|
flags[ReportBatching] = config.flags[ReportBatching] || false;
|
|
564
643
|
// The server returns stringified numbers, sowe need to parse
|
|
@@ -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,12 @@
|
|
|
1
|
+
import { MParticleUser } from './sdkRuntimeModels';
|
|
2
|
+
|
|
3
|
+
export function didUserChange(
|
|
4
|
+
previousUser: MParticleUser,
|
|
5
|
+
newUser: MParticleUser
|
|
6
|
+
): boolean {
|
|
7
|
+
return (
|
|
8
|
+
!previousUser ||
|
|
9
|
+
newUser.getMPID() !== previousUser.getMPID() ||
|
|
10
|
+
previousUser.isLoggedIn() !== newUser.isLoggedIn()
|
|
11
|
+
);
|
|
12
|
+
}
|
package/src/utils.ts
CHANGED
|
@@ -227,6 +227,9 @@ const mergeObjects = <T extends object>(...objects: T[]): T => {
|
|
|
227
227
|
return Object.assign({}, ...objects);
|
|
228
228
|
};
|
|
229
229
|
|
|
230
|
+
const moveElementToEnd = <T>(array: T[], index: number): T[] =>
|
|
231
|
+
array.slice(0, index).concat(array.slice(index + 1), array[index]);
|
|
232
|
+
|
|
230
233
|
export {
|
|
231
234
|
createCookieString,
|
|
232
235
|
revertCookieString,
|
|
@@ -256,4 +259,5 @@ export {
|
|
|
256
259
|
isEmpty,
|
|
257
260
|
isValidCustomFlagProperty,
|
|
258
261
|
mergeObjects,
|
|
262
|
+
moveElementToEnd,
|
|
259
263
|
};
|