Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/sdkRuntimeModels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,9 @@ export interface SDKInitConfig
extends Omit<MPConfiguration, 'dataPlan' | 'logLevel'> {
dataPlan?: DataPlanConfig | KitBlockerDataPlan; // TODO: These should be eventually split into two different attributes
logLevel?: LogLevelType;

noFunctional?: boolean;
noTargeting?: boolean;

kitConfigs?: IKitConfigs[];
kits?: Dictionary<UnregisteredKit>;
Expand Down
28 changes: 28 additions & 0 deletions src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ export interface IFeatureFlags {
export interface IStore {
isEnabled: boolean;
isInitialized: boolean;
noFunctional: boolean;
noTargeting: boolean;

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

getNoFunctional?(): boolean;
setNoFunctional?(noFunctional: boolean): void;
getNoTargeting?(): boolean;
setNoTargeting?(noTargeting: boolean): void;

getDeviceId?(): string;
setDeviceId?(deviceId: string): void;
getFirstSeenTime?(mpid: MPID): number;
Expand Down Expand Up @@ -245,6 +252,8 @@ export default function Store(

const defaultStore: Partial<IStore> = {
isEnabled: true,
noFunctional: false,
noTargeting: false,
sessionAttributes: {},
localSessionAttributes: {},
currentSessionMPIDs: [],
Expand Down Expand Up @@ -588,6 +597,16 @@ export default function Store(
}
};

this.getNoFunctional = (): boolean => this.noFunctional;
this.setNoFunctional = (noFunctional: boolean): void => {
this.noFunctional = noFunctional;
};

this.getNoTargeting = (): boolean => this.noTargeting;
this.setNoTargeting = (noTargeting: boolean): void => {
this.noTargeting = noTargeting;
};

this.getDeviceId = () => this.deviceId;
this.setDeviceId = (deviceId: string) => {
this.deviceId = deviceId;
Expand Down Expand Up @@ -720,6 +739,15 @@ export default function Store(
this.storageName = createMainStorageName(workspaceToken);
this.prodStorageName = createProductStorageName(workspaceToken);

// Extract privacy flags directly from config into Store
if (config.hasOwnProperty('noFunctional')) {
this.setNoFunctional(config.noFunctional);
}

if (config.hasOwnProperty('noTargeting')) {
this.setNoTargeting(config.noTargeting);
}

this.SDKConfig.requiredWebviewBridgeName =
requiredWebviewBridgeName || workspaceToken;

Expand Down
85 changes: 85 additions & 0 deletions test/jest/store.flags.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import Store, { IStore } from '../../src/store';
import { IMParticleWebSDKInstance } from '../../src/mp-instance';
import { SDKInitConfig } from '../../src/sdkRuntimeModels';

describe('Store privacy flags', () => {
let store: IStore & Record<string, any>;
let mockMPInstance: IMParticleWebSDKInstance & Record<string, any>;

beforeEach(() => {
mockMPInstance = {
_Helpers: {
createMainStorageName: () => 'mprtcl-v4',
createProductStorageName: () => 'mprtcl-prodv4',
Validators: { isFunction: () => true },
extend: Object.assign,
},
_NativeSdkHelpers: {
isWebviewEnabled: () => false,
},
_Persistence: {
update: () => {},
savePersistence: () => {},
getPersistence: () => ({ gs: {} }),
},
Logger: {
verbose: () => {},
warning: () => {},
error: () => {},
},
Identity: {
getCurrentUser: () => ({ getMPID: () => 'mpid' }),
},
} as any;

store = {} as any;
// Construct Store with our mock 'this'
(Store as any).call(store, {} as SDKInitConfig, mockMPInstance, 'apikey');
});

it('should default noFunctional and noTargeting to false when not provided', () => {
const cfg: SDKInitConfig = { flags: {} } as any;
store.processConfig(cfg);
expect(store.getNoFunctional()).toBe(false);
expect(store.getNoTargeting()).toBe(false);
});

it('should set noFunctional as true and noTargeting as true from config', () => {
const cfg: SDKInitConfig = {
noFunctional: true,
noTargeting: true,
flags: {},
} as any;

store.processConfig(cfg);

expect(store.getNoFunctional()).toBe(true);
expect(store.getNoTargeting()).toBe(true);
});

it('should set noFunctional as true and noTargeting as false from config', () => {
const cfg: SDKInitConfig = {
noFunctional: true,
noTargeting: false,
flags: {},
} as any;

store.processConfig(cfg);

expect(store.getNoFunctional()).toBe(true);
expect(store.getNoTargeting()).toBe(false);
});

it('should set noFunctional as false and noTargeting as true from config', () => {
const cfg: SDKInitConfig = {
noFunctional: false,
noTargeting: true,
flags: {},
} as any;

store.processConfig(cfg);

expect(store.getNoFunctional()).toBe(false);
expect(store.getNoTargeting()).toBe(true);
});
});
23 changes: 23 additions & 0 deletions test/src/tests-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1801,4 +1801,27 @@ describe('Store', () => {
});
});
});

describe('#privacy flags', () => {
it('should set noFunctional and noTargeting to false when not provided', () => {
const inst = window.mParticle.getInstance();
const store = (inst as any)._Store;
expect(store.getNoFunctional()).to.equal(false);
expect(store.getNoTargeting()).to.equal(false);
});

it('should set noFunctional and noTargeting from init config', () => {
window.mParticle._resetForTests(MPConfig);
window.mParticle.config = window.mParticle.config || {};
window.mParticle.config.noFunctional = true;
window.mParticle.config.noTargeting = true;

window.mParticle.init(apiKey, window.mParticle.config);

const inst = window.mParticle.getInstance();
const store = (inst as any)._Store;
expect(store.getNoFunctional()).to.equal(true);
expect(store.getNoTargeting()).to.equal(true);
});
});
});
Loading