@@ -17,8 +17,6 @@ export default function _Persistence(
1717 this : IPersistence ,
1818 mpInstance : IMParticleWebSDKInstance
1919) : void {
20- const self = this ;
21-
2220 // https://go.mparticle.com/work/SQDSDKS-5022
2321 this . useLocalStorage = function ( ) : boolean {
2422 return (
@@ -30,8 +28,8 @@ export default function _Persistence(
3028 this . initializeStorage = function ( ) : void {
3129 try {
3230 let storage : Storage ,
33- localStorageData = self . getLocalStorage ( ) ,
34- cookies = self . getCookie ( ) ,
31+ localStorageData = this . getLocalStorage ( ) ,
32+ cookies = this . getCookie ( ) ,
3533 allData : IPersistenceMinified ;
3634
3735 // https://go.mparticle.com/work/SQDSDKS-6045
@@ -69,7 +67,7 @@ export default function _Persistence(
6967 } else if ( cookies ) {
7068 allData = cookies ;
7169 }
72- self . storeDataInMemory ( allData ) ;
70+ this . storeDataInMemory ( allData ) ;
7371 } else {
7472 // For migrating from cookie to localStorage -- If an instance is newly switching from cookies to localStorage, then
7573 // no mParticle localStorage exists yet and there are cookies. Get the cookies, set them to localStorage, then delete the cookies.
@@ -84,14 +82,14 @@ export default function _Persistence(
8482 } else {
8583 allData = cookies ;
8684 }
87- self . storeDataInMemory ( allData ) ;
88- self . expireCookies ( mpInstance . _Store . storageName ) ;
85+ this . storeDataInMemory ( allData ) ;
86+ this . expireCookies ( mpInstance . _Store . storageName ) ;
8987 } else {
90- self . storeDataInMemory ( localStorageData ) ;
88+ this . storeDataInMemory ( localStorageData ) ;
9189 }
9290 }
9391 } else {
94- self . storeDataInMemory ( cookies ) ;
92+ this . storeDataInMemory ( cookies ) ;
9593 }
9694
9795 // https://go.mparticle.com/work/SQDSDKS-6046
@@ -104,17 +102,17 @@ export default function _Persistence(
104102 }
105103 }
106104 }
107- self . update ( ) ;
105+ this . update ( ) ;
108106 } catch ( e ) {
109107 // If cookies or local storage is corrupt, we want to remove it
110108 // so that in the future, initializeStorage will work
111109 if (
112- self . useLocalStorage ( ) &&
110+ this . useLocalStorage ( ) &&
113111 mpInstance . _Store . isLocalStorageAvailable
114112 ) {
115113 localStorage . removeItem ( mpInstance . _Store . storageName ) ;
116114 } else {
117- self . expireCookies ( mpInstance . _Store . storageName ) ;
115+ this . expireCookies ( mpInstance . _Store . storageName ) ;
118116 }
119117 mpInstance . Logger . error ( 'Error initializing storage: ' + e ) ;
120118 }
@@ -123,10 +121,10 @@ export default function _Persistence(
123121 this . update = function ( ) : void {
124122 if ( ! mpInstance . _Store . webviewBridgeEnabled ) {
125123 if ( mpInstance . _Store . SDKConfig . useCookieStorage ) {
126- self . setCookie ( ) ;
124+ this . setCookie ( ) ;
127125 }
128126
129- self . setLocalStorage ( ) ;
127+ this . setLocalStorage ( ) ;
130128 }
131129 } ;
132130
@@ -249,7 +247,7 @@ export default function _Persistence(
249247 }
250248
251249 const key = mpInstance . _Store . storageName ;
252- let localStorageData = self . getLocalStorage ( ) || ( { } as IPersistenceMinified ) ;
250+ let localStorageData = this . getLocalStorage ( ) || ( { } as IPersistenceMinified ) ;
253251 const currentUser = mpInstance . Identity . getCurrentUser ( ) ;
254252 const mpid = currentUser ? currentUser . getMPID ( ) : null ;
255253 if ( ! mpInstance . _Store . SDKConfig . useCookieStorage ) {
@@ -281,7 +279,7 @@ export default function _Persistence(
281279 try {
282280 window . localStorage . setItem (
283281 encodeURIComponent ( key ) ,
284- self . encodePersistence ( JSON . stringify ( localStorageData ) )
282+ this . encodePersistence ( JSON . stringify ( localStorageData ) )
285283 ) ;
286284 } catch ( e ) {
287285 mpInstance . Logger . error (
@@ -322,7 +320,7 @@ export default function _Persistence(
322320 }
323321
324322 const key = mpInstance . _Store . storageName ;
325- const localStorageString = self . decodePersistence (
323+ const localStorageString = this . decodePersistence (
326324 window . localStorage . getItem ( key )
327325 ) ;
328326 const obj : Dictionary = { } ;
@@ -353,7 +351,7 @@ export default function _Persistence(
353351 let domain : string ;
354352 let cookieDomain : string ;
355353
356- cookieDomain = self . getCookieDomain ( ) ;
354+ cookieDomain = this . getCookieDomain ( ) ;
357355
358356 if ( cookieDomain === '' ) {
359357 domain = '' ;
@@ -408,7 +406,7 @@ export default function _Persistence(
408406
409407 if ( result ) {
410408 mpInstance . Logger . verbose ( Messages . InformationMessages . CookieFound ) ;
411- return JSON . parse ( self . decodePersistence ( result as string ) ) ;
409+ return JSON . parse ( this . decodePersistence ( result as string ) ) ;
412410 } else {
413411 return null ;
414412 }
@@ -429,7 +427,7 @@ export default function _Persistence(
429427 }
430428 const date = new Date ( ) ;
431429 const key = mpInstance . _Store . storageName ;
432- let cookies = self . getCookie ( ) || ( { } as IPersistenceMinified ) ;
430+ let cookies = this . getCookie ( ) || ( { } as IPersistenceMinified ) ;
433431 const expires = new Date (
434432 date . getTime ( ) +
435433 ( mpInstance . _Store . SDKConfig as Dictionary ) . cookieExpiration *
@@ -442,7 +440,7 @@ export default function _Persistence(
442440 let domain : string ;
443441 let encodedCookiesWithExpirationAndPath : string ;
444442
445- cookieDomain = self . getCookieDomain ( ) ;
443+ cookieDomain = this . getCookieDomain ( ) ;
446444
447445 if ( cookieDomain === '' ) {
448446 domain = '' ;
@@ -473,7 +471,7 @@ export default function _Persistence(
473471 mpInstance . _Store . nonCurrentUserMPIDs = { } ;
474472 }
475473
476- encodedCookiesWithExpirationAndPath = self . reduceAndEncodePersistence (
474+ encodedCookiesWithExpirationAndPath = this . reduceAndEncodePersistence (
477475 cookies ,
478476 expires ,
479477 domain ,
@@ -596,19 +594,19 @@ export default function _Persistence(
596594 return encodedCookiesWithExpirationAndPath ;
597595 } ;
598596
599- function createFullEncodedCookie (
597+ const createFullEncodedCookie = (
600598 persistence : IPersistenceMinified ,
601599 expires : string ,
602600 domain : string
603- ) : string {
601+ ) : string => {
604602 return (
605- self . encodePersistence ( JSON . stringify ( persistence ) ) +
603+ this . encodePersistence ( JSON . stringify ( persistence ) ) +
606604 ';expires=' +
607605 expires +
608606 ';path=/' +
609607 domain
610608 ) ;
611- }
609+ } ;
612610
613611 this . findPrevCookiesBasedOnUI = function (
614612 identityApiData : IdentityApiData
@@ -642,7 +640,7 @@ export default function _Persistence(
642640 }
643641
644642 if ( matchedUser ) {
645- self . storeDataInMemory ( persistence , matchedUser ) ;
643+ this . storeDataInMemory ( persistence , matchedUser ) ;
646644 }
647645 } ;
648646
@@ -767,7 +765,7 @@ export default function _Persistence(
767765 if ( mpInstance . _Store . SDKConfig . cookieDomain ) {
768766 return mpInstance . _Store . SDKConfig . cookieDomain ;
769767 } else {
770- const rootDomain = self . getDomain ( document , location . hostname ) ;
768+ const rootDomain = this . getDomain ( document , location . hostname ) ;
771769 if ( rootDomain === '' ) {
772770 return '' ;
773771 } else {
@@ -808,7 +806,7 @@ export default function _Persistence(
808806 csd : CookieSyncDates
809807 ) : void {
810808 if ( csd ) {
811- const persistence = self . getPersistence ( ) ;
809+ const persistence = this . getPersistence ( ) ;
812810 if ( persistence ) {
813811 if ( persistence [ mpid ] ) {
814812 persistence [ mpid ] . csd = csd ;
@@ -818,7 +816,7 @@ export default function _Persistence(
818816 } ;
819817 }
820818 }
821- self . savePersistence ( persistence ) ;
819+ this . savePersistence ( persistence ) ;
822820 }
823821 } ;
824822
@@ -828,11 +826,11 @@ export default function _Persistence(
828826 currentSessionMPIDs : MPID [ ]
829827 ) : void {
830828 if ( previousMPID && currentMPID && previousMPID !== currentMPID ) {
831- const persistence = self . getPersistence ( ) ;
829+ const persistence = this . getPersistence ( ) ;
832830 if ( persistence ) {
833831 persistence . cu = currentMPID ;
834832 persistence . gs . csm = currentSessionMPIDs ;
835- self . savePersistence ( persistence ) ;
833+ this . savePersistence ( persistence ) ;
836834 }
837835 }
838836 } ;
@@ -846,7 +844,7 @@ export default function _Persistence(
846844 return ;
847845 }
848846
849- const encodedPersistence = self . encodePersistence (
847+ const encodedPersistence = this . encodePersistence (
850848 JSON . stringify ( persistence )
851849 ) ;
852850 const date = new Date ( ) ;
@@ -859,7 +857,7 @@ export default function _Persistence(
859857 60 *
860858 1000
861859 ) . toUTCString ( ) ;
862- const cookieDomain = self . getCookieDomain ( ) ;
860+ const cookieDomain = this . getCookieDomain ( ) ;
863861 let domain : string ;
864862
865863 if ( cookieDomain === '' ) {
@@ -869,7 +867,7 @@ export default function _Persistence(
869867 }
870868
871869 if ( mpInstance . _Store . SDKConfig . useCookieStorage ) {
872- const encodedCookiesWithExpirationAndPath = self . reduceAndEncodePersistence (
870+ const encodedCookiesWithExpirationAndPath = this . reduceAndEncodePersistence (
873871 persistence ,
874872 expires ,
875873 domain ,
@@ -901,7 +899,7 @@ export default function _Persistence(
901899 if ( ! mpid ) {
902900 return null ;
903901 }
904- const persistence = self . getPersistence ( ) ;
902+ const persistence = this . getPersistence ( ) ;
905903 if ( persistence && persistence [ mpid ] && persistence [ mpid ] . fst ) {
906904 return persistence [ mpid ] . fst ;
907905 } else {
@@ -921,14 +919,14 @@ export default function _Persistence(
921919 if ( ! time ) {
922920 time = new Date ( ) . getTime ( ) ;
923921 }
924- const persistence = self . getPersistence ( ) ;
922+ const persistence = this . getPersistence ( ) ;
925923 if ( persistence ) {
926924 if ( ! persistence [ mpid ] ) {
927925 persistence [ mpid ] = { } ;
928926 }
929927 if ( ! persistence [ mpid ] . fst ) {
930928 persistence [ mpid ] . fst = time ;
931- self . savePersistence ( persistence ) ;
929+ this . savePersistence ( persistence ) ;
932930 }
933931 }
934932 } ;
@@ -946,7 +944,7 @@ export default function _Persistence(
946944 //if the mpid is the current user, its last seen time is the current time
947945 return new Date ( ) . getTime ( ) ;
948946 } else {
949- const persistence = self . getPersistence ( ) ;
947+ const persistence = this . getPersistence ( ) ;
950948 if ( persistence && persistence [ mpid ] && persistence [ mpid ] . lst ) {
951949 return persistence [ mpid ] . lst ;
952950 }
@@ -962,10 +960,10 @@ export default function _Persistence(
962960 if ( ! time ) {
963961 time = new Date ( ) . getTime ( ) ;
964962 }
965- const persistence = self . getPersistence ( ) ;
963+ const persistence = this . getPersistence ( ) ;
966964 if ( persistence && persistence [ mpid ] ) {
967965 persistence [ mpid ] . lst = time ;
968- self . savePersistence ( persistence ) ;
966+ this . savePersistence ( persistence ) ;
969967 }
970968 } ;
971969
@@ -975,24 +973,24 @@ export default function _Persistence(
975973
976974 this . setDeviceId = function ( guid : string ) : void {
977975 mpInstance . _Store . deviceId = guid ;
978- self . update ( ) ;
976+ this . update ( ) ;
979977 } ;
980978
981979 this . resetPersistence = function ( ) : void {
982980 localStorage . clear ( ) ;
983981
984- self . expireCookies ( StorageNames . cookieName ) ;
985- self . expireCookies ( StorageNames . cookieNameV2 ) ;
986- self . expireCookies ( StorageNames . cookieNameV3 ) ;
987- self . expireCookies ( StorageNames . cookieNameV4 ) ;
988- self . expireCookies ( mpInstance . _Store . storageName ) ;
982+ this . expireCookies ( StorageNames . cookieName ) ;
983+ this . expireCookies ( StorageNames . cookieNameV2 ) ;
984+ this . expireCookies ( StorageNames . cookieNameV3 ) ;
985+ this . expireCookies ( StorageNames . cookieNameV4 ) ;
986+ this . expireCookies ( mpInstance . _Store . storageName ) ;
989987
990988 if ( ( window . mParticle as Dictionary ) ?. _isTestEnv ) {
991989 const testWorkspaceToken = 'abcdef' ;
992990 removeLocalStorage (
993991 mpInstance . _Helpers . createMainStorageName ( testWorkspaceToken )
994992 ) ;
995- self . expireCookies (
993+ this . expireCookies (
996994 mpInstance . _Helpers . createMainStorageName ( testWorkspaceToken )
997995 ) ;
998996 }
0 commit comments