Skip to content

Commit

Permalink
Make millis a number, make apiKey optional, turn other comments
Browse files Browse the repository at this point in the history
  • Loading branch information
rmi22186 committed Nov 9, 2023
1 parent e0f364d commit e923b91
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ const Constants = {
integrationDelayTimeout: 5000, // Milliseconds for forcing the integration delay to un-suspend event queueing due to integration partner errors
maxCookieSize: 3000, // Number of bytes for cookie size to not exceed
aliasMaxWindow: 90, // Max age of Alias request startTime, in days
uploadInterval: '0', // Maximum milliseconds in between batch uploads, below 500 will mean immediate upload. This is a string because that is how the server returns it
uploadInterval: 0, // Maximum milliseconds in between batch uploads, below 500 will mean immediate upload. This is a string because that is how the server returns it
},
DefaultBaseUrls: {
v1SecureServiceUrl: 'jssdks.mparticle.com/v1/JS/',
Expand Down
12 changes: 7 additions & 5 deletions src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
SDKInitConfig,
SDKProduct,
} from './sdkRuntimeModels';
import { isNumber, isDataPlanSlug, Dictionary } from './utils';
import { isNumber, isDataPlanSlug, Dictionary, parseNumber } from './utils';
import { SDKConsentState } from './consent';

// This represents the runtime configuration of the SDK AFTER
Expand Down Expand Up @@ -111,9 +111,10 @@ interface WrapperSDKInfo {
isInfoSet: boolean;
}

// TODO: https://go.mparticle.com/SQDSDKS-5954
export interface IFeatureFlags {
reportBatching?: string;
eventBatchingIntervalMillis?: string;
eventBatchingIntervalMillis?: number;
offlineStorage?: string;
directURLRouting?: boolean;
}
Expand Down Expand Up @@ -168,7 +169,7 @@ export default function Store(
this: IStore,
config: SDKInitConfig,
mpInstance: MParticleWebSDK,
apiKey: string
apiKey?: string
) {
const defaultStore: Partial<IStore> = {
isEnabled: true,
Expand Down Expand Up @@ -218,7 +219,7 @@ export default function Store(
for (var key in defaultStore) {
this[key] = defaultStore[key];
}
this.devToken = apiKey;
this.devToken = apiKey || null;

this.integrationDelayTimeoutStart = Date.now();

Expand Down Expand Up @@ -437,8 +438,9 @@ export function processFlags(

// Passed in config flags take priority over defaults
flags[ReportBatching] = config.flags[ReportBatching] || false;
// The server returns stringified numbers, sowe need to parse
flags[EventBatchingIntervalMillis] =
config.flags[EventBatchingIntervalMillis] ||
parseNumber(config.flags[EventBatchingIntervalMillis]) ||
Constants.DefaultConfig.uploadInterval;
flags[OfflineStorage] = config.flags[OfflineStorage] || '0';
flags[DirectUrlRouting] = config.flags[DirectUrlRouting] === 'True';
Expand Down
2 changes: 1 addition & 1 deletion test/src/tests-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ beforeEach(function() {
requestConfig: false,
isDevelopmentMode: false,
flags: {
eventBatchingIntervalMillis: "0",
eventBatchingIntervalMillis: 0,
}
};

Expand Down
28 changes: 19 additions & 9 deletions test/src/tests-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('Store', () => {

it('should initialize Store with defaults', () => {
// Use sample config to make sure our types are safe
const store: IStore = new Store(sampleConfig, window.mParticle.getInstance(), apiKey);
const store: IStore = new Store(sampleConfig, window.mParticle.getInstance());
expect(store).to.be.ok;
expect(store.isEnabled, 'isEnabled').to.eq(true);
expect(store.sessionAttributes, 'sessionAttributes').to.be.ok;
Expand All @@ -46,7 +46,7 @@ describe('Store', () => {
expect(store.isFirstRun, 'isFirstRun').to.eq(null);
expect(store.clientId, 'clientId').to.eq(null);
expect(store.deviceId, 'deviceId').to.eq(null);
expect(store.devToken, 'devToken').to.eq(apiKey);
expect(store.devToken, 'devToken').to.eq(null);
expect(store.serverSettings, 'serverSettings').to.be.ok;
expect(store.dateLastEventSent, 'dateLastEventSent').to.eq(null);
expect(store.sessionStartDate, 'sessionStartDate').to.eq(null);
Expand Down Expand Up @@ -85,7 +85,7 @@ describe('Store', () => {
});

it('should initialize store.SDKConfig with valid defaults', () => {
const store: IStore = new Store(sampleConfig, window.mParticle.getInstance(), apiKey);
const store: IStore = new Store(sampleConfig, window.mParticle.getInstance());

expect(store.SDKConfig.aliasMaxWindow, 'aliasMaxWindow').to.eq(90);
expect(store.SDKConfig.aliasUrl, 'aliasUrl').to.eq(
Expand All @@ -109,7 +109,7 @@ describe('Store', () => {
expect(
store.SDKConfig.flags?.eventBatchingIntervalMillis,
'flags.eventBatchingIntervalMillis'
).to.eq('0');
).to.eq(0);
expect(store.SDKConfig.forceHttps, 'forceHttps').to.eq(true);

expect(store.SDKConfig.identityCallback, 'identityCallback').to.be
Expand Down Expand Up @@ -167,7 +167,7 @@ describe('Store', () => {
planVersion: 3,
},
};
const store: IStore = new Store(dataPlanConfig, window.mParticle.getInstance(), apiKey);
const store: IStore = new Store(dataPlanConfig, window.mParticle.getInstance());

expect(store.SDKConfig.dataPlan, 'dataPlan').to.deep.equal({
PlanId: 'test_data_plan',
Expand All @@ -184,13 +184,23 @@ describe('Store', () => {
...sampleConfig,
sideloadedKits,
};
const store: IStore = new Store(config, window.mParticle.getInstance(), apiKey);
const store: IStore = new Store(config, window.mParticle.getInstance());

expect(store.SDKConfig.sideloadedKits.length, 'side loaded kits').to.equal(sideloadedKits.length);
expect(store.SDKConfig.sideloadedKits[0], 'side loaded kits').to.deep.equal(sideloadedKit1);
expect(store.SDKConfig.sideloadedKits[1], 'side loaded kits').to.deep.equal(sideloadedKit2);
});

it('should assign apiKey to devToken property', () => {
const config = {
...sampleConfig
};

const store: IStore = new Store(config, window.mParticle.getInstance(), apiKey);

expect(store.devToken, 'devToken').to.equal(apiKey);
});

describe('#processFlags', () => {
it('should return an empty object if no featureFlags are passed', () => {
const flags = processFlags({} as SDKInitConfig, {} as SDKConfig);
Expand All @@ -201,7 +211,7 @@ describe('Store', () => {
const flags = processFlags({flags: {}} as SDKInitConfig, {} as SDKConfig);
const expectedResult = {
reportBatching: false,
eventBatchingIntervalMillis: '0',
eventBatchingIntervalMillis: 0,
offlineStorage: '0',
directURLRouting: false,
};
Expand All @@ -212,7 +222,7 @@ describe('Store', () => {
it('should return featureFlags if featureFlags are passed in', () => {
const cutomizedFlags = {
reportBatching: true,
eventBatchingIntervalMillis: '5000',
eventBatchingIntervalMillis: 5000,
offlineStorage: '100',
directURLRouting: 'True',
};
Expand All @@ -221,7 +231,7 @@ describe('Store', () => {

const expectedResult = {
reportBatching: true,
eventBatchingIntervalMillis: '5000',
eventBatchingIntervalMillis: 5000,
offlineStorage: '100',
directURLRouting: true,
}
Expand Down

0 comments on commit e923b91

Please sign in to comment.