@quranjs/api 3.8.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.
@@ -1,3 +1,3 @@
1
- import be from'humps';var Y={analytics:{v1:{operations:{submitAnalyticsEvents:{auth:"app",method:"post",path:"/v1/events:batch"}},service:"analytics",version:"v1"}},auth:{v1:{operations:{getV1Collections:{auth:"user",method:"get",path:"/v1/collections"},postV1Collections:{auth:"user",method:"post",path:"/v1/collections"},postV1CollectionsByCollectionIdBookmarks:{auth:"user",method:"post",path:"/v1/collections/{collectionId}/bookmarks"},deleteV1CollectionsByCollectionIdBookmarks:{auth:"user",method:"delete",path:"/v1/collections/{collectionId}/bookmarks"},getV1CollectionsByCollectionId:{auth:"user",method:"get",path:"/v1/collections/{collectionId}"},postV1CollectionsByCollectionId:{auth:"user",method:"post",path:"/v1/collections/{collectionId}"},deleteV1CollectionsByCollectionId:{auth:"user",method:"delete",path:"/v1/collections/{collectionId}"},deleteV1CollectionsByCollectionIdBookmarksByBookmarkId:{auth:"user",method:"delete",path:"/v1/collections/{collectionId}/bookmarks/{bookmarkId}"},getV1CollectionsAll:{auth:"user",method:"get",path:"/v1/collections/all"},getV1Bookmarks:{auth:"user",method:"get",path:"/v1/bookmarks"},postV1Bookmarks:{auth:"user",method:"post",path:"/v1/bookmarks"},deleteV1BookmarksByBookmarkId:{auth:"user",method:"delete",path:"/v1/bookmarks/{bookmarkId}"},getV1BookmarksAyahsRange:{auth:"user",method:"get",path:"/v1/bookmarks/ayahs-range"},getV1BookmarksBookmark:{auth:"user",method:"get",path:"/v1/bookmarks/bookmark"},getV1BookmarksCollections:{auth:"user",method:"get",path:"/v1/bookmarks/collections"},getV1Preferences:{auth:"user",method:"get",path:"/v1/preferences"},postV1Preferences:{auth:"user",method:"post",path:"/v1/preferences"},postV1PreferencesBulk:{auth:"user",method:"post",path:"/v1/preferences/bulk"},getV1ReadingSessions:{auth:"user",method:"get",path:"/v1/reading-sessions"},postV1ReadingSessions:{auth:"user",method:"post",path:"/v1/reading-sessions"},getV1GoalsGetTodaysPlan:{auth:"user",method:"get",path:"/v1/goals/get-todays-plan"},putV1GoalsById:{auth:"user",method:"put",path:"/v1/goals/{id}"},deleteV1GoalsById:{auth:"user",method:"delete",path:"/v1/goals/{id}"},postV1Goals:{auth:"user",method:"post",path:"/v1/goals"},getV1GoalsEstimate:{auth:"user",method:"get",path:"/v1/goals/estimate"},getV1Streaks:{auth:"user",method:"get",path:"/v1/streaks"},getV1StreaksCurrentStreakDays:{auth:"user",method:"get",path:"/v1/streaks/current-streak-days"},getV1ActivityDays:{auth:"user",method:"get",path:"/v1/activity-days"},postV1ActivityDays:{auth:"user",method:"post",path:"/v1/activity-days"},getV1ActivityDaysEstimateReadingTime:{auth:"user",method:"get",path:"/v1/activity-days/estimate-reading-time"},getV1Notes:{auth:"user",method:"get",path:"/v1/notes"},postV1Notes:{auth:"user",method:"post",path:"/v1/notes"},getV1NotesByVerseByVerseKey:{auth:"user",method:"get",path:"/v1/notes/by-verse/{verseKey}"},getV1NotesByAttachedEntity:{auth:"user",method:"get",path:"/v1/notes/by-attached-entity"},getV1NotesCountWithinRange:{auth:"user",method:"get",path:"/v1/notes/count-within-range"},getV1NotesByRange:{auth:"user",method:"get",path:"/v1/notes/by-range"},getV1NotesByNoteId:{auth:"user",method:"get",path:"/v1/notes/{noteId}"},patchV1NotesByNoteId:{auth:"user",method:"patch",path:"/v1/notes/{noteId}"},deleteV1NotesByNoteId:{auth:"user",method:"delete",path:"/v1/notes/{noteId}"},postV1NotesByNoteIdPublish:{auth:"user",method:"post",path:"/v1/notes/{noteId}/publish"}},service:"auth",version:"v1"}},content:{v4:{operations:{audioReciterTimestamp:{auth:"app",method:"get",path:"/audio/reciters/{reciter_id}/timestamp"},audioReciterLookup:{auth:"app",method:"get",path:"/audio/reciters/{reciter_id}/lookup"},listChapters:{auth:"app",method:"get",path:"/chapters"},getChapter:{auth:"app",method:"get",path:"/chapters/{id}"},getChapterInfo:{auth:"app",method:"get",path:"/chapters/{id}/info"},hadithReferencesByAyah:{auth:"app",method:"get",path:"/hadith_references/by_ayah/{ayah_key}"},hadithsByAyah:{auth:"app",method:"get",path:"/hadith_references/by_ayah/{ayah_key}/hadiths"},hadithCountWithinRange:{auth:"app",method:"get",path:"/hadith_references/count_within_range"},listPages:{auth:"app",method:"get",path:"/pages"},getPagesLookup:{auth:"app",method:"get",path:"/pages/lookup"},getPagesPageNumber:{auth:"app",method:"get",path:"/pages/{page_number}"},versesByChapterNumber:{auth:"app",method:"get",path:"/verses/by_chapter/{chapter_number}"},versesByPageNumber:{auth:"app",method:"get",path:"/verses/by_page/{page_number}"},versesByJuzNumber:{auth:"app",method:"get",path:"/verses/by_juz/{juz_number}"},versesByHizbNumber:{auth:"app",method:"get",path:"/verses/by_hizb/{hizb_number}"},versesByRubElHizbNumber:{auth:"app",method:"get",path:"/verses/by_rub/{rub_el_hizb_number}"},versesByManzilNumber:{auth:"app",method:"get",path:"/verses/by_manzil/{manzil_number}"},versesByRukuNumber:{auth:"app",method:"get",path:"/verses/by_ruku/{ruku_number}"},versesByRange:{auth:"app",method:"get",path:"/verses/by_range"},versesByVerseKey:{auth:"app",method:"get",path:"/verses/by_key/{verse_key}"},randomVerse:{auth:"app",method:"get",path:"/verses/random"},listJuzs:{auth:"app",method:"get",path:"/juzs"},quranVersesByScript:{auth:"app",method:"get",path:"/quran/verses/{script}"},quranVersesIndopak:{auth:"app",method:"get",path:"/quran/verses/indopak"},quranVersesIndopakNastaleeq:{auth:"app",method:"get",path:"/quran/verses/indopak_nastaleeq"},quranVersesUthmaniTajweed:{auth:"app",method:"get",path:"/quran/verses/uthmani_tajweed"},quranVersesUthmani:{auth:"app",method:"get",path:"/quran/verses/uthmani"},quranVersesUthmaniSimple:{auth:"app",method:"get",path:"/quran/verses/uthmani_simple"},quranVersesImlaei:{auth:"app",method:"get",path:"/quran/verses/imlaei"},recitations:{auth:"app",method:"get",path:"/resources/recitations"},recitationAudioFiles:{auth:"app",method:"get",path:"/quran/recitations/{recitation_id}"},translation:{auth:"app",method:"get",path:"/quran/translations/{translation_id}"},chapterReciters:{auth:"app",method:"get",path:"/resources/chapter_reciters"},tafsir:{auth:"app",method:"get",path:"/quran/tafsirs/{tafsir_id}"},quranVersesCodeV1:{auth:"app",method:"get",path:"/quran/verses/code_v1"},quranVersesCodeV2:{auth:"app",method:"get",path:"/quran/verses/code_v2"},listSurahRecitation:{auth:"app",method:"get",path:"/recitations/{recitation_id}/by_chapter/{chapter_number}"},listJuzRecitation:{auth:"app",method:"get",path:"/recitations/{recitation_id}/by_juz/{juz_number}"},listPageRecitation:{auth:"app",method:"get",path:"/recitations/{recitation_id}/by_page/{page_number}"},listRubElHizbRecitation:{auth:"app",method:"get",path:"/recitations/{recitation_id}/by_rub/{rub_el_hizb_number}"},listHizbRecitation:{auth:"app",method:"get",path:"/recitations/{recitation_id}/by_hizb/{hizb_number}"},listAyahRecitation:{auth:"app",method:"get",path:"/recitations/{recitation_id}/by_ayah/{ayah_key}"},recitationInfo:{auth:"app",method:"get",path:"/resources/recitations/{recitation_id}/info"},translationInfo:{auth:"app",method:"get",path:"/resources/translations/{translation_id}/info"},translations:{auth:"app",method:"get",path:"/resources/translations"},tafsirs:{auth:"app",method:"get",path:"/resources/tafsirs"},tafsirInfo:{auth:"app",method:"get",path:"/resources/tafsirs/{tafsir_id}/info"},recitationStyles:{auth:"app",method:"get",path:"/resources/recitation_styles"},languages:{auth:"app",method:"get",path:"/resources/languages"},chapterInfo:{auth:"app",method:"get",path:"/resources/chapter_infos"},verseMedia:{auth:"app",method:"get",path:"/resources/verse_media"},listManzilRecitation:{auth:"app",method:"get",path:"/recitations/{recitation_id}/by_manzil/{manzil_number}"},listRukuRecitation:{auth:"app",method:"get",path:"/recitations/{recitation_id}/by_ruku/{ruku_number}"},listSurahTranslations:{auth:"app",method:"get",path:"/translations/{resource_id}/by_chapter/{chapter_number}"},listPageTranslations:{auth:"app",method:"get",path:"/translations/{resource_id}/by_page/{page_number}"},listJuzTranslations:{auth:"app",method:"get",path:"/translations/{resource_id}/by_juz/{juz_number}"},listRubElHizbTranslations:{auth:"app",method:"get",path:"/translations/{resource_id}/by_rub_el_hizb/{rub_el_hizb_number}"},listHizbTranslations:{auth:"app",method:"get",path:"/translations/{resource_id}/by_hizb/{hizb_number}"},listManzilTranslations:{auth:"app",method:"get",path:"/translations/{resource_id}/by_manzil/{manzil_number}"},listRukuTranslations:{auth:"app",method:"get",path:"/translations/{resource_id}/by_ruku/{ruku_number}"},listAyahTranslations:{auth:"app",method:"get",path:"/translations/{resource_id}/by_ayah/{ayah_key}"},listSurahTafsirs:{auth:"app",method:"get",path:"/tafsirs/{resource_id}/by_chapter/{chapter_number}"},listPageTafsirs:{auth:"app",method:"get",path:"/tafsirs/{resource_id}/by_page/{page_number}"},listJuzTafsirs:{auth:"app",method:"get",path:"/tafsirs/{resource_id}/by_juz/{juz_number}"},listRubElHizbTafsirs:{auth:"app",method:"get",path:"/tafsirs/{resource_id}/by_rub_el_hizb/{rub_el_hizb_number}"},listHizbTafsirs:{auth:"app",method:"get",path:"/tafsirs/{resource_id}/by_hizb/{hizb_number}"},listManzilTafsirs:{auth:"app",method:"get",path:"/tafsirs/{resource_id}/by_manzil/{manzil_number}"},listRukuTafsirs:{auth:"app",method:"get",path:"/tafsirs/{resource_id}/by_ruku/{ruku_number}"},listAyahTafsirs:{auth:"app",method:"get",path:"/tafsirs/{resource_id}/by_ayah/{ayah_key}"},getJuz:{auth:"app",method:"get",path:"/juzs/{id}"},listHizbs:{auth:"app",method:"get",path:"/hizbs"},getHizb:{auth:"app",method:"get",path:"/hizbs/{id}"},listRubElHizbs:{auth:"app",method:"get",path:"/rub_el_hizbs"},getRubElHizb:{auth:"app",method:"get",path:"/rub_el_hizbs/{id}"},listRukus:{auth:"app",method:"get",path:"/rukus"},getRuku:{auth:"app",method:"get",path:"/rukus/{id}"},listManzils:{auth:"app",method:"get",path:"/manzils"},getManzil:{auth:"app",method:"get",path:"/manzils/{id}"},getFootNote:{auth:"app",method:"get",path:"/foot_notes/{id}"},postsControllerFeed:{auth:"app",method:"get",path:"/quran-reflect/v1/posts/feed"},postsControllerFindOne:{auth:"app",method:"get",path:"/quran-reflect/v1/posts/{id}"},postsControllerGetUserPost:{auth:"app",method:"get",path:"/quran-reflect/v1/posts/user-posts/{id}"},postsControllerGetComments:{auth:"app",method:"get",path:"/quran-reflect/v1/posts/{id}/comments"},postsControllerGetAllComment:{auth:"app",method:"get",path:"/quran-reflect/v1/posts/{id}/all-comments"},chapterReciterAudioFiles:{auth:"app",method:"get",path:"/chapter_recitations/{reciter_id}"},chapterReciterAudioFile:{auth:"app",method:"get",path:"/chapter_recitations/{reciter_id}/{chapter_number}"},versesByRubElHizbNumberRubElHizb:{auth:"app",method:"get",path:"/verses/by_rub_el_hizb/{rub_el_hizb_number}"},listRubElHizbTranslationsRub:{auth:"app",method:"get",path:"/translations/{resource_id}/by_rub/{rub_el_hizb_number}"},listRubElHizbTafsirsRub:{auth:"app",method:"get",path:"/tafsirs/{resource_id}/by_rub/{rub_el_hizb_number}"},listRubElHizbRecitationRubElHizb:{auth:"app",method:"get",path:"/recitations/{recitation_id}/by_rub_el_hizb/{rub_el_hizb_number}"},listAyahAnswers:{auth:"app",method:"get",path:"/answers/by_ayah/{ayah_key}"},getAnswerById:{auth:"app",method:"get",path:"/answers/{question_id}"},countAnswersWithinRange:{auth:"app",method:"get",path:"/answers/count_within_range"},resourcesSync:{auth:"app",method:"get",path:"/resources/sync"},resourcesSnapshot:{auth:"app",method:"get",path:"/resources/snapshots/{resource_group}/{id}"}},service:"content",version:"v4"}},oauth2:{v1:{operations:{oauth2TokenExchange:{auth:"none",method:"post",path:"/oauth2/token"},introspectOauth2Token:{auth:"none",method:"post",path:"/oauth2/introspect"},revokeOauth2Token:{auth:"none",method:"post",path:"/oauth2/revoke"},oAuth2Authorize:{auth:"none",method:"get",path:"/oauth2/auth"},getOidcUserInfo:{auth:"user",method:"get",path:"/userinfo"},revokeOidcSession:{auth:"none",method:"get",path:"/oauth2/sessions/logout"}},service:"oauth2",version:"v1"}},quranReflect:{v1:{operations:{usersControllerProfile:{auth:"user",method:"get",path:"/v1/users/profile"},usersControllerUpdateProfile:{auth:"user",method:"put",path:"/v1/users/profile"},usersControllerEditProfile:{auth:"user",method:"patch",path:"/v1/users/profile"},usersControllerRooms:{auth:"user",method:"get",path:"/v1/users/my-rooms"},usersControllerSearch:{auth:"user",method:"get",path:"/v1/users/search"},usersControllerToggleFollow:{auth:"user",method:"post",path:"/v1/users/{followeeId}/toggle-follow"},usersControllerRemoveFollower:{auth:"user",method:"post",path:"/v1/users/{followerId}/remove-follower"},usersControllerGetUserProfile:{auth:"user",method:"get",path:"/v1/users/{id}"},usersControllerGetUserProfile2:{auth:"user",method:"get",path:"/v1/users/{username}/profile"},usersControllerGetUserFollowers:{auth:"user",method:"get",path:"/v1/users/{id}/followers"},usersControllerGetUserFollowing:{auth:"user",method:"get",path:"/v1/users/{id}/following"},roomsControllerAdminsAccess:{auth:"user",method:"post",path:"/v1/rooms/admins-access"},roomsControllerCreateNewGroup:{auth:"user",method:"post",path:"/v1/rooms/groups"},roomsControllerUpdateGroup:{auth:"user",method:"patch",path:"/v1/rooms/groups"},roomsControllerCreateNewPage:{auth:"user",method:"post",path:"/v1/rooms/pages"},roomsControllerUpdatePage:{auth:"user",method:"patch",path:"/v1/rooms/pages"},roomsControllerGetRoomMembers:{auth:"user",method:"get",path:"/v1/rooms/{id}/members"},roomsControllerGetClosedGroupJoinRequestStatus:{auth:"user",method:"get",path:"/v1/rooms/{groupId}/join-request"},roomsControllerRequestToJoinClosedGroup:{auth:"user",method:"post",path:"/v1/rooms/{groupId}/join-request"},roomsControllerCancelClosedGroupJoinRequest:{auth:"user",method:"delete",path:"/v1/rooms/{groupId}/join-request"},roomsControllerGetPendingClosedGroupJoinRequests:{auth:"user",method:"get",path:"/v1/rooms/{groupId}/join-requests"},roomsControllerApproveClosedGroupJoinRequest:{auth:"user",method:"post",path:"/v1/rooms/{groupId}/join-requests/{userId}/approve"},roomsControllerRejectClosedGroupJoinRequest:{auth:"user",method:"delete",path:"/v1/rooms/{groupId}/join-requests/{userId}"},roomsControllerInviteUserToRoom:{auth:"user",method:"post",path:"/v1/rooms/{id}/invite"},roomsControllerAcceptInvite:{auth:"user",method:"get",path:"/v1/rooms/{id}/accept-invite"},roomsControllerRejectInvite:{auth:"user",method:"get",path:"/v1/rooms/{id}/reject-invite"},roomsControllerRemoveMember:{auth:"user",method:"delete",path:"/v1/rooms/{id}/members/{userId}"},roomsControllerGetRooms:{auth:"user",method:"get",path:"/v1/rooms/joined-rooms"},roomsControllerGetRooms2:{auth:"user",method:"get",path:"/v1/rooms/managed-rooms"},roomsControllerSearchRooms:{auth:"user",method:"get",path:"/v1/rooms/search"},roomsControllerGetRoomProfile:{auth:"user",method:"get",path:"/v1/rooms/group/{url}"},roomsControllerGetRoomProfile2:{auth:"user",method:"get",path:"/v1/rooms/page/{subdomain}"},roomsControllerAcceptByPrivateToken:{auth:"user",method:"get",path:"/v1/rooms/group/{url}/accept/{token}"},roomsControllerAcceptByPrivateToken2:{auth:"user",method:"get",path:"/v1/rooms/page/{subdomain}/accept/{token}"},roomsControllerGetRoomProfileById:{auth:"user",method:"get",path:"/v1/rooms/{id}"},roomsControllerGetRoomPosts:{auth:"user",method:"get",path:"/v1/rooms/{id}/posts"},roomsControllerJoinRoom:{auth:"user",method:"post",path:"/v1/rooms/{groupId}/join"},roomsControllerLeaveGroup:{auth:"user",method:"post",path:"/v1/rooms/{groupId}/leave"},roomsControllerFollowPage:{auth:"user",method:"post",path:"/v1/rooms/{pageId}/follow"},roomsControllerUnfollowPage:{auth:"user",method:"post",path:"/v1/rooms/{pageId}/unfollow"},roomsControllerUpdatePostPrivacy:{auth:"user",method:"patch",path:"/v1/rooms/{roomId}/posts/{postId}/privacy"},postsControllerFeed:{auth:"user",method:"get",path:"/v1/posts/feed"},postsControllerGetRelatedPosts:{auth:"user",method:"get",path:"/v1/posts/{postId}/related"},postsControllerGetReReflections:{auth:"user",method:"get",path:"/v1/posts/{postId}/re-reflections"},postsControllerGetLoggedinUserPosts:{auth:"user",method:"get",path:"/v1/posts/my-posts"},postsControllerGetMyPostsCountWithinRange:{auth:"user",method:"get",path:"/v1/posts/count-within-range"},postsControllerGetLikedState:{auth:"user",method:"get",path:"/v1/posts/{id}/liked"},postsControllerFindOne:{auth:"user",method:"get",path:"/v1/posts/{id}"},postsControllerEdit:{auth:"user",method:"patch",path:"/v1/posts/{id}"},postsControllerDelete:{auth:"user",method:"delete",path:"/v1/posts/{id}"},postsControllerViewTracking:{auth:"user",method:"post",path:"/v1/posts/viewed/{id}"},postsControllerReadTracking:{auth:"user",method:"post",path:"/v1/posts/read/{id}"},postsControllerCreate:{auth:"user",method:"post",path:"/v1/posts"},postsControllerReportAbuse:{auth:"user",method:"post",path:"/v1/posts/{id}/report"},postsControllerGetUserPost:{auth:"user",method:"get",path:"/v1/posts/user-posts/{id}"},postsControllerToggleLike:{auth:"user",method:"post",path:"/v1/posts/{id}/toggle-like"},postsControllerToggleSave:{auth:"user",method:"post",path:"/v1/posts/{id}/toggle-save"},postsControllerGetComments:{auth:"user",method:"get",path:"/v1/posts/{id}/comments"},postsControllerGetAllComment:{auth:"user",method:"get",path:"/v1/posts/{id}/all-comments"},postsControllerExportMultiplePosts:{auth:"user",method:"post",path:"/v1/posts/export/pdf"},postsControllerGetPublicPostCountByVerse:{auth:"user",method:"get",path:"/v1/posts/count-by-verse/{verseId}"},postsControllerGetMyPostsByVerse:{auth:"user",method:"get",path:"/v1/posts/by-verse/{verseKey}"},tagsControllerFind:{auth:"user",method:"get",path:"/v1/tags"},commentsControllerCreate:{auth:"user",method:"post",path:"/v1/comments"},commentsControllerEdit:{auth:"user",method:"patch",path:"/v1/comments/{id}"},commentsControllerDeleteComment:{auth:"user",method:"get",path:"/v1/comments/{id}/delete"},commentsControllerToggleLike:{auth:"user",method:"post",path:"/v1/comments/{id}/toggle-like"},commentsControllerGet:{auth:"user",method:"get",path:"/v1/comments/{id}/replies"},exploreControllerFind:{auth:"user",method:"get",path:"/v1/explore"},trendingHashtagsControllerFind:{auth:"user",method:"get",path:"/v1/trending-hashtags"}},service:"quranReflect",version:"v1"}},search:{v1:{operations:{searchControllerSearch:{auth:"app",method:"get",path:"/v1/search"}},service:"search",version:"v1"}}};var d=Y,x=(s,e,t)=>({...t,operationName:t.operationName??e,service:t.service??s.service,tags:t.tags??[],version:t.version??s.version});var v=(s,e)=>{let t=`${s}:${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.")},Z=(s,e)=>{if(!(s.body===void 0||s.body===null))return typeof s.body=="string"||s.body instanceof URLSearchParams?(s.contentType&&e.set("Content-Type",s.contentType),s.body):(e.set("Content-Type",s.contentType??"application/json"),JSON.stringify(s.body))},b=(s,e)=>{let t=s.expiresIn??s.expires_in,r=s.accessToken??s.access_token,o=s.idToken??s.id_token??e?.idToken,n=s.refreshToken??s.refresh_token??e?.refreshToken,i=s.tokenType??s.token_type??e?.tokenType,u=s.scope??e?.scope,a=t?Date.now()+t*1e3:e?.expiresAt;return {accessToken:r,expiresAt:a,idToken:o,refreshToken:n,scope:u,tokenType:i}};var X={delete:"remove",get:"list",patch:"update",post:"create",put:"update"},A=s=>{let e=s.replace(/([a-z0-9])([A-Z])/g,"$1 $2").replace(/[^A-Za-z0-9]+/g," ").trim().split(/\s+/).filter(Boolean);return e.length===0?"misc":e.map((t,r)=>{let o=t.toLowerCase();return r===0?o:o.charAt(0).toUpperCase()+o.slice(1)}).join("")},Re=s=>{let e=A(s);return e.charAt(0).toUpperCase()+e.slice(1)},P=s=>s.startsWith("{")&&s.endsWith("}"),L=s=>{let e=s.split("/").filter(Boolean);return e[0]?.match(/^v\d+$/)?e.slice(1):e},ve=s=>{let e=L(s.path),t=e.at(-1),r=e.filter(i=>!P(i)),o=r.at(-1),n=r[0];return e.length===1?X[s.method]:e.length===2&&t&&P(t)?s.method==="get"?"get":s.method==="delete"?"remove":"update":t&&!P(t)&&o?o===n?`${X[s.method]}ById`:A(o):A(s.operationName)},f=(s,e)=>{let t={};for(let[r,o]of Object.entries(e.operations)){let n=x(e,r,o);t[r]=i=>s.requestOperation(n,i);}return t},U=(s,e)=>{let t={};for(let[r,o]of Object.entries(s.operations)){let n=x(s,r,o),i=L(n.path).filter(l=>!P(l)),u=A(i[0]??"misc"),a=ve(n),p=t[u]??{},h=a;p[h]&&(h=`${a}${Re(r)}`),p[h]=e[r],t[u]=p;}return t};var{decamelize:z}=be,y=s=>s.startsWith("/")?s:`/${s}`,g=s=>s.endsWith("/")?s.slice(0,-1):s;var C=(s,e)=>s.replace(/\{([^}]+)\}/g,(t,r)=>{let o=e?.[r];if(o===void 0)throw new Error(`Missing path parameter: ${r}`);return encodeURIComponent(String(o))}),w=s=>s.replace(/(^|\/):([A-Za-z0-9_]+)/g,"$1{$2}"),ee=["wordFields","translationFields","fields"],te=new Set([...ee,...ee.map(s=>z(s))]),Pe=new Set(["navigationalResultsNumber","pageSize","versesResultsNumber"]),re=(s,e={})=>{if(!s)return "";let t=new URLSearchParams;for(let[r,o]of Object.entries(s)){if(o===void 0)continue;let n=e.preserveCase||Pe.has(r)?r:z(r);if(te.has(r)||te.has(n)){let i=Object.entries(o).filter(([,u])=>u).map(([u])=>z(u));i.length>0&&t.set(n,i.join(","));continue}typeof o=="string"?t.set(n,o):typeof o=="number"||typeof o=="boolean"?t.set(n,o.toString()):Array.isArray(o)&&t.set(n,o.join(","));}return t.size===0?"":`?${t.toString()}`};var R=(s,e)=>s===void 0?{}:{[e]:s},Ae=s=>({event_id:s.eventId,name:s.name,occurred_at:s.occurredAt instanceof Date?s.occurredAt.toISOString():s.occurredAt,version:s.version,...R(s.actionId,"action_id"),...R(s.anonymousId,"anonymous_id"),...R(s.properties,"properties"),...R(s.sessionId,"session_id"),...R(s.userId,"user_id")}),se=s=>({events:{submit:e=>s.submitAnalyticsEvents({body:{events:e.events.map(Ae)}})},raw:s});var Ce=s=>!!s&&typeof s=="object"&&!Array.isArray(s),we=s=>Ce(s)?typeof s.body=="string"&&typeof s.draft=="boolean"&&Array.isArray(s.references)&&Array.isArray(s.mentions):false,oe=(s,e)=>({...s,create:n=>we(n)?e("POST","/v1/posts",{body:{post:n}}):e("POST","/v1/posts",n),get:(n,i)=>typeof n=="string"||typeof n=="number"?e("GET","/v1/posts/{id}",{path:{id:n},query:i}):e("GET","/v1/posts/{id}",n),update:(n,i)=>i!==void 0?e("PATCH","/v1/posts/{id}",{body:i,path:{id:n}}):e("PATCH","/v1/posts/{id}",n)});var m=s=>{let e=typeof s=="number"?s:Number(s);return !(!e||e<=0||e>114)};var q=s=>{let e=typeof s=="number"?s:Number(s);return !(!e||e<=0||e>30)};var N=s=>{let e=typeof s=="number"?s:Number(s);return !(!e||e<=0||e>240)};var H=s=>{let e=typeof s=="number"?s:Number(s);return !(!e||e<=0||e>60)};var F=s=>{let e=typeof s=="number"?s:Number(s);return !(!e||e<=0||e>604)};var ae={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 c=s=>{let[e,t]=s.trim().split(":");if(!e||!t||!m(e))return false;let r=Number(t),o=ae[e];return !(!r||r<=0||r>o)};var Se=s=>Object.fromEntries(Object.entries(s).map(([e,t])=>t.types?[e,{...t,types:Object.fromEntries(Object.entries(t.types).map(([r,o])=>[r.toUpperCase(),o]))}]:[e,t])),S=class{constructor(e){this.fetcher=e;}async findByAyah(e,t){if(!c(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,r){if(!c(e)||!c(t))throw new Error("Invalid verse key");let o=await this.fetcher.fetch("/content/api/v4/answers/count_within_range",{...r,from:e,to:t});return Se(o)}};var ke="https://verses.quran.com";function ne(s){return s.map(e=>{let t=e.url.startsWith("http://")||e.url.startsWith("https://")?e.url:`${ke}/${e.url.replace(/^\/+/,"")}`;return {...e,audioUrl:t}})}var k=class{constructor(e){this.fetcher=e;}async findAllChapterRecitations(e,t){let{audioFiles:r}=await this.fetcher.fetch(`/content/api/v4/chapter_recitations/${e}`,t);return r}async findChapterRecitationById(e,t,r){if(!m(t))throw new Error("Invalid chapter id");let{audioFile:o}=await this.fetcher.fetch(`/content/api/v4/chapter_recitations/${e}/${t}`,r);return o}async findVerseRecitationsByChapter(e,t,r){if(!m(e))throw new Error("Invalid chapter id");let o=await this.fetcher.fetch(`/content/api/v4/recitations/${t}/by_chapter/${e}`,r);return {...o,audioFiles:ne(o.audioFiles)}}async findVerseRecitationsByKey(e,t,r){if(!c(e))throw new Error("Invalid verse key");let o=await this.fetcher.fetch(`/content/api/v4/recitations/${t}/by_ayah/${e}`,r);return {...o,audioFiles:ne(o.audioFiles)}}};var _=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(!m(e))throw new Error("Invalid chapter id");let{chapter:r}=await this.fetcher.fetch(`/content/api/v4/chapters/${e}`,t);return r}async findInfoById(e,t){let{chapterInfo:r}=await this.findInfoResponseById(e,t);return r}async findInfoResponseById(e,t){if(!m(e))throw new Error("Invalid chapter id");return this.fetcher.fetch(`/content/api/v4/chapters/${e}/info`,t)}};var Q=async(s,e={retries:3})=>{let t;for(let r=0;r<=e.retries;r++)try{return await s()}catch(o){if(t=o,r===e.retries)throw t;await new Promise(n=>setTimeout(n,Math.pow(2,r)*1e3));}throw t};var ie="https://apis.quran.foundation",I={analytics:"https://apis.quran.foundation/analytics",auth:"https://apis.quran.foundation/auth",content:"https://apis.quran.foundation/content",oauth2:"https://oauth2.quran.foundation",quranReflect:"https://apis.quran.foundation/quran-reflect",search:"https://apis.quran.foundation/search"},pe={analytics:"/v1",auth:"/v1",content:"/api/v4",oauth2:"",quranReflect:"/v1",search:"/v1"},M={analytics:"/analytics/v1",auth:"/auth/v1",content:"/content/api/v4",oauth2:"",quranReflect:"/quran-reflect/v1",search:"/search/v1"},ue={analytics:["/analytics/v1","/v1"],auth:["/auth/v1","/v1"],content:["/content/api/v4","/api/v4"],oauth2:[],quranReflect:["/quran-reflect/v1","/v1"],search:["/search/v1","/v1"]};var{camelizeKeys:Ie}=be,he={analytics:"analytics.events.write",content:"content",search:"search"},Te="/quran-reflect/v1/posts/",Oe=["/comments","/all-comments"],Ee=["analytics","auth","content","quranReflect","search"],ce="User session expired. Sign in again.",Ve="invalid_grant",Ge=6e4,Be=async s=>{try{return await s.text()}catch{return ""}},xe=(s,e)=>s.status<400||s.status>=500||s.status===429?false:e.toLowerCase().includes(Ve),Ue=(s,e)=>{let t=e.trim(),r=t?`: ${t}`:"";return `Token refresh failed: ${s.status} ${s.statusText}${r}`},T=class{constructor(e,t){this.mode=e;this.config=t;this.userSession=t.userSession;}appTokens=new Map;userSession;userSessionRefreshPromise=null;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}clearCachedTokens(){this.appTokens.clear();}async getUserSession(){let e=await this.config.storage?.getSession?.();return e!==void 0?e:this.userSession??null}async setUserSession(e){if(!this.config.storage){this.userSession=e;return}if(!e){if(this.config.storage.clearSession){await this.config.storage.clearSession(),this.userSession=null;return}await this.config.storage.setSession?.(null),this.userSession=null;return}await this.config.storage.setSession?.(e),this.userSession=e;}buildServiceUrl(e,t,r){let o=this.isCrossServiceGatewayPath(e,t),{baseUrl:n,usesGateway:i}=this.resolveServiceBaseUrl(e,o),u=this.normalizeServicePath(e,t,i,o);return `${n}${u}${re(r,{preserveCase:e==="auth"||e==="quranReflect"})}`}async requestOperation(e,t){return this.request(e.service,C(e.path,t?.path),t?.query,{...t,auth:t?.auth==="auto"||!t?.auth?e.auth:t.auth,method:t?.method??e.method.toUpperCase(),path:void 0})}async request(e,t,r,o={}){let n=this.resolveAuthMode(e,o.auth);if(this.mode==="public"&&n==="app")throw new Error("This API requires @quranjs/api/server or a backend. Content and search are server-side for confidential clients.");let i=this.buildServiceUrl(e,t,r),u=await this.getRequestUserSession(n,o),a=await this.performRequest(e,i,o,n,u?.accessToken);if(this.shouldRetryUserRequest(a,n,o,u)){let l=await this.refreshStoredUserSession();a=await this.performRequest(e,i,o,n,l.accessToken);}if(!a.ok)throw new Error(`${a.status} ${a.statusText}`);if(a.status===204)return;if(!(a.headers.get("content-type")??"").includes("application/json"))return await a.text();let h=await a.json();return Ie(h)}async fetch(e,t){let r=this.resolveLegacyRoute(e);return this.request(r.service,r.path,{...this.config.defaults,...t})}async performRequest(e,t,r,o,n){let i=new Headers(r.headers),u=Z(r,i);return e!=="oauth2"&&i.set("x-client-id",this.config.clientId),await this.applyAuthenticationHeaders(e,o,i,{...r,accessToken:n??r.accessToken},t),this.getFetch()(t,{body:u,headers:i,method:r.method??"GET"})}resolveLegacyRoute(e){let t=y(w(e));if(t.startsWith("/content/api/v4")||t.startsWith("/api/v4"))return {path:t,service:"content"};if(t==="/v1/search"||t.startsWith("/search/v1"))return {path:t,service:"search"};if(t.startsWith("/auth/v1"))return {path:t,service:"auth"};if(t.startsWith("/quran-reflect/v1"))return {path:t,service:"quranReflect"};if(t.startsWith("/oauth2")||t.startsWith("/userinfo"))return {path:t,service:"oauth2"};throw new Error(`Unsupported SDK route: ${e}`)}resolveAuthMode(e,t="auto"){return t!=="auto"?t:e==="content"||e==="search"?"app":e==="auth"||e==="quranReflect"?"user":"none"}async getRequestUserSession(e,t){if(e!=="user"||t.accessToken||this.mode!=="server")return null;let r=await this.getUserSession();if(!r?.accessToken)throw new Error("This operation requires a user session. Sign in first or use @quranjs/api/server.");return this.shouldRefreshUserSession(r)?this.refreshStoredUserSession(r):r}shouldRefreshUserSession(e){return !e.refreshToken||!e.expiresAt?false:e.expiresAt<=Date.now()+Ge}shouldRetryUserRequest(e,t,r,o){return e.status!==401||t!=="user"||r.accessToken||this.mode!=="server"?false:!!o?.refreshToken}async applyAuthenticationHeaders(e,t,r,o,n){if(o.basicAuth&&r.set("Authorization",`Basic ${v(o.basicAuth.username,o.basicAuth.password)}`),o.accessToken){this.setTokenHeaders(e,r,o.accessToken);return}if(t==="none")return;if(t==="app"){let u=await this.getAppAccessToken(e,n);this.setTokenHeaders(e,r,u);return}let i=await this.getUserSession();if(!i?.accessToken)throw new Error("This operation requires a user session. Sign in first or use @quranjs/api/server.");this.setTokenHeaders(e,r,i.accessToken);}async refreshStoredUserSession(e){if(this.userSessionRefreshPromise)return this.userSessionRefreshPromise;let t=this.executeUserSessionRefresh(e);this.userSessionRefreshPromise=t;try{return await t}finally{this.userSessionRefreshPromise===t&&(this.userSessionRefreshPromise=null);}}async executeUserSessionRefresh(e){if(this.mode!=="server"||!("clientSecret"in this.config))throw new Error("Automatic session refresh requires @quranjs/api/server or a backend.");let t=this.config.clientSecret,r=e??await this.getUserSession();if(!r?.refreshToken)throw new Error(ce);let o=`${g(this.config.services?.tokenHost??this.config.services?.oauth2BaseUrl??I.oauth2)}/oauth2/token`,n=new URLSearchParams({grant_type:"refresh_token",refresh_token:r.refreshToken}),i=await Q(()=>this.getFetch()(o,{body:n,headers:{Accept:"application/json",Authorization:`Basic ${v(this.config.clientId,t)}`,"Content-Type":"application/x-www-form-urlencoded"},method:"POST"}),{retries:3});if(!i.ok){let p=await Be(i);throw xe(i,p)?(await this.setUserSession(null),new Error(ce)):new Error(Ue(i,p))}let u=await i.json(),a=b(u,r);return await this.setUserSession(a),a}setTokenHeaders(e,t,r){if(e==="oauth2"){t.set("Authorization",`Bearer ${r}`);return}t.set("x-auth-token",r);}async getAppAccessToken(e,t){if(this.mode!=="server")throw new Error("App-authenticated APIs require @quranjs/api/server or a backend.");let r=this.resolveAppScope(e,t);if(!r)throw new Error(`No client-credentials scope is configured for ${e}.`);let o=`${e}:${r}`,n=this.appTokens.get(o);if(n&&n.expiresAt>Date.now()+3e4)return n.value;if(!("clientSecret"in this.config))throw new Error("client_secret is server-only. Use @quranjs/api/server.");let i=this.config.clientSecret,u=`${g(this.config.services?.tokenHost??this.config.services?.oauth2BaseUrl??I.oauth2)}/oauth2/token`,a=new URLSearchParams({grant_type:"client_credentials",scope:r}),p=await Q(()=>this.getFetch()(u,{body:a,headers:{Accept:"application/json",Authorization:`Basic ${v(this.config.clientId,i)}`,"Content-Type":"application/x-www-form-urlencoded"},method:"POST"}),{retries:3});if(!p.ok)throw new Error(`Token request failed: ${p.status} ${p.statusText}`);let h=await p.json(),l={expiresAt:Date.now()+h.expires_in*1e3,value:h.access_token};return this.appTokens.set(o,l),l.value}resolveAppScope(e,t){if(e!=="content"||!t)return he[e];let r=new URL(t).pathname;return r.startsWith(Te)?Oe.some(o=>r.endsWith(o))?"comment.read":"post.read":he.content}resolveServiceBaseUrl(e,t=false){let{services:r}=this.config;if(t)return {baseUrl:g(r?.gatewayUrl??ie),usesGateway:true};let o=e==="analytics"?r?.analyticsBaseUrl:e==="content"?r?.contentBaseUrl:e==="search"?r?.searchBaseUrl:e==="auth"?r?.authBaseUrl:e==="quranReflect"?r?.quranReflectBaseUrl:r?.oauth2BaseUrl??r?.tokenHost;return o?{baseUrl:g(o),usesGateway:false}:r?.gatewayUrl&&e!=="oauth2"?{baseUrl:g(r.gatewayUrl),usesGateway:true}:{baseUrl:I[e],usesGateway:false}}normalizeServicePath(e,t,r,o=false){let n=y(w(t));if(e==="oauth2"||o)return n;let i=n;for(let a of ue[e])if(i.startsWith(a)){i=y(i.slice(a.length));break}let u=r?M[e]:pe[e];return i.startsWith(u)?i:`${u}${i}`}isCrossServiceGatewayPath(e,t){let r=y(w(t)),o=Ee.find(n=>this.pathMatchesPrefix(r,M[n]));return !!(o&&o!==e)}pathMatchesPrefix(e,t){return t.length>0&&(e===t||e.startsWith(`${t}/`))}};var O=class{constructor(e){this.fetcher=e;}async findByAyah(e,t){if(!c(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(!c(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,r){if(!c(e)||!c(t))throw new Error("Invalid verse key");return this.fetcher.fetch("/content/api/v4/hadith_references/count_within_range",{...r,from:e,to:t})}};var E=class{constructor(e){this.fetcher=e;}async findAll(){let{juzs:e}=await this.fetcher.fetch("/content/api/v4/juzs");return e}};var V=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:r}=await this.fetcher.fetch(`/content/api/v4/resources/recitations/${e}/info`,t);return r}async findTranslationInfo(e,t){let{translationInfo:r}=await this.fetcher.fetch(`/content/api/v4/resources/translations/${e}/info`,t);return r}async findTafsirInfo(e,t){let{tafsirInfo:r}=await this.fetcher.fetch(`/content/api/v4/resources/tafsirs/${e}/info`,t);return r}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,r){return this.fetcher.fetch(`/content/api/v4/resources/snapshots/${e}/${t}`,r)}};var G=class{constructor(e){this.fetcher=e;}async search(e,t){return this.fetcher.fetch("/v1/search",{query:e,size:30,...t})}};var B=class{constructor(e){this.fetcher=e;}async findByKey(e,t){if(!c(e))throw new Error("Invalid verse key");let{verse:r}=await this.fetcher.fetch(`/content/api/v4/verses/by_key/${e}`,{words:false,...t});return r}async findByRange(e,t,r){if(!c(e)||!c(t))throw new Error("Invalid verse key");let{verses:o}=await this.fetcher.fetch("/content/api/v4/verses/by_range",{words:false,...r,from:e,to:t});return o}async findByChapter(e,t){if(!m(e))throw new Error("Invalid chapter id");let{verses:r}=await this.fetcher.fetch(`/content/api/v4/verses/by_chapter/${e}`,{words:false,...t});return r}async findByPage(e,t){if(!F(e))throw new Error("Invalid page number");let{verses:r}=await this.fetcher.fetch(`/content/api/v4/verses/by_page/${e}`,{words:false,...t});return r}async findByJuz(e,t){if(!q(e))throw new Error("Invalid juz");let{verses:r}=await this.fetcher.fetch(`/content/api/v4/verses/by_juz/${e}`,{words:false,...t});return r}async findByHizb(e,t){if(!H(e))throw new Error("Invalid hizb");let{verses:r}=await this.fetcher.fetch(`/content/api/v4/verses/by_hizb/${e}`,{words:false,...t});return r}async findByRub(e,t){if(!N(e))throw new Error("Invalid rub");let{verses:r}=await this.fetcher.fetch(`/content/api/v4/verses/by_rub/${e}`,{words:false,...t});return r}async findRandom(e){let{verse:t}=await this.fetcher.fetch("/content/api/v4/verses/random",{words:false,...e});return t}};var ze="auth.bookmarks.get(bookmarkId) is not supported because /v1/bookmarks/bookmark expects bookmark detail query parameters. Pass a query object such as { mushafId, key, type, verseNumber } or { mushafId, isReading: true }.",le=(s,e)=>(t,r,o)=>s.request(e,C(r,o?.path),o?.query,{...o,auth:"user",method:t,path:void 0,query:void 0}),qe=s=>{let e=f(s,d.auth.v1),t=U(d.auth.v1,e),r=le(s,"auth");return {...t,collections:{...t.collections,addBookmark:(o,n)=>r("POST","/v1/collections/{collectionId}/bookmarks",{body:n,path:{collectionId:o}}),create:o=>r("POST","/v1/collections",{body:o}),get:(o,n)=>r("GET","/v1/collections/{collectionId}",{path:{collectionId:o},query:n}),list:o=>r("GET","/v1/collections",{query:o}),listAll:o=>r("GET","/v1/collections/all",{query:o}),remove:o=>r("DELETE","/v1/collections/{collectionId}",{path:{collectionId:o}}),removeBookmark:(o,n)=>r("DELETE","/v1/collections/{collectionId}/bookmarks/{bookmarkId}",{path:{bookmarkId:n,collectionId:o}}),update:(o,n)=>r("POST","/v1/collections/{collectionId}",{body:n,path:{collectionId:o}})},bookmarks:{...t.bookmarks,create:o=>r("POST","/v1/bookmarks",{body:o}),get:async o=>{if(typeof o=="string")throw new Error(ze);return r("GET","/v1/bookmarks/bookmark",{query:o})},list:o=>r("GET","/v1/bookmarks",{query:o}),listCollections:o=>r("GET","/v1/bookmarks/collections",{query:o}),listRange:o=>r("GET","/v1/bookmarks/ayahs-range",{query:o}),remove:o=>r("DELETE","/v1/bookmarks/{bookmarkId}",{path:{bookmarkId:o}})},goals:{...t.goals,create:o=>r("POST","/v1/goals",{body:o}),estimate:o=>r("GET","/v1/goals/estimate",{query:o}),getTodaysPlan:o=>r("GET","/v1/goals/get-todays-plan",{query:o}),remove:o=>r("DELETE","/v1/goals/{id}",{path:{id:o}}),update:(o,n)=>r("PUT","/v1/goals/{id}",{body:n,path:{id:o}})},notes:{...t.notes,create:o=>r("POST","/v1/notes",{body:o}),get:o=>r("GET","/v1/notes/{noteId}",{path:{noteId:o}}),list:o=>r("GET","/v1/notes",{query:o}),listByAttachedEntity:o=>r("GET","/v1/notes/by-attached-entity",{query:o}),listByRange:o=>r("GET","/v1/notes/by-range",{query:o}),listByVerseKey:(o,n)=>r("GET","/v1/notes/by-verse/{verseKey}",{path:{verseKey:o},query:n}),publish:(o,n)=>r("POST","/v1/notes/{noteId}/publish",{body:n,path:{noteId:o}}),remove:o=>r("DELETE","/v1/notes/{noteId}",{path:{noteId:o}}),update:(o,n)=>r("PATCH","/v1/notes/{noteId}",{body:n,path:{noteId:o}})},preferences:{...t.preferences,bulkUpdate:o=>r("POST","/v1/preferences/bulk",{body:o}),get:o=>r("GET","/v1/preferences",{query:o}),update:o=>r("POST","/v1/preferences",{body:o})},raw:e,readingSessions:{...t.readingSessions,create:o=>r("POST","/v1/reading-sessions",{body:o}),list:o=>r("GET","/v1/reading-sessions",{query:o})}}},Ne=s=>{let e=f(s,d.quranReflect.v1),t=U(d.quranReflect.v1,e);return {comments:t.comments??{},posts:oe(t.posts??{},le(s,"quranReflect")),raw:e,rooms:t.rooms??{},tags:t.tags??{},users:t.users??{}}},He=(s,e,t)=>{let r=f(s,d.oauth2.v1),o=async(n,i={})=>{if(i.requiresRefreshToken&&!n.get("refresh_token"))throw new Error("Missing refresh token.");let u=n.get("refresh_token")??void 0,a=i.requiresRefreshToken?await s.getUserSession():null,p=i.requiresRefreshToken&&u?{...a??{},refreshToken:u}:a,h=await s.request("oauth2","/oauth2/token",void 0,{auth:"none",basicAuth:"clientSecret"in t?{password:t.clientSecret,username:t.clientId}:void 0,body:n,contentType:"application/x-www-form-urlencoded",method:"POST"});return await s.setUserSession(b(h,p)),h};return {authorizeUrl:n=>s.buildServiceUrl("oauth2","/oauth2/auth",n),exchangeCode:n=>{let i=new URLSearchParams({code:n.code,grant_type:"authorization_code",redirect_uri:n.redirectUri});return n.codeVerifier&&i.set("code_verifier",n.codeVerifier),n.scope&&i.set("scope",n.scope),o(i,{})},getUserInfo:n=>s.request("oauth2","/userinfo",void 0,{accessToken:n,auth:"user",method:"GET"}),introspect:n=>{if(!("clientSecret"in t))throw new Error("Token introspection requires @quranjs/api/server or a backend.");return s.request("oauth2","/oauth2/introspect",void 0,{auth:"none",basicAuth:{password:t.clientSecret,username:t.clientId},body:new URLSearchParams({token:n}),contentType:"application/x-www-form-urlencoded",method:"POST"})},logout:n=>s.request("oauth2","/oauth2/sessions/logout",n,{auth:"none",method:"GET"}),raw:r,refresh:async n=>{let i=await s.getUserSession(),u=new URLSearchParams({grant_type:"refresh_token",refresh_token:n??i?.refreshToken??""});return o(u,{requiresRefreshToken:true})}}},Fe=(s,e,t,r,o,n,i,u)=>({answers:{byAyah:(a,p)=>s.findByAyah(a,p),countWithinRange:(a,p,h)=>s.countWithinRange(a,p,h),get:a=>s.findByQuestionId(a)},audio:{chapterRecitation:{get:(a,p,h)=>o.findChapterRecitationById(a,p,h),list:(a,p)=>o.findAllChapterRecitations(a,p)},verseRecitation:{byChapter:(a,p,h)=>o.findVerseRecitationsByChapter(a,p,h),byKey:(a,p,h)=>o.findVerseRecitationsByKey(a,p,h)}},chapters:{get:(a,p)=>e.findById(a,p),getInfo:(a,p)=>e.findInfoById(a,p),getInfoResponse:(a,p)=>e.findInfoResponseById(a,p),list:a=>e.findAll(a)},hadithReferences:{byAyah:(a,p)=>n.findByAyah(a,p),countWithinRange:(a,p,h)=>n.countWithinRange(a,p,h),hadithsByAyah:(a,p)=>n.findHadithsByAyah(a,p)},juzs:{list:()=>r.findAll()},raw:u,resources:{findSnapshot:(a,p,h)=>i.findSnapshot(a,p,h),chapterInfos:{list:a=>i.findAllChapterInfos(a)},chapterReciters:{list:a=>i.findAllChapterReciters(a)},languages:{list:a=>i.findAllLanguages(a)},recitationStyles:{list:a=>i.findAllRecitationStyles(a)},recitations:{getInfo:(a,p)=>i.findRecitationInfo(a,p),list:a=>i.findAllRecitations(a)},tafsirs:{getInfo:(a,p)=>i.findTafsirInfo(a,p),list:a=>i.findAllTafsirs(a)},translations:{getInfo:(a,p)=>i.findTranslationInfo(a,p),list:a=>i.findAllTranslations(a)},verseMedia:{list:a=>i.findVerseMedia(a)},sync:a=>i.sync(a)},verses:{byChapter:(a,p)=>t.findByChapter(a,p),byHizb:(a,p)=>t.findByHizb(a,p),byJuz:(a,p)=>t.findByJuz(a,p),byKey:(a,p)=>t.findByKey(a,p),byPage:(a,p)=>t.findByPage(a,p),byRange:(a,p,h)=>t.findByRange(a,p,h),byRub:(a,p)=>t.findByRub(a,p),random:a=>t.findRandom(a)}}),de=(s,e)=>{let t=new T(s,e);t.getFetch();let r=new S(t),o=new _(t),n=new B(t),i=new E(t),u=new k(t),a=new O(t),p=new V(t),h=new G(t),l={analytics:{v1:f(t,d.analytics.v1)},auth:{v1:f(t,d.auth.v1)},content:{v4:f(t,d.content.v4)},oauth2:{v1:f(t,d.oauth2.v1)},quranReflect:{v1:f(t,d.quranReflect.v1)},search:{v1:f(t,d.search.v1)}},K=Fe(r,o,n,i,u,a,p,l.content.v4),j=se(l.analytics.v1),$=qe(t),W=Ne(t),D=He(t,s,e),J=({query:fe,...ge})=>h.search(fe,ge),me=Object.assign(h,{query:J,raw:l.search.v1,v1:{query:J,raw:l.search.v1}});return {analytics:{...j,v1:j},answers:r,audio:u,auth:{...$,v1:$},chapters:o,clearCachedTokens:()=>t.clearCachedTokens(),content:{...K,v4:K},getUserSession:()=>t.getUserSession(),hadithReferences:a,juzs:i,oauth2:{...D,v1:D},quranReflect:{...W,v1:W},raw:l,resources:p,search:me,verses:n}};var zr=s=>de("server",{...s,defaults:{language:"ar",...s.defaults}});
2
- export{zr as createServerClient};//# sourceMappingURL=server.min.mjs.map
1
+ import st from'humps';var Ae={analytics:{v1:{operations:{submitAnalyticsEvents:{auth:"app",method:"post",path:"/v1/events:batch"}},service:"analytics",version:"v1"}},auth:{v1:{operations:{getUserCsrfToken:{auth:"user",method:"get",path:"/users/csrf-token"},listUserConnectedApps:{auth:"user",method:"get",path:"/users/connected-apps"},runUserConnectedAppLifecycle:{auth:"user",method:"post",path:"/users/connected-apps/{appId}/lifecycle"},getAppStateConfiguration:{auth:"user",method:"get",path:"/v1/app-state:config"},bootstrapAppState:{auth:"user",method:"get",path:"/v1/app-state:bootstrap"},getAppStateChanges:{auth:"user",method:"get",path:"/v1/app-state:changes"},listAppStateDocuments:{auth:"user",method:"get",path:"/v1/app-state/{collection}"},getAppStateDocument:{auth:"user",method:"get",path:"/v1/app-state/{collection}/{key}"},putAppStateDocument:{auth:"user",method:"put",path:"/v1/app-state/{collection}/{key}"},deleteAppStateDocument:{auth:"user",method:"delete",path:"/v1/app-state/{collection}/{key}"},getV1Collections:{auth:"user",method:"get",path:"/v1/collections"},postV1Collections:{auth:"user",method:"post",path:"/v1/collections"},postV1CollectionsByCollectionIdBookmarks:{auth:"user",method:"post",path:"/v1/collections/{collectionId}/bookmarks"},deleteV1CollectionsByCollectionIdBookmarks:{auth:"user",method:"delete",path:"/v1/collections/{collectionId}/bookmarks"},getV1CollectionsByCollectionId:{auth:"user",method:"get",path:"/v1/collections/{collectionId}"},postV1CollectionsByCollectionId:{auth:"user",method:"post",path:"/v1/collections/{collectionId}"},deleteV1CollectionsByCollectionId:{auth:"user",method:"delete",path:"/v1/collections/{collectionId}"},deleteV1CollectionsByCollectionIdBookmarksByBookmarkId:{auth:"user",method:"delete",path:"/v1/collections/{collectionId}/bookmarks/{bookmarkId}"},getV1CollectionsAll:{auth:"user",method:"get",path:"/v1/collections/all"},getV1Bookmarks:{auth:"user",method:"get",path:"/v1/bookmarks"},postV1Bookmarks:{auth:"user",method:"post",path:"/v1/bookmarks"},deleteV1BookmarksByBookmarkId:{auth:"user",method:"delete",path:"/v1/bookmarks/{bookmarkId}"},getV1BookmarksAyahsRange:{auth:"user",method:"get",path:"/v1/bookmarks/ayahs-range"},getV1BookmarksBookmark:{auth:"user",method:"get",path:"/v1/bookmarks/bookmark"},getV1BookmarksCollections:{auth:"user",method:"get",path:"/v1/bookmarks/collections"},getV1Preferences:{auth:"user",method:"get",path:"/v1/preferences"},postV1Preferences:{auth:"user",method:"post",path:"/v1/preferences"},postV1PreferencesBulk:{auth:"user",method:"post",path:"/v1/preferences/bulk"},getV1ReadingSessions:{auth:"user",method:"get",path:"/v1/reading-sessions"},postV1ReadingSessions:{auth:"user",method:"post",path:"/v1/reading-sessions"},getV1GoalsGetTodaysPlan:{auth:"user",method:"get",path:"/v1/goals/get-todays-plan"},putV1GoalsById:{auth:"user",method:"put",path:"/v1/goals/{id}"},deleteV1GoalsById:{auth:"user",method:"delete",path:"/v1/goals/{id}"},postV1Goals:{auth:"user",method:"post",path:"/v1/goals"},getV1GoalsEstimate:{auth:"user",method:"get",path:"/v1/goals/estimate"},getV1Streaks:{auth:"user",method:"get",path:"/v1/streaks"},getV1StreaksCurrentStreakDays:{auth:"user",method:"get",path:"/v1/streaks/current-streak-days"},getV1ActivityDays:{auth:"user",method:"get",path:"/v1/activity-days"},postV1ActivityDays:{auth:"user",method:"post",path:"/v1/activity-days"},getV1ActivityDaysEstimateReadingTime:{auth:"user",method:"get",path:"/v1/activity-days/estimate-reading-time"},getV1Notes:{auth:"user",method:"get",path:"/v1/notes"},postV1Notes:{auth:"user",method:"post",path:"/v1/notes"},getV1NotesByVerseByVerseKey:{auth:"user",method:"get",path:"/v1/notes/by-verse/{verseKey}"},getV1NotesByAttachedEntity:{auth:"user",method:"get",path:"/v1/notes/by-attached-entity"},getV1NotesCountWithinRange:{auth:"user",method:"get",path:"/v1/notes/count-within-range"},getV1NotesByRange:{auth:"user",method:"get",path:"/v1/notes/by-range"},getV1NotesByNoteId:{auth:"user",method:"get",path:"/v1/notes/{noteId}"},patchV1NotesByNoteId:{auth:"user",method:"patch",path:"/v1/notes/{noteId}"},deleteV1NotesByNoteId:{auth:"user",method:"delete",path:"/v1/notes/{noteId}"},postV1NotesByNoteIdPublish:{auth:"user",method:"post",path:"/v1/notes/{noteId}/publish"}},service:"auth",version:"v1"}},content:{v4:{operations:{audioReciterTimestamp:{auth:"app",method:"get",path:"/audio/reciters/{reciter_id}/timestamp"},audioReciterLookup:{auth:"app",method:"get",path:"/audio/reciters/{reciter_id}/lookup"},listChapters:{auth:"app",method:"get",path:"/chapters"},getChapter:{auth:"app",method:"get",path:"/chapters/{id}"},getChapterInfo:{auth:"app",method:"get",path:"/chapters/{id}/info"},hadithReferencesByAyah:{auth:"app",method:"get",path:"/hadith_references/by_ayah/{ayah_key}"},hadithsByAyah:{auth:"app",method:"get",path:"/hadith_references/by_ayah/{ayah_key}/hadiths"},hadithCountWithinRange:{auth:"app",method:"get",path:"/hadith_references/count_within_range"},listPages:{auth:"app",method:"get",path:"/pages"},getPagesLookup:{auth:"app",method:"get",path:"/pages/lookup"},getPagesPageNumber:{auth:"app",method:"get",path:"/pages/{page_number}"},versesByChapterNumber:{auth:"app",method:"get",path:"/verses/by_chapter/{chapter_number}"},versesByPageNumber:{auth:"app",method:"get",path:"/verses/by_page/{page_number}"},versesByJuzNumber:{auth:"app",method:"get",path:"/verses/by_juz/{juz_number}"},versesByHizbNumber:{auth:"app",method:"get",path:"/verses/by_hizb/{hizb_number}"},versesByRubElHizbNumber:{auth:"app",method:"get",path:"/verses/by_rub/{rub_el_hizb_number}"},versesByManzilNumber:{auth:"app",method:"get",path:"/verses/by_manzil/{manzil_number}"},versesByRukuNumber:{auth:"app",method:"get",path:"/verses/by_ruku/{ruku_number}"},versesByRange:{auth:"app",method:"get",path:"/verses/by_range"},versesByVerseKey:{auth:"app",method:"get",path:"/verses/by_key/{verse_key}"},randomVerse:{auth:"app",method:"get",path:"/verses/random"},listJuzs:{auth:"app",method:"get",path:"/juzs"},quranVersesByScript:{auth:"app",method:"get",path:"/quran/verses/{script}"},quranVersesIndopak:{auth:"app",method:"get",path:"/quran/verses/indopak"},quranVersesIndopakNastaleeq:{auth:"app",method:"get",path:"/quran/verses/indopak_nastaleeq"},quranVersesUthmaniTajweed:{auth:"app",method:"get",path:"/quran/verses/uthmani_tajweed"},quranVersesUthmani:{auth:"app",method:"get",path:"/quran/verses/uthmani"},quranVersesUthmaniSimple:{auth:"app",method:"get",path:"/quran/verses/uthmani_simple"},quranVersesImlaei:{auth:"app",method:"get",path:"/quran/verses/imlaei"},recitations:{auth:"app",method:"get",path:"/resources/recitations"},recitationAudioFiles:{auth:"app",method:"get",path:"/quran/recitations/{recitation_id}"},translation:{auth:"app",method:"get",path:"/quran/translations/{translation_id}"},chapterReciters:{auth:"app",method:"get",path:"/resources/chapter_reciters"},tafsir:{auth:"app",method:"get",path:"/quran/tafsirs/{tafsir_id}"},quranVersesCodeV1:{auth:"app",method:"get",path:"/quran/verses/code_v1"},quranVersesCodeV2:{auth:"app",method:"get",path:"/quran/verses/code_v2"},listSurahRecitation:{auth:"app",method:"get",path:"/recitations/{recitation_id}/by_chapter/{chapter_number}"},listJuzRecitation:{auth:"app",method:"get",path:"/recitations/{recitation_id}/by_juz/{juz_number}"},listPageRecitation:{auth:"app",method:"get",path:"/recitations/{recitation_id}/by_page/{page_number}"},listRubElHizbRecitation:{auth:"app",method:"get",path:"/recitations/{recitation_id}/by_rub/{rub_el_hizb_number}"},listHizbRecitation:{auth:"app",method:"get",path:"/recitations/{recitation_id}/by_hizb/{hizb_number}"},listAyahRecitation:{auth:"app",method:"get",path:"/recitations/{recitation_id}/by_ayah/{ayah_key}"},recitationInfo:{auth:"app",method:"get",path:"/resources/recitations/{recitation_id}/info"},translationInfo:{auth:"app",method:"get",path:"/resources/translations/{translation_id}/info"},translations:{auth:"app",method:"get",path:"/resources/translations"},tafsirs:{auth:"app",method:"get",path:"/resources/tafsirs"},tafsirInfo:{auth:"app",method:"get",path:"/resources/tafsirs/{tafsir_id}/info"},recitationStyles:{auth:"app",method:"get",path:"/resources/recitation_styles"},languages:{auth:"app",method:"get",path:"/resources/languages"},chapterInfo:{auth:"app",method:"get",path:"/resources/chapter_infos"},verseMedia:{auth:"app",method:"get",path:"/resources/verse_media"},listManzilRecitation:{auth:"app",method:"get",path:"/recitations/{recitation_id}/by_manzil/{manzil_number}"},listRukuRecitation:{auth:"app",method:"get",path:"/recitations/{recitation_id}/by_ruku/{ruku_number}"},listSurahTranslations:{auth:"app",method:"get",path:"/translations/{resource_id}/by_chapter/{chapter_number}"},listPageTranslations:{auth:"app",method:"get",path:"/translations/{resource_id}/by_page/{page_number}"},listJuzTranslations:{auth:"app",method:"get",path:"/translations/{resource_id}/by_juz/{juz_number}"},listRubElHizbTranslations:{auth:"app",method:"get",path:"/translations/{resource_id}/by_rub_el_hizb/{rub_el_hizb_number}"},listHizbTranslations:{auth:"app",method:"get",path:"/translations/{resource_id}/by_hizb/{hizb_number}"},listManzilTranslations:{auth:"app",method:"get",path:"/translations/{resource_id}/by_manzil/{manzil_number}"},listRukuTranslations:{auth:"app",method:"get",path:"/translations/{resource_id}/by_ruku/{ruku_number}"},listAyahTranslations:{auth:"app",method:"get",path:"/translations/{resource_id}/by_ayah/{ayah_key}"},listSurahTafsirs:{auth:"app",method:"get",path:"/tafsirs/{resource_id}/by_chapter/{chapter_number}"},listPageTafsirs:{auth:"app",method:"get",path:"/tafsirs/{resource_id}/by_page/{page_number}"},listJuzTafsirs:{auth:"app",method:"get",path:"/tafsirs/{resource_id}/by_juz/{juz_number}"},listRubElHizbTafsirs:{auth:"app",method:"get",path:"/tafsirs/{resource_id}/by_rub_el_hizb/{rub_el_hizb_number}"},listHizbTafsirs:{auth:"app",method:"get",path:"/tafsirs/{resource_id}/by_hizb/{hizb_number}"},listManzilTafsirs:{auth:"app",method:"get",path:"/tafsirs/{resource_id}/by_manzil/{manzil_number}"},listRukuTafsirs:{auth:"app",method:"get",path:"/tafsirs/{resource_id}/by_ruku/{ruku_number}"},listAyahTafsirs:{auth:"app",method:"get",path:"/tafsirs/{resource_id}/by_ayah/{ayah_key}"},getJuz:{auth:"app",method:"get",path:"/juzs/{id}"},listHizbs:{auth:"app",method:"get",path:"/hizbs"},getHizb:{auth:"app",method:"get",path:"/hizbs/{id}"},listRubElHizbs:{auth:"app",method:"get",path:"/rub_el_hizbs"},getRubElHizb:{auth:"app",method:"get",path:"/rub_el_hizbs/{id}"},listRukus:{auth:"app",method:"get",path:"/rukus"},getRuku:{auth:"app",method:"get",path:"/rukus/{id}"},listManzils:{auth:"app",method:"get",path:"/manzils"},getManzil:{auth:"app",method:"get",path:"/manzils/{id}"},getFootNote:{auth:"app",method:"get",path:"/foot_notes/{id}"},postsControllerFeed:{auth:"app",method:"get",path:"/quran-reflect/v1/posts/feed"},postsControllerFindOne:{auth:"app",method:"get",path:"/quran-reflect/v1/posts/{id}"},postsControllerGetUserPost:{auth:"app",method:"get",path:"/quran-reflect/v1/posts/user-posts/{id}"},postsControllerGetComments:{auth:"app",method:"get",path:"/quran-reflect/v1/posts/{id}/comments"},postsControllerGetAllComment:{auth:"app",method:"get",path:"/quran-reflect/v1/posts/{id}/all-comments"},chapterReciterAudioFiles:{auth:"app",method:"get",path:"/chapter_recitations/{reciter_id}"},chapterReciterAudioFile:{auth:"app",method:"get",path:"/chapter_recitations/{reciter_id}/{chapter_number}"},versesByRubElHizbNumberRubElHizb:{auth:"app",method:"get",path:"/verses/by_rub_el_hizb/{rub_el_hizb_number}"},listRubElHizbTranslationsRub:{auth:"app",method:"get",path:"/translations/{resource_id}/by_rub/{rub_el_hizb_number}"},listRubElHizbTafsirsRub:{auth:"app",method:"get",path:"/tafsirs/{resource_id}/by_rub/{rub_el_hizb_number}"},listRubElHizbRecitationRubElHizb:{auth:"app",method:"get",path:"/recitations/{recitation_id}/by_rub_el_hizb/{rub_el_hizb_number}"},listAyahAnswers:{auth:"app",method:"get",path:"/answers/by_ayah/{ayah_key}"},getAnswerById:{auth:"app",method:"get",path:"/answers/{question_id}"},countAnswersWithinRange:{auth:"app",method:"get",path:"/answers/count_within_range"},resourcesSync:{auth:"app",method:"get",path:"/resources/sync"},resourcesSnapshot:{auth:"app",method:"get",path:"/resources/snapshots/{resource_group}/{id}"}},service:"content",version:"v4"}},oauth2:{v1:{operations:{oauth2TokenExchange:{auth:"none",method:"post",path:"/oauth2/token"},introspectOauth2Token:{auth:"none",method:"post",path:"/oauth2/introspect"},revokeOauth2Token:{auth:"none",method:"post",path:"/oauth2/revoke"},oAuth2Authorize:{auth:"none",method:"get",path:"/oauth2/auth"},getOidcUserInfo:{auth:"user",method:"get",path:"/userinfo"},revokeOidcSession:{auth:"none",method:"get",path:"/oauth2/sessions/logout"}},service:"oauth2",version:"v1"}},quranReflect:{v1:{operations:{usersControllerProfile:{auth:"user",method:"get",path:"/v1/users/profile"},usersControllerUpdateProfile:{auth:"user",method:"put",path:"/v1/users/profile"},usersControllerEditProfile:{auth:"user",method:"patch",path:"/v1/users/profile"},usersControllerRooms:{auth:"user",method:"get",path:"/v1/users/my-rooms"},usersControllerSearch:{auth:"user",method:"get",path:"/v1/users/search"},usersControllerToggleFollow:{auth:"user",method:"post",path:"/v1/users/{followeeId}/toggle-follow"},usersControllerRemoveFollower:{auth:"user",method:"post",path:"/v1/users/{followerId}/remove-follower"},usersControllerGetUserProfile:{auth:"user",method:"get",path:"/v1/users/{id}"},usersControllerGetUserProfile2:{auth:"user",method:"get",path:"/v1/users/{username}/profile"},usersControllerGetUserFollowers:{auth:"user",method:"get",path:"/v1/users/{id}/followers"},usersControllerGetUserFollowing:{auth:"user",method:"get",path:"/v1/users/{id}/following"},roomsControllerAdminsAccess:{auth:"user",method:"post",path:"/v1/rooms/admins-access"},roomsControllerCreateNewGroup:{auth:"user",method:"post",path:"/v1/rooms/groups"},roomsControllerUpdateGroup:{auth:"user",method:"patch",path:"/v1/rooms/groups"},roomsControllerCreateNewPage:{auth:"user",method:"post",path:"/v1/rooms/pages"},roomsControllerUpdatePage:{auth:"user",method:"patch",path:"/v1/rooms/pages"},roomsControllerGetRoomMembers:{auth:"user",method:"get",path:"/v1/rooms/{id}/members"},roomsControllerGetClosedGroupJoinRequestStatus:{auth:"user",method:"get",path:"/v1/rooms/{groupId}/join-request"},roomsControllerRequestToJoinClosedGroup:{auth:"user",method:"post",path:"/v1/rooms/{groupId}/join-request"},roomsControllerCancelClosedGroupJoinRequest:{auth:"user",method:"delete",path:"/v1/rooms/{groupId}/join-request"},roomsControllerGetPendingClosedGroupJoinRequests:{auth:"user",method:"get",path:"/v1/rooms/{groupId}/join-requests"},roomsControllerApproveClosedGroupJoinRequest:{auth:"user",method:"post",path:"/v1/rooms/{groupId}/join-requests/{userId}/approve"},roomsControllerRejectClosedGroupJoinRequest:{auth:"user",method:"delete",path:"/v1/rooms/{groupId}/join-requests/{userId}"},roomsControllerInviteUserToRoom:{auth:"user",method:"post",path:"/v1/rooms/{id}/invite"},roomsControllerAcceptInvite:{auth:"user",method:"get",path:"/v1/rooms/{id}/accept-invite"},roomsControllerRejectInvite:{auth:"user",method:"get",path:"/v1/rooms/{id}/reject-invite"},roomsControllerRemoveMember:{auth:"user",method:"delete",path:"/v1/rooms/{id}/members/{userId}"},roomsControllerGetRooms:{auth:"user",method:"get",path:"/v1/rooms/joined-rooms"},roomsControllerGetRooms2:{auth:"user",method:"get",path:"/v1/rooms/managed-rooms"},roomsControllerSearchRooms:{auth:"user",method:"get",path:"/v1/rooms/search"},roomsControllerGetRoomProfile:{auth:"user",method:"get",path:"/v1/rooms/group/{url}"},roomsControllerGetRoomProfile2:{auth:"user",method:"get",path:"/v1/rooms/page/{subdomain}"},roomsControllerAcceptByPrivateToken:{auth:"user",method:"get",path:"/v1/rooms/group/{url}/accept/{token}"},roomsControllerAcceptByPrivateToken2:{auth:"user",method:"get",path:"/v1/rooms/page/{subdomain}/accept/{token}"},roomsControllerGetRoomProfileById:{auth:"user",method:"get",path:"/v1/rooms/{id}"},roomsControllerGetRoomPosts:{auth:"user",method:"get",path:"/v1/rooms/{id}/posts"},roomsControllerJoinRoom:{auth:"user",method:"post",path:"/v1/rooms/{groupId}/join"},roomsControllerLeaveGroup:{auth:"user",method:"post",path:"/v1/rooms/{groupId}/leave"},roomsControllerFollowPage:{auth:"user",method:"post",path:"/v1/rooms/{pageId}/follow"},roomsControllerUnfollowPage:{auth:"user",method:"post",path:"/v1/rooms/{pageId}/unfollow"},roomsControllerUpdatePostPrivacy:{auth:"user",method:"patch",path:"/v1/rooms/{roomId}/posts/{postId}/privacy"},postsControllerFeed:{auth:"user",method:"get",path:"/v1/posts/feed"},postsControllerGetRelatedPosts:{auth:"user",method:"get",path:"/v1/posts/{postId}/related"},postsControllerGetReReflections:{auth:"user",method:"get",path:"/v1/posts/{postId}/re-reflections"},postsControllerGetLoggedinUserPosts:{auth:"user",method:"get",path:"/v1/posts/my-posts"},postsControllerGetMyPostsCountWithinRange:{auth:"user",method:"get",path:"/v1/posts/count-within-range"},postsControllerGetLikedState:{auth:"user",method:"get",path:"/v1/posts/{id}/liked"},postsControllerFindOne:{auth:"user",method:"get",path:"/v1/posts/{id}"},postsControllerEdit:{auth:"user",method:"patch",path:"/v1/posts/{id}"},postsControllerDelete:{auth:"user",method:"delete",path:"/v1/posts/{id}"},postsControllerViewTracking:{auth:"user",method:"post",path:"/v1/posts/viewed/{id}"},postsControllerReadTracking:{auth:"user",method:"post",path:"/v1/posts/read/{id}"},postsControllerCreate:{auth:"user",method:"post",path:"/v1/posts"},postsControllerReportAbuse:{auth:"user",method:"post",path:"/v1/posts/{id}/report"},postsControllerGetUserPost:{auth:"user",method:"get",path:"/v1/posts/user-posts/{id}"},postsControllerToggleLike:{auth:"user",method:"post",path:"/v1/posts/{id}/toggle-like"},postsControllerToggleSave:{auth:"user",method:"post",path:"/v1/posts/{id}/toggle-save"},postsControllerGetComments:{auth:"user",method:"get",path:"/v1/posts/{id}/comments"},postsControllerGetAllComment:{auth:"user",method:"get",path:"/v1/posts/{id}/all-comments"},postsControllerExportMultiplePosts:{auth:"user",method:"post",path:"/v1/posts/export/pdf"},postsControllerGetPublicPostCountByVerse:{auth:"user",method:"get",path:"/v1/posts/count-by-verse/{verseId}"},postsControllerGetMyPostsByVerse:{auth:"user",method:"get",path:"/v1/posts/by-verse/{verseKey}"},tagsControllerFind:{auth:"user",method:"get",path:"/v1/tags"},commentsControllerCreate:{auth:"user",method:"post",path:"/v1/comments"},commentsControllerEdit:{auth:"user",method:"patch",path:"/v1/comments/{id}"},commentsControllerDeleteComment:{auth:"user",method:"get",path:"/v1/comments/{id}/delete"},commentsControllerToggleLike:{auth:"user",method:"post",path:"/v1/comments/{id}/toggle-like"},commentsControllerGet:{auth:"user",method:"get",path:"/v1/comments/{id}/replies"},exploreControllerFind:{auth:"user",method:"get",path:"/v1/explore"},trendingHashtagsControllerFind:{auth:"user",method:"get",path:"/v1/trending-hashtags"}},service:"quranReflect",version:"v1"}},search:{v1:{operations:{searchControllerSearch:{auth:"app",method:"get",path:"/v1/search"}},service:"search",version:"v1"}}};var A=Ae,ie=(r,e,t)=>({...t,operationName:t.operationName??e,service:t.service??r.service,tags:t.tags??[],version:t.version??r.version});var Q=(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.")},Se=(r,e)=>{if(!(r.body===void 0||r.body===null))return typeof r.body=="string"||r.body instanceof URLSearchParams?(r.contentType&&e.set("Content-Type",r.contentType),r.body):(e.set("Content-Type",r.contentType??"application/json"),JSON.stringify(r.body))},D=(r,e)=>{let t=r.expiresIn??r.expires_in,o=r.accessToken??r.access_token,s=r.idToken??r.id_token??e?.idToken,n=r.refreshToken??r.refresh_token??e?.refreshToken,i=r.tokenType??r.token_type??e?.tokenType,d=r.scope??e?.scope,a=t?Date.now()+t*1e3:e?.expiresAt;return {accessToken:o,expiresAt:a,idToken:s,refreshToken:n,scope:d,tokenType:i}};var be={delete:"remove",get:"list",patch:"update",post:"create",put:"update"},K=r=>{let e=r.replace(/([a-z0-9])([A-Z])/g,"$1 $2").replace(/[^A-Za-z0-9]+/g," ").trim().split(/\s+/).filter(Boolean);return e.length===0?"misc":e.map((t,o)=>{let s=t.toLowerCase();return o===0?s:s.charAt(0).toUpperCase()+s.slice(1)}).join("")},rt=r=>{let e=K(r);return e.charAt(0).toUpperCase()+e.slice(1)},j=r=>r.startsWith("{")&&r.endsWith("}"),Pe=r=>{let e=r.split("/").filter(Boolean);return e[0]?.match(/^v\d+$/)?e.slice(1):e},ot=r=>{let e=Pe(r.path),t=e.at(-1),o=e.filter(i=>!j(i)),s=o.at(-1),n=o[0];return e.length===1?be[r.method]:e.length===2&&t&&j(t)?r.method==="get"?"get":r.method==="delete"?"remove":"update":t&&!j(t)&&s?s===n?`${be[r.method]}ById`:K(s):K(r.operationName)},w=(r,e)=>{let t={};for(let[o,s]of Object.entries(e.operations)){let n=ie(e,o,s);t[o]=i=>r.requestOperation(n,i);}return t},pe=(r,e)=>{let t={};for(let[o,s]of Object.entries(r.operations)){let n=ie(r,o,s),i=Pe(n.path).filter(y=>!j(y)),d=K(i[0]??"misc"),a=ot(n),u=t[d]??{},c=a;u[c]&&(c=`${a}${rt(o)}`),u[c]=e[o],t[d]=u;}return t};var{decamelize:ue}=st,N=r=>r.startsWith("/")?r:`/${r}`,I=r=>r.endsWith("/")?r.slice(0,-1):r;var E=(r,e)=>r.replace(/\{([^}]+)\}/g,(t,o)=>{let s=e?.[o];if(s===void 0)throw new Error(`Missing path parameter: ${o}`);return encodeURIComponent(String(s))}),$=r=>r.replace(/(^|\/):([A-Za-z0-9_]+)/g,"$1{$2}"),we=["wordFields","translationFields","fields"],_e=new Set([...we,...we.map(r=>ue(r))]),nt=new Set(["navigationalResultsNumber","pageSize","versesResultsNumber"]),Ce=(r,e={})=>{if(!r)return "";let t=new URLSearchParams;for(let[o,s]of Object.entries(r)){if(s===void 0)continue;let n=e.preserveCase||nt.has(o)?o:ue(o);if(_e.has(o)||_e.has(n)){let i=Object.entries(s).filter(([,d])=>d).map(([d])=>ue(d));i.length>0&&t.set(n,i.join(","));continue}typeof s=="string"?t.set(n,s):typeof s=="number"||typeof s=="boolean"?t.set(n,s.toString()):Array.isArray(s)&&t.set(n,s.join(","));}return t.size===0?"":`?${t.toString()}`};var M=(r,e)=>r===void 0?{}:{[e]:r},at=r=>({event_id:r.eventId,name:r.name,occurred_at:r.occurredAt instanceof Date?r.occurredAt.toISOString():r.occurredAt,version:r.version,...M(r.actionId,"action_id"),...M(r.anonymousId,"anonymous_id"),...M(r.properties,"properties"),...M(r.sessionId,"session_id"),...M(r.userId,"user_id")}),Te=r=>({events:{submit:e=>r.submitAnalyticsEvents({body:{events:e.events.map(at)}})},raw:r});var ce=(r,e)=>E("/v1/app-state/{collection}/{key}",{collection:r,key:e}),ke=r=>{let{idempotencyKey:e,ifMatch:t,ifNoneMatch:o}=r;if(t!==void 0&&o!==void 0)throw new Error("App State mutations accept only one of ifMatch or ifNoneMatch.");return Object.freeze({"Idempotency-Key":e,...t===void 0?{}:{"If-Match":t},...o===void 0?{}:{"If-None-Match":o}})},it=r=>{let e=JSON.parse(JSON.stringify(r)),t=o=>{if(!(typeof o!="object"||o===null)){Object.freeze(o);for(let s of Object.values(o))t(s);}};return t(e),e},Ee=r=>{let e=(o,s,n,i={})=>r.request("auth",s,n,{...i,auth:"user",method:o,preserveResponseKeys:true}),t=async(o,s,n={})=>{let i=null,d=0;return {...await e(o,s,void 0,{...n,onResponse:u=>{i=u.headers.get("etag"),d=u.status;}}),etag:i,status:d}};return {bootstrap:(o={})=>e("GET","/v1/app-state:bootstrap",o),deleteDocument:async(o,s,n)=>{await e("DELETE",ce(o,s),void 0,{headers:ke(n)});},getChanges:(o,s={})=>e("GET","/v1/app-state:changes",{...s,since:o}),getConfiguration:()=>e("GET","/v1/app-state:config"),getDocument:(o,s)=>t("GET",ce(o,s)),listDocuments:(o,s={})=>e("GET",E("/v1/app-state/{collection}",{collection:o}),s),putDocument:async(o,s,n,i)=>{let d=ke(i),a=it(n);return t("PUT",ce(o,s),{body:a,headers:d})}}};var pt=r=>!!r&&typeof r=="object"&&!Array.isArray(r),ut=r=>pt(r)?typeof r.body=="string"&&typeof r.draft=="boolean"&&Array.isArray(r.references)&&Array.isArray(r.mentions):false,Ie=(r,e)=>({...r,create:n=>ut(n)?e("POST","/v1/posts",{body:{post:n}}):e("POST","/v1/posts",n),get:(n,i)=>typeof n=="string"||typeof n=="number"?e("GET","/v1/posts/{id}",{path:{id:n},query:i}):e("GET","/v1/posts/{id}",n),update:(n,i)=>i!==void 0?e("PATCH","/v1/posts/{id}",{body:i,path:{id:n}}):e("PATCH","/v1/posts/{id}",n)});var b=r=>{let e=typeof r=="number"?r:Number(r);return !(!e||e<=0||e>114)};var he=r=>{let e=typeof r=="number"?r:Number(r);return !(!e||e<=0||e>30)};var le=r=>{let e=typeof r=="number"?r:Number(r);return !(!e||e<=0||e>240)};var de=r=>{let e=typeof r=="number"?r:Number(r);return !(!e||e<=0||e>60)};var me=r=>{let e=typeof r=="number"?r:Number(r);return !(!e||e<=0||e>604)};var Oe={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 R=r=>{let[e,t]=r.trim().split(":");if(!e||!t||!b(e))return false;let o=Number(t),s=Oe[e];return !(!o||o<=0||o>s)};var ct=r=>Object.fromEntries(Object.entries(r).map(([e,t])=>t.types?[e,{...t,types:Object.fromEntries(Object.entries(t.types).map(([o,s])=>[o.toUpperCase(),s]))}]:[e,t])),W=class{constructor(e){this.fetcher=e;}async findByAyah(e,t){if(!R(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,o){if(!R(e)||!R(t))throw new Error("Invalid verse key");let s=await this.fetcher.fetch("/content/api/v4/answers/count_within_range",{...o,from:e,to:t});return ct(s)}};var ht="https://verses.quran.com";function Ve(r){return r.map(e=>{let t=e.url.startsWith("http://")||e.url.startsWith("https://")?e.url:`${ht}/${e.url.replace(/^\/+/,"")}`;return {...e,audioUrl:t}})}var J=class{constructor(e){this.fetcher=e;}async findAllChapterRecitations(e,t){let{audioFiles:o}=await this.fetcher.fetch(`/content/api/v4/chapter_recitations/${e}`,t);return o}async findChapterRecitationById(e,t,o){if(!b(t))throw new Error("Invalid chapter id");let{audioFile:s}=await this.fetcher.fetch(`/content/api/v4/chapter_recitations/${e}/${t}`,o);return s}async findVerseRecitationsByChapter(e,t,o){if(!b(e))throw new Error("Invalid chapter id");let s=await this.fetcher.fetch(`/content/api/v4/recitations/${t}/by_chapter/${e}`,o);return {...s,audioFiles:Ve(s.audioFiles)}}async findVerseRecitationsByKey(e,t,o){if(!R(e))throw new Error("Invalid verse key");let s=await this.fetcher.fetch(`/content/api/v4/recitations/${t}/by_ayah/${e}`,o);return {...s,audioFiles:Ve(s.audioFiles)}}};var L=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(!b(e))throw new Error("Invalid chapter id");let{chapter:o}=await this.fetcher.fetch(`/content/api/v4/chapters/${e}`,t);return o}async findInfoById(e,t){let{chapterInfo:o}=await this.findInfoResponseById(e,t);return o}async findInfoResponseById(e,t){if(!b(e))throw new Error("Invalid chapter id");return this.fetcher.fetch(`/content/api/v4/chapters/${e}/info`,t)}};var fe=async(r,e={retries:3})=>{let t;for(let o=0;o<=e.retries;o++)try{return await r()}catch(s){if(t=s,o===e.retries)throw t;await new Promise(n=>setTimeout(n,Math.pow(2,o)*1e3));}throw t};var lt=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}},Be=class Ue 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 Ue(e,await lt(e))}};Object.defineProperty(Be,"name",{configurable:true,value:"QuranHttpError"});var xe=Symbol.for("@quranjs/api/QuranHttpError/v1"),Ge=globalThis,O=Ge[xe]??Be;Ge[xe]=O;var qe="https://apis.quran.foundation",Z={analytics:"https://apis.quran.foundation/analytics",auth:"https://apis.quran.foundation/auth",content:"https://apis.quran.foundation/content",oauth2:"https://oauth2.quran.foundation",quranReflect:"https://apis.quran.foundation/quran-reflect",search:"https://apis.quran.foundation/search"},Ne={analytics:"/v1",auth:"/v1",content:"/api/v4",oauth2:"",quranReflect:"/v1",search:"/v1"},ge={analytics:"/analytics/v1",auth:"/auth/v1",content:"/content/api/v4",oauth2:"",quranReflect:"/quran-reflect/v1",search:"/search/v1"},Me={analytics:["/analytics/v1","/v1"],auth:["/auth/v1","/v1"],content:["/content/api/v4","/api/v4"],oauth2:[],quranReflect:["/quran-reflect/v1","/v1"],search:["/search/v1","/v1"]};var{camelizeKeys:mt}=st,ze={analytics:"analytics.events.write",content:"content",search:"search"},ft="/quran-reflect/v1/posts/",gt=["/comments","/all-comments"],yt=["analytics","auth","content","quranReflect","search"],He="User session expired. Sign in again.",Rt="invalid_grant",vt=6e4,At=async r=>{try{return await r.text()}catch{return ""}},St=(r,e)=>r.status<400||r.status>=500||r.status===429?false:e.toLowerCase().includes(Rt),bt=(r,e)=>{let t=e.trim(),o=t?`: ${t}`:"";return `Token refresh failed: ${r.status} ${r.statusText}${o}`},X=class{constructor(e,t){this.mode=e;this.config=t;this.userSession=t.userSession;}appTokens=new Map;userSession;userSessionRefreshPromise=null;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}clearCachedTokens(){this.appTokens.clear();}async getUserSession(){let e=await this.config.storage?.getSession?.();return e!==void 0?e:this.userSession??null}async setUserSession(e){if(!this.config.storage){this.userSession=e;return}if(!e){if(this.config.storage.clearSession){await this.config.storage.clearSession(),this.userSession=null;return}await this.config.storage.setSession?.(null),this.userSession=null;return}await this.config.storage.setSession?.(e),this.userSession=e;}buildServiceUrl(e,t,o){let s=this.isCrossServiceGatewayPath(e,t),{baseUrl:n,usesGateway:i}=this.resolveServiceBaseUrl(e,s),d=this.normalizeServicePath(e,t,i,s);return `${n}${d}${Ce(o,{preserveCase:e==="auth"||e==="quranReflect"})}`}async requestOperation(e,t){return this.request(e.service,E(e.path,t?.path),t?.query,{...t,auth:t?.auth==="auto"||!t?.auth?e.auth:t.auth,method:t?.method??e.method.toUpperCase(),path:void 0})}async request(e,t,o,s={}){let n=this.resolveAuthMode(e,s.auth);if(this.mode==="public"&&n==="app")throw new Error("This API requires @quranjs/api/server or a backend. Content and search are server-side for confidential clients.");let i=this.buildServiceUrl(e,t,o),d=await this.getRequestUserSession(n,s),a=await this.performRequest(e,i,s,n,d?.accessToken);if(this.shouldRetryUserRequest(a,n,s,d)){let y=await this.refreshStoredUserSession();a=await this.performRequest(e,i,s,n,y.accessToken);}if(!a.ok)throw await O.fromResponse(a);if(s.onResponse?.({headers:a.headers,status:a.status}),a.status===204)return;if(!(a.headers.get("content-type")??"").includes("application/json"))return await a.text();let c=await a.json();return s.preserveResponseKeys?c:mt(c)}async fetch(e,t){let o=this.resolveLegacyRoute(e);return this.request(o.service,o.path,{...this.config.defaults,...t})}async performRequest(e,t,o,s,n){let i=new Headers(o.headers),d=Se(o,i);return e!=="oauth2"&&i.set("x-client-id",this.config.clientId),await this.applyAuthenticationHeaders(e,s,i,{...o,accessToken:n??o.accessToken},t),this.getFetch()(t,{body:d,headers:i,method:o.method??"GET"})}resolveLegacyRoute(e){let t=N($(e));if(t.startsWith("/content/api/v4")||t.startsWith("/api/v4"))return {path:t,service:"content"};if(t==="/v1/search"||t.startsWith("/search/v1"))return {path:t,service:"search"};if(t.startsWith("/auth/v1"))return {path:t,service:"auth"};if(t.startsWith("/quran-reflect/v1"))return {path:t,service:"quranReflect"};if(t.startsWith("/oauth2")||t.startsWith("/userinfo"))return {path:t,service:"oauth2"};throw new Error(`Unsupported SDK route: ${e}`)}resolveAuthMode(e,t="auto"){return t!=="auto"?t:e==="content"||e==="search"?"app":e==="auth"||e==="quranReflect"?"user":"none"}async getRequestUserSession(e,t){if(e!=="user"||t.accessToken||this.mode!=="server")return null;let o=await this.getUserSession();if(!o?.accessToken)throw new Error("This operation requires a user session. Sign in first or use @quranjs/api/server.");return this.shouldRefreshUserSession(o)?this.refreshStoredUserSession(o):o}shouldRefreshUserSession(e){return !e.refreshToken||!e.expiresAt?false:e.expiresAt<=Date.now()+vt}shouldRetryUserRequest(e,t,o,s){return e.status!==401||t!=="user"||o.accessToken||this.mode!=="server"?false:!!s?.refreshToken}async applyAuthenticationHeaders(e,t,o,s,n){if(s.basicAuth&&o.set("Authorization",`Basic ${Q(s.basicAuth.username,s.basicAuth.password)}`),s.accessToken){this.setTokenHeaders(e,o,s.accessToken);return}if(t==="none")return;if(t==="app"){let d=await this.getAppAccessToken(e,n);this.setTokenHeaders(e,o,d);return}let i=await this.getUserSession();if(!i?.accessToken)throw new Error("This operation requires a user session. Sign in first or use @quranjs/api/server.");this.setTokenHeaders(e,o,i.accessToken);}async refreshStoredUserSession(e){if(this.userSessionRefreshPromise)return this.userSessionRefreshPromise;let t=this.executeUserSessionRefresh(e);this.userSessionRefreshPromise=t;try{return await t}finally{this.userSessionRefreshPromise===t&&(this.userSessionRefreshPromise=null);}}async executeUserSessionRefresh(e){if(this.mode!=="server"||!("clientSecret"in this.config))throw new Error("Automatic session refresh requires @quranjs/api/server or a backend.");let t=this.config.clientSecret,o=e??await this.getUserSession();if(!o?.refreshToken)throw new Error(He);let s=`${I(this.config.services?.tokenHost??this.config.services?.oauth2BaseUrl??Z.oauth2)}/oauth2/token`,n=new URLSearchParams({grant_type:"refresh_token",refresh_token:o.refreshToken}),i=await fe(()=>this.getFetch()(s,{body:n,headers:{Accept:"application/json",Authorization:`Basic ${Q(this.config.clientId,t)}`,"Content-Type":"application/x-www-form-urlencoded"},method:"POST"}),{retries:3});if(!i.ok){let u=await At(i);throw St(i,u)?(await this.setUserSession(null),new Error(He)):new Error(bt(i,u))}let d=await i.json(),a=D(d,o);return await this.setUserSession(a),a}setTokenHeaders(e,t,o){if(e==="oauth2"){t.set("Authorization",`Bearer ${o}`);return}t.set("x-auth-token",o);}async getAppAccessToken(e,t){if(this.mode!=="server")throw new Error("App-authenticated APIs require @quranjs/api/server or a backend.");let o=this.resolveAppScope(e,t);if(!o)throw new Error(`No client-credentials scope is configured for ${e}.`);let s=`${e}:${o}`,n=this.appTokens.get(s);if(n&&n.expiresAt>Date.now()+3e4)return n.value;if(!("clientSecret"in this.config))throw new Error("client_secret is server-only. Use @quranjs/api/server.");let i=this.config.clientSecret,d=`${I(this.config.services?.tokenHost??this.config.services?.oauth2BaseUrl??Z.oauth2)}/oauth2/token`,a=new URLSearchParams({grant_type:"client_credentials",scope:o}),u=await fe(()=>this.getFetch()(d,{body:a,headers:{Accept:"application/json",Authorization:`Basic ${Q(this.config.clientId,i)}`,"Content-Type":"application/x-www-form-urlencoded"},method:"POST"}),{retries:3});if(!u.ok)throw new Error(`Token request failed: ${u.status} ${u.statusText}`);let c=await u.json(),y={expiresAt:Date.now()+c.expires_in*1e3,value:c.access_token};return this.appTokens.set(s,y),y.value}resolveAppScope(e,t){if(e!=="content"||!t)return ze[e];let o=new URL(t).pathname;return o.startsWith(ft)?gt.some(s=>o.endsWith(s))?"comment.read":"post.read":ze.content}resolveServiceBaseUrl(e,t=false){let{services:o}=this.config;if(t)return {baseUrl:I(o?.gatewayUrl??qe),usesGateway:true};let s=e==="analytics"?o?.analyticsBaseUrl:e==="content"?o?.contentBaseUrl:e==="search"?o?.searchBaseUrl:e==="auth"?o?.authBaseUrl:e==="quranReflect"?o?.quranReflectBaseUrl:o?.oauth2BaseUrl??o?.tokenHost;return s?{baseUrl:I(s),usesGateway:false}:o?.gatewayUrl&&e!=="oauth2"?{baseUrl:I(o.gatewayUrl),usesGateway:true}:{baseUrl:Z[e],usesGateway:false}}normalizeServicePath(e,t,o,s=false){let n=N($(t));if(e==="oauth2"||s)return n;let i=n;for(let a of Me[e])if(i.startsWith(a)){i=N(i.slice(a.length));break}let d=o?ge[e]:Ne[e];return i.startsWith(d)?i:`${d}${i}`}isCrossServiceGatewayPath(e,t){let o=N($(t)),s=yt.find(n=>this.pathMatchesPrefix(o,ge[n]));return !!(s&&s!==e)}pathMatchesPrefix(e,t){return t.length>0&&(e===t||e.startsWith(`${t}/`))}};var Y=class{constructor(e){this.fetcher=e;}async findByAyah(e,t){if(!R(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(!R(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,o){if(!R(e)||!R(t))throw new Error("Invalid verse key");return this.fetcher.fetch("/content/api/v4/hadith_references/count_within_range",{...o,from:e,to:t})}};var ee=class{constructor(e){this.fetcher=e;}async findAll(){let{juzs:e}=await this.fetcher.fetch("/content/api/v4/juzs");return e}};var te=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:o}=await this.fetcher.fetch(`/content/api/v4/resources/recitations/${e}/info`,t);return o}async findTranslationInfo(e,t){let{translationInfo:o}=await this.fetcher.fetch(`/content/api/v4/resources/translations/${e}/info`,t);return o}async findTafsirInfo(e,t){let{tafsirInfo:o}=await this.fetcher.fetch(`/content/api/v4/resources/tafsirs/${e}/info`,t);return o}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,o){return this.fetcher.fetch(`/content/api/v4/resources/snapshots/${e}/${t}`,o)}};var re=class{constructor(e){this.fetcher=e;}async search(e,t){return this.fetcher.fetch("/v1/search",{query:e,size:30,...t})}};var oe=class{constructor(e){this.fetcher=e;}async findByKey(e,t){if(!R(e))throw new Error("Invalid verse key");let{verse:o}=await this.fetcher.fetch(`/content/api/v4/verses/by_key/${e}`,{words:false,...t});return o}async findByRange(e,t,o){if(!R(e)||!R(t))throw new Error("Invalid verse key");let{verses:s}=await this.fetcher.fetch("/content/api/v4/verses/by_range",{words:false,...o,from:e,to:t});return s}async findByChapter(e,t){if(!b(e))throw new Error("Invalid chapter id");let{verses:o}=await this.fetcher.fetch(`/content/api/v4/verses/by_chapter/${e}`,{words:false,...t});return o}async findByPage(e,t){if(!me(e))throw new Error("Invalid page number");let{verses:o}=await this.fetcher.fetch(`/content/api/v4/verses/by_page/${e}`,{words:false,...t});return o}async findByJuz(e,t){if(!he(e))throw new Error("Invalid juz");let{verses:o}=await this.fetcher.fetch(`/content/api/v4/verses/by_juz/${e}`,{words:false,...t});return o}async findByHizb(e,t){if(!de(e))throw new Error("Invalid hizb");let{verses:o}=await this.fetcher.fetch(`/content/api/v4/verses/by_hizb/${e}`,{words:false,...t});return o}async findByRub(e,t){if(!le(e))throw new Error("Invalid rub");let{verses:o}=await this.fetcher.fetch(`/content/api/v4/verses/by_rub/${e}`,{words:false,...t});return o}async findRandom(e){let{verse:t}=await this.fetcher.fetch("/content/api/v4/verses/random",{words:false,...e});return t}};var Pt="auth.bookmarks.get(bookmarkId) is not supported because /v1/bookmarks/bookmark expects bookmark detail query parameters. Pass a query object such as { mushafId, key, type, verseNumber } or { mushafId, isReading: true }.",Fe=(r,e)=>(t,o,s)=>r.request(e,E(o,s?.path),s?.query,{...s,auth:"user",method:t,path:void 0,query:void 0}),wt=r=>{let e=w(r,A.auth.v1),t=pe(A.auth.v1,e),o=Fe(r,"auth");return {...t,appState:Ee(r),collections:{...t.collections,addBookmark:(s,n)=>o("POST","/v1/collections/{collectionId}/bookmarks",{body:n,path:{collectionId:s}}),create:s=>o("POST","/v1/collections",{body:s}),get:(s,n)=>o("GET","/v1/collections/{collectionId}",{path:{collectionId:s},query:n}),list:s=>o("GET","/v1/collections",{query:s}),listAll:s=>o("GET","/v1/collections/all",{query:s}),remove:s=>o("DELETE","/v1/collections/{collectionId}",{path:{collectionId:s}}),removeBookmark:(s,n)=>o("DELETE","/v1/collections/{collectionId}/bookmarks/{bookmarkId}",{path:{bookmarkId:n,collectionId:s}}),update:(s,n)=>o("POST","/v1/collections/{collectionId}",{body:n,path:{collectionId:s}})},bookmarks:{...t.bookmarks,create:s=>o("POST","/v1/bookmarks",{body:s}),get:async s=>{if(typeof s=="string")throw new Error(Pt);return o("GET","/v1/bookmarks/bookmark",{query:s})},list:s=>o("GET","/v1/bookmarks",{query:s}),listCollections:s=>o("GET","/v1/bookmarks/collections",{query:s}),listRange:s=>o("GET","/v1/bookmarks/ayahs-range",{query:s}),remove:s=>o("DELETE","/v1/bookmarks/{bookmarkId}",{path:{bookmarkId:s}})},goals:{...t.goals,create:s=>o("POST","/v1/goals",{body:s}),estimate:s=>o("GET","/v1/goals/estimate",{query:s}),getTodaysPlan:s=>o("GET","/v1/goals/get-todays-plan",{query:s}),remove:s=>o("DELETE","/v1/goals/{id}",{path:{id:s}}),update:(s,n)=>o("PUT","/v1/goals/{id}",{body:n,path:{id:s}})},notes:{...t.notes,create:s=>o("POST","/v1/notes",{body:s}),get:s=>o("GET","/v1/notes/{noteId}",{path:{noteId:s}}),list:s=>o("GET","/v1/notes",{query:s}),listByAttachedEntity:s=>o("GET","/v1/notes/by-attached-entity",{query:s}),listByRange:s=>o("GET","/v1/notes/by-range",{query:s}),listByVerseKey:(s,n)=>o("GET","/v1/notes/by-verse/{verseKey}",{path:{verseKey:s},query:n}),publish:(s,n)=>o("POST","/v1/notes/{noteId}/publish",{body:n,path:{noteId:s}}),remove:s=>o("DELETE","/v1/notes/{noteId}",{path:{noteId:s}}),update:(s,n)=>o("PATCH","/v1/notes/{noteId}",{body:n,path:{noteId:s}})},preferences:{...t.preferences,bulkUpdate:s=>o("POST","/v1/preferences/bulk",{body:s}),get:s=>o("GET","/v1/preferences",{query:s}),update:s=>o("POST","/v1/preferences",{body:s})},raw:e,readingSessions:{...t.readingSessions,create:s=>o("POST","/v1/reading-sessions",{body:s}),list:s=>o("GET","/v1/reading-sessions",{query:s})}}},_t=r=>{let e=w(r,A.quranReflect.v1),t=pe(A.quranReflect.v1,e);return {comments:t.comments??{},posts:Ie(t.posts??{},Fe(r,"quranReflect")),raw:e,rooms:t.rooms??{},tags:t.tags??{},users:t.users??{}}},Ct=(r,e,t)=>{let o=w(r,A.oauth2.v1),s=async(n,i={})=>{if(i.requiresRefreshToken&&!n.get("refresh_token"))throw new Error("Missing refresh token.");let d=n.get("refresh_token")??void 0,a=i.requiresRefreshToken?await r.getUserSession():null,u=i.requiresRefreshToken&&d?{...a??{},refreshToken:d}:a,c=await r.request("oauth2","/oauth2/token",void 0,{auth:"none",basicAuth:"clientSecret"in t?{password:t.clientSecret,username:t.clientId}:void 0,body:n,contentType:"application/x-www-form-urlencoded",method:"POST"});return await r.setUserSession(D(c,u)),c};return {authorizeUrl:n=>r.buildServiceUrl("oauth2","/oauth2/auth",n),exchangeCode:n=>{let i=new URLSearchParams({code:n.code,grant_type:"authorization_code",redirect_uri:n.redirectUri});return n.codeVerifier&&i.set("code_verifier",n.codeVerifier),n.scope&&i.set("scope",n.scope),s(i,{})},getUserInfo:n=>r.request("oauth2","/userinfo",void 0,{accessToken:n,auth:"user",method:"GET"}),introspect:n=>{if(!("clientSecret"in t))throw new Error("Token introspection requires @quranjs/api/server or a backend.");return r.request("oauth2","/oauth2/introspect",void 0,{auth:"none",basicAuth:{password:t.clientSecret,username:t.clientId},body:new URLSearchParams({token:n}),contentType:"application/x-www-form-urlencoded",method:"POST"})},logout:n=>r.request("oauth2","/oauth2/sessions/logout",n,{auth:"none",method:"GET"}),raw:o,refresh:async n=>{let i=await r.getUserSession(),d=new URLSearchParams({grant_type:"refresh_token",refresh_token:n??i?.refreshToken??""});return s(d,{requiresRefreshToken:true})}}},Tt=(r,e,t,o,s,n,i,d)=>({answers:{byAyah:(a,u)=>r.findByAyah(a,u),countWithinRange:(a,u,c)=>r.countWithinRange(a,u,c),get:a=>r.findByQuestionId(a)},audio:{chapterRecitation:{get:(a,u,c)=>s.findChapterRecitationById(a,u,c),list:(a,u)=>s.findAllChapterRecitations(a,u)},verseRecitation:{byChapter:(a,u,c)=>s.findVerseRecitationsByChapter(a,u,c),byKey:(a,u,c)=>s.findVerseRecitationsByKey(a,u,c)}},chapters:{get:(a,u)=>e.findById(a,u),getInfo:(a,u)=>e.findInfoById(a,u),getInfoResponse:(a,u)=>e.findInfoResponseById(a,u),list:a=>e.findAll(a)},hadithReferences:{byAyah:(a,u)=>n.findByAyah(a,u),countWithinRange:(a,u,c)=>n.countWithinRange(a,u,c),hadithsByAyah:(a,u)=>n.findHadithsByAyah(a,u)},juzs:{list:()=>o.findAll()},raw:d,resources:{findSnapshot:(a,u,c)=>i.findSnapshot(a,u,c),chapterInfos:{list:a=>i.findAllChapterInfos(a)},chapterReciters:{list:a=>i.findAllChapterReciters(a)},languages:{list:a=>i.findAllLanguages(a)},recitationStyles:{list:a=>i.findAllRecitationStyles(a)},recitations:{getInfo:(a,u)=>i.findRecitationInfo(a,u),list:a=>i.findAllRecitations(a)},tafsirs:{getInfo:(a,u)=>i.findTafsirInfo(a,u),list:a=>i.findAllTafsirs(a)},translations:{getInfo:(a,u)=>i.findTranslationInfo(a,u),list:a=>i.findAllTranslations(a)},verseMedia:{list:a=>i.findVerseMedia(a)},sync:a=>i.sync(a)},verses:{byChapter:(a,u)=>t.findByChapter(a,u),byHizb:(a,u)=>t.findByHizb(a,u),byJuz:(a,u)=>t.findByJuz(a,u),byKey:(a,u)=>t.findByKey(a,u),byPage:(a,u)=>t.findByPage(a,u),byRange:(a,u,c)=>t.findByRange(a,u,c),byRub:(a,u)=>t.findByRub(a,u),random:a=>t.findRandom(a)}}),Qe=(r,e)=>{let t=new X(r,e);t.getFetch();let o=new W(t),s=new L(t),n=new oe(t),i=new ee(t),d=new J(t),a=new Y(t),u=new te(t),c=new re(t),y={analytics:{v1:w(t,A.analytics.v1)},auth:{v1:w(t,A.auth.v1)},content:{v4:w(t,A.content.v4)},oauth2:{v1:w(t,A.oauth2.v1)},quranReflect:{v1:w(t,A.quranReflect.v1)},search:{v1:w(t,A.search.v1)}},P=Tt(o,s,n,i,d,a,u,y.content.v4),T=Te(y.analytics.v1),B=wt(t),k=_t(t),U=Ct(t,r,e),F=({query:ne,...ae})=>c.search(ne,ae),x=Object.assign(c,{query:F,raw:y.search.v1,v1:{query:F,raw:y.search.v1}});return {analytics:{...T,v1:T},answers:o,audio:d,auth:{...B,v1:B},chapters:s,clearCachedTokens:()=>t.clearCachedTokens(),content:{...P,v4:P},getUserSession:()=>t.getUserSession(),hadithReferences:a,juzs:i,oauth2:{...U,v1:U},quranReflect:{...k,v1:k},raw:y,resources:u,search:x,verses:n}};var kt=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"]),V=r=>{if(!(r instanceof O))return;let e=r.payload;if(typeof e!="object"||e===null)return;let t=e.details;if(typeof t!="object"||t===null)return;let o=t.error,s=typeof o=="string"?o:typeof o=="object"&&o!==null?o.code:void 0;return typeof s=="string"&&kt.has(s)?s:void 0};function Et(r,e){let t=V(r);return t!==void 0&&(e===void 0||e===t)}var _=class extends Error{code;constructor(e){super(`App State reconciliation protocol error: ${e}`),this.name="AppStateProtocolError",this.code=e;}},S=r=>JSON.parse(JSON.stringify(r)),C=r=>{if(typeof r!="object"||r===null||Object.isFrozen(r))return r;for(let e of Object.values(r))C(e);return Object.freeze(r)},se=r=>{if(Array.isArray(r))return `[${r.map(se).join(",")}]`;if(typeof r=="object"&&r!==null){let e=r;return `{${Object.keys(e).sort().map(t=>`${JSON.stringify(t)}:${se(e[t])}`).join(",")}}`}return JSON.stringify(r)},z=(r,e)=>`${r}/${encodeURIComponent(e)}`,It=()=>({bootstrapCursor:null,localRevision:0,pendingMutations:[],shadow:{},stagingBootstrap:null,syncToken:null}),Ot=r=>{if(typeof r=="object"&&r!==null&&"then"in r&&typeof r.then=="function")throw new TypeError("App State store reducers must be synchronous.")},Vt=(r={})=>{let e=new Map(Object.entries(r).map(([o,s])=>[o,C(S(s))])),t=new Map;return {transaction:(o,s)=>{if(!o)return Promise.reject(new TypeError("App State transactions require an account ID."));let i=(t.get(o)??Promise.resolve()).then(()=>{let d=e.get(o)??It(),a=S(d),u=s(a);return Ot(u),C(a),e.set(o,a),u});return t.set(o,i.then(()=>{},()=>{})),i}}},De=(r,e)=>{let t=z(e.collection,e.key),o=r[t];if(!(o&&e.version<o.version)){if(o&&e.version===o.version){if(se(o)!==se(e))throw new _("same_version_conflict");return}r[t]=S(e);}},H=(r,e,t,o="shadow")=>{let s=o==="shadow"?r.shadow:r.stagingBootstrap??{},n=S(s);for(let i of e)De(n,i);o==="shadow"?r.shadow=n:r.stagingBootstrap=n,r.syncToken=t;},je=(r,e,t)=>{let o=S(r.stagingBootstrap??{});for(let s of e)De(o,s);r.stagingBootstrap=o,r.bootstrapCursor=t;},Ke=r=>{r.shadow=S(r.stagingBootstrap??{}),r.stagingBootstrap=null,r.bootstrapCursor=null;},$e=(r,e,t)=>{let o=r.shadow[z(e,t)];return o?.operation==="upsert"?{ifMatch:o.etag}:{ifNoneMatch:"*"}},We=(r,e,t,o,s)=>{let n=r.localRevision+1,i={...$e(r,e,t),body:S(o),collection:e,idempotencyKey:s,key:t,localRevision:n,method:"PUT"};return C(i),r.pendingMutations=[...r.pendingMutations,i],r.localRevision=n,n},Je=(r,e,t,o)=>{let s=r.localRevision+1,n={...$e(r,e,t),collection:e,idempotencyKey:o,key:t,localRevision:s,method:"DELETE"};return C(n),r.pendingMutations=[...r.pendingMutations,n],r.localRevision=s,s},Bt=r=>{let e={};for(let[t,o]of Object.entries(r))o.operation!=="delete"&&(e[t]={collection:o.collection,etag:o.etag,key:o.key,pending:false,schemaVersion:o.schemaVersion,updatedAt:o.updatedAt,value:S(o.value),version:o.version});return e},Le=r=>{let e=S(r),t=Bt(e.shadow);for(let o of e.pendingMutations){let s=z(o.collection,o.key);if(o.method==="DELETE"){delete t[s];continue}let n=t[s];t[s]={collection:o.collection,etag:n?.etag??null,key:o.key,pending:true,schemaVersion:o.body.schemaVersion,updatedAt:n?.updatedAt??null,value:S(o.body.value),version:n?.version??null};}return C({...e,visible:t})},Ze=r=>C(S(r.pendingMutations)),ye=(r,e)=>{r.pendingMutations=r.pendingMutations.filter(t=>t.localRevision!==e);},Xe=(r,e)=>{r.pendingMutations=r.pendingMutations.map(t=>t.localRevision===e.localRevision?C(S(e)):t);};var Ut=100,xt=3,Gt=3,qt=()=>{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()},Ye=r=>r.ifMatch!==void 0?{idempotencyKey:r.idempotencyKey,ifMatch:r.ifMatch}:r.ifNoneMatch!==void 0?{idempotencyKey:r.idempotencyKey,ifNoneMatch:r.ifNoneMatch}:{idempotencyKey:r.idempotencyKey},Nt=r=>r.map(e=>({...e,operation:"upsert"})),Re=r=>{let e=V(r);return e==="bootstrap_required"||e==="sync_token_expired"},Mt=(r,e)=>{if(!Number.isInteger(r)||r<=0)throw new TypeError(`${e} must be a positive integer.`);return r},zt=({accountId:r,createIdempotencyKey:e=qt,maxRebaseAttempts:t=Gt,pageSize:o=Ut,store:s,transport:n})=>{if(!r)throw new TypeError("App State reconciliation requires an account ID.");if(Mt(o,"pageSize"),!Number.isInteger(t)||t<0)throw new TypeError("maxRebaseAttempts must be a non-negative integer.");let i=r,d=n,a=0,u=Promise.resolve(),c=p=>p.accountId===i&&p.generation===a,y=()=>({accountId:i,generation:a,transport:d}),P=async(p,h)=>c(p)?s.transaction(p.accountId,l=>c(p)?(h(l),true):false):false,T=p=>s.transaction(p.accountId,h=>({bootstrapCursor:h.bootstrapCursor,hasStaging:h.stagingBootstrap!==null,syncToken:h.syncToken})),B=p=>P(p,h=>{h.bootstrapCursor=null,h.stagingBootstrap={},h.syncToken=null;}),k=async(p,h)=>{let l=0;if(!(h&&!await B(p)))for(;c(p);){for(;c(p);){let m=await T(p);if(!c(p))return;if(m.hasStaging&&m.bootstrapCursor===null&&m.syncToken!==null)break;let g;try{g=await p.transport.bootstrap({...m.bootstrapCursor===null?{}:{cursor:m.bootstrapCursor},limit:o});}catch(q){if(!c(p))return;throw q}if(!c(p))return;let f=g.data;if(f.hasMore&&f.nextCursor===null)throw new _("bootstrap_cursor_missing");if(!f.hasMore&&f.nextSyncToken===null)throw new _("bootstrap_sync_token_missing");if(!await P(p,q=>{je(q,Nt(f.items),f.hasMore?f.nextCursor:null),f.hasMore||(q.syncToken=f.nextSyncToken);}))return;if(!f.hasMore)break}for(;c(p);){let{syncToken:m}=await T(p);if(!c(p))return;if(m===null)throw new _("bootstrap_sync_token_missing");let g;try{g=await p.transport.getChanges(m,{limit:o});}catch(v){if(!c(p))return;if(!Re(v))throw v;if(!await B(p))return;if(l>=xt)throw v;l+=1;break}if(!c(p)||!await P(p,v=>{H(v,g.data.changes,g.data.nextSyncToken,"stagingBootstrap"),g.data.hasMore||Ke(v);})||!g.data.hasMore)return}}},U=async p=>{let h=await T(p);if(c(p)){if(h.syncToken===null||h.hasStaging){await k(p,false);return}for(;c(p);){let{syncToken:l}=await T(p);if(!c(p))return;if(l===null){await k(p,false);return}try{let m=await p.transport.getChanges(l,{limit:o});if(!c(p)||!await P(p,f=>{H(f,m.data.changes,m.data.nextSyncToken);})||!m.data.hasMore)return}catch(m){if(!c(p))return;if(!Re(m))throw m;await k(p,true);return}}}},F=async(p,h,l)=>{let m=l.etag;if(m===null)throw new _("put_response_etag_missing");await P(p,g=>{if(g.syncToken!==null){let f={...l.data,etag:m,operation:"upsert",value:h.body.value};H(g,[f],g.syncToken);}ye(g,h.localRevision);});},x=async(p,h)=>{await P(p,l=>{let m=z(h.collection,h.key),g=l.shadow[m];g&&(l.shadow[m]={...g,operation:"delete",value:null}),ye(l,h.localRevision);});},ne=async(p,h)=>{let l;try{l=await p.transport.getDocument(h.collection,h.key);}catch(f){if(V(f)!=="document_not_found")throw f;l=null;}if(!c(p))return null;if(l!==null&&l.etag===null)throw new Error("App State conflict refresh did not return an ETag.");if(l===null&&h.method==="DELETE")return await x(p,h),null;let m=h.method==="PUT"?{body:h.body,collection:h.collection,idempotencyKey:e(),...l===null?{ifNoneMatch:"*"}:{ifMatch:l.etag},key:h.key,localRevision:h.localRevision,method:"PUT"}:{collection:h.collection,idempotencyKey:e(),ifMatch:l.etag,key:h.key,localRevision:h.localRevision,method:"DELETE"};return await P(p,f=>{l!==null&&f.syncToken!==null&&H(f,[{...l.data,etag:l.etag,operation:"upsert"}],f.syncToken),Xe(f,m);})?m:null},ae=async(p,h)=>{let l=h,m=0;for(;c(p);)try{if(l.method==="PUT"){let g=await p.transport.putDocument(l.collection,l.key,l.body,Ye(l));if(!c(p))return;await F(p,l,g);}else {if(await p.transport.deleteDocument(l.collection,l.key,Ye(l)),!c(p))return;await x(p,l);}return}catch(g){if(!c(p))return;let f=V(g);if(l.method==="DELETE"&&f==="document_not_found"){await x(p,l);return}if(f!=="precondition_failed"||m>=t)throw g;m+=1;let v=await ne(p,l);if(v===null)return;l=v;}},ve=async p=>{let h=await s.transaction(p.accountId,Ze);for(let l of h){if(!c(p))return;await ae(p,l);}},et=async p=>{if(await U(p),!!c(p)){try{await ve(p);}catch(h){if(!Re(h))throw h;if(await k(p,true),!c(p))return;await ve(p);}c(p)&&await U(p);}},G=p=>s.transaction(p,Le);return {deleteDocument:async(p,h)=>{let l=y(),m=e();return await s.transaction(l.accountId,g=>{Je(g,p,h,m);}),G(i)},getState:()=>G(i),putDocument:async(p,h,l)=>{let m=y(),g=e(),f=JSON.parse(JSON.stringify(l));return await s.transaction(m.accountId,v=>{We(v,p,h,f,g);}),G(i)},reconcile:()=>{let p=y(),h=u.then(()=>et(p));return u=h.then(()=>{},()=>{}),h.then(()=>G(i))},switchAccount:(p,h)=>p?(a+=1,i=p,d=h,G(p)):Promise.reject(new TypeError("App State reconciliation requires an account ID."))}};var Jo=r=>Qe("server",{...r,defaults:{language:"ar",...r.defaults}});
2
+ export{_ as AppStateProtocolError,O as QuranHttpError,Vt as createAppStateMemoryStore,zt as createAppStateReconciler,Jo as createServerClient,V as getAppStateErrorCode,Et as isAppStateHttpError};//# sourceMappingURL=server.min.mjs.map
3
3
  //# sourceMappingURL=server.min.mjs.map