[AI-8410] loadSidebarV2 host API bridge, context, and integration docs - #47
Merged
Conversation
…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 Scan Summary
To detect these findings earlier in the dev lifecycle, try using Wiz Code VS Code Extension. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
loadSidebarV2: postMessage handlers forGET_EXTERNAL_HEADERS, website/analytics context, and host localStorage.ExternalHeadersCallback,LAYOUT_SIDEBAR, andLAYOUT_FLOATING_CHATfrom the package.aiContext, custom CSS, and callbacks) and addsrc/load-sidebar-v2/README.mdplus root README link.Builds on merged loadSidebarV2 core (#43) and layouts/chat toggle (#44).
Test plan
npm test(171 tests)npm run buildthen opendemo/load-sidebar-v2-sidebar/,demo/load-sidebar-v2-floating-chat/, anddemo/load-sidebar-v2-full-config/via local static serveronCloseand sends demo headers viagetExternalHeadersaiContext/ widget config onHOST_READY✨ PR Description
1. Problem & Context
Implements host-side postMessage API bridge for
loadSidebarV2to 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)
host-api-bridge.tsconfig.tsExternalHeadersCallbacktype,analyticsfield toHostConfig,getExternalHeaderstoCallbacksConfigboot-sidebar.tsinitHostApiBridge()before container setup with iframe origin + callbacksresolve-config.tsgetExternalHeaderscallback through config resolutionindex.tsExternalHeadersCallbacktype3. How It Works
On boot,
initHostApiBridge()registers a globalmessagelistener (origin-checked against iframe). When iframe postsGET_EXTERNAL_HEADERS,GET_WEBSITE_CONTEXT,GET_ANALYTICS_CONTEXT, or localStorage ops on aMessagePort, host invokes the callback (or fetches from config) and responds viaport.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