# Native Bright enrichment developer contract

## Ownership and scope

`cloudflare/src/embed.js` owns the browser loader; `worker.js` serializes it at `/embed.js` and serves `/current/enrichment.json`; `render.js` builds semantic markup and scoped styles. The current pilot recognizes exact saved authorized Bright signed URLs for Woodbridge city `10000006615`, all property types, monthly. Preserve signatures; never generate them or silently substitute scope. Domain/account entitlements and general enrollment are not implemented.

## Browser contract

- One unchanged loader URL supports default sitewide and `data-placement="inline"` modes. `defer` avoids parser blocking.
- Match normalized exact approved URLs in iframe `src`, `data-src` or `data-lazy-src`. Inline selects the nearest prior sibling iframe, or the last nested iframe in a prior sibling container. It does not choose an unrelated market. A legacy explicit `data-bright-source` is accepted only if verified against the same source list.
- Sitewide groups by nearest `section`/`article`, otherwise parent element, and inserts after the last supported frame in each group. Inline reserves its group; duplicate global loaders share an endpoint registry, and duplicate inline loaders for one chart select the first.
- The loader inserts `.vr-market-enrichment` in ordinary host light DOM. No iframe or shadow root carries enrichment. Scoped CSS and unique DOM IDs isolate report styling and accessible relationships. Embedded headings start at H2; preserve the destination H1.
- Payload HTML is controlled generated content, never arbitrary customer HTML. Strip executable scripts except JSON-LD, embedded documents, style/link/base/object/embed elements and event attributes; constrain content URLs. Review any widening of allowed markup as a security change.
- Endpoint query options are bounded `preset`, `periods`, `inventory`, and `price`. `data-query-from-page="true"` is an explicit opt-in for query pages. Shared default installation does not need these values.
- Observe late iframe additions/source attributes for two minutes. Fetch the saved generation every 300,000 ms while open, with a 15-second timeout and no concurrent check. Subsequent polls rediscover targets. Preserve expanded detail state on generation replacement. Pagehide stops the interval; persisted pageshow resumes it.
- Fetch failure retains the browser's already rendered last-good content and updates its visible status. First-load failure leaves the original Bright chart independent. There is no automatic stale-report removal.

## Saved generation and provider budget

`/current/enrichment.json` returns generation, HTML, CSS, base URL, exact supported sources and current status from the saved R2 bundle. Its public CORS response is not account authorization. Cache keys include generation and bounded query options; a cached response receives current status. Visitor traffic never fetches Bright, even with empty storage. Empty or invalid storage returns unavailable.

Only scheduled refresh uses the durable budget: one attempt per UTC half-day, at most two per UTC date, persisted before provider requests. Failures and restarts do not refund attempts. Use existing namespace and gate; do not add force routes, visitor refreshes or duplicate timers. Validate all eight series and render before switching the atomic `current.json` generation. Retain last-good values and actual verification dates on failure.

## SEO/AEO evidence contract

Native browser DOM delivery resolves the iframe isolation problem for render-capable consumers. It does not add facts to raw HTTP HTML. Record both separately, and do not label a user-agent-spoofed request an actual Google crawl. Browser rendering, valid schema and search indexing are separate claims.

JSON-LD must describe visible, same-generation evidence. Host-page identities must refer to the destination rather than pretending it is the managed report host. Do not fabricate agent identity, neighborhood boundaries or extra metrics. Full plotted values must have a readable HTML representation. Schema presence alone does not prove rich-result eligibility or AI citation.

For non-JavaScript consumers, an additional initial-HTML delivery integration is required. Do not silently promise that the script covers this gap. `native.html` and copied HTML/CSV exports are dated snapshots unless connected to a separately accepted refresh path.

## Required acceptance

Run runtime fixtures and real browser tests against the released script. Prove inline, sitewide, mixed-mode deduplication, unrelated sources, multiple sections, late/lazy frames, scoped styles/IDs, current and changed generations, malformed/unavailable responses and preserved original frames. Keep synthetic refresh/failure fixtures isolated from public source data.

On the real WordPress public destination capture desktop and 390/320-pixel mobile views, full DOM/schema, raw HTTP and rendered text extracts, and a video of insertion. Confirm zero enrichment iframes and readable plotted-value tables. Retain version/generation/time with evidence. Verify every public guide/video URL before sharing. A prior iframe install test is not acceptance of this implementation.

## Support and rollback

Use `/health` and `/status.json` for current status; distinguish last failure from latest check and a new check from a new monthly period. Remove only enrichment installation code to roll back. Never remove or rewrite the authorized original Bright iframe. Update the existing `/tool/` and `/support-guide/` rather than creating a competing landing page. Publish KB changes through the `kb-note` inbox workflow; only ingestion/refinement owns canonical concepts.
