@quranjs/api 3.7.0 → 3.9.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/dist/index.min.js CHANGED
@@ -1,3 +1,3 @@
1
- 'use strict';var G=require('humps');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var G__default=/*#__PURE__*/_interopDefault(G);var T=(n,e)=>{let t=`${n}:${e}`;if(typeof Buffer<"u")return Buffer.from(t).toString("base64");if(typeof globalThis.btoa=="function")return globalThis.btoa(t);throw new Error("No base64 encoder available for HTTP basic auth.")};var g=async(n,e={retries:3})=>{let t;for(let s=0;s<=e.retries;s++)try{return await n()}catch(i){if(t=i,s===e.retries)throw t;await new Promise(o=>setTimeout(o,Math.pow(2,s)*1e3));}throw t};var S="https://apis.quran.foundation",B={oauth2:"https://oauth2.quran.foundation"};var{decamelize:b}=G__default.default;var N=n=>n.startsWith("/")?n.slice(1):n;var E=["wordFields","translationFields","fields"],O=new Set([...E,...E.map(n=>b(n))]),U=new Set(["navigationalResultsNumber","pageSize","versesResultsNumber"]),_=(n,e={})=>{if(!n)return "";let t=new URLSearchParams;for(let[s,i]of Object.entries(n)){if(i===void 0)continue;let o=e.preserveCase||U.has(s)?s:b(s);if(O.has(s)||O.has(o)){let V=Object.entries(i).filter(([,A])=>A).map(([A])=>b(A));V.length>0&&t.set(o,V.join(","));continue}typeof i=="string"?t.set(o,i):typeof i=="number"||typeof i=="boolean"?t.set(o,i.toString()):Array.isArray(i)&&t.set(o,i.join(","));}return t.size===0?"":`?${t.toString()}`};var z=(o=>(o.Word="word",o.End="end",o.Pause="pause",o.Sajdah="sajdah",o.RubElHizb="rub-el-hizb",o))(z||{});var K=(p=>(p.SURAH="surah",p.JUZ="juz",p.HIZB="hizb",p.AYAH="ayah",p.RUB_EL_HIZB="rub_el_hizb",p.SEARCH_PAGE="search_page",p.PAGE="page",p.RANGE="range",p.QURAN_RANGE="quran_range",p))(K||{});var $=(t=>(t.Advanced="advanced",t.Quick="quick",t))($||{});var H=(r=>(r.ARABIC="ar",r.ENGLISH="en",r.URDU="ur",r.BENGALI="bn",r.TURKISH="tr",r.SPANISH="es",r.GERMAN="de",r.BOSNIAN="bs",r.RUSSIAN="ru",r.ALBANIAN_AL="al",r.FRENCH="fr",r.DUTCH="nl",r.TAMIL="ta",r.TAJIK="tg",r.INDONESIAN="id",r.UZBEK="uz",r.VIETNAMESE="vi",r.CHINESE="zh",r.ITALIAN="it",r.JAPANESE="ja",r.MALAYALAM="ml",r.AMHARIC="am",r.KAZAKH="kk",r.PORTUGUESE="pt",r.TAGALOG="tl",r.THAI="th",r.KOREAN="ko",r.HINDI="hi",r.KURDISH="ku",r.HAUSA="ha",r.AZERI="az",r.SWAHILI="sw",r.PERSIAN="fa",r.SERBIAN="sr",r.MARANAO="mrn",r.AMAZIGH="zgh",r.ASSAMESE="as",r.BULGARIAN="bg",r.CHECHEN="ce",r.CZECH="cs",r.DIVEHI="dv",r.FINNISH="fi",r.GUJAARATI="gu",r.HEBREW="he",r.GEORGIAN="ka",r.CENTRAL_KHMER="km",r.GANDA="lg",r.MARATHI="mr",r.YORUBA="yo",r.MALAY="ms",r.NEPALI="ne",r.SWEDISH="sv",r.TELUGU="te",r.TATAR="tt",r.UYGHUR="ug",r.UKRAINIAN="uk",r.NORWEGIAN="no",r.OROMO="om",r.POLISH="pl",r.PASHTO="ps",r.ROMANIAN="ro",r.SINDHI="sd",r.NORTHERN_SAMI="se",r.SINHALA="si",r.SOMALI="so",r.ALBANIAN_SQ="sq",r))(H||{}),Q=(s=>(s.MadaniV1="code_v1",s.MadaniV2="code_v2",s.Uthmani="text_uthmani",s))(Q||{});var c=n=>{let e=typeof n=="number"?n:Number(n);return !(!e||e<=0||e>114)};var I=n=>{let e=typeof n=="number"?n:Number(n);return !(!e||e<=0||e>30)};var v=n=>{let e=typeof n=="number"?n:Number(n);return !(!e||e<=0||e>240)};var w=n=>{let e=typeof n=="number"?n:Number(n);return !(!e||e<=0||e>60)};var C=n=>{let e=typeof n=="number"?n:Number(n);return !(!e||e<=0||e>604)};var k={1:7,2:286,3:200,4:176,5:120,6:165,7:206,8:75,9:129,10:109,11:123,12:111,13:43,14:52,15:99,16:128,17:111,18:110,19:98,20:135,21:112,22:78,23:118,24:64,25:77,26:227,27:93,28:88,29:69,30:60,31:34,32:30,33:73,34:54,35:45,36:83,37:182,38:88,39:75,40:85,41:54,42:53,43:89,44:59,45:37,46:35,47:38,48:29,49:18,50:45,51:60,52:49,53:62,54:55,55:78,56:96,57:29,58:22,59:24,60:13,61:14,62:11,63:11,64:18,65:12,66:12,67:30,68:52,69:52,70:44,71:28,72:28,73:20,74:56,75:40,76:31,77:50,78:40,79:46,80:42,81:29,82:19,83:36,84:25,85:22,86:17,87:19,88:26,89:30,90:20,91:15,92:21,93:11,94:8,95:8,96:19,97:5,98:8,99:8,100:11,101:11,102:8,103:3,104:9,105:5,106:4,107:7,108:3,109:6,110:3,111:5,112:4,113:5,114:6};var a=n=>{let[e,t]=n.trim().split(":");if(!e||!t||!c(e))return false;let s=Number(t),i=k[e];return !(!s||s<=0||s>i)};var W=n=>Object.fromEntries(Object.entries(n).map(([e,t])=>t.types?[e,{...t,types:Object.fromEntries(Object.entries(t.types).map(([s,i])=>[s.toUpperCase(),i]))}]:[e,t])),h=class{constructor(e){this.fetcher=e;}async findByAyah(e,t){if(!a(e))throw new Error("Invalid verse key");return this.fetcher.fetch(`/content/api/v4/answers/by_ayah/${e}`,t)}async findByQuestionId(e){return this.fetcher.fetch(`/content/api/v4/answers/${e}`)}async countWithinRange(e,t,s){if(!a(e)||!a(t))throw new Error("Invalid verse key");let i=await this.fetcher.fetch("/content/api/v4/answers/count_within_range",{...s,from:e,to:t});return W(i)}};var M="https://verses.quran.com";function F(n){return n.map(e=>{let t=e.url.startsWith("http://")||e.url.startsWith("https://")?e.url:`${M}/${e.url.replace(/^\/+/,"")}`;return {...e,audioUrl:t}})}var f=class{constructor(e){this.fetcher=e;}async findAllChapterRecitations(e,t){let{audioFiles:s}=await this.fetcher.fetch(`/content/api/v4/chapter_recitations/${e}`,t);return s}async findChapterRecitationById(e,t,s){if(!c(t))throw new Error("Invalid chapter id");let{audioFile:i}=await this.fetcher.fetch(`/content/api/v4/chapter_recitations/${e}/${t}`,s);return i}async findVerseRecitationsByChapter(e,t,s){if(!c(e))throw new Error("Invalid chapter id");let i=await this.fetcher.fetch(`/content/api/v4/recitations/${t}/by_chapter/${e}`,s);return {...i,audioFiles:F(i.audioFiles)}}async findVerseRecitationsByKey(e,t,s){if(!a(e))throw new Error("Invalid verse key");let i=await this.fetcher.fetch(`/content/api/v4/recitations/${t}/by_ayah/${e}`,s);return {...i,audioFiles:F(i.audioFiles)}}};var u=class{constructor(e){this.fetcher=e;}async findAll(e){let{chapters:t}=await this.fetcher.fetch("/content/api/v4/chapters",e);return t}async findById(e,t){if(!c(e))throw new Error("Invalid chapter id");let{chapter:s}=await this.fetcher.fetch(`/content/api/v4/chapters/${e}`,t);return s}async findInfoById(e,t){let{chapterInfo:s}=await this.findInfoResponseById(e,t);return s}async findInfoResponseById(e,t){if(!c(e))throw new Error("Invalid chapter id");return this.fetcher.fetch(`/content/api/v4/chapters/${e}/info`,t)}};var l=class{constructor(e){this.fetcher=e;}async findByAyah(e,t){if(!a(e))throw new Error("Invalid verse key");return this.fetcher.fetch(`/content/api/v4/hadith_references/by_ayah/${e}`,t)}async findHadithsByAyah(e,t){if(!a(e))throw new Error("Invalid verse key");return this.fetcher.fetch(`/content/api/v4/hadith_references/by_ayah/${e}/hadiths`,t)}async countWithinRange(e,t,s){if(!a(e)||!a(t))throw new Error("Invalid verse key");return this.fetcher.fetch("/content/api/v4/hadith_references/count_within_range",{...s,from:e,to:t})}};var d=class{constructor(e){this.fetcher=e;}async findAll(){let{juzs:e}=await this.fetcher.fetch("/content/api/v4/juzs");return e}};var m=class{constructor(e){this.fetcher=e;}async findAllRecitations(e){let{recitations:t}=await this.fetcher.fetch("/content/api/v4/resources/recitations",e);return t}async findAllTranslations(e){let{translations:t}=await this.fetcher.fetch("/content/api/v4/resources/translations",e);return t}async findAllTafsirs(e){let{tafsirs:t}=await this.fetcher.fetch("/content/api/v4/resources/tafsirs",e);return t}async findAllLanguages(e){let{languages:t}=await this.fetcher.fetch("/content/api/v4/resources/languages",e);return t}async findRecitationInfo(e,t){let{recitationInfo:s}=await this.fetcher.fetch(`/content/api/v4/resources/recitations/${e}/info`,t);return s}async findTranslationInfo(e,t){let{translationInfo:s}=await this.fetcher.fetch(`/content/api/v4/resources/translations/${e}/info`,t);return s}async findTafsirInfo(e,t){let{tafsirInfo:s}=await this.fetcher.fetch(`/content/api/v4/resources/tafsirs/${e}/info`,t);return s}async findAllChapterInfos(e){let{chapterInfos:t}=await this.fetcher.fetch("/content/api/v4/resources/chapter_infos",e);return t}async findAllChapterReciters(e){let{reciters:t}=await this.fetcher.fetch("/content/api/v4/resources/chapter_reciters",e);return t}async findAllRecitationStyles(e){let{recitationStyles:t}=await this.fetcher.fetch("/content/api/v4/resources/recitation_styles",e);return t}async findVerseMedia(e){let{verseMedia:t}=await this.fetcher.fetch("/content/api/v4/resources/verse_media",e);return t}async sync(e){return this.fetcher.fetch("/content/api/v4/resources/sync",e)}async findSnapshot(e,t,s){return this.fetcher.fetch(`/content/api/v4/resources/snapshots/${e}/${t}`,s)}};var y=class{constructor(e){this.fetcher=e;}async search(e,t){return this.fetcher.fetch("/v1/search",{query:e,size:30,...t})}};var R=class{constructor(e){this.fetcher=e;}async findByKey(e,t){if(!a(e))throw new Error("Invalid verse key");let{verse:s}=await this.fetcher.fetch(`/content/api/v4/verses/by_key/${e}`,{words:false,...t});return s}async findByRange(e,t,s){if(!a(e)||!a(t))throw new Error("Invalid verse key");let{verses:i}=await this.fetcher.fetch("/content/api/v4/verses/by_range",{words:false,...s,from:e,to:t});return i}async findByChapter(e,t){if(!c(e))throw new Error("Invalid chapter id");let{verses:s}=await this.fetcher.fetch(`/content/api/v4/verses/by_chapter/${e}`,{words:false,...t});return s}async findByPage(e,t){if(!C(e))throw new Error("Invalid page number");let{verses:s}=await this.fetcher.fetch(`/content/api/v4/verses/by_page/${e}`,{words:false,...t});return s}async findByJuz(e,t){if(!I(e))throw new Error("Invalid juz");let{verses:s}=await this.fetcher.fetch(`/content/api/v4/verses/by_juz/${e}`,{words:false,...t});return s}async findByHizb(e,t){if(!w(e))throw new Error("Invalid hizb");let{verses:s}=await this.fetcher.fetch(`/content/api/v4/verses/by_hizb/${e}`,{words:false,...t});return s}async findByRub(e,t){if(!v(e))throw new Error("Invalid rub");let{verses:s}=await this.fetcher.fetch(`/content/api/v4/verses/by_rub/${e}`,{words:false,...t});return s}async findRandom(e){let{verse:t}=await this.fetcher.fetch("/content/api/v4/verses/random",{words:false,...e});return t}};var {camelizeKeys:D}=G__default.default,J="content search",P=class{constructor(e){this.config=e;}cachedToken=null;updateConfig(e){this.config=e;}getFetch(){let e=this.config.fetch??globalThis.fetch;if(typeof e!="function")throw new Error("No fetch function available. Please provide a fetch implementation or ensure global fetch is available.");return e}clearCachedToken(){this.cachedToken=null;}async fetch(e,t){let s=await this.getAccessToken(),i=await this.getFetch()(this.makeUrl(e,t),{headers:{"Content-Type":"application/json","x-auth-token":s,"x-client-id":this.config.clientId}});if(!i.ok||i.status>=400)throw new Error(`${i.status} ${i.statusText}`);let o=await i.json();return D(o)}makeUrl(e,t){return `${this.config.contentBaseUrl}/${N(e)}${_({...this.config.defaults,...t})}`}async getAccessToken(){if(this.cachedToken&&this.cachedToken.expiresAt>Date.now()+3e4)return this.cachedToken.value;let e=new URLSearchParams({grant_type:"client_credentials",scope:J}).toString(),t=await g(()=>this.getFetch()(`${this.config.authBaseUrl}/oauth2/token`,{body:e,headers:{Accept:"application/json",Authorization:`Basic ${T(this.config.clientId,this.config.clientSecret)}`,"Content-Type":"application/x-www-form-urlencoded"},method:"POST"}),{retries:3});if(!t.ok)throw new Error(`Token request failed: ${t.statusText}`);let s=await t.json();return this.cachedToken={expiresAt:Date.now()+s.expires_in*1e3,value:s.access_token},this.cachedToken.value}},x=class{config;fetcher;chapters;answers;verses;juzs;audio;hadithReferences;resources;search;constructor(e){this.config={authBaseUrl:B.oauth2,contentBaseUrl:S,...e,defaults:{language:"ar",...e.defaults}},this.fetcher=new P(this.config),this.fetcher.getFetch(),this.answers=new h(this.fetcher),this.chapters=new u(this.fetcher),this.verses=new R(this.fetcher),this.juzs=new d(this.fetcher),this.audio=new f(this.fetcher),this.hadithReferences=new l(this.fetcher),this.resources=new m(this.fetcher),this.search=new y(this.fetcher);}getConfig(){return {...this.config}}updateConfig(e){this.config={...this.config,...e,defaults:{...this.config.defaults,...e.defaults}},this.fetcher.updateConfig(this.config);}clearCachedToken(){this.fetcher.clearCachedToken();}};
2
- exports.CharType=z;exports.Language=H;exports.QuranClient=x;exports.QuranFont=Q;exports.SearchMode=$;exports.SearchNavigationType=K;exports.isValidChapterId=c;exports.isValidHizb=w;exports.isValidJuz=I;exports.isValidQuranPage=C;exports.isValidRub=v;exports.isValidVerseKey=a;//# sourceMappingURL=index.min.js.map
1
+ 'use strict';var ke=require('humps');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var ke__default=/*#__PURE__*/_interopDefault(ke);var re=(r,e)=>{let t=`${r}:${e}`;if(typeof Buffer<"u")return Buffer.from(t).toString("base64");if(typeof globalThis.btoa=="function")return globalThis.btoa(t);throw new Error("No base64 encoder available for HTTP basic auth.")};var ne=async(r,e={retries:3})=>{let t;for(let n=0;n<=e.retries;n++)try{return await r()}catch(i){if(t=i,n===e.retries)throw t;await new Promise(c=>setTimeout(c,Math.pow(2,n)*1e3));}throw t};var oe="https://apis.quran.foundation",se={oauth2:"https://oauth2.quran.foundation"};var{decamelize:K}=ke__default.default;var pe=r=>r.startsWith("/")?r.slice(1):r;var ie=["wordFields","translationFields","fields"],ae=new Set([...ie,...ie.map(r=>K(r))]),Ve=new Set(["navigationalResultsNumber","pageSize","versesResultsNumber"]),ce=(r,e={})=>{if(!r)return "";let t=new URLSearchParams;for(let[n,i]of Object.entries(r)){if(i===void 0)continue;let c=e.preserveCase||Ve.has(n)?n:K(n);if(ae.has(n)||ae.has(c)){let h=Object.entries(i).filter(([,w])=>w).map(([w])=>K(w));h.length>0&&t.set(c,h.join(","));continue}typeof i=="string"?t.set(c,i):typeof i=="number"||typeof i=="boolean"?t.set(c,i.toString()):Array.isArray(i)&&t.set(c,i.join(","));}return t.size===0?"":`?${t.toString()}`};var Oe=(c=>(c.Word="word",c.End="end",c.Pause="pause",c.Sajdah="sajdah",c.RubElHizb="rub-el-hizb",c))(Oe||{});var Be=(y=>(y.SURAH="surah",y.JUZ="juz",y.HIZB="hizb",y.AYAH="ayah",y.RUB_EL_HIZB="rub_el_hizb",y.SEARCH_PAGE="search_page",y.PAGE="page",y.RANGE="range",y.QURAN_RANGE="quran_range",y))(Be||{});var Ne=(t=>(t.Advanced="advanced",t.Quick="quick",t))(Ne||{});var ue=(s=>(s.ARABIC="ar",s.ENGLISH="en",s.URDU="ur",s.BENGALI="bn",s.TURKISH="tr",s.SPANISH="es",s.GERMAN="de",s.BOSNIAN="bs",s.RUSSIAN="ru",s.ALBANIAN_AL="al",s.FRENCH="fr",s.DUTCH="nl",s.TAMIL="ta",s.TAJIK="tg",s.INDONESIAN="id",s.UZBEK="uz",s.VIETNAMESE="vi",s.CHINESE="zh",s.ITALIAN="it",s.JAPANESE="ja",s.MALAYALAM="ml",s.AMHARIC="am",s.KAZAKH="kk",s.PORTUGUESE="pt",s.TAGALOG="tl",s.THAI="th",s.KOREAN="ko",s.HINDI="hi",s.KURDISH="ku",s.HAUSA="ha",s.AZERI="az",s.SWAHILI="sw",s.PERSIAN="fa",s.SERBIAN="sr",s.MARANAO="mrn",s.AMAZIGH="zgh",s.ASSAMESE="as",s.BULGARIAN="bg",s.CHECHEN="ce",s.CZECH="cs",s.DIVEHI="dv",s.FINNISH="fi",s.GUJAARATI="gu",s.HEBREW="he",s.GEORGIAN="ka",s.CENTRAL_KHMER="km",s.GANDA="lg",s.MARATHI="mr",s.YORUBA="yo",s.MALAY="ms",s.NEPALI="ne",s.SWEDISH="sv",s.TELUGU="te",s.TATAR="tt",s.UYGHUR="ug",s.UKRAINIAN="uk",s.NORWEGIAN="no",s.OROMO="om",s.POLISH="pl",s.PASHTO="ps",s.ROMANIAN="ro",s.SINDHI="sd",s.NORTHERN_SAMI="se",s.SINHALA="si",s.SOMALI="so",s.ALBANIAN_SQ="sq",s))(ue||{}),He=(n=>(n.MadaniV1="code_v1",n.MadaniV2="code_v2",n.Uthmani="text_uthmani",n))(He||{});var S=r=>{let e=typeof r=="number"?r:Number(r);return !(!e||e<=0||e>114)};var $=r=>{let e=typeof r=="number"?r:Number(r);return !(!e||e<=0||e>30)};var j=r=>{let e=typeof r=="number"?r:Number(r);return !(!e||e<=0||e>240)};var q=r=>{let e=typeof r=="number"?r:Number(r);return !(!e||e<=0||e>60)};var W=r=>{let e=typeof r=="number"?r:Number(r);return !(!e||e<=0||e>604)};var de={1:7,2:286,3:200,4:176,5:120,6:165,7:206,8:75,9:129,10:109,11:123,12:111,13:43,14:52,15:99,16:128,17:111,18:110,19:98,20:135,21:112,22:78,23:118,24:64,25:77,26:227,27:93,28:88,29:69,30:60,31:34,32:30,33:73,34:54,35:45,36:83,37:182,38:88,39:75,40:85,41:54,42:53,43:89,44:59,45:37,46:35,47:38,48:29,49:18,50:45,51:60,52:49,53:62,54:55,55:78,56:96,57:29,58:22,59:24,60:13,61:14,62:11,63:11,64:18,65:12,66:12,67:30,68:52,69:52,70:44,71:28,72:28,73:20,74:56,75:40,76:31,77:50,78:40,79:46,80:42,81:29,82:19,83:36,84:25,85:22,86:17,87:19,88:26,89:30,90:20,91:15,92:21,93:11,94:8,95:8,96:19,97:5,98:8,99:8,100:11,101:11,102:8,103:3,104:9,105:5,106:4,107:7,108:3,109:6,110:3,111:5,112:4,113:5,114:6};var m=r=>{let[e,t]=r.trim().split(":");if(!e||!t||!S(e))return false;let n=Number(t),i=de[e];return !(!n||n<=0||n>i)};var Me=r=>Object.fromEntries(Object.entries(r).map(([e,t])=>t.types?[e,{...t,types:Object.fromEntries(Object.entries(t.types).map(([n,i])=>[n.toUpperCase(),i]))}]:[e,t])),V=class{constructor(e){this.fetcher=e;}async findByAyah(e,t){if(!m(e))throw new Error("Invalid verse key");return this.fetcher.fetch(`/content/api/v4/answers/by_ayah/${e}`,t)}async findByQuestionId(e){return this.fetcher.fetch(`/content/api/v4/answers/${e}`)}async countWithinRange(e,t,n){if(!m(e)||!m(t))throw new Error("Invalid verse key");let i=await this.fetcher.fetch("/content/api/v4/answers/count_within_range",{...n,from:e,to:t});return Me(i)}};var Ue="https://verses.quran.com";function le(r){return r.map(e=>{let t=e.url.startsWith("http://")||e.url.startsWith("https://")?e.url:`${Ue}/${e.url.replace(/^\/+/,"")}`;return {...e,audioUrl:t}})}var O=class{constructor(e){this.fetcher=e;}async findAllChapterRecitations(e,t){let{audioFiles:n}=await this.fetcher.fetch(`/content/api/v4/chapter_recitations/${e}`,t);return n}async findChapterRecitationById(e,t,n){if(!S(t))throw new Error("Invalid chapter id");let{audioFile:i}=await this.fetcher.fetch(`/content/api/v4/chapter_recitations/${e}/${t}`,n);return i}async findVerseRecitationsByChapter(e,t,n){if(!S(e))throw new Error("Invalid chapter id");let i=await this.fetcher.fetch(`/content/api/v4/recitations/${t}/by_chapter/${e}`,n);return {...i,audioFiles:le(i.audioFiles)}}async findVerseRecitationsByKey(e,t,n){if(!m(e))throw new Error("Invalid verse key");let i=await this.fetcher.fetch(`/content/api/v4/recitations/${t}/by_ayah/${e}`,n);return {...i,audioFiles:le(i.audioFiles)}}};var B=class{constructor(e){this.fetcher=e;}async findAll(e){let{chapters:t}=await this.fetcher.fetch("/content/api/v4/chapters",e);return t}async findById(e,t){if(!S(e))throw new Error("Invalid chapter id");let{chapter:n}=await this.fetcher.fetch(`/content/api/v4/chapters/${e}`,t);return n}async findInfoById(e,t){let{chapterInfo:n}=await this.findInfoResponseById(e,t);return n}async findInfoResponseById(e,t){if(!S(e))throw new Error("Invalid chapter id");return this.fetcher.fetch(`/content/api/v4/chapters/${e}/info`,t)}};var N=class{constructor(e){this.fetcher=e;}async findByAyah(e,t){if(!m(e))throw new Error("Invalid verse key");return this.fetcher.fetch(`/content/api/v4/hadith_references/by_ayah/${e}`,t)}async findHadithsByAyah(e,t){if(!m(e))throw new Error("Invalid verse key");return this.fetcher.fetch(`/content/api/v4/hadith_references/by_ayah/${e}/hadiths`,t)}async countWithinRange(e,t,n){if(!m(e)||!m(t))throw new Error("Invalid verse key");return this.fetcher.fetch("/content/api/v4/hadith_references/count_within_range",{...n,from:e,to:t})}};var H=class{constructor(e){this.fetcher=e;}async findAll(){let{juzs:e}=await this.fetcher.fetch("/content/api/v4/juzs");return e}};var M=class{constructor(e){this.fetcher=e;}async findAllRecitations(e){let{recitations:t}=await this.fetcher.fetch("/content/api/v4/resources/recitations",e);return t}async findAllTranslations(e){let{translations:t}=await this.fetcher.fetch("/content/api/v4/resources/translations",e);return t}async findAllTafsirs(e){let{tafsirs:t}=await this.fetcher.fetch("/content/api/v4/resources/tafsirs",e);return t}async findAllLanguages(e){let{languages:t}=await this.fetcher.fetch("/content/api/v4/resources/languages",e);return t}async findRecitationInfo(e,t){let{recitationInfo:n}=await this.fetcher.fetch(`/content/api/v4/resources/recitations/${e}/info`,t);return n}async findTranslationInfo(e,t){let{translationInfo:n}=await this.fetcher.fetch(`/content/api/v4/resources/translations/${e}/info`,t);return n}async findTafsirInfo(e,t){let{tafsirInfo:n}=await this.fetcher.fetch(`/content/api/v4/resources/tafsirs/${e}/info`,t);return n}async findAllChapterInfos(e){let{chapterInfos:t}=await this.fetcher.fetch("/content/api/v4/resources/chapter_infos",e);return t}async findAllChapterReciters(e){let{reciters:t}=await this.fetcher.fetch("/content/api/v4/resources/chapter_reciters",e);return t}async findAllRecitationStyles(e){let{recitationStyles:t}=await this.fetcher.fetch("/content/api/v4/resources/recitation_styles",e);return t}async findVerseMedia(e){let{verseMedia:t}=await this.fetcher.fetch("/content/api/v4/resources/verse_media",e);return t}async sync(e){return this.fetcher.fetch("/content/api/v4/resources/sync",e)}async findSnapshot(e,t,n){return this.fetcher.fetch(`/content/api/v4/resources/snapshots/${e}/${t}`,n)}};var U=class{constructor(e){this.fetcher=e;}async search(e,t){return this.fetcher.fetch("/v1/search",{query:e,size:30,...t})}};var F=class{constructor(e){this.fetcher=e;}async findByKey(e,t){if(!m(e))throw new Error("Invalid verse key");let{verse:n}=await this.fetcher.fetch(`/content/api/v4/verses/by_key/${e}`,{words:false,...t});return n}async findByRange(e,t,n){if(!m(e)||!m(t))throw new Error("Invalid verse key");let{verses:i}=await this.fetcher.fetch("/content/api/v4/verses/by_range",{words:false,...n,from:e,to:t});return i}async findByChapter(e,t){if(!S(e))throw new Error("Invalid chapter id");let{verses:n}=await this.fetcher.fetch(`/content/api/v4/verses/by_chapter/${e}`,{words:false,...t});return n}async findByPage(e,t){if(!W(e))throw new Error("Invalid page number");let{verses:n}=await this.fetcher.fetch(`/content/api/v4/verses/by_page/${e}`,{words:false,...t});return n}async findByJuz(e,t){if(!$(e))throw new Error("Invalid juz");let{verses:n}=await this.fetcher.fetch(`/content/api/v4/verses/by_juz/${e}`,{words:false,...t});return n}async findByHizb(e,t){if(!q(e))throw new Error("Invalid hizb");let{verses:n}=await this.fetcher.fetch(`/content/api/v4/verses/by_hizb/${e}`,{words:false,...t});return n}async findByRub(e,t){if(!j(e))throw new Error("Invalid rub");let{verses:n}=await this.fetcher.fetch(`/content/api/v4/verses/by_rub/${e}`,{words:false,...t});return n}async findRandom(e){let{verse:t}=await this.fetcher.fetch("/content/api/v4/verses/random",{words:false,...e});return t}};var {camelizeKeys:Ge}=ke__default.default,De="content search",J=class{constructor(e){this.config=e;}cachedToken=null;updateConfig(e){this.config=e;}getFetch(){let e=this.config.fetch??globalThis.fetch;if(typeof e!="function")throw new Error("No fetch function available. Please provide a fetch implementation or ensure global fetch is available.");return e}clearCachedToken(){this.cachedToken=null;}async fetch(e,t){let n=await this.getAccessToken(),i=await this.getFetch()(this.makeUrl(e,t),{headers:{"Content-Type":"application/json","x-auth-token":n,"x-client-id":this.config.clientId}});if(!i.ok||i.status>=400)throw new Error(`${i.status} ${i.statusText}`);let c=await i.json();return Ge(c)}makeUrl(e,t){return `${this.config.contentBaseUrl}/${pe(e)}${ce({...this.config.defaults,...t})}`}async getAccessToken(){if(this.cachedToken&&this.cachedToken.expiresAt>Date.now()+3e4)return this.cachedToken.value;let e=new URLSearchParams({grant_type:"client_credentials",scope:De}).toString(),t=await ne(()=>this.getFetch()(`${this.config.authBaseUrl}/oauth2/token`,{body:e,headers:{Accept:"application/json",Authorization:`Basic ${re(this.config.clientId,this.config.clientSecret)}`,"Content-Type":"application/x-www-form-urlencoded"},method:"POST"}),{retries:3});if(!t.ok)throw new Error(`Token request failed: ${t.statusText}`);let n=await t.json();return this.cachedToken={expiresAt:Date.now()+n.expires_in*1e3,value:n.access_token},this.cachedToken.value}},Z=class{config;fetcher;chapters;answers;verses;juzs;audio;hadithReferences;resources;search;constructor(e){this.config={authBaseUrl:se.oauth2,contentBaseUrl:oe,...e,defaults:{language:"ar",...e.defaults}},this.fetcher=new J(this.config),this.fetcher.getFetch(),this.answers=new V(this.fetcher),this.chapters=new B(this.fetcher),this.verses=new F(this.fetcher),this.juzs=new H(this.fetcher),this.audio=new O(this.fetcher),this.hadithReferences=new N(this.fetcher),this.resources=new M(this.fetcher),this.search=new U(this.fetcher);}getConfig(){return {...this.config}}updateConfig(e){this.config={...this.config,...e,defaults:{...this.config.defaults,...e.defaults}},this.fetcher.updateConfig(this.config);}clearCachedToken(){this.fetcher.clearCachedToken();}};var Qe=async r=>{try{let e=await r.text();if(!e)return;if(r.headers.get("content-type")?.toLowerCase().includes("json"))try{return JSON.parse(e)}catch{return e}return e}catch{return}},fe=class he extends Error{headers;payload;status;constructor(e,t){super(`${e.status} ${e.statusText}`),this.name="QuranHttpError",this.headers=new Headers(e.headers),this.payload=t,this.status=e.status;}static async fromResponse(e){return new he(e,await Qe(e))}};Object.defineProperty(fe,"name",{configurable:true,value:"QuranHttpError"});var me=Symbol.for("@quranjs/api/QuranHttpError/v1"),ye=globalThis,G=ye[me]??fe;ye[me]=G;var ze=new Set(["app_state_data_deleted","app_state_disabled","app_state_policy_changed","app_state_unavailable","bootstrap_required","collection_not_allowed","document_not_found","document_too_large","idempotency_key_reused","internal_server_error","insufficient_scope","invalid_collection","invalid_etag","invalid_idempotency_key","invalid_json","invalid_key","invalid_precondition","invalid_sync_token","invalid_token","namespace_resolution_unavailable","payload_too_large","precondition_failed","precondition_required","quota_exceeded","rate_limit_exceeded","sync_token_expired"]),_=r=>{if(!(r instanceof G))return;let e=r.payload;if(typeof e!="object"||e===null)return;let t=e.details;if(typeof t!="object"||t===null)return;let n=t.error,i=typeof n=="string"?n:typeof n=="object"&&n!==null?n.code:void 0;return typeof i=="string"&&ze.has(i)?i:void 0};function Ke(r,e){let t=_(r);return t!==void 0&&(e===void 0||e===t)}var g=class extends Error{code;constructor(e){super(`App State reconciliation protocol error: ${e}`),this.name="AppStateProtocolError",this.code=e;}},R=r=>JSON.parse(JSON.stringify(r)),b=r=>{if(typeof r!="object"||r===null||Object.isFrozen(r))return r;for(let e of Object.values(r))b(e);return Object.freeze(r)},D=r=>{if(Array.isArray(r))return `[${r.map(D).join(",")}]`;if(typeof r=="object"&&r!==null){let e=r;return `{${Object.keys(e).sort().map(t=>`${JSON.stringify(t)}:${D(e[t])}`).join(",")}}`}return JSON.stringify(r)},I=(r,e)=>`${r}/${encodeURIComponent(e)}`,$e=()=>({bootstrapCursor:null,localRevision:0,pendingMutations:[],shadow:{},stagingBootstrap:null,syncToken:null}),je=r=>{if(typeof r=="object"&&r!==null&&"then"in r&&typeof r.then=="function")throw new TypeError("App State store reducers must be synchronous.")},qe=(r={})=>{let e=new Map(Object.entries(r).map(([n,i])=>[n,b(R(i))])),t=new Map;return {transaction:(n,i)=>{if(!n)return Promise.reject(new TypeError("App State transactions require an account ID."));let h=(t.get(n)??Promise.resolve()).then(()=>{let w=e.get(n)??$e(),v=R(w),y=i(v);return je(y),b(v),e.set(n,v),y});return t.set(n,h.then(()=>{},()=>{})),h}}},Ae=(r,e)=>{let t=I(e.collection,e.key),n=r[t];if(!(n&&e.version<n.version)){if(n&&e.version===n.version){if(D(n)!==D(e))throw new g("same_version_conflict");return}r[t]=R(e);}},C=(r,e,t,n="shadow")=>{let i=n==="shadow"?r.shadow:r.stagingBootstrap??{},c=R(i);for(let h of e)Ae(c,h);n==="shadow"?r.shadow=c:r.stagingBootstrap=c,r.syncToken=t;},Re=(r,e,t)=>{let n=R(r.stagingBootstrap??{});for(let i of e)Ae(n,i);r.stagingBootstrap=n,r.bootstrapCursor=t;},Se=r=>{r.shadow=R(r.stagingBootstrap??{}),r.stagingBootstrap=null,r.bootstrapCursor=null;},ge=(r,e,t)=>{let n=r.shadow[I(e,t)];return n?.operation==="upsert"?{ifMatch:n.etag}:{ifNoneMatch:"*"}},we=(r,e,t,n,i)=>{let c=r.localRevision+1,h={...ge(r,e,t),body:R(n),collection:e,idempotencyKey:i,key:t,localRevision:c,method:"PUT"};return b(h),r.pendingMutations=[...r.pendingMutations,h],r.localRevision=c,c},be=(r,e,t,n)=>{let i=r.localRevision+1,c={...ge(r,e,t),collection:e,idempotencyKey:n,key:t,localRevision:i,method:"DELETE"};return b(c),r.pendingMutations=[...r.pendingMutations,c],r.localRevision=i,i},We=r=>{let e={};for(let[t,n]of Object.entries(r))n.operation!=="delete"&&(e[t]={collection:n.collection,etag:n.etag,key:n.key,pending:false,schemaVersion:n.schemaVersion,updatedAt:n.updatedAt,value:R(n.value),version:n.version});return e},ve=r=>{let e=R(r),t=We(e.shadow);for(let n of e.pendingMutations){let i=I(n.collection,n.key);if(n.method==="DELETE"){delete t[i];continue}let c=t[i];t[i]={collection:n.collection,etag:c?.etag??null,key:n.key,pending:true,schemaVersion:n.body.schemaVersion,updatedAt:c?.updatedAt??null,value:R(n.body.value),version:c?.version??null};}return b({...e,visible:t})},Pe=r=>b(R(r.pendingMutations)),Y=(r,e)=>{r.pendingMutations=r.pendingMutations.filter(t=>t.localRevision!==e);},_e=(r,e)=>{r.pendingMutations=r.pendingMutations.map(t=>t.localRevision===e.localRevision?b(R(e)):t);};var Je=100,Ze=3,Ye=3,Xe=()=>{let r=globalThis.crypto;if(typeof r?.randomUUID!="function")throw new Error("App State reconciliation requires createIdempotencyKey when crypto.randomUUID is unavailable.");return r.randomUUID()},Te=r=>r.ifMatch!==void 0?{idempotencyKey:r.idempotencyKey,ifMatch:r.ifMatch}:r.ifNoneMatch!==void 0?{idempotencyKey:r.idempotencyKey,ifNoneMatch:r.ifNoneMatch}:{idempotencyKey:r.idempotencyKey},Le=r=>r.map(e=>({...e,operation:"upsert"})),X=r=>{let e=_(r);return e==="bootstrap_required"||e==="sync_token_expired"},et=(r,e)=>{if(!Number.isInteger(r)||r<=0)throw new TypeError(`${e} must be a positive integer.`);return r},tt=({accountId:r,createIdempotencyKey:e=Xe,maxRebaseAttempts:t=Ye,pageSize:n=Je,store:i,transport:c})=>{if(!r)throw new TypeError("App State reconciliation requires an account ID.");if(et(n,"pageSize"),!Number.isInteger(t)||t<0)throw new TypeError("maxRebaseAttempts must be a non-negative integer.");let h=r,w=c,v=0,y=Promise.resolve(),f=o=>o.accountId===h&&o.generation===v,Q=()=>({accountId:h,generation:v,transport:w}),P=async(o,a)=>f(o)?i.transaction(o.accountId,p=>f(o)?(a(p),true):false):false,x=o=>i.transaction(o.accountId,a=>({bootstrapCursor:a.bootstrapCursor,hasStaging:a.stagingBootstrap!==null,syncToken:a.syncToken})),L=o=>P(o,a=>{a.bootstrapCursor=null,a.stagingBootstrap={},a.syncToken=null;}),k=async(o,a)=>{let p=0;if(!(a&&!await L(o)))for(;f(o);){for(;f(o);){let u=await x(o);if(!f(o))return;if(u.hasStaging&&u.bootstrapCursor===null&&u.syncToken!==null)break;let l;try{l=await o.transport.bootstrap({...u.bootstrapCursor===null?{}:{cursor:u.bootstrapCursor},limit:n});}catch(E){if(!f(o))return;throw E}if(!f(o))return;let d=l.data;if(d.hasMore&&d.nextCursor===null)throw new g("bootstrap_cursor_missing");if(!d.hasMore&&d.nextSyncToken===null)throw new g("bootstrap_sync_token_missing");if(!await P(o,E=>{Re(E,Le(d.items),d.hasMore?d.nextCursor:null),d.hasMore||(E.syncToken=d.nextSyncToken);}))return;if(!d.hasMore)break}for(;f(o);){let{syncToken:u}=await x(o);if(!f(o))return;if(u===null)throw new g("bootstrap_sync_token_missing");let l;try{l=await o.transport.getChanges(u,{limit:n});}catch(A){if(!f(o))return;if(!X(A))throw A;if(!await L(o))return;if(p>=Ze)throw A;p+=1;break}if(!f(o)||!await P(o,A=>{C(A,l.data.changes,l.data.nextSyncToken,"stagingBootstrap"),l.data.hasMore||Se(A);})||!l.data.hasMore)return}}},ee=async o=>{let a=await x(o);if(f(o)){if(a.syncToken===null||a.hasStaging){await k(o,false);return}for(;f(o);){let{syncToken:p}=await x(o);if(!f(o))return;if(p===null){await k(o,false);return}try{let u=await o.transport.getChanges(p,{limit:n});if(!f(o)||!await P(o,d=>{C(d,u.data.changes,u.data.nextSyncToken);})||!u.data.hasMore)return}catch(u){if(!f(o))return;if(!X(u))throw u;await k(o,true);return}}}},Ee=async(o,a,p)=>{let u=p.etag;if(u===null)throw new g("put_response_etag_missing");await P(o,l=>{if(l.syncToken!==null){let d={...p.data,etag:u,operation:"upsert",value:a.body.value};C(l,[d],l.syncToken);}Y(l,a.localRevision);});},z=async(o,a)=>{await P(o,p=>{let u=I(a.collection,a.key),l=p.shadow[u];l&&(p.shadow[u]={...l,operation:"delete",value:null}),Y(p,a.localRevision);});},Ie=async(o,a)=>{let p;try{p=await o.transport.getDocument(a.collection,a.key);}catch(d){if(_(d)!=="document_not_found")throw d;p=null;}if(!f(o))return null;if(p!==null&&p.etag===null)throw new Error("App State conflict refresh did not return an ETag.");if(p===null&&a.method==="DELETE")return await z(o,a),null;let u=a.method==="PUT"?{body:a.body,collection:a.collection,idempotencyKey:e(),...p===null?{ifNoneMatch:"*"}:{ifMatch:p.etag},key:a.key,localRevision:a.localRevision,method:"PUT"}:{collection:a.collection,idempotencyKey:e(),ifMatch:p.etag,key:a.key,localRevision:a.localRevision,method:"DELETE"};return await P(o,d=>{p!==null&&d.syncToken!==null&&C(d,[{...p.data,etag:p.etag,operation:"upsert"}],d.syncToken),_e(d,u);})?u:null},Ce=async(o,a)=>{let p=a,u=0;for(;f(o);)try{if(p.method==="PUT"){let l=await o.transport.putDocument(p.collection,p.key,p.body,Te(p));if(!f(o))return;await Ee(o,p,l);}else {if(await o.transport.deleteDocument(p.collection,p.key,Te(p)),!f(o))return;await z(o,p);}return}catch(l){if(!f(o))return;let d=_(l);if(p.method==="DELETE"&&d==="document_not_found"){await z(o,p);return}if(d!=="precondition_failed"||u>=t)throw l;u+=1;let A=await Ie(o,p);if(A===null)return;p=A;}},te=async o=>{let a=await i.transaction(o.accountId,Pe);for(let p of a){if(!f(o))return;await Ce(o,p);}},xe=async o=>{if(await ee(o),!!f(o)){try{await te(o);}catch(a){if(!X(a))throw a;if(await k(o,true),!f(o))return;await te(o);}f(o)&&await ee(o);}},T=o=>i.transaction(o,ve);return {deleteDocument:async(o,a)=>{let p=Q(),u=e();return await i.transaction(p.accountId,l=>{be(l,o,a,u);}),T(h)},getState:()=>T(h),putDocument:async(o,a,p)=>{let u=Q(),l=e(),d=JSON.parse(JSON.stringify(p));return await i.transaction(u.accountId,A=>{we(A,o,a,d,l);}),T(h)},reconcile:()=>{let o=Q(),a=y.then(()=>xe(o));return y=a.then(()=>{},()=>{}),a.then(()=>T(h))},switchAccount:(o,a)=>o?(v+=1,h=o,w=a,T(o)):Promise.reject(new TypeError("App State reconciliation requires an account ID."))}};
2
+ exports.AppStateProtocolError=g;exports.CharType=Oe;exports.Language=ue;exports.QuranClient=Z;exports.QuranFont=He;exports.QuranHttpError=G;exports.SearchMode=Ne;exports.SearchNavigationType=Be;exports.createAppStateMemoryStore=qe;exports.createAppStateReconciler=tt;exports.getAppStateErrorCode=_;exports.isAppStateHttpError=Ke;exports.isValidChapterId=S;exports.isValidHizb=q;exports.isValidJuz=$;exports.isValidQuranPage=W;exports.isValidRub=j;exports.isValidVerseKey=m;//# sourceMappingURL=index.min.js.map
3
3
  //# sourceMappingURL=index.min.js.map