@@ -24,7 +24,7 @@ const defaultSerializedCache: JsonCache = {
24
24
/**
25
25
* In-memory token cache manager
26
26
*/
27
- export class CacheManager {
27
+ export class TokenCache {
28
28
29
29
private storage : Storage ;
30
30
private hasChanged : boolean ;
@@ -84,7 +84,6 @@ export class CacheManager {
84
84
async writeToPersistence ( ) : Promise < void > {
85
85
if ( this . persistence ) {
86
86
let cache = Serializer . serializeAllCache ( this . storage . getCache ( ) as InMemoryCache ) ;
87
-
88
87
const getMergedState = ( stateFromDisk : string ) => {
89
88
90
89
if ( ! StringUtils . isEmpty ( stateFromDisk ) ) {
@@ -144,13 +143,13 @@ export class CacheManager {
144
143
*/
145
144
private mergeUpdates ( oldState : any , newState : any ) : JsonCache {
146
145
147
- let finalState = oldState ;
148
- Object . keys ( newState ) . forEach ( ( newKey ) => {
146
+ let finalState = { ... oldState } ;
147
+ Object . keys ( newState ) . forEach ( ( newKey : string ) => {
149
148
let newValue = newState [ newKey ] ;
150
149
151
150
// if oldState does not contain value but newValue does, add it
152
151
if ( ! finalState . hasOwnProperty ( newKey ) ) {
153
- if ( newValue != null ) {
152
+ if ( newValue !== null ) {
154
153
finalState [ newKey ] = newValue ;
155
154
}
156
155
} else {
@@ -177,11 +176,11 @@ export class CacheManager {
177
176
* @param newState
178
177
*/
179
178
private mergeRemovals ( oldState : JsonCache , newState : JsonCache ) : JsonCache {
180
- const accounts = oldState . Account != null ? this . mergeRemovalsStringDict ( oldState . Account , newState . Account ) : oldState . Account ;
181
- const accessTokens = oldState . AccessToken != null ? this . mergeRemovalsStringDict ( oldState . AccessToken , newState . AccessToken ) : oldState . AccessToken ;
182
- const refreshTokens = oldState . RefreshToken != null ? this . mergeRemovalsStringDict ( oldState . RefreshToken , newState . RefreshToken ) : oldState . RefreshToken ;
183
- const idTokens = oldState . IdToken != null ? this . mergeRemovalsStringDict ( oldState . IdToken , newState . IdToken ) : oldState . IdToken ;
184
- const appMetadata = oldState . AppMetadata != null ? this . mergeRemovalsStringDict ( oldState . AppMetadata , newState . AppMetadata ) : oldState . AppMetadata ;
179
+ const accounts = oldState . Account !== null ? this . mergeRemovalsStringDict ( oldState . Account , newState . Account ) : oldState . Account ;
180
+ const accessTokens = oldState . AccessToken !== null ? this . mergeRemovalsStringDict ( oldState . AccessToken , newState . AccessToken ) : oldState . AccessToken ;
181
+ const refreshTokens = oldState . RefreshToken !== null ? this . mergeRemovalsStringDict ( oldState . RefreshToken , newState . RefreshToken ) : oldState . RefreshToken ;
182
+ const idTokens = oldState . IdToken !== null ? this . mergeRemovalsStringDict ( oldState . IdToken , newState . IdToken ) : oldState . IdToken ;
183
+ const appMetadata = oldState . AppMetadata !== null ? this . mergeRemovalsStringDict ( oldState . AppMetadata , newState . AppMetadata ) : oldState . AppMetadata ;
185
184
186
185
return {
187
186
Account : accounts ,
@@ -192,14 +191,14 @@ export class CacheManager {
192
191
}
193
192
}
194
193
195
- private mergeRemovalsStringDict ( oldAccounts : StringDict , newAccounts ?: StringDict ) : StringDict {
196
- let finalAccounts = oldAccounts ;
197
- Object . keys ( oldAccounts ) . forEach ( ( oldKey ) => {
198
- if ( ! newAccounts || ! ( newAccounts . hasOwnProperty ( oldKey ) ) ) {
199
- delete finalAccounts [ oldKey ] ;
194
+ private mergeRemovalsStringDict ( oldState : StringDict , newState ?: StringDict ) : StringDict {
195
+ let finalState = { ... oldState } ;
196
+ Object . keys ( oldState ) . forEach ( ( oldKey ) => {
197
+ if ( ! newState || ! ( newState . hasOwnProperty ( oldKey ) ) ) {
198
+ delete finalState [ oldKey ] ;
200
199
}
201
200
} ) ;
202
- return finalAccounts ;
201
+ return finalState ;
203
202
}
204
203
205
204
private overlayDefaults ( passedInCache : JsonCache ) : JsonCache {
0 commit comments