Skip to content

Commit 81da886

Browse files
committed
chore: revert to offlineStorageEnabled and update StorageTypes
1 parent b9b7d9a commit 81da886

3 files changed

Lines changed: 13 additions & 14 deletions

File tree

src/batchUploader.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export class BatchUploader {
4343
batchingEnabled: boolean;
4444
private eventVault: SessionStorageVault<SDKEvent[]>;
4545
private batchVault: LocalStorageVault<Batch[]>;
46-
private OfflineStorage: boolean = false;
46+
private offlineStorageEnabled: boolean = false;
4747
private uploader: AsyncUploader;
4848
private lastASTEventTime: number = 0;
4949
private readonly AST_DEBOUNCE_MS: number = 1000; // 1 second debounce
@@ -72,11 +72,11 @@ export class BatchUploader {
7272

7373
// Cache Offline Storage Availability boolean
7474
// so that we don't have to check it every time
75-
this.OfflineStorage =
75+
this.offlineStorageEnabled =
7676
this.isOfflineStorageAvailable() &&
77-
!mpInstance._Store.getPrivacyFlag('Events');
77+
!mpInstance._Store.getPrivacyFlag('OfflineEvents');
7878

79-
if (this.OfflineStorage) {
79+
if (this.offlineStorageEnabled) {
8080
this.eventVault = new SessionStorageVault<SDKEvent[]>(
8181
`${mpInstance._Store.storageName}-events`,
8282
{
@@ -259,7 +259,7 @@ export class BatchUploader {
259259
const { verbose } = this.mpInstance.Logger;
260260

261261
this.eventsQueuedForProcessing.push(event);
262-
if (this.OfflineStorage && this.eventVault) {
262+
if (this.offlineStorageEnabled && this.eventVault) {
263263
this.eventVault.store(this.eventsQueuedForProcessing);
264264
}
265265

@@ -375,7 +375,7 @@ export class BatchUploader {
375375
const currentEvents: SDKEvent[] = this.eventsQueuedForProcessing;
376376

377377
this.eventsQueuedForProcessing = [];
378-
if (this.OfflineStorage && this.eventVault) {
378+
if (this.offlineStorageEnabled && this.eventVault) {
379379
this.eventVault.store([]);
380380
}
381381

@@ -389,7 +389,7 @@ export class BatchUploader {
389389
}
390390

391391
// Top Load any older Batches from Offline Storage so they go out first
392-
if (this.OfflineStorage && this.batchVault) {
392+
if (this.offlineStorageEnabled && this.batchVault) {
393393
this.batchesQueuedForProcessing.unshift(
394394
...this.batchVault.retrieve()
395395
);
@@ -422,7 +422,7 @@ export class BatchUploader {
422422
}
423423

424424
// Update Offline Storage with current state of batch queue
425-
if (!useBeacon && this.OfflineStorage && this.batchVault) {
425+
if (!useBeacon && this.offlineStorageEnabled && this.batchVault) {
426426
// Note: since beacon is "Fire and forget" it will empty `batchesThatDidNotUplod`
427427
// regardless of whether the batches were successfully uploaded or not. We should
428428
// therefore NOT overwrite Offline Storage when beacon returns, so that we can retry

src/constants.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,13 +219,12 @@ export const HTTP_SERVER_ERROR = 500 as const;
219219
// Privacy dependency map for storage keys
220220
export type PrivacyControl = 'functional' | 'targeting';
221221

222-
export type StorageTypes = 'SDKState' | 'Products' | 'Events' | 'Batches' | 'IdCache' | 'TimeOnSite';
222+
export type StorageTypes = 'SDKState' | 'Products' | 'OfflineEvents' | 'IdentityCache' | 'TimeOnSite';
223223

224224
export const StoragePrivacyMap: Record<StorageTypes, PrivacyControl> = {
225225
SDKState: 'functional',
226226
Products: 'targeting',
227-
Events: 'functional',
228-
Batches: 'functional',
229-
IdCache: 'functional',
227+
OfflineEvents: 'functional',
228+
IdentityCache: 'functional',
230229
TimeOnSite: 'targeting',
231230
};

test/jest/batchUploader.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ describe('BatchUploader', () => {
141141
mockMPInstance._Store.noFunctional = true;
142142

143143
const uploader = new BatchUploader(mockMPInstance, 1000);
144-
expect(uploader['OfflineStorage']).toBe(false);
144+
expect(uploader['offlineStorageEnabled']).toBe(false);
145145

146146
uploader.queueEvent({ EventDataType: 4 } as any);
147147
expect(sessionStorage.getItem('mprtcl-v4_abcdef-events')).toBeNull();
@@ -151,7 +151,7 @@ describe('BatchUploader', () => {
151151
it('should enable offline storage when noFunctional is default (false)', async () => {
152152
const uploader = new BatchUploader(mockMPInstance, 1000);
153153

154-
expect(uploader['OfflineStorage']).toBe(true);
154+
expect(uploader['offlineStorageEnabled']).toBe(true);
155155

156156
uploader.queueEvent({ EventDataType: 4 } as any);
157157
expect(sessionStorage.getItem('mprtcl-v4_abcdef-events')).not.toBeNull();

0 commit comments

Comments
 (0)