Skip to content

[AI-8410] loadSidebarV2 host API bridge, context, and integration docs - #47

Merged
matipojo merged 4 commits into
masterfrom
AI-8410-v2-host-bridge
Jun 1, 2026
Merged

[AI-8410] loadSidebarV2 host API bridge, context, and integration docs#47
matipojo merged 4 commits into
masterfrom
AI-8410-v2-host-bridge

Conversation

@matipojo

@matipojo matipojo commented Jun 1, 2026

Copy link
Copy Markdown
Member

Summary

  • Add host API bridge for loadSidebarV2: postMessage handlers for GET_EXTERNAL_HEADERS, website/analytics context, and host localStorage.
  • Wire bridge into sidebar boot and export ExternalHeadersCallback, LAYOUT_SIDEBAR, and LAYOUT_FLOATING_CHAT from the package.
  • Expand browser demos (sidebar, floating chat, full-config example with aiContext, custom CSS, and callbacks) and add src/load-sidebar-v2/README.md plus root README link.
  • Bump version to 1.4.9.

Builds on merged loadSidebarV2 core (#43) and layouts/chat toggle (#44).

Test plan

  • npm test (171 tests)
  • npm run build then open demo/load-sidebar-v2-sidebar/, demo/load-sidebar-v2-floating-chat/, and demo/load-sidebar-v2-full-config/ via local static server
  • Confirm host toggle opens sidebar; full-config demo logs onClose and sends demo headers via getExternalHeaders
  • Verify embedded Angie receives aiContext / widget config on HOST_READY

✨ PR Description

1. Problem & Context

Implements host-side postMessage API bridge for loadSidebarV2 to enable secure two-way communication between embedded Angie iframe and host page. Allows iframe to request external auth headers, website/analytics context, and localStorage access without exposing host internals.

2. What Changed (Where)

File Change
host-api-bridge.ts New 148-line module handling iframe postMessage, origin validation, external headers callback, context builders
config.ts Added ExternalHeadersCallback type, analytics field to HostConfig, getExternalHeaders to CallbacksConfig
boot-sidebar.ts Calls initHostApiBridge() before container setup with iframe origin + callbacks
resolve-config.ts Threads getExternalHeaders callback through config resolution
index.ts Exports ExternalHeadersCallback type
Demo + docs Full-config example, README.md integration guide, test coverage (237-line test suite)

3. How It Works

On boot, initHostApiBridge() registers a global message listener (origin-checked against iframe). When iframe posts GET_EXTERNAL_HEADERS, GET_WEBSITE_CONTEXT, GET_ANALYTICS_CONTEXT, or localStorage ops on a MessagePort, host invokes the callback (or fetches from config) and responds via port.postMessage(). Undefined headers filtered; errors wrapped in error response. Bridge state is singleton per page (prevents double-registration).

4. Risks

None material. Origin validation prevents CSRF. Callback is optional (defaults to empty). localStorage errors gracefully degrade (catch blocks). Test coverage is comprehensive (237 lines). Minor: resetHostApiBridgeForTests() is export-only used in tests—fine for test cleanup.

Generated by LinearB AI and added by gitStream.
AI-generated content may contain inaccuracies. Please verify before using.
💡 Tip: You can customize your AI Description using Guidelines Learn how

matipojo and others added 4 commits June 1, 2026 13:10
…ar boot process

- Added ExternalHeadersCallback type to support dynamic header retrieval.
- Integrated initHostApiBridge function to initialize the host API with external headers.
- Updated bootSidebar to call initHostApiBridge with the necessary configuration.
- Created tests for host API bridge to validate header retrieval and error handling.
- Ensured callbacks are preserved in the configuration resolution process.
- Added support for retrieving website and analytics context from the host configuration.
- Updated initHostApiBridge to accept host configuration, including website and analytics data.
- Implemented new message types for website and analytics context requests.
- Enhanced tests to validate the retrieval of website and analytics context from the host.
- Introduced localStorage handling for GET and SET operations in the host API bridge.
Add integration README, full-config browser demo with host CSS, and link from root README.
@wiz-9a149474ff

wiz-9a149474ff Bot commented Jun 1, 2026

Copy link
Copy Markdown

Wiz Scan Summary

Scanner Findings
Vulnerability Finding Vulnerabilities -
Data Finding Sensitive Data -
Secret Finding Secrets -
IaC Misconfiguration IaC Misconfigurations -
SAST Finding SAST Findings 1 Low
Software Management Finding Software Management Findings -
Total 1 Low

View scan details in Wiz

To detect these findings earlier in the dev lifecycle, try using Wiz Code VS Code Extension.

@matipojo
matipojo merged commit c8e839c into master Jun 1, 2026
14 checks passed
@matipojo
matipojo deleted the AI-8410-v2-host-bridge branch June 1, 2026 16:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant