@quranjs/api 3.5.0 → 3.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -0
- package/dist/{index-BgoJducH.d.mts → index-BJ5hWalX.d.mts} +2 -1
- package/dist/{index-BgoJducH.d.ts → index-BJ5hWalX.d.ts} +2 -1
- package/dist/index.d.mts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.min.js +2 -2
- package/dist/index.min.js.map +1 -1
- package/dist/index.min.mjs +2 -2
- package/dist/index.min.mjs.map +1 -1
- package/dist/public.d.mts +3 -3
- package/dist/public.d.ts +3 -3
- package/dist/public.min.js +1 -1
- package/dist/public.min.js.map +1 -1
- package/dist/public.min.mjs +1 -1
- package/dist/public.min.mjs.map +1 -1
- package/dist/{runtime-utils-CpHQzQN3.d.mts → runtime-utils-BG7Q7TVB.d.mts} +1 -1
- package/dist/{runtime-utils-XwV859WP.d.ts → runtime-utils-z2Ga9MgK.d.ts} +1 -1
- package/dist/server.d.mts +18 -3
- package/dist/server.d.ts +18 -3
- package/dist/server.min.js +2 -2
- package/dist/server.min.js.map +1 -1
- package/dist/server.min.mjs +2 -2
- package/dist/server.min.mjs.map +1 -1
- package/dist/{verses-CMsmJnhG.d.ts → verses-CWixKr_f.d.mts} +43 -6
- package/dist/{verses-BiAZ4lTB.d.mts → verses-gs60vEyE.d.ts} +43 -6
- package/package.json +3 -3
package/dist/public.min.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
'use strict';var L=require('humps');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var L__default=/*#__PURE__*/_interopDefault(L);var b={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"}},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"},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"},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"},postsControllerGetMyPostsCountWithinRange:{auth:"user",method:"get",path:"/v1/posts/count-within-range"},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"}}};var c=b;var T=(o,t)=>{if(!(o.body===void 0||o.body===null))return typeof o.body=="string"||o.body instanceof URLSearchParams?(o.contentType&&t.set("Content-Type",o.contentType),o.body):(t.set("Content-Type",o.contentType??"application/json"),JSON.stringify(o.body))},S=(o,t)=>{let r=o.expiresIn??o.expires_in,s=o.accessToken??o.access_token,e=o.idToken??o.id_token??t?.idToken,n=o.refreshToken??o.refresh_token??t?.refreshToken,a=o.tokenType??o.token_type??t?.tokenType,i=o.scope??t?.scope,p=r?Date.now()+r*1e3:t?.expiresAt;return {accessToken:s,expiresAt:p,idToken:e,refreshToken:n,scope:i,tokenType:a}};var P=(o,t,r)=>({...r,operationName:r.operationName??t,service:r.service??o.service,tags:r.tags??[],version:r.version??o.version});var O={delete:"remove",get:"list",patch:"update",post:"create",put:"update"},d=o=>{let t=o.replace(/([a-z0-9])([A-Z])/g,"$1 $2").replace(/[^A-Za-z0-9]+/g," ").trim().split(/\s+/).filter(Boolean);return t.length===0?"misc":t.map((r,s)=>{let e=r.toLowerCase();return s===0?e:e.charAt(0).toUpperCase()+e.slice(1)}).join("")},M=o=>{let t=d(o);return t.charAt(0).toUpperCase()+t.slice(1)},h=o=>o.startsWith("{")&&o.endsWith("}"),w=o=>{let t=o.split("/").filter(Boolean);return t[0]?.match(/^v\d+$/)?t.slice(1):t},N=o=>{let t=w(o.path),r=t.at(-1),s=t.filter(a=>!h(a)),e=s.at(-1),n=s[0];return t.length===1?O[o.method]:t.length===2&&r&&h(r)?o.method==="get"?"get":o.method==="delete"?"remove":"update":r&&!h(r)&&e?e===n?`${O[o.method]}ById`:d(e):d(o.operationName)},m=(o,t)=>{let r={};for(let[s,e]of Object.entries(t.operations)){let n=P(t,s,e);r[s]=a=>o.requestOperation(n,a);}return r},y=(o,t)=>{let r={};for(let[s,e]of Object.entries(o.operations)){let n=P(o,s,e),a=w(n.path).filter(v=>!h(v)),i=d(a[0]??"misc"),p=N(n),u=r[i]??{},l=p;u[l]&&(l=`${p}${M(s)}`),u[l]=t[s],r[i]=u;}return r};var{decamelize:R}=L__default.default,k=o=>o.startsWith("/")?o:`/${o}`,C=o=>o.endsWith("/")?o.slice(0,-1):o;var g=(o,t)=>o.replace(/\{([^}]+)\}/g,(r,s)=>{let e=t?.[s];if(e===void 0)throw new Error(`Missing path parameter: ${s}`);return encodeURIComponent(String(e))}),E=o=>o.replace(/(^|\/):([A-Za-z0-9_]+)/g,"$1{$2}"),A=["wordFields","translationFields","fields"],G=new Set([...A,...A.map(o=>R(o))]),H=new Set(["navigationalResultsNumber","pageSize","versesResultsNumber"]),U=(o,t={})=>{if(!o)return "";let r=new URLSearchParams;for(let[s,e]of Object.entries(o)){if(e===void 0)continue;let n=t.preserveCase||H.has(s)?s:R(s);if(G.has(s)||G.has(n)){let a=Object.entries(e).filter(([,i])=>i).map(([i])=>R(i));a.length>0&&r.set(n,a.join(","));continue}typeof e=="string"?r.set(n,e):typeof e=="number"||typeof e=="boolean"?r.set(n,e.toString()):Array.isArray(e)&&r.set(n,e.join(","));}return r.size===0?"":`?${r.toString()}`};var j=o=>!!o&&typeof o=="object"&&!Array.isArray(o),$=o=>j(o)?typeof o.body=="string"&&typeof o.draft=="boolean"&&Array.isArray(o.references)&&Array.isArray(o.mentions):false,x=(o,t)=>({...o,create:n=>$(n)?t("POST","/v1/posts",{body:{post:n}}):t("POST","/v1/posts",n),get:(n,a)=>typeof n=="string"||typeof n=="number"?t("GET","/v1/posts/{id}",{path:{id:n},query:a}):t("GET","/v1/posts/{id}",n),update:(n,a)=>a!==void 0?t("PATCH","/v1/posts/{id}",{body:a,path:{id:n}}):t("PATCH","/v1/posts/{id}",n)});var I={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"},q={auth:"/v1",content:"/api/v4",oauth2:"",quranReflect:"/v1",search:"/v1"},B={auth:"/auth/v1",content:"/content/api/v4",oauth2:"",quranReflect:"/quran-reflect/v1",search:"/search/v1"},Q={auth:["/auth/v1","/v1"],content:["/content/api/v4","/api/v4"],oauth2:[],quranReflect:["/quran-reflect/v1","/v1"],search:["/search/v1","/v1"]};var{camelizeKeys:K}=L__default.default,f=class{constructor(t){this.config=t;this.userSession=t.userSession;}userSession;clearCachedTokens(){}getFetch(){let t=this.config.fetch??globalThis.fetch;if(typeof t!="function")throw new Error("No fetch function available. Please provide a fetch implementation or ensure global fetch is available.");return t}async getUserSession(){let t=await this.config.storage?.getSession?.();return t!==void 0?t:this.userSession??null}async setUserSession(t){if(!this.config.storage){this.userSession=t;return}if(!t){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?.(t),this.userSession=t;}buildServiceUrl(t,r,s){let{baseUrl:e,usesGateway:n}=this.resolveServiceBaseUrl(t),a=this.normalizeServicePath(t,r,n);return `${e}${a}${U(s,{preserveCase:t==="auth"||t==="quranReflect"})}`}async requestOperation(t,r){return this.request(t.service,g(t.path,r?.path),r?.query,{...r,auth:r?.auth==="auto"||!r?.auth?t.auth:r.auth,method:r?.method??t.method.toUpperCase(),path:void 0})}async request(t,r,s,e={}){if(e.basicAuth)throw new Error("client_secret is server-only. Use @quranjs/api/server.");let n=this.resolveAuthMode(t,e.auth),a=this.buildServiceUrl(t,r,s),i=new Headers(e.headers),p=T(e,i);t!=="oauth2"&&i.set("x-client-id",this.config.clientId),await this.applyAuthenticationHeaders(t,n,i,e);let u=await this.getFetch()(a,{body:p,headers:i,method:e.method??"GET"});if(!u.ok)throw new Error(`${u.status} ${u.statusText}`);if(u.status===204)return;if(!(u.headers.get("content-type")??"").includes("application/json"))return await u.text();let v=await u.json();return K(v)}resolveAuthMode(t,r="auto"){if(r!=="auto"){if(r==="app")throw new Error("This API requires @quranjs/api/server or a backend. Content and search are server-side for confidential clients.");return r}return t==="auth"||t==="quranReflect"?"user":"none"}async applyAuthenticationHeaders(t,r,s,e){if(e.accessToken){this.setTokenHeaders(t,s,e.accessToken);return}if(r==="none")return;let n=await this.getUserSession();if(!n?.accessToken)throw new Error("This operation requires a user session. Sign in first or use @quranjs/api/server.");this.setTokenHeaders(t,s,n.accessToken);}setTokenHeaders(t,r,s){if(t==="oauth2"){r.set("Authorization",`Bearer ${s}`);return}r.set("x-auth-token",s);}resolveServiceBaseUrl(t){let{services:r}=this.config,s=t==="auth"?r?.authBaseUrl:t==="quranReflect"?r?.quranReflectBaseUrl:r?.oauth2BaseUrl??r?.tokenHost;return s?{baseUrl:C(s),usesGateway:false}:r?.gatewayUrl&&t!=="oauth2"?{baseUrl:C(r.gatewayUrl),usesGateway:true}:{baseUrl:I[t],usesGateway:false}}normalizeServicePath(t,r,s){let e=k(E(r));for(let a of Q[t])if(e.startsWith(a)){e=k(e.slice(a.length));break}let n=s?B[t]:q[t];return e.startsWith(n)||n.length===0?e:`${n}${e}`}};var V="This API requires @quranjs/api/server or a backend. Content and search are server-side for confidential clients.",W="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 }.",_=(o,t)=>(r,s,e)=>o.request(t,g(s,e?.path),e?.query,{...e,auth:"user",method:r,path:void 0,query:void 0}),X=o=>{let t=m(o,c.auth.v1),r=y(c.auth.v1,t),s=_(o,"auth");return {...r,collections:{...r.collections,addBookmark:(e,n)=>s("POST","/v1/collections/{collectionId}/bookmarks",{body:n,path:{collectionId:e}}),create:e=>s("POST","/v1/collections",{body:e}),get:(e,n)=>s("GET","/v1/collections/{collectionId}",{path:{collectionId:e},query:n}),list:e=>s("GET","/v1/collections",{query:e}),listAll:e=>s("GET","/v1/collections/all",{query:e}),remove:e=>s("DELETE","/v1/collections/{collectionId}",{path:{collectionId:e}}),removeBookmark:(e,n)=>s("DELETE","/v1/collections/{collectionId}/bookmarks/{bookmarkId}",{path:{bookmarkId:n,collectionId:e}}),update:(e,n)=>s("POST","/v1/collections/{collectionId}",{body:n,path:{collectionId:e}})},bookmarks:{...r.bookmarks,create:e=>s("POST","/v1/bookmarks",{body:e}),get:async e=>{if(typeof e=="string")throw new Error(W);return s("GET","/v1/bookmarks/bookmark",{query:e})},list:e=>s("GET","/v1/bookmarks",{query:e}),listCollections:e=>s("GET","/v1/bookmarks/collections",{query:e}),listRange:e=>s("GET","/v1/bookmarks/ayahs-range",{query:e}),remove:e=>s("DELETE","/v1/bookmarks/{bookmarkId}",{path:{bookmarkId:e}})},goals:{...r.goals,create:e=>s("POST","/v1/goals",{body:e}),estimate:e=>s("GET","/v1/goals/estimate",{query:e}),getTodaysPlan:e=>s("GET","/v1/goals/get-todays-plan",{query:e}),remove:e=>s("DELETE","/v1/goals/{id}",{path:{id:e}}),update:(e,n)=>s("PUT","/v1/goals/{id}",{body:n,path:{id:e}})},notes:{...r.notes,create:e=>s("POST","/v1/notes",{body:e}),get:e=>s("GET","/v1/notes/{noteId}",{path:{noteId:e}}),list:e=>s("GET","/v1/notes",{query:e}),listByAttachedEntity:e=>s("GET","/v1/notes/by-attached-entity",{query:e}),listByRange:e=>s("GET","/v1/notes/by-range",{query:e}),listByVerseKey:(e,n)=>s("GET","/v1/notes/by-verse/{verseKey}",{path:{verseKey:e},query:n}),publish:(e,n)=>s("POST","/v1/notes/{noteId}/publish",{body:n,path:{noteId:e}}),remove:e=>s("DELETE","/v1/notes/{noteId}",{path:{noteId:e}}),update:(e,n)=>s("PATCH","/v1/notes/{noteId}",{body:n,path:{noteId:e}})},preferences:{...r.preferences,bulkUpdate:e=>s("POST","/v1/preferences/bulk",{body:e}),get:e=>s("GET","/v1/preferences",{query:e}),update:e=>s("POST","/v1/preferences",{body:e})},raw:t,readingSessions:{...r.readingSessions,create:e=>s("POST","/v1/reading-sessions",{body:e}),list:e=>s("GET","/v1/reading-sessions",{query:e})}}},Y=o=>{let t=m(o,c.quranReflect.v1),r=y(c.quranReflect.v1,t);return {comments:r.comments??{},posts:x(r.posts??{},_(o,"quranReflect")),raw:t,rooms:r.rooms??{},tags:r.tags??{},users:r.users??{}}},J=(o,t)=>{let r=m(o,c.oauth2.v1),s=async(e,n={})=>{if(t.clientType!=="public")throw new Error("This OAuth2 exchange requires a backend because your client is confidential.");if(n.requiresRefreshToken&&!e.get("refresh_token"))throw new Error("Missing refresh token.");e.set("client_id",t.clientId);let a=e.get("refresh_token")??void 0,i=n.requiresRefreshToken?await o.getUserSession():null,p=n.requiresRefreshToken&&a?{...i??{},refreshToken:a}:i,u=await o.request("oauth2","/oauth2/token",void 0,{auth:"none",body:e,contentType:"application/x-www-form-urlencoded",method:"POST"});return await o.setUserSession(S(u,p)),u};return {authorizeUrl:e=>o.buildServiceUrl("oauth2","/oauth2/auth",e),exchangeCode:e=>{let n=new URLSearchParams({code:e.code,grant_type:"authorization_code",redirect_uri:e.redirectUri});return e.codeVerifier&&n.set("code_verifier",e.codeVerifier),e.scope&&n.set("scope",e.scope),s(n)},getUserInfo:e=>o.request("oauth2","/userinfo",void 0,{accessToken:e,auth:"user",method:"GET"}),introspect:()=>{throw new Error("Token introspection requires @quranjs/api/server or a backend.")},logout:e=>o.request("oauth2","/oauth2/sessions/logout",e,{auth:"none",method:"GET"}),raw:r,refresh:async e=>{let n=await o.getUserSession(),a=new URLSearchParams({grant_type:"refresh_token",refresh_token:e??n?.refreshToken??""});return s(a,{requiresRefreshToken:true})}}},Z=()=>{let o=()=>Promise.reject(new Error(V)),t=new Proxy(o,{apply(){return Promise.reject(new Error(V))},get(r,s){if(s!=="then")return t}});return t},F=o=>{let t=new f(o);t.getFetch();let r=X(t),s=Y(t),e=J(t,o),n=Z(),a={auth:{v1:r.raw},content:{v4:n},oauth2:{v1:e.raw},quranReflect:{v1:s.raw},search:{v1:n}};return {answers:n,audio:n,auth:{...r,v1:r},chapters:n,clearCachedTokens:()=>t.clearCachedTokens(),content:n,getUserSession:()=>t.getUserSession(),hadithReferences:n,juzs:n,oauth2:{...e,v1:e},quranReflect:{...s,v1:s},raw:a,resources:n,search:n,verses:n}};var Te=o=>{if(o.clientSecret)throw new Error("client_secret is server-only. Use @quranjs/api/server.");return F(o)};
|
|
1
|
+
'use strict';var j=require('humps');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var j__default=/*#__PURE__*/_interopDefault(j);var b={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"}},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"}}};var l=b;var T=(o,t)=>{if(!(o.body===void 0||o.body===null))return typeof o.body=="string"||o.body instanceof URLSearchParams?(o.contentType&&t.set("Content-Type",o.contentType),o.body):(t.set("Content-Type",o.contentType??"application/json"),JSON.stringify(o.body))},S=(o,t)=>{let r=o.expiresIn??o.expires_in,s=o.accessToken??o.access_token,e=o.idToken??o.id_token??t?.idToken,n=o.refreshToken??o.refresh_token??t?.refreshToken,a=o.tokenType??o.token_type??t?.tokenType,i=o.scope??t?.scope,p=r?Date.now()+r*1e3:t?.expiresAt;return {accessToken:s,expiresAt:p,idToken:e,refreshToken:n,scope:i,tokenType:a}};var P=(o,t,r)=>({...r,operationName:r.operationName??t,service:r.service??o.service,tags:r.tags??[],version:r.version??o.version});var O={delete:"remove",get:"list",patch:"update",post:"create",put:"update"},d=o=>{let t=o.replace(/([a-z0-9])([A-Z])/g,"$1 $2").replace(/[^A-Za-z0-9]+/g," ").trim().split(/\s+/).filter(Boolean);return t.length===0?"misc":t.map((r,s)=>{let e=r.toLowerCase();return s===0?e:e.charAt(0).toUpperCase()+e.slice(1)}).join("")},M=o=>{let t=d(o);return t.charAt(0).toUpperCase()+t.slice(1)},h=o=>o.startsWith("{")&&o.endsWith("}"),w=o=>{let t=o.split("/").filter(Boolean);return t[0]?.match(/^v\d+$/)?t.slice(1):t},N=o=>{let t=w(o.path),r=t.at(-1),s=t.filter(a=>!h(a)),e=s.at(-1),n=s[0];return t.length===1?O[o.method]:t.length===2&&r&&h(r)?o.method==="get"?"get":o.method==="delete"?"remove":"update":r&&!h(r)&&e?e===n?`${O[o.method]}ById`:d(e):d(o.operationName)},m=(o,t)=>{let r={};for(let[s,e]of Object.entries(t.operations)){let n=P(t,s,e);r[s]=a=>o.requestOperation(n,a);}return r},y=(o,t)=>{let r={};for(let[s,e]of Object.entries(o.operations)){let n=P(o,s,e),a=w(n.path).filter(v=>!h(v)),i=d(a[0]??"misc"),p=N(n),u=r[i]??{},c=p;u[c]&&(c=`${p}${M(s)}`),u[c]=t[s],r[i]=u;}return r};var{decamelize:R}=j__default.default,C=o=>o.startsWith("/")?o:`/${o}`,k=o=>o.endsWith("/")?o.slice(0,-1):o;var g=(o,t)=>o.replace(/\{([^}]+)\}/g,(r,s)=>{let e=t?.[s];if(e===void 0)throw new Error(`Missing path parameter: ${s}`);return encodeURIComponent(String(e))}),E=o=>o.replace(/(^|\/):([A-Za-z0-9_]+)/g,"$1{$2}"),A=["wordFields","translationFields","fields"],G=new Set([...A,...A.map(o=>R(o))]),L=new Set(["navigationalResultsNumber","pageSize","versesResultsNumber"]),U=(o,t={})=>{if(!o)return "";let r=new URLSearchParams;for(let[s,e]of Object.entries(o)){if(e===void 0)continue;let n=t.preserveCase||L.has(s)?s:R(s);if(G.has(s)||G.has(n)){let a=Object.entries(e).filter(([,i])=>i).map(([i])=>R(i));a.length>0&&r.set(n,a.join(","));continue}typeof e=="string"?r.set(n,e):typeof e=="number"||typeof e=="boolean"?r.set(n,e.toString()):Array.isArray(e)&&r.set(n,e.join(","));}return r.size===0?"":`?${r.toString()}`};var H=o=>!!o&&typeof o=="object"&&!Array.isArray(o),$=o=>H(o)?typeof o.body=="string"&&typeof o.draft=="boolean"&&Array.isArray(o.references)&&Array.isArray(o.mentions):false,q=(o,t)=>({...o,create:n=>$(n)?t("POST","/v1/posts",{body:{post:n}}):t("POST","/v1/posts",n),get:(n,a)=>typeof n=="string"||typeof n=="number"?t("GET","/v1/posts/{id}",{path:{id:n},query:a}):t("GET","/v1/posts/{id}",n),update:(n,a)=>a!==void 0?t("PATCH","/v1/posts/{id}",{body:a,path:{id:n}}):t("PATCH","/v1/posts/{id}",n)});var 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"},x={analytics:"/v1",auth:"/v1",content:"/api/v4",oauth2:"",quranReflect:"/v1",search:"/v1"},B={analytics:"/analytics/v1",auth:"/auth/v1",content:"/content/api/v4",oauth2:"",quranReflect:"/quran-reflect/v1",search:"/search/v1"},Q={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:K}=j__default.default,f=class{constructor(t){this.config=t;this.userSession=t.userSession;}userSession;clearCachedTokens(){}getFetch(){let t=this.config.fetch??globalThis.fetch;if(typeof t!="function")throw new Error("No fetch function available. Please provide a fetch implementation or ensure global fetch is available.");return t}async getUserSession(){let t=await this.config.storage?.getSession?.();return t!==void 0?t:this.userSession??null}async setUserSession(t){if(!this.config.storage){this.userSession=t;return}if(!t){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?.(t),this.userSession=t;}buildServiceUrl(t,r,s){let{baseUrl:e,usesGateway:n}=this.resolveServiceBaseUrl(t),a=this.normalizeServicePath(t,r,n);return `${e}${a}${U(s,{preserveCase:t==="auth"||t==="quranReflect"})}`}async requestOperation(t,r){return this.request(t.service,g(t.path,r?.path),r?.query,{...r,auth:r?.auth==="auto"||!r?.auth?t.auth:r.auth,method:r?.method??t.method.toUpperCase(),path:void 0})}async request(t,r,s,e={}){if(e.basicAuth)throw new Error("client_secret is server-only. Use @quranjs/api/server.");let n=this.resolveAuthMode(t,e.auth),a=this.buildServiceUrl(t,r,s),i=new Headers(e.headers),p=T(e,i);t!=="oauth2"&&i.set("x-client-id",this.config.clientId),await this.applyAuthenticationHeaders(t,n,i,e);let u=await this.getFetch()(a,{body:p,headers:i,method:e.method??"GET"});if(!u.ok)throw new Error(`${u.status} ${u.statusText}`);if(u.status===204)return;if(!(u.headers.get("content-type")??"").includes("application/json"))return await u.text();let v=await u.json();return K(v)}resolveAuthMode(t,r="auto"){if(r!=="auto"){if(r==="app")throw new Error("This API requires @quranjs/api/server or a backend. Content and search are server-side for confidential clients.");return r}return t==="auth"||t==="quranReflect"?"user":"none"}async applyAuthenticationHeaders(t,r,s,e){if(e.accessToken){this.setTokenHeaders(t,s,e.accessToken);return}if(r==="none")return;let n=await this.getUserSession();if(!n?.accessToken)throw new Error("This operation requires a user session. Sign in first or use @quranjs/api/server.");this.setTokenHeaders(t,s,n.accessToken);}setTokenHeaders(t,r,s){if(t==="oauth2"){r.set("Authorization",`Bearer ${s}`);return}r.set("x-auth-token",s);}resolveServiceBaseUrl(t){let{services:r}=this.config,s=t==="auth"?r?.authBaseUrl:t==="quranReflect"?r?.quranReflectBaseUrl:r?.oauth2BaseUrl??r?.tokenHost;return s?{baseUrl:k(s),usesGateway:false}:r?.gatewayUrl&&t!=="oauth2"?{baseUrl:k(r.gatewayUrl),usesGateway:true}:{baseUrl:I[t],usesGateway:false}}normalizeServicePath(t,r,s){let e=C(E(r));for(let a of Q[t])if(e.startsWith(a)){e=C(e.slice(a.length));break}let n=s?B[t]:x[t];return e.startsWith(n)||n.length===0?e:`${n}${e}`}};var V="This API requires @quranjs/api/server or a backend. Content and search are server-side for confidential clients.",W="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 }.",_=(o,t)=>(r,s,e)=>o.request(t,g(s,e?.path),e?.query,{...e,auth:"user",method:r,path:void 0,query:void 0}),J=o=>{let t=m(o,l.auth.v1),r=y(l.auth.v1,t),s=_(o,"auth");return {...r,collections:{...r.collections,addBookmark:(e,n)=>s("POST","/v1/collections/{collectionId}/bookmarks",{body:n,path:{collectionId:e}}),create:e=>s("POST","/v1/collections",{body:e}),get:(e,n)=>s("GET","/v1/collections/{collectionId}",{path:{collectionId:e},query:n}),list:e=>s("GET","/v1/collections",{query:e}),listAll:e=>s("GET","/v1/collections/all",{query:e}),remove:e=>s("DELETE","/v1/collections/{collectionId}",{path:{collectionId:e}}),removeBookmark:(e,n)=>s("DELETE","/v1/collections/{collectionId}/bookmarks/{bookmarkId}",{path:{bookmarkId:n,collectionId:e}}),update:(e,n)=>s("POST","/v1/collections/{collectionId}",{body:n,path:{collectionId:e}})},bookmarks:{...r.bookmarks,create:e=>s("POST","/v1/bookmarks",{body:e}),get:async e=>{if(typeof e=="string")throw new Error(W);return s("GET","/v1/bookmarks/bookmark",{query:e})},list:e=>s("GET","/v1/bookmarks",{query:e}),listCollections:e=>s("GET","/v1/bookmarks/collections",{query:e}),listRange:e=>s("GET","/v1/bookmarks/ayahs-range",{query:e}),remove:e=>s("DELETE","/v1/bookmarks/{bookmarkId}",{path:{bookmarkId:e}})},goals:{...r.goals,create:e=>s("POST","/v1/goals",{body:e}),estimate:e=>s("GET","/v1/goals/estimate",{query:e}),getTodaysPlan:e=>s("GET","/v1/goals/get-todays-plan",{query:e}),remove:e=>s("DELETE","/v1/goals/{id}",{path:{id:e}}),update:(e,n)=>s("PUT","/v1/goals/{id}",{body:n,path:{id:e}})},notes:{...r.notes,create:e=>s("POST","/v1/notes",{body:e}),get:e=>s("GET","/v1/notes/{noteId}",{path:{noteId:e}}),list:e=>s("GET","/v1/notes",{query:e}),listByAttachedEntity:e=>s("GET","/v1/notes/by-attached-entity",{query:e}),listByRange:e=>s("GET","/v1/notes/by-range",{query:e}),listByVerseKey:(e,n)=>s("GET","/v1/notes/by-verse/{verseKey}",{path:{verseKey:e},query:n}),publish:(e,n)=>s("POST","/v1/notes/{noteId}/publish",{body:n,path:{noteId:e}}),remove:e=>s("DELETE","/v1/notes/{noteId}",{path:{noteId:e}}),update:(e,n)=>s("PATCH","/v1/notes/{noteId}",{body:n,path:{noteId:e}})},preferences:{...r.preferences,bulkUpdate:e=>s("POST","/v1/preferences/bulk",{body:e}),get:e=>s("GET","/v1/preferences",{query:e}),update:e=>s("POST","/v1/preferences",{body:e})},raw:t,readingSessions:{...r.readingSessions,create:e=>s("POST","/v1/reading-sessions",{body:e}),list:e=>s("GET","/v1/reading-sessions",{query:e})}}},X=o=>{let t=m(o,l.quranReflect.v1),r=y(l.quranReflect.v1,t);return {comments:r.comments??{},posts:q(r.posts??{},_(o,"quranReflect")),raw:t,rooms:r.rooms??{},tags:r.tags??{},users:r.users??{}}},Y=(o,t)=>{let r=m(o,l.oauth2.v1),s=async(e,n={})=>{if(t.clientType!=="public")throw new Error("This OAuth2 exchange requires a backend because your client is confidential.");if(n.requiresRefreshToken&&!e.get("refresh_token"))throw new Error("Missing refresh token.");e.set("client_id",t.clientId);let a=e.get("refresh_token")??void 0,i=n.requiresRefreshToken?await o.getUserSession():null,p=n.requiresRefreshToken&&a?{...i??{},refreshToken:a}:i,u=await o.request("oauth2","/oauth2/token",void 0,{auth:"none",body:e,contentType:"application/x-www-form-urlencoded",method:"POST"});return await o.setUserSession(S(u,p)),u};return {authorizeUrl:e=>o.buildServiceUrl("oauth2","/oauth2/auth",e),exchangeCode:e=>{let n=new URLSearchParams({code:e.code,grant_type:"authorization_code",redirect_uri:e.redirectUri});return e.codeVerifier&&n.set("code_verifier",e.codeVerifier),e.scope&&n.set("scope",e.scope),s(n)},getUserInfo:e=>o.request("oauth2","/userinfo",void 0,{accessToken:e,auth:"user",method:"GET"}),introspect:()=>{throw new Error("Token introspection requires @quranjs/api/server or a backend.")},logout:e=>o.request("oauth2","/oauth2/sessions/logout",e,{auth:"none",method:"GET"}),raw:r,refresh:async e=>{let n=await o.getUserSession(),a=new URLSearchParams({grant_type:"refresh_token",refresh_token:e??n?.refreshToken??""});return s(a,{requiresRefreshToken:true})}}},Z=()=>{let o=()=>Promise.reject(new Error(V)),t=new Proxy(o,{apply(){return Promise.reject(new Error(V))},get(r,s){if(s!=="then")return t}});return t},F=o=>{let t=new f(o);t.getFetch();let r=J(t),s=X(t),e=Y(t,o),n=Z(),a={auth:{v1:r.raw},content:{v4:n},oauth2:{v1:e.raw},quranReflect:{v1:s.raw},search:{v1:n}};return {answers:n,audio:n,auth:{...r,v1:r},chapters:n,clearCachedTokens:()=>t.clearCachedTokens(),content:n,getUserSession:()=>t.getUserSession(),hadithReferences:n,juzs:n,oauth2:{...e,v1:e},quranReflect:{...s,v1:s},raw:a,resources:n,search:n,verses:n}};var Te=o=>{if(o.clientSecret)throw new Error("client_secret is server-only. Use @quranjs/api/server.");return F(o)};
|
|
2
2
|
exports.createPublicClient=Te;//# sourceMappingURL=public.min.js.map
|
|
3
3
|
//# sourceMappingURL=public.min.js.map
|