deen-api-client 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Imaniro
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,68 @@
1
+ # Deen API JS Client
2
+
3
+ A Node.js client for the Deen API, providing easy access to Islamic resources including Hadith, Quran verses, and Duas.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install deen-api-client
9
+ ```
10
+
11
+ # Quick Start
12
+
13
+ ```js
14
+ const { ImaniroDeenAPIClient } = require('deen-api-client');
15
+
16
+ // Or using ES modules
17
+ import { ImaniroDeenAPIClient } from 'deen-api-client';
18
+
19
+ // Initialize client with your API key
20
+ const client = new ImaniroDeenAPIClient('your_api_key_here');
21
+
22
+ // Get hadiths from Sahih al-Bukhari
23
+ async function getHadiths() {
24
+ try {
25
+ const hadiths = await client.getHadiths('Sahih al-Bukhari', 5);
26
+
27
+ hadiths.forEach((hadith) => {
28
+ console.log(`Book: ${hadith.book}`);
29
+ console.log(`Chapter: ${hadith.chapter}`);
30
+ console.log(`Text: ${hadith.text}`);
31
+ console.log(`Translation: ${hadith.translation}`);
32
+ console.log('---');
33
+ });
34
+ } catch (error) {
35
+ console.error('Error:', error.message);
36
+ }
37
+ }
38
+
39
+ getHadiths();
40
+ ```
41
+
42
+ # API Reference
43
+
44
+ ## Methods
45
+
46
+ - getHadiths(book, maxLimits, options)
47
+
48
+ - getQuranVerses(surah, verse, maxLimits, options)
49
+
50
+ - getDuas(category, maxLimits, options)
51
+
52
+ - searchHadith(query, book, maxLimits)
53
+
54
+ - getBooks()
55
+
56
+ # Error Handling
57
+
58
+ ```js
59
+ try {
60
+ const hadiths = await client.getHadiths('Sahih al-Bukhari');
61
+ } catch (error) {
62
+ if (error.name === 'AuthenticationError') {
63
+ console.log('Invalid API key');
64
+ } else if (error.name === 'RateLimitError') {
65
+ console.log('Rate limit exceeded');
66
+ }
67
+ }
68
+ ```
package/dist/client.js ADDED
@@ -0,0 +1,76 @@
1
+ const axios = require('axios');
2
+ const {
3
+ DeenAPIError,
4
+ AuthenticationError,
5
+ RateLimitError,
6
+ NotFoundError,
7
+ ServerError
8
+ } = require('./exceptions');
9
+ const {
10
+ Hadith,
11
+ QuranVerse,
12
+ Dua,
13
+ APIResponse
14
+ } = require('./models');
15
+ class ImaniroDeenAPIClient {
16
+ constructor(apiKey, baseURL = 'https://deen-api.imaniro.com/api/v1') {
17
+ if (!apiKey) {
18
+ throw new Error('API key is required');
19
+ }
20
+ this.apiKey = apiKey;
21
+ this.baseURL = baseURL.replace(/\/$/, '');
22
+ this.client = axios.create({
23
+ baseURL: this.baseURL,
24
+ headers: {
25
+ 'Content-Type': 'application/json',
26
+ 'X-API-Key': this.apiKey
27
+ },
28
+ timeout: 30000
29
+ });
30
+ this._setupInterceptors();
31
+ }
32
+ _setupInterceptors() {
33
+ this.client.interceptors.response.use(response => response, error => {
34
+ if (error.response) {
35
+ const {
36
+ status,
37
+ data
38
+ } = error.response;
39
+ switch (status) {
40
+ case 401:
41
+ throw new AuthenticationError(data?.message);
42
+ case 404:
43
+ throw new NotFoundError(data?.message);
44
+ case 429:
45
+ throw new RateLimitError(data?.message);
46
+ case 500:
47
+ throw new ServerError(data?.message);
48
+ default:
49
+ throw new DeenAPIError(data?.message || `HTTP Error: ${status}`, status);
50
+ }
51
+ } else if (error.request) {
52
+ throw new DeenAPIError('Network error: Unable to connect to API');
53
+ } else {
54
+ throw new DeenAPIError(error.message);
55
+ }
56
+ });
57
+ }
58
+ async _makeRequest(endpoint, params = {}) {
59
+ try {
60
+ const response = await this.client.post(`/${endpoint}`, params);
61
+ return new APIResponse(response.data);
62
+ } catch (error) {
63
+ throw error;
64
+ }
65
+ }
66
+ async getHadiths(book, maxLimits = 10, options = {}) {
67
+ const params = {
68
+ book,
69
+ maxLimits,
70
+ ...options
71
+ };
72
+ const response = await this._makeRequest('hadiths', params);
73
+ return response.data.map(item => new Hadith(item));
74
+ }
75
+ }
76
+ module.exports = ImaniroDeenAPIClient;
@@ -0,0 +1,38 @@
1
+ class DeenAPIError extends Error {
2
+ constructor(message, statusCode) {
3
+ super(message);
4
+ this.name = 'DeenAPIError';
5
+ this.statusCode = statusCode;
6
+ }
7
+ }
8
+ class AuthenticationError extends DeenAPIError {
9
+ constructor(message = 'Invalid API key') {
10
+ super(message, 401);
11
+ this.name = 'AuthenticationError';
12
+ }
13
+ }
14
+ class RateLimitError extends DeenAPIError {
15
+ constructor(message = 'Rate limit exceeded') {
16
+ super(message, 429);
17
+ this.name = 'RateLimitError';
18
+ }
19
+ }
20
+ class NotFoundError extends DeenAPIError {
21
+ constructor(message = 'Resource not found') {
22
+ super(message, 404);
23
+ this.name = 'NotFoundError';
24
+ }
25
+ }
26
+ class ServerError extends DeenAPIError {
27
+ constructor(message = 'Server error occurred') {
28
+ super(message, 500);
29
+ this.name = 'ServerError';
30
+ }
31
+ }
32
+ module.exports = {
33
+ DeenAPIError,
34
+ AuthenticationError,
35
+ RateLimitError,
36
+ NotFoundError,
37
+ ServerError
38
+ };
package/dist/index.js ADDED
@@ -0,0 +1,25 @@
1
+ const ImaniroDeenAPIClient = require('./client');
2
+ const {
3
+ Hadith,
4
+ APIResponse
5
+ } = require('./models');
6
+ const {
7
+ DeenAPIError,
8
+ AuthenticationError,
9
+ RateLimitError,
10
+ NotFoundError,
11
+ ServerError
12
+ } = require('./exceptions');
13
+ module.exports = {
14
+ ImaniroDeenAPIClient,
15
+ Hadith,
16
+ APIResponse,
17
+ DeenAPIError,
18
+ AuthenticationError,
19
+ RateLimitError,
20
+ NotFoundError,
21
+ ServerError
22
+ };
23
+
24
+ // Default export for ES modules
25
+ module.exports.default = ImaniroDeenAPIClient;
package/dist/models.js ADDED
@@ -0,0 +1,26 @@
1
+ class Hadith {
2
+ constructor(data) {
3
+ this.attribution = data.attribution || '';
4
+ this.authenticity = data.authenticity || '';
5
+ this.category = data.category || '';
6
+ this.context = data.context | '';
7
+ this.book = data.book || '';
8
+ this.number = data.number || '';
9
+ this.explanation = data.explanation || '';
10
+ this.hadith = data.hadith || '';
11
+ this.narratedBy = data.narratedBy || '';
12
+ this.translation = data.translation || '';
13
+ }
14
+ }
15
+ class APIResponse {
16
+ constructor(data) {
17
+ this.success = data.success || false;
18
+ this.data = data.data || [];
19
+ this.message = data.message || '';
20
+ this.count = data.count || 0;
21
+ }
22
+ }
23
+ module.exports = {
24
+ Hadith,
25
+ APIResponse
26
+ };
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "deen-api-client",
3
+ "version": "1.0.0",
4
+ "description": "Node.js client for Deen API - Islamic resources API (Hadith, Quran, Duas)",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "scripts": {
8
+ "build": "babel src --out-dir dist",
9
+ "prepublishOnly": "npm run build",
10
+ "test": "jest",
11
+ "test:watch": "jest --watch",
12
+ "example": "node examples/hadith-example.js"
13
+ },
14
+ "keywords": [
15
+ "islamic",
16
+ "api",
17
+ "hadith",
18
+ "quran",
19
+ "dua",
20
+ "muslim",
21
+ "deen",
22
+ "islam"
23
+ ],
24
+ "author": "Imaniro Pvt Ltd <info@imaniro.com>",
25
+ "license": "MIT",
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "git+https://github.com/imaniro-tech/deen-api-js-client.git"
29
+ },
30
+ "homepage": "https://github.com/imaniro-tech/deen-api-js-client",
31
+ "bugs": {
32
+ "url": "https://github.com/imaniro-tech/deen-api-js-client/issues"
33
+ },
34
+ "dependencies": {
35
+ "axios": "^1.6.0"
36
+ },
37
+ "devDependencies": {
38
+ "@babel/cli": "^7.28.3",
39
+ "@babel/core": "^7.28.4",
40
+ "@babel/preset-env": "^7.28.3",
41
+ "jest": "^29.7.0",
42
+ "nock": "^13.5.6"
43
+ },
44
+ "engines": {
45
+ "node": ">=14.0.0"
46
+ },
47
+ "files": [
48
+ "dist",
49
+ "README.md",
50
+ "LICENSE"
51
+ ],
52
+ "directories": {
53
+ "example": "examples",
54
+ "test": "tests"
55
+ }
56
+ }