Skip to content

Commit 60bbf8e

Browse files
authored
Revert "MWPW-187769: bulk publisher guardrails" (#5479)
Revert "MWPW-187769: bulk publisher guardrails (#5421)" This reverts commit fbdd057.
1 parent 2cd422c commit 60bbf8e

File tree

3 files changed

+37
-106
lines changed

3 files changed

+37
-106
lines changed

libs/blocks/caas/utils.js

Lines changed: 17 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -192,29 +192,6 @@ export function getPageLocale(currentPath, locales = pageLocales) {
192192
return '';
193193
}
194194

195-
let configJson = null;
196-
197-
const cacheByBase = new Map();
198-
199-
export async function getLingoSiteMappingConfig(fqdn = 'www.adobe.com', baseUrl = 'https://www.adobe.com') {
200-
const normalized = baseUrl.replace(/\/$/, '');
201-
const cacheKey = `${normalized}::${fqdn}`;
202-
if (!cacheByBase.has(normalized)) {
203-
const url = `${normalized}/federal/assets/data/lingo-site-mapping.json?${encodeURIComponent(cacheKey)}`;
204-
const promise = fetch(url)
205-
.then((response) => {
206-
if (!response.ok) throw new Error(`HTTP ${response.status}`);
207-
return response.json();
208-
})
209-
.catch((e) => {
210-
cacheByBase.delete(normalized);
211-
throw e;
212-
});
213-
cacheByBase.set(normalized, promise);
214-
}
215-
return cacheByBase.get(normalized);
216-
}
217-
218195
export const isValidUuid = (id) => /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/.test(id);
219196

220197
export const loadStrings = async (
@@ -569,9 +546,11 @@ const isLocaleInRegionalSites = (regionalSites, locStr) => {
569546
.includes(locStr);
570547
};
571548

572-
export async function getIsLingoLocale(origin, country, language, fqdn = 'www.adobe.com') {
549+
async function getIsLingoLocale(origin, country, language, fqdn = 'www.adobe.com') {
573550
if (origin === 'news') return true;
574-
if (!configJson) configJson = await getLingoSiteMappingConfig(fqdn);
551+
const response = await fetch(`https://www.adobe.com/federal/assets/data/lingo-site-mapping.json?${fqdn}`);
552+
if (!response.ok) throw new Error(`HTTP ${response.status}`);
553+
const configJson = await response.json();
575554

576555
let siteId;
577556
let isKnownLingoSiteLocale = false;
@@ -624,16 +603,13 @@ async function getLangFirstParam(origin, country, language) {
624603
return true;
625604
}
626605

627-
async function getLingoSiteLocale(origin, path, fqdn = 'www.adobe.com', fromBulkPublisher = false) {
606+
async function getLingoSiteLocale(origin, path, fqdn = 'www.adobe.com') {
628607
const host = origin.toLowerCase();
629-
let lingoSiteMapping;
630-
// only provide fallback values if not from the bulk publisher
631-
if (!fromBulkPublisher) {
632-
lingoSiteMapping = {
633-
country: 'xx',
634-
language: 'en',
635-
};
636-
}
608+
let lingoSiteMapping = {
609+
country: 'xx',
610+
language: 'en',
611+
};
612+
637613
// Extract pathname from URL if path includes domain
638614
let pathname = path;
639615
if (path.includes('://') || !path.startsWith('/')) {
@@ -653,7 +629,9 @@ async function getLingoSiteLocale(origin, path, fqdn = 'www.adobe.com', fromBulk
653629

654630
try {
655631
let siteId;
656-
if (!configJson) configJson = await getLingoSiteMappingConfig(fqdn);
632+
const response = await fetch(`https://www.adobe.com/federal/assets/data/lingo-site-mapping.json?${fqdn}`);
633+
if (!response.ok) throw new Error(`HTTP ${response.status}`);
634+
const configJson = await response.json();
657635

658636
const siteQueryIndexMap = configJson['site-query-index-map']?.data ?? [];
659637
const siteLocalesData = configJson['site-locales']?.data ?? [];
@@ -708,31 +686,18 @@ async function getLingoSiteLocale(origin, path, fqdn = 'www.adobe.com', fromBulk
708686
return lingoSiteMapping;
709687
}
710688

711-
export const getLanguageFirstCountryAndLang = async (
712-
path,
713-
origin,
714-
fqdn,
715-
fromBulkPublisher = false,
716-
) => {
689+
export const getLanguageFirstCountryAndLang = async (path, origin, fqdn) => {
717690
const localeArr = path.split('/');
718-
let langStr;
719-
let countryStr;
720-
// only provide fallback values if not from the bulk publisher
721-
if (!fromBulkPublisher) {
722-
langStr = 'en';
723-
countryStr = 'xx';
724-
}
691+
let langStr = 'en';
692+
let countryStr = 'xx';
725693
if (origin.toLowerCase() === 'news') {
726694
langStr = LANGS[localeArr[1]] ?? LANGS[''] ?? 'en';
727695
countryStr = LOCALES[localeArr[2]] ?? 'xx';
728696
if (typeof countryStr === 'object') {
729697
countryStr = countryStr.ietf?.split('-')[1] ?? 'xx';
730698
}
731699
} else {
732-
const mapping = await getLingoSiteLocale(origin, path, fqdn, fromBulkPublisher);
733-
if (!mapping) {
734-
throw new Error('Failed to get lingo site locale for bulk publisher');
735-
}
700+
const mapping = await getLingoSiteLocale(origin, path, fqdn);
736701
countryStr = LOCALES[mapping.country.toLowerCase()] ?? 'xx';
737702
if (typeof countryStr === 'object') {
738703
countryStr = countryStr.ietf?.split('-')[1] ?? 'xx';

test/blocks/caas/utils.test.js

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,6 @@ import {
1313
getGrayboxExperienceId,
1414
} from '../../../libs/blocks/caas/utils.js';
1515

16-
// Mock lingo-site-mapping.json for test runner
17-
(function patchFetchForLingoMapping() {
18-
const orig = window.fetch;
19-
const defaultLingoMock = () => Promise.resolve({
20-
ok: true,
21-
json: () => Promise.resolve({
22-
'site-query-index-map': { data: [] },
23-
'site-locales': { data: [] },
24-
}),
25-
});
26-
window.fetch = function patchedFetch(resource, options) {
27-
const url = typeof resource === 'string' ? resource : (resource?.url ?? resource?.href ?? '');
28-
if (url.includes('lingo-site-mapping.json')) {
29-
return defaultLingoMock();
30-
}
31-
return orig.call(window, resource, options);
32-
};
33-
}());
34-
3516
describe('utils.js export sanity', () => {
3617
it('getLingoActive() is callable and returns a boolean', async () => {
3718
const val = await getLingoActive();

tools/send-to-caas/send-utils.js

Lines changed: 20 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
getPageLocale,
66
getGrayboxExperienceId,
77
getLanguageFirstCountryAndLang,
8-
getIsLingoLocale,
98
} from '../../libs/blocks/caas/utils.js';
109

1110
const CAAS_TAG_URL = 'https://www.adobe.com/chimera-api/tags';
@@ -306,15 +305,7 @@ const getBulkPublishLangAttr = async (options) => {
306305
options.prodUrl,
307306
options.repo,
308307
options.host,
309-
true,
310308
);
311-
if (!country || !lang) {
312-
throw new Error('Failed to get lang-first locales for bulk publisher');
313-
}
314-
const isLingoLocale = await getIsLingoLocale(options.repo, country, lang);
315-
if (!isLingoLocale) {
316-
throw new Error(`This page is not a valid language-first case for repo: ${options.repo}, country: ${country}, language: ${lang}`);
317-
}
318309
return `${lang}-${country}`;
319310
}
320311
if (!getLocale) {
@@ -328,22 +319,6 @@ const getBulkPublishLangAttr = async (options) => {
328319
};
329320

330321
const getCountryAndLang = async (options, origin) => {
331-
let langAttr;
332-
/* c8 ignore next */
333-
if (window.location.pathname.includes('/tools/send-to-caas/bulkpublisher')) {
334-
const langStr = window.location.pathname.includes('/tools/send-to-caas/bulkpublisher')
335-
? await getBulkPublishLangAttr(options)
336-
: (LOCALES[window.location.pathname.split('/')[1]] || LOCALES['']).ietf;
337-
langAttr = langStr?.toLowerCase().split('-') || [];
338-
// do not use the fallback values if the language first is enabled
339-
if (options.languageFirst) {
340-
const [lang, country] = langAttr;
341-
return {
342-
country,
343-
lang,
344-
};
345-
}
346-
}
347322
const langFirst = lingoActive();
348323
if (langFirst) {
349324
return getLanguageFirstCountryAndLang(
@@ -352,6 +327,12 @@ const getCountryAndLang = async (options, origin) => {
352327
window.location.hostname,
353328
);
354329
}
330+
/* c8 ignore next */
331+
const langStr = window.location.pathname.includes('/tools/send-to-caas/bulkpublisher')
332+
? await getBulkPublishLangAttr(options)
333+
: (LOCALES[window.location.pathname.split('/')[1]] || LOCALES['']).ietf;
334+
const langAttr = langStr?.toLowerCase().split('-') || [];
335+
355336
const [lang = 'en', country = 'us'] = langAttr;
356337
return {
357338
country,
@@ -409,14 +390,6 @@ function localizeCtaUrl(val) {
409390
return val;
410391
}
411392

412-
const makeCountryLangResolver = (key) => async (s, options) => {
413-
if (s) return s;
414-
const fgColor = options.floodgatecolor || getMetadata('floodgatecolor');
415-
const origin = getOrigin(fgColor);
416-
const result = await getCountryAndLang(options, origin);
417-
return result[key];
418-
};
419-
420393
/** card metadata props - either a func that computes the value or
421394
* 0 to use the string as is
422395
* funcs that return an object with { error: string } will report the error
@@ -442,7 +415,13 @@ const props = {
442415
cardimagealttext: (s) => s || getCardImageAltText(),
443416
contentid: (_, options) => getUuid(options.prodUrl),
444417
contenttype: (s) => s || getMetaContent('property', 'og:type') || getConfig().contentType,
445-
country: makeCountryLangResolver('country'),
418+
country: async (s, options) => {
419+
if (s) return s;
420+
const fgColor = options.floodgatecolor || getMetadata('floodgatecolor');
421+
const origin = getOrigin(fgColor);
422+
const { country } = await getCountryAndLang(options, origin);
423+
return country;
424+
},
446425
created: (s) => {
447426
if (s) {
448427
return getDateProp(s, `Invalid Created Date: ${s}`);
@@ -480,7 +459,13 @@ const props = {
480459
eventend: (s) => getDateProp(s, `Invalid Event End Date: ${s}`),
481460
eventstart: (s) => getDateProp(s, `Invalid Event Start Date: ${s}`),
482461
floodgatecolor: (s, options) => s || options.floodgatecolor || getMetadata('floodgatecolor') || 'default',
483-
lang: makeCountryLangResolver('lang'),
462+
lang: async (s, options) => {
463+
if (s) return s;
464+
const fgColor = options.floodgatecolor || getMetadata('floodgatecolor');
465+
const origin = getOrigin(fgColor);
466+
const { lang } = await getCountryAndLang(options, origin);
467+
return lang;
468+
},
484469
modified: (s) => {
485470
const { doc, lastModified } = getConfig();
486471
return s

0 commit comments

Comments
 (0)