Skip to content

Commit 6ba361d

Browse files
Address PR Comments
1 parent 0e9cbfe commit 6ba361d

File tree

6 files changed

+30
-28
lines changed

6 files changed

+30
-28
lines changed

src/cookieSyncManager.interfaces.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,19 @@ import { Dictionary } from './utils';
33
import { IConsentRules } from './consent';
44

55
export type CookieSyncDates = Dictionary<number>;
6+
7+
export interface IPixelConfiguration {
8+
name?: string;
9+
moduleId: number;
10+
esId?: number;
11+
isDebug?: boolean;
12+
isProduction?: boolean;
13+
settings: Dictionary<string>;
14+
frequencyCap: number;
15+
pixelUrl: string;
16+
redirectUrl: string;
17+
filteringConsentRuleValues?: IConsentRules;
18+
}
619
export interface ICookieSyncManager {
720
attemptCookieSync: (
821
previousMPID: MPID,

src/cookieSyncManager.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,6 @@ import { IConsentRules } from './consent';
88
const { Messages } = Constants;
99
const { InformationMessages } = Messages;
1010

11-
interface PixelConfig {
12-
moduleId: string;
13-
frequencyCap: number;
14-
pixelUrl: string;
15-
redirectUrl: string;
16-
filteringConsentRuleValues: IConsentRules;
17-
}
18-
1911
export const DAYS_IN_MILLISECONDS = 1000 * 60 * 60 * 24;
2012

2113
const hasFrequencyCapExpired = (
@@ -107,9 +99,7 @@ export default function CookieSyncManager(
10799
persistence[mpid].csd = {};
108100
}
109101

110-
const lastSyncDateForModule = persistence[mpid].csd[moduleId]
111-
? persistence[mpid].csd[moduleId]
112-
: null;
102+
const lastSyncDateForModule = persistence[mpid].csd[moduleId] || null;
113103

114104
// Check to see if we need to refresh cookieSync
115105
if (hasFrequencyCapExpired(lastSyncDateForModule, frequencyCap)) {
@@ -123,7 +113,6 @@ export default function CookieSyncManager(
123113
requiresConsent
124114
);
125115
}
126-
127116
}
128117
});
129118
};

src/sdkRuntimeModels.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
Callback,
77
IdentityApiData,
88
} from '@mparticle/web-sdk';
9-
import { IStore, PixelConfiguration } from './store';
9+
import { IStore } from './store';
1010
import Validators from './validators';
1111
import { Dictionary } from './utils';
1212
import { IServerModel } from './serverModel';
@@ -31,7 +31,7 @@ import {
3131
} from './identity-user-interfaces';
3232
import { IIdentityType } from './types.interfaces';
3333
import IntegrationCapture from './integrationCapture';
34-
import { ICookieSyncManager } from './cookieSyncManager.interfaces';
34+
import { ICookieSyncManager, IPixelConfiguration } from './cookieSyncManager.interfaces';
3535

3636
// TODO: Resolve this with version in @mparticle/web-sdk
3737
export type SDKEventCustomFlags = Dictionary<any>;
@@ -230,7 +230,7 @@ export interface SDKInitConfig
230230
sideloadedKits?: MPForwarder[];
231231
dataPlanOptions?: KitBlockerOptions;
232232
flags?: Dictionary;
233-
pixelConfigs?: PixelConfiguration[];
233+
pixelConfigs?: IPixelConfiguration[];
234234

235235
aliasMaxWindow?: number;
236236
deviceId?: string;

src/store.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import {
3737
IGlobalStoreV2MinifiedKeys,
3838
IPersistenceMinified,
3939
} from './persistence.interfaces';
40-
import { CookieSyncDates } from './cookieSyncManager.interfaces';
40+
import { CookieSyncDates, IPixelConfiguration } from './cookieSyncManager.interfaces';
4141

4242
// This represents the runtime configuration of the SDK AFTER
4343
// initialization has been complete and all settings and
@@ -119,7 +119,6 @@ function createSDKConfig(config: SDKInitConfig): SDKConfig {
119119

120120
// TODO: Placeholder Types to be filled in as we migrate more modules
121121
// to TypeScript
122-
export type PixelConfiguration = Dictionary;
123122
export type ServerSettings = Dictionary;
124123
export type SessionAttributes = Dictionary;
125124
export type IntegrationAttributes = Dictionary<Dictionary<string>>;
@@ -179,7 +178,7 @@ export interface IStore {
179178
kits: Dictionary<MPForwarder>;
180179
sideloadedKits: MPForwarder[];
181180
configuredForwarders: MPForwarder[];
182-
pixelConfigurations: PixelConfiguration[];
181+
pixelConfigurations: IPixelConfiguration[];
183182
integrationDelayTimeoutStart: number; // UNIX Timestamp
184183
webviewBridgeEnabled?: boolean;
185184
wrapperSDKInfo: WrapperSDKInfo;

test/jest/cookieSyncManager.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import CookieSyncManager, { DAYS_IN_MILLISECONDS } from '../../src/cookieSyncManager';
2+
import { IPixelConfiguration } from '../../src/cookieSyncManager.interfaces';
23
import { MParticleWebSDK } from '../../src/sdkRuntimeModels';
3-
import { PixelConfiguration } from '../../src/store';
44
import { testMPID } from '../src/config/constants';
55

6-
const pixelSettings: PixelConfiguration = {
6+
const pixelSettings: IPixelConfiguration = {
77
name: 'TestPixel',
88
moduleId: 5,
99
esId: 24053,
@@ -90,11 +90,11 @@ describe.only('CookieSyncManager', () => {
9090
});
9191

9292
it('should toggle requiresConsent value if filtering filteringConsentRuleValues are defined', () => {
93-
const myPixelSettings: PixelConfiguration = {
93+
const myPixelSettings: IPixelConfiguration = {
9494
filteringConsentRuleValues: {
9595
values: ['test'],
9696
},
97-
};
97+
} as unknown as IPixelConfiguration;
9898

9999
const mockMPInstance = ({
100100
_Store: {
@@ -125,10 +125,10 @@ describe.only('CookieSyncManager', () => {
125125
});
126126

127127
it('should update the urlWithRedirect if a redirectUrl is defined', () => {
128-
const myPixelSettings: PixelConfiguration = {
128+
const myPixelSettings: IPixelConfiguration = {
129129
pixelUrl: 'https://test.com',
130130
redirectUrl: '?redirect=https://redirect.com&mpid=%%mpid%%',
131-
};
131+
} as unknown as IPixelConfiguration;
132132

133133
const mockMPInstance = ({
134134
_Store: {

test/src/tests-cookie-syncing.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ import Utils from './config/utils';
33
import fetchMock from 'fetch-mock/esm/client';
44
import { urls, testMPID, MPConfig, v4LSKey, apiKey } from './config/constants';
55
import { MParticleWebSDK } from '../../src/sdkRuntimeModels';
6-
import { PixelConfiguration } from '../../src/store';
76
import { IMParticleUser } from '../../src/identity-user-interfaces';
7+
import { IPixelConfiguration } from '../../src/cookieSyncManager.interfaces';
8+
import { IConsentRules } from '../../src/consent';
89
const { fetchMockSuccess, waitForCondition, hasIdentifyReturned } = Utils;
910

1011
const { setLocalStorage, MockForwarder, getLocalStorage } = Utils;
1112

12-
const pixelSettings: PixelConfiguration = {
13+
const pixelSettings: IPixelConfiguration = {
1314
name: 'TestPixel',
1415
moduleId: 5,
1516
esId: 24053,
@@ -343,7 +344,7 @@ describe('cookie syncing', function() {
343344
it('should perform a cookiesync when consent is not configured on the cookiesync setting', function(done) {
344345
mParticle._resetForTests(MPConfig);
345346

346-
pixelSettings.filteringConsentRuleValues = {};
347+
pixelSettings.filteringConsentRuleValues = {} as unknown as IConsentRules;
347348
window.mParticle.config.pixelConfigs = [pixelSettings];
348349

349350
mParticle.init(apiKey, window.mParticle.config);
@@ -1213,7 +1214,7 @@ describe('cookie syncing', function() {
12131214
mParticle.config.isDevelopmentMode = false;
12141215

12151216
// pixelSetting1 has consent required, and so should only perform a cookiesync after consent is saved to the user
1216-
const pixelSettings1: PixelConfiguration = {
1217+
const pixelSettings1: IPixelConfiguration = {
12171218
name: 'TestPixel',
12181219
moduleId: 1,
12191220
esId: 24053,

0 commit comments

Comments
 (0)