Skip to content

Deduplicate bridge-layer fallback adapters onto engine-owned browser implementations (SC-01)#1841

Merged
transphorm merged 6 commits intodevfrom
justin/kmp-sc-01
Mar 11, 2026
Merged

Deduplicate bridge-layer fallback adapters onto engine-owned browser implementations (SC-01)#1841
transphorm merged 6 commits intodevfrom
justin/kmp-sc-01

Conversation

@transphorm
Copy link
Copy Markdown
Member

@transphorm transphorm commented Mar 11, 2026

Summary

  • Consolidates duplicated browser fallback adapters (IndexedDB documents, console analytics, no-op haptic, WebCrypto) from webview-bridge onto the canonical implementations in
    mobile-sdk-alpha/adapters/browser
  • Exports adapters/browser as a new public subpath from mobile-sdk-alpha via package.json exports and tsup config
  • Replaces local documents-web.ts and analytics-web.ts in webview-bridge with thin wrappers that delegate to the engine-owned adapters
  • Delegates bridgeCryptoAdapter.hash() to the shared createWebCryptoAdapter() instead of inlining Web Crypto calls
  • Adds structuredClone fallback with try/catch in the engine's cloneForStorage for WebViews with partial implementations
  • Fixes CI build order: adds mobile-sdk-alpha build step before webview-bridge in both webview-bridge-ci and webview-app-ci workflows
  • Syncs bundled country-document-types.json with staging API (AFG now includes ID card)

Test plan

  • cd packages/mobile-sdk-alpha && yarn test && yarn types
  • cd packages/webview-bridge && yarn build && yarn test
  • CI pipelines pass (build, types, test for both webview-bridge and webview-app)

Native Consolidation Checklist

  • CONTRACTS.md reviewed - no unintended contract changes
  • Layer 1 bridge contract tests pass (cd app && yarn jest:run / yarn workspace @selfxyz/rn-sdk-test-app test)
  • Layer 3 builds pass (app iOS, RN test app iOS, RN test app Android)
  • Layer 4 manual smoke test signed off (if consolidation PR)
  • No new native business logic added (logic belongs in TypeScript)

Summary by CodeRabbit

  • New Features

    • Browser adapter entrypoints (documents, analytics, haptic, crypto) are now exposed for reuse across packages
  • Bug Fixes

    • Safer data persistence with a cloning fallback to prevent accidental mutations
  • Refactor

    • Crypto now delegates to a standardized WebCrypto implementation
    • Bridge adapters consolidated and wrapped; legacy web-specific adapters replaced
  • Other

    • Afghanistan document types expanded; CI now builds common and mobile-sdk-alpha first

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 11, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 10264c15-f799-4637-8ee7-c5d3e5756c8b

📥 Commits

Reviewing files that changed from the base of the PR and between d88a9e3 and 3730be1.

📒 Files selected for processing (1)
  • .github/workflows/webview-app-ci.yml

📝 Walkthrough

Walkthrough

Centralizes browser adapter implementations into the mobile SDK, adds a new ./adapters/browser package export and build entry, introduces a safe deep-clone helper, rewires webview-bridge to delegate to mobile-sdk-alpha browser factories (with tests updated), removes local webview adapter implementations, and updates CI to build mobile-sdk-alpha.

Changes

Cohort / File(s) Summary
Mobile SDK package & build
packages/mobile-sdk-alpha/package.json, packages/mobile-sdk-alpha/tsup.config.ts, packages/mobile-sdk-alpha/tsconfig.json
Added public export ./adapters/browser and tsup entry; updated TS path mappings; externalized @selfxyz/common subpaths in build configs.
Mobile SDK browser adapters & data
packages/mobile-sdk-alpha/src/adapters/browser/..., packages/mobile-sdk-alpha/tests/adapters/browser/documents.test.ts, packages/mobile-sdk-alpha/src/data/country-document-types.json
Added cloneForStorage<T> (structuredClone with JSON fallback) and replaced direct structuredClone uses; added test for fallback behavior; added "i" to Afghanistan document types.
WebView Bridge dependency & public API
packages/webview-bridge/package.json, packages/webview-bridge/src/adapters/index.ts, packages/webview-bridge/src/adapters/crypto.ts
Added dependency on @selfxyz/mobile-sdk-alpha; replaced local implementations with wrapper exports that delegate to mobile-sdk-alpha browser factories (documents, analytics, haptic, crypto) and adjusted exported type aliases.
Removed local WebView implementations
packages/webview-bridge/src/adapters/documents-web.ts, packages/webview-bridge/src/adapters/analytics-web.ts, packages/webview-bridge/src/adapters/haptic.ts
Deleted local IndexedDB documents adapter, web analytics adapter, and no-op haptic adapter — functionality moved to mobile SDK browser adapters and exposed via wrappers.
Tests updated to mock browser adapters
packages/webview-bridge/src/__tests__/*
Rewrote tests to mock @selfxyz/mobile-sdk-alpha/adapters/browser; added tests for SHA-256 alias normalization, no-op haptic behavior, and adapter delegation; removed heavier integration tests.
CI
.github/workflows/webview-app-ci.yml, .github/workflows/webview-bridge-ci.yml
Added workflow steps to build @selfxyz/common and @selfxyz/mobile-sdk-alpha in build and types jobs.
Tooling & scripts
scripts/check-license-headers.mjs
Added nested .git repo detection and skip logic to avoid traversing submodules when checking license headers.
Docs/spec updates
specs/.../SPEC.md, specs/.../SC-01-fallback-adapter-dedup.md
Updated status/metadata marking adapter dedup work as complete.

Sequence Diagram

sequenceDiagram
    participant App as App
    participant WebBridge as WebViewBridge
    participant MobileSDK as MobileSDK\n(Browser Adapters)
    participant BrowserAPI as Browser APIs

    App->>WebBridge: request adapter (documents / crypto / analytics / haptic)
    WebBridge->>MobileSDK: call create*Adapter() wrapper
    MobileSDK->>BrowserAPI: use IndexedDB / WebCrypto / fetch / other APIs
    BrowserAPI-->>MobileSDK: result
    MobileSDK-->>WebBridge: adapter instance / result
    WebBridge-->>App: return adapter / result

    App->>WebBridge: adapter.method(args)
    WebBridge->>MobileSDK: delegate method call
    MobileSDK->>BrowserAPI: perform operation (cloneForStorage, hash, persist, etc.)
    BrowserAPI-->>MobileSDK: operation result
    MobileSDK-->>WebBridge: result
    WebBridge-->>App: result
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested labels

codex

Suggested reviewers

  • aaronmgdr

Poem

✨ Adapters moved into core's fold,
A safer clone to guard the old.
Tests mock engines, CI joins the run,
Exports shift — the refactor's done. 🚀

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 10.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: consolidating duplicated bridge-layer adapters onto engine-owned implementations, with reference to the associated task (SC-01).
Description check ✅ Passed The description covers the summary, test plan, and native consolidation checklist, addressing most template sections. However, the 'How to QA' section is missing explicit repeatable QA steps beyond the test plan.
Linked Issues check ✅ Passed The PR title includes reference to SC-01 task, and the spec files confirm completion status updates. The PR appears properly linked to the associated task.
Out of Scope Changes check ✅ Passed All changes are directly related to the consolidation goal: adapter deduplication, public export configuration, CI fixes, and data sync. The country-document-types.json update aligns with the stated sync objective.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch justin/kmp-sc-01

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
specs/projects/sdk/workstreams/sdk-core/plans/SC-01-fallback-adapter-dedup.md (1)

3-4: Status updated correctly; consider filling in Branch/PR fields.

The status and Definition of Done updates accurately reflect the completed consolidation work. Minor nit: Lines 9-10 still show "TBD" for Branch and PR while Status is "Done". Consider updating these to reflect the actual PR number (1841) and branch (justin/kmp-sc-01) for traceability.

Also applies to: 9-10

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@specs/projects/sdk/workstreams/sdk-core/plans/SC-01-fallback-adapter-dedup.md`
around lines 3 - 4, Update the metadata fields in the
SC-01-fallback-adapter-dedup.md header: replace "Branch: TBD" with "Branch:
justin/kmp-sc-01" and "PR: TBD" with "PR: 1841" so the document shows the actual
branch and PR used for the completed work.
packages/webview-bridge/src/adapters/index.ts (1)

60-67: Consider clarifying the type as never cast.

The noOpHapticAdapter wrapper works correctly, but the type as never cast on line 65 is unconventional. The SDK's createNoOpHapticAdapter returns a function typed as (type: HapticFeedbackTypes) => void, so casting to never silences TypeScript when the bridge passes arbitrary strings.

This is functionally correct for a no-op, but an inline comment explaining the intent would aid maintainability.

🔧 Optional: Add clarifying comment
 export function noOpHapticAdapter(): BridgeHapticAdapter {
   const trigger = createNoOpHapticAdapter();

   return {
     trigger(type: string): void {
+      // Cast to `never` since the no-op ignores the type anyway
       trigger(type as never);
     },
   };
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/webview-bridge/src/adapters/index.ts` around lines 60 - 67, The
`type as never` cast in noOpHapticAdapter's returned trigger is unclear; update
the noOpHapticAdapter (and its returned trigger function) to keep the existing
harmless cast but add a brief inline comment explaining that
createNoOpHapticAdapter returns (type: HapticFeedbackTypes) => void and we
intentionally cast arbitrary bridge strings to never because this is a true
no-op and we intentionally ignore runtime values; reference the functions
createNoOpHapticAdapter and noOpHapticAdapter and the trigger method in your
comment so future maintainers understand the rationale.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/webview-bridge/src/adapters/index.ts`:
- Around line 60-67: The `type as never` cast in noOpHapticAdapter's returned
trigger is unclear; update the noOpHapticAdapter (and its returned trigger
function) to keep the existing harmless cast but add a brief inline comment
explaining that createNoOpHapticAdapter returns (type: HapticFeedbackTypes) =>
void and we intentionally cast arbitrary bridge strings to never because this is
a true no-op and we intentionally ignore runtime values; reference the functions
createNoOpHapticAdapter and noOpHapticAdapter and the trigger method in your
comment so future maintainers understand the rationale.

In
`@specs/projects/sdk/workstreams/sdk-core/plans/SC-01-fallback-adapter-dedup.md`:
- Around line 3-4: Update the metadata fields in the
SC-01-fallback-adapter-dedup.md header: replace "Branch: TBD" with "Branch:
justin/kmp-sc-01" and "PR: TBD" with "PR: 1841" so the document shows the actual
branch and PR used for the completed work.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 9b9f1d94-0339-4827-8d11-833ed7dd409a

📥 Commits

Reviewing files that changed from the base of the PR and between b53626c and 0e6937c.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (15)
  • packages/mobile-sdk-alpha/package.json
  • packages/mobile-sdk-alpha/src/adapters/browser/documents.ts
  • packages/mobile-sdk-alpha/tests/adapters/browser/documents.test.ts
  • packages/mobile-sdk-alpha/tsup.config.ts
  • packages/webview-bridge/package.json
  • packages/webview-bridge/src/__tests__/adapters.test.ts
  • packages/webview-bridge/src/__tests__/analytics-web.test.ts
  • packages/webview-bridge/src/__tests__/documents-web.test.ts
  • packages/webview-bridge/src/adapters/analytics-web.ts
  • packages/webview-bridge/src/adapters/crypto.ts
  • packages/webview-bridge/src/adapters/documents-web.ts
  • packages/webview-bridge/src/adapters/haptic.ts
  • packages/webview-bridge/src/adapters/index.ts
  • specs/projects/sdk/workstreams/sdk-core/SPEC.md
  • specs/projects/sdk/workstreams/sdk-core/plans/SC-01-fallback-adapter-dedup.md
💤 Files with no reviewable changes (3)
  • packages/webview-bridge/src/adapters/haptic.ts
  • packages/webview-bridge/src/adapters/analytics-web.ts
  • packages/webview-bridge/src/adapters/documents-web.ts

@transphorm transphorm changed the title sc-01 first commmit Deduplicate bridge-layer fallback adapters onto engine-owned browser implementations (SC-01) Mar 11, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
.github/workflows/webview-bridge-ci.yml (1)

44-52: ⚠️ Potential issue | 🟠 Major

Potential inconsistency: test job may also need the SDK build step.

The build and types jobs now build mobile-sdk-alpha first, but the test job does not. If webview-bridge tests import from @selfxyz/mobile-sdk-alpha (e.g., the new adapters/browser exports), tests could fail without the SDK being built.

Consider adding the same build step for consistency:

  test:
    runs-on: ubuntu-latest
    timeout-minutes: 15
    steps:
      - uses: actions/checkout@v6
      - name: Install dependencies
        uses: ./.github/actions/yarn-install
+     - name: Build mobile-sdk-alpha
+       run: yarn workspace `@selfxyz/mobile-sdk-alpha` build
      - name: Test
        run: yarn workspace `@selfxyz/webview-bridge` test
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.github/workflows/webview-bridge-ci.yml around lines 44 - 52, The test job
currently runs yarn workspace `@selfxyz/webview-bridge` test without building the
SDK, which can cause imports from `@selfxyz/mobile-sdk-alpha` to fail; add a step
in the test job's steps to build the SDK first (e.g., run yarn workspace
`@selfxyz/mobile-sdk-alpha` build or the same build command used in the
build/types jobs) before running yarn workspace `@selfxyz/webview-bridge` test so
tests have the latest SDK artifacts available.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In @.github/workflows/webview-bridge-ci.yml:
- Around line 44-52: The test job currently runs yarn workspace
`@selfxyz/webview-bridge` test without building the SDK, which can cause imports
from `@selfxyz/mobile-sdk-alpha` to fail; add a step in the test job's steps to
build the SDK first (e.g., run yarn workspace `@selfxyz/mobile-sdk-alpha` build or
the same build command used in the build/types jobs) before running yarn
workspace `@selfxyz/webview-bridge` test so tests have the latest SDK artifacts
available.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 926e79a8-8843-4351-afc3-190789a18035

📥 Commits

Reviewing files that changed from the base of the PR and between 0e6937c and 597076f.

📒 Files selected for processing (3)
  • .github/workflows/webview-app-ci.yml
  • .github/workflows/webview-bridge-ci.yml
  • packages/mobile-sdk-alpha/src/data/country-document-types.json

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.github/workflows/webview-app-ci.yml:
- Around line 29-32: The workflow currently runs steps "Build common" and "Build
mobile-sdk-alpha" but the workflow's path filters (pull_request.paths and
push.paths) still exclude the corresponding directories, so changes in common/
or packages/mobile-sdk-alpha/ won't trigger the CI; update the path filters in
.github/workflows/webview-app-ci.yml to include the new upstream dependency
paths (e.g., common/** and packages/mobile-sdk-alpha/**) for both
pull_request.paths and push.paths (and any other path include/exclude blocks
referenced in the file) so that changes to those directories will run the
workflow that executes the "Build common" and "Build mobile-sdk-alpha" steps.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: bd9ca5d3-1970-4158-abdf-ea3564abe59e

📥 Commits

Reviewing files that changed from the base of the PR and between 9dded28 and d88a9e3.

📒 Files selected for processing (4)
  • .github/workflows/webview-app-ci.yml
  • .github/workflows/webview-bridge-ci.yml
  • packages/mobile-sdk-alpha/tsup.config.ts
  • scripts/check-license-headers.mjs
🚧 Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/webview-bridge-ci.yml

Comment thread .github/workflows/webview-app-ci.yml
@transphorm transphorm merged commit 73d2075 into dev Mar 11, 2026
35 checks passed
@transphorm transphorm deleted the justin/kmp-sc-01 branch March 11, 2026 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant