@mparticle/web-sdk 2.34.0 → 2.35.1

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.
@@ -27,6 +27,7 @@ import {
27
27
  } from './consent';
28
28
  import { IMParticleUser, ISDKUserIdentity } from './identity-user-interfaces';
29
29
  import { IMParticleWebSDKInstance } from './mp-instance';
30
+ import { appendUserInfo } from './user-utils';
30
31
 
31
32
  const MessageType = Types.MessageType;
32
33
  const ApplicationTransitionType = Types.ApplicationTransitionType;
@@ -140,7 +141,6 @@ export interface IServerModel {
140
141
  convertEventToV2DTO: (event: IUploadObject) => IServerV2DTO;
141
142
  createEventObject: (event: BaseEvent, user?: IMParticleUser) => SDKEvent;
142
143
  convertToConsentStateV2DTO: (state: SDKConsentState) => IConsentStateV2DTO;
143
- appendUserInfo: (user: IMParticleUser, event: SDKEvent) => void;
144
144
  }
145
145
 
146
146
  // TODO: Make this a pure function that returns a new object
@@ -201,51 +201,6 @@ export default function ServerModel(
201
201
  ) {
202
202
  var self = this;
203
203
 
204
- // TODO: Can we refactor this to not mutate the event?
205
- this.appendUserInfo = function(
206
- user: IMParticleUser,
207
- event: SDKEvent
208
- ): void {
209
- if (!event) {
210
- return;
211
- }
212
- if (!user) {
213
- event.MPID = null;
214
- event.ConsentState = null;
215
- event.UserAttributes = null;
216
- event.UserIdentities = null;
217
- return;
218
- }
219
- if (event.MPID && event.MPID === user.getMPID()) {
220
- return;
221
- }
222
- event.MPID = user.getMPID();
223
- event.ConsentState = user.getConsentState();
224
- event.UserAttributes = user.getAllUserAttributes();
225
-
226
- var userIdentities = user.getUserIdentities().userIdentities;
227
- var dtoUserIdentities = {};
228
- for (var identityKey in userIdentities) {
229
- var identityType = Types.IdentityType.getIdentityType(identityKey);
230
- if (identityType !== false) {
231
- dtoUserIdentities[identityType] = userIdentities[identityKey];
232
- }
233
- }
234
-
235
- var validUserIdentities = [];
236
- if (mpInstance._Helpers.isObject(dtoUserIdentities)) {
237
- if (Object.keys(dtoUserIdentities).length) {
238
- for (var key in dtoUserIdentities) {
239
- var userIdentity: Partial<ISDKUserIdentity> = {};
240
- userIdentity.Identity = dtoUserIdentities[key];
241
- userIdentity.Type = mpInstance._Helpers.parseNumber(key);
242
- validUserIdentities.push(userIdentity);
243
- }
244
- }
245
- }
246
- event.UserIdentities = validUserIdentities;
247
- };
248
-
249
204
  this.convertToConsentStateV2DTO = function(
250
205
  state: SDKConsentState
251
206
  ): IConsentStateV2DTO {
@@ -397,7 +352,7 @@ export default function ServerModel(
397
352
  // FIXME: Remove duplicate occurence
398
353
  eventObject.CurrencyCode = mpInstance._Store.currencyCode;
399
354
  var currentUser = user || mpInstance.Identity.getCurrentUser();
400
- self.appendUserInfo(currentUser, eventObject as SDKEvent);
355
+ appendUserInfo(currentUser, eventObject as SDKEvent);
401
356
 
402
357
  if (event.messageType === Types.MessageType.SessionEnd) {
403
358
  eventObject.SessionLength =
package/src/store.ts CHANGED
@@ -30,7 +30,7 @@ import {
30
30
  returnConvertedBoolean,
31
31
  } from './utils';
32
32
  import { IMinifiedConsentJSONObject, SDKConsentState } from './consent';
33
- import { Kit, MPForwarder } from './forwarders.interfaces';
33
+ import { ConfiguredKit, MPForwarder, UnregisteredKit } from './forwarders.interfaces';
34
34
  import { IdentityCallback, UserAttributes } from './identity-user-interfaces';
35
35
  import {
36
36
  IGlobalStoreV2MinifiedKeys,
@@ -61,7 +61,7 @@ export interface SDKConfig {
61
61
  package?: string;
62
62
  flags?: IFeatureFlags;
63
63
  kitConfigs: IKitConfigs[];
64
- kits: Dictionary<Kit>;
64
+ kits: Dictionary<UnregisteredKit>;
65
65
  logLevel?: LogLevelType;
66
66
  cookieDomain?: string;
67
67
  maxCookieSize?: number | undefined;
@@ -138,6 +138,8 @@ export interface IFeatureFlags {
138
138
  offlineStorage?: string;
139
139
  directURLRouting?: boolean;
140
140
  cacheIdentity?: boolean;
141
+ captureIntegrationSpecificIds?: boolean;
142
+ astBackgroundEvents?: boolean;
141
143
  }
142
144
 
143
145
  // Temporary Interface until Store can be refactored as a class
@@ -176,7 +178,7 @@ export interface IStore {
176
178
  isLocalStorageAvailable: boolean | null;
177
179
  storageName: string | null;
178
180
  prodStorageName: string | null;
179
- activeForwarders: MPForwarder[];
181
+ activeForwarders: ConfiguredKit[];
180
182
  kits: Dictionary<MPForwarder>;
181
183
  sideloadedKits: MPForwarder[];
182
184
  configuredForwarders: MPForwarder[];
@@ -714,6 +716,7 @@ export function processFlags(config: SDKInitConfig): IFeatureFlags {
714
716
  CacheIdentity,
715
717
  AudienceAPI,
716
718
  CaptureIntegrationSpecificIds,
719
+ AstBackgroundEvents
717
720
  } = Constants.FeatureFlags;
718
721
 
719
722
  if (!config.flags) {
@@ -732,6 +735,7 @@ export function processFlags(config: SDKInitConfig): IFeatureFlags {
732
735
  flags[CacheIdentity] = config.flags[CacheIdentity] === 'True';
733
736
  flags[AudienceAPI] = config.flags[AudienceAPI] === 'True';
734
737
  flags[CaptureIntegrationSpecificIds] = config.flags[CaptureIntegrationSpecificIds] === 'True';
738
+ flags[AstBackgroundEvents] = config.flags[AstBackgroundEvents] === 'True';
735
739
 
736
740
  return flags;
737
741
  }
package/src/user-utils.ts CHANGED
@@ -1,4 +1,8 @@
1
- import { IMParticleUser, IdentityResultBody } from './identity-user-interfaces';
1
+ import { UserIdentities } from '@mparticle/web-sdk';
2
+ import { IMParticleUser, ISDKUserIdentity, IdentityResultBody } from './identity-user-interfaces';
3
+ import { SDKEvent } from './sdkRuntimeModels';
4
+ import Types from './types';
5
+ import { isObject, parseNumber } from './utils';
2
6
 
3
7
  export function hasMPIDAndUserLoginChanged(
4
8
  previousUser: IMParticleUser,
@@ -23,3 +27,49 @@ export function hasMPIDChanged(
23
27
  identityApiResult.mpid !== prevUser.getMPID())
24
28
  );
25
29
  }
30
+
31
+ // https://go.mparticle.com/work/SQDSDKS-7136
32
+ export function appendUserInfo(
33
+ user: IMParticleUser,
34
+ event: SDKEvent
35
+ ): void {
36
+ if (!event) {
37
+ return;
38
+ }
39
+ if (!user) {
40
+ event.MPID = null;
41
+ event.ConsentState = null;
42
+ event.UserAttributes = null;
43
+ event.UserIdentities = null;
44
+ return;
45
+ }
46
+ if (event.MPID && event.MPID === user.getMPID()) {
47
+ return;
48
+ }
49
+
50
+ event.MPID = user.getMPID();
51
+ event.ConsentState = user.getConsentState();
52
+ event.UserAttributes = user.getAllUserAttributes();
53
+
54
+ const userIdentities: UserIdentities = user.getUserIdentities().userIdentities;
55
+ const dtoUserIdentities = {};
56
+ for (const identityKey in userIdentities) {
57
+ const identityType = Types.IdentityType.getIdentityType(identityKey);
58
+ if (identityType !== false) {
59
+ dtoUserIdentities[identityType] = userIdentities[identityKey];
60
+ }
61
+ }
62
+
63
+ const validUserIdentities: ISDKUserIdentity[] = [];
64
+ if (isObject(dtoUserIdentities)) {
65
+ if (Object.keys(dtoUserIdentities).length) {
66
+ for (const key in dtoUserIdentities) {
67
+ const userIdentity = {} as ISDKUserIdentity;
68
+ userIdentity.Identity = dtoUserIdentities[key];
69
+ userIdentity.Type = parseNumber(key);
70
+ validUserIdentities.push(userIdentity);
71
+ }
72
+ }
73
+ }
74
+ event.UserIdentities = validUserIdentities;
75
+ }