@mparticle/web-sdk 2.42.0 → 2.43.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.
@@ -5,6 +5,7 @@ import Types from './types';
5
5
  import { generateDeprecationMessage } from './utils';
6
6
  import { IMParticleUser } from './identity-user-interfaces';
7
7
  import { IMParticleWebSDKInstance } from './mp-instance';
8
+ import { hasIdentityRequestChanged } from './identity-utils';
8
9
 
9
10
  const { Messages } = Constants;
10
11
 
@@ -30,7 +31,7 @@ export default function SessionManager(
30
31
  ) {
31
32
  const self = this;
32
33
 
33
- this.initialize = function(): void {
34
+ this.initialize = function (): void {
34
35
  if (mpInstance._Store.sessionId) {
35
36
  const sessionTimeoutInMilliseconds: number =
36
37
  mpInstance._Store.SDKConfig.sessionTimeout * 60000;
@@ -46,9 +47,14 @@ export default function SessionManager(
46
47
  self.startNewSession();
47
48
  } else {
48
49
  // https://go.mparticle.com/work/SQDSDKS-6045
49
- const persistence: IPersistenceMinified = mpInstance._Persistence.getPersistence();
50
- if (persistence && !persistence.cu) {
51
- // https://go.mparticle.com/work/SQDSDKS-6323
50
+ // https://go.mparticle.com/work/SQDSDKS-6323
51
+ const currentUser = mpInstance.Identity.getCurrentUser();
52
+ const sdkIdentityRequest =
53
+ mpInstance._Store.SDKConfig.identifyRequest;
54
+
55
+ if (
56
+ hasIdentityRequestChanged(currentUser, sdkIdentityRequest)
57
+ ) {
52
58
  mpInstance.Identity.identify(
53
59
  mpInstance._Store.SDKConfig.identifyRequest,
54
60
  mpInstance._Store.SDKConfig.identityCallback
@@ -62,7 +68,7 @@ export default function SessionManager(
62
68
  }
63
69
  };
64
70
 
65
- this.getSession = function(): string {
71
+ this.getSession = function (): string {
66
72
  mpInstance.Logger.warning(
67
73
  generateDeprecationMessage(
68
74
  'SessionManager.getSession()',
@@ -73,11 +79,11 @@ export default function SessionManager(
73
79
  return this.getSessionId();
74
80
  };
75
81
 
76
- this.getSessionId = function(): string {
82
+ this.getSessionId = function (): string {
77
83
  return mpInstance._Store.sessionId;
78
84
  };
79
85
 
80
- this.startNewSession = function(): void {
86
+ this.startNewSession = function (): void {
81
87
  mpInstance.Logger.verbose(
82
88
  Messages.InformationMessages.StartingNewSession
83
89
  );
@@ -87,7 +93,8 @@ export default function SessionManager(
87
93
  .generateUniqueId()
88
94
  .toUpperCase();
89
95
 
90
- const currentUser: IMParticleUser = mpInstance.Identity.getCurrentUser();
96
+ const currentUser: IMParticleUser =
97
+ mpInstance.Identity.getCurrentUser();
91
98
  const mpid: MPID = currentUser ? currentUser.getMPID() : null;
92
99
 
93
100
  if (mpid) {
@@ -121,7 +128,7 @@ export default function SessionManager(
121
128
  }
122
129
  };
123
130
 
124
- this.endSession = function(override: boolean): void {
131
+ this.endSession = function (override: boolean): void {
125
132
  mpInstance.Logger.verbose(
126
133
  Messages.InformationMessages.StartingEndSession
127
134
  );
@@ -152,9 +159,10 @@ export default function SessionManager(
152
159
  let sessionTimeoutInMilliseconds: number;
153
160
  let timeSinceLastEventSent: number;
154
161
 
155
- const cookies: IPersistenceMinified = mpInstance._Persistence.getPersistence();
162
+ const cookies: IPersistenceMinified =
163
+ mpInstance._Persistence.getPersistence();
156
164
 
157
- if (!cookies || cookies.gs && !cookies.gs.sid) {
165
+ if (!cookies || (cookies.gs && !cookies.gs.sid)) {
158
166
  mpInstance.Logger.verbose(
159
167
  Messages.InformationMessages.NoSessionToEnd
160
168
  );
@@ -189,16 +197,16 @@ export default function SessionManager(
189
197
  mpInstance._timeOnSiteTimer?.resetTimer();
190
198
  };
191
199
 
192
- this.setSessionTimer = function(): void {
200
+ this.setSessionTimer = function (): void {
193
201
  const sessionTimeoutInMilliseconds: number =
194
202
  mpInstance._Store.SDKConfig.sessionTimeout * 60000;
195
203
 
196
- mpInstance._Store.globalTimer = window.setTimeout(function() {
204
+ mpInstance._Store.globalTimer = window.setTimeout(function () {
197
205
  self.endSession();
198
206
  }, sessionTimeoutInMilliseconds);
199
207
  };
200
208
 
201
- this.resetSessionTimer = function(): void {
209
+ this.resetSessionTimer = function (): void {
202
210
  if (!mpInstance._Store.webviewBridgeEnabled) {
203
211
  if (!mpInstance._Store.sessionId) {
204
212
  self.startNewSession();
@@ -209,7 +217,7 @@ export default function SessionManager(
209
217
  self.startNewSessionIfNeeded();
210
218
  };
211
219
 
212
- this.clearSessionTimeout = function(): void {
220
+ this.clearSessionTimeout = function (): void {
213
221
  clearTimeout(mpInstance._Store.globalTimer);
214
222
  };
215
223
 
package/src/validators.ts CHANGED
@@ -40,7 +40,37 @@ const Validators = {
40
40
  );
41
41
  },
42
42
 
43
- validateIdentities: function(
43
+ removeFalsyIdentityValues: function (
44
+ identityApiData: IdentityApiData,
45
+ logger: any
46
+ ): IdentityApiData {
47
+ if (!identityApiData || !identityApiData.userIdentities) {
48
+ return identityApiData;
49
+ }
50
+
51
+ const cleanedData = {} as IdentityApiData;
52
+ const cleanedUserIdentities = { ...identityApiData.userIdentities };
53
+
54
+ for (const identityType in identityApiData.userIdentities) {
55
+ if (identityApiData.userIdentities.hasOwnProperty(identityType)) {
56
+ const value = identityApiData.userIdentities[identityType];
57
+
58
+ // Check if value is falsy (undefined, false, 0, '', etc.) but not null
59
+ if (value !== null && !value) {
60
+ logger.warning(
61
+ `Identity value for '${identityType}' is falsy (${value}). This value will be removed from the request.`
62
+ );
63
+ delete cleanedUserIdentities[identityType];
64
+ }
65
+ }
66
+ }
67
+
68
+ cleanedData.userIdentities = cleanedUserIdentities;
69
+
70
+ return cleanedData;
71
+ },
72
+
73
+ validateIdentities: function (
44
74
  identityApiData: IdentityApiData,
45
75
  method?: IdentityAPIMethod
46
76
  ): ValidationIdentitiesReturn {