Skip to content

Commit ce57997

Browse files
authored
refactor: Revert noFunctional/noTargeting mappings (#1119)
1 parent 3cb1319 commit ce57997

17 files changed

+26
-699
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: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -233,14 +233,3 @@ export const HTTP_UNAUTHORIZED = 401 as const;
233233
export const HTTP_FORBIDDEN = 403 as const;
234234
export const HTTP_NOT_FOUND = 404 as const;
235235
export const HTTP_SERVER_ERROR = 500 as const;
236-
237-
export type PrivacyControl = 'functional' | 'targeting';
238-
239-
export type StorageTypes = 'SDKState' | 'OfflineEvents' | 'IdentityCache' | 'TimeOnSite';
240-
241-
export const StoragePrivacyMap: Record<StorageTypes, PrivacyControl> = {
242-
SDKState: 'functional',
243-
OfflineEvents: 'functional',
244-
IdentityCache: 'functional',
245-
TimeOnSite: 'targeting',
246-
};

src/mp-instance.ts

Lines changed: 4 additions & 6 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, valueof, generateDeprecationMessage } from './utils';
40-
import { DisabledVault, LocalStorageVault } from './vault';
40+
import { LocalStorageVault } from './vault';
4141
import { removeExpiredIdentityCacheDates } from './identity-utils';
4242
import IntegrationCapture from './integrationCapture';
4343
import { IPreInit, processReadyQueue } from './pre-init-utils';
@@ -1543,11 +1543,9 @@ function createKitBlocker(config, mpInstance) {
15431543
}
15441544

15451545
function createIdentityCache(mpInstance) {
1546-
const cacheKey = `${mpInstance._Store.storageName}-id-cache`;
1547-
if (mpInstance._Store.getPrivacyFlag('IdentityCache')) {
1548-
return new DisabledVault(cacheKey, { logger: mpInstance.Logger });
1549-
}
1550-
return new LocalStorageVault(cacheKey, { logger: mpInstance.Logger });
1546+
return new LocalStorageVault(`${mpInstance._Store.storageName}-id-cache`, {
1547+
logger: mpInstance.Logger,
1548+
});
15511549
}
15521550

15531551
function runPreConfigFetchInitialization(mpInstance, apiKey, config) {

src/persistence.js

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ export default function _Persistence(mpInstance) {
3535
mpInstance._Store.isFirstRun = false;
3636
}
3737

38-
if (mpInstance._Store.getPrivacyFlag('SDKState')) {
39-
return;
40-
}
41-
4238
// https://go.mparticle.com/work/SQDSDKS-6045
4339
if (!mpInstance._Store.isLocalStorageAvailable) {
4440
mpInstance._Store.SDKConfig.useCookieStorage = true;
@@ -117,10 +113,7 @@ export default function _Persistence(mpInstance) {
117113
};
118114

119115
this.update = function() {
120-
if (
121-
!mpInstance._Store.webviewBridgeEnabled &&
122-
!mpInstance._Store.getPrivacyFlag('SDKState')
123-
) {
116+
if (!mpInstance._Store.webviewBridgeEnabled) {
124117
if (mpInstance._Store.SDKConfig.useCookieStorage) {
125118
self.setCookie();
126119
}
@@ -810,9 +803,6 @@ export default function _Persistence(mpInstance) {
810803

811804
// https://go.mparticle.com/work/SQDSDKS-6021
812805
this.savePersistence = function(persistence) {
813-
if (mpInstance._Store.getPrivacyFlag('SDKState')) {
814-
return;
815-
}
816806
var encodedPersistence = self.encodePersistence(
817807
JSON.stringify(persistence)
818808
),
@@ -857,9 +847,6 @@ export default function _Persistence(mpInstance) {
857847
};
858848

859849
this.getPersistence = function() {
860-
if (mpInstance._Store.getPrivacyFlag('SDKState')) {
861-
return null;
862-
}
863850
var persistence = this.useLocalStorage()
864851
? this.getLocalStorage()
865852
: this.getCookie();

src/sdkRuntimeModels.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,6 @@ export interface SDKInitConfig
271271
extends Omit<MPConfiguration, 'dataPlan' | 'logLevel'> {
272272
dataPlan?: DataPlanConfig | KitBlockerDataPlan; // TODO: These should be eventually split into two different attributes
273273
logLevel?: LogLevelType;
274-
275-
noFunctional?: boolean;
276-
noTargeting?: boolean;
277274

278275
kitConfigs?: IKitConfigs[];
279276
kits?: Dictionary<UnregisteredKit>;

src/store.ts

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
UserIdentities,
99
} from '@mparticle/web-sdk';
1010
import { IKitConfigs } from './configAPIClient';
11-
import Constants, { PrivacyControl, StoragePrivacyMap, StorageTypes } from './constants';
11+
import Constants from './constants';
1212
import {
1313
DataPlanResult,
1414
KitBlockerOptions,
@@ -153,8 +153,6 @@ export interface IFeatureFlags {
153153
export interface IStore {
154154
isEnabled: boolean;
155155
isInitialized: boolean;
156-
noFunctional: boolean;
157-
noTargeting: boolean;
158156

159157
// Session Attributes are persistent attributes that are tied to the current session and
160158
// are uploaded then cleared when the session ends.
@@ -211,12 +209,6 @@ export interface IStore {
211209
_getFromPersistence?<T>(mpid: MPID, key: string): T;
212210
_setPersistence?<T>(mpid: MPID, key: string, value: T): void;
213211

214-
getNoFunctional?(): boolean;
215-
setNoFunctional?(noFunctional: boolean): void;
216-
getNoTargeting?(): boolean;
217-
setNoTargeting?(noTargeting: boolean): void;
218-
getPrivacyFlag?(storageType: StorageTypes): boolean;
219-
220212
getDeviceId?(): string;
221213
setDeviceId?(deviceId: string): void;
222214
getFirstSeenTime?(mpid: MPID): number;
@@ -252,8 +244,6 @@ export default function Store(
252244

253245
const defaultStore: Partial<IStore> = {
254246
isEnabled: true,
255-
noFunctional: false,
256-
noTargeting: false,
257247
sessionAttributes: {},
258248
localSessionAttributes: {},
259249
currentSessionMPIDs: [],
@@ -596,27 +586,6 @@ export default function Store(
596586
}
597587
};
598588

599-
this.getNoFunctional = (): boolean => this.noFunctional;
600-
this.setNoFunctional = (noFunctional: boolean): void => {
601-
this.noFunctional = noFunctional;
602-
};
603-
604-
this.getNoTargeting = (): boolean => this.noTargeting;
605-
this.setNoTargeting = (noTargeting: boolean): void => {
606-
this.noTargeting = noTargeting;
607-
};
608-
609-
this.getPrivacyFlag = (storageType: StorageTypes): boolean => {
610-
const privacyControl: PrivacyControl = StoragePrivacyMap[storageType];
611-
if (privacyControl === 'functional') {
612-
return this.getNoFunctional();
613-
}
614-
if (privacyControl === 'targeting') {
615-
return this.getNoTargeting();
616-
}
617-
return false;
618-
};
619-
620589
this.getDeviceId = () => this.deviceId;
621590
this.setDeviceId = (deviceId: string) => {
622591
this.deviceId = deviceId;
@@ -737,21 +706,9 @@ export default function Store(
737706
this.SDKConfig[baseUrlKeys] = baseUrls[baseUrlKeys];
738707
}
739708

740-
const { noFunctional, noTargeting } = config?.launcherOptions ?? {};
741-
742-
if (noFunctional != null) {
743-
this.setNoFunctional(noFunctional);
744-
}
745-
746-
if (noTargeting != null) {
747-
this.setNoTargeting(noTargeting);
748-
}
749-
750709
if (workspaceToken) {
751710
this.SDKConfig.workspaceToken = workspaceToken;
752-
if (!this.getPrivacyFlag('TimeOnSite')) {
753-
mpInstance._timeOnSiteTimer = new ForegroundTimer(workspaceToken);
754-
}
711+
mpInstance._timeOnSiteTimer = new ForegroundTimer(workspaceToken);
755712
} else {
756713
mpInstance.Logger.warning(
757714
'You should have a workspaceToken on your config object for security purposes.'

src/vault.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -102,20 +102,4 @@ 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-
return this.contents;
120-
}
121105
}

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/jest/foregroundTimeTracker.spec.ts

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
import ForegroundTimeTracker from '../../src/foregroundTimeTracker';
2-
import Store, { IStore } from '../../src/store';
3-
import { SDKInitConfig } from '../../src/sdkRuntimeModels';
4-
import { IMParticleWebSDKInstance } from '../../src/mp-instance';
52

63
describe('ForegroundTimeTracker', () => {
74
let foregroundTimeTracker: ForegroundTimeTracker;
@@ -493,65 +490,4 @@ describe('ForegroundTimeTracker', () => {
493490
expect(updatePersistenceSpy).toHaveBeenCalled();
494491
});
495492
});
496-
497-
describe('#privacy flags', () => {
498-
const workspaceToken = 'abcdef';
499-
const tosKey = `mprtcl-tos-${workspaceToken}`;
500-
let mockMPInstance: IMParticleWebSDKInstance;
501-
let store: IStore;
502-
503-
beforeEach(() => {
504-
jest.useFakeTimers({ now: Date.now(), advanceTimers: true });
505-
localStorage.clear();
506-
507-
mockMPInstance = {
508-
_Helpers: {
509-
createMainStorageName: () => `mprtcl-v4_${workspaceToken}`,
510-
createProductStorageName: () => `mprtcl-prodv4_${workspaceToken}`,
511-
Validators: { isFunction: () => true },
512-
extend: Object.assign,
513-
},
514-
_NativeSdkHelpers: { isWebviewEnabled: () => false },
515-
_Persistence: {
516-
update: jest.fn(),
517-
savePersistence: jest.fn(),
518-
getPersistence: () => ({ gs: {} }),
519-
},
520-
Logger: { verbose: jest.fn(), warning: jest.fn(), error: jest.fn() },
521-
Identity: { getCurrentUser: () => ({ getMPID: () => 'mpid' }) },
522-
_timeOnSiteTimer: undefined as any,
523-
} as unknown as IMParticleWebSDKInstance;
524-
525-
store = {} as IStore;
526-
(Store as any).call(store, {} as SDKInitConfig, mockMPInstance, 'apikey');
527-
mockMPInstance._Store = store;
528-
});
529-
530-
afterEach(() => {
531-
jest.useRealTimers();
532-
localStorage.clear();
533-
});
534-
535-
it('should track time on site when noTargeting is false by default', () => {
536-
store.processConfig({ workspaceToken } as SDKInitConfig);
537-
expect(mockMPInstance._timeOnSiteTimer).toBeDefined();
538-
jest.advanceTimersByTime(1000);
539-
mockMPInstance._timeOnSiteTimer.getTimeInForeground();
540-
expect(localStorage.getItem(tosKey)).not.toBeNull();
541-
});
542-
543-
it('should NOT track time on site when noTargeting is true', () => {
544-
store.processConfig({ workspaceToken, launcherOptions: { noTargeting: true } } as SDKInitConfig);
545-
expect(mockMPInstance._timeOnSiteTimer).toBeUndefined();
546-
expect(localStorage.getItem(tosKey)).toBeNull();
547-
});
548-
549-
it('should track time on site when noTargeting is false', () => {
550-
store.processConfig({ workspaceToken, launcherOptions: { noTargeting: false } } as SDKInitConfig);
551-
expect(mockMPInstance._timeOnSiteTimer).toBeDefined();
552-
jest.advanceTimersByTime(1000);
553-
mockMPInstance._timeOnSiteTimer.getTimeInForeground();
554-
expect(localStorage.getItem(tosKey)).not.toBeNull();
555-
});
556-
});
557493
});

0 commit comments

Comments
 (0)