Skip to content

feat(shared): add unified DeepLinkResolver with polymorphic fallback chain#415

Closed
Itzzavdheshh wants to merge 9 commits into
Dev-Card:mainfrom
Itzzavdheshh:deep-link-pr
Closed

feat(shared): add unified DeepLinkResolver with polymorphic fallback chain#415
Itzzavdheshh wants to merge 9 commits into
Dev-Card:mainfrom
Itzzavdheshh:deep-link-pr

Conversation

@Itzzavdheshh

Copy link
Copy Markdown
Contributor

Summary

Closes #42

This PR introduces a unified DeepLinkResolver utility in packages/shared that eliminates fragmented deep-link logic previously spread across platforms.ts and the backend follow.ts route. The resolver implements a polymorphic fallback chain — native-deeplink → universal-link → web-url → webview — and is consumed by both the mobile screen and the backend API, removing all duplicated URL construction logic.


Type of Change

  • Bug fix
  • New feature
  • Refactor (no functional change)
  • UI / Design change
  • Tests only
  • Documentation
  • Infrastructure / DevOps
  • Security

What Changed

  • packages/shared/src/deepLinks.ts (new): defines LinkStrategy, ResolvedLink types and exports resolveDeepLink(platform, username, context) which builds and returns the full priority fallback chain based on device + app-install context.
  • packages/shared/src/platforms.ts: extends PlatformDef interface with nativeScheme: string | null, universalLink: string | null, and webViewFallback: boolean; updates all 17 platform registry entries with correct values.
  • packages/shared/src/index.ts: re-exports everything from ./deepLinks so consumers import from @devcard/shared.
  • apps/backend/src/routes/follow.ts: replaces ad-hoc URL assembly with a call to resolveDeepLink(..., { isMobile: false }); returns { strategy: 'webview', url } when the resolved strategy is webview.
  • apps/mobile/src/screens/DevCardViewScreen.tsx: introduces executeResolvedLinkChain(resolved, link) async helper; refactors handlePlatformAction for all three action variants to call resolveDeepLink and traverse the chain with Linking.canOpenURL / Linking.openURL, falling back to handleWebViewConnect when strategy === 'webview'.
  • packages/shared/src/__tests__/deepLinks.test.ts (new): Vitest suite covering all 4 strategies, full chain traversal in mobile + desktop context, and {username} interpolation for all platforms.

How to Test

  1. Run TypeScript type-check in the shared package:
    pnpm --filter @devcard/shared typecheck
  2. Run the new unit tests in isolation:
    pnpm --filter @devcard/shared test src/__tests__/deepLinks.test.ts
  3. Run the backend follow endpoint tests:
    pnpm --filter @devcard/backend test src/__tests__/follow.test.ts
  4. Run the full test suite to confirm no regressions:
    pnpm -r test
  5. On a physical device (or simulator) with LinkedIn installed, tap the LinkedIn connect button — verify the app opens directly. Remove LinkedIn and tap again — verify the in-app webview fallback is used.

Checklist

  • My code follows the project's coding style (pnpm -r run lint passes).
  • TypeScript compiles without errors (pnpm -r run typecheck).
  • I have added or updated tests for the changes I made.
  • All tests pass locally (pnpm -r run test).
  • I have updated documentation where necessary.
  • No new console.log or debug statements left in the code.
  • Breaking changes are documented in this PR description.

Breaking changes: The PlatformDef interface now requires three new fields (nativeScheme, universalLink, webViewFallback). Any downstream code that constructs a PlatformDef object manually must be updated to include these fields. All 17 entries in PLATFORMS have been updated; no runtime breakage is expected.


Screenshots / Recordings

Not applicable — no UI changes; behaviour is functionally equivalent with improved reliability.


Additional Context

  • The fallback chain is intentionally lazy: each node holds an optional .fallback reference rather than a flat array, making it easy to extend with new strategies in the future without breaking existing consumers.
  • webViewFallback: true is currently set only for LinkedIn and Twitter/X, which require authenticated sessions that prevent direct in-app browsing.
  • Future work: consider caching the result of Linking.canOpenURL per platform per session to avoid repeated async checks on repeated taps.

Submitted as part of Open Source Contribution — GSSoC (GirlScript Summer of Code)

itzzavdhesh and others added 2 commits May 30, 2026 19:55
Signed-off-by: AVDHESH KUMAR DADHICH <aavdhesh.dadhich@gmail.com>
@Itzzavdheshh

Itzzavdheshh commented May 30, 2026

Copy link
Copy Markdown
Contributor Author

Hi @ShantKhatri & @Harxhit — thanks for taking the time to review this!

Unified Deep-Link Resolver — cross-package refactor

Introduced a shared resolveDeepLink utility in packages/shared that consolidates
all platform URL logic into a single, typed, polymorphic fallback chain
(native-deeplink → universal-link → web-url → webview).

Previously, deep-link construction was duplicated across the backend follow route
and the mobile DevCardViewScreen, each with its own branching logic and no shared
contract. This change gives every current and future platform a first-class resolver
entry (nativeScheme, universalLink, webViewFallback) and makes both consumers
— mobile and backend — delegate entirely to the shared package.

Difficulty: senior | Scope: packages/shared, apps/backend, apps/mobile
Tests added: exhaustive Vitest suite covering all 4 strategies and all 17 platforms.

Happy to address any feedback or make adjustments — just let me know! 🚀

@Harxhit Harxhit added the gssoc:approved Required label for every approved PR. Gives the base +50 points and enables contribution tracking. label May 31, 2026
@Itzzavdheshh

Copy link
Copy Markdown
Contributor Author

Hi @ShantKhatri updates?

Signed-off-by: AVDHESH KUMAR DADHICH <aavdhesh.dadhich@gmail.com>
@vercel

vercel Bot commented Jun 5, 2026

Copy link
Copy Markdown

@Itzzavdheshh is attempting to deploy a commit to the Prashantkumar Khatri's projects Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions

github-actions Bot commented Jun 5, 2026

Copy link
Copy Markdown

CI — All Checks Passed

Backend — PASS

Check Result
Lint PASS
Test PASS
Typecheck PASS

Mobile — PASS

Check Result
Lint PASS
Test PASS

Web — PASS

Check Result
Check PASS
Build PASS

Last updated: Sat, 06 Jun 2026 12:26:14 GMT

@Itzzavdheshh

Copy link
Copy Markdown
Contributor Author

Hi @ShantKhatri please check , i did some changes ...i request you to please review and give necessary feedback and i am happy to address them . Thanku

@Itzzavdheshh

Copy link
Copy Markdown
Contributor Author

Hi @ShantKhatri are you closing this one too?

@Itzzavdheshh

Copy link
Copy Markdown
Contributor Author

@ShantKhatri ???

@ShantKhatri

Copy link
Copy Markdown
Contributor

Hi @ShantKhatri are you closing this one too?

Yes

@ShantKhatri ShantKhatri closed this Jun 6, 2026
@Itzzavdheshh

Copy link
Copy Markdown
Contributor Author

@ShantKhatri bro i spend so much time and make so much effort on this one , and it all goes to recycle bin 😢

@ShantKhatri

Copy link
Copy Markdown
Contributor

@ShantKhatri bro i spend so much time and make so much effort on this one , and it all goes to recycle bin 😢

But this PR was not supposed to be reviewed, as it's recommended to have short reviewable PR. This PR had about 45 files changed and was flooded with features.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc:approved Required label for every approved PR. Gives the base +50 points and enables contribution tracking.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

shared + backend: design unified platform deep-link resolver with fallback chain

4 participants