Skip to content

Commit

Permalink
Merge pull request #392 from rudderlabs/source-config-api-update
Browse files Browse the repository at this point in the history
writekey added in source config API
  • Loading branch information
saikumarrs authored Dec 26, 2021
2 parents d2aa5c7 + dbc1879 commit 2f48519
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
6 changes: 3 additions & 3 deletions analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import {
getReferrer,
getReferringDomain,
removeTrailingSlashes,
getConfigUrl,
} from "./utils/utils";
import {
CONFIG_URL,
MAX_WAIT_FOR_INTEGRATION_LOAD,
INTEGRATION_LOAD_CHECK_INTERVAL,
DEST_SDK_BASE_URL,
Expand Down Expand Up @@ -971,9 +971,9 @@ class Analytics {
return;
}

let configUrl = CONFIG_URL;
let configUrl = getConfigUrl(writeKey);
if (options && options.configUrl) {
configUrl = getUserProvidedConfigUrl(options.configUrl);
configUrl = getUserProvidedConfigUrl(options.configUrl, configUrl);
}

try {
Expand Down
11 changes: 9 additions & 2 deletions utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,13 +406,13 @@ function type(val) {
return typeof val;
}

function getUserProvidedConfigUrl(configUrl) {
function getUserProvidedConfigUrl(configUrl, defConfigUrl) {
let url = configUrl;
if (url.indexOf("sourceConfig") === -1) {
url = `${removeTrailingSlashes(url)}/sourceConfig/`;
}
url = url.slice(-1) === "/" ? url : `${url}/`;
const defQueryParams = CONFIG_URL.split("?")[1];
const defQueryParams = defConfigUrl.split("?")[1];
const urlSplitItems = url.split("?");
if (urlSplitItems.length > 1 && urlSplitItems[1] !== defQueryParams) {
url = `${urlSplitItems[0]}?${defQueryParams}`;
Expand Down Expand Up @@ -630,6 +630,12 @@ const getDataFromSource = (src, dest, properties) => {
return data;
};

const getConfigUrl = (writeKey) => {
return CONFIG_URL.concat(CONFIG_URL.includes("?") ? "&" : "?").concat(
writeKey ? `writeKey=${writeKey}` : ""
);
};

export {
replacer,
generateUUID,
Expand All @@ -656,4 +662,5 @@ export {
isDefinedAndNotNull,
getDataFromSource,
removeTrailingSlashes,
getConfigUrl,
};

0 comments on commit 2f48519

Please sign in to comment.