Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incognito report #681

Draft
wants to merge 4 commits into
base: first-report
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 3 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
5 changes: 3 additions & 2 deletions tools/reports/news/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
};

const draw = async () => {
const config = getConfig();
const config = await getConfig();

report.filter = {
url: [config.url],
Expand Down Expand Up @@ -222,9 +222,10 @@
initShare(document);
initFilters(document);

const config = getConfig();
const config = await getConfig();

getDetails(config.url).then((details) => {
console.log('LOG: > getDetails > details:', details);

Check warning on line 228 in tools/reports/news/ui.js

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement
const post = document.getElementById('post');
Object.keys(details).forEach((key) => {
const el = post.querySelector(`.post-${key}`);
Expand Down
37 changes: 35 additions & 2 deletions tools/reports/news/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
Loading