Skip to content

feat(webview): route document storage through the documents bridge domain - #2264

Open
seshanthS wants to merge 2 commits into
feat/documents-bridge-domainfrom
feat/documents-domain-swap
Open

feat(webview): route document storage through the documents bridge domain#2264
seshanthS wants to merge 2 commits into
feat/documents-bridge-domainfrom
feat/documents-domain-swap

Conversation

@seshanthS

@seshanthS seshanthS commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator

Stacked on #2263 (→ #2262#2245). PR 2 of 2 for the documents-domain swap — spec: specs/projects/sdk/workstreams/webview-in-app/plans/WIA-documents-bridge-domain.md.

What

webview-app previously tunneled document JSON through the secureStorage bridge domain (self_document_catalog / self_doc_*), bypassing rn-sdk's dedicated DocumentsHandler and creating a parallel document store. Documents now go over the documents domain, so the host controls storage:

  • WIA host (Self app): WebViewHostScreen already implements the documents prop against the app's production keychain store (documentCatalog / document-<contentHash> via passportDataProvider) — WebView document I/O now lands directly in the app's real store, eliminating the documents half of cutover blocker B2 (no document migration; existing users' documents just appear).
  • Partner apps: rn-sdk's keychain-backed default from feat(rn-sdk): keychain-backed default DocumentsStore #2263.

How

  • New createBridgeDocumentsSdkAdapter(bridge): DocumentsAdapter — typed wrapper over the raw bridgeDocumentsAdapter; normalizes null/malformed catalogs to { documents: [] } (a never-written host store legitimately returns null per the DocumentsHandler contract, but SDK callers dereference catalog.documents unguarded).
  • sdk-adapter-map and SelfClientProvider both use it; the provider's second per-instance adapter is gone (one construction site); createKeychainDocumentsAdapter deleted.
  • KeychainDebugScreen dumps the catalog via the documents adapter; self_document_catalog removed from its raw key list.
  • Test harness (renderWithBridge) gains documents-domain handlers mirroring DocumentsHandler semantics, with seeding + exposure on the result.

Also in this PR

  • Content-hash document ids: capture routes keyed documents by document number (passport-<number>), which is PII — keychain service names derived from the id appear verbatim in native logs (RNKeychainManager logs missing services). Both routes now use the SDK's storePassportData (contentHash ids matching the app's native document-<hash> scheme, dedup, richer catalog metadata). Pinned by a flow test asserting the id never contains a document number.

Decisions / risks

  • No migration of orphaned self_doc_* secureStorage entries — dev-only data, nothing production shipped on that path.
  • useKmpBridge (prototype) reroutes only secureStorage; documents traffic always hits the TS handler. KMP documents parity is a noted follow-up.
  • Release coupling with feat(rn-sdk): keychain-backed default DocumentsStore #2263: the rn-sdk release whose embedded bundle contains this change must include the keychain-backed default store.

Validation

  • webview-bridge: build + 72/72 tests (4 new: null/malformed normalization, app DocumentCatalog fixture pin — the B2 schema-compatibility check — and domain routing).
  • webview-app: build + 245/245 tests; passport happy-path now asserts the captured document lands in the documents-domain store with isRegistered: false.
  • Grep gate: zero residual createKeychainDocumentsAdapter / self_document_catalog / self_doc_ references.
  • Pending on-device (before merge): example-app capture → force-kill → relaunch persistence (Pixel 7a), and WIA host cross-visibility of documents.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added reliable document storage through the SDK.
    • Document catalogs and individual documents can now be loaded, saved, and deleted.
    • Invalid or missing document data is handled safely.
  • Bug Fixes

    • Improved passport document persistence during NFC onboarding.
    • Passport document identifiers no longer include document numbers.
    • Debug tools now inspect document catalogs separately from secure key storage and avoid deleting documents when clearing keys.

…main

webview-app previously tunneled document JSON through secureStorage
(self_document_catalog / self_doc_* keys), bypassing rn-sdk's dedicated
DocumentsHandler and creating a parallel store that the WIA cutover would
have had to migrate. Documents now go over the documents domain, so hosts
control storage: the Self app's WIA host already implements the documents
prop against its production keychain store (documentCatalog /
document-<hash>), which means WebView document I/O lands directly in the
app's real store — no document migration at cutover (B2, documents half).

- createBridgeDocumentsSdkAdapter: typed SDK-facing wrapper over the raw
  documents-domain adapter; normalizes null/malformed catalogs to
  { documents: [] } (SDK callers dereference catalog.documents unguarded;
  a never-written host store legitimately returns null).
- sdk-adapter-map + SelfClientProvider use it; the second per-provider
  adapter instantiation is gone; createKeychainDocumentsAdapter deleted.
- KeychainDebugScreen dumps the catalog via the documents adapter instead
  of the removed secureStorage key.
- Test harness gains documents-domain handlers mirroring DocumentsHandler
  semantics; passport happy-path now asserts the captured document lands
  in the documents store (isRegistered: false); catalog fixture test pins
  the app's DocumentCatalog shape through normalization.

No migration of orphaned self_doc_* secureStorage entries (dev-only data).
Spec: specs/projects/sdk/workstreams/webview-in-app/plans/WIA-documents-bridge-domain.md

Validation: webview-bridge build + 72 tests, webview-app build + 245 tests green.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@vercel

vercel Bot commented Aug 12, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
self-webview-app Ready Ready Preview Aug 12, 2026 10:05am

Request Review

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: bfad00ae-f9a2-4feb-85de-e0fa816cdb30

📥 Commits

Reviewing files that changed from the base of the PR and between 6063e67 and 6a4e5c4.

📒 Files selected for processing (3)
  • packages/webview-app/src/screens/onboarding/eu-id/NfcInstructionsRoute.tsx
  • packages/webview-app/src/screens/onboarding/passport/NfcRoute.tsx
  • packages/webview-app/tests/flows/onboarding.passport.test.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/webview-app/tests/flows/onboarding.passport.test.tsx

📝 Walkthrough

Walkthrough

The webview now obtains document storage from the typed bridge documents adapter. Keychain-backed document storage was removed. Passport onboarding stores normalized data through storePassportData.

Changes

Documents adapter migration

Layer / File(s) Summary
Typed bridge adapter and validation
packages/webview-bridge/src/adapters/documents.ts, packages/webview-bridge/src/__tests__/adapters.test.ts
Added typed document operations with catalog normalization and invalid-document handling. Added tests for catalog reads, document lookup, and catalog writes.
SDK adapter wiring
packages/webview-bridge/src/adapters/index.ts, packages/webview-bridge/src/adapters/sdk-adapter-map.ts, packages/webview-bridge/src/adapters/keychain-documents.ts, packages/webview-app/src/providers/SelfClientProvider.tsx
The SDK adapter map and provider now use the bridge documents adapter. The keychain documents adapter implementation and public export were removed.
Passport storage flow
packages/webview-app/src/screens/onboarding/eu-id/NfcInstructionsRoute.tsx, packages/webview-app/src/screens/onboarding/passport/NfcRoute.tsx
Both NFC routes now call storePassportData after passport normalization instead of manually saving documents and updating the catalog.
Webview document state and verification
packages/webview-app/src/screens/debug/KeychainDebugScreen.tsx, packages/webview-app/tests/utils/renderWithBridge.tsx, packages/webview-app/tests/flows/onboarding.passport.test.tsx
Debug operations access document data through documents. The test harness stores document catalog and document data. Passport onboarding tests verify persisted document state.

Estimated code review effort: 3 (Moderate) | ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% 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
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: routing webview document storage through the documents bridge domain.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/documents-domain-swap

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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6063e67d7c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

network: createWebNetworkAdapter(),
auth,
documents: createKeychainDocumentsAdapter(bridge),
documents: createBridgeDocumentsSdkAdapter(bridge),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Keep shared document IDs content-addressed

When the WebView is hosted by the Self app, this now writes the catalog directly into the app's production document store, but the passport and EU-ID capture routes still create IDs such as passport-<passportNumber> and id_card-<documentNumber>. The shared DocumentMetadata contract defines IDs as content hashes, and the native storeDocumentWithDeduplication path searches by a freshly calculated content hash, so capturing the same document later through the native path misses the WebView entry and creates a duplicate. Route capture through the existing mobile-sdk deduplication utility, or otherwise calculate the canonical content hash before exposing these records to the host catalog.

AGENTS.md reference: AGENTS.md:L17-L17

Useful? React with 👍 / 👎.

) {
return raw as DocumentCatalog;
}
return EMPTY_CATALOG;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Return a fresh empty catalog

When a host returns null or malformed catalog data, this returns the module-level EMPTY_CATALOG object, but capture callers mutate the returned documents array in place before saving it. If saveDocumentCatalog fails, or a subsequent host read is still unset/corrupt, later loads return the previously mutated fallback and expose stale document metadata instead of failing closed to an empty catalog; this can select a document body that was never successfully persisted. Construct a new { documents: [] } for each normalization failure rather than sharing a mutable singleton.

AGENTS.md reference: AGENTS.md:L36-L36

Useful? React with 👍 / 👎.

network: createWebNetworkAdapter(),
auth,
documents: createKeychainDocumentsAdapter(bridge),
documents: createBridgeDocumentsSdkAdapter(bridge),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Add document handlers before switching every native shell

When this WebView bundle runs in either standalone native shell, every document request now fails: packages/native-shell-android/.../SelfVerificationActivity.kt registers only secure-storage, crypto, and lifecycle handlers, and packages/native-shell-ios/.../SelfSdk.swift does the same, while scripts/build-webview-bundle.sh copies this WebView into both shells. Consequently the first documents.save during NFC capture receives DOMAIN_NOT_FOUND/UNKNOWN_DOMAIN and the successfully scanned user is routed to the NFC error screen. Register a compatible documents handler in those hosts before making the domain mandatory, or retain a compatible storage path for them.

Useful? React with 👍 / 👎.

Comment on lines +51 to +53
Array.isArray((raw as { documents?: unknown }).documents)
) {
return raw as DocumentCatalog;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Validate catalog entries before accepting the host value

A host response such as { documents: [null] }, or an array containing entries without a string id, passes this check and is cast to DocumentCatalog. SDK consumers then dereference fields such as doc.id and doc.isRegistered, causing runtime failures or persisting an invalid selectedDocumentId instead of using the intended empty fallback. Since this adapter explicitly treats malformed host catalogs as a boundary failure, validate the entry shapes and optional selected ID before returning the value.

AGENTS.md reference: AGENTS.md:L36-L36

Useful? React with 👍 / 👎.

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: e34b0280-612c-41b2-814a-6afed0fdb3b3

📥 Commits

Reviewing files that changed from the base of the PR and between 0d51094 and 6063e67.

📒 Files selected for processing (9)
  • packages/webview-app/src/providers/SelfClientProvider.tsx
  • packages/webview-app/src/screens/debug/KeychainDebugScreen.tsx
  • packages/webview-app/tests/flows/onboarding.passport.test.tsx
  • packages/webview-app/tests/utils/renderWithBridge.tsx
  • packages/webview-bridge/src/__tests__/adapters.test.ts
  • packages/webview-bridge/src/adapters/documents.ts
  • packages/webview-bridge/src/adapters/index.ts
  • packages/webview-bridge/src/adapters/keychain-documents.ts
  • packages/webview-bridge/src/adapters/sdk-adapter-map.ts
💤 Files with no reviewable changes (1)
  • packages/webview-bridge/src/adapters/keychain-documents.ts

Comment on lines +41 to +55
const EMPTY_CATALOG: DocumentCatalog = { documents: [] };

// The documents host store legitimately returns null for a never-written
// catalog (DocumentsHandler contract), but SDK callers dereference
// catalog.documents unguarded — normalize anything malformed to an empty
// catalog at the boundary.
function normalizeCatalog(raw: unknown): DocumentCatalog {
if (
raw &&
typeof raw === 'object' &&
Array.isArray((raw as { documents?: unknown }).documents)
) {
return raw as DocumentCatalog;
}
return EMPTY_CATALOG;

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.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Return a new empty catalog for each read.

EMPTY_CATALOG is mutable. Each null or malformed host response returns the same object. A caller can mutate catalog.documents, and later reads can return that process-local mutation even when the host store remains empty or a save failed. Return a new { documents: [] } fallback from normalizeCatalog.

Proposed fix
-const EMPTY_CATALOG: DocumentCatalog = { documents: [] };
-
 function normalizeCatalog(raw: unknown): DocumentCatalog {
   if (
     raw &&
     typeof raw === 'object' &&
     Array.isArray((raw as { documents?: unknown }).documents)
   ) {
     return raw as DocumentCatalog;
   }
-  return EMPTY_CATALOG;
+  return { documents: [] };
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const EMPTY_CATALOG: DocumentCatalog = { documents: [] };
// The documents host store legitimately returns null for a never-written
// catalog (DocumentsHandler contract), but SDK callers dereference
// catalog.documents unguarded — normalize anything malformed to an empty
// catalog at the boundary.
function normalizeCatalog(raw: unknown): DocumentCatalog {
if (
raw &&
typeof raw === 'object' &&
Array.isArray((raw as { documents?: unknown }).documents)
) {
return raw as DocumentCatalog;
}
return EMPTY_CATALOG;
// The documents host store legitimately returns null for a never-written
// catalog (DocumentsHandler contract), but SDK callers dereference
// catalog.documents unguarded — normalize anything malformed to an empty
// catalog at the boundary.
function normalizeCatalog(raw: unknown): DocumentCatalog {
if (
raw &&
typeof raw === 'object' &&
Array.isArray((raw as { documents?: unknown }).documents)
) {
return raw as DocumentCatalog;
}
return { documents: [] };
}
🧰 Tools
🪛 GitHub Check: lint

[warning] 48-48:
Replace ⏎····raw·&&⏎····typeof·raw·===·'object'·&&⏎····Array.isArray((raw·as·{·documents?:·unknown·}).documents)⏎·· with raw·&&·typeof·raw·===·'object'·&&·Array.isArray((raw·as·{·documents?:·unknown·}).documents)

Capture routes keyed documents by document number (passport-<number> /
id_card-<number>), which is PII: keychain service names derived from the
id appear verbatim in native logs (RNKeychainManager logs missing
services), and number-based ids collide across document types.

Replace the hand-rolled save + catalog upsert in NfcRoute and
NfcInstructionsRoute with the SDK's storePassportData, which computes
calculateContentHash ids (matching the app's native document-<hash>
scheme), dedups re-captures, and writes richer catalog metadata
(data: mrz for name display). Flow test pins that the id is a content
hash, never a document number.

Validation: webview-app build + 245 tests green.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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