Skip to content
Open
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
1 change: 0 additions & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
npx lint-staged
npm test

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems unintentional?

2 changes: 1 addition & 1 deletion nx/blocks/loc/connectors/glaas/api.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import makeBatches from '../../../../public/utils/batch.js';
import makeBatches from '../../../../../nx2/public/utils/batch.js';

export async function throttle(ms = 500) {
return new Promise((resolve) => {
Expand Down
2 changes: 1 addition & 1 deletion nx/blocks/loc/connectors/glaas/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Queue } from '../../../../public/utils/tree.js';
import { Queue } from '../../../../../nx2/public/utils/tree.js';
import {
checkSession, createTask, addAssets, updateStatus, getTask, downloadAsset,
prepareTargetPreview, getGlaasFilename,
Expand Down
12 changes: 6 additions & 6 deletions nx/blocks/loc/connectors/glaas/multimodalApi.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DA_ORIGIN } from '../../../../public/utils/constants.js';
import { Queue } from '../../../../public/utils/tree.js';
import { daFetch } from '../../../../utils/daFetch.js';
import { DA_ADMIN } from '../../../../../nx2/utils/utils.js';
import { Queue } from '../../../../../nx2/public/utils/tree.js';
import { daFetch } from '../../../../../nx2/utils/api.js';
import {
buildGlaasCreateMetadata, getOpts, glaasSourcePreviewUrl, throttle,
} from './api.js';
Expand Down Expand Up @@ -430,7 +430,7 @@

/** Map delivery URL to DA Admin source (same path after /source/). */
export function contentDaLiveToDaSourceUrl(imageUrl) {
return imageUrl.replace(CONTENT_DA_LIVE_ORIGIN, `${DA_ORIGIN}/source`);
return imageUrl.replace(CONTENT_DA_LIVE_ORIGIN, `${DA_ADMIN}/source`);
}

export function contentDaLivePathKey(href) {
Expand Down Expand Up @@ -650,7 +650,7 @@
logRequest?.('fetch-image', { imageIndex, contentDaLiveUrl: imageUrl, daSourceUrl: imageSourceUrl });
let imageResp;
try {
imageResp = await daFetch(imageSourceUrl);
imageResp = await daFetch({ url: imageSourceUrl });
} catch {
return { error: 'Error fetching content.da.live image.', step: `fetch-image-${imageIndex}` };
}
Expand Down Expand Up @@ -867,12 +867,12 @@
};
logRequest?.('media-image-size', detail);
if (!logRequest) {
console.info('[GLaaS multimodal] Media image upload size:', detail);

Check warning on line 870 in nx/blocks/loc/connectors/glaas/multimodalApi.js

View workflow job for this annotation

GitHub Actions / Running tests (20.x)

Unexpected console statement
}
if (exceedsUploadLimit) {
console.warn('[GLaaS multimodal] Image exceeds observed Media Bus upload limit:', detail);

Check warning on line 873 in nx/blocks/loc/connectors/glaas/multimodalApi.js

View workflow job for this annotation

GitHub Actions / Running tests (20.x)

Unexpected console statement
} else if (exceedsDocumentedLimit) {
console.warn('[GLaaS multimodal] Image exceeds documented Media Bus limit:', detail);

Check warning on line 875 in nx/blocks/loc/connectors/glaas/multimodalApi.js

View workflow job for this annotation

GitHub Actions / Running tests (20.x)

Unexpected console statement
}
return detail;
}
Expand Down Expand Up @@ -913,7 +913,7 @@
const body = new FormData();
body.append('data', data, mediaPath.split('/').pop());
try {
const resp = await daFetch(`${DA_ORIGIN}/media/${org}/${site}${mediaPath}`, { method: 'POST', body });
const resp = await daFetch({ url: `${DA_ADMIN}/media/${org}/${site}${mediaPath}`, opts: { method: 'POST', body } });
if (!resp.ok) {
if (resp.status === 413) {
return skippedOversizedMediaUpload({ glaasName, sizeCheck });
Expand Down Expand Up @@ -960,7 +960,7 @@
maxFormatted: uploaded.maxFormatted,
};
logRequest?.('media-image-skip', detail);
console.warn('[GLaaS multimodal] Skipping oversized image (keeping source URL):', detail);

Check warning on line 963 in nx/blocks/loc/connectors/glaas/multimodalApi.js

View workflow job for this annotation

GitHub Actions / Running tests (20.x)

Unexpected console statement
return {
skipped: true,
glaasName: image.glaasName,
Expand Down
16 changes: 8 additions & 8 deletions nx/blocks/loc/connectors/glaas/translationMetadata.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DA_ORIGIN } from '../../../../public/utils/constants.js';
import { daFetch } from '../../../../utils/daFetch.js';
import { DA_ADMIN } from '../../../../../nx2/utils/utils.js';
import { daFetch } from '../../../../../nx2/utils/api.js';

const BLOCK_SCHEMA_PATH = '/.da/block-schema.json';
const SEO_GLOSSARY_PATH = '/.da/seo/glossary.json';
Expand Down Expand Up @@ -80,9 +80,9 @@ export function parseBlockSchema(schemaData) {
}

async function fetchJson(org, site, relativePath) {
const url = `${DA_ORIGIN}/source/${org}/${site}${relativePath}`;
const url = `${DA_ADMIN}/source/${org}/${site}${relativePath}`;
try {
const resp = await daFetch(url);
const resp = await daFetch({ url });
if (!resp.ok) return null;
return resp.json();
} catch (error) {
Expand Down Expand Up @@ -112,17 +112,17 @@ export async function fetchKeywordsFile(org, site, pagePath) {
const cleanPath = pagePath.replace(/\.html$/, '');
const keywordsPath = `${cleanPath}-keywords.json`;
// Try primary path
let url = `${DA_ORIGIN}/source/${org}/${site}${keywordsPath}`;
let url = `${DA_ADMIN}/source/${org}/${site}${keywordsPath}`;
try {
const resp = await daFetch(url);
const resp = await daFetch({ url });
if (resp.ok) {
return resp.json();
}
// If 404 and path contains /langstore/, try fallback
if (resp.status === 404 && keywordsPath.includes('/langstore/')) {
const fallbackPath = keywordsPath.replace(/\/langstore\/[^/]+\//, '/');
url = `${DA_ORIGIN}/source/${org}/${site}${fallbackPath}`;
const fallbackResp = await daFetch(url);
url = `${DA_ADMIN}/source/${org}/${site}${fallbackPath}`;
const fallbackResp = await daFetch({ url });
if (fallbackResp.ok) {
return fallbackResp.json();
}
Expand Down
2 changes: 1 addition & 1 deletion nx/blocks/loc/connectors/google/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { addDnt, removeDnt } from '../../dnt/dnt.js';
import { Queue } from '../../../../public/utils/tree.js';
import { Queue } from '../../../../../nx2/public/utils/tree.js';
import { convertPath } from '../../utils/utils.js';

const MAX_LENGTH = 5000;
Expand Down
2 changes: 1 addition & 1 deletion nx/blocks/loc/connectors/smartling/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Queue } from '../../../../public/utils/tree.js';
import { Queue } from '../../../../../nx2/public/utils/tree.js';
import { addDnt, removeDnt } from '../../dnt/dnt.js';

export const dnt = { addDnt };
Expand Down
4 changes: 2 additions & 2 deletions nx/blocks/loc/connectors/trados/auth.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { daFetch } from '../../../../utils/daFetch.js';
import { daFetch } from '../../../../../nx2/utils/api.js';

const LOGIN_ORIGIN = 'https://da-etc.adobeaem.workers.dev';
const TOKEN_BUFFER = 300000; // 5 min buffer before expiry
Expand Down Expand Up @@ -32,7 +32,7 @@ export async function getAccessToken(service) {

const opts = { method: 'POST' };

const resp = await daFetch(`${LOGIN_ORIGIN}/${org}/sites/${site}/integrations/trados/login`, opts);
const resp = await daFetch({ url: `${LOGIN_ORIGIN}/${org}/sites/${site}/integrations/trados/login`, opts });
if (!resp.ok) return null;

const { access_token: accessToken, expires_in: expiresIn } = await resp.json();
Expand Down
2 changes: 1 addition & 1 deletion nx/blocks/loc/connectors/trados/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Queue } from '../../../../public/utils/tree.js';
import { Queue } from '../../../../../nx2/public/utils/tree.js';
import { addDnt, removeDnt } from '../../dnt/dnt.js';
import authReady, { getAccessToken } from './auth.js';
import { corsFetch } from './utils.js';
Expand Down
6 changes: 3 additions & 3 deletions nx/blocks/loc/loc.css
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
:host {
display: block;
color: var(--s2-gray-900);
font-size: var(--type-body-s-size);
font-size: var(--s2-body-size-s);
}

.nx-loc-step {
display: block;
max-width: var(--grid-container-width);
margin: 0 auto var(--spacing-500) auto;
max-width: var(--se-grid-container-width);
margin: 0 auto var(--s2-spacing-500) auto;
}
15 changes: 6 additions & 9 deletions nx/blocks/loc/loc.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { LitElement, html, nothing } from 'da-lit';
import { getConfig } from '../../scripts/nexter.js';
import getStyle from '../../utils/styles.js';
import { getHashDetails, loadProject, updateProject } from './utils/utils.js';

import '../../public/sl/components.js';
import { loadStyle } from '../../../nx2/scripts/nx.js';

import './views/header/header.js';
import './views/steps/steps.js';
Expand All @@ -18,11 +15,11 @@ import './views/rollout/rollout.js';
import './views/complete/complete.js';
import './views/url-details/url-details.js';

import '../../../nx2/public/sl/components.js';

const EL_NAME = 'nx-loc';

const { nxBase: nx } = getConfig();
const sl = await getStyle(`${nx}/public/sl/styles.css`);
const styles = await getStyle(import.meta.url);
const styles = await loadStyle(import.meta.url);

class NxLoc extends LitElement {
static properties = {
Expand All @@ -36,7 +33,7 @@ class NxLoc extends LitElement {

connectedCallback() {
super.connectedCallback();
this.shadowRoot.adoptedStyleSheets = [sl, styles];
this.shadowRoot.adoptedStyleSheets = [styles];
}

update(props) {
Expand Down Expand Up @@ -178,7 +175,7 @@ function handleHashCallback() {
}

export default function init(el) {
el.innerHTML = '';
el.replaceChildren();
handleHashCallback();
setup(el);
window.addEventListener('hashchange', () => { setup(el); });
Expand Down
85 changes: 59 additions & 26 deletions nx/blocks/loc/project/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import getElementMetadata from '../../../utils/getElementMetadata.js';
import getElementMetadata from '../../../../nx2/utils/getElementMetadata.js';
import { regionalDiff, removeLocTags } from '../regional-diff/regional-diff.js';
import { daFetch, saveToDa } from '../../../utils/daFetch.js';
import { DA_ORIGIN } from '../../../public/utils/constants.js';
import { Queue } from '../../../public/utils/tree.js';
import { daFetch, source as daSource } from '../../../../nx2/utils/api.js';
import { DA_ADMIN } from '../../../../nx2/utils/utils.js';
import { Queue } from '../../../../nx2/public/utils/tree.js';

// Max concurrent /source/ reads from da-admin. Prevents flooding da-admin
// with OPTIONS+GET bursts during content scans (translate, rollout, validate).
Expand All @@ -28,7 +28,7 @@ let projPath;
let projJson;

async function fetchData(path) {
const resp = await daFetch(path);
const resp = await daFetch({ url: path });
if (!resp.ok) return null;
return resp.json();
}
Expand Down Expand Up @@ -88,7 +88,7 @@ export async function detectService(config, env = 'stage') {

export async function getDetails() {
projPath = window.location.hash.replace('#', '');
const data = await fetchData(`${DA_ORIGIN}/source${projPath}.json`);
const data = await fetchData(`${DA_ADMIN}/source${projPath}.json`);
return data;
}

Expand All @@ -110,7 +110,7 @@ export async function saveStatus(json) {
const file = new Blob([JSON.stringify(proj)], { type: 'application/json' });
body.append('data', file);
const opts = { body, method: 'POST' };
const resp = await daFetch(`${DA_ORIGIN}/source${projPath}.json`, opts);
const resp = await daFetch({ url: `${DA_ADMIN}/source${projPath}.json`, opts });
if (!resp.ok) return { error: 'Could not update project' };
return json;
}
Expand All @@ -125,7 +125,7 @@ async function saveVersion(path, label) {
try {
const opts = { method: 'POST' };
if (label) opts.body = JSON.stringify({ label });
await daFetch(`${DA_ORIGIN}/versionsource${path}`, opts);
await daFetch({ url: `${DA_ADMIN}/versionsource${path}`, opts });
} finally {
versionSaving.delete(path);
}
Expand All @@ -146,7 +146,7 @@ function collapseInnerTextSpaces(html) {

const getHtml = async (path, html) => {
const fetchHtml = async () => {
const res = await daFetch(`${DA_ORIGIN}/source${path}`);
const res = await daFetch({ url: `${DA_ADMIN}/source${path}` });
if (!res.ok) return null;
const str = await res.text();
return str;
Expand All @@ -163,6 +163,43 @@ const getDaUrl = (url) => {
return { org, repo, pathname };
};

function replaceHtml(text, fromOrg, fromRepo, options = {}) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you double-check whether we already have a similar function in nx2, and if yes move to a shared utils location?

const { daMetadata = {}, replaceRelative = true } = options;
let inner = text;

if (fromOrg && fromRepo && replaceRelative) {
const fromOrigin = `https://main--${fromRepo}--${fromOrg}.aem.live`;
inner = text
.replaceAll('./media', `${fromOrigin}/media`)
.replaceAll('href="/', `href="${fromOrigin}/`);
}

let metadataHTML = '';
if (Object.keys(daMetadata).length > 0) {
const daRows = Object.entries(daMetadata)
.map(([key, value]) => {
const textContent = value?.text ?? value ?? '';
return `<div><div>${key}</div><div>${textContent}</div></div>`;
})
.join('');
metadataHTML = `\n <div class="da-metadata">${daRows}</div>\n`;
}

return `
<body>
<header></header>
<main>${inner}</main>
${metadataHTML}<footer></footer>
</body>
`;
}

function saveHtml(url, content, { daMetadata = {}, replaceRelative = false } = {}) {
const { org, repo, pathname } = getDaUrl(url);
const body = replaceHtml(content, org, repo, { daMetadata, replaceRelative });
return daSource.save({ org, site: repo, path: `${pathname}.html`, body });
}

export async function overwriteCopy(url, title) {
let resp;
if (url.sourceContent) {
Expand All @@ -173,19 +210,15 @@ export async function overwriteCopy(url, title) {
body: new FormData(),
};
opts.body.append('data', blob);
resp = await daFetch(`${DA_ORIGIN}/source${url.destination}`, opts);
resp = await daFetch({ url: `${DA_ADMIN}/source${url.destination}`, opts });
} else {
const srcHtml = await getHtml(url.source);
if (srcHtml) {
removeLocTags(srcHtml);
const daMetadata = getElementMetadata(srcHtml.querySelector(DA_METADATA_SELECTOR));
delete daMetadata?.acceptedhashes;
delete daMetadata?.rejectedhashes;
resp = await saveToDa(
srcHtml.querySelector('main').innerHTML,
getDaUrl(url),
{ daMetadata, replaceRelative: false },
);
resp = await saveHtml(url, srcHtml.querySelector('main').innerHTML, { daMetadata });
}
}

Expand Down Expand Up @@ -245,15 +278,14 @@ export async function rolloutCopy(
if (labelUpstream) daMetadata['diff-label-upstream'] = labelUpstream;

return new Promise((resolve) => {
const daUrl = getDaUrl(url);
const savePromise = saveToDa(diffed.innerHTML, daUrl, { daMetadata, replaceRelative: false });
const savePromise = saveHtml(url, diffed.innerHTML, { daMetadata });

const timedout = setTimeout(() => {
url.status = 'timeout';
resolve('timeout');
}, DEFAULT_TIMEOUT);

savePromise.then(({ daResp }) => {
savePromise.then((daResp) => {
clearTimeout(timedout);
url.status = daResp.ok ? 'success' : 'error';
if (daResp.ok) {
Expand Down Expand Up @@ -307,12 +339,7 @@ export async function mergeCopy(
if (labelLocal) daMetadata['diff-label-local'] = labelLocal;
if (labelUpstream) daMetadata['diff-label-upstream'] = labelUpstream;

const daUrl = getDaUrl(url);
const { daResp } = await saveToDa(
diffed.innerHTML,
daUrl,
{ daMetadata, replaceRelative: false },
);
const daResp = await saveHtml(url, diffed.innerHTML, { daMetadata });
if (daResp.ok) {
url.status = 'success';
saveVersion(url.destination, `${projectTitle} - Rolled Out`);
Expand All @@ -338,8 +365,14 @@ export async function saveLangItems(sitePath, items, lang, removeDnt) {
const body = new FormData();
body.append('data', blob);
const opts = { body, method: 'POST' };
const resp = await daFetch(`${DA_ORIGIN}/source${path}`, opts);
results[idx] = { success: resp.status };
try {
const resp = await daFetch({ url: `${DA_ADMIN}/source${path}`, opts });
results[idx] = resp.ok
? { success: resp.status }
: { error: 'Could not save item.', status: resp.status };
} catch (e) {
results[idx] = { error: e.message };
}
}, MAX_CONCURRENT_WRITES);

await Promise.all(items.map((item, idx) => queue.push({ item, idx })));
Expand Down
2 changes: 1 addition & 1 deletion nx/blocks/loc/project/project.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
:host {
display: block;
max-width: var(--grid-container-width);
max-width: var(--se-grid-container-width);
margin: var(--spacing-800) auto;
}

Expand Down
6 changes: 3 additions & 3 deletions nx/blocks/loc/project/project.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { LitElement, html, nothing } from '../../../deps/lit/dist/index.js';
import getStyle from '../../../utils/styles.js';
import { LitElement, html, nothing } from 'da-lit';
import { loadStyle } from '../../../../nx2/utils/utils.js';
import { getDetails } from './index.js';

const style = await getStyle(import.meta.url);
const style = await loadStyle(import.meta.url);

class NxLocProject extends LitElement {
static properties = {
Expand Down
Loading
Loading