Repository navigation
Description
Summary
#149 shipped the detection half of embed reporting but not the send: boot() takes the payload
and drops it (void report — src/Widget.tsx:377), with a comment noting the receiving endpoint
was a separate SahajCloud ticket. That endpoint now exists and is deployed —
POST /api/clients/report, sydevs/SahajCloud#633 (PR #636) — so the send can be switched on.
Switching it on as-is would fail, though: two payload mismatches mean every report 400s, and the
mount key silently collapses on WordPress. Separately, SahajCloud's follow-up verifies embeds
server-side and needs one thing #149 never specced — a readiness marker in the DOM.
Verified against the shipped code at 8e6c4ce and a SahajCloud instance running the new schema.
1. Payload shape — every report currently 400s
Widget sends (src/loader/report.ts) |
Endpoint expects |
|---|---|
mount: "https://host/path" (one field) |
origin and pathname as separate fields |
mode: 'component' | 'iframe' |
mode: 'inline' | 'iframe' |
The split is not cosmetic — the endpoint rejects a pathname carrying a query string or fragment,
and it can only enforce that if the path arrives on its own. mount is still the storage key; the
server rebuilds it as origin + pathname.
On mode: component is arguably the better name, but the CMS contract is deployed and published
at /api/docs, so the cheaper fix is for the widget to send inline. Say if you'd rather the CMS
rename — its column is JSON, so that side is a validator change with no migration.
canonicalViable is extra as far as the endpoint is concerned; unknown keys are stripped, so it is
harmless to keep sending.
2. mountKey() collapses every WordPress page onto one mount
mountKey() returns origin + pathname, discarding the query. On a WordPress site using default
permalinks every page is /?p=<id>, so every post reports as https://site.com/ — all mounts
collapse into one record, and the page an operator needs to designate as canonical cannot be named
at all. That is precisely the audience this program targets.
The endpoint was changed for this: a path may now carry ?p=<digits> and nothing else. Every
other query string is still refused, for the reason hostPageUrl() already documents — a host query
can carry a reset token or an OAuth code, and none of that may leave the page. A numeric post id is
not seeker input.
So mountKey() should preserve ?p=<digits> and continue discarding everything else, including
?p=123&utm_source=….
3. Readiness marker — new, not something #149 missed
SahajCloud only lets a server-verified embed yield a canonical URL: the CMS loads the page itself
via Cloudflare Browser Rendering and confirms the widget really booted. This closes a hole where a
forged report could otherwise reshape a live canonical URL — reports nominate a candidate, the
server decides.
A postMessage cannot serve this. The Browser Rendering REST API renders a page and returns DOM,
with no message channel, and an injected listener races the widget's own boot — which would
false-FAIL healthy sites. A DOM attribute is raceless and carries the state the verifier needs:
document.documentElement.setAttribute(
'data-sahaj-atlas-ready',
JSON.stringify({ v: 2, routing: 'query', topLevel: true, urlWritable: true }),
)Two requirements:
- Set it only after the widget has genuinely mounted and rendered, never on script load. A
marker set on load attests to nothing and makes verification theatre. - Its JSON is a cross-repo contract, hence the
vfield. The verifier readsroutingfrom it, which
is what makes routing server-attested rather than self-reported.
No postMessage is wanted — the verifier is the only consumer, so one mechanism, not two.
4. Report on every mount, not only on change
#149 gates the POST on the fingerprint differing from /clients/me. That makes lastSeen useless
as a liveness signal: a healthy, unchanged embed reports once, ever, and the admin panel would
show "last seen 8 months ago" for a working site.
The server already suppresses unchanged reports for an hour, so reporting on every mount costs at
most one write per mount per hour. The differs-from-/clients/me gate then becomes unnecessary —
which also removes a round trip from the load path.
5. Two things worth knowing about the endpoint
allowedDomainsmust be non-empty, and the reportedoriginmust match it. Unlike the read
surface, an empty allowlist is refused (403) rather than allowing everything — with no allowlist
there is nothing to attribute a mount to. An unconfigured service simply cannot report.- A client may accumulate at most 50 distinct mounts; a new one past that is 429. Known mounts keep
reporting normally.
6. Cleanup: legacyConfig is gone
SahajCloud removed the field. ClientSchema (src/types/client.ts:18) still declares it and the
/clients/me query still selects it. It is .nullish() and never read for behaviour, and I
confirmed a stale select[legacyConfig]=true still returns 200 — so nothing breaks. It is dead
weight to drop when convenient, along with the regenerated payload-types.ts.
Acceptance criteria
- The report POSTs to
POST /api/clients/reportand a successful send is asserted in the node lane. - Payload sends
origin+pathnameseparately, andmodeuses the endpoint's enum. -
mountKey()preserves?p=<digits>and discards every other query string and all fragments — asserted both directions. -
data-sahaj-atlas-readyis set only after a genuine mount, carryingv,routing,topLevel,urlWritable. - The report fires on every mount; the differs-from-
/clients/megate is removed. - A 403 or 429 from the endpoint is a console diagnostic, never a thrown error in the host's page.
-
legacyConfigdropped fromClientSchemaand the/clients/meselect.
References
- feat(access): add embed metadata and canonical ownership to Clients SahajCloud#633 / PR #636 — the endpoint, the
?p=carve-out, and the verification design .claude/rules/api-clients.mdin SahajCloud — the endpoint contract- feat(widget): split the embed into a smart loader and an element bundle #149 — the loader split this completes
src/Widget.tsx:377(void report),src/loader/report.ts,src/loader/detect.ts
Metadata
Metadata
Assignees
Labels
Type
Fields
Hold Until
Activity
docs: point the changelog entries at the real PR number
refactor(widget): one observation, joined to its mount at the send site
fix(access): pin the canonical mount and make eviction reach the colu…
fix(lib): move isSoon into the shape event helpers
test(types): drop the client locale case that duplicates the legacyCo…
docs(api-clients): state the cap as a storage bound, not a refusal
test(overlay): pin the two menus' ItemCheck against drift instead of …