feat(sdk): add tafsir facade#58
Open
TheFlowRunner wants to merge 2 commits into
Open
Conversation
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.
d2168c7 to
f1e47d2
Compare
There was a problem hiding this comment.
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
QuranTafsirSDK class with methods to fetch tafsir by various Quran divisions (ayah/chapter/page/juz/hizb/etc). - Wires the tafsir facade into
QuranClientand runtime clients (client.tafsirandclient.content.v4.tafsir.*). - Adds a
TafsirResponsetype, 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, | ||
| ); | ||
| } |
|
|
||
| ```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) => |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds Tafsir client methods, runtime wiring, tests, and docs.