Skip to content

[codex] Add v4 content parity SDK methods#53

Merged
osamasayed merged 2 commits into
mainfrom
codex/v4-content-parity-sdk
May 4, 2026
Merged

[codex] Add v4 content parity SDK methods#53
osamasayed merged 2 commits into
mainfrom
codex/v4-content-parity-sdk

Conversation

@basit3407
Copy link
Copy Markdown
Collaborator

Summary

This PR brings the JavaScript SDK up to date with the v4 Content API work that was recently merged in quran/quran.com-api:

  • quran/quran.com-api#796 - qdc-style chapter info resource support in v4
  • quran/quran.com-api#798 - public v4 hadith reference endpoints
  • quran/quran.com-api#801 - grouped tafsir text on v4 list endpoints

The goal is for SDK consumers to be able to use the new API behavior through typed SDK methods where we have first-class SDK surfaces, and through the generated raw v4 operation client where the SDK already exposes operation-catalog endpoints.

What Changed

Chapter Info Resource Support

  • Added ChapterInfoResponse, including:
    • chapterInfo: ChapterInfo | null
    • optional resources catalog when includeResources is requested
    • optional resourceId on ChapterInfo
  • Added QuranChapters.findInfoResponseById(id, options) for callers that need the full response shape.
  • Kept QuranChapters.findInfoById(id, options) as the convenience method, now returning ChapterInfo | null because resource-specific lookups can legitimately miss.
  • Exposed the full response method on the modern runtime facade as client.content.v4.chapters.getInfoResponse(...).
  • Added support for resourceId and includeResources query options.

Hadith References

  • Added a typed QuranHadithReferences SDK module with:
    • findByAyah(key, options?)
    • findHadithsByAyah(key, options?)
    • countWithinRange(from, to, options?)
  • Exposed the same methods on the modern runtime facade:
    • client.content.v4.hadithReferences.byAyah(...)
    • client.content.v4.hadithReferences.hadithsByAyah(...)
    • client.content.v4.hadithReferences.countWithinRange(...)
  • Added Hadith Reference response types for references, hadith payloads, grades, pagination metadata, and range counts.
  • Added public-client server-only guarding for hadithReferences, consistent with other app-authenticated Content API reads.

Grouped Tafsir List Endpoint Parity

  • Added contract coverage for the generated raw v4 grouped tafsir operation:
    • client.content.v4.raw.listSurahTafsirs(...)
  • Live validation confirms the generated raw SDK operations for grouped tafsir lists return populated text from both prelive and production for:
    • by chapter
    • by page
    • by juz

No additional first-class typed tafsir wrapper was added in this PR because these endpoints are already exposed through the generated raw operation catalog.

Tests, Mocks, and Release Metadata

  • Extended MSW mocks for chapter-info resource responses, null resource responses, and hadith reference endpoints.
  • Added focused unit coverage for chapter-info resource behavior and hadith reference methods.
  • Added a changeset with a minor bump for @quranjs/api.

Docs

The SDK docs have been updated in the existing docs PR:

Docs updates include:

  • New JavaScript SDK Hadith References page.
  • Chapter Info docs for getInfoResponse, includeResources, resourceId, and nullable chapterInfo.
  • Notes for grouped tafsir list responses returning populated text.
  • API-by-runtime and sidebar updates.
  • llms.txt regeneration and docs config test updates.

Validation

SDK Local Checks

  • pnpm --filter @quranjs/api exec vitest run test/hadith-references.test.ts test/chapters.test.ts test/contracts.test.ts
    • 3 files passed
    • 20 tests passed
  • pnpm --filter @quranjs/api build
    • passed
  • pnpm --filter @quranjs/api lint
    • passed with one existing warning in packages/api/src/types/quran-client.ts for @typescript-eslint/consistent-type-imports

Docs Checks

Run from the qf-api-docs sdk-updates worktree:

  • node --test (Get-ChildItem .\tests -Filter *.test.cjs | ForEach-Object { $_.FullName })
    • 56 tests passed
  • yarn typecheck
    • passed

Live SDK Smoke Test

Run from C:\Code\qf-user-poc using the POC credentials, but importing this branch's local SDK build from:

C:\Code\api-js\packages\api\dist\server.min.mjs

This verified that the SDK itself generates the app token through createServerClient and then calls the new SDK methods/endpoints. No credentials or tokens were printed.

Prelive

  • client.content.v4.chapters.getInfoResponse(1, { includeResources: true })
    • passed
    • returned 1 chapter-info resource
  • client.content.v4.chapters.getInfoResponse(1, { resourceId })
    • passed
    • selected resource returned chapterInfo
  • client.content.v4.hadithReferences.byAyah("1:1")
    • passed
    • response shape is correct; prelive currently has no hadith references loaded for this range
  • client.content.v4.hadithReferences.hadithsByAyah("1:1", { limit: 1 })
    • passed
    • response shape is correct; prelive returned an empty list
  • client.content.v4.hadithReferences.countWithinRange("1:1", "1:7")
    • passed
    • prelive returned no count keys, consistent with the empty hadith-reference dataset
  • client.content.v4.raw.listSurahTafsirs(...), listPageTafsirs(...), and listJuzTafsirs(...)
    • passed using resource 926 / Arabic Jalalayn Tafseer
    • each returned 3 rows and populated text

Production

  • client.content.v4.chapters.getInfoResponse(1, { includeResources: true })
    • passed
    • returned 2 chapter-info resources
  • client.content.v4.chapters.getInfoResponse(1, { resourceId })
    • passed
    • selected resource returned chapterInfo
  • client.content.v4.hadithReferences.byAyah("1:1")
    • passed
    • returned 1 reference
  • client.hadithReferences.findByAyah("1:1")
    • passed
    • returned the same reference count through the root SDK module
  • client.content.v4.hadithReferences.hadithsByAyah("1:1", { limit: 1 })
    • passed
    • returned 1 hadith payload
  • client.content.v4.hadithReferences.countWithinRange("1:1", "1:7")
    • passed
    • returned count keys for 1:1 through 1:7
  • client.content.v4.raw.listSurahTafsirs(...), listPageTafsirs(...), and listJuzTafsirs(...)
    • passed using resource 926 / Arabic Jalalayn Tafseer
    • each returned 3 rows and populated text

Prelive Data Caveat

Initial testing used 12:12 because that appears in local mocks and examples. In prelive, 12:12 returns 404 Not Found even through the normal verse endpoint:

  • client.content.v4.verses.byKey("12:12") => 404 Not Found in prelive
  • client.content.v4.verses.byKey("12:12") => resolves in production

So the prelive 12:12 failure is a prelive content-data issue, not an SDK token, route, or method issue. The final prelive validation used 1:1, which resolves successfully there.

Known Unrelated Test Issue

The full pnpm --filter @quranjs/api test command still hits the pre-existing packages/api/test/operation-catalog-generator.test.js module-load failure before assertions with SyntaxError: Invalid or unexpected token. The targeted test files for this change pass, and the package build succeeds.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 4, 2026

size-limit report 📦

Path Size
dist/index.min.js 4.44 KB (+2.72% 🔺)
dist/index.min.mjs 4.49 KB (+2.62% 🔺)
dist/server.min.js 10.31 KB (+1.46% 🔺)
dist/public.min.js 5.84 KB (+0.14% 🔺)

@basit3407 basit3407 marked this pull request as ready for review May 4, 2026 04:17
@basit3407 basit3407 requested a review from Copilot May 4, 2026 04:20
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates @quranjs/api to match recently-added v4 Content API capabilities by adding first-class typed SDK surfaces (and runtime-facade exposure) for chapter-info resource selection and hadith reference endpoints, plus contract coverage for grouped tafsir list operations.

Changes:

  • Added typed v4 Hadith References SDK module + runtime facade wiring (server-only guarded for public runtime).
  • Extended Chapters SDK to support resourceId / includeResources, and added a full-response findInfoResponseById method (nullable chapterInfo).
  • Updated MSW mocks, unit tests, and operation-contract representative coverage; added a changeset for release.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/api/test/hadith-references.test.ts Adds unit coverage for new hadith references SDK methods and runtime facade exposure.
packages/api/test/contracts.test.ts Extends representative operations coverage for hadith references + grouped tafsir list operation names/paths.
packages/api/test/chapters.test.ts Adds coverage for resourceId, includeResources, and nullable chapterInfo behavior.
packages/api/src/types/api/index.ts Re-exports new Hadith Reference API types.
packages/api/src/types/api/HadithReference.ts Introduces typed response shapes for hadith references, hadith payloads, and range counts.
packages/api/src/types/api/ChapterInfo.ts Adds resourceId and full ChapterInfoResponse shape with optional resources list.
packages/api/src/sdk/hadith-references.ts Implements typed SDK methods for hadith reference endpoints with verse-key validation.
packages/api/src/sdk/client.ts Exposes hadithReferences on the classic QuranClient.
packages/api/src/sdk/chapters.ts Adds findInfoResponseById and supports resourceId/includeResources query options.
packages/api/src/runtime/create-public-client.ts Adds server-only guarding for hadithReferences on the public runtime client surface.
packages/api/src/runtime/create-client.ts Wires hadith references into the server runtime facade (content.v4.hadithReferences + root).
packages/api/mocks/handlers.ts Extends MSW handlers for chapter-info resources/null cases and new hadith reference endpoints.
.changeset/v4-content-parity.md Declares a minor bump for the new typed SDK surfaces.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/api/mocks/handlers.ts
Comment thread packages/api/mocks/handlers.ts
@basit3407 basit3407 requested a review from osamasayed May 4, 2026 04:32
@osamasayed osamasayed merged commit 3cc9de4 into main May 4, 2026
6 checks passed
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.

3 participants