Skip to content

Commit 5a60fce

Browse files
Jaissica HoraJaissica Hora
authored andcommitted
feat: added DisabledVault to disable id cache when noFunctional is set
1 parent 848ae7c commit 5a60fce

2 files changed

Lines changed: 30 additions & 4 deletions

File tree

src/mp-instance.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import KitBlocker from './kitBlocking';
3737
import ConfigAPIClient, { IKitConfigs } from './configAPIClient';
3838
import IdentityAPIClient from './identityApiClient';
3939
import { isFunction, parseConfig } from './utils';
40-
import { LocalStorageVault } from './vault';
40+
import { DisabledVault, LocalStorageVault } from './vault';
4141
import { removeExpiredIdentityCacheDates } from './identity-utils';
4242
import IntegrationCapture from './integrationCapture';
4343
import { IPreInit, processReadyQueue } from './pre-init-utils';
@@ -1522,9 +1522,11 @@ function createKitBlocker(config, mpInstance) {
15221522
}
15231523

15241524
function createIdentityCache(mpInstance) {
1525-
return new LocalStorageVault(`${mpInstance._Store.storageName}-id-cache`, {
1526-
logger: mpInstance.Logger,
1527-
});
1525+
const cacheKey = `${mpInstance._Store.storageName}-id-cache`;
1526+
if (mpInstance._Store.getNoFunctional()) {
1527+
return new DisabledVault(cacheKey, { logger: mpInstance.Logger });
1528+
}
1529+
return new LocalStorageVault(cacheKey, { logger: mpInstance.Logger });
15281530
}
15291531

15301532
function runPreConfigFetchInitialization(mpInstance, apiKey, config) {

src/vault.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,28 @@ export class SessionStorageVault<StorableItem> extends BaseVault<StorableItem> {
102102
constructor(storageKey: string, options?: IVaultOptions) {
103103
super(storageKey, window.sessionStorage, options);
104104
}
105+
}
106+
107+
// DisabledVault is used when persistence is disabled by privacy flags.
108+
export class DisabledVault<StorableItem> extends BaseVault<StorableItem> {
109+
constructor(storageKey: string, options?: IVaultOptions) {
110+
super(storageKey, window.localStorage, options);
111+
this.contents = null;
112+
}
113+
114+
public store(_item: StorableItem): void {
115+
this.contents = null;
116+
}
117+
118+
public retrieve(): StorableItem | null {
119+
this.contents = null;
120+
return null;
121+
}
122+
123+
public purge(): void {
124+
this.contents = null;
125+
try {
126+
window.localStorage.removeItem(this._storageKey);
127+
} catch {}
128+
}
105129
}

0 commit comments

Comments
 (0)