Skip to content

fix: adapt aem-preview-publish.js to work with HLX6 - #673

Merged
mhaack merged 6 commits into
mainfrom
hlx6pp
Aug 18, 2026
Merged

fix: adapt aem-preview-publish.js to work with HLX6#673
mhaack merged 6 commits into
mainfrom
hlx6pp

Conversation

@mhaack

@mhaack mhaack commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

.... so we can preview and publish from experience workspace

mhaack added 5 commits August 17, 2026 12:05
… multi-sheet bug

- Add nx2/test/mocks/fetch.js: generalized window.fetch mock (route
  matching + built-in HLX6 ping handling) so api.js-dependent tests
  don't each hand-roll their own mock.
- Add test/nx2/utils/daConfig.test.js: direct coverage of
  fetchDaConfigs (legacy, hlx6, memoization, error/cache-eviction) and
  getFirstSheet, using the shared mock.
- Refactor ewFlags.test.js to use the shared mock instead of a local,
  ad hoc window.fetch stub.
- Fix getFirstSheet's multi-sheet branch: it read
  Object.keys(json)[0], which is always ':type' (not a sheet name),
  so it always returned undefined for multi-sheet docs. Now uses
  json[':names'][0], matching sheet2object's approach.
…uter

nx2/test/mocks/fetch.js now mirrors api.test.js's installFetch/
restoreFetch/lastCall/callsTo exactly (single response + built-in
isHlx6 ping handling), rather than a generic route-matching mock.

- api.test.js now imports these from the shared module instead of
  defining them locally; ad hoc calls = [] resets became
  calls.length = 0 since calls is now an imported array reference.
- ewFlags.test.js and daConfig.test.js reuse the same helper, and
  follow api.test.js's own convention (assign window.fetch directly
  after restoreFetch(), push into the shared calls array) for cases
  needing per-URL differentiation, instead of a bespoke routing API.
…eness

- saveToAem now dispatches through api.js's aem.preview/aem.publish
  instead of hand-building the legacy HLX_ADMIN/{preview|live}/... URL,
  so preview/publish requests hit AEM_API on hlx6-migrated sites
  instead of always going through the legacy admin host.
- requestAemRole now reads/writes the aem-permission-requests.json file
  via api.js's source.get/source.save instead of a raw daFetch to
  DA_ADMIN, making the permission-request flow hlx6-aware too (same
  pattern as the daConfig.js/org-check.js fixes).
- fetchSidekickHosts is left on direct daFetch: there is no AEM_API
  equivalent wired into api.js for resolving custom preview/live
  hostnames, and config.getAggregated (the only close candidate) has
  no consumers or verified shape to confirm it carries the same info.

Test changes:
- requestAemRole's test mock now serves isHlx6's ping probe (triggered
  by source.get/source.save) and uses unique org/site per test to
  avoid isHlx6's module-level memoization bleeding between tests.
- Added coverage for runAemPreviewOrPublish/saveToAem, which had none
  before: legacy vs hlx6 URL routing, publish's two-step preview+live
  flow, 401 authorization errors, x-error detail stripping, and the
  missing-preview-URL failure path.
@aem-code-sync

aem-code-sync Bot commented Aug 17, 2026

Copy link
Copy Markdown

Hello, I'm the AEM Code Sync Bot and I will run some actions to deploy your branch.
In case there are problems, just click the checkbox below to rerun the respective action.

  • Re-sync branch
Commits

@mhaack
mhaack changed the base branch from main to hlx6cfg August 17, 2026 12:23
sharanyavinod
sharanyavinod previously approved these changes Aug 18, 2026
Base automatically changed from hlx6cfg to main August 18, 2026 07:10
@mhaack
mhaack dismissed sharanyavinod’s stale review August 18, 2026 07:10

The base branch was changed.

@mhaack
mhaack merged commit f558191 into main Aug 18, 2026
3 checks passed
@mhaack
mhaack deleted the hlx6pp branch August 18, 2026 08:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants