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
9 changes: 6 additions & 3 deletions scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,16 @@ export function setLibs(location) {
}

export function getMarketoLibs(location = window.location, getMetadata = null) {
const { search } = location;
const { search, hostname } = location;
const branch = new URLSearchParams(search).get('marketolibs') || getMetadata?.('marketo-libs');
if (!branch) return null;
if (!/^[a-zA-Z0-9_-]+$/.test(branch)) throw new Error('Invalid branch name.');

if (!['.aem.', '.hlx.', '.stage.', 'local', '.da.'].some((i) => hostname.includes(i))) {
if (branch === 'main') return 'https://main--da-marketo--adobecom.aem.live/mkto';
if (branch === 'stage') return 'https://stage--da-marketo--adobecom.aem.live/mkto';
return null;
}
if (branch === 'local') return 'http://localhost:6586/mkto';
if (branch === 'main') return 'https://main--da-marketo--adobecom.aem.live/mkto';
return branch.includes('--') ? `https://${branch}.aem.live/mkto` : `https://${branch}--da-marketo--adobecom.aem.live/mkto`;
}

Expand Down
13 changes: 10 additions & 3 deletions test/scripts/scripts.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,18 @@ describe('injectMarqueePlayIcon', () => {
describe('Marketo Libs', () => {
const tests = [
['https://business.adobe.com', '', null],
['https://business.adobe.com?marketolibs=main', '', 'https://main--da-marketo--adobecom.aem.live/mkto'],
['https://business.adobe.com?marketolibs=stage', '', 'https://stage--da-marketo--adobecom.aem.live/mkto'],
['https://business.adobe.com?marketolibs=foo', '', null],
['https://business.adobe.com?marketolibs=awesome--da-marketo--forkedowner', '', null],
['https://business.adobe.com', 'main', 'https://main--da-marketo--adobecom.aem.live/mkto'],
['https://business.adobe.com?marketolibs=foo', '', 'https://foo--da-marketo--adobecom.aem.live/mkto'],
['https://business.adobe.com', 'stage', 'https://stage--da-marketo--adobecom.aem.live/mkto'],
['https://business.adobe.com', 'local', null],
['https://business.adobe.com', 'foo', null],
['https://business.stage.adobe.com', '', null],
['https://business.stage.adobe.com?marketolibs=foo', '', 'https://foo--da-marketo--adobecom.aem.live/mkto'],
['https://business.stage.adobe.com?marketolibs=main', '', 'https://main--da-marketo--adobecom.aem.live/mkto'],
['https://business.stage.adobe.com?marketolibs=awesome--da-marketo--forkedowner', '', 'https://awesome--da-marketo--forkedowner.aem.live/mkto'],
['https://business.stage.adobe.com', 'awesome--da-marketo--forkedowner', 'https://awesome--da-marketo--forkedowner.aem.live/mkto'],
['https://main--da-bacom--adobecom.aem.page/', '', null],
['https://main--da-bacom--adobecom.aem.page/?marketolibs=foo', '', 'https://foo--da-marketo--adobecom.aem.live/mkto'],
['https://main--da-bacom--adobecom.aem.page/?marketolibs=local', '', 'http://localhost:6586/mkto'],
Expand All @@ -263,7 +270,7 @@ describe('Marketo Libs', () => {
];

tests.forEach(([url, metadata, expected]) => {
it(`Sets marketo libs for ${url} with metadata ${metadata}`, () => {
it(`Sets marketo libs for ${url} ${metadata ? `with metadata ${metadata}` : ''}`, () => {
const location = new URL(url);
const libs = getMarketoLibs(location, () => metadata);

Expand Down
Loading