From 6dbd40b743940cf48a30d1521e7d0ba7ad2c723b Mon Sep 17 00:00:00 2001 From: fkakatie Date: Thu, 14 Nov 2024 13:54:11 -0700 Subject: [PATCH 1/2] feat: missing domain key fallback --- tools/reports/news/ui.js | 5 +++-- tools/reports/news/utils.js | 37 +++++++++++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/tools/reports/news/ui.js b/tools/reports/news/ui.js index 228b642b..a6ffbfe6 100644 --- a/tools/reports/news/ui.js +++ b/tools/reports/news/ui.js @@ -99,7 +99,7 @@ const getGlobalFilters = () => { }; const draw = async () => { - const config = getConfig(); + const config = await getConfig(); report.filter = { url: [config.url], @@ -222,9 +222,10 @@ const main = async () => { initShare(document); initFilters(document); - const config = getConfig(); + const config = await getConfig(); getDetails(config.url).then((details) => { + console.log('LOG: > getDetails > details:', details); const post = document.getElementById('post'); Object.keys(details).forEach((key) => { const el = post.querySelector(`.post-${key}`); diff --git a/tools/reports/news/utils.js b/tools/reports/news/utils.js index 74006cb0..fcde938c 100644 --- a/tools/reports/news/utils.js +++ b/tools/reports/news/utils.js @@ -20,10 +20,43 @@ const getDomain = () => { return hostname; }; -const getConfig = () => { +const getDomainKey = async (domain) => { + const urlKey = searchParams.get('domainkey'); + if (!urlKey || urlKey === 'incognito' || urlKey === 'null') { + const rum = 'https://rum.fastly-aem.page'; + try { + const auth = localStorage.getItem('rum-bundler-token'); + const res = await fetch(`${rum}/domainkey/${domain}`, { + headers: { + authorization: `Bearer ${auth}`, + }, + }); + if (res.ok) { + const json = await res.json(); + return json.domainkey; + } + // probe for open access + const n = new Date(); + const y = n.getFullYear(); + const m = String(n.getMonth() + 1).padStart(2, '0'); + const d = String(n.getDate()).padStart(2, '0'); + const probe = await fetch(`${rum}/bundles/${domain}/${y}/${m}/${d}?domainkey=open`); + if (probe.ok) { + return 'open'; + } + throw probe; + } catch (error) { + return 'error'; + } + } else { + return urlKey; + } +}; + +const getConfig = async () => { const config = { domain: getDomain(), - domainKey: searchParams.get('domainkey') || '', + domainKey: await getDomainKey(getDomain()), apiEndpoint: API_ENDPOINT, start: searchParams.get('start'), end: searchParams.get('end'), From ab56a7200fe5efd66ee1b27f61463dbc4202c78c Mon Sep 17 00:00:00 2001 From: kptdobe Date: Mon, 18 Nov 2024 16:58:49 +0100 Subject: [PATCH 2/2] fix: remove domain hashes --- tools/reports/news/news.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tools/reports/news/news.js b/tools/reports/news/news.js index 88ec40d7..559c67af 100644 --- a/tools/reports/news/news.js +++ b/tools/reports/news/news.js @@ -70,7 +70,18 @@ class URLReports { dataChunks.addFacet('referer', (bundle) => bundle.events .filter((evt) => evt.checkpoint === 'enter') .map((evt) => evt.source) - .filter((source) => source)); + .filter((source) => (source)) + .map((source) => { + try { + const u = new URL(source); + u.hash = ''; + u.search = ''; + return u.toString(); + } catch (error) { + // ignore + } + return source; + })); const possiblePrefixes = []; const s = new Date(this.start);