Skip to content

Extract Reusable App Adapter Factories for SelfClient Assembly#1862

Merged
seshanthS merged 1 commit intodevfrom
feat/SC-03
Mar 24, 2026
Merged

Extract Reusable App Adapter Factories for SelfClient Assembly#1862
seshanthS merged 1 commit intodevfrom
feat/SC-03

Conversation

@seshanthS
Copy link
Copy Markdown
Collaborator

@seshanthS seshanthS commented Mar 24, 2026

Summary

Test plan


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 network adapter is now available for web-based applications, supporting HTTP and WebSocket communication.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 24, 2026

📝 Walkthrough

Walkthrough

Introduces a new createWebNetworkAdapter() factory function that provides browser-native network capabilities using fetch and WebSocket APIs. The implementation is exported through the public API barrel files and tracked as complete in project specifications.

Changes

Cohort / File(s) Summary
Browser Network Adapter Implementation
packages/mobile-sdk-alpha/src/adapters/browser/network.ts
Adds createWebNetworkAdapter() returning a NetworkAdapter with HTTP via native fetch and WebSocket via WebSocket constructor, including event handlers for message, error, and close events.
API Exports
packages/mobile-sdk-alpha/src/adapters/browser/index.ts, packages/mobile-sdk-alpha/src/browser.ts
Barrel file re-exports of the new createWebNetworkAdapter factory for public consumption.
Specification & Status Updates
specs/projects/sdk/workstreams/sdk-core/SPEC.md, specs/projects/sdk/workstreams/sdk-core/plans/SC-03-selfclient-adapter-assembly.md
Marks SC-03 task as Done, documents scope refinement toward webview-app support, and confirms RN app remains unmodified.

Estimated Code Review Effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly Related PRs

Suggested Labels

codex

Poem

🌐 Fetch and sockets dance in code,
Browser adapters take the road,
WebViews smile with networks lean,
Cleanest adapter ever seen! 🚀

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is largely incomplete, with empty placeholders for the Summary and Test plan sections, and unchecked Native Consolidation Checklist items that should be verified. Fill in the Summary section with details about what was changed and why. Provide a concrete Test plan explaining how the changes were tested or validated.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: extracting reusable browser-based adapter factories for use in SelfClient assembly.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/SC-03

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.

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 `@packages/mobile-sdk-alpha/src/adapters/browser/network.ts`:
- Line 21: The send implementation on the browser network adapter should guard
against sending when the underlying socket isn't open: update the send function
(the send property that calls socket.send) to first check socket.readyState ===
WebSocket.OPEN and if not throw a clear SDK error (matching the React-Native
adapter’s behavior) instead of calling socket.send directly to avoid the DOM
InvalidStateError; reference the send property, socket and readyState symbols
when locating and changing the code.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 96bbeb2a-e5c2-43ea-b58e-6c86880b510b

📥 Commits

Reviewing files that changed from the base of the PR and between 3eae9dc and df83def.

📒 Files selected for processing (5)
  • packages/mobile-sdk-alpha/src/adapters/browser/index.ts
  • packages/mobile-sdk-alpha/src/adapters/browser/network.ts
  • packages/mobile-sdk-alpha/src/browser.ts
  • specs/projects/sdk/workstreams/sdk-core/SPEC.md
  • specs/projects/sdk/workstreams/sdk-core/plans/SC-03-selfclient-adapter-assembly.md

connect: (url: string): WsConn => {
const socket = new WebSocket(url);
return {
send: (data: string | ArrayBufferView | ArrayBuffer) => socket.send(data),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

send() should check readyState before dispatching.

The socket.send(data) call will throw an InvalidStateError if the WebSocket is not in the OPEN state. The parallel React-Native adapter in src/adapters/react-native/network.ts guards this case with a descriptive error. Without this check, callers get an obscure DOM exception instead of a clear SDK error.

🛡️ Proposed fix
-          send: (data: string | ArrayBufferView | ArrayBuffer) => socket.send(data),
+          send: (data: string | ArrayBufferView | ArrayBuffer) => {
+            if (socket.readyState !== WebSocket.OPEN) {
+              throw new Error(`Cannot send data — WebSocket is not open (readyState=${socket.readyState}).`);
+            }
+            socket.send(data);
+          },
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/mobile-sdk-alpha/src/adapters/browser/network.ts` at line 21, The
send implementation on the browser network adapter should guard against sending
when the underlying socket isn't open: update the send function (the send
property that calls socket.send) to first check socket.readyState ===
WebSocket.OPEN and if not throw a clear SDK error (matching the React-Native
adapter’s behavior) instead of calling socket.send directly to avoid the DOM
InvalidStateError; reference the send property, socket and readyState symbols
when locating and changing the code.

@seshanthS seshanthS merged commit 8947671 into dev Mar 24, 2026
33 of 34 checks passed
@seshanthS seshanthS deleted the feat/SC-03 branch March 24, 2026 17:54
@transphorm transphorm mentioned this pull request Mar 25, 2026
10 tasks
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