Skip to content

Commit

Permalink
Rename DefaultUrls to DefaultBaseUrls
Browse files Browse the repository at this point in the history
  • Loading branch information
rmi22186 committed Nov 8, 2023
1 parent e7a8515 commit 196b7b8
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 69 deletions.
2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ const Constants = {
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
},
DefaultUrls: {
DefaultBaseUrls: {
v1SecureServiceUrl: 'jssdks.mparticle.com/v1/JS/',
v2SecureServiceUrl: 'jssdks.mparticle.com/v2/JS/',
v3SecureServiceUrl: 'jssdks.mparticle.com/v3/JS/',
Expand Down
64 changes: 22 additions & 42 deletions src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ function createSDKConfig(config: SDKInitConfig): SDKConfig {
}
}

for (const prop in Constants.DefaultUrls) {
sdkConfig[prop] = Constants.DefaultUrls[prop];
for (const prop in Constants.DefaultBaseUrls) {
sdkConfig[prop] = Constants.DefaultBaseUrls[prop];
}

return sdkConfig;
Expand Down Expand Up @@ -262,8 +262,7 @@ export default function Store(

this.SDKConfig.kits = config.kits || {};

this.SDKConfig.sideloadedKits =
config.sideloadedKits || [];
this.SDKConfig.sideloadedKits = config.sideloadedKits || [];

if (config.hasOwnProperty('isIOS')) {
this.SDKConfig.isIOS = config.isIOS;
Expand All @@ -275,17 +274,15 @@ export default function Store(
}

if (config.hasOwnProperty('useCookieStorage')) {
this.SDKConfig.useCookieStorage =
config.useCookieStorage;
this.SDKConfig.useCookieStorage = config.useCookieStorage;
} else {
this.SDKConfig.useCookieStorage = false;
}

if (config.hasOwnProperty('maxProducts')) {
this.SDKConfig.maxProducts = config.maxProducts;
} else {
this.SDKConfig.maxProducts =
Constants.DefaultConfig.maxProducts;
this.SDKConfig.maxProducts = Constants.DefaultConfig.maxProducts;
}

if (config.hasOwnProperty('maxCookieSize')) {
Expand All @@ -312,19 +309,13 @@ export default function Store(
}

if (config.hasOwnProperty('identifyRequest')) {
this.SDKConfig.identifyRequest =
config.identifyRequest;
this.SDKConfig.identifyRequest = config.identifyRequest;
}

if (config.hasOwnProperty('identityCallback')) {
var callback = config.identityCallback;
if (
mpInstance._Helpers.Validators.isFunction(
callback
)
) {
this.SDKConfig.identityCallback =
config.identityCallback;
if (mpInstance._Helpers.Validators.isFunction(callback)) {
this.SDKConfig.identityCallback = config.identityCallback;
} else {
mpInstance.Logger.warning(
'The optional callback must be a function. You tried entering a(n) ' +
Expand All @@ -343,8 +334,7 @@ export default function Store(
}

if (config.hasOwnProperty('sessionTimeout')) {
this.SDKConfig.sessionTimeout =
config.sessionTimeout;
this.SDKConfig.sessionTimeout = config.sessionTimeout;
}

if (config.hasOwnProperty('dataPlan')) {
Expand All @@ -356,8 +346,7 @@ export default function Store(
const dataPlan = config.dataPlan as DataPlanConfig;
if (dataPlan.planId) {
if (isDataPlanSlug(dataPlan.planId)) {
this.SDKConfig.dataPlan.PlanId =
dataPlan.planId;
this.SDKConfig.dataPlan.PlanId = dataPlan.planId;
} else {
mpInstance.Logger.error(
'Your data plan id must be a string and match the data plan slug format (i.e. under_case_slug)'
Expand All @@ -367,8 +356,7 @@ export default function Store(

if (dataPlan.planVersion) {
if (isNumber(dataPlan.planVersion)) {
this.SDKConfig.dataPlan.PlanVersion =
dataPlan.planVersion;
this.SDKConfig.dataPlan.PlanVersion = dataPlan.planVersion;
} else {
mpInstance.Logger.error(
'Your data plan version must be a number'
Expand Down Expand Up @@ -396,8 +384,7 @@ export default function Store(
}

if (config.hasOwnProperty('aliasMaxWindow')) {
this.SDKConfig.aliasMaxWindow =
config.aliasMaxWindow;
this.SDKConfig.aliasMaxWindow = config.aliasMaxWindow;
} else {
this.SDKConfig.aliasMaxWindow =
Constants.DefaultConfig.aliasMaxWindow;
Expand All @@ -406,19 +393,11 @@ export default function Store(
if (config.hasOwnProperty('dataPlanOptions')) {
const dataPlanOptions = config.dataPlanOptions;
if (
!dataPlanOptions.hasOwnProperty(
'dataPlanVersion'
) ||
!dataPlanOptions.hasOwnProperty(
'blockUserAttributes'
) ||
!dataPlanOptions.hasOwnProperty(
'blockEventAttributes'
) ||
!dataPlanOptions.hasOwnProperty('dataPlanVersion') ||
!dataPlanOptions.hasOwnProperty('blockUserAttributes') ||
!dataPlanOptions.hasOwnProperty('blockEventAttributes') ||
!dataPlanOptions.hasOwnProperty('blockEvents') ||
!dataPlanOptions.hasOwnProperty(
'blockUserIdentities'
)
!dataPlanOptions.hasOwnProperty('blockUserIdentities')
) {
mpInstance.Logger.error(
'Ensure your config.dataPlanOptions object has the following keys: a "dataPlanVersion" object, and "blockUserAttributes", "blockEventAttributes", "blockEvents", "blockUserIdentities" booleans'
Expand All @@ -428,8 +407,7 @@ export default function Store(

if (config.hasOwnProperty('onCreateBatch')) {
if (typeof config.onCreateBatch === 'function') {
this.SDKConfig.onCreateBatch =
config.onCreateBatch;
this.SDKConfig.onCreateBatch = config.onCreateBatch;
} else {
mpInstance.Logger.error(
'config.onCreateBatch must be a function'
Expand Down Expand Up @@ -491,11 +469,13 @@ export function processBaseUrls(
}

function processCustomBaseUrls(config: SDKInitConfig): Dictionary<string> {
let defaultBaseUrls: Dictionary<string> = Constants.DefaultUrls;
let defaultBaseUrls: Dictionary<string> = Constants.DefaultBaseUrls;
let newBaseUrls: Dictionary<string> = {};

// If there is no custo base url, we use the default base url
for (let baseUrlKey in defaultBaseUrls) {
newBaseUrls[baseUrlKey] = config[baseUrlKey] || defaultBaseUrls[baseUrlKey];
newBaseUrls[baseUrlKey] =
config[baseUrlKey] || defaultBaseUrls[baseUrlKey];
}

return newBaseUrls;
Expand All @@ -505,7 +485,7 @@ function processDirectBaseUrls(
config: SDKInitConfig,
apiKey: string
): Dictionary {
let defaultBaseUrls = Constants.DefaultUrls;
let defaultBaseUrls = Constants.DefaultBaseUrls;
let directBaseUrls: Dictionary<string> = {};
// When Direct URL Routing is true, we create a new set of baseUrls that
// include the silo in the urls. mParticle API keys are prefixed with the
Expand Down
26 changes: 13 additions & 13 deletions test/src/tests-core-sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -786,12 +786,12 @@ describe('core SDK', function() {

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

mParticle.getInstance()._Store.SDKConfig.v1SecureServiceUrl.should.equal(Constants.DefaultUrls.v1SecureServiceUrl);
mParticle.getInstance()._Store.SDKConfig.v2SecureServiceUrl.should.equal(Constants.DefaultUrls.v2SecureServiceUrl)
mParticle.getInstance()._Store.SDKConfig.v3SecureServiceUrl.should.equal(Constants.DefaultUrls.v3SecureServiceUrl)
mParticle.getInstance()._Store.SDKConfig.configUrl.should.equal(Constants.DefaultUrls.configUrl)
mParticle.getInstance()._Store.SDKConfig.identityUrl.should.equal(Constants.DefaultUrls.identityUrl)
mParticle.getInstance()._Store.SDKConfig.aliasUrl.should.equal(Constants.DefaultUrls.aliasUrl)
mParticle.getInstance()._Store.SDKConfig.v1SecureServiceUrl.should.equal(Constants.DefaultBaseUrls.v1SecureServiceUrl);
mParticle.getInstance()._Store.SDKConfig.v2SecureServiceUrl.should.equal(Constants.DefaultBaseUrls.v2SecureServiceUrl)
mParticle.getInstance()._Store.SDKConfig.v3SecureServiceUrl.should.equal(Constants.DefaultBaseUrls.v3SecureServiceUrl)
mParticle.getInstance()._Store.SDKConfig.configUrl.should.equal(Constants.DefaultBaseUrls.configUrl)
mParticle.getInstance()._Store.SDKConfig.identityUrl.should.equal(Constants.DefaultBaseUrls.identityUrl)
mParticle.getInstance()._Store.SDKConfig.aliasUrl.should.equal(Constants.DefaultBaseUrls.aliasUrl)

done();
});
Expand Down Expand Up @@ -1135,7 +1135,7 @@ describe('core SDK', function() {
});

describe('pod feature flag', function() {
const endpoints = Constants.DefaultUrls;
const endpoints = Constants.DefaultBaseUrls;
// set up URLs object for each silo
let URLs = {
us1: {},
Expand Down Expand Up @@ -1175,7 +1175,7 @@ describe('core SDK', function() {

mParticle.init(apiKey, window.mParticle.config);
mParticle.getInstance()._Store.SDKConfig.aliasUrl.should.equal(URLs[silo].aliasUrl);
mParticle.getInstance()._Store.SDKConfig.configUrl.should.equal(Constants.DefaultUrls.configUrl);
mParticle.getInstance()._Store.SDKConfig.configUrl.should.equal(Constants.DefaultBaseUrls.configUrl);
mParticle.getInstance()._Store.SDKConfig.identityUrl.should.equal(URLs[silo].identityUrl);
mParticle.getInstance()._Store.SDKConfig.v1SecureServiceUrl.should.equal(URLs[silo].v1SecureServiceUrl);
mParticle.getInstance()._Store.SDKConfig.v2SecureServiceUrl.should.equal(URLs[silo].v2SecureServiceUrl);
Expand All @@ -1193,7 +1193,7 @@ describe('core SDK', function() {

mParticle.init(apiKey, window.mParticle.config);
mParticle.getInstance()._Store.SDKConfig.aliasUrl.should.equal(URLs[silo].aliasUrl);
mParticle.getInstance()._Store.SDKConfig.configUrl.should.equal(Constants.DefaultUrls.configUrl);
mParticle.getInstance()._Store.SDKConfig.configUrl.should.equal(Constants.DefaultBaseUrls.configUrl);
mParticle.getInstance()._Store.SDKConfig.identityUrl.should.equal(URLs[silo].identityUrl);
mParticle.getInstance()._Store.SDKConfig.v1SecureServiceUrl.should.equal(URLs[silo].v1SecureServiceUrl);
mParticle.getInstance()._Store.SDKConfig.v2SecureServiceUrl.should.equal(URLs[silo].v2SecureServiceUrl);
Expand All @@ -1211,7 +1211,7 @@ describe('core SDK', function() {

mParticle.init(apiKey, window.mParticle.config);
mParticle.getInstance()._Store.SDKConfig.aliasUrl.should.equal(URLs[silo].aliasUrl);
mParticle.getInstance()._Store.SDKConfig.configUrl.should.equal(Constants.DefaultUrls.configUrl);
mParticle.getInstance()._Store.SDKConfig.configUrl.should.equal(Constants.DefaultBaseUrls.configUrl);
mParticle.getInstance()._Store.SDKConfig.identityUrl.should.equal(URLs[silo].identityUrl);
mParticle.getInstance()._Store.SDKConfig.v1SecureServiceUrl.should.equal(URLs[silo].v1SecureServiceUrl);
mParticle.getInstance()._Store.SDKConfig.v2SecureServiceUrl.should.equal(URLs[silo].v2SecureServiceUrl);
Expand All @@ -1229,7 +1229,7 @@ describe('core SDK', function() {

mParticle.init(apiKey, window.mParticle.config);
mParticle.getInstance()._Store.SDKConfig.aliasUrl.should.equal(URLs[silo].aliasUrl);
mParticle.getInstance()._Store.SDKConfig.configUrl.should.equal(Constants.DefaultUrls.configUrl);
mParticle.getInstance()._Store.SDKConfig.configUrl.should.equal(Constants.DefaultBaseUrls.configUrl);
mParticle.getInstance()._Store.SDKConfig.identityUrl.should.equal(URLs[silo].identityUrl);
mParticle.getInstance()._Store.SDKConfig.v1SecureServiceUrl.should.equal(URLs[silo].v1SecureServiceUrl);
mParticle.getInstance()._Store.SDKConfig.v2SecureServiceUrl.should.equal(URLs[silo].v2SecureServiceUrl);
Expand All @@ -1247,7 +1247,7 @@ describe('core SDK', function() {

mParticle.init(apiKey, window.mParticle.config);
mParticle.getInstance()._Store.SDKConfig.aliasUrl.should.equal(URLs[silo].aliasUrl);
mParticle.getInstance()._Store.SDKConfig.configUrl.should.equal(Constants.DefaultUrls.configUrl);
mParticle.getInstance()._Store.SDKConfig.configUrl.should.equal(Constants.DefaultBaseUrls.configUrl);
mParticle.getInstance()._Store.SDKConfig.identityUrl.should.equal(URLs[silo].identityUrl);
mParticle.getInstance()._Store.SDKConfig.v1SecureServiceUrl.should.equal(URLs[silo].v1SecureServiceUrl);
mParticle.getInstance()._Store.SDKConfig.v2SecureServiceUrl.should.equal(URLs[silo].v2SecureServiceUrl);
Expand All @@ -1265,7 +1265,7 @@ describe('core SDK', function() {

mParticle.init(apiKey, window.mParticle.config);
mParticle.getInstance()._Store.SDKConfig.aliasUrl.should.equal(URLs[silo].aliasUrl);
mParticle.getInstance()._Store.SDKConfig.configUrl.should.equal(Constants.DefaultUrls.configUrl);
mParticle.getInstance()._Store.SDKConfig.configUrl.should.equal(Constants.DefaultBaseUrls.configUrl);
mParticle.getInstance()._Store.SDKConfig.identityUrl.should.equal(URLs[silo].identityUrl);
mParticle.getInstance()._Store.SDKConfig.v1SecureServiceUrl.should.equal(URLs[silo].v1SecureServiceUrl);
mParticle.getInstance()._Store.SDKConfig.v2SecureServiceUrl.should.equal(URLs[silo].v2SecureServiceUrl);
Expand Down
26 changes: 13 additions & 13 deletions test/src/tests-store.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from 'chai';
import sinon from 'sinon';
import { SDKInitConfig } from '../../src/sdkRuntimeModels';
import Store, { IStore, SDKConfig, processFlags, processEndpoints, IFeatureFlags } from '../../src/store';
import Store, { IStore, SDKConfig, processFlags, processBaseUrls, IFeatureFlags } from '../../src/store';
import { MPConfig, apiKey } from './config';
import Utils from './utils';
import { Dictionary } from '../../src/utils';
Expand Down Expand Up @@ -230,30 +230,30 @@ describe('Store', () => {
});
});

describe('#processEndpoints', () => {
describe('#processBaseUrls', () => {
describe('directURLRouting === false', () => {
const featureFlags = { directURLRouting: false };

it('should return default endpoints if no endpoints are passed', () => {
const endpoints: Dictionary = Constants.DefaultUrls;
const result = processEndpoints(
it('should return default baseUrls if no baseUrls are passed', () => {
const baseUrls: Dictionary = Constants.DefaultBaseUrls;
const result = processBaseUrls(
{} as unknown as SDKInitConfig,
featureFlags as unknown as IFeatureFlags,
'apikey'
);

expect(result).to.deep.equal(endpoints)
expect(result).to.deep.equal(baseUrls)
});

it('should return non-default endpoints for custom endpoints that are passed', () => {
it('should return non-default baseUrls for custom baseUrls that are passed', () => {
const config = {
v3SecureServiceUrl: 'testtesttest-custom-v3secureserviceurl/v3/JS/',
configUrl: 'foo-custom-configUrl/v2/JS/',
identityUrl: 'custom-identityUrl/',
aliasUrl: 'custom-aliasUrl/',
};

const result = processEndpoints(
const result = processBaseUrls(
config as unknown as SDKInitConfig,
featureFlags as unknown as IFeatureFlags,
'apikey'
Expand All @@ -273,17 +273,17 @@ describe('Store', () => {
});

describe('directURLRouting === true', () => {
it('should return direct urls when no endpoints are passed ', () => {
it('should return direct urls when no baseUrls are passed ', () => {
const featureFlags = {directURLRouting: true};

const result = processEndpoints(
const result = processBaseUrls(
{} as unknown as SDKInitConfig,
featureFlags as unknown as IFeatureFlags,
'apikey'
);

const expectedResult = {
configUrl: Constants.DefaultUrls.configUrl,
configUrl: Constants.DefaultBaseUrls.configUrl,
aliasUrl: "jssdks.us1.mparticle.com/v1/identity/",
identityUrl: "identity.us1.mparticle.com/v1/",
v1SecureServiceUrl: "jssdks.us1.mparticle.com/v1/JS/",
Expand All @@ -299,7 +299,7 @@ describe('Store', () => {
expect(result.v3SecureServiceUrl).to.equal(expectedResult.v3SecureServiceUrl)
});

it('should prioritize passed in endpoints over direct urls', () => {
it('should prioritize passed in baseUrls over direct urls', () => {
const featureFlags = {directURLRouting: true};

const config = {
Expand All @@ -309,7 +309,7 @@ describe('Store', () => {
aliasUrl: 'custom-aliasUrl/',
};

const result = processEndpoints(
const result = processBaseUrls(
config as unknown as SDKInitConfig,
featureFlags as unknown as IFeatureFlags,
'apikey'
Expand Down

0 comments on commit 196b7b8

Please sign in to comment.