Skip to content

Commit 9fff9b8

Browse files
committed
remove offline event storage dependency on noFunctional privacy flag
1 parent 53edb66 commit 9fff9b8

File tree

4 files changed

+4
-166
lines changed

4 files changed

+4
-166
lines changed

src/batchUploader.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,7 @@ export class BatchUploader {
7272

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

7977
if (this.offlineStorageEnabled) {
8078
this.eventVault = new SessionStorageVault<SDKEvent[]>(

src/constants.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,9 @@ export const HTTP_SERVER_ERROR = 500 as const;
236236

237237
export type PrivacyControl = 'functional' | 'targeting';
238238

239-
export type StorageTypes = 'SDKState' | 'OfflineEvents' | 'TimeOnSite';
239+
export type StorageTypes = 'SDKState' | 'TimeOnSite';
240240

241241
export const StoragePrivacyMap: Record<StorageTypes, PrivacyControl> = {
242242
SDKState: 'functional',
243-
OfflineEvents: 'functional',
244243
TimeOnSite: 'targeting',
245244
};

test/jest/batchUploader.spec.ts

Lines changed: 2 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import { BatchUploader } from '../../src/batchUploader';
22
import { IMParticleWebSDKInstance } from '../../src/mp-instance';
3-
import { IStore } from '../../src/store';
4-
import { StoragePrivacyMap, StorageTypes } from '../../src/constants';
5-
import { SDKEvent } from '../../src/sdkRuntimeModels';
63

74
describe('BatchUploader', () => {
85
let batchUploader: BatchUploader;
@@ -21,39 +18,18 @@ describe('BatchUploader', () => {
2118
// Create a mock mParticle instance with mocked methods for instantiating a BatchUploader
2219
mockMPInstance = {
2320
_Store: {
24-
storageName: 'mprtcl-v4_abcdef',
25-
getNoFunctional: function(this: IStore) { return this.noFunctional; },
26-
getNoTargeting: function(this: IStore) { return this.noTargeting; },
27-
getPrivacyFlag: function(this: IStore, storageType: StorageTypes) {
28-
const privacyControl = StoragePrivacyMap[storageType];
29-
if (privacyControl === 'functional') {
30-
return this.getNoFunctional();
31-
}
32-
if (privacyControl === 'targeting') {
33-
return this.getNoTargeting();
34-
}
35-
return false;
36-
},
37-
deviceId: 'device-1',
3821
SDKConfig: {
3922
flags: {}
4023
}
4124
},
4225
_Helpers: {
43-
getFeatureFlag: jest.fn().mockReturnValue('100'),
26+
getFeatureFlag: jest.fn().mockReturnValue(false),
4427
createServiceUrl: jest.fn().mockReturnValue('https://mock-url.com'),
45-
generateUniqueId: jest.fn().mockReturnValue('req-1'),
4628
},
4729
Identity: {
4830
getCurrentUser: jest.fn().mockReturnValue({
49-
getMPID: () => 'test-mpid',
50-
getConsentState: jest.fn().mockReturnValue(null),
31+
getMPID: () => 'test-mpid'
5132
})
52-
},
53-
Logger: {
54-
verbose: jest.fn(),
55-
error: jest.fn(),
56-
warning: jest.fn(),
5733
}
5834
} as unknown as IMParticleWebSDKInstance;
5935

@@ -132,50 +108,4 @@ describe('BatchUploader', () => {
132108
expect(secondCallTime).toBe(firstCallTime);
133109
});
134110
});
135-
136-
describe('noFunctional', () => {
137-
beforeEach(() => {
138-
localStorage.clear();
139-
sessionStorage.clear();
140-
});
141-
142-
it('should disable offline storage when noFunctional is true', () => {
143-
mockMPInstance._Store.noFunctional = true;
144-
145-
const uploader = new BatchUploader(mockMPInstance, 1000);
146-
expect(uploader['offlineStorageEnabled']).toBe(false);
147-
148-
uploader.queueEvent({ EventDataType: 4 } as SDKEvent);
149-
expect(sessionStorage.getItem('mprtcl-v4_abcdef-events')).toBeNull();
150-
expect(localStorage.getItem('mprtcl-v4_abcdef-batches')).toBeNull();
151-
});
152-
153-
it('should enable offline storage when noFunctional is false by default', async () => {
154-
const uploader = new BatchUploader(mockMPInstance, 1000);
155-
156-
expect(uploader['offlineStorageEnabled']).toBe(true);
157-
158-
uploader.queueEvent({ EventDataType: 4 } as SDKEvent);
159-
expect(sessionStorage.getItem('mprtcl-v4_abcdef-events')).not.toBeNull();
160-
161-
jest.advanceTimersByTime(1000);
162-
await Promise.resolve();
163-
164-
expect(localStorage.getItem('mprtcl-v4_abcdef-batches')).not.toBeNull();
165-
});
166-
167-
it('should enable offline storage when noFunctional is false', async () => {
168-
mockMPInstance._Store.noFunctional = false;
169-
170-
const uploader = new BatchUploader(mockMPInstance, 1000);
171-
172-
uploader.queueEvent({ EventDataType: 4 } as SDKEvent);
173-
expect(sessionStorage.getItem('mprtcl-v4_abcdef-events')).not.toBeNull();
174-
175-
jest.advanceTimersByTime(1000);
176-
await Promise.resolve();
177-
178-
expect(localStorage.getItem('mprtcl-v4_abcdef-batches')).not.toBeNull();
179-
});
180-
});
181111
});

test/src/tests-batchUploader.ts

Lines changed: 0 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,94 +1381,5 @@ describe('batch uploader', () => {
13811381
'Batch 4: AST'
13821382
).to.equal('application_state_transition');
13831383
});
1384-
1385-
describe('noFunctional', () => {
1386-
const eventStorageKey = 'mprtcl-v4_abcdef-events';
1387-
const batchStorageKey = 'mprtcl-v4_abcdef-batches';
1388-
1389-
it('should store batches in session storage when noFunctional is false by default', async () => {
1390-
window.mParticle.config.flags = {
1391-
offlineStorage: '100',
1392-
...enableBatchingConfigFlags,
1393-
};
1394-
window.mParticle.init(apiKey, window.mParticle.config);
1395-
await waitForCondition(hasIdentifyReturned);
1396-
const mpInstance = window.mParticle.getInstance();
1397-
const uploader = mpInstance._APIClient.uploader;
1398-
uploader.queueEvent(event0);
1399-
expect(window.sessionStorage.getItem(eventStorageKey)).to.not.equal(null);
1400-
});
1401-
1402-
it('should NOT store events in session storage when noFunctional is true', async () => {
1403-
window.mParticle.config.flags = {
1404-
offlineStorage: '100',
1405-
...enableBatchingConfigFlags,
1406-
};
1407-
window.mParticle.config.launcherOptions = { noFunctional: true };
1408-
window.mParticle.init(apiKey, window.mParticle.config);
1409-
await waitForCondition(hasIdentifyReturned);
1410-
const mpInstance = window.mParticle.getInstance();
1411-
const uploader = mpInstance._APIClient.uploader;
1412-
uploader.queueEvent(event0);
1413-
expect(window.sessionStorage.getItem(eventStorageKey)).to.equal(null);
1414-
});
1415-
1416-
it('should store events in session storage when noFunctional is false', async () => {
1417-
window.mParticle.config.flags = {
1418-
offlineStorage: '100',
1419-
...enableBatchingConfigFlags,
1420-
};
1421-
window.mParticle.config.launcherOptions = { noFunctional: false };
1422-
window.mParticle.init(apiKey, window.mParticle.config);
1423-
await waitForCondition(hasIdentifyReturned);
1424-
const mpInstance = window.mParticle.getInstance();
1425-
const uploader = mpInstance._APIClient.uploader;
1426-
uploader.queueEvent(event0);
1427-
expect(window.sessionStorage.getItem(eventStorageKey)).to.not.equal(null);
1428-
});
1429-
1430-
it('should store batches in local storage when noFunctional is false by default', async () => {
1431-
window.mParticle.init(apiKey, window.mParticle.config);
1432-
await waitForCondition(hasIdentifyReturned);
1433-
const mpInstance = window.mParticle.getInstance();
1434-
const uploader = mpInstance._APIClient.uploader;
1435-
fetchMock.post(urls.events, 500, { overwriteRoutes: true });
1436-
uploader.queueEvent(event0);
1437-
await window.mParticle.getInstance()._APIClient.uploader.prepareAndUpload();
1438-
expect(window.localStorage.getItem(batchStorageKey)).to.not.equal(null);
1439-
});
1440-
1441-
it('should NOT store batches in local storage when noFunctional is true', async () => {
1442-
window.mParticle.config.flags = {
1443-
offlineStorage: '100',
1444-
...enableBatchingConfigFlags,
1445-
};
1446-
window.mParticle.config.launcherOptions = { noFunctional: true };
1447-
window.mParticle.init(apiKey, window.mParticle.config);
1448-
await waitForCondition(hasIdentifyReturned);
1449-
const mpInstance = window.mParticle.getInstance();
1450-
const uploader = mpInstance._APIClient.uploader;
1451-
uploader.queueEvent(event0);
1452-
await window.mParticle.getInstance()._APIClient.uploader.prepareAndUpload();
1453-
expect(window.localStorage.getItem(batchStorageKey)).to.equal(null);
1454-
});
1455-
1456-
it('should store batches in local storage when noFunctional is false', async () => {
1457-
window.mParticle.config.flags = {
1458-
offlineStorage: '100',
1459-
...enableBatchingConfigFlags,
1460-
};
1461-
window.mParticle.config.launcherOptions = { noFunctional: false };
1462-
window.mParticle.init(apiKey, window.mParticle.config);
1463-
await waitForCondition(hasIdentifyReturned);
1464-
const mpInstance = window.mParticle.getInstance();
1465-
const uploader = mpInstance._APIClient.uploader;
1466-
fetchMock.post(urls.events, 500, { overwriteRoutes: true });
1467-
uploader.queueEvent(event0);
1468-
await window.mParticle.getInstance()._APIClient.uploader.prepareAndUpload();
1469-
expect(window.localStorage.getItem(batchStorageKey)).to.not.equal(null);
1470-
});
1471-
1472-
});
14731384
});
14741385
});

0 commit comments

Comments
 (0)