Skip to content

feat(sdk): add tafsir facade#58

Open
TheFlowRunner wants to merge 2 commits into
quran:mainfrom
TheFlowRunner:feat/tafsir-sdk
Open

feat(sdk): add tafsir facade#58
TheFlowRunner wants to merge 2 commits into
quran:mainfrom
TheFlowRunner:feat/tafsir-sdk

Conversation

@TheFlowRunner
Copy link
Copy Markdown

@TheFlowRunner TheFlowRunner commented May 17, 2026

Adds Tafsir client methods, runtime wiring, tests, and docs.

add a dedicated tafsir client and content facade so tafsir endpoints can be used directly through the SDK instead of only through resources or raw calls. include docs and tests for the new surface.
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

This PR adds a first-class Tafsir facade to the @quranjs/api SDK, wiring it into both the core QuranClient and the runtime clients, plus adding initial tests and documentation for the new surface.

Changes:

  • Introduces a new QuranTafsir SDK class with methods to fetch tafsir by various Quran divisions (ayah/chapter/page/juz/hizb/etc).
  • Wires the tafsir facade into QuranClient and runtime clients (client.tafsir and client.content.v4.tafsir.*).
  • Adds a TafsirResponse type, Vitest coverage, and new docs page for the Tafsir API.

Reviewed changes

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

Show a summary per file
File Description
packages/api/test/tafsir.test.ts Adds new Vitest coverage for the tafsir facade.
packages/api/test/server-client.test.ts Verifies server runtime client exposes the tafsir facade.
packages/api/test/public-client.test.ts Verifies public runtime client exposes a server-only guarded tafsir facade shape.
packages/api/src/types/api/TafsirResponse.ts Adds a typed response model for tafsir endpoints.
packages/api/src/types/api/index.ts Re-exports the new TafsirResponse type from the API types barrel.
packages/api/src/sdk/tafsir.ts Implements the QuranTafsir facade and its methods.
packages/api/src/sdk/client.ts Adds tafsir to the core QuranClient instance surface.
packages/api/src/runtime/create-public-client.ts Adds tafsir to the public runtime client as server-only guarded.
packages/api/src/runtime/create-client.ts Wires tafsir into the runtime client and content v4 facade.
apps/docs/content/docs/tafsir.mdx Adds developer documentation for the new Tafsir API surface.

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

export interface TafsirResponse {
tafsirs: Tafsir[];
meta?: TafsirMeta;
pagination?: Pagination & {
* @param {string | number} tafsirId tafsir id
* @param {GetTafsirOptions} options
* @example
* client.tafsir.get('169', { chapterNumber: 1 })
Comment on lines +103 to +129
/**
* Get tafsirs for a specific rub el hizb.
*/
async findByRubElHizb(
resourceId: string | number,
rubElHizbNumber: number | string,
options?: GetTafsirOptions,
): Promise<TafsirResponse> {
return this.fetcher.fetch<TafsirResponse>(
`/content/api/v4/tafsirs/${resourceId}/by_rub_el_hizb/${rubElHizbNumber}`,
options,
);
}

/**
* Alias for rub el hizb.
*/
async findByRub(
resourceId: string | number,
rubNumber: number | string,
options?: GetTafsirOptions,
): Promise<TafsirResponse> {
return this.fetcher.fetch<TafsirResponse>(
`/content/api/v4/tafsirs/${resourceId}/by_rub/${rubNumber}`,
options,
);
}
Comment thread apps/docs/content/docs/tafsir.mdx Outdated

```ts
const tafsir = await client.tafsir.get("169", {
chapter_number: 1,
Comment on lines +29 to +55
describe("findByPage()", () => {
it("should return tafsirs for a page", async () => {
const response = await testClient.tafsir.findByPage(RESOURCE_ID, "1");
expect(response.tafsirs).toBeInstanceOf(Array);
});
});

describe("findByJuz()", () => {
it("should return tafsirs for a juz", async () => {
const response = await testClient.tafsir.findByJuz(RESOURCE_ID, "1");
expect(response.tafsirs).toBeInstanceOf(Array);
});
});

describe("findByHizb()", () => {
it("should return tafsirs for a hizb", async () => {
const response = await testClient.tafsir.findByHizb(RESOURCE_ID, "1");
expect(response.tafsirs).toBeInstanceOf(Array);
});
});

describe("findByAyah()", () => {
it("should return tafsirs for an ayah", async () => {
const response = await testClient.tafsir.findByAyah(RESOURCE_ID, "1:1");
expect(response.tafsirs).toBeInstanceOf(Array);
});

Comment on lines +429 to +431
byRub: (resourceId: string | number, rubNumber: number | string, query?: ApiParams) =>
tafsir.findByRub(resourceId, rubNumber, query),
byRubElHizb: (resourceId: string | number, rubElHizbNumber: number | string, query?: ApiParams) =>
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