From 669c6927517f091ad5f3ebf32d264433d9f5955b Mon Sep 17 00:00:00 2001 From: Ben Peter Date: Sat, 10 Oct 2026 00:08:03 +0200 Subject: [PATCH 01/28] test(quick-edit): cover hlx6 source url, collab room, image upload and preview red: the portal hardcodes admin.da.live for the document, the room name and the image upload, and admin.hlx.page for preview, so it can't open hlx6 (source bus) documents. the lint disables on the two missing imports go away with the fix. --- .../blocks/quick-edit-portal/images.test.js | 90 +++++++++++++-- .../blocks/quick-edit-portal/source.test.js | 107 ++++++++++++++++++ .../nx/blocks/quick-edit-portal/utils.test.js | 65 +++++++++++ test/nx2/utils/api.test.js | 29 +++++ 4 files changed, 279 insertions(+), 12 deletions(-) create mode 100644 test/nx/blocks/quick-edit-portal/source.test.js create mode 100644 test/nx/blocks/quick-edit-portal/utils.test.js diff --git a/test/nx/blocks/quick-edit-portal/images.test.js b/test/nx/blocks/quick-edit-portal/images.test.js index 58168c194..f0ca71b95 100644 --- a/test/nx/blocks/quick-edit-portal/images.test.js +++ b/test/nx/blocks/quick-edit-portal/images.test.js @@ -3,6 +3,20 @@ import { Schema } from 'prosemirror-model'; import { EditorState } from 'prosemirror-state'; import { handleImageReplace } from '../../../../nx/blocks/quick-edit-portal/src/images.js'; import { getImageDocumentVersion } from '../../../../nx2/public/utils/quick-edit-images.js'; +import { AEM_API, DA_ADMIN, HLX_ADMIN } from '../../../../nx2/utils/utils.js'; + +const daUploadResponse = (url) => { + const { pathname } = new URL(url); + const contentUrl = `https://content.da.live${pathname.replace(/^\/source/, '')}`; + return new Response(JSON.stringify({ source: { contentUrl } }), { status: 201 }); +}; + +const mockFetch = (onUpload) => { + window.fetch = async (url, opts = {}) => { + if (url.startsWith(`${HLX_ADMIN}/ping/`)) return new Response('', { status: 200 }); + return onUpload(url, opts); + }; +}; describe('standalone quick-edit image replacement', () => { const imageData = 'data:image/png;base64,iVBORw0KGgo='; @@ -17,10 +31,10 @@ describe('standalone quick-edit image replacement', () => { beforeEach(() => { savedFetch = window.fetch; uploads = []; - window.fetch = async (url, opts) => { + mockFetch(async (url, opts) => { uploads.push({ url, opts }); - return new Response('', { status: 201 }); - }; + return daUploadResponse(url); + }); const schema = new Schema({ nodes: { doc: { content: 'block+' }, @@ -86,13 +100,13 @@ describe('standalone quick-edit image replacement', () => { }); it('tracks the intended image past a concurrent edit and an identical URL', async () => { - window.fetch = async () => { + mockFetch(async (url) => { uploads.push(true); ctx.view.dispatch(state.tr.insert(3, state.schema.nodes.image.create({ src: '/same.png', alt: 'New image', }))); - return new Response('', { status: 201 }); - }; + return daUploadResponse(url); + }); await handleImageReplace(request(), ctx); expect(uploads).to.have.length(1); @@ -103,11 +117,11 @@ describe('standalone quick-edit image replacement', () => { }); it('accepts an unrelated text edit while the image uploads', async () => { - window.fetch = async () => { + mockFetch(async (url) => { uploads.push(true); ctx.view.dispatch(state.tr.insertText('before ', 2)); - return new Response('', { status: 201 }); - }; + return daUploadResponse(url); + }); await handleImageReplace(request(), ctx); expect(posted.at(-1).payload.newSrc).to.contain('/org/site/.page/pic.png'); @@ -116,13 +130,13 @@ describe('standalone quick-edit image replacement', () => { }); it('rejects a removed target even when another image has the same URL', async () => { - window.fetch = async () => { + mockFetch(async (url) => { uploads.push(true); ctx.view.dispatch(state.tr.delete(3, 4).insert(3, state.schema.nodes.image.create({ src: '/same.png', alt: 'Replacement', }))); - return new Response('', { status: 201 }); - }; + return daUploadResponse(url); + }); await handleImageReplace(request(), ctx); expect(uploads).to.have.length(1); @@ -147,4 +161,56 @@ describe('standalone quick-edit image replacement', () => { expect(changed).to.equal(null); expect(posted.at(-1).payload.error).to.contain('ambiguous'); }); + + it('uploads to the da source store on legacy sites and uses the returned content url', async () => { + const contentUrl = 'https://stage-content.da.live/org/site/.page/pic.png'; + mockFetch(async (url, opts) => { + uploads.push({ url, opts }); + return new Response(JSON.stringify({ source: { contentUrl } }), { status: 201 }); + }); + await handleImageReplace(request(), ctx); + + expect(uploads).to.have.length(1); + expect(uploads[0].url).to.equal(`${DA_ADMIN}/source/org/site/.page/pic.png`); + expect(uploads[0].opts.body).to.be.instanceof(FormData); + expect(state.doc.nodeAt(3).attrs.src).to.equal(contentUrl); + expect(posted.at(-1).payload.newSrc).to.equal(contentUrl); + }); + + it('uploads to the media bus on hlx6 sites and uses the returned media url', async () => { + const org = `qe-img-${Math.floor(Math.random() * 1e6)}`; + const site = 'hlx6-site'; + localStorage.setItem('hlx6-upgrade', JSON.stringify({ + ...(JSON.parse(localStorage.getItem('hlx6-upgrade')) ?? {}), + [`/${org}/${site}`]: true, + })); + ctx.owner = org; + ctx.repo = site; + mockFetch(async (url, opts) => { + uploads.push({ url, opts }); + const uri = `https://main--${site}--${org}.aem.page/media_abc123.png`; + return new Response(JSON.stringify({ uri, meta: { type: 'image/png' } }), { status: 200 }); + }); + await handleImageReplace(request(), ctx); + + expect(uploads).to.have.length(1); + expect(uploads[0].url).to.equal(`${AEM_API}/${org}/sites/${site}/media/.page/pic.png`); + expect(uploads[0].opts.method).to.equal('POST'); + expect(uploads[0].opts.body).to.be.instanceof(Blob); + expect(uploads.some(({ url }) => url.startsWith(DA_ADMIN))).to.equal(false); + expect(state.doc.nodeAt(3).attrs.src).to.equal('./media_abc123.png'); + expect(posted.at(-1).payload.newSrc).to.equal('./media_abc123.png'); + }); + + it('reports the status of a failed upload and leaves the image unchanged', async () => { + mockFetch(async (url, opts) => { + uploads.push({ url, opts }); + return new Response('', { status: 413 }); + }); + await handleImageReplace(request(), ctx); + + expect(posted.at(-1).payload.error).to.contain('413'); + expect(changed).to.equal(null); + expect(state.doc.nodeAt(3).attrs.src).to.equal('/same.png'); + }); }); diff --git a/test/nx/blocks/quick-edit-portal/source.test.js b/test/nx/blocks/quick-edit-portal/source.test.js new file mode 100644 index 000000000..7a4acf3b0 --- /dev/null +++ b/test/nx/blocks/quick-edit-portal/source.test.js @@ -0,0 +1,107 @@ +import { expect } from '@esm-bundle/chai'; +import { AEM_API, DA_ADMIN } from '../../../../nx2/utils/utils.js'; +import { + calls, installFetch, restoreFetch, lastCall, +} from '../../../nx2/mocks/fetch.js'; +// eslint-disable-next-line import/no-unresolved +import { getOrgSite, loadDocSource } from '../../../../nx/blocks/quick-edit-portal/src/source.js'; + +const STORAGE_KEY = 'hlx6-upgrade'; + +let counter = 0; +const makeOrgSite = ({ hlx6 = false } = {}) => { + counter += 1; + const org = `qe-org-${counter}-${Math.floor(Math.random() * 1e6)}`; + const site = `qe-site-${counter}`; + if (hlx6) { + localStorage.setItem(STORAGE_KEY, JSON.stringify({ + ...(JSON.parse(localStorage.getItem(STORAGE_KEY)) ?? {}), + [`/${org}/${site}`]: true, + })); + } + return { org, site }; +}; + +describe('quick-edit portal source', () => { + afterEach(() => restoreFetch()); + + describe('getOrgSite', () => { + it('reads org and site from a da content mountpoint', () => { + expect(getOrgSite('https://content.da.live/scdemos/demo/')).to.deep.equal({ + org: 'scdemos', site: 'demo', + }); + }); + + it('reads org and site from a source bus mountpoint', () => { + expect(getOrgSite('https://api.aem.live/scdemos/sites/demo-hlx6/source')).to.deep.equal({ + org: 'scdemos', site: 'demo-hlx6', + }); + }); + + it('reads org and site from a source bus mountpoint with a trailing slash', () => { + expect(getOrgSite('https://api.aem.live/scdemos/sites/demo-hlx6/source/')).to.deep.equal({ + org: 'scdemos', site: 'demo-hlx6', + }); + }); + + it('returns no site for a mountpoint without one', () => { + expect(getOrgSite('https://content.da.live/scdemos/').site).to.equal(undefined); + }); + }); + + describe('loadDocSource', () => { + it('uses the source bus url on hlx6, the same url the da-live canvas names its room with', async () => { + installFetch(); + const { org, site } = makeOrgSite({ hlx6: true }); + const result = await loadDocSource({ org, site, pathname: '/drafts/page' }); + + const expected = `${AEM_API}/${org}/sites/${site}/source/drafts/page.html`; + expect(result.sourceUrl).to.equal(expected); + expect(lastCall().url).to.equal(expected); + expect(lastCall().method).to.equal('HEAD'); + expect(result.permissions).to.deep.equal(['read', 'write']); + expect(calls.some((c) => c.url.startsWith(DA_ADMIN))).to.equal(false); + }); + + it('uses the da-admin source url on legacy sites', async () => { + installFetch({ headers: { 'x-da-actions': '/org/site/drafts/page.html=read' } }); + const { org, site } = makeOrgSite(); + const result = await loadDocSource({ org, site, pathname: '/drafts/page' }); + + const expected = `${DA_ADMIN}/source/${org}/${site}/drafts/page.html`; + expect(result.sourceUrl).to.equal(expected); + expect(lastCall().url).to.equal(expected); + expect(result.permissions).to.deep.equal(['read']); + }); + + it('keeps read and write when a legacy response has no permission hints', async () => { + installFetch(); + const { org, site } = makeOrgSite(); + const { permissions } = await loadDocSource({ org, site, pathname: '/page' }); + expect(permissions).to.deep.equal(['read', 'write']); + }); + + it('maps a folder path to its index document', async () => { + installFetch(); + const { org, site } = makeOrgSite({ hlx6: true }); + const { sourceUrl } = await loadDocSource({ org, site, pathname: '/drafts/' }); + expect(sourceUrl).to.equal(`${AEM_API}/${org}/sites/${site}/source/drafts/index.html`); + }); + + it('maps the root path to the index document', async () => { + installFetch(); + const { org, site } = makeOrgSite(); + const { sourceUrl } = await loadDocSource({ org, site, pathname: '/' }); + expect(sourceUrl).to.equal(`${DA_ADMIN}/source/${org}/${site}/index.html`); + }); + + it('returns an error with the status when the document cannot be read', async () => { + installFetch({ status: 403 }); + const { org, site } = makeOrgSite(); + const result = await loadDocSource({ org, site, pathname: '/page' }); + expect(result.status).to.equal(403); + expect(result.error).to.be.a('string'); + expect(result.sourceUrl).to.equal(undefined); + }); + }); +}); diff --git a/test/nx/blocks/quick-edit-portal/utils.test.js b/test/nx/blocks/quick-edit-portal/utils.test.js new file mode 100644 index 000000000..92e1ca481 --- /dev/null +++ b/test/nx/blocks/quick-edit-portal/utils.test.js @@ -0,0 +1,65 @@ +import { expect } from '@esm-bundle/chai'; +import { AEM_API, HLX_ADMIN } from '../../../../nx2/utils/utils.js'; +import { installFetch, restoreFetch, lastCall } from '../../../nx2/mocks/fetch.js'; +import { handlePreview } from '../../../../nx/blocks/quick-edit-portal/src/utils.js'; +import { MESSAGE_TYPES } from '../../../../nx/utils/message-types.js'; + +let counter = 0; +const makeCtx = ({ hlx6 = false, path = '/drafts/page' } = {}) => { + counter += 1; + const owner = `qe-preview-${counter}-${Math.floor(Math.random() * 1e6)}`; + const repo = 'site'; + if (hlx6) { + localStorage.setItem('hlx6-upgrade', JSON.stringify({ + ...(JSON.parse(localStorage.getItem('hlx6-upgrade')) ?? {}), + [`/${owner}/${repo}`]: true, + })); + } + const posted = []; + return { + owner, repo, path, posted, port: { postMessage: (message) => posted.push(message) }, + }; +}; + +describe('quick-edit portal preview', () => { + afterEach(() => restoreFetch()); + + it('previews through the api on hlx6 sites', async () => { + installFetch(); + const ctx = makeCtx({ hlx6: true }); + await handlePreview(ctx); + + expect(lastCall().url).to.equal(`${AEM_API}/${ctx.owner}/sites/${ctx.repo}/preview/drafts/page`); + expect(lastCall().method).to.equal('POST'); + expect(ctx.posted.at(-1)).to.deep.equal({ type: MESSAGE_TYPES.PREVIEW, payload: { ok: true } }); + }); + + it('previews through admin.hlx.page on legacy sites', async () => { + installFetch(); + const ctx = makeCtx(); + await handlePreview(ctx); + + expect(lastCall().url).to.equal(`${HLX_ADMIN}/preview/${ctx.owner}/${ctx.repo}/main/drafts/page`); + expect(lastCall().method).to.equal('POST'); + expect(ctx.posted.at(-1).payload.ok).to.equal(true); + }); + + it('previews the index document of a folder', async () => { + installFetch(); + const ctx = makeCtx({ hlx6: true, path: '/drafts/' }); + await handlePreview(ctx); + + expect(lastCall().url).to.equal(`${AEM_API}/${ctx.owner}/sites/${ctx.repo}/preview/drafts/index`); + }); + + it('reports a failed preview', async () => { + installFetch({ status: 401 }); + const ctx = makeCtx({ hlx6: true }); + await handlePreview(ctx); + + const { type, payload } = ctx.posted.at(-1); + expect(type).to.equal(MESSAGE_TYPES.PREVIEW); + expect(payload.ok).to.equal(false); + expect(payload.error).to.contain('Failed to preview'); + }); +}); diff --git a/test/nx2/utils/api.test.js b/test/nx2/utils/api.test.js index a1520dba2..754d22664 100644 --- a/test/nx2/utils/api.test.js +++ b/test/nx2/utils/api.test.js @@ -11,6 +11,8 @@ import { isHlx6, signout, fromPath, + // eslint-disable-next-line import/named + getSourceUrl, source, versions, config, @@ -1553,6 +1555,33 @@ describe('api.js', () => { }); }); + describe('getSourceUrl', () => { + it('returns the source bus url on hlx6', async () => { + const { org: o, site: s } = makeOrgSite({ hlx6: true }); + const url = await getSourceUrl({ org: o, site: s, path: '/drafts/page.html' }); + expect(url).to.equal(`${AEM_API}/${o}/sites/${s}/source/drafts/page.html`); + }); + + it('returns the da-admin source url on legacy', async () => { + const { org: o, site: s } = makeOrgSite(); + const url = await getSourceUrl({ org: o, site: s, path: '/drafts/page.html' }); + expect(url).to.equal(`${DA_ADMIN}/source/${o}/${s}/drafts/page.html`); + }); + + it('accepts the path-string form', async () => { + const { org: o, site: s } = makeOrgSite({ hlx6: true }); + const url = await getSourceUrl(`/${o}/${s}/index.html`); + expect(url).to.equal(`${AEM_API}/${o}/sites/${s}/source/index.html`); + }); + + it('builds the url without requesting the document', async () => { + const { org: o, site: s } = makeOrgSite({ hlx6: true }); + await getSourceUrl({ org: o, site: s, path: '/page.html' }); + expect(callsTo(AEM_API)).to.have.lengthOf(0); + expect(callsTo(DA_ADMIN)).to.have.lengthOf(0); + }); + }); + describe('fromPath', () => { it('splits /org/site/file/path into { org, site, path }', () => { expect(fromPath('/adobe/aem-boilerplate/index.html')).to.deep.equal({ From 0a44144a94b1ab4a58cea1eadc9b7cf8f32b60af Mon Sep 17 00:00:00 2001 From: Ben Peter Date: Sat, 10 Oct 2026 00:11:27 +0200 Subject: [PATCH 02/28] fix(quick-edit): open hlx6 documents through the nx2 api the standalone portal read the document, named its collab room, uploaded images and previewed against admin.da.live / admin.hlx.page only. on hlx6 (source bus) sites the HEAD 404s, so nothing became editable. - read org/site from both mountpoint shapes (the sidekick passes the source bus url on hlx6 sites) - resolve the document with getSourceUrl + source.getMetadata and name the room with that url, the same one the da-live editors use - upload images with source.uploadMedia and use the returned url - preview with aem.preview - export getSourceUrl from nx2/utils/api.js --- docs/quick-edit-events.md | 15 ++++++++ .../quick-edit-portal/quick-edit-portal.js | 21 ++++------ nx/blocks/quick-edit-portal/src/images.js | 18 +++------ nx/blocks/quick-edit-portal/src/prose.js | 4 +- nx/blocks/quick-edit-portal/src/source.js | 20 ++++++++++ nx/blocks/quick-edit-portal/src/utils.js | 38 +------------------ nx/utils/message-types.js | 2 +- nx2/utils/api.d.ts | 6 +++ nx2/utils/api.js | 6 +++ nx2/utils/api.md | 14 ++++++- .../blocks/quick-edit-portal/source.test.js | 1 - test/nx2/utils/api.test.js | 1 - 12 files changed, 77 insertions(+), 69 deletions(-) create mode 100644 nx/blocks/quick-edit-portal/src/source.js diff --git a/docs/quick-edit-events.md b/docs/quick-edit-events.md index f0a2a57f5..5e04fc419 100644 --- a/docs/quick-edit-events.md +++ b/docs/quick-edit-events.md @@ -77,6 +77,17 @@ parallel one. If you do add a new key: --- +### `INIT` + +`config.mountpoint` is the site's content source: the sidekick passes its +`contentSourceUrl`, which is `https://content.da.live/{org}/{site}/` on DA sites and +`https://api.aem.live/{org}/sites/{site}/source` on hlx6 (source bus) sites. Some +sites build the DA shape themselves when there's no sidekick. The standalone portal reads +org/site from either shape and asks nx2 `api.js` (`isHlx6`) where the document lives, +so the payload shape doesn't decide the store. It names the collab room with +`getSourceUrl`, the url the da-live editors use, so quick edit and the canvas join the +same room. + ### `DROP_TARGET` da-live owns drags that start in another iframe (extension SDK drags and the AEM @@ -232,6 +243,10 @@ upload. An out-of-date/missing index fails instead of choosing an image by URL. For older iframes, a URL-only request is accepted only when it identifies exactly one image. +Both hosts upload through nx2 `source.uploadMedia` and reply with the url the upload +returned: a `content.da.live` url on DA sites, a media bus url on hlx6 sites (usually +relative, `./media_…`), which the iframe resolves against the page. + Both hosts use `nx2/public/utils/quick-edit-images.js` for document versions, image-position resolution, and replacement after upload. It accepts the host's ProseMirror document/view without importing ProseMirror. Instrumentation and diff --git a/nx/blocks/quick-edit-portal/quick-edit-portal.js b/nx/blocks/quick-edit-portal/quick-edit-portal.js index 2a378d767..7390d3880 100644 --- a/nx/blocks/quick-edit-portal/quick-edit-portal.js +++ b/nx/blocks/quick-edit-portal/quick-edit-portal.js @@ -1,4 +1,5 @@ -import { checkPermissions, signIn, handlePreview, getImageCookie } from './src/utils.js'; +import { signIn, handlePreview, getImageCookie } from './src/utils.js'; +import { getOrgSite, loadDocSource } from './src/source.js'; import createProse from './src/prose.js'; import { updateDocument, updateCursors, updateState, handleUndoRedo, getEditor, handleCursorMove, @@ -27,14 +28,10 @@ function onMessage(e, ctx) { } async function initProse(owner, repo, path, el, ctx) { - const sourceUrl = `https://admin.da.live/source/${owner}/${repo}/${ - path.endsWith('/') ? `${path.replace(/^\//, '')}index.html` : `${path.replace(/^\//, '')}.html` - }`; - - const resp = await checkPermissions(sourceUrl); - if (!resp.ok) return; - - const { permissions } = resp; + const { sourceUrl, permissions, error } = await loadDocSource({ + org: owner, site: repo, pathname: path, + }); + if (error) return; const { proseEl, wsProvider, view } = createProse({ path: sourceUrl, @@ -82,11 +79,7 @@ export default async function decorate(el) { return; } - // Parse the mountpoint URL to extract owner and repo - const url = new URL(mountPoint); - const pathSegments = url.pathname.split('/').filter(Boolean); - const owner = pathSegments[0]; - const repo = pathSegments[1]; + const { org: owner, site: repo } = getOrgSite(mountPoint); if (!owner || !repo) { return; diff --git a/nx/blocks/quick-edit-portal/src/images.js b/nx/blocks/quick-edit-portal/src/images.js index 35d159bb0..465f65f05 100644 --- a/nx/blocks/quick-edit-portal/src/images.js +++ b/nx/blocks/quick-edit-portal/src/images.js @@ -1,6 +1,5 @@ /* eslint-disable import/prefer-default-export */ -import { daFetch } from '../../../utils/daFetch.js'; -import { DA_ORIGIN } from '../../../public/utils/constants.js'; +import { source } from '../../../../nx2/utils/api.js'; import { MESSAGE_TYPES } from '../../../utils/message-types.js'; import { resolveImagePosition, updateImageInDocument, @@ -46,23 +45,18 @@ export async function handleImageReplace(payload, ctx) { const pageName = getPageName(ctx.path); const parentPath = ctx.path === '/' ? '' : ctx.path.replace(/\/[^/]+$/, ''); - // Construct the upload URL: /source/{owner}/{repo}{parent}/.{pageName}/{fileName} const uploadPath = `${parentPath}/.${pageName}/${fileName}`; - const uploadUrl = `${DA_ORIGIN}/source/${ctx.owner}/${ctx.repo}${uploadPath}`; - - // Upload the image - const formData = new FormData(); - formData.append('data', blob, fileName); - const opts = { method: 'PUT', body: formData }; - const resp = await daFetch(uploadUrl, opts); + const resp = await source.uploadMedia({ + org: ctx.owner, site: ctx.repo, path: uploadPath, body: blob, + }); if (!resp.ok) { reply({ error: `Upload failed with status ${resp.status}` }); return; } - // Construct the new image URL (AEM delivery URL) - const newSrc = `https://content.da.live/${ctx.owner}/${ctx.repo}${uploadPath}`; + const { source: { contentUrl: newSrc } = {} } = await resp.json(); + if (!newSrc) throw new Error('The upload did not return an image URL.'); if (ctx.view !== view) throw new Error('Image editor changed during the upload. Please try again.'); updateImageInDocument({ view, target, newSrc }); diff --git a/nx/blocks/quick-edit-portal/src/prose.js b/nx/blocks/quick-edit-portal/src/prose.js index 53202e7d9..54b1053f4 100644 --- a/nx/blocks/quick-edit-portal/src/prose.js +++ b/nx/blocks/quick-edit-portal/src/prose.js @@ -11,7 +11,7 @@ import { ySyncPluginKey, } from 'da-y-wrapper'; import { getSchema } from 'https://da.live/deps/da-parser/dist/index.js'; -import { COLLAB_ORIGIN, DA_ORIGIN } from 'https://da.live/blocks/shared/constants.js'; +import { COLLAB_ORIGIN } from 'https://da.live/blocks/shared/constants.js'; import { findChangedNodes, generateColor, findCommonEditableAncestor } from './utils.js'; function registerErrorHandler(ydoc) { @@ -78,7 +78,7 @@ export default function initProse({ path, permissions, rerenderPage, updateCurso const ydoc = new Y.Doc(); const server = COLLAB_ORIGIN; - const roomName = `${DA_ORIGIN}${new URL(path).pathname}`; + const roomName = path; const opts = {}; diff --git a/nx/blocks/quick-edit-portal/src/source.js b/nx/blocks/quick-edit-portal/src/source.js new file mode 100644 index 000000000..1f0252d6c --- /dev/null +++ b/nx/blocks/quick-edit-portal/src/source.js @@ -0,0 +1,20 @@ +import { getSourceUrl, source } from '../../../../nx2/utils/api.js'; + +export function getOrgSite(mountpoint) { + const segments = new URL(mountpoint).pathname.split('/').filter(Boolean); + const [org, sites, site, store] = segments; + if (segments.length === 4 && sites === 'sites' && store === 'source') return { org, site }; + return { org, site: sites }; +} + +const getDocPath = (pathname) => (pathname.endsWith('/') ? `${pathname}index.html` : `${pathname}.html`); + +export async function loadDocSource({ org, site, pathname }) { + const path = getDocPath(pathname); + const [sourceUrl, resp] = await Promise.all([ + getSourceUrl({ org, site, path }), + source.getMetadata({ org, site, path }), + ]); + if (!resp.ok) return { error: `Could not load ${path}`, status: resp.status }; + return { sourceUrl, permissions: resp.permissions ?? ['read', 'write'] }; +} diff --git a/nx/blocks/quick-edit-portal/src/utils.js b/nx/blocks/quick-edit-portal/src/utils.js index 50dcf4cdb..e6017d349 100644 --- a/nx/blocks/quick-edit-portal/src/utils.js +++ b/nx/blocks/quick-edit-portal/src/utils.js @@ -1,5 +1,6 @@ import { handleSignIn, loadIms } from '../../../utils/ims.js'; import { MESSAGE_TYPES } from '../../../utils/message-types.js'; +import { aem } from '../../../../nx2/utils/api.js'; import { isRenderedBlock } from './rerender-scope.js'; const DA_LIVE_PREVIEW_ENVS = { @@ -221,39 +222,6 @@ export function generateColor(name, hRange = [0, 360], sRange = [60, 80], lRange return `#${f(0)}${f(8)}${f(4)}`; } -export async function checkPermissions(sourceUrl) { - const token = await getToken(); - const resp = await fetch(sourceUrl, { - method: 'HEAD', - headers: { Authorization: `Bearer ${token}` }, - }); - - // If child actions header is present, use it. - // This is a hint as to what can be done with the children. - if (resp.headers?.get('x-da-child-actions')) { - resp.permissions = resp.headers - .get('x-da-child-actions') - .split('=') - .pop() - .split(','); - return resp; - } - - // Use the self actions hint if child actions are not present. - if (resp.headers?.get('x-da-actions')) { - resp.permissions = resp.headers - ?.get('x-da-actions') - ?.split('=') - .pop() - .split(','); - return resp; - } - - // Support legacy admin.role.all - resp.permissions = ['read', 'write']; - return resp; -} - export async function signIn() { const token = await getToken(); if (!token) { @@ -276,9 +244,7 @@ export async function signIn() { export async function handlePreview(ctx) { const path = ctx.path.endsWith('/') ? `${ctx.path}index` : `${ctx.path}`; - const url = `https://admin.hlx.page/preview/${ctx.owner}/${ctx.repo}/main${path}`; - const token = await getToken(); - const resp = await fetch(url, { method: 'POST', headers: { Authorization: `Bearer ${token}` } }); + const resp = await aem.preview({ org: ctx.owner, site: ctx.repo, path }); if (!resp.ok) { // eslint-disable-next-line no-console console.error('Failed to preview:', resp.statusText); diff --git a/nx/utils/message-types.js b/nx/utils/message-types.js index 604797d7b..b910c8196 100644 --- a/nx/utils/message-types.js +++ b/nx/utils/message-types.js @@ -6,7 +6,7 @@ // context (why a message exists, which host implementations wire it up). export const MESSAGE_TYPES = Object.freeze({ // Host <-> iframe: handshake - INIT: 'init', // { config: { mountpoint }, location: { pathname } } + INIT: 'init', // { config: { mountpoint: DA content or hlx6 source bus url }, location: { pathname } } READY: 'ready', // no payload // Host -> iframe diff --git a/nx2/utils/api.d.ts b/nx2/utils/api.d.ts index ad8343c3c..d12cf594c 100644 --- a/nx2/utils/api.d.ts +++ b/nx2/utils/api.d.ts @@ -53,6 +53,12 @@ export function signout(): void; /** Split `/org/site/file/path` into `{ org, site, path }`. */ export function fromPath(fullPath: string): { org: string; site: string; path: string }; +/** + * Source url of a document without requesting it: `${AEM_API}/{org}/sites/{site}/source{path}` + * on hlx6, `${DA_ADMIN}/source/{org}/{site}{path}` on legacy DA. Collab rooms are named with it. + */ +export function getSourceUrl(arg: { org: string; site: string; path: string } | string): Promise; + // ─── response helpers ────────────────────────────────────────────────────── /** Failure reason returned by `asJson` / `asText` when `ok` is false. */ diff --git a/nx2/utils/api.js b/nx2/utils/api.js index ee4d2548e..3b8f96b3e 100644 --- a/nx2/utils/api.js +++ b/nx2/utils/api.js @@ -37,6 +37,7 @@ export { AEM_API }; // daFetch authenticated fetch (used by everything above) // isHlx6 Helix 6 upgrade-status probe (cached) // fromPath `/org/site/file/path` -> { org, site, path } +// getSourceUrl document source url on DA or the hlx6 source bus // // All namespace methods return a raw `Response` (augmented with // `resp.permissions`) EXCEPT `source.list`, which merges body + header @@ -701,6 +702,11 @@ export function fromPath(str) { return { org, site, path: parts.length ? `/${parts.join('/')}` : '' }; } +// Document source url on DA or the hlx6 source bus; collab rooms are named after it. +export const getSourceUrl = withArgs( + ({ org, site, path }) => getDaApiPath(SOURCE, org, site, path), +); + // Site token exchange for authenticated content access. // Uses IIFE pattern for memoized token retrieval. export const getAemSiteToken = (() => { diff --git a/nx2/utils/api.md b/nx2/utils/api.md index ca6ef8e3f..e9076f2db 100644 --- a/nx2/utils/api.md +++ b/nx2/utils/api.md @@ -2,7 +2,7 @@ A unified client for talking to **DA admin** (`admin.da.live`) and the **AEM admin API** in either its legacy form (`admin.hlx.page`, "helix5") or its new form (`api.aem.live`, "helix6"). Every method auto-routes by the per-site **hlx6** upgrade flag — once a site has been upgraded, calls flow to the new origin; otherwise they fall back to the legacy origin. -The module ships its low-level primitive (`daFetch`), an upgrade detector (`isHlx6`), helpers (`fromPath`, `signout`, `asJson`, `asText`), and **eight namespaced surfaces**: `source`, `versions`, `config`, `org`, `status`, `aem`, `snapshot`, `jobs`. Type definitions live in `[api.d.ts](./api.d.ts)` — VSCode picks them up automatically and surfaces overloads, field-level docs, and inline shapes. +The module ships its low-level primitive (`daFetch`), an upgrade detector (`isHlx6`), helpers (`fromPath`, `getSourceUrl`, `signout`, `asJson`, `asText`), and **eight namespaced surfaces**: `source`, `versions`, `config`, `org`, `status`, `aem`, `snapshot`, `jobs`. Type definitions live in `[api.d.ts](./api.d.ts)` — VSCode picks them up automatically and surfaces overloads, field-level docs, and inline shapes. > **Routing model.** Some endpoints are owned by DA itself (`source`, `list`, `config`, `versions`) and DA proxies them to AEM when the site is upgraded. Others are AEM-only (`status`, `preview`, `live`, `snapshots`, `jobs`) and live on either `admin.hlx.page` (legacy) or `api.aem.live` (hlx6). The module hides this distinction; callers always pass `{ org, site, path }` and get a `Response` back. @@ -13,7 +13,7 @@ The module ships its low-level primitive (`daFetch`), an upgrade detector (`isHl ```js import { // Low-level - daFetch, isHlx6, signout, fromPath, + daFetch, isHlx6, signout, fromPath, getSourceUrl, // Namespaces source, versions, config, org, status, aem, snapshot, jobs, // Response helpers @@ -447,6 +447,16 @@ fromPath('/adobe/aem-boilerplate/index.html'); // → { org: 'adobe', site: 'aem-boilerplate', path: '/index.html' } ``` +### `getSourceUrl(arg)` + +Resolves the source url of a document without requesting it: `${AEM_API}/{org}/sites/{site}/source{path}` on hlx6, `${DA_ADMIN}/source/{org}/{site}{path}` on legacy DA. Accepts the object or path-string form. Collab (da-collab) rooms are named with this url, so editors that open the same document should name their room with it to share one. + +```js +await getSourceUrl({ org: 'adobe', site: 'aem-boilerplate', path: '/index.html' }); +// → 'https://api.aem.live/adobe/sites/aem-boilerplate/source/index.html' (hlx6) +// → 'https://admin.da.live/source/adobe/aem-boilerplate/index.html' (legacy) +``` + ### `asJson(promise)` / `asText(promise)` Opt-in unwrappers. Each awaits a namespace method's returned promise, attempts to parse the body, and returns a flat result: diff --git a/test/nx/blocks/quick-edit-portal/source.test.js b/test/nx/blocks/quick-edit-portal/source.test.js index 7a4acf3b0..971411e93 100644 --- a/test/nx/blocks/quick-edit-portal/source.test.js +++ b/test/nx/blocks/quick-edit-portal/source.test.js @@ -3,7 +3,6 @@ import { AEM_API, DA_ADMIN } from '../../../../nx2/utils/utils.js'; import { calls, installFetch, restoreFetch, lastCall, } from '../../../nx2/mocks/fetch.js'; -// eslint-disable-next-line import/no-unresolved import { getOrgSite, loadDocSource } from '../../../../nx/blocks/quick-edit-portal/src/source.js'; const STORAGE_KEY = 'hlx6-upgrade'; diff --git a/test/nx2/utils/api.test.js b/test/nx2/utils/api.test.js index 754d22664..d98a5be31 100644 --- a/test/nx2/utils/api.test.js +++ b/test/nx2/utils/api.test.js @@ -11,7 +11,6 @@ import { isHlx6, signout, fromPath, - // eslint-disable-next-line import/named getSourceUrl, source, versions, From f495e87c2ca7fd8804d9fb3645b88e3c43afed2a Mon Sep 17 00:00:00 2001 From: Ben Peter Date: Sat, 10 Oct 2026 05:29:33 +0200 Subject: [PATCH 03/28] test(quick-edit): keep media bus picture sources relative red: da-live's prose2aem builds the picture sources from the resolved img.src (da.live/plugins/media_...) and, in live mode, strips the first two path segments of any *.da.live image url, so neither the portal's origin nor the preview origin works. relative refs resolve against the page like delivered html. --- .../nx/blocks/quick-edit-portal/utils.test.js | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/test/nx/blocks/quick-edit-portal/utils.test.js b/test/nx/blocks/quick-edit-portal/utils.test.js index 92e1ca481..01374a54e 100644 --- a/test/nx/blocks/quick-edit-portal/utils.test.js +++ b/test/nx/blocks/quick-edit-portal/utils.test.js @@ -1,7 +1,7 @@ import { expect } from '@esm-bundle/chai'; import { AEM_API, HLX_ADMIN } from '../../../../nx2/utils/utils.js'; import { installFetch, restoreFetch, lastCall } from '../../../nx2/mocks/fetch.js'; -import { handlePreview } from '../../../../nx/blocks/quick-edit-portal/src/utils.js'; +import { handlePreview, keepMediaBusImagesRelative } from '../../../../nx/blocks/quick-edit-portal/src/utils.js'; import { MESSAGE_TYPES } from '../../../../nx/utils/message-types.js'; let counter = 0; @@ -63,3 +63,22 @@ describe('quick-edit portal preview', () => { expect(payload.error).to.contain('Failed to preview'); }); }); + +describe('quick-edit portal media bus images', () => { + const ref = './media_123.png#width=320&height=160'; + const picture = (src, srcset) => ``; + + it('keeps the picture sources of media bus images relative', () => { + const html = `
${picture(ref, 'https://da.live/plugins/media_123.png#width=320&height=160')}
`; + const doc = new DOMParser().parseFromString(keepMediaBusImagesRelative(html), 'text/html'); + expect([...doc.querySelectorAll('source')].map((source) => source.getAttribute('srcset'))) + .to.deep.equal([ref, ref]); + expect(doc.querySelector('img').getAttribute('src')).to.equal(ref); + }); + + it('leaves other pictures alone', () => { + const src = 'https://content.da.live/org/site/.page/pic.png'; + const html = `
${picture(src, src)}
`; + expect(keepMediaBusImagesRelative(html)).to.equal(html); + }); +}); From 29bd50402f51c4230605f87cd0c978687106ffa5 Mon Sep 17 00:00:00 2001 From: Ben Peter Date: Sat, 10 Oct 2026 05:30:09 +0200 Subject: [PATCH 04/28] fix(quick-edit): keep media bus picture sources relative replaces the preview-origin rewrite: da-live's prose2aem strips the first two path segments of *.da.live image urls in live mode, so the rewritten src lost its file name. the portal now leaves ./media_ refs relative in img and source srcset, and the page resolves them like delivered html. getInstrumentedHTML and render.js are back to main. --- docs/quick-edit-events.md | 5 ++++- nx/blocks/quick-edit-portal/src/prose2aem.js | 3 ++- nx/blocks/quick-edit-portal/src/utils.js | 12 ++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/docs/quick-edit-events.md b/docs/quick-edit-events.md index 5e04fc419..63e5e63bd 100644 --- a/docs/quick-edit-events.md +++ b/docs/quick-edit-events.md @@ -245,7 +245,10 @@ exactly one image. Both hosts upload through nx2 `source.uploadMedia` and reply with the url the upload returned: a `content.da.live` url on DA sites, a media bus url on hlx6 sites (usually -relative, `./media_…`), which the iframe resolves against the page. +relative, `./media_…`), which the iframe resolves against the page. In `SET_BODY` the +standalone portal keeps `./media_` refs relative in both `` and ``, so +the page resolves them against its own url like delivered html (da-live's `prose2aem` +would otherwise point the sources at the portal's origin). Both hosts use `nx2/public/utils/quick-edit-images.js` for document versions, image-position resolution, and replacement after upload. It accepts the host's diff --git a/nx/blocks/quick-edit-portal/src/prose2aem.js b/nx/blocks/quick-edit-portal/src/prose2aem.js index 1f2b20dd4..5880f797e 100644 --- a/nx/blocks/quick-edit-portal/src/prose2aem.js +++ b/nx/blocks/quick-edit-portal/src/prose2aem.js @@ -2,6 +2,7 @@ import prose2aem from 'https://da.live/blocks/shared/prose2aem.js'; import { getImageDocumentVersion } from '../../../../nx2/public/utils/quick-edit-images.js'; import { EDITABLE_SELECTORS } from './editable-elements.js'; +import { keepMediaBusImagesRelative } from './utils.js'; function isOutermostWysiwygEditable(el) { if (!el?.matches?.(EDITABLE_SELECTORS)) return false; @@ -109,5 +110,5 @@ export function getInstrumentedHTML(view) { }); // Convert to an HTML string using prose2aem. - return prose2aem(editorClone, true, false, true); + return keepMediaBusImagesRelative(prose2aem(editorClone, true, false, true)); } diff --git a/nx/blocks/quick-edit-portal/src/utils.js b/nx/blocks/quick-edit-portal/src/utils.js index e6017d349..5bb7ab96f 100644 --- a/nx/blocks/quick-edit-portal/src/utils.js +++ b/nx/blocks/quick-edit-portal/src/utils.js @@ -34,6 +34,18 @@ function getLivePreviewUrl(owner, repo) { return `${protocol}://main--${repo}--${owner}.${domain}`; } +// prose2aem sets to the resolved img.src; ./media_ must resolve against the page. +export function keepMediaBusImagesRelative(html) { + if (!html.includes('src="./media_')) return html; + const doc = new DOMParser().parseFromString(html, 'text/html'); + doc.querySelectorAll('picture').forEach((picture) => { + const src = picture.querySelector('img')?.getAttribute('src'); + if (!src?.startsWith('./media_')) return; + picture.querySelectorAll('source').forEach((source) => source.setAttribute('srcset', src)); + }); + return doc.documentElement.outerHTML; +} + export async function getImageCookie(owner, repo) { const token = await getToken(); if (token) { From f4f743b2f77afc624cd8040e70a0a8472edab77e Mon Sep 17 00:00:00 2001 From: Ben Peter Date: Tue, 24 Nov 2026 22:40:55 +0100 Subject: [PATCH 05/28] test(quick-edit): keep the webp type of uploaded images --- .../blocks/quick-edit-portal/images.test.js | 9 ++++++++ test/nx2/utils/api.test.js | 21 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/test/nx/blocks/quick-edit-portal/images.test.js b/test/nx/blocks/quick-edit-portal/images.test.js index f0ca71b95..180c83dd4 100644 --- a/test/nx/blocks/quick-edit-portal/images.test.js +++ b/test/nx/blocks/quick-edit-portal/images.test.js @@ -177,6 +177,15 @@ describe('standalone quick-edit image replacement', () => { expect(posted.at(-1).payload.newSrc).to.equal(contentUrl); }); + it('keeps the webp type of the uploaded file on legacy sites', async () => { + await handleImageReplace({ + ...request(), imageData: 'data:image/webp;base64,UklGRg==', fileName: 'pic.webp', + }, ctx); + + expect(uploads[0].url).to.equal(`${DA_ADMIN}/source/org/site/.page/pic.webp`); + expect(uploads[0].opts.body.get('data').type).to.equal('image/webp'); + }); + it('uploads to the media bus on hlx6 sites and uses the returned media url', async () => { const org = `qe-img-${Math.floor(Math.random() * 1e6)}`; const site = 'hlx6-site'; diff --git a/test/nx2/utils/api.test.js b/test/nx2/utils/api.test.js index d98a5be31..2195498e3 100644 --- a/test/nx2/utils/api.test.js +++ b/test/nx2/utils/api.test.js @@ -549,6 +549,17 @@ describe('api.js', () => { expect(calls.some((c) => c.url.includes('/media'))).to.equal(false); }); + it('source.uploadMedia legacy keeps the blob type for extensions the type map lacks', async () => { + restoreFetch(); + installFetch({ + body: JSON.stringify({ source: { contentUrl: 'https://stage-content.da.live/o/s/img.webp' } }), + }); + const { org: o, site: s } = makeOrgSite(); + const data = new Blob(['binary'], { type: 'image/webp' }); + await source.uploadMedia({ org: o, site: s, path: '/img.webp', body: data }); + expect(lastCall().body.get('data').type).to.equal('image/webp'); + }); + it('source.uploadMedia hlx6 POSTs to the media route with content-type header and raw body', async () => { const { org: o, site: s } = makeOrgSite({ hlx6: true }); restoreFetch(); @@ -574,6 +585,16 @@ describe('api.js', () => { expect(lastCall().headers['content-type']).to.equal('application/octet-stream'); }); + it('source.uploadMedia hlx6 sends the blob type for extensions the type map lacks', async () => { + const { org: o, site: s } = makeOrgSite({ hlx6: true }); + restoreFetch(); + installFetch({ + body: JSON.stringify({ uri: `https://main--${s}--${o}.aem.page/media_1.webp`, meta: {} }), + }); + await source.uploadMedia({ org: o, site: s, path: '/img.webp', body: new Blob(['x'], { type: 'image/webp' }) }); + expect(lastCall().headers['content-type']).to.equal('image/webp'); + }); + it('source.uploadMedia hlx6 normalizes contentUrl by stripping the site aem.page prefix', async () => { restoreFetch(); const { org: o, site: s } = makeOrgSite({ hlx6: true }); From 0151df5eb723b914cd04a8d32e975ee48d1c1d46 Mon Sep 17 00:00:00 2001 From: Ben Peter Date: Tue, 24 Nov 2026 22:41:29 +0100 Subject: [PATCH 06/28] fix(quick-edit): keep the webp type of uploaded images --- nx2/utils/api.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/nx2/utils/api.js b/nx2/utils/api.js index 3b8f96b3e..767810e65 100644 --- a/nx2/utils/api.js +++ b/nx2/utils/api.js @@ -334,7 +334,7 @@ export const source = { _saveDA: withArgs(async ({ org, site, path, body }) => { const url = await getDaApiPath(SOURCE, org, site, path); const formData = new FormData(); - formData.append('data', new Blob([body], { type: findContentType(path) })); + formData.append('data', new Blob([body], { type: findContentType(path, body) })); const opts = { method: 'POST', body: formData, @@ -357,7 +357,7 @@ export const source = { method: 'POST', body, headers: { - 'content-type': findContentType(path) || 'application/octet-stream', + 'content-type': findContentType(path, body) || 'application/octet-stream', }, }; const resp = await daFetch({ url, opts }); @@ -757,12 +757,13 @@ const TYPE_MAP = { }; /** - * finds the content type by path extension + * finds the content type by path extension, else the type of a Blob body * @param path + * @param body */ -function findContentType(path) { +function findContentType(path, body) { const ext = Object.keys(TYPE_MAP).find((e) => path.toLowerCase().endsWith(e)); - return TYPE_MAP[ext]; + return TYPE_MAP[ext] ?? (body?.type || undefined); } // Rewrite relative `media_` refs (src/href/srcset) to absolute URLs against From 98dd68bcc7febb3c7ea8b4f67d5930f4767f8e31 Mon Sep 17 00:00:00 2001 From: Ben Peter Date: Tue, 24 Nov 2026 22:41:53 +0100 Subject: [PATCH 07/28] test(quick-edit): preview with only the authorization header --- .../nx/blocks/quick-edit-portal/utils.test.js | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/test/nx/blocks/quick-edit-portal/utils.test.js b/test/nx/blocks/quick-edit-portal/utils.test.js index 01374a54e..813614e1b 100644 --- a/test/nx/blocks/quick-edit-portal/utils.test.js +++ b/test/nx/blocks/quick-edit-portal/utils.test.js @@ -1,6 +1,8 @@ import { expect } from '@esm-bundle/chai'; import { AEM_API, HLX_ADMIN } from '../../../../nx2/utils/utils.js'; -import { installFetch, restoreFetch, lastCall } from '../../../nx2/mocks/fetch.js'; +import { + calls, installFetch, restoreFetch, lastCall, +} from '../../../nx2/mocks/fetch.js'; import { handlePreview, keepMediaBusImagesRelative } from '../../../../nx/blocks/quick-edit-portal/src/utils.js'; import { MESSAGE_TYPES } from '../../../../nx/utils/message-types.js'; @@ -52,6 +54,38 @@ describe('quick-edit portal preview', () => { expect(lastCall().url).to.equal(`${AEM_API}/${ctx.owner}/sites/${ctx.repo}/preview/drafts/index`); }); + it('sends the IMS token only in Authorization', async () => { + installFetch(); + const legacy = makeCtx(); + await handlePreview(legacy); + const hlx6 = makeCtx({ hlx6: true }); + await handlePreview(hlx6); + + const previews = calls.filter(({ url }) => url.includes('/preview/')); + expect(previews).to.have.length(2); + previews.forEach(({ headers }) => { + expect(headers.Authorization).to.equal('Bearer test-token'); + expect(headers['x-content-source-authorization']).to.equal(undefined); + }); + }); + + it('reports a preview request that fails before a response', async () => { + restoreFetch(); + const savedFetch = window.fetch; + window.fetch = async () => { throw new TypeError('Failed to fetch'); }; + const ctx = makeCtx(); + try { + await handlePreview(ctx); + } finally { + window.fetch = savedFetch; + } + + const { type, payload } = ctx.posted.at(-1); + expect(type).to.equal(MESSAGE_TYPES.PREVIEW); + expect(payload.ok).to.equal(false); + expect(payload.error).to.contain('Failed to preview'); + }); + it('reports a failed preview', async () => { installFetch({ status: 401 }); const ctx = makeCtx({ hlx6: true }); From feaeccec1658b3a951785c7788dcfd9489397b45 Mon Sep 17 00:00:00 2001 From: Ben Peter Date: Tue, 24 Nov 2026 22:42:54 +0100 Subject: [PATCH 08/28] fix(quick-edit): preview with only the authorization header --- nx/blocks/quick-edit-portal/src/utils.js | 32 ++++++++++++++++-------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/nx/blocks/quick-edit-portal/src/utils.js b/nx/blocks/quick-edit-portal/src/utils.js index 5bb7ab96f..9f808a6d6 100644 --- a/nx/blocks/quick-edit-portal/src/utils.js +++ b/nx/blocks/quick-edit-portal/src/utils.js @@ -1,6 +1,7 @@ import { handleSignIn, loadIms } from '../../../utils/ims.js'; import { MESSAGE_TYPES } from '../../../utils/message-types.js'; -import { aem } from '../../../../nx2/utils/api.js'; +import { isHlx6, loadIms as loadApiIms } from '../../../../nx2/utils/api.js'; +import { AEM_API, HLX_ADMIN } from '../../../../nx2/utils/utils.js'; import { isRenderedBlock } from './rerender-scope.js'; const DA_LIVE_PREVIEW_ENVS = { @@ -254,17 +255,26 @@ export async function signIn() { } } +// Not aem.preview: daFetch also sends the token in x-content-source-authorization (da-nx#866). +async function requestPreview({ owner, repo, path }) { + const page = path.endsWith('/') ? `${path}index` : path; + const url = await isHlx6(owner, repo) + ? `${AEM_API}/${owner}/sites/${repo}/preview${page}` + : `${HLX_ADMIN}/preview/${owner}/${repo}/main${page}`; + const { accessToken } = await loadApiIms(); + const resp = await fetch(url, { method: 'POST', headers: { Authorization: `Bearer ${accessToken.token}` } }); + return resp.ok ? undefined : (resp.statusText || `${resp.status}`); +} + export async function handlePreview(ctx) { - const path = ctx.path.endsWith('/') ? `${ctx.path}index` : `${ctx.path}`; - const resp = await aem.preview({ org: ctx.owner, site: ctx.repo, path }); - if (!resp.ok) { - // eslint-disable-next-line no-console - console.error('Failed to preview:', resp.statusText); - const error = `Failed to preview: ${resp.statusText}`; - ctx.port.postMessage({ - type: MESSAGE_TYPES.PREVIEW, payload: { ok: false, error }, - }); - } else { + const error = await requestPreview(ctx).catch((e) => e.message); + if (error === undefined) { ctx.port.postMessage({ type: MESSAGE_TYPES.PREVIEW, payload: { ok: true } }); + return; } + // eslint-disable-next-line no-console + console.error('Failed to preview:', error); + ctx.port.postMessage({ + type: MESSAGE_TYPES.PREVIEW, payload: { ok: false, error: `Failed to preview: ${error}` }, + }); } From 78bd62a97dc068f597d715cc5bdfa66e2c263b75 Mon Sep 17 00:00:00 2001 From: Ben Peter Date: Tue, 24 Nov 2026 22:43:36 +0100 Subject: [PATCH 09/28] test(quick-edit): start on source bus sites without a mountpoint url --- .../blocks/quick-edit-portal/source.test.js | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/test/nx/blocks/quick-edit-portal/source.test.js b/test/nx/blocks/quick-edit-portal/source.test.js index 971411e93..d9dae449b 100644 --- a/test/nx/blocks/quick-edit-portal/source.test.js +++ b/test/nx/blocks/quick-edit-portal/source.test.js @@ -3,7 +3,7 @@ import { AEM_API, DA_ADMIN } from '../../../../nx2/utils/utils.js'; import { calls, installFetch, restoreFetch, lastCall, } from '../../../nx2/mocks/fetch.js'; -import { getOrgSite, loadDocSource } from '../../../../nx/blocks/quick-edit-portal/src/source.js'; +import { getInitSite, getOrgSite, loadDocSource } from '../../../../nx/blocks/quick-edit-portal/src/source.js'; const STORAGE_KEY = 'hlx6-upgrade'; @@ -48,6 +48,32 @@ describe('quick-edit portal source', () => { }); }); + describe('getInitSite', () => { + const owner = 'scdemos'; + const repo = 'demo-hlx6'; + + it('reads org and site from the mountpoint url', () => { + expect(getInitSite({ mountpoint: `${AEM_API}/scdemos/sites/demo-hlx6/source`, owner: 'x', repo: 'y' })) + .to.deep.equal({ org: owner, site: repo }); + expect(getInitSite({ mountpoint: { url: 'https://content.da.live/scdemos/demo/' } })) + .to.deep.equal({ org: owner, site: 'demo' }); + }); + + it('uses owner and repo for a source bus without a url', () => { + expect(getInitSite({ mountpoint: { type: 'sourcebus' }, owner, repo })) + .to.deep.equal({ org: owner, site: repo }); + expect(getInitSite({ contentSourceType: 'sourcebus', owner, repo })) + .to.deep.equal({ org: owner, site: repo }); + expect(getInitSite({ apiUpgrade: true, owner, repo })) + .to.deep.equal({ org: owner, site: repo }); + }); + + it('finds no site without a mountpoint or a source bus', () => { + expect(getInitSite({ owner, repo })).to.deep.equal({}); + expect(getInitSite(undefined)).to.deep.equal({}); + }); + }); + describe('loadDocSource', () => { it('uses the source bus url on hlx6, the same url the da-live canvas names its room with', async () => { installFetch(); From ce2c23f990346f91683189f61ccd2f1cfea933cd Mon Sep 17 00:00:00 2001 From: Ben Peter Date: Tue, 24 Nov 2026 22:44:14 +0100 Subject: [PATCH 10/28] fix(quick-edit): start on source bus sites without a mountpoint url --- docs/quick-edit-events.md | 8 ++++++-- nx/blocks/quick-edit-portal/quick-edit-portal.js | 10 ++-------- nx/blocks/quick-edit-portal/src/source.js | 10 ++++++++++ nx/utils/message-types.js | 2 +- 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/docs/quick-edit-events.md b/docs/quick-edit-events.md index 63e5e63bd..f4178bd13 100644 --- a/docs/quick-edit-events.md +++ b/docs/quick-edit-events.md @@ -82,8 +82,12 @@ parallel one. If you do add a new key: `config.mountpoint` is the site's content source: the sidekick passes its `contentSourceUrl`, which is `https://content.da.live/{org}/{site}/` on DA sites and `https://api.aem.live/{org}/sites/{site}/source` on hlx6 (source bus) sites. Some -sites build the DA shape themselves when there's no sidekick. The standalone portal reads -org/site from either shape and asks nx2 `api.js` (`isHlx6`) where the document lives, +sites build the DA shape themselves when there's no sidekick. A source bus site can also have +no url (site config `content.source` is just `{ type: 'sourcebus' }`), and then the sidekick +sends no mountpoint. In that case the portal uses `config.owner` / `config.repo` if the config +marks a source bus (`mountpoint.type` or `contentSourceType` is `sourcebus`) or an upgraded +site (`apiUpgrade: true`). The standalone portal reads org/site from either url shape and asks +nx2 `api.js` (`isHlx6`) where the document lives, so the payload shape doesn't decide the store. It names the collab room with `getSourceUrl`, the url the da-live editors use, so quick edit and the canvas join the same room. diff --git a/nx/blocks/quick-edit-portal/quick-edit-portal.js b/nx/blocks/quick-edit-portal/quick-edit-portal.js index 7390d3880..73a3bcb4f 100644 --- a/nx/blocks/quick-edit-portal/quick-edit-portal.js +++ b/nx/blocks/quick-edit-portal/quick-edit-portal.js @@ -1,5 +1,5 @@ import { signIn, handlePreview, getImageCookie } from './src/utils.js'; -import { getOrgSite, loadDocSource } from './src/source.js'; +import { getInitSite, loadDocSource } from './src/source.js'; import createProse from './src/prose.js'; import { updateDocument, updateCursors, updateState, handleUndoRedo, getEditor, handleCursorMove, @@ -72,14 +72,8 @@ export default async function decorate(el) { const [port] = e.ports; const { config, location } = e.data.payload ?? {}; - const mountPoint = config?.mountpoint; const path = location?.pathname; - - if (!mountPoint) { - return; - } - - const { org: owner, site: repo } = getOrgSite(mountPoint); + const { org: owner, site: repo } = getInitSite(config); if (!owner || !repo) { return; diff --git a/nx/blocks/quick-edit-portal/src/source.js b/nx/blocks/quick-edit-portal/src/source.js index 1f0252d6c..b8f0fe84b 100644 --- a/nx/blocks/quick-edit-portal/src/source.js +++ b/nx/blocks/quick-edit-portal/src/source.js @@ -7,6 +7,16 @@ export function getOrgSite(mountpoint) { return { org, site: sites }; } +export function getInitSite(config) { + const { + mountpoint, contentSourceType, apiUpgrade, owner, repo, + } = config ?? {}; + const url = typeof mountpoint === 'string' ? mountpoint : mountpoint?.url; + if (url) return getOrgSite(url); + const sourceBus = mountpoint?.type === 'sourcebus' || contentSourceType === 'sourcebus' || apiUpgrade === true; + return sourceBus ? { org: owner, site: repo } : {}; +} + const getDocPath = (pathname) => (pathname.endsWith('/') ? `${pathname}index.html` : `${pathname}.html`); export async function loadDocSource({ org, site, pathname }) { diff --git a/nx/utils/message-types.js b/nx/utils/message-types.js index b910c8196..d853a79c8 100644 --- a/nx/utils/message-types.js +++ b/nx/utils/message-types.js @@ -6,7 +6,7 @@ // context (why a message exists, which host implementations wire it up). export const MESSAGE_TYPES = Object.freeze({ // Host <-> iframe: handshake - INIT: 'init', // { config: { mountpoint: DA content or hlx6 source bus url }, location: { pathname } } + INIT: 'init', // { config: { mountpoint: DA content or hlx6 source bus url, owner, repo, apiUpgrade }, location: { pathname } } READY: 'ready', // no payload // Host -> iframe From 38a7cd05ecbb97b72f95b82e56111b9429d2e1c8 Mon Sep 17 00:00:00 2001 From: Ben Peter Date: Tue, 24 Nov 2026 22:44:43 +0100 Subject: [PATCH 11/28] fix(quick-edit): retry opening the document after a failed start --- nx/blocks/quick-edit-portal/quick-edit-portal.js | 10 +++++++++- test/nx/blocks/quick-edit-portal/source.test.js | 9 +++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/nx/blocks/quick-edit-portal/quick-edit-portal.js b/nx/blocks/quick-edit-portal/quick-edit-portal.js index 73a3bcb4f..f4fc1b11f 100644 --- a/nx/blocks/quick-edit-portal/quick-edit-portal.js +++ b/nx/blocks/quick-edit-portal/quick-edit-portal.js @@ -111,7 +111,15 @@ export default async function decorate(el) { if (!bootstrapComplete) await getImageCookie(owner, repo); await initProse(owner, repo, path, el, ctx); })(); - await editorPromise; + try { + await editorPromise; + } catch (error) { + editorPromise = undefined; + port.close(); + // eslint-disable-next-line no-console + console.error('Failed to open the document for quick edit', error); + return; + } if (editorPort !== port) { port.close(); return; diff --git a/test/nx/blocks/quick-edit-portal/source.test.js b/test/nx/blocks/quick-edit-portal/source.test.js index d9dae449b..7d9adb88b 100644 --- a/test/nx/blocks/quick-edit-portal/source.test.js +++ b/test/nx/blocks/quick-edit-portal/source.test.js @@ -120,6 +120,15 @@ describe('quick-edit portal source', () => { expect(sourceUrl).to.equal(`${DA_ADMIN}/source/${org}/${site}/index.html`); }); + it('rejects when the upgrade check fails, so the portal can retry', async () => { + const savedFetch = window.fetch; + window.fetch = async () => { throw new TypeError('Failed to fetch'); }; + const { org, site } = makeOrgSite(); + const error = await loadDocSource({ org, site, pathname: '/page' }).then(() => null, (e) => e); + window.fetch = savedFetch; + expect(error).to.be.instanceof(Error); + }); + it('returns an error with the status when the document cannot be read', async () => { installFetch({ status: 403 }); const { org, site } = makeOrgSite(); From 2f6f0487064456679c8ad7c586225b47a9bea88f Mon Sep 17 00:00:00 2001 From: Ben Peter Date: Tue, 24 Nov 2026 22:45:08 +0100 Subject: [PATCH 12/28] test(quick-edit): keep linked media bus images relative --- test/nx/blocks/quick-edit-portal/utils.test.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/nx/blocks/quick-edit-portal/utils.test.js b/test/nx/blocks/quick-edit-portal/utils.test.js index 813614e1b..6364eeacd 100644 --- a/test/nx/blocks/quick-edit-portal/utils.test.js +++ b/test/nx/blocks/quick-edit-portal/utils.test.js @@ -110,6 +110,15 @@ describe('quick-edit portal media bus images', () => { expect(doc.querySelector('img').getAttribute('src')).to.equal(ref); }); + it('keeps linked media bus images relative', () => { + const resolved = new URL(ref, document.baseURI).href; + const html = `
`; + const doc = new DOMParser().parseFromString(keepMediaBusImagesRelative(html), 'text/html'); + const link = doc.querySelector('a'); + expect(link.getAttribute('href')).to.equal(ref); + expect(link.textContent).to.equal(ref); + }); + it('leaves other pictures alone', () => { const src = 'https://content.da.live/org/site/.page/pic.png'; const html = `
${picture(src, src)}
`; From 5ec2d9fda86742f926cfb63f27dd45f1a3eb608f Mon Sep 17 00:00:00 2001 From: Ben Peter Date: Tue, 24 Nov 2026 22:45:47 +0100 Subject: [PATCH 13/28] fix(quick-edit): keep linked media bus images relative --- docs/quick-edit-events.md | 6 +++--- nx/blocks/quick-edit-portal/src/utils.js | 12 ++++++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/docs/quick-edit-events.md b/docs/quick-edit-events.md index f4178bd13..f572da91e 100644 --- a/docs/quick-edit-events.md +++ b/docs/quick-edit-events.md @@ -250,9 +250,9 @@ exactly one image. Both hosts upload through nx2 `source.uploadMedia` and reply with the url the upload returned: a `content.da.live` url on DA sites, a media bus url on hlx6 sites (usually relative, `./media_…`), which the iframe resolves against the page. In `SET_BODY` the -standalone portal keeps `./media_` refs relative in both `` and ``, so -the page resolves them against its own url like delivered html (da-live's `prose2aem` -would otherwise point the sources at the portal's origin). +standalone portal keeps `./media_` refs relative in ``, `` and linked +images (``), so the page resolves them against its own url like +delivered html (da-live's `prose2aem` would otherwise point them at the portal's origin). Both hosts use `nx2/public/utils/quick-edit-images.js` for document versions, image-position resolution, and replacement after upload. It accepts the host's diff --git a/nx/blocks/quick-edit-portal/src/utils.js b/nx/blocks/quick-edit-portal/src/utils.js index 9f808a6d6..f5b3f8dcb 100644 --- a/nx/blocks/quick-edit-portal/src/utils.js +++ b/nx/blocks/quick-edit-portal/src/utils.js @@ -35,15 +35,23 @@ function getLivePreviewUrl(owner, repo) { return `${protocol}://main--${repo}--${owner}.${domain}`; } -// prose2aem sets to the resolved img.src; ./media_ must resolve against the page. +// prose2aem resolves ./media_ refs against the portal (sources, linked images); keep them relative. export function keepMediaBusImagesRelative(html) { - if (!html.includes('src="./media_')) return html; + const base = new URL('./', document.baseURI).href; + if (!html.includes('src="./media_') && !html.includes(`${base}media_`)) return html; const doc = new DOMParser().parseFromString(html, 'text/html'); doc.querySelectorAll('picture').forEach((picture) => { const src = picture.querySelector('img')?.getAttribute('src'); if (!src?.startsWith('./media_')) return; picture.querySelectorAll('source').forEach((source) => source.setAttribute('srcset', src)); }); + doc.querySelectorAll('a[data-edit-as="image"]').forEach((link) => { + const href = link.getAttribute('href'); + if (!href?.startsWith(`${base}media_`)) return; + const ref = `./${href.slice(base.length)}`; + if (link.textContent === href) link.textContent = ref; + link.setAttribute('href', ref); + }); return doc.documentElement.outerHTML; } From a0ddc42d386f420c4cca78e1d9c949d03e1d760a Mon Sep 17 00:00:00 2001 From: Ben Peter Date: Tue, 24 Nov 2026 22:46:18 +0100 Subject: [PATCH 14/28] refactor(quick-edit): head the document at the room url --- nx/blocks/quick-edit-portal/src/source.js | 8 +++---- .../blocks/quick-edit-portal/source.test.js | 22 +++++-------------- 2 files changed, 9 insertions(+), 21 deletions(-) diff --git a/nx/blocks/quick-edit-portal/src/source.js b/nx/blocks/quick-edit-portal/src/source.js index b8f0fe84b..ab42fb4a6 100644 --- a/nx/blocks/quick-edit-portal/src/source.js +++ b/nx/blocks/quick-edit-portal/src/source.js @@ -1,4 +1,4 @@ -import { getSourceUrl, source } from '../../../../nx2/utils/api.js'; +import { daFetch, getSourceUrl } from '../../../../nx2/utils/api.js'; export function getOrgSite(mountpoint) { const segments = new URL(mountpoint).pathname.split('/').filter(Boolean); @@ -21,10 +21,8 @@ const getDocPath = (pathname) => (pathname.endsWith('/') ? `${pathname}index.htm export async function loadDocSource({ org, site, pathname }) { const path = getDocPath(pathname); - const [sourceUrl, resp] = await Promise.all([ - getSourceUrl({ org, site, path }), - source.getMetadata({ org, site, path }), - ]); + const sourceUrl = await getSourceUrl({ org, site, path }); + const resp = await daFetch({ url: sourceUrl, opts: { method: 'HEAD' } }); if (!resp.ok) return { error: `Could not load ${path}`, status: resp.status }; return { sourceUrl, permissions: resp.permissions ?? ['read', 'write'] }; } diff --git a/test/nx/blocks/quick-edit-portal/source.test.js b/test/nx/blocks/quick-edit-portal/source.test.js index 7d9adb88b..0de40f7d4 100644 --- a/test/nx/blocks/quick-edit-portal/source.test.js +++ b/test/nx/blocks/quick-edit-portal/source.test.js @@ -5,20 +5,10 @@ import { } from '../../../nx2/mocks/fetch.js'; import { getInitSite, getOrgSite, loadDocSource } from '../../../../nx/blocks/quick-edit-portal/src/source.js'; -const STORAGE_KEY = 'hlx6-upgrade'; - let counter = 0; -const makeOrgSite = ({ hlx6 = false } = {}) => { +const makeOrgSite = () => { counter += 1; - const org = `qe-org-${counter}-${Math.floor(Math.random() * 1e6)}`; - const site = `qe-site-${counter}`; - if (hlx6) { - localStorage.setItem(STORAGE_KEY, JSON.stringify({ - ...(JSON.parse(localStorage.getItem(STORAGE_KEY)) ?? {}), - [`/${org}/${site}`]: true, - })); - } - return { org, site }; + return { org: `qe-org-${counter}-${Math.floor(Math.random() * 1e6)}`, site: `qe-site-${counter}` }; }; describe('quick-edit portal source', () => { @@ -76,8 +66,8 @@ describe('quick-edit portal source', () => { describe('loadDocSource', () => { it('uses the source bus url on hlx6, the same url the da-live canvas names its room with', async () => { - installFetch(); - const { org, site } = makeOrgSite({ hlx6: true }); + installFetch({ pingHlx6: true }); + const { org, site } = makeOrgSite(); const result = await loadDocSource({ org, site, pathname: '/drafts/page' }); const expected = `${AEM_API}/${org}/sites/${site}/source/drafts/page.html`; @@ -107,8 +97,8 @@ describe('quick-edit portal source', () => { }); it('maps a folder path to its index document', async () => { - installFetch(); - const { org, site } = makeOrgSite({ hlx6: true }); + installFetch({ pingHlx6: true }); + const { org, site } = makeOrgSite(); const { sourceUrl } = await loadDocSource({ org, site, pathname: '/drafts/' }); expect(sourceUrl).to.equal(`${AEM_API}/${org}/sites/${site}/source/drafts/index.html`); }); From 13d44efda2333781de3e7b8a62c7c27712c07a99 Mon Sep 17 00:00:00 2001 From: Ben Peter Date: Tue, 24 Nov 2026 22:55:39 +0100 Subject: [PATCH 15/28] docs(api): note the blob type fallback for legacy uploads --- nx2/utils/api.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nx2/utils/api.md b/nx2/utils/api.md index e9076f2db..318726fdb 100644 --- a/nx2/utils/api.md +++ b/nx2/utils/api.md @@ -116,7 +116,7 @@ Document CRUD on `source` paths. Bridges DA's `/source` and AEM's `/sites/{site} | -------------- | --------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `get` | `({ org, site, path })` or `(fullPath)` | GET — raw `Response`. | | `list` | `({ org, site, path?, continuationToken? })` or `(fullPath, { continuationToken? })` | List a folder. Returns `{ ok, items, continuationToken, permissions }` (normalized — items match legacy DA shape regardless of server). Pass `{ org }` (no site) to list at org level — merges DA-legacy folders (`${DA_ADMIN}/list/{org}`) with hlx6 source-bus sites (`org.listSites`), deduped by name. Only DA paginates; `org.listSites` is only queried on the first page (no `continuationToken`). Bulk lists paginate — pass `continuationToken` back into the next call. | -| `save` | `({ org, site, path, body })` or `(fullPath, { body })` | Upload — raw `Response`. POST for both branches. **DA-legacy**: wraps `body` as a Blob in `multipart/form-data` field `data`, with the Blob's type set from the path extension via `TYPE_MAP`. **hlx6**: sends `body` raw (string, Blob, or File); `Content-Type` is set from the path extension via `TYPE_MAP` and overrides any auto-applied Blob type. Extensions not in `TYPE_MAP` send no `Content-Type`. On success, `resp.json()` is normalized to DA's `{ source: { contentUrl } }` shape (`contentUrl` = the written source URL), since the hlx6 endpoint returns an empty body; non-ok responses pass through unchanged. | +| `save` | `({ org, site, path, body })` or `(fullPath, { body })` | Upload — raw `Response`. POST for both branches. **DA-legacy**: wraps `body` as a Blob in `multipart/form-data` field `data`, with the Blob's type set from the path extension via `TYPE_MAP` (for extensions not in `TYPE_MAP`, the type of a Blob/File `body`). **hlx6**: sends `body` raw (string, Blob, or File); `Content-Type` is set from the path extension via `TYPE_MAP` and overrides any auto-applied Blob type. Extensions not in `TYPE_MAP` send no `Content-Type`. On success, `resp.json()` is normalized to DA's `{ source: { contentUrl } }` shape (`contentUrl` = the written source URL), since the hlx6 endpoint returns an empty body; non-ok responses pass through unchanged. | | `getMetadata` | `({ org, site, path })` or `(fullPath)` | HEAD — raw `Response`. Value is in `resp.headers` (`doc-id`, `last-modified`, etc.). | | `delete` | `({ org, site, path, continuationToken? })` or `(fullPath, { continuationToken? })` | DELETE — raw `Response` (typically 204). For recursive folder deletion use `deleteFolder`. | | `copy` | `({ org, site, path, destination, collision?, continuationToken? })` or `(fullPath, { destination, collision?, continuationToken? })` | Raw `Response`. `path` = source, `destination` = target. **hlx6**: PUT to dest URL with `?source=…&collision=…` query. **DA**: POST `/copy/{org}/{site}{path}` with `multipart/form-data` field `destination`. | From 8086736c0bfbf2f0a9388b49db49d19642ef76e0 Mon Sep 17 00:00:00 2001 From: Ben Peter Date: Wed, 25 Nov 2026 00:11:30 +0100 Subject: [PATCH 16/28] test(quick-edit): use owner and repo only on helix 6 sites --- .../blocks/quick-edit-portal/source.test.js | 48 ++++++++++++------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/test/nx/blocks/quick-edit-portal/source.test.js b/test/nx/blocks/quick-edit-portal/source.test.js index 0de40f7d4..07883bf71 100644 --- a/test/nx/blocks/quick-edit-portal/source.test.js +++ b/test/nx/blocks/quick-edit-portal/source.test.js @@ -39,28 +39,44 @@ describe('quick-edit portal source', () => { }); describe('getInitSite', () => { - const owner = 'scdemos'; - const repo = 'demo-hlx6'; + it('reads org and site from the mountpoint url without an upgrade check', async () => { + installFetch({ pingHlx6: true }); + expect(await getInitSite({ mountpoint: `${AEM_API}/scdemos/sites/demo-hlx6/source`, owner: 'x', repo: 'y' })) + .to.deep.equal({ org: 'scdemos', site: 'demo-hlx6' }); + expect(await getInitSite({ mountpoint: { url: 'https://content.da.live/scdemos/demo/' } })) + .to.deep.equal({ org: 'scdemos', site: 'demo' }); + expect(calls.length).to.equal(0); + }); - it('reads org and site from the mountpoint url', () => { - expect(getInitSite({ mountpoint: `${AEM_API}/scdemos/sites/demo-hlx6/source`, owner: 'x', repo: 'y' })) + it('uses owner and repo without a url when the site is on helix 6', async () => { + installFetch({ pingHlx6: true }); + const { org: owner, site: repo } = makeOrgSite(); + expect(await getInitSite({ owner, repo, mountpoints: [] })) .to.deep.equal({ org: owner, site: repo }); - expect(getInitSite({ mountpoint: { url: 'https://content.da.live/scdemos/demo/' } })) - .to.deep.equal({ org: owner, site: 'demo' }); }); - it('uses owner and repo for a source bus without a url', () => { - expect(getInitSite({ mountpoint: { type: 'sourcebus' }, owner, repo })) - .to.deep.equal({ org: owner, site: repo }); - expect(getInitSite({ contentSourceType: 'sourcebus', owner, repo })) - .to.deep.equal({ org: owner, site: repo }); - expect(getInitSite({ apiUpgrade: true, owner, repo })) - .to.deep.equal({ org: owner, site: repo }); + it('finds no site without a url on a legacy site, even with apiUpgrade', async () => { + installFetch(); + const { org: owner, site: repo } = makeOrgSite(); + const config = { owner, repo, apiUpgrade: true, mountpoints: [] }; + expect(await getInitSite(config)).to.deep.equal({}); }); - it('finds no site without a mountpoint or a source bus', () => { - expect(getInitSite({ owner, repo })).to.deep.equal({}); - expect(getInitSite(undefined)).to.deep.equal({}); + it('finds no site when the upgrade check fails', async () => { + restoreFetch(); + const savedFetch = window.fetch; + window.fetch = async () => { throw new TypeError('Failed to fetch'); }; + const { org: owner, site: repo } = makeOrgSite(); + const site = await getInitSite({ owner, repo, apiUpgrade: true }); + window.fetch = savedFetch; + expect(site).to.deep.equal({}); + }); + + it('finds no site without a mountpoint url or owner and repo', async () => { + installFetch({ pingHlx6: true }); + expect(await getInitSite({ owner: 'scdemos' })).to.deep.equal({}); + expect(await getInitSite(undefined)).to.deep.equal({}); + expect(calls.length).to.equal(0); }); }); From e1a47a2e3555c6c6186a876a177a955faac16efa Mon Sep 17 00:00:00 2001 From: Ben Peter Date: Wed, 25 Nov 2026 00:11:54 +0100 Subject: [PATCH 17/28] fix(quick-edit): use owner and repo only on helix 6 sites --- docs/quick-edit-events.md | 8 ++++---- nx/blocks/quick-edit-portal/quick-edit-portal.js | 2 +- nx/blocks/quick-edit-portal/src/source.js | 12 +++++------- nx/utils/message-types.js | 2 +- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/docs/quick-edit-events.md b/docs/quick-edit-events.md index f572da91e..f79f509cf 100644 --- a/docs/quick-edit-events.md +++ b/docs/quick-edit-events.md @@ -84,10 +84,10 @@ parallel one. If you do add a new key: `https://api.aem.live/{org}/sites/{site}/source` on hlx6 (source bus) sites. Some sites build the DA shape themselves when there's no sidekick. A source bus site can also have no url (site config `content.source` is just `{ type: 'sourcebus' }`), and then the sidekick -sends no mountpoint. In that case the portal uses `config.owner` / `config.repo` if the config -marks a source bus (`mountpoint.type` or `contentSourceType` is `sourcebus`) or an upgraded -site (`apiUpgrade: true`). The standalone portal reads org/site from either url shape and asks -nx2 `api.js` (`isHlx6`) where the document lives, +sends no mountpoint. In that case the portal uses `config.owner` / `config.repo` when the +upgrade check (nx2 `isHlx6`) says the site is on Helix 6. It ignores `apiUpgrade`: the sidekick +sends `true` for most legacy sites too. The standalone portal reads org/site from either url +shape and asks nx2 `api.js` (`isHlx6`) where the document lives, so the payload shape doesn't decide the store. It names the collab room with `getSourceUrl`, the url the da-live editors use, so quick edit and the canvas join the same room. diff --git a/nx/blocks/quick-edit-portal/quick-edit-portal.js b/nx/blocks/quick-edit-portal/quick-edit-portal.js index f4fc1b11f..f20ebf332 100644 --- a/nx/blocks/quick-edit-portal/quick-edit-portal.js +++ b/nx/blocks/quick-edit-portal/quick-edit-portal.js @@ -73,7 +73,7 @@ export default async function decorate(el) { const { config, location } = e.data.payload ?? {}; const path = location?.pathname; - const { org: owner, site: repo } = getInitSite(config); + const { org: owner, site: repo } = await getInitSite(config); if (!owner || !repo) { return; diff --git a/nx/blocks/quick-edit-portal/src/source.js b/nx/blocks/quick-edit-portal/src/source.js index ab42fb4a6..26ece2b56 100644 --- a/nx/blocks/quick-edit-portal/src/source.js +++ b/nx/blocks/quick-edit-portal/src/source.js @@ -1,4 +1,4 @@ -import { daFetch, getSourceUrl } from '../../../../nx2/utils/api.js'; +import { daFetch, getSourceUrl, isHlx6 } from '../../../../nx2/utils/api.js'; export function getOrgSite(mountpoint) { const segments = new URL(mountpoint).pathname.split('/').filter(Boolean); @@ -7,14 +7,12 @@ export function getOrgSite(mountpoint) { return { org, site: sites }; } -export function getInitSite(config) { - const { - mountpoint, contentSourceType, apiUpgrade, owner, repo, - } = config ?? {}; +export async function getInitSite(config) { + const { mountpoint, owner, repo } = config ?? {}; const url = typeof mountpoint === 'string' ? mountpoint : mountpoint?.url; if (url) return getOrgSite(url); - const sourceBus = mountpoint?.type === 'sourcebus' || contentSourceType === 'sourcebus' || apiUpgrade === true; - return sourceBus ? { org: owner, site: repo } : {}; + const hlx6 = owner && repo && await isHlx6(owner, repo).catch(() => false); + return hlx6 ? { org: owner, site: repo } : {}; } const getDocPath = (pathname) => (pathname.endsWith('/') ? `${pathname}index.html` : `${pathname}.html`); diff --git a/nx/utils/message-types.js b/nx/utils/message-types.js index d853a79c8..fd0acf9b9 100644 --- a/nx/utils/message-types.js +++ b/nx/utils/message-types.js @@ -6,7 +6,7 @@ // context (why a message exists, which host implementations wire it up). export const MESSAGE_TYPES = Object.freeze({ // Host <-> iframe: handshake - INIT: 'init', // { config: { mountpoint: DA content or hlx6 source bus url, owner, repo, apiUpgrade }, location: { pathname } } + INIT: 'init', // { config: { mountpoint: DA content or hlx6 source bus url, owner, repo }, location: { pathname } } READY: 'ready', // no payload // Host -> iframe From dbded81d9a57085481a3a81e5534d774ebb57149 Mon Sep 17 00:00:00 2001 From: Ben Peter Date: Wed, 25 Nov 2026 00:12:46 +0100 Subject: [PATCH 18/28] test(quick-edit): ask for the image cookie once across retries --- .../quick-edit-portal.test.js | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 test/nx/blocks/quick-edit-portal/quick-edit-portal.test.js diff --git a/test/nx/blocks/quick-edit-portal/quick-edit-portal.test.js b/test/nx/blocks/quick-edit-portal/quick-edit-portal.test.js new file mode 100644 index 000000000..fc659e6c3 --- /dev/null +++ b/test/nx/blocks/quick-edit-portal/quick-edit-portal.test.js @@ -0,0 +1,58 @@ +import { expect } from '@esm-bundle/chai'; +import { setConfig } from '../../../../nx/scripts/nexter.js'; +import { DA_ADMIN } from '../../../../nx2/utils/utils.js'; +import { MESSAGE_TYPES } from '../../../../nx/utils/message-types.js'; + +setConfig({ imsClientId: 'test-client' }); + +const imsScript = document.createElement('script'); +imsScript.type = 'text/plain'; +imsScript.src = 'https://auth.services.adobe.com/imslib/imslib.min.js'; +document.head.append(imsScript); +window.adobeIMS = { + getAccessToken: () => ({ token: 'test-token' }), + getProfile: async () => ({}), +}; + +const { default: decorate } = await import('../../../../nx/blocks/quick-edit-portal/quick-edit-portal.js'); + +const wait = (ms) => new Promise((resolve) => { setTimeout(resolve, ms); }); + +describe('quick-edit portal', () => { + it('asks for the image cookie once when opening the document keeps failing', async () => { + const owner = `qe-portal-${Math.floor(Math.random() * 1e6)}`; + const calls = []; + const savedFetch = window.fetch; + window.fetch = async (url, opts = {}) => { + const href = url.toString(); + calls.push({ href, method: opts.method || 'GET' }); + if (href.endsWith('/gimme_cookie') || href.includes('/ping/')) return new Response(''); + throw new TypeError('Failed to fetch'); + }; + + try { + const decorated = decorate(document.createElement('div')); + window.adobeid.onReady(); + await decorated; + + const init = async () => { + const { port2 } = new MessageChannel(); + const payload = { + config: { mountpoint: `https://content.da.live/${owner}/site/` }, + location: { pathname: '/page' }, + }; + window.postMessage({ type: MESSAGE_TYPES.INIT, payload }, '*', [port2]); + await wait(200); + }; + await init(); + await init(); + } finally { + window.fetch = savedFetch; + } + + const heads = calls.filter(({ href, method }) => method === 'HEAD' && href.startsWith(DA_ADMIN)); + const cookies = calls.filter(({ href }) => href.endsWith('/gimme_cookie')); + expect(heads.length).to.equal(2); + expect(cookies.length).to.equal(1); + }); +}); From 6fbe83ce339aa6f6cd294f0670e6ddce7447c8e8 Mon Sep 17 00:00:00 2001 From: Ben Peter Date: Wed, 25 Nov 2026 00:13:03 +0100 Subject: [PATCH 19/28] fix(quick-edit): ask for the image cookie once across retries --- nx/blocks/quick-edit-portal/quick-edit-portal.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/nx/blocks/quick-edit-portal/quick-edit-portal.js b/nx/blocks/quick-edit-portal/quick-edit-portal.js index f20ebf332..d65d05228 100644 --- a/nx/blocks/quick-edit-portal/quick-edit-portal.js +++ b/nx/blocks/quick-edit-portal/quick-edit-portal.js @@ -108,7 +108,10 @@ export default async function decorate(el) { editorPort = port; editorPromise ||= (async () => { el.innerHTML = ''; - if (!bootstrapComplete) await getImageCookie(owner, repo); + if (!bootstrapComplete) { + await getImageCookie(owner, repo); + bootstrapComplete = true; + } await initProse(owner, repo, path, el, ctx); })(); try { From 34a05b483719070a6fe1b12a659d2eef20c6468a Mon Sep 17 00:00:00 2001 From: Ben Peter Date: Wed, 25 Nov 2026 00:15:01 +0100 Subject: [PATCH 20/28] test(quick-edit): report a missing sign-in on preview --- .../nx/blocks/quick-edit-portal/utils.test.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/nx/blocks/quick-edit-portal/utils.test.js b/test/nx/blocks/quick-edit-portal/utils.test.js index 6364eeacd..853dc4457 100644 --- a/test/nx/blocks/quick-edit-portal/utils.test.js +++ b/test/nx/blocks/quick-edit-portal/utils.test.js @@ -6,6 +6,9 @@ import { import { handlePreview, keepMediaBusImagesRelative } from '../../../../nx/blocks/quick-edit-portal/src/utils.js'; import { MESSAGE_TYPES } from '../../../../nx/utils/message-types.js'; +// The IMS mock instance that nx2/utils/api.js loads through the import map. +const { resetMockIms, setMockIms } = await import(`${window.location.origin}/nx2/utils/ims.js`); + let counter = 0; const makeCtx = ({ hlx6 = false, path = '/drafts/page' } = {}) => { counter += 1; @@ -86,6 +89,22 @@ describe('quick-edit portal preview', () => { expect(payload.error).to.contain('Failed to preview'); }); + it('reports a missing sign-in without sending a request', async () => { + installFetch(); + setMockIms({ anonymous: true }); + const ctx = makeCtx({ hlx6: true }); + try { + await handlePreview(ctx); + } finally { + resetMockIms(); + } + + expect(calls.length).to.equal(0); + const { type, payload } = ctx.posted.at(-1); + expect(type).to.equal(MESSAGE_TYPES.PREVIEW); + expect(payload).to.deep.equal({ ok: false, error: 'Failed to preview: not signed in' }); + }); + it('reports a failed preview', async () => { installFetch({ status: 401 }); const ctx = makeCtx({ hlx6: true }); From 4b78f7c5de95e962c927594c046e66c02551fd44 Mon Sep 17 00:00:00 2001 From: Ben Peter Date: Wed, 25 Nov 2026 00:15:20 +0100 Subject: [PATCH 21/28] fix(quick-edit): report a missing sign-in on preview --- nx/blocks/quick-edit-portal/src/utils.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nx/blocks/quick-edit-portal/src/utils.js b/nx/blocks/quick-edit-portal/src/utils.js index f5b3f8dcb..0180705a5 100644 --- a/nx/blocks/quick-edit-portal/src/utils.js +++ b/nx/blocks/quick-edit-portal/src/utils.js @@ -265,11 +265,12 @@ export async function signIn() { // Not aem.preview: daFetch also sends the token in x-content-source-authorization (da-nx#866). async function requestPreview({ owner, repo, path }) { + const { accessToken } = await loadApiIms(); + if (!accessToken) return 'not signed in'; const page = path.endsWith('/') ? `${path}index` : path; const url = await isHlx6(owner, repo) ? `${AEM_API}/${owner}/sites/${repo}/preview${page}` : `${HLX_ADMIN}/preview/${owner}/${repo}/main${page}`; - const { accessToken } = await loadApiIms(); const resp = await fetch(url, { method: 'POST', headers: { Authorization: `Bearer ${accessToken.token}` } }); return resp.ok ? undefined : (resp.statusText || `${resp.status}`); } From bb1261617f51bb9cd2e5ab4bc516e3b934c2f621 Mon Sep 17 00:00:00 2001 From: Ben Peter Date: Wed, 25 Nov 2026 00:15:29 +0100 Subject: [PATCH 22/28] refactor(quick-edit): send the preview reply from one place --- nx/blocks/quick-edit-portal/src/utils.js | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/nx/blocks/quick-edit-portal/src/utils.js b/nx/blocks/quick-edit-portal/src/utils.js index 0180705a5..2dbde6139 100644 --- a/nx/blocks/quick-edit-portal/src/utils.js +++ b/nx/blocks/quick-edit-portal/src/utils.js @@ -277,13 +277,8 @@ async function requestPreview({ owner, repo, path }) { export async function handlePreview(ctx) { const error = await requestPreview(ctx).catch((e) => e.message); - if (error === undefined) { - ctx.port.postMessage({ type: MESSAGE_TYPES.PREVIEW, payload: { ok: true } }); - return; - } + const payload = error === undefined ? { ok: true } : { ok: false, error: `Failed to preview: ${error}` }; // eslint-disable-next-line no-console - console.error('Failed to preview:', error); - ctx.port.postMessage({ - type: MESSAGE_TYPES.PREVIEW, payload: { ok: false, error: `Failed to preview: ${error}` }, - }); + if (!payload.ok) console.error(payload.error); + ctx.port.postMessage({ type: MESSAGE_TYPES.PREVIEW, payload }); } From b1147ca5d1f6810e53b5fde27141310cd21bfaa4 Mon Sep 17 00:00:00 2001 From: Ben Peter Date: Wed, 25 Nov 2026 01:04:35 +0100 Subject: [PATCH 23/28] revert(quick-edit): move the start retry to its own branch --- .../quick-edit-portal/quick-edit-portal.js | 15 +---- .../quick-edit-portal.test.js | 58 ------------------- .../blocks/quick-edit-portal/source.test.js | 2 +- 3 files changed, 3 insertions(+), 72 deletions(-) delete mode 100644 test/nx/blocks/quick-edit-portal/quick-edit-portal.test.js diff --git a/nx/blocks/quick-edit-portal/quick-edit-portal.js b/nx/blocks/quick-edit-portal/quick-edit-portal.js index d65d05228..dc3a573fb 100644 --- a/nx/blocks/quick-edit-portal/quick-edit-portal.js +++ b/nx/blocks/quick-edit-portal/quick-edit-portal.js @@ -108,21 +108,10 @@ export default async function decorate(el) { editorPort = port; editorPromise ||= (async () => { el.innerHTML = ''; - if (!bootstrapComplete) { - await getImageCookie(owner, repo); - bootstrapComplete = true; - } + if (!bootstrapComplete) await getImageCookie(owner, repo); await initProse(owner, repo, path, el, ctx); })(); - try { - await editorPromise; - } catch (error) { - editorPromise = undefined; - port.close(); - // eslint-disable-next-line no-console - console.error('Failed to open the document for quick edit', error); - return; - } + await editorPromise; if (editorPort !== port) { port.close(); return; diff --git a/test/nx/blocks/quick-edit-portal/quick-edit-portal.test.js b/test/nx/blocks/quick-edit-portal/quick-edit-portal.test.js deleted file mode 100644 index fc659e6c3..000000000 --- a/test/nx/blocks/quick-edit-portal/quick-edit-portal.test.js +++ /dev/null @@ -1,58 +0,0 @@ -import { expect } from '@esm-bundle/chai'; -import { setConfig } from '../../../../nx/scripts/nexter.js'; -import { DA_ADMIN } from '../../../../nx2/utils/utils.js'; -import { MESSAGE_TYPES } from '../../../../nx/utils/message-types.js'; - -setConfig({ imsClientId: 'test-client' }); - -const imsScript = document.createElement('script'); -imsScript.type = 'text/plain'; -imsScript.src = 'https://auth.services.adobe.com/imslib/imslib.min.js'; -document.head.append(imsScript); -window.adobeIMS = { - getAccessToken: () => ({ token: 'test-token' }), - getProfile: async () => ({}), -}; - -const { default: decorate } = await import('../../../../nx/blocks/quick-edit-portal/quick-edit-portal.js'); - -const wait = (ms) => new Promise((resolve) => { setTimeout(resolve, ms); }); - -describe('quick-edit portal', () => { - it('asks for the image cookie once when opening the document keeps failing', async () => { - const owner = `qe-portal-${Math.floor(Math.random() * 1e6)}`; - const calls = []; - const savedFetch = window.fetch; - window.fetch = async (url, opts = {}) => { - const href = url.toString(); - calls.push({ href, method: opts.method || 'GET' }); - if (href.endsWith('/gimme_cookie') || href.includes('/ping/')) return new Response(''); - throw new TypeError('Failed to fetch'); - }; - - try { - const decorated = decorate(document.createElement('div')); - window.adobeid.onReady(); - await decorated; - - const init = async () => { - const { port2 } = new MessageChannel(); - const payload = { - config: { mountpoint: `https://content.da.live/${owner}/site/` }, - location: { pathname: '/page' }, - }; - window.postMessage({ type: MESSAGE_TYPES.INIT, payload }, '*', [port2]); - await wait(200); - }; - await init(); - await init(); - } finally { - window.fetch = savedFetch; - } - - const heads = calls.filter(({ href, method }) => method === 'HEAD' && href.startsWith(DA_ADMIN)); - const cookies = calls.filter(({ href }) => href.endsWith('/gimme_cookie')); - expect(heads.length).to.equal(2); - expect(cookies.length).to.equal(1); - }); -}); diff --git a/test/nx/blocks/quick-edit-portal/source.test.js b/test/nx/blocks/quick-edit-portal/source.test.js index 07883bf71..f5dc9b44a 100644 --- a/test/nx/blocks/quick-edit-portal/source.test.js +++ b/test/nx/blocks/quick-edit-portal/source.test.js @@ -126,7 +126,7 @@ describe('quick-edit portal source', () => { expect(sourceUrl).to.equal(`${DA_ADMIN}/source/${org}/${site}/index.html`); }); - it('rejects when the upgrade check fails, so the portal can retry', async () => { + it('rejects when the upgrade check fails', async () => { const savedFetch = window.fetch; window.fetch = async () => { throw new TypeError('Failed to fetch'); }; const { org, site } = makeOrgSite(); From 270f96fdc277c9047d0de21935cdeda15d9a257a Mon Sep 17 00:00:00 2001 From: Ben Peter Date: Wed, 25 Nov 2026 01:04:48 +0100 Subject: [PATCH 24/28] revert(quick-edit): move the preview status code to its own branch --- nx/blocks/quick-edit-portal/src/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nx/blocks/quick-edit-portal/src/utils.js b/nx/blocks/quick-edit-portal/src/utils.js index 2dbde6139..fce4304c7 100644 --- a/nx/blocks/quick-edit-portal/src/utils.js +++ b/nx/blocks/quick-edit-portal/src/utils.js @@ -272,7 +272,7 @@ async function requestPreview({ owner, repo, path }) { ? `${AEM_API}/${owner}/sites/${repo}/preview${page}` : `${HLX_ADMIN}/preview/${owner}/${repo}/main${page}`; const resp = await fetch(url, { method: 'POST', headers: { Authorization: `Bearer ${accessToken.token}` } }); - return resp.ok ? undefined : (resp.statusText || `${resp.status}`); + return resp.ok ? undefined : resp.statusText; } export async function handlePreview(ctx) { From 73a01d376fb4397e29f142d7e2d7e6df7c19a0a9 Mon Sep 17 00:00:00 2001 From: Ben Peter Date: Wed, 25 Nov 2026 19:12:40 +0100 Subject: [PATCH 25/28] test(quick-edit): fall back to legacy da when the upgrade check fails --- .../blocks/quick-edit-portal/images.test.js | 17 ++++++++++++++ .../blocks/quick-edit-portal/source.test.js | 22 +++++++++++++------ .../nx/blocks/quick-edit-portal/utils.test.js | 15 +++++++++++++ 3 files changed, 47 insertions(+), 7 deletions(-) diff --git a/test/nx/blocks/quick-edit-portal/images.test.js b/test/nx/blocks/quick-edit-portal/images.test.js index 180c83dd4..8c7d3b322 100644 --- a/test/nx/blocks/quick-edit-portal/images.test.js +++ b/test/nx/blocks/quick-edit-portal/images.test.js @@ -186,6 +186,23 @@ describe('standalone quick-edit image replacement', () => { expect(uploads[0].opts.body.get('data').type).to.equal('image/webp'); }); + it('uploads to the da source store when the upgrade check fails', async () => { + ctx.owner = `qe-img-down-${Math.floor(Math.random() * 1e6)}`; + ctx.repo = 'site'; + const contentUrl = `https://content.da.live/${ctx.owner}/site/.page/pic.png`; + window.fetch = async (url, opts = {}) => { + if (url.startsWith(`${HLX_ADMIN}/ping/`)) throw new TypeError('Failed to fetch'); + uploads.push({ url, opts }); + return new Response(JSON.stringify({ source: { contentUrl } }), { status: 201 }); + }; + await handleImageReplace(request(), ctx); + + expect(uploads).to.have.length(1); + expect(uploads[0].url).to.equal(`${DA_ADMIN}/source/${ctx.owner}/site/.page/pic.png`); + expect(uploads[0].opts.body).to.be.instanceof(FormData); + expect(posted.at(-1).payload.newSrc).to.equal(contentUrl); + }); + it('uploads to the media bus on hlx6 sites and uses the returned media url', async () => { const org = `qe-img-${Math.floor(Math.random() * 1e6)}`; const site = 'hlx6-site'; diff --git a/test/nx/blocks/quick-edit-portal/source.test.js b/test/nx/blocks/quick-edit-portal/source.test.js index f5dc9b44a..67c3644d9 100644 --- a/test/nx/blocks/quick-edit-portal/source.test.js +++ b/test/nx/blocks/quick-edit-portal/source.test.js @@ -1,5 +1,5 @@ import { expect } from '@esm-bundle/chai'; -import { AEM_API, DA_ADMIN } from '../../../../nx2/utils/utils.js'; +import { AEM_API, DA_ADMIN, HLX_ADMIN } from '../../../../nx2/utils/utils.js'; import { calls, installFetch, restoreFetch, lastCall, } from '../../../nx2/mocks/fetch.js'; @@ -126,13 +126,21 @@ describe('quick-edit portal source', () => { expect(sourceUrl).to.equal(`${DA_ADMIN}/source/${org}/${site}/index.html`); }); - it('rejects when the upgrade check fails', async () => { - const savedFetch = window.fetch; - window.fetch = async () => { throw new TypeError('Failed to fetch'); }; + it('uses the da-admin source url when the upgrade check fails', async () => { + installFetch(); const { org, site } = makeOrgSite(); - const error = await loadDocSource({ org, site, pathname: '/page' }).then(() => null, (e) => e); - window.fetch = savedFetch; - expect(error).to.be.instanceof(Error); + const pingFetch = window.fetch; + window.fetch = async (url, opts) => { + if (url.startsWith(`${HLX_ADMIN}/ping/`)) throw new TypeError('Failed to fetch'); + return pingFetch(url, opts); + }; + const result = await loadDocSource({ org, site, pathname: '/page' }); + + const expected = `${DA_ADMIN}/source/${org}/${site}/page.html`; + expect(result.sourceUrl).to.equal(expected); + expect(lastCall().url).to.equal(expected); + expect(lastCall().method).to.equal('HEAD'); + expect(result.permissions).to.deep.equal(['read', 'write']); }); it('returns an error with the status when the document cannot be read', async () => { diff --git a/test/nx/blocks/quick-edit-portal/utils.test.js b/test/nx/blocks/quick-edit-portal/utils.test.js index 853dc4457..76a3a175f 100644 --- a/test/nx/blocks/quick-edit-portal/utils.test.js +++ b/test/nx/blocks/quick-edit-portal/utils.test.js @@ -49,6 +49,21 @@ describe('quick-edit portal preview', () => { expect(ctx.posted.at(-1).payload.ok).to.equal(true); }); + it('previews through the legacy admin when the upgrade check fails', async () => { + installFetch(); + const pingFetch = window.fetch; + window.fetch = async (url, opts) => { + if (url.startsWith(`${HLX_ADMIN}/ping/`)) throw new TypeError('Failed to fetch'); + return pingFetch(url, opts); + }; + const ctx = makeCtx(); + await handlePreview(ctx); + + expect(lastCall().url).to.equal(`${HLX_ADMIN}/preview/${ctx.owner}/${ctx.repo}/main/drafts/page`); + expect(lastCall().method).to.equal('POST'); + expect(ctx.posted.at(-1)).to.deep.equal({ type: MESSAGE_TYPES.PREVIEW, payload: { ok: true } }); + }); + it('previews the index document of a folder', async () => { installFetch(); const ctx = makeCtx({ hlx6: true, path: '/drafts/' }); From b83c1ca122e49eb8b756e6b0115252806f5a188d Mon Sep 17 00:00:00 2001 From: Ben Peter Date: Wed, 25 Nov 2026 19:13:05 +0100 Subject: [PATCH 26/28] fix(quick-edit): use legacy da when the upgrade check fails --- nx/blocks/quick-edit-portal/src/images.js | 4 ++-- nx/blocks/quick-edit-portal/src/source.js | 26 ++++++++++++++++++++--- nx/blocks/quick-edit-portal/src/utils.js | 5 +++-- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/nx/blocks/quick-edit-portal/src/images.js b/nx/blocks/quick-edit-portal/src/images.js index 465f65f05..560e4477a 100644 --- a/nx/blocks/quick-edit-portal/src/images.js +++ b/nx/blocks/quick-edit-portal/src/images.js @@ -1,5 +1,5 @@ /* eslint-disable import/prefer-default-export */ -import { source } from '../../../../nx2/utils/api.js'; +import { uploadImage } from './source.js'; import { MESSAGE_TYPES } from '../../../utils/message-types.js'; import { resolveImagePosition, updateImageInDocument, @@ -46,7 +46,7 @@ export async function handleImageReplace(payload, ctx) { const parentPath = ctx.path === '/' ? '' : ctx.path.replace(/\/[^/]+$/, ''); const uploadPath = `${parentPath}/.${pageName}/${fileName}`; - const resp = await source.uploadMedia({ + const resp = await uploadImage({ org: ctx.owner, site: ctx.repo, path: uploadPath, body: blob, }); diff --git a/nx/blocks/quick-edit-portal/src/source.js b/nx/blocks/quick-edit-portal/src/source.js index 26ece2b56..ed2c4e9a0 100644 --- a/nx/blocks/quick-edit-portal/src/source.js +++ b/nx/blocks/quick-edit-portal/src/source.js @@ -1,4 +1,15 @@ -import { daFetch, getSourceUrl, isHlx6 } from '../../../../nx2/utils/api.js'; +import { + daFetch, getSourceUrl, isHlx6, source, +} from '../../../../nx2/utils/api.js'; +import { DA_ADMIN } from '../../../../nx2/utils/utils.js'; + +export async function checkSite(org, site) { + try { + return await isHlx6(org, site); + } catch { + return false; + } +} export function getOrgSite(mountpoint) { const segments = new URL(mountpoint).pathname.split('/').filter(Boolean); @@ -11,7 +22,7 @@ export async function getInitSite(config) { const { mountpoint, owner, repo } = config ?? {}; const url = typeof mountpoint === 'string' ? mountpoint : mountpoint?.url; if (url) return getOrgSite(url); - const hlx6 = owner && repo && await isHlx6(owner, repo).catch(() => false); + const hlx6 = owner && repo && await checkSite(owner, repo); return hlx6 ? { org: owner, site: repo } : {}; } @@ -19,8 +30,17 @@ const getDocPath = (pathname) => (pathname.endsWith('/') ? `${pathname}index.htm export async function loadDocSource({ org, site, pathname }) { const path = getDocPath(pathname); - const sourceUrl = await getSourceUrl({ org, site, path }); + const sourceUrl = await checkSite(org, site) + ? await getSourceUrl({ org, site, path }) + : `${DA_ADMIN}/source/${org}/${site}${path}`; const resp = await daFetch({ url: sourceUrl, opts: { method: 'HEAD' } }); if (!resp.ok) return { error: `Could not load ${path}`, status: resp.status }; return { sourceUrl, permissions: resp.permissions ?? ['read', 'write'] }; } + +export async function uploadImage({ org, site, path, body }) { + if (await checkSite(org, site)) return source.uploadMedia({ org, site, path, body }); + const formData = new FormData(); + formData.append('data', body); + return daFetch({ url: `${DA_ADMIN}/source/${org}/${site}${path}`, opts: { method: 'POST', body: formData } }); +} diff --git a/nx/blocks/quick-edit-portal/src/utils.js b/nx/blocks/quick-edit-portal/src/utils.js index fce4304c7..3e3333253 100644 --- a/nx/blocks/quick-edit-portal/src/utils.js +++ b/nx/blocks/quick-edit-portal/src/utils.js @@ -1,7 +1,8 @@ import { handleSignIn, loadIms } from '../../../utils/ims.js'; import { MESSAGE_TYPES } from '../../../utils/message-types.js'; -import { isHlx6, loadIms as loadApiIms } from '../../../../nx2/utils/api.js'; +import { loadIms as loadApiIms } from '../../../../nx2/utils/api.js'; import { AEM_API, HLX_ADMIN } from '../../../../nx2/utils/utils.js'; +import { checkSite } from './source.js'; import { isRenderedBlock } from './rerender-scope.js'; const DA_LIVE_PREVIEW_ENVS = { @@ -268,7 +269,7 @@ async function requestPreview({ owner, repo, path }) { const { accessToken } = await loadApiIms(); if (!accessToken) return 'not signed in'; const page = path.endsWith('/') ? `${path}index` : path; - const url = await isHlx6(owner, repo) + const url = await checkSite(owner, repo) ? `${AEM_API}/${owner}/sites/${repo}/preview${page}` : `${HLX_ADMIN}/preview/${owner}/${repo}/main${page}`; const resp = await fetch(url, { method: 'POST', headers: { Authorization: `Bearer ${accessToken.token}` } }); From 7ca09e48a70325654e884ed9f3947a57853ee00d Mon Sep 17 00:00:00 2001 From: Ben Peter Date: Wed, 25 Nov 2026 19:13:24 +0100 Subject: [PATCH 27/28] docs(quick-edit): describe the legacy fallback of a failed upgrade check --- docs/quick-edit-events.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/quick-edit-events.md b/docs/quick-edit-events.md index f79f509cf..c4933971b 100644 --- a/docs/quick-edit-events.md +++ b/docs/quick-edit-events.md @@ -88,7 +88,9 @@ sends no mountpoint. In that case the portal uses `config.owner` / `config.repo` upgrade check (nx2 `isHlx6`) says the site is on Helix 6. It ignores `apiUpgrade`: the sidekick sends `true` for most legacy sites too. The standalone portal reads org/site from either url shape and asks nx2 `api.js` (`isHlx6`) where the document lives, -so the payload shape doesn't decide the store. It names the collab room with +so the payload shape doesn't decide the store. If the check fails (the ping gets no answer), the +portal treats the site as legacy DA, as it did before Helix 6 support: it opens, uploads and +previews through the legacy DA and Helix admin APIs. It names the collab room with `getSourceUrl`, the url the da-live editors use, so quick edit and the canvas join the same room. From 5ebc62c5fa1ddf0003ec7a8b05b915f944bfc339 Mon Sep 17 00:00:00 2001 From: Ben Peter Date: Sat, 28 Nov 2026 12:25:11 +0100 Subject: [PATCH 28/28] refactor(quick-edit): keep source routing in the portal --- docs/quick-edit-events.md | 10 +++--- nx/blocks/quick-edit-portal/src/source.js | 8 ++--- nx2/utils/api.d.ts | 6 ---- nx2/utils/api.js | 17 +++------- nx2/utils/api.md | 16 ++-------- test/nx2/utils/api.test.js | 39 ----------------------- 6 files changed, 16 insertions(+), 80 deletions(-) diff --git a/docs/quick-edit-events.md b/docs/quick-edit-events.md index c4933971b..b3b8fb892 100644 --- a/docs/quick-edit-events.md +++ b/docs/quick-edit-events.md @@ -90,9 +90,8 @@ sends `true` for most legacy sites too. The standalone portal reads org/site fro shape and asks nx2 `api.js` (`isHlx6`) where the document lives, so the payload shape doesn't decide the store. If the check fails (the ping gets no answer), the portal treats the site as legacy DA, as it did before Helix 6 support: it opens, uploads and -previews through the legacy DA and Helix admin APIs. It names the collab room with -`getSourceUrl`, the url the da-live editors use, so quick edit and the canvas join the -same room. +previews through the legacy DA and Helix admin APIs. Quick edit and the canvas both use +the document's source URL as the collab room name. ### `DROP_TARGET` @@ -249,8 +248,9 @@ upload. An out-of-date/missing index fails instead of choosing an image by URL. For older iframes, a URL-only request is accepted only when it identifies exactly one image. -Both hosts upload through nx2 `source.uploadMedia` and reply with the url the upload -returned: a `content.da.live` url on DA sites, a media bus url on hlx6 sites (usually +Both hosts use nx2 `source.uploadMedia` on Helix 6. On legacy DA, the standalone portal +posts the multipart upload directly. Both reply with the url the upload returned: +a `content.da.live` url on DA sites, a media bus url on hlx6 sites (usually relative, `./media_…`), which the iframe resolves against the page. In `SET_BODY` the standalone portal keeps `./media_` refs relative in ``, `` and linked images (``), so the page resolves them against its own url like diff --git a/nx/blocks/quick-edit-portal/src/source.js b/nx/blocks/quick-edit-portal/src/source.js index ed2c4e9a0..4460d125f 100644 --- a/nx/blocks/quick-edit-portal/src/source.js +++ b/nx/blocks/quick-edit-portal/src/source.js @@ -1,7 +1,5 @@ -import { - daFetch, getSourceUrl, isHlx6, source, -} from '../../../../nx2/utils/api.js'; -import { DA_ADMIN } from '../../../../nx2/utils/utils.js'; +import { daFetch, isHlx6, source } from '../../../../nx2/utils/api.js'; +import { AEM_API, DA_ADMIN } from '../../../../nx2/utils/utils.js'; export async function checkSite(org, site) { try { @@ -31,7 +29,7 @@ const getDocPath = (pathname) => (pathname.endsWith('/') ? `${pathname}index.htm export async function loadDocSource({ org, site, pathname }) { const path = getDocPath(pathname); const sourceUrl = await checkSite(org, site) - ? await getSourceUrl({ org, site, path }) + ? `${AEM_API}/${org}/sites/${site}/source${path}` : `${DA_ADMIN}/source/${org}/${site}${path}`; const resp = await daFetch({ url: sourceUrl, opts: { method: 'HEAD' } }); if (!resp.ok) return { error: `Could not load ${path}`, status: resp.status }; diff --git a/nx2/utils/api.d.ts b/nx2/utils/api.d.ts index d12cf594c..ad8343c3c 100644 --- a/nx2/utils/api.d.ts +++ b/nx2/utils/api.d.ts @@ -53,12 +53,6 @@ export function signout(): void; /** Split `/org/site/file/path` into `{ org, site, path }`. */ export function fromPath(fullPath: string): { org: string; site: string; path: string }; -/** - * Source url of a document without requesting it: `${AEM_API}/{org}/sites/{site}/source{path}` - * on hlx6, `${DA_ADMIN}/source/{org}/{site}{path}` on legacy DA. Collab rooms are named with it. - */ -export function getSourceUrl(arg: { org: string; site: string; path: string } | string): Promise; - // ─── response helpers ────────────────────────────────────────────────────── /** Failure reason returned by `asJson` / `asText` when `ok` is false. */ diff --git a/nx2/utils/api.js b/nx2/utils/api.js index 767810e65..ce71afca5 100644 --- a/nx2/utils/api.js +++ b/nx2/utils/api.js @@ -37,7 +37,6 @@ export { AEM_API }; // daFetch authenticated fetch (used by everything above) // isHlx6 Helix 6 upgrade-status probe (cached) // fromPath `/org/site/file/path` -> { org, site, path } -// getSourceUrl document source url on DA or the hlx6 source bus // // All namespace methods return a raw `Response` (augmented with // `resp.permissions`) EXCEPT `source.list`, which merges body + header @@ -334,7 +333,7 @@ export const source = { _saveDA: withArgs(async ({ org, site, path, body }) => { const url = await getDaApiPath(SOURCE, org, site, path); const formData = new FormData(); - formData.append('data', new Blob([body], { type: findContentType(path, body) })); + formData.append('data', new Blob([body], { type: findContentType(path) })); const opts = { method: 'POST', body: formData, @@ -357,7 +356,7 @@ export const source = { method: 'POST', body, headers: { - 'content-type': findContentType(path, body) || 'application/octet-stream', + 'content-type': findContentType(path) || body?.type || 'application/octet-stream', }, }; const resp = await daFetch({ url, opts }); @@ -702,11 +701,6 @@ export function fromPath(str) { return { org, site, path: parts.length ? `/${parts.join('/')}` : '' }; } -// Document source url on DA or the hlx6 source bus; collab rooms are named after it. -export const getSourceUrl = withArgs( - ({ org, site, path }) => getDaApiPath(SOURCE, org, site, path), -); - // Site token exchange for authenticated content access. // Uses IIFE pattern for memoized token retrieval. export const getAemSiteToken = (() => { @@ -757,13 +751,12 @@ const TYPE_MAP = { }; /** - * finds the content type by path extension, else the type of a Blob body + * finds the content type by path extension * @param path - * @param body */ -function findContentType(path, body) { +function findContentType(path) { const ext = Object.keys(TYPE_MAP).find((e) => path.toLowerCase().endsWith(e)); - return TYPE_MAP[ext] ?? (body?.type || undefined); + return TYPE_MAP[ext]; } // Rewrite relative `media_` refs (src/href/srcset) to absolute URLs against diff --git a/nx2/utils/api.md b/nx2/utils/api.md index 318726fdb..ca6ef8e3f 100644 --- a/nx2/utils/api.md +++ b/nx2/utils/api.md @@ -2,7 +2,7 @@ A unified client for talking to **DA admin** (`admin.da.live`) and the **AEM admin API** in either its legacy form (`admin.hlx.page`, "helix5") or its new form (`api.aem.live`, "helix6"). Every method auto-routes by the per-site **hlx6** upgrade flag — once a site has been upgraded, calls flow to the new origin; otherwise they fall back to the legacy origin. -The module ships its low-level primitive (`daFetch`), an upgrade detector (`isHlx6`), helpers (`fromPath`, `getSourceUrl`, `signout`, `asJson`, `asText`), and **eight namespaced surfaces**: `source`, `versions`, `config`, `org`, `status`, `aem`, `snapshot`, `jobs`. Type definitions live in `[api.d.ts](./api.d.ts)` — VSCode picks them up automatically and surfaces overloads, field-level docs, and inline shapes. +The module ships its low-level primitive (`daFetch`), an upgrade detector (`isHlx6`), helpers (`fromPath`, `signout`, `asJson`, `asText`), and **eight namespaced surfaces**: `source`, `versions`, `config`, `org`, `status`, `aem`, `snapshot`, `jobs`. Type definitions live in `[api.d.ts](./api.d.ts)` — VSCode picks them up automatically and surfaces overloads, field-level docs, and inline shapes. > **Routing model.** Some endpoints are owned by DA itself (`source`, `list`, `config`, `versions`) and DA proxies them to AEM when the site is upgraded. Others are AEM-only (`status`, `preview`, `live`, `snapshots`, `jobs`) and live on either `admin.hlx.page` (legacy) or `api.aem.live` (hlx6). The module hides this distinction; callers always pass `{ org, site, path }` and get a `Response` back. @@ -13,7 +13,7 @@ The module ships its low-level primitive (`daFetch`), an upgrade detector (`isHl ```js import { // Low-level - daFetch, isHlx6, signout, fromPath, getSourceUrl, + daFetch, isHlx6, signout, fromPath, // Namespaces source, versions, config, org, status, aem, snapshot, jobs, // Response helpers @@ -116,7 +116,7 @@ Document CRUD on `source` paths. Bridges DA's `/source` and AEM's `/sites/{site} | -------------- | --------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `get` | `({ org, site, path })` or `(fullPath)` | GET — raw `Response`. | | `list` | `({ org, site, path?, continuationToken? })` or `(fullPath, { continuationToken? })` | List a folder. Returns `{ ok, items, continuationToken, permissions }` (normalized — items match legacy DA shape regardless of server). Pass `{ org }` (no site) to list at org level — merges DA-legacy folders (`${DA_ADMIN}/list/{org}`) with hlx6 source-bus sites (`org.listSites`), deduped by name. Only DA paginates; `org.listSites` is only queried on the first page (no `continuationToken`). Bulk lists paginate — pass `continuationToken` back into the next call. | -| `save` | `({ org, site, path, body })` or `(fullPath, { body })` | Upload — raw `Response`. POST for both branches. **DA-legacy**: wraps `body` as a Blob in `multipart/form-data` field `data`, with the Blob's type set from the path extension via `TYPE_MAP` (for extensions not in `TYPE_MAP`, the type of a Blob/File `body`). **hlx6**: sends `body` raw (string, Blob, or File); `Content-Type` is set from the path extension via `TYPE_MAP` and overrides any auto-applied Blob type. Extensions not in `TYPE_MAP` send no `Content-Type`. On success, `resp.json()` is normalized to DA's `{ source: { contentUrl } }` shape (`contentUrl` = the written source URL), since the hlx6 endpoint returns an empty body; non-ok responses pass through unchanged. | +| `save` | `({ org, site, path, body })` or `(fullPath, { body })` | Upload — raw `Response`. POST for both branches. **DA-legacy**: wraps `body` as a Blob in `multipart/form-data` field `data`, with the Blob's type set from the path extension via `TYPE_MAP`. **hlx6**: sends `body` raw (string, Blob, or File); `Content-Type` is set from the path extension via `TYPE_MAP` and overrides any auto-applied Blob type. Extensions not in `TYPE_MAP` send no `Content-Type`. On success, `resp.json()` is normalized to DA's `{ source: { contentUrl } }` shape (`contentUrl` = the written source URL), since the hlx6 endpoint returns an empty body; non-ok responses pass through unchanged. | | `getMetadata` | `({ org, site, path })` or `(fullPath)` | HEAD — raw `Response`. Value is in `resp.headers` (`doc-id`, `last-modified`, etc.). | | `delete` | `({ org, site, path, continuationToken? })` or `(fullPath, { continuationToken? })` | DELETE — raw `Response` (typically 204). For recursive folder deletion use `deleteFolder`. | | `copy` | `({ org, site, path, destination, collision?, continuationToken? })` or `(fullPath, { destination, collision?, continuationToken? })` | Raw `Response`. `path` = source, `destination` = target. **hlx6**: PUT to dest URL with `?source=…&collision=…` query. **DA**: POST `/copy/{org}/{site}{path}` with `multipart/form-data` field `destination`. | @@ -447,16 +447,6 @@ fromPath('/adobe/aem-boilerplate/index.html'); // → { org: 'adobe', site: 'aem-boilerplate', path: '/index.html' } ``` -### `getSourceUrl(arg)` - -Resolves the source url of a document without requesting it: `${AEM_API}/{org}/sites/{site}/source{path}` on hlx6, `${DA_ADMIN}/source/{org}/{site}{path}` on legacy DA. Accepts the object or path-string form. Collab (da-collab) rooms are named with this url, so editors that open the same document should name their room with it to share one. - -```js -await getSourceUrl({ org: 'adobe', site: 'aem-boilerplate', path: '/index.html' }); -// → 'https://api.aem.live/adobe/sites/aem-boilerplate/source/index.html' (hlx6) -// → 'https://admin.da.live/source/adobe/aem-boilerplate/index.html' (legacy) -``` - ### `asJson(promise)` / `asText(promise)` Opt-in unwrappers. Each awaits a namespace method's returned promise, attempts to parse the body, and returns a flat result: diff --git a/test/nx2/utils/api.test.js b/test/nx2/utils/api.test.js index 2195498e3..8c27ab5c1 100644 --- a/test/nx2/utils/api.test.js +++ b/test/nx2/utils/api.test.js @@ -11,7 +11,6 @@ import { isHlx6, signout, fromPath, - getSourceUrl, source, versions, config, @@ -549,17 +548,6 @@ describe('api.js', () => { expect(calls.some((c) => c.url.includes('/media'))).to.equal(false); }); - it('source.uploadMedia legacy keeps the blob type for extensions the type map lacks', async () => { - restoreFetch(); - installFetch({ - body: JSON.stringify({ source: { contentUrl: 'https://stage-content.da.live/o/s/img.webp' } }), - }); - const { org: o, site: s } = makeOrgSite(); - const data = new Blob(['binary'], { type: 'image/webp' }); - await source.uploadMedia({ org: o, site: s, path: '/img.webp', body: data }); - expect(lastCall().body.get('data').type).to.equal('image/webp'); - }); - it('source.uploadMedia hlx6 POSTs to the media route with content-type header and raw body', async () => { const { org: o, site: s } = makeOrgSite({ hlx6: true }); restoreFetch(); @@ -1575,33 +1563,6 @@ describe('api.js', () => { }); }); - describe('getSourceUrl', () => { - it('returns the source bus url on hlx6', async () => { - const { org: o, site: s } = makeOrgSite({ hlx6: true }); - const url = await getSourceUrl({ org: o, site: s, path: '/drafts/page.html' }); - expect(url).to.equal(`${AEM_API}/${o}/sites/${s}/source/drafts/page.html`); - }); - - it('returns the da-admin source url on legacy', async () => { - const { org: o, site: s } = makeOrgSite(); - const url = await getSourceUrl({ org: o, site: s, path: '/drafts/page.html' }); - expect(url).to.equal(`${DA_ADMIN}/source/${o}/${s}/drafts/page.html`); - }); - - it('accepts the path-string form', async () => { - const { org: o, site: s } = makeOrgSite({ hlx6: true }); - const url = await getSourceUrl(`/${o}/${s}/index.html`); - expect(url).to.equal(`${AEM_API}/${o}/sites/${s}/source/index.html`); - }); - - it('builds the url without requesting the document', async () => { - const { org: o, site: s } = makeOrgSite({ hlx6: true }); - await getSourceUrl({ org: o, site: s, path: '/page.html' }); - expect(callsTo(AEM_API)).to.have.lengthOf(0); - expect(callsTo(DA_ADMIN)).to.have.lengthOf(0); - }); - }); - describe('fromPath', () => { it('splits /org/site/file/path into { org, site, path }', () => { expect(fromPath('/adobe/aem-boilerplate/index.html')).to.deep.equal({