Skip to content

[codex] Add SDK support for Content v4 Answers endpoints#55

Open
basit3407 wants to merge 2 commits into
mainfrom
codex/v4-answers-sdk
Open

[codex] Add SDK support for Content v4 Answers endpoints#55
basit3407 wants to merge 2 commits into
mainfrom
codex/v4-answers-sdk

Conversation

@basit3407
Copy link
Copy Markdown
Collaborator

Summary

  • Add first-class SDK types and methods for the public Content v4 Answers endpoints introduced by quran/quran.com-api#800.
  • Expose the endpoints through both client.answers and client.content.v4.answers in the server runtime, with a server-only guard in the public runtime.
  • Preserve the pageSize query parameter casing for answers.byAyah, because this endpoint's API contract uses camelCase there.
  • Normalize answer count type buckets after response camelization so dynamic keys remain usable as TAFSIR, CLARIFICATION, etc.

Why

While smoke testing the published @quranjs/api package through the qf-user-poc, we realized the recently merged quran/quran.com-api#800 endpoints were live and documented but did not have first-class SDK wrappers yet. The SDK could only reach them through generated raw operations, which meant consumers did not get the typed and ergonomic surface we expect for new Content v4 public APIs.

This follows the same process as the previous SDK follow-up: compare the merged API contract, add the missing SDK facade, test it in unit coverage, then install the local SDK build into the PoC and run live/prelive smoke checks before opening the PR.

API Surface

await client.content.v4.answers.byAyah("1:1", {
  language: "en",
  page: 1,
  pageSize: 2,
});

await client.content.v4.answers.get("64");

await client.content.v4.answers.countWithinRange("1:1", "1:1", {
  language: "en",
});

The same calls are also available from the root content client as client.answers.findByAyah, client.answers.findByQuestionId, and client.answers.countWithinRange.

Validation

  • pnpm --filter @quranjs/api lint passes with the existing type-import warning in packages/api/src/types/quran-client.ts and Node module-type warning for eslint.config.js.
  • pnpm --filter @quranjs/api build
  • pnpm --filter @quranjs/api exec vitest run --exclude test/operation-catalog-generator.test.js
  • Installed the local SDK build into C:\Code\qf-user-poc as file:../api-js/packages/api and verified the PoC displays @quranjs/[email protected] (local file: file:../api-js/packages/api).
  • PoC live checks:
    • Pre-live /sdk/content-answers/prelive: 4 passed, 0 warnings, 0 failed.
    • Production /sdk/content-answers/production: 4 passed, 0 warnings, 0 failed.

Docs

Docs PR #147 has been updated with the SDK Answers page and sidebar/runtime references: quran/qf-api-docs#147.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 4, 2026

size-limit report 📦

Path Size
dist/index.min.js 4.57 KB (+3.11% 🔺)
dist/index.min.mjs 4.62 KB (+2.96% 🔺)
dist/server.min.js 10.47 KB (+1.47% 🔺)
dist/public.min.js 5.85 KB (+0.21% 🔺)

@basit3407 basit3407 requested a review from Copilot May 4, 2026 10:06
@basit3407 basit3407 marked this pull request as ready for review May 4, 2026 10:06
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

Adds first-class SDK support for the new Content v4 answers endpoints so consumers can call them through both the legacy/root SDK surface and the server runtime facade.

Changes:

  • Added Answer-related API types and a new QuranAnswers SDK wrapper for by-ayah, by-id, and count-within-range endpoints.
  • Exposed answers through client.answers and client.content.v4.answers on the server runtime, with a server-only guard on the public runtime.
  • Preserved pageSize query casing and added tests/mocks for the new answers flows.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/api/test/answers.test.ts Adds unit coverage for the new answers SDK methods and one content.v4 alias path.
packages/api/src/types/api/index.ts Re-exports the new answer-related API types.
packages/api/src/types/api/Answer.ts Defines answer/question/count response types for the new endpoints.
packages/api/src/sdk/client.ts Exposes the new answers SDK on the legacy root client.
packages/api/src/sdk/answers.ts Implements the answers SDK wrapper and count-type normalization.
packages/api/src/runtime/create-public-client.ts Adds a public-runtime server-only guard for top-level answers.
packages/api/src/runtime/create-client.ts Wires answers into the server runtime root and content.v4 facade.
packages/api/src/lib/url.ts Preserves camelCase for pageSize during query serialization.
packages/api/mocks/handlers.ts Adds mock handlers for the new answers endpoints used by tests.
.changeset/v4-answers-sdk.md Declares a minor release for the new SDK surface.

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

Comment thread packages/api/src/runtime/create-public-client.ts
Comment thread packages/api/src/sdk/client.ts
Comment thread packages/api/src/runtime/create-client.ts
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

Copilot reviewed 12 out of 12 changed files in this pull request and generated no new comments.

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.

2 participants