@mparticle/web-sdk 2.26.2 → 2.26.4
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 +59 -76
- package/dist/mparticle.esm.js +59 -76
- package/dist/mparticle.js +754 -789
- package/package.json +1 -1
- package/src/apiClient.ts +3 -2
- package/src/batchUploader.ts +5 -9
- package/src/consent.ts +4 -3
- package/src/forwarders.interfaces.ts +20 -18
- package/src/identity-user-interfaces.ts +64 -0
- package/src/identity-utils.ts +1 -1
- package/src/identity.interfaces.ts +205 -0
- package/src/identity.js +221 -158
- package/src/identityApiClient.js +0 -2
- package/src/persistence.interfaces.ts +1 -3
- package/src/persistence.js +0 -17
- package/src/sdkRuntimeModels.ts +15 -92
- package/src/sdkToEventsApiConverter.ts +33 -23
- package/src/serverModel.ts +10 -12
- package/src/sessionManager.ts +3 -2
- package/src/store.ts +0 -18
- package/src/types.js +44 -3
- package/src/utils.ts +2 -4
- package/src/validators.ts +1 -1
- package/src/type-utils.ts +0 -66
- package/src/user-utils.ts +0 -12
package/src/sdkRuntimeModels.ts
CHANGED
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
import * as EventsApi from '@mparticle/event-models';
|
|
2
2
|
import { DataPlanVersion } from '@mparticle/data-planning-models';
|
|
3
|
-
import {
|
|
4
|
-
MPConfiguration,
|
|
5
|
-
IdentityApiData,
|
|
6
|
-
MPID,
|
|
7
|
-
Callback,
|
|
8
|
-
} from '@mparticle/web-sdk';
|
|
3
|
+
import { MPConfiguration, MPID, Callback } from '@mparticle/web-sdk';
|
|
9
4
|
import { IStore } from './store';
|
|
10
5
|
import Validators from './validators';
|
|
11
|
-
import { Dictionary
|
|
6
|
+
import { Dictionary } from './utils';
|
|
12
7
|
import { IServerModel } from './serverModel';
|
|
13
8
|
import { IKitConfigs } from './configAPIClient';
|
|
14
9
|
import { SDKConsentApi, SDKConsentState } from './consent';
|
|
@@ -16,7 +11,13 @@ import { IPersistence } from './persistence.interfaces';
|
|
|
16
11
|
import { IMPSideloadedKit } from './sideloadedKit';
|
|
17
12
|
import { ISessionManager } from './sessionManager';
|
|
18
13
|
import { Kit, MPForwarder } from './forwarders.interfaces';
|
|
19
|
-
import
|
|
14
|
+
import { SDKIdentityApi } from './identity.interfaces';
|
|
15
|
+
import {
|
|
16
|
+
ISDKUserAttributeChangeData,
|
|
17
|
+
ISDKUserIdentityChanges,
|
|
18
|
+
IMParticleUser,
|
|
19
|
+
ISDKUserIdentity,
|
|
20
|
+
} from './identity-user-interfaces';
|
|
20
21
|
|
|
21
22
|
// TODO: Resolve this with version in @mparticle/web-sdk
|
|
22
23
|
export type SDKEventCustomFlags = Dictionary<any>;
|
|
@@ -26,11 +27,8 @@ export interface SDKEvent {
|
|
|
26
27
|
IsFirstRun: boolean;
|
|
27
28
|
EventName: string;
|
|
28
29
|
EventCategory: number;
|
|
29
|
-
|
|
30
|
-
// https://go.mparticle.com/work/SQDSDKS-5196
|
|
31
30
|
UserAttributes?: { [key: string]: string | string[] | null };
|
|
32
|
-
|
|
33
|
-
UserIdentities?: SDKUserIdentity[];
|
|
31
|
+
UserIdentities?: ISDKUserIdentity[];
|
|
34
32
|
SourceMessageId: string;
|
|
35
33
|
MPID: string;
|
|
36
34
|
EventAttributes?: { [key: string]: string };
|
|
@@ -54,15 +52,12 @@ export interface SDKEvent {
|
|
|
54
52
|
PromotionAction?: SDKPromotionAction;
|
|
55
53
|
ProductImpressions?: SDKProductImpression[];
|
|
56
54
|
ShoppingCart?: SDKShoppingCart;
|
|
57
|
-
UserIdentityChanges?:
|
|
58
|
-
UserAttributeChanges?:
|
|
55
|
+
UserIdentityChanges?: ISDKUserIdentityChanges;
|
|
56
|
+
UserAttributeChanges?: ISDKUserAttributeChangeData;
|
|
59
57
|
CurrencyCode: string;
|
|
60
58
|
DataPlan?: SDKDataPlan;
|
|
61
59
|
LaunchReferral?: string;
|
|
62
60
|
}
|
|
63
|
-
|
|
64
|
-
export type IdentityAPIMethod = valueof<typeof Constants.IdentityMethods>;
|
|
65
|
-
|
|
66
61
|
export interface SDKGeoLocation {
|
|
67
62
|
lat: number | string;
|
|
68
63
|
lng: number | string;
|
|
@@ -73,11 +68,6 @@ export interface SDKDataPlan {
|
|
|
73
68
|
PlanId?: string | null;
|
|
74
69
|
}
|
|
75
70
|
|
|
76
|
-
export interface SDKUserIdentity {
|
|
77
|
-
Identity?: string;
|
|
78
|
-
Type: number;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
71
|
export interface SDKShoppingCart {
|
|
82
72
|
ProductList?: SDKProduct[];
|
|
83
73
|
}
|
|
@@ -242,16 +232,6 @@ export interface DataPlanConfig {
|
|
|
242
232
|
document?: DataPlanResult; // when the data plan comes from the server via /mparticle.js
|
|
243
233
|
}
|
|
244
234
|
|
|
245
|
-
export interface SDKIdentityApi {
|
|
246
|
-
getCurrentUser();
|
|
247
|
-
IdentityAPI;
|
|
248
|
-
identify;
|
|
249
|
-
login;
|
|
250
|
-
logout;
|
|
251
|
-
modify;
|
|
252
|
-
getUser(mpid: string): MParticleUser;
|
|
253
|
-
}
|
|
254
|
-
|
|
255
235
|
export interface SDKHelpersApi {
|
|
256
236
|
canLog?(): boolean;
|
|
257
237
|
createMainStorageName?(workspaceToken: string): string;
|
|
@@ -274,7 +254,7 @@ export interface SDKHelpersApi {
|
|
|
274
254
|
callback: Callback,
|
|
275
255
|
code: string,
|
|
276
256
|
body: string,
|
|
277
|
-
mParticleUser?:
|
|
257
|
+
mParticleUser?: IMParticleUser,
|
|
278
258
|
previousMpid?: MPID
|
|
279
259
|
): void;
|
|
280
260
|
sanitizeAttributes?(
|
|
@@ -307,38 +287,6 @@ export interface SDKConfigApi {
|
|
|
307
287
|
onCreateBatch(batch: EventsApi.Batch): EventsApi.Batch;
|
|
308
288
|
}
|
|
309
289
|
|
|
310
|
-
// https://go.mparticle.com/work/SQDSDKS-5033
|
|
311
|
-
export interface MParticleUser {
|
|
312
|
-
getMPID?(): string;
|
|
313
|
-
getConsentState?(): SDKConsentState;
|
|
314
|
-
|
|
315
|
-
// https://go.mparticle.com/work/SQDSDKS-5196
|
|
316
|
-
getAllUserAttributes?(): any;
|
|
317
|
-
|
|
318
|
-
getUserIdentities?(): IdentityApiData;
|
|
319
|
-
isLoggedIn?(): boolean;
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
export interface SDKUserIdentityChangeData {
|
|
323
|
-
New: Identity;
|
|
324
|
-
Old: Identity;
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
export interface Identity {
|
|
328
|
-
IdentityType: SDKIdentityTypeEnum;
|
|
329
|
-
Identity: string;
|
|
330
|
-
Timestamp: number;
|
|
331
|
-
CreatedThisBatch: boolean;
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
export interface SDKUserAttributeChangeData {
|
|
335
|
-
UserAttributeName: string;
|
|
336
|
-
New: string;
|
|
337
|
-
Old: string;
|
|
338
|
-
Deleted: boolean;
|
|
339
|
-
IsNewAttribute: boolean;
|
|
340
|
-
}
|
|
341
|
-
|
|
342
290
|
export interface BaseEvent {
|
|
343
291
|
messageType: number;
|
|
344
292
|
name?: string;
|
|
@@ -347,8 +295,8 @@ export interface BaseEvent {
|
|
|
347
295
|
customFlags?: { [key: string]: string };
|
|
348
296
|
toEventAPIObject?(): SDKEvent;
|
|
349
297
|
sourceMessageId?: string;
|
|
350
|
-
userAttributeChanges?:
|
|
351
|
-
userIdentityChanges?:
|
|
298
|
+
userAttributeChanges?: ISDKUserAttributeChangeData;
|
|
299
|
+
userIdentityChanges?: ISDKUserIdentityChanges;
|
|
352
300
|
}
|
|
353
301
|
|
|
354
302
|
export interface KitBlockerOptions {
|
|
@@ -375,28 +323,3 @@ export interface DataPlanResult {
|
|
|
375
323
|
};
|
|
376
324
|
error_message?: string;
|
|
377
325
|
}
|
|
378
|
-
|
|
379
|
-
export enum SDKIdentityTypeEnum {
|
|
380
|
-
other = 'other',
|
|
381
|
-
customerId = 'customerid',
|
|
382
|
-
facebook = 'facebook',
|
|
383
|
-
twitter = 'twitter',
|
|
384
|
-
google = 'google',
|
|
385
|
-
microsoft = 'microsoft',
|
|
386
|
-
yahoo = 'yahoo',
|
|
387
|
-
email = 'email',
|
|
388
|
-
alias = 'alias',
|
|
389
|
-
facebookCustomAudienceId = 'facebookcustomaudienceid',
|
|
390
|
-
otherId2 = 'other2',
|
|
391
|
-
otherId3 = 'other3',
|
|
392
|
-
otherId4 = 'other4',
|
|
393
|
-
otherId5 = 'other5',
|
|
394
|
-
otherId6 = 'other6',
|
|
395
|
-
otherId7 = 'other7',
|
|
396
|
-
otherId8 = 'other8',
|
|
397
|
-
otherId9 = 'other9',
|
|
398
|
-
otherId10 = 'other10',
|
|
399
|
-
mobileNumber = 'mobile_number',
|
|
400
|
-
phoneNumber2 = 'phone_number_2',
|
|
401
|
-
phoneNumber3 = 'phone_number_3',
|
|
402
|
-
}
|
|
@@ -3,10 +3,8 @@ import {
|
|
|
3
3
|
SDKGeoLocation,
|
|
4
4
|
SDKProduct,
|
|
5
5
|
SDKPromotion,
|
|
6
|
-
SDKUserIdentity,
|
|
7
6
|
SDKProductActionType,
|
|
8
7
|
MParticleWebSDK,
|
|
9
|
-
SDKIdentityTypeEnum,
|
|
10
8
|
} from './sdkRuntimeModels';
|
|
11
9
|
import * as EventsApi from '@mparticle/event-models';
|
|
12
10
|
import {
|
|
@@ -16,6 +14,8 @@ import {
|
|
|
16
14
|
} from './consent';
|
|
17
15
|
import Types from './types';
|
|
18
16
|
import { isEmpty } from './utils';
|
|
17
|
+
import { ISDKUserIdentity } from './identity-user-interfaces';
|
|
18
|
+
import { SDKIdentityTypeEnum } from './identity.interfaces';
|
|
19
19
|
|
|
20
20
|
export function convertEvents(
|
|
21
21
|
mpid: string,
|
|
@@ -151,7 +151,7 @@ export function convertCcpaConsentState(
|
|
|
151
151
|
}
|
|
152
152
|
|
|
153
153
|
export function convertUserIdentities(
|
|
154
|
-
sdkUserIdentities?:
|
|
154
|
+
sdkUserIdentities?: ISDKUserIdentity[]
|
|
155
155
|
): EventsApi.BatchUserIdentities | null {
|
|
156
156
|
if (!sdkUserIdentities || !sdkUserIdentities.length) {
|
|
157
157
|
return null;
|
|
@@ -407,8 +407,9 @@ export function convertShoppingCart(
|
|
|
407
407
|
export function convertCommerceEvent(
|
|
408
408
|
sdkEvent: SDKEvent
|
|
409
409
|
): EventsApi.CommerceEvent {
|
|
410
|
-
const commonEventData: EventsApi.CommonEventData =
|
|
411
|
-
|
|
410
|
+
const commonEventData: EventsApi.CommonEventData = convertBaseEventData(
|
|
411
|
+
sdkEvent
|
|
412
|
+
);
|
|
412
413
|
let commerceEventData: EventsApi.CommerceEventData = {
|
|
413
414
|
custom_flags: sdkEvent.CustomFlags,
|
|
414
415
|
product_action: convertProductAction(sdkEvent),
|
|
@@ -427,8 +428,9 @@ export function convertCommerceEvent(
|
|
|
427
428
|
export function convertCrashReportEvent(
|
|
428
429
|
sdkEvent: SDKEvent
|
|
429
430
|
): EventsApi.CrashReportEvent {
|
|
430
|
-
const commonEventData: EventsApi.CommonEventData =
|
|
431
|
-
|
|
431
|
+
const commonEventData: EventsApi.CommonEventData = convertBaseEventData(
|
|
432
|
+
sdkEvent
|
|
433
|
+
);
|
|
432
434
|
let crashReportEventData: EventsApi.CrashReportEventData = {
|
|
433
435
|
message: sdkEvent.EventName,
|
|
434
436
|
};
|
|
@@ -442,8 +444,9 @@ export function convertCrashReportEvent(
|
|
|
442
444
|
export function convertAST(
|
|
443
445
|
sdkEvent: SDKEvent
|
|
444
446
|
): EventsApi.ApplicationStateTransitionEvent {
|
|
445
|
-
const commonEventData: EventsApi.CommonEventData =
|
|
446
|
-
|
|
447
|
+
const commonEventData: EventsApi.CommonEventData = convertBaseEventData(
|
|
448
|
+
sdkEvent
|
|
449
|
+
);
|
|
447
450
|
let astEventData: EventsApi.ApplicationStateTransitionEventData = {
|
|
448
451
|
application_transition_type:
|
|
449
452
|
EventsApi
|
|
@@ -463,8 +466,9 @@ export function convertAST(
|
|
|
463
466
|
export function convertSessionEndEvent(
|
|
464
467
|
sdkEvent: SDKEvent
|
|
465
468
|
): EventsApi.SessionEndEvent {
|
|
466
|
-
const commonEventData: EventsApi.CommonEventData =
|
|
467
|
-
|
|
469
|
+
const commonEventData: EventsApi.CommonEventData = convertBaseEventData(
|
|
470
|
+
sdkEvent
|
|
471
|
+
);
|
|
468
472
|
let sessionEndEventData: EventsApi.SessionEndEventData = {
|
|
469
473
|
session_duration_ms: sdkEvent.SessionLength,
|
|
470
474
|
//note: External Events DTO does not support the session mpids array as of this time.
|
|
@@ -480,8 +484,9 @@ export function convertSessionEndEvent(
|
|
|
480
484
|
export function convertSessionStartEvent(
|
|
481
485
|
sdkEvent: SDKEvent
|
|
482
486
|
): EventsApi.SessionStartEvent {
|
|
483
|
-
const commonEventData: EventsApi.CommonEventData =
|
|
484
|
-
|
|
487
|
+
const commonEventData: EventsApi.CommonEventData = convertBaseEventData(
|
|
488
|
+
sdkEvent
|
|
489
|
+
);
|
|
485
490
|
let sessionStartEventData: EventsApi.SessionStartEventData = {};
|
|
486
491
|
sessionStartEventData = Object.assign(
|
|
487
492
|
sessionStartEventData,
|
|
@@ -496,8 +501,9 @@ export function convertSessionStartEvent(
|
|
|
496
501
|
export function convertPageViewEvent(
|
|
497
502
|
sdkEvent: SDKEvent
|
|
498
503
|
): EventsApi.ScreenViewEvent {
|
|
499
|
-
const commonEventData: EventsApi.CommonEventData =
|
|
500
|
-
|
|
504
|
+
const commonEventData: EventsApi.CommonEventData = convertBaseEventData(
|
|
505
|
+
sdkEvent
|
|
506
|
+
);
|
|
501
507
|
let screenViewEventData: EventsApi.ScreenViewEventData = {
|
|
502
508
|
custom_flags: sdkEvent.CustomFlags,
|
|
503
509
|
screen_name: sdkEvent.EventName,
|
|
@@ -510,8 +516,9 @@ export function convertPageViewEvent(
|
|
|
510
516
|
}
|
|
511
517
|
|
|
512
518
|
export function convertOptOutEvent(sdkEvent: SDKEvent): EventsApi.OptOutEvent {
|
|
513
|
-
const commonEventData: EventsApi.CommonEventData =
|
|
514
|
-
|
|
519
|
+
const commonEventData: EventsApi.CommonEventData = convertBaseEventData(
|
|
520
|
+
sdkEvent
|
|
521
|
+
);
|
|
515
522
|
let optOutEventData: EventsApi.OptOutEventData = {
|
|
516
523
|
is_opted_out: sdkEvent.OptOut,
|
|
517
524
|
};
|
|
@@ -523,8 +530,9 @@ export function convertOptOutEvent(sdkEvent: SDKEvent): EventsApi.OptOutEvent {
|
|
|
523
530
|
}
|
|
524
531
|
|
|
525
532
|
export function convertCustomEvent(sdkEvent: SDKEvent): EventsApi.CustomEvent {
|
|
526
|
-
const commonEventData: EventsApi.CommonEventData =
|
|
527
|
-
|
|
533
|
+
const commonEventData: EventsApi.CommonEventData = convertBaseEventData(
|
|
534
|
+
sdkEvent
|
|
535
|
+
);
|
|
528
536
|
let customEventData: EventsApi.CustomEventData = {
|
|
529
537
|
custom_event_type: convertSdkEventType(
|
|
530
538
|
sdkEvent.EventCategory
|
|
@@ -628,8 +636,9 @@ export function convertSDKLocation(
|
|
|
628
636
|
export function convertUserAttributeChangeEvent(
|
|
629
637
|
sdkEvent: SDKEvent
|
|
630
638
|
): EventsApi.UserAttributeChangeEvent | null {
|
|
631
|
-
const commonEventData: EventsApi.CommonEventData =
|
|
632
|
-
|
|
639
|
+
const commonEventData: EventsApi.CommonEventData = convertBaseEventData(
|
|
640
|
+
sdkEvent
|
|
641
|
+
);
|
|
633
642
|
let userAttributeChangeEvent: EventsApi.UserAttributeChangeEventData = {
|
|
634
643
|
user_attribute_name: sdkEvent.UserAttributeChanges.UserAttributeName,
|
|
635
644
|
new: sdkEvent.UserAttributeChanges.New,
|
|
@@ -652,8 +661,9 @@ export function convertUserAttributeChangeEvent(
|
|
|
652
661
|
export function convertUserIdentityChangeEvent(
|
|
653
662
|
sdkEvent: SDKEvent
|
|
654
663
|
): EventsApi.UserIdentityChangeEvent | null {
|
|
655
|
-
const commonEventData: EventsApi.CommonEventData =
|
|
656
|
-
|
|
664
|
+
const commonEventData: EventsApi.CommonEventData = convertBaseEventData(
|
|
665
|
+
sdkEvent
|
|
666
|
+
);
|
|
657
667
|
|
|
658
668
|
let userIdentityChangeEvent: EventsApi.UserIdentityChangeEventData = {
|
|
659
669
|
new: {
|
package/src/serverModel.ts
CHANGED
|
@@ -6,12 +6,10 @@ import Types from './types';
|
|
|
6
6
|
import Constants from './constants';
|
|
7
7
|
import {
|
|
8
8
|
BaseEvent,
|
|
9
|
-
MParticleUser,
|
|
10
9
|
MParticleWebSDK,
|
|
11
10
|
SDKEvent,
|
|
12
11
|
SDKGeoLocation,
|
|
13
12
|
SDKProduct,
|
|
14
|
-
SDKUserIdentity,
|
|
15
13
|
} from './sdkRuntimeModels';
|
|
16
14
|
import {
|
|
17
15
|
parseNumber,
|
|
@@ -27,7 +25,7 @@ import {
|
|
|
27
25
|
IPrivacyV2DTO,
|
|
28
26
|
SDKConsentState,
|
|
29
27
|
} from './consent';
|
|
30
|
-
import {
|
|
28
|
+
import { IMParticleUser, ISDKUserIdentity } from './identity-user-interfaces';
|
|
31
29
|
|
|
32
30
|
const MessageType = Types.MessageType;
|
|
33
31
|
const ApplicationTransitionType = Types.ApplicationTransitionType;
|
|
@@ -48,11 +46,8 @@ export interface IServerV2DTO {
|
|
|
48
46
|
dp_v?: number;
|
|
49
47
|
n?: string;
|
|
50
48
|
et?: number;
|
|
51
|
-
|
|
52
|
-
// https://go.mparticle.com/work/SQDSDKS-5196
|
|
53
49
|
ua?: Dictionary<string | string[]>;
|
|
54
|
-
|
|
55
|
-
ui?: SDKUserIdentity[];
|
|
50
|
+
ui?: ISDKUserIdentity[];
|
|
56
51
|
ia?: Dictionary<Dictionary<string>>;
|
|
57
52
|
str?: ServerSettings;
|
|
58
53
|
sdk?: string;
|
|
@@ -139,9 +134,9 @@ export interface IUploadObject extends SDKEvent {
|
|
|
139
134
|
|
|
140
135
|
export interface IServerModel {
|
|
141
136
|
convertEventToV2DTO: (event: IUploadObject) => IServerV2DTO;
|
|
142
|
-
createEventObject: (event: BaseEvent, user?:
|
|
137
|
+
createEventObject: (event: BaseEvent, user?: IMParticleUser) => SDKEvent;
|
|
143
138
|
convertToConsentStateV2DTO: (state: SDKConsentState) => IConsentStateV2DTO;
|
|
144
|
-
appendUserInfo: (user:
|
|
139
|
+
appendUserInfo: (user: IMParticleUser, event: SDKEvent) => void;
|
|
145
140
|
}
|
|
146
141
|
|
|
147
142
|
// TODO: Make this a pure function that returns a new object
|
|
@@ -203,7 +198,10 @@ export default function ServerModel(
|
|
|
203
198
|
var self = this;
|
|
204
199
|
|
|
205
200
|
// TODO: Can we refactor this to not mutate the event?
|
|
206
|
-
this.appendUserInfo = function(
|
|
201
|
+
this.appendUserInfo = function(
|
|
202
|
+
user: IMParticleUser,
|
|
203
|
+
event: SDKEvent
|
|
204
|
+
): void {
|
|
207
205
|
if (!event) {
|
|
208
206
|
return;
|
|
209
207
|
}
|
|
@@ -234,7 +232,7 @@ export default function ServerModel(
|
|
|
234
232
|
if (mpInstance._Helpers.isObject(dtoUserIdentities)) {
|
|
235
233
|
if (Object.keys(dtoUserIdentities).length) {
|
|
236
234
|
for (var key in dtoUserIdentities) {
|
|
237
|
-
var userIdentity: Partial<
|
|
235
|
+
var userIdentity: Partial<ISDKUserIdentity> = {};
|
|
238
236
|
userIdentity.Identity = dtoUserIdentities[key];
|
|
239
237
|
userIdentity.Type = mpInstance._Helpers.parseNumber(key);
|
|
240
238
|
validUserIdentities.push(userIdentity);
|
|
@@ -296,7 +294,7 @@ export default function ServerModel(
|
|
|
296
294
|
|
|
297
295
|
this.createEventObject = function(
|
|
298
296
|
event: BaseEvent,
|
|
299
|
-
user?:
|
|
297
|
+
user?: IMParticleUser
|
|
300
298
|
): SDKEvent | IUploadObject {
|
|
301
299
|
var uploadObject: Partial<IUploadObject> = {};
|
|
302
300
|
var eventObject: Partial<SDKEvent> = {};
|
package/src/sessionManager.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { MPID } from '@mparticle/web-sdk';
|
|
2
2
|
import Constants from './constants';
|
|
3
3
|
import { IPersistenceMinified } from './persistence.interfaces';
|
|
4
|
-
import {
|
|
4
|
+
import { MParticleWebSDK } from './sdkRuntimeModels';
|
|
5
5
|
import Types from './types';
|
|
6
6
|
import { generateDeprecationMessage } from './utils';
|
|
7
|
+
import { IMParticleUser } from './identity-user-interfaces';
|
|
7
8
|
|
|
8
9
|
const { Messages } = Constants;
|
|
9
10
|
|
|
@@ -86,7 +87,7 @@ export default function SessionManager(
|
|
|
86
87
|
.generateUniqueId()
|
|
87
88
|
.toUpperCase();
|
|
88
89
|
|
|
89
|
-
const currentUser:
|
|
90
|
+
const currentUser: IMParticleUser = mpInstance.Identity.getCurrentUser();
|
|
90
91
|
const mpid: MPID = currentUser ? currentUser.getMPID() : null;
|
|
91
92
|
|
|
92
93
|
if (mpid) {
|
package/src/store.ts
CHANGED
|
@@ -26,7 +26,6 @@ import {
|
|
|
26
26
|
isEmpty,
|
|
27
27
|
isNumber,
|
|
28
28
|
isObject,
|
|
29
|
-
moveElementToEnd,
|
|
30
29
|
parseNumber,
|
|
31
30
|
returnConvertedBoolean,
|
|
32
31
|
} from './utils';
|
|
@@ -186,7 +185,6 @@ export interface IStore {
|
|
|
186
185
|
getLastSeenTime?(mpid: MPID): number;
|
|
187
186
|
setLastSeenTime?(mpid: MPID, time?: number): void;
|
|
188
187
|
|
|
189
|
-
addMpidToSessionHistory?(mpid: MPID, previousMpid?: MPID): void;
|
|
190
188
|
hasInvalidIdentifyRequest?: () => boolean;
|
|
191
189
|
nullifySession?: () => void;
|
|
192
190
|
processConfig(config: SDKInitConfig): void;
|
|
@@ -495,22 +493,6 @@ export default function Store(
|
|
|
495
493
|
mpInstance._Persistence.update();
|
|
496
494
|
};
|
|
497
495
|
|
|
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
|
-
}
|
|
512
|
-
};
|
|
513
|
-
|
|
514
496
|
this.getFirstSeenTime = (mpid: MPID) => {
|
|
515
497
|
if (!mpid) {
|
|
516
498
|
return null;
|
package/src/types.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { getIdentityName } from './type-utils';
|
|
2
|
-
|
|
3
1
|
var MessageType = {
|
|
4
2
|
SessionStart: 1,
|
|
5
3
|
SessionEnd: 2,
|
|
@@ -211,7 +209,50 @@ IdentityType.getIdentityType = function(identityName) {
|
|
|
211
209
|
};
|
|
212
210
|
|
|
213
211
|
IdentityType.getIdentityName = function(identityType) {
|
|
214
|
-
|
|
212
|
+
switch (identityType) {
|
|
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
|
+
}
|
|
215
256
|
};
|
|
216
257
|
|
|
217
258
|
var ProductActionType = {
|
package/src/utils.ts
CHANGED
|
@@ -7,6 +7,8 @@ type valueof<T> = T[keyof T];
|
|
|
7
7
|
// Placeholder for Dictionary-like Types
|
|
8
8
|
export type Dictionary<V = any> = Record<string, V>;
|
|
9
9
|
|
|
10
|
+
export type Environment = 'development' | 'production';
|
|
11
|
+
|
|
10
12
|
const createCookieString = (value: string): string =>
|
|
11
13
|
replaceCommasWithPipes(replaceQuotesWithApostrophes(value));
|
|
12
14
|
|
|
@@ -227,9 +229,6 @@ const mergeObjects = <T extends object>(...objects: T[]): T => {
|
|
|
227
229
|
return Object.assign({}, ...objects);
|
|
228
230
|
};
|
|
229
231
|
|
|
230
|
-
const moveElementToEnd = <T>(array: T[], index: number): T[] =>
|
|
231
|
-
array.slice(0, index).concat(array.slice(index + 1), array[index]);
|
|
232
|
-
|
|
233
232
|
export {
|
|
234
233
|
createCookieString,
|
|
235
234
|
revertCookieString,
|
|
@@ -259,5 +258,4 @@ export {
|
|
|
259
258
|
isEmpty,
|
|
260
259
|
isValidCustomFlagProperty,
|
|
261
260
|
mergeObjects,
|
|
262
|
-
moveElementToEnd,
|
|
263
261
|
};
|
package/src/validators.ts
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
} from './utils';
|
|
9
9
|
import Constants from './constants';
|
|
10
10
|
import { IdentityApiData } from '@mparticle/web-sdk';
|
|
11
|
-
import { IdentityAPIMethod } from './
|
|
11
|
+
import { IdentityAPIMethod } from './identity.interfaces';
|
|
12
12
|
|
|
13
13
|
type ValidationIdentitiesReturn = {
|
|
14
14
|
valid: boolean;
|
package/src/type-utils.ts
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
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/user-utils.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
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
|
-
}
|