Skip to content

Commit c96cb13

Browse files
kptdobeCopilot
andauthored
feat: bridge legacy reads and saves for migrated sites (#344)
* feat: bridge migrated DA reads and saves Keep legacy DA clients usable after HLX6 cutover. Require DA ACLs and caller-token HLX6 permissions. Reject unsupported operations instead of writing stale storage. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * docs: document HLX6 compatibility helpers Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix: harden HLX6 bridge after review Build org listings from config so they no longer depend on HLX6. Forward preconditions only for source reads/saves; reject redirects. Guard malformed save Locations and map string upload types. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix: list HLX6 source sites in org listings Merge DA sites with GET /{org}/source/ and configured migrated sites. Fall back to DA plus configured sites when HLX6 listing fails. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix: point bridge errors to api.aem.live Drop Helix 6 naming from client-facing error messages. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * refactor: list org HLX6 sites from source only The HLX6 org source listing already includes migrated sites. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * test: cover HLX6 bridge error paths Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix: address HLX6 bridge review feedback List only bridged HLX6 sites in org listings, with a 3s timeout. Dedupe org entries by path; keep save JSON on upstream 204. Guard unparseable save Locations; infer untyped upload types. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 489979f commit c96cb13

11 files changed

Lines changed: 1115 additions & 35 deletions

File tree

‎README.md‎

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,59 @@ Browse to `http://localhost:8787/list` to ensure you see the expected buckets.
4545

4646
### Helix 6 request handling
4747

48-
Site-scoped requests, including config and version APIs, return `410 Gone` for
49-
sites listed in `HLX6_MIGRATED_SITES`, an array of `org/site` entries (or a
50-
JSON-encoded array). These sites must use `https://api.aem.live`; requests for
51-
these sites do not access their legacy content. The check is a local
52-
configuration lookup; no network probe is made.
53-
54-
Org-level requests, authentication, logout, and CORS preflight remain available.
48+
Sites listed in `HLX6_MIGRATED_SITES`, an array of `org/site` entries (or a
49+
JSON-encoded array or comma/newline-separated string), use a synchronous
50+
compatibility bridge to `AEM_API` (`https://api.aem.live` by default). The site
51+
check is local; no network probe is made.
52+
53+
The bridge supports:
54+
55+
- Source GET/HEAD, streaming bodies and returning ETag/Last-Modified. Matching
56+
`If-None-Match` returns 304; `If-Match` read failures return 412.
57+
- Site/folder GET listings, converted to DA item fields and hidden-file
58+
filtering. HLX6 listings are unpaginated; a legacy continuation token on a
59+
migrated site's listing is rejected.
60+
- Org GET listings, merging legacy DA sites with the org's bridged HLX6 sites:
61+
entries of `GET /{org}/source/` (caller token, 3s timeout) that are also in
62+
`HLX6_MIGRATED_SITES`, filtered by DA ACLs. If the HLX6 listing fails
63+
(outage, timeout, missing HLX6 role), the DA listing is still returned.
64+
Only the first legacy page adds HLX6 sites; subsequent pages preserve the
65+
DA continuation token without repeating them.
66+
- Site editor-config GET and multipart PUT/POST (`config` field), converting
67+
between DA sheet wrappers and `config/editor/da.json` row arrays. The whole
68+
AEM site configuration is never replaced.
69+
- Source multipart PUT/POST (`data` field) and raw uploads, converted to HLX6
70+
POST, including its image-import behavior and validation. String `data`
71+
fields are accepted for `.html`, `.json` and `.svg` only (415 otherwise).
72+
Successful saves return DA's source/edit/preview/live URL envelope and the
73+
upstream ETag. Bodyless folder writes become trailing-slash POSTs.
74+
Upstream redirects are rejected with 502.
75+
76+
All requests retain existing DA ACL checks and require the caller's Bearer
77+
token and the corresponding HLX6 permissions. There is no service-token
78+
elevation, mutation retry, or fallback to writable legacy storage. Responses
79+
are private/no-store. Legacy UUID and permission-hint headers are not invented:
80+
`x-da-id`, `x-da-actions`, and `x-da-child-actions` are unavailable on bridged
81+
site responses. DA ACLs and HLX6 roles must be configured separately.
82+
83+
Version/history APIs, copy/move/delete, dedicated media uploads, GUID-specified
84+
uploads, collaborative writes, and extensionless file uploads remain
85+
unsupported and return 410. Raw `/.versions` and `/.history` access through
86+
source/list is blocked. Multiple-author token headers are rejected rather
87+
than silently selecting an author. HTML transformations, validation, request
88+
limits, and empty-document restore points are not identical to DA.
89+
90+
Org config, authentication, logout, and CORS preflight remain available locally.
91+
The bridge does not change the HLX6 editor's org-config inheritance behavior.
5592
Sites configured for dual write in `HLX6_DUAL_WRITES` retain normal DA behavior
5693
during migration, even if they also appear in `HLX6_MIGRATED_SITES`.
5794

95+
The companion da-content change routes migrated sites through its `daadmin`
96+
binding before direct-R2 allowlists and asset opt-outs. Configure the same
97+
migration variables on both workers, and deploy the da-admin bridge first.
98+
Content path/cookie handling remains on the legacy host; no browser redirect
99+
or Library URL rewrite is required for supported source reads.
100+
58101
### Helix 6 migration (dual write)
59102
Sites listed in the `HLX6_DUAL_WRITES` env variable are being migrated to Helix 6. Every successful modification on those sites (source create/update/delete, folder creation, copy, move, version creation) is also propagated, in the background, to the Helix 6 source bus at `AEM_API` (`https://api.aem.live`) using the caller's IMS token. Failures are logged but do not affect the DA response.
60103

‎src/index.d.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ export interface Env {
2525
DA_OPS_IMS_BOT_EMAIL: string;
2626
// hlx6 api service base URL (eg https://api.aem.live)
2727
AEM_API?: string;
28-
// migrated hlx6 sites, as "org/site". Legacy requests return 410 unless dual-writing.
28+
// migrated hlx6 sites, as "org/site". Reads and saves use the hlx6 bridge;
29+
// unsupported operations return 410 unless dual-writing.
2930
HLX6_MIGRATED_SITES?: string[] | string;
3031
// sites dual-writing to hlx6, as "org/site" or "org/site -> org2/site2".
3132
// Modifications on these sites are propagated to the hlx6 source bus.

‎src/index.js‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ import headHandler from './handlers/head.js';
1616
import getHandler from './handlers/get.js';
1717
import postHandler from './handlers/post.js';
1818
import deleteHandler from './handlers/delete.js';
19-
import { HLX6_GONE, initHlx6, isHlx6Site } from './utils/hlx6.js';
19+
import { hasHlx6Sites, initHlx6, isHlx6Site } from './utils/hlx6.js';
20+
import hlx6Handler, { listHlx6Org } from './routes/hlx6.js';
2021

2122
export default {
2223
/**
@@ -76,7 +77,10 @@ export default {
7677
// The key also identifies bare site roots, where daCtx.site is undefined.
7778
const [site] = (key || '').split('/');
7879
if (api !== 'login' && api !== 'logout' && isHlx6Site(env, org, site)) {
79-
return daResp({ ...HLX6_GONE, body: req.method === 'HEAD' ? undefined : HLX6_GONE.body });
80+
return await hlx6Handler({ req, env, daCtx });
81+
}
82+
if (api === 'list' && org && !key && req.method === 'GET' && hasHlx6Sites(env, org)) {
83+
return await listHlx6Org({ req, env, daCtx });
8084
}
8185

8286
switch (req.method) {

‎src/routes/config.js‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@ import putKv from '../storage/kv/put.js';
1414
import getKv from '../storage/kv/get.js';
1515
import { configPermissionPath, hasPermission } from '../utils/auth.js';
1616

17-
// Config access is granted if the user has the action on the resource's own keyword
18-
// (the per-site `/{site}/CONFIG`, or `CONFIG` for org config) OR on the org-level
19-
// `CONFIG` keyword. The latter lets org admins manage any site's config; site rules
20-
// (including `/{site}/**` wildcards) can grant additional access but never restrict it.
21-
function hasConfigPermission(daCtx, action) {
17+
/**
18+
* Grants config access through either the resource CONFIG keyword or the org CONFIG keyword.
19+
* Site rules can grant additional access but cannot restrict an org config administrator.
20+
* @param {Object} daCtx DA context with the resource key, users and org-scoped ACLs.
21+
* @param {string} action Required config action.
22+
* @returns {boolean} Whether either config permission grants the action.
23+
*/
24+
export function hasConfigPermission(daCtx, action) {
2225
return hasPermission(daCtx, configPermissionPath(daCtx), action, true)
2326
|| hasPermission(daCtx, 'CONFIG', action, true);
2427
}

‎src/routes/copy.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@
1212
import copyObject from '../storage/object/copy.js';
1313
import copyHelper from '../helpers/copy.js';
1414
import { hasPermission } from '../utils/auth.js';
15-
import { syncCopy } from '../utils/hlx6.js';
15+
import { HLX6_GONE, isHlx6Site, syncCopy } from '../utils/hlx6.js';
1616

1717
export default async function copyHandler({ req, env, daCtx }) {
1818
const details = await copyHelper(req, daCtx);
1919
if (details.error) return details.error;
2020
if (!hasPermission(daCtx, details.source, 'read')
2121
|| !hasPermission(daCtx, details.destination, 'write')) return { status: 403 };
22+
if (isHlx6Site(env, daCtx.org, details.destination.split('/')[0])) return HLX6_GONE;
2223
const resp = await copyObject(env, daCtx, details, false);
2324
syncCopy({
2425
req, env, daCtx, details, resp,

0 commit comments

Comments
 (0)