@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mparticle/web-sdk",
3
- "version": "2.26.2",
3
+ "version": "2.26.4",
4
4
  "description": "mParticle core SDK for web applications",
5
5
  "license": "Apache-2.0",
6
6
  "keywords": [
package/src/apiClient.ts CHANGED
@@ -1,11 +1,12 @@
1
1
  import Constants from './constants';
2
2
  import Types from './types';
3
3
  import { BatchUploader } from './batchUploader';
4
- import { MParticleUser, MParticleWebSDK, SDKEvent } from './sdkRuntimeModels';
4
+ import { MParticleWebSDK, SDKEvent } from './sdkRuntimeModels';
5
5
  import KitBlocker from './kitBlocking';
6
6
  import { Dictionary, getRampNumber, isEmpty, parseNumber } from './utils';
7
7
  import { IUploadObject } from './serverModel';
8
8
  import { MPForwarder } from './forwarders.interfaces';
9
+ import { IMParticleUser } from './identity-user-interfaces';
9
10
 
10
11
  export type ForwardingStatsData = Dictionary<any>;
11
12
 
@@ -13,7 +14,7 @@ export interface IAPIClient {
13
14
  uploader: BatchUploader | null;
14
15
  queueEventForBatchUpload: (event: SDKEvent) => void;
15
16
  processQueuedEvents: () => void;
16
- appendUserInfoToEvents: (user: MParticleUser, events: SDKEvent[]) => void;
17
+ appendUserInfoToEvents: (user: IMParticleUser, events: SDKEvent[]) => void;
17
18
  sendEventToServer: (event: SDKEvent, _options?: Dictionary<any>) => void;
18
19
  sendSingleEventToServer: (event: SDKEvent) => void;
19
20
  sendBatchForwardingStatsToServer: (
@@ -1,21 +1,17 @@
1
1
  import { Batch } from '@mparticle/event-models';
2
2
  import Constants from './constants';
3
- import {
4
- SDKEvent,
5
- MParticleUser,
6
- MParticleWebSDK,
7
- SDKLoggerApi,
8
- } from './sdkRuntimeModels';
3
+ import { SDKEvent, MParticleWebSDK, SDKLoggerApi } from './sdkRuntimeModels';
9
4
  import { convertEvents } from './sdkToEventsApiConverter';
10
5
  import Types from './types';
11
6
  import { getRampNumber, isEmpty } from './utils';
12
7
  import { SessionStorageVault, LocalStorageVault } from './vault';
13
- import {
8
+ import {
14
9
  AsyncUploader,
15
10
  FetchUploader,
16
11
  XHRUploader,
17
- fetchPayload
12
+ fetchPayload,
18
13
  } from './uploaders';
14
+ import { IMParticleUser } from './identity-user-interfaces';
19
15
 
20
16
  /**
21
17
  * BatchUploader contains all the logic to store/retrieve events and batches
@@ -205,7 +201,7 @@ export class BatchUploader {
205
201
  */
206
202
  private static createNewBatches(
207
203
  sdkEvents: SDKEvent[],
208
- defaultUser: MParticleUser,
204
+ defaultUser: IMParticleUser,
209
205
  mpInstance: MParticleWebSDK
210
206
  ): Batch[] | null {
211
207
  if (!defaultUser || !sdkEvents || !sdkEvents.length) {
package/src/consent.ts CHANGED
@@ -4,10 +4,11 @@ import {
4
4
  GDPRConsentState,
5
5
  PrivacyConsentState,
6
6
  } from '@mparticle/web-sdk';
7
- import { MParticleUser, MParticleWebSDK } from './sdkRuntimeModels';
7
+ import { MParticleWebSDK } from './sdkRuntimeModels';
8
8
  import { Dictionary, isObject } from './utils';
9
9
  import KitFilterHelper from './kitFilterHelper';
10
10
  import Constants from './constants';
11
+ import { IMParticleUser } from './identity-user-interfaces';
11
12
 
12
13
  const { CCPAPurpose } = Constants;
13
14
 
@@ -108,7 +109,7 @@ export interface IConsentState extends ConsentState {
108
109
  export interface IConsent {
109
110
  isEnabledForUserConsent: (
110
111
  consentRules: IConsentRules,
111
- user: MParticleUser
112
+ user: IMParticleUser
112
113
  ) => boolean;
113
114
  createPrivacyConsent: ICreatePrivacyConsentFunction;
114
115
  createConsentState: (consentState?: ConsentState) => ConsentState;
@@ -123,7 +124,7 @@ export default function Consent(this: IConsent, mpInstance: MParticleWebSDK) {
123
124
  // forwarder should be initialized
124
125
  this.isEnabledForUserConsent = function(
125
126
  consentRules: IConsentRules,
126
- user: MParticleUser
127
+ user: IMParticleUser
127
128
  ): boolean {
128
129
  if (
129
130
  !consentRules ||
@@ -1,13 +1,12 @@
1
- import {
2
- MParticleUser,
3
- SDKEvent,
4
- SDKEventCustomFlags,
5
- SDKUserIdentity,
6
- } from './sdkRuntimeModels';
1
+ import { SDKEvent, SDKEventCustomFlags } from './sdkRuntimeModels';
7
2
  import { Dictionary } from './utils';
8
3
  import { IKitConfigs } from './configAPIClient';
9
- import { UserAttributes } from './persistence.interfaces';
10
4
  import { IdentityApiData } from '@mparticle/web-sdk';
5
+ import {
6
+ IMParticleUser,
7
+ ISDKUserIdentity,
8
+ UserAttributes,
9
+ } from './identity-user-interfaces';
11
10
 
12
11
  // TODO: https://go.mparticle.com/work/SQDSDKS-6035
13
12
  export type Kit = Dictionary;
@@ -19,7 +18,7 @@ export interface UnregisteredKit {
19
18
  register(config): void;
20
19
  }
21
20
 
22
- // The state of the kit after being added to forwarderConstructors in the CDN
21
+ // The state of the kit after being added to forwarderConstructors in the CDN
23
22
  // or after registered to SDKConfig.kits via NPM
24
23
  export interface RegisteredKit {
25
24
  constructor(): void;
@@ -37,47 +36,50 @@ export interface ConfiguredKit
37
36
  testMode: boolean,
38
37
  trackerId: string | null,
39
38
  userAttributes: UserAttributes,
40
- userIdentities: SDKUserIdentity,
39
+ userIdentities: ISDKUserIdentity,
41
40
  appVersion: string,
42
41
  appName: string,
43
42
  customFlags: SDKEventCustomFlags,
44
43
  clientId: string
45
44
  ): string;
46
45
  onIdentifyComplete(
47
- user: MParticleUser,
46
+ user: IMParticleUser,
48
47
  filteredIdentityRequest: IdentityApiData
49
48
  ): string | KitMappedMethodFailure;
50
49
  onLoginComplete(
51
- user: MParticleUser,
50
+ user: IMParticleUser,
52
51
  filteredIdentityRequest: IdentityApiData
53
52
  ): string | KitMappedMethodFailure;
54
53
  onLogoutComplete(
55
- user: MParticleUser,
54
+ user: IMParticleUser,
56
55
  filteredIdentityRequest: IdentityApiData
57
56
  ): string | KitMappedMethodFailure;
58
57
  onModifyComplete(
59
- user: MParticleUser,
58
+ user: IMParticleUser,
60
59
  filteredIdentityRequest: IdentityApiData
61
60
  ): string | KitMappedMethodFailure;
62
- onUserIdentified(user: MParticleUser): string | KitMappedMethodFailure;
61
+ onUserIdentified(user: IMParticleUser): string | KitMappedMethodFailure;
63
62
  process(event: SDKEvent): string;
64
63
  setOptOut(isOptingOut: boolean): string | KitMappedMethodFailure;
65
64
  removeUserAttribute(key: string): string;
66
- setUserAttribute(key: string, value:string): string;
65
+ setUserAttribute(key: string, value: string): string;
67
66
 
68
67
  // TODO: Convert type to enum during Identity migration
69
68
  // https://go.mparticle.com/work/SQDSDKS-5218
70
69
  setUserIdentity(id: UserIdentityId, type: UserIdentityType): void;
71
70
 
72
71
  // TODO: https://go.mparticle.com/work/SQDSDKS-5156
73
- isSandbox: boolean;
72
+ isSandbox: boolean;
74
73
  hasSandbox: boolean;
75
74
  }
76
75
  export interface KitMappedMethodFailure {
77
- error: string
76
+ error: string;
78
77
  }
79
78
 
80
79
  export type UserIdentityId = string;
81
80
  export type UserIdentityType = number;
82
81
 
83
- export type forwardingStatsCallback = (forwarder: ConfiguredKit, event: SDKEvent) => void;
82
+ export type forwardingStatsCallback = (
83
+ forwarder: ConfiguredKit,
84
+ event: SDKEvent
85
+ ) => void;
@@ -0,0 +1,64 @@
1
+ import {
2
+ AllUserAttributes,
3
+ IdentityCallback,
4
+ Product,
5
+ User,
6
+ } from '@mparticle/web-sdk';
7
+ import { SDKIdentityTypeEnum } from './identity.interfaces';
8
+ import { MessageType } from './types.interfaces';
9
+ import { BaseEvent } from './sdkRuntimeModels';
10
+
11
+ // https://go.mparticle.com/work/SQDSDKS-5033
12
+ // https://go.mparticle.com/work/SQDSDKS-6354
13
+ export interface IMParticleUser extends User {
14
+ getAllUserAttributes(): any;
15
+ setUserTag(tagName: string, value?: any): void;
16
+ setUserAttribute(key: string, value: any): void;
17
+ getUserAudiences?(callback?: IdentityCallback): void;
18
+ }
19
+
20
+ export interface ISDKUserIdentity {
21
+ Identity: string;
22
+ Type: number;
23
+ }
24
+
25
+ export interface ISDKUserIdentityChanges {
26
+ New: ISDKUserIdentityChangeData;
27
+ Old: ISDKUserIdentityChangeData;
28
+ }
29
+
30
+ export interface ISDKUserIdentityChangeData {
31
+ IdentityType: SDKIdentityTypeEnum;
32
+ Identity: string;
33
+ CreatedThisBatch: boolean;
34
+ // https://go.mparticle.com/work/SQDSDKS-6438
35
+ Timestamp?: number;
36
+ }
37
+
38
+ export interface IUserIdentityChangeEvent extends BaseEvent {
39
+ messageType: MessageType.UserIdentityChange;
40
+ userIdentityChanges: ISDKUserIdentityChanges;
41
+ }
42
+
43
+ export interface ISDKUserAttributeChangeData {
44
+ UserAttributeName: string;
45
+ New: string;
46
+ Old: string;
47
+ Deleted: boolean;
48
+ IsNewAttribute: boolean;
49
+ }
50
+
51
+ export interface IUserAttributeChangeEvent extends BaseEvent {
52
+ messageType: MessageType.UserAttributeChange;
53
+ userAttributeChanges: ISDKUserAttributeChangeData;
54
+ }
55
+
56
+ export interface mParticleUserCart {
57
+ add(product: Product, logEvent: boolean): void;
58
+ remove(product: Product, logEvent: boolean): void;
59
+ clear(): void;
60
+ getCartProducts(): Product[];
61
+ }
62
+
63
+ // https://go.mparticle.com/work/SQDSDKS-5196
64
+ export type UserAttributes = AllUserAttributes;
@@ -3,7 +3,7 @@ import { Dictionary, parseNumber, isObject, generateHash } from './utils';
3
3
  import { BaseVault } from './vault';
4
4
  import Types from './types';
5
5
  import { IdentityApiData, UserIdentities, IdentityCallback } from '@mparticle/web-sdk';
6
- import { IdentityAPIMethod, MParticleWebSDK } from './sdkRuntimeModels';
6
+ import { IdentityAPIMethod } from './identity.interfaces';
7
7
 
8
8
  const { Identify, Modify, Login, Logout } = Constants.IdentityMethods;
9
9
 
@@ -0,0 +1,205 @@
1
+ import {
2
+ IdentityApiData,
3
+ IdentityCallback,
4
+ MPID,
5
+ UserIdentities,
6
+ } from '@mparticle/web-sdk';
7
+ import AudienceManager from './audienceManager';
8
+ import { ICachedIdentityCall, IKnownIdentities } from './identity-utils';
9
+ import { BaseVault } from './vault';
10
+ import { Dictionary, Environment, valueof } from './utils';
11
+ import Constants from './constants';
12
+ import {
13
+ IUserAttributeChangeEvent,
14
+ IUserIdentityChangeEvent,
15
+ IMParticleUser,
16
+ mParticleUserCart,
17
+ } from './identity-user-interfaces';
18
+ const { platform, sdkVendor, sdkVersion, HTTPCodes } = Constants;
19
+
20
+ export type IdentityPreProcessResult = {
21
+ valid: boolean;
22
+ error?: string;
23
+ };
24
+
25
+ export type IdentityAPIMethod = valueof<typeof Constants.IdentityMethods>;
26
+
27
+ export enum SDKIdentityTypeEnum {
28
+ other = 'other',
29
+ customerId = 'customerid',
30
+ facebook = 'facebook',
31
+ twitter = 'twitter',
32
+ google = 'google',
33
+ microsoft = 'microsoft',
34
+ yahoo = 'yahoo',
35
+ email = 'email',
36
+ alias = 'alias',
37
+ facebookCustomAudienceId = 'facebookcustomaudienceid',
38
+ otherId2 = 'other2',
39
+ otherId3 = 'other3',
40
+ otherId4 = 'other4',
41
+ otherId5 = 'other5',
42
+ otherId6 = 'other6',
43
+ otherId7 = 'other7',
44
+ otherId8 = 'other8',
45
+ otherId9 = 'other9',
46
+ otherId10 = 'other10',
47
+ mobileNumber = 'mobile_number',
48
+ phoneNumber2 = 'phone_number_2',
49
+ phoneNumber3 = 'phone_number_3',
50
+ }
51
+
52
+ export interface IIdentityAPIRequestData {
53
+ client_sdk: {
54
+ platform: typeof platform;
55
+ sdk_vendor: typeof sdkVendor;
56
+ sdk_version: typeof sdkVersion;
57
+ };
58
+ context: string | null;
59
+ environment: Environment;
60
+ request_id: string;
61
+ reqest_timestamp_unixtime_ms: number;
62
+ previous_mpid: MPID | null;
63
+ known_identities: IKnownIdentities;
64
+ }
65
+
66
+ export interface IIdentityAPIModifyRequestData
67
+ extends Omit<
68
+ IIdentityAPIRequestData,
69
+ 'known_identities' | 'previous_mpid'
70
+ > {
71
+ identity_changes: IIdentityAPIIdentityChangeData[];
72
+ }
73
+
74
+ export interface IIdentityAPIIdentityChangeData {
75
+ identity_type: SDKIdentityTypeEnum;
76
+ old_value: string;
77
+ new_value: string;
78
+ }
79
+
80
+ export interface IIdentityRequest {
81
+ createIdentityRequest(
82
+ identityApiData: IdentityApiData,
83
+ platform: string,
84
+ sdkVendor: string,
85
+ sdkVersion: string,
86
+ deviceId: string,
87
+ context: string | null,
88
+ mpid: MPID
89
+ ): IIdentityAPIRequestData;
90
+ createModifyIdentityRequest(
91
+ currentUserIdentities: UserIdentities,
92
+ newUserIdentities: UserIdentities,
93
+ platform: string,
94
+ sdkVendor: string,
95
+ sdkVersion: string,
96
+ context: string | null
97
+ ): IIdentityAPIModifyRequestData;
98
+ createIdentityChanges(
99
+ previousIdentities: UserIdentities,
100
+ newIdentitie: UserIdentities
101
+ ): IIdentityAPIIdentityChangeData;
102
+ preProcessIdentityRequest(
103
+ identityApiData: IdentityApiData,
104
+ callback: IdentityCallback,
105
+ method: IdentityAPIMethod
106
+ ): IdentityPreProcessResult;
107
+ }
108
+
109
+ export interface IAliasRequest {
110
+ destinationMpid: MPID;
111
+ sourceMpid: MPID;
112
+ startTime: number;
113
+ endTime: number;
114
+ scope?: string;
115
+ }
116
+
117
+ export interface SDKIdentityApi {
118
+ HTTPCodes: typeof HTTPCodes;
119
+ identify?(
120
+ identityApiData?: IdentityApiData,
121
+ callback?: IdentityCallback
122
+ ): void;
123
+ login?(
124
+ identityApiData?: IdentityApiData,
125
+ callback?: IdentityCallback
126
+ ): void;
127
+ logout?(
128
+ identityApiData?: IdentityApiData,
129
+ callback?: IdentityCallback
130
+ ): void;
131
+ modify?(
132
+ identityApiData?: IdentityApiData,
133
+ callback?: IdentityCallback
134
+ ): void;
135
+ getCurrentUser?(): IMParticleUser;
136
+ getUser?(mpid: string): IMParticleUser;
137
+ getUsers?(): IMParticleUser[];
138
+ aliasUsers?(
139
+ aliasRequest?: IAliasRequest,
140
+ callback?: IdentityCallback
141
+ ): void;
142
+ createAliasRequest?(
143
+ sourceUser: IMParticleUser,
144
+ destinationUser: IMParticleUser
145
+ ): IAliasRequest;
146
+ }
147
+
148
+ export interface IIdentity {
149
+ audienceManager: AudienceManager;
150
+ idCache: BaseVault<Dictionary<ICachedIdentityCall>>;
151
+
152
+ IdentityAPI: SDKIdentityApi;
153
+ IdentityRequest: IIdentityRequest;
154
+
155
+ mParticleUser(mpid: MPID, IsLoggedIn: boolean): IMParticleUser;
156
+
157
+ checkIdentitySwap(
158
+ previousMPID: MPID,
159
+ currentMPID: MPID,
160
+ currentSessionMPIDs?: MPID[]
161
+ ): void;
162
+ createUserAttributeChange(
163
+ key: string,
164
+ newValue: string,
165
+ previousUserAttributeValue: string,
166
+ isNewAttribute: boolean,
167
+ deleted: boolean,
168
+ user: IMParticleUser
169
+ ): IUserAttributeChangeEvent;
170
+ createUserIdentityChange(
171
+ identityType: SDKIdentityTypeEnum,
172
+ newIdentity: string,
173
+ oldIdentity: string,
174
+ newCreatedThisBatch: boolean,
175
+ userInMemory: IMParticleUser
176
+ ): IUserIdentityChangeEvent;
177
+ parseIdentityResponse(
178
+ xhr: XMLHttpRequest,
179
+ previousMPID: MPID,
180
+ callback: IdentityCallback,
181
+ identityApiData: IdentityApiData,
182
+ method: IdentityAPIMethod,
183
+ knownIdentities: UserIdentities,
184
+ parsingCachedResponse: boolean
185
+ ): void;
186
+ sendUserAttributeChangeEvent(
187
+ attributeKey: string,
188
+ newUserAttributeValue: string,
189
+ previousUserAttributeValue: string,
190
+ isNewAttribute: boolean,
191
+ deleted: boolean,
192
+ user: IMParticleUser
193
+ ): void;
194
+ sendUserIdentityChangeEvent(
195
+ newUserIdentities: UserIdentities,
196
+ method: IdentityAPIMethod,
197
+ mpid: MPID,
198
+ prevUserIdentities: UserIdentities
199
+ ): void;
200
+
201
+ /**
202
+ * @deprecated
203
+ */
204
+ mParticleUserCart(mpid: MPID): mParticleUserCart;
205
+ }