Skip to content

Commit e7ad62e

Browse files
committed
chore: revert to offlineStorageEnabled and update StorageTypes
1 parent 57823b6 commit e7ad62e

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
{
@@ -262,7 +262,7 @@ export class BatchUploader {
262262
const { verbose } = this.mpInstance.Logger;
263263

264264
this.eventsQueuedForProcessing.push(event);
265-
if (this.OfflineStorage && this.eventVault) {
265+
if (this.offlineStorageEnabled && this.eventVault) {
266266
this.eventVault.store(this.eventsQueuedForProcessing);
267267
}
268268

@@ -378,7 +378,7 @@ export class BatchUploader {
378378
const currentEvents: SDKEvent[] = this.eventsQueuedForProcessing;
379379

380380
this.eventsQueuedForProcessing = [];
381-
if (this.OfflineStorage && this.eventVault) {
381+
if (this.offlineStorageEnabled && this.eventVault) {
382382
this.eventVault.store([]);
383383
}
384384

@@ -392,7 +392,7 @@ export class BatchUploader {
392392
}
393393

394394
// Top Load any older Batches from Offline Storage so they go out first
395-
if (this.OfflineStorage && this.batchVault) {
395+
if (this.offlineStorageEnabled && this.batchVault) {
396396
this.batchesQueuedForProcessing.unshift(
397397
...this.batchVault.retrieve()
398398
);
@@ -425,7 +425,7 @@ export class BatchUploader {
425425
}
426426

427427
// Update Offline Storage with current state of batch queue
428-
if (!useBeacon && this.OfflineStorage && this.batchVault) {
428+
if (!useBeacon && this.offlineStorageEnabled && this.batchVault) {
429429
// Note: since beacon is "Fire and forget" it will empty `batchesThatDidNotUplod`
430430
// regardless of whether the batches were successfully uploaded or not. We should
431431
// 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
@@ -233,13 +233,12 @@ export const HTTP_SERVER_ERROR = 500 as const;
233233
// Privacy dependency map for storage keys
234234
export type PrivacyControl = 'functional' | 'targeting';
235235

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

238238
export const StoragePrivacyMap: Record<StorageTypes, PrivacyControl> = {
239239
SDKState: 'functional',
240240
Products: 'targeting',
241-
Events: 'functional',
242-
Batches: 'functional',
243-
IdCache: 'functional',
241+
OfflineEvents: 'functional',
242+
IdentityCache: 'functional',
244243
TimeOnSite: 'targeting',
245244
};

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)