@nhost/nhost-js
Version:
Nhost JavaScript SDK
2 lines • 26.4 kB
JavaScript
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("../fetch-B_MCWy66.cjs");function s(t){let s="";for(const e of t)s+=String.fromCharCode(e);return btoa(s).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function e(){const t=new Uint8Array(32);return crypto.getRandomValues(t),s(t)}async function a(t){const e=await crypto.subtle.digest("SHA-256",(new TextEncoder).encode(t));return s(new Uint8Array(e))}exports.createAPIClient=(s,e=[])=>{let a=t.createEnhancedFetch(e);return{baseURL:s,pushChainFunction:s=>{e.push(s),a=t.createEnhancedFetch(e)},getJWKs:async e=>{const n=`${s}/.well-known/jwks.json`,r=await a(n,{...e,method:"GET",headers:{...e?.headers}});if(r.status>=300){const s=[412].includes(r.status)?null:await r.text();throw new t.FetchError(s?JSON.parse(s):{},r.status,r.headers)}const o=[204,205,304].includes(r.status)?null:await r.text();return{body:o?JSON.parse(o):{},status:r.status,headers:r.headers}},elevateWebauthn:async e=>{const n=`${s}/elevate/webauthn`,r=await a(n,{...e,method:"POST",headers:{...e?.headers}});if(r.status>=300){const s=[412].includes(r.status)?null:await r.text();throw new t.FetchError(s?JSON.parse(s):{},r.status,r.headers)}const o=[204,205,304].includes(r.status)?null:await r.text();return{body:o?JSON.parse(o):{},status:r.status,headers:r.headers}},verifyElevateWebauthn:async(e,n)=>{const r=`${s}/elevate/webauthn/verify`,o=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(o.status>=300){const s=[412].includes(o.status)?null:await o.text();throw new t.FetchError(s?JSON.parse(s):{},o.status,o.headers)}const i=[204,205,304].includes(o.status)?null:await o.text();return{body:i?JSON.parse(i):{},status:o.status,headers:o.headers}},healthCheckGet:async e=>{const n=`${s}/healthz`,r=await a(n,{...e,method:"GET",headers:{...e?.headers}});if(r.status>=300){const s=[412].includes(r.status)?null:await r.text();throw new t.FetchError(s?JSON.parse(s):{},r.status,r.headers)}const o=[204,205,304].includes(r.status)?null:await r.text();return{body:o?JSON.parse(o):{},status:r.status,headers:r.headers}},healthCheckHead:async e=>{const n=`${s}/healthz`,r=await a(n,{...e,method:"HEAD",headers:{...e?.headers}});if(r.status>=300){const s=[412].includes(r.status)?null:await r.text();throw new t.FetchError(s?JSON.parse(s):{},r.status,r.headers)}return{body:void 0,status:r.status,headers:r.headers}},linkIdToken:async(e,n)=>{const r=`${s}/link/idtoken`,o=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(o.status>=300){const s=[412].includes(o.status)?null:await o.text();throw new t.FetchError(s?JSON.parse(s):{},o.status,o.headers)}const i=[204,205,304].includes(o.status)?null:await o.text();return{body:i?JSON.parse(i):{},status:o.status,headers:o.headers}},changeUserMfa:async e=>{const n=`${s}/mfa/totp/generate`,r=await a(n,{...e,method:"GET",headers:{...e?.headers}});if(r.status>=300){const s=[412].includes(r.status)?null:await r.text();throw new t.FetchError(s?JSON.parse(s):{},r.status,r.headers)}const o=[204,205,304].includes(r.status)?null:await r.text();return{body:o?JSON.parse(o):{},status:r.status,headers:r.headers}},createPAT:async(e,n)=>{const r=`${s}/pat`,o=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(o.status>=300){const s=[412].includes(o.status)?null:await o.text();throw new t.FetchError(s?JSON.parse(s):{},o.status,o.headers)}const i=[204,205,304].includes(o.status)?null:await o.text();return{body:i?JSON.parse(i):{},status:o.status,headers:o.headers}},signInAnonymous:async(e,n)=>{const r=`${s}/signin/anonymous`,o=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(o.status>=300){const s=[412].includes(o.status)?null:await o.text();throw new t.FetchError(s?JSON.parse(s):{},o.status,o.headers)}const i=[204,205,304].includes(o.status)?null:await o.text();return{body:i?JSON.parse(i):{},status:o.status,headers:o.headers}},signInEmailPassword:async(e,n)=>{const r=`${s}/signin/email-password`,o=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(o.status>=300){const s=[412].includes(o.status)?null:await o.text();throw new t.FetchError(s?JSON.parse(s):{},o.status,o.headers)}const i=[204,205,304].includes(o.status)?null:await o.text();return{body:i?JSON.parse(i):{},status:o.status,headers:o.headers}},signInIdToken:async(e,n)=>{const r=`${s}/signin/idtoken`,o=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(o.status>=300){const s=[412].includes(o.status)?null:await o.text();throw new t.FetchError(s?JSON.parse(s):{},o.status,o.headers)}const i=[204,205,304].includes(o.status)?null:await o.text();return{body:i?JSON.parse(i):{},status:o.status,headers:o.headers}},verifySignInMfaTotp:async(e,n)=>{const r=`${s}/signin/mfa/totp`,o=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(o.status>=300){const s=[412].includes(o.status)?null:await o.text();throw new t.FetchError(s?JSON.parse(s):{},o.status,o.headers)}const i=[204,205,304].includes(o.status)?null:await o.text();return{body:i?JSON.parse(i):{},status:o.status,headers:o.headers}},signInOTPEmail:async(e,n)=>{const r=`${s}/signin/otp/email`,o=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(o.status>=300){const s=[412].includes(o.status)?null:await o.text();throw new t.FetchError(s?JSON.parse(s):{},o.status,o.headers)}const i=[204,205,304].includes(o.status)?null:await o.text();return{body:i?JSON.parse(i):{},status:o.status,headers:o.headers}},verifySignInOTPEmail:async(e,n)=>{const r=`${s}/signin/otp/email/verify`,o=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(o.status>=300){const s=[412].includes(o.status)?null:await o.text();throw new t.FetchError(s?JSON.parse(s):{},o.status,o.headers)}const i=[204,205,304].includes(o.status)?null:await o.text();return{body:i?JSON.parse(i):{},status:o.status,headers:o.headers}},signInPasswordlessEmail:async(e,n)=>{const r=`${s}/signin/passwordless/email`,o=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(o.status>=300){const s=[412].includes(o.status)?null:await o.text();throw new t.FetchError(s?JSON.parse(s):{},o.status,o.headers)}const i=[204,205,304].includes(o.status)?null:await o.text();return{body:i?JSON.parse(i):{},status:o.status,headers:o.headers}},signInPasswordlessSms:async(e,n)=>{const r=`${s}/signin/passwordless/sms`,o=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(o.status>=300){const s=[412].includes(o.status)?null:await o.text();throw new t.FetchError(s?JSON.parse(s):{},o.status,o.headers)}const i=[204,205,304].includes(o.status)?null:await o.text();return{body:i?JSON.parse(i):{},status:o.status,headers:o.headers}},verifySignInPasswordlessSms:async(e,n)=>{const r=`${s}/signin/passwordless/sms/otp`,o=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(o.status>=300){const s=[412].includes(o.status)?null:await o.text();throw new t.FetchError(s?JSON.parse(s):{},o.status,o.headers)}const i=[204,205,304].includes(o.status)?null:await o.text();return{body:i?JSON.parse(i):{},status:o.status,headers:o.headers}},signInPAT:async(e,n)=>{const r=`${s}/signin/pat`,o=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(o.status>=300){const s=[412].includes(o.status)?null:await o.text();throw new t.FetchError(s?JSON.parse(s):{},o.status,o.headers)}const i=[204,205,304].includes(o.status)?null:await o.text();return{body:i?JSON.parse(i):{},status:o.status,headers:o.headers}},signInProviderURL:(t,e)=>{const a=e&&Object.entries(e).flatMap((([t,s])=>{if("providerSpecificParams"===t)return"object"!=typeof s||null===s||Array.isArray(s)?[`${t}=${encodeURIComponent(String(s))}`]:Object.entries(s).map((([t,s])=>`${t}=${encodeURIComponent(String(s))}`));if("upstreamParams"===t)return"object"!=typeof s||null===s||Array.isArray(s)?[]:Object.entries(s).map((([t,s])=>`upstreamParams[${encodeURIComponent(t)}]=${encodeURIComponent(String(s))}`));const e=Array.isArray(s)?s.join(","):"object"==typeof s&&null!==s?JSON.stringify(s):String(s);return[`${t}=${encodeURIComponent(e)}`]})).join("&");return a?`${s}/signin/provider/${t}?${a}`:`${s}/signin/provider/${t}`},getProviderTokens:async(e,n)=>{const r=`${s}/signin/provider/${e}/callback/tokens`,o=await a(r,{...n,method:"GET",headers:{...n?.headers}});if(o.status>=300){const s=[412].includes(o.status)?null:await o.text();throw new t.FetchError(s?JSON.parse(s):{},o.status,o.headers)}const i=[204,205,304].includes(o.status)?null:await o.text();return{body:i?JSON.parse(i):{},status:o.status,headers:o.headers}},signInWebauthn:async(e,n)=>{const r=`${s}/signin/webauthn`,o=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(o.status>=300){const s=[412].includes(o.status)?null:await o.text();throw new t.FetchError(s?JSON.parse(s):{},o.status,o.headers)}const i=[204,205,304].includes(o.status)?null:await o.text();return{body:i?JSON.parse(i):{},status:o.status,headers:o.headers}},verifySignInWebauthn:async(e,n)=>{const r=`${s}/signin/webauthn/verify`,o=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(o.status>=300){const s=[412].includes(o.status)?null:await o.text();throw new t.FetchError(s?JSON.parse(s):{},o.status,o.headers)}const i=[204,205,304].includes(o.status)?null:await o.text();return{body:i?JSON.parse(i):{},status:o.status,headers:o.headers}},signOut:async(e,n)=>{const r=`${s}/signout`,o=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(o.status>=300){const s=[412].includes(o.status)?null:await o.text();throw new t.FetchError(s?JSON.parse(s):{},o.status,o.headers)}const i=[204,205,304].includes(o.status)?null:await o.text();return{body:i?JSON.parse(i):{},status:o.status,headers:o.headers}},signUpEmailPassword:async(e,n)=>{const r=`${s}/signup/email-password`,o=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(o.status>=300){const s=[412].includes(o.status)?null:await o.text();throw new t.FetchError(s?JSON.parse(s):{},o.status,o.headers)}const i=[204,205,304].includes(o.status)?null:await o.text();return{body:i?JSON.parse(i):{},status:o.status,headers:o.headers}},signUpWebauthn:async(e,n)=>{const r=`${s}/signup/webauthn`,o=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(o.status>=300){const s=[412].includes(o.status)?null:await o.text();throw new t.FetchError(s?JSON.parse(s):{},o.status,o.headers)}const i=[204,205,304].includes(o.status)?null:await o.text();return{body:i?JSON.parse(i):{},status:o.status,headers:o.headers}},verifySignUpWebauthn:async(e,n)=>{const r=`${s}/signup/webauthn/verify`,o=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(o.status>=300){const s=[412].includes(o.status)?null:await o.text();throw new t.FetchError(s?JSON.parse(s):{},o.status,o.headers)}const i=[204,205,304].includes(o.status)?null:await o.text();return{body:i?JSON.parse(i):{},status:o.status,headers:o.headers}},signUpPasswordlessEmail:async(e,n)=>{const r=`${s}/signup/passwordless/email`,o=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(o.status>=300){const s=[412].includes(o.status)?null:await o.text();throw new t.FetchError(s?JSON.parse(s):{},o.status,o.headers)}const i=[204,205,304].includes(o.status)?null:await o.text();return{body:i?JSON.parse(i):{},status:o.status,headers:o.headers}},signUpOTPEmail:async(e,n)=>{const r=`${s}/signup/otp/email`,o=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(o.status>=300){const s=[412].includes(o.status)?null:await o.text();throw new t.FetchError(s?JSON.parse(s):{},o.status,o.headers)}const i=[204,205,304].includes(o.status)?null:await o.text();return{body:i?JSON.parse(i):{},status:o.status,headers:o.headers}},signUpPasswordlessSms:async(e,n)=>{const r=`${s}/signup/passwordless/sms`,o=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(o.status>=300){const s=[412].includes(o.status)?null:await o.text();throw new t.FetchError(s?JSON.parse(s):{},o.status,o.headers)}const i=[204,205,304].includes(o.status)?null:await o.text();return{body:i?JSON.parse(i):{},status:o.status,headers:o.headers}},signUpIdToken:async(e,n)=>{const r=`${s}/signup/idtoken`,o=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(o.status>=300){const s=[412].includes(o.status)?null:await o.text();throw new t.FetchError(s?JSON.parse(s):{},o.status,o.headers)}const i=[204,205,304].includes(o.status)?null:await o.text();return{body:i?JSON.parse(i):{},status:o.status,headers:o.headers}},signUpProviderURL:(t,e)=>{const a=e&&Object.entries(e).flatMap((([t,s])=>{if("providerSpecificParams"===t)return"object"!=typeof s||null===s||Array.isArray(s)?[`${t}=${encodeURIComponent(String(s))}`]:Object.entries(s).map((([t,s])=>`${t}=${encodeURIComponent(String(s))}`));if("upstreamParams"===t)return"object"!=typeof s||null===s||Array.isArray(s)?[]:Object.entries(s).map((([t,s])=>`upstreamParams[${encodeURIComponent(t)}]=${encodeURIComponent(String(s))}`));const e=Array.isArray(s)?s.join(","):"object"==typeof s&&null!==s?JSON.stringify(s):String(s);return[`${t}=${encodeURIComponent(e)}`]})).join("&");return a?`${s}/signup/provider/${t}?${a}`:`${s}/signup/provider/${t}`},refreshToken:async(e,n)=>{const r=`${s}/token`,o=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(o.status>=300){const s=[412].includes(o.status)?null:await o.text();throw new t.FetchError(s?JSON.parse(s):{},o.status,o.headers)}const i=[204,205,304].includes(o.status)?null:await o.text();return{body:i?JSON.parse(i):{},status:o.status,headers:o.headers}},refreshProviderToken:async(e,n,r)=>{const o=`${s}/token/provider/${e}`,i=await a(o,{...r,method:"POST",headers:{"Content-Type":"application/json",...r?.headers},body:JSON.stringify(n)});if(i.status>=300){const s=[412].includes(i.status)?null:await i.text();throw new t.FetchError(s?JSON.parse(s):{},i.status,i.headers)}const u=[204,205,304].includes(i.status)?null:await i.text();return{body:u?JSON.parse(u):{},status:i.status,headers:i.headers}},verifyToken:async(e,n)=>{const r=`${s}/token/verify`,o=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(o.status>=300){const s=[412].includes(o.status)?null:await o.text();throw new t.FetchError(s?JSON.parse(s):{},o.status,o.headers)}const i=[204,205,304].includes(o.status)?null:await o.text();return{body:i?JSON.parse(i):{},status:o.status,headers:o.headers}},getUser:async e=>{const n=`${s}/user`,r=await a(n,{...e,method:"GET",headers:{...e?.headers}});if(r.status>=300){const s=[412].includes(r.status)?null:await r.text();throw new t.FetchError(s?JSON.parse(s):{},r.status,r.headers)}const o=[204,205,304].includes(r.status)?null:await r.text();return{body:o?JSON.parse(o):{},status:r.status,headers:r.headers}},deanonymizeUser:async(e,n)=>{const r=`${s}/user/deanonymize`,o=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(o.status>=300){const s=[412].includes(o.status)?null:await o.text();throw new t.FetchError(s?JSON.parse(s):{},o.status,o.headers)}const i=[204,205,304].includes(o.status)?null:await o.text();return{body:i?JSON.parse(i):{},status:o.status,headers:o.headers}},changeUserEmail:async(e,n)=>{const r=`${s}/user/email/change`,o=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(o.status>=300){const s=[412].includes(o.status)?null:await o.text();throw new t.FetchError(s?JSON.parse(s):{},o.status,o.headers)}const i=[204,205,304].includes(o.status)?null:await o.text();return{body:i?JSON.parse(i):{},status:o.status,headers:o.headers}},sendVerificationEmail:async(e,n)=>{const r=`${s}/user/email/send-verification-email`,o=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(o.status>=300){const s=[412].includes(o.status)?null:await o.text();throw new t.FetchError(s?JSON.parse(s):{},o.status,o.headers)}const i=[204,205,304].includes(o.status)?null:await o.text();return{body:i?JSON.parse(i):{},status:o.status,headers:o.headers}},verifyChangeUserMfa:async(e,n)=>{const r=`${s}/user/mfa`,o=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(o.status>=300){const s=[412].includes(o.status)?null:await o.text();throw new t.FetchError(s?JSON.parse(s):{},o.status,o.headers)}const i=[204,205,304].includes(o.status)?null:await o.text();return{body:i?JSON.parse(i):{},status:o.status,headers:o.headers}},changeUserPassword:async(e,n)=>{const r=`${s}/user/password`,o=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(o.status>=300){const s=[412].includes(o.status)?null:await o.text();throw new t.FetchError(s?JSON.parse(s):{},o.status,o.headers)}const i=[204,205,304].includes(o.status)?null:await o.text();return{body:i?JSON.parse(i):{},status:o.status,headers:o.headers}},sendPasswordResetEmail:async(e,n)=>{const r=`${s}/user/password/reset`,o=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(o.status>=300){const s=[412].includes(o.status)?null:await o.text();throw new t.FetchError(s?JSON.parse(s):{},o.status,o.headers)}const i=[204,205,304].includes(o.status)?null:await o.text();return{body:i?JSON.parse(i):{},status:o.status,headers:o.headers}},addSecurityKey:async e=>{const n=`${s}/user/webauthn/add`,r=await a(n,{...e,method:"POST",headers:{...e?.headers}});if(r.status>=300){const s=[412].includes(r.status)?null:await r.text();throw new t.FetchError(s?JSON.parse(s):{},r.status,r.headers)}const o=[204,205,304].includes(r.status)?null:await r.text();return{body:o?JSON.parse(o):{},status:r.status,headers:r.headers}},verifyAddSecurityKey:async(e,n)=>{const r=`${s}/user/webauthn/verify`,o=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(o.status>=300){const s=[412].includes(o.status)?null:await o.text();throw new t.FetchError(s?JSON.parse(s):{},o.status,o.headers)}const i=[204,205,304].includes(o.status)?null:await o.text();return{body:i?JSON.parse(i):{},status:o.status,headers:o.headers}},tokenExchange:async(e,n)=>{const r=`${s}/token/exchange`,o=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(o.status>=300){const s=[412].includes(o.status)?null:await o.text();throw new t.FetchError(s?JSON.parse(s):{},o.status,o.headers)}const i=[204,205,304].includes(o.status)?null:await o.text();return{body:i?JSON.parse(i):{},status:o.status,headers:o.headers}},verifyTicketURL:t=>{const e=t&&Object.entries(t).flatMap((([t,s])=>{const e=Array.isArray(s)?s.join(","):"object"==typeof s&&null!==s?JSON.stringify(s):String(s);return[`${t}=${encodeURIComponent(e)}`]})).join("&");return e?`${s}/verify?${e}`:`${s}/verify`},getVersion:async e=>{const n=`${s}/version`,r=await a(n,{...e,method:"GET",headers:{...e?.headers}});if(r.status>=300){const s=[412].includes(r.status)?null:await r.text();throw new t.FetchError(s?JSON.parse(s):{},r.status,r.headers)}const o=[204,205,304].includes(r.status)?null:await r.text();return{body:o?JSON.parse(o):{},status:r.status,headers:r.headers}},getOpenIDConfiguration:async e=>{const n=`${s}/.well-known/openid-configuration`,r=await a(n,{...e,method:"GET",headers:{...e?.headers}});if(r.status>=300){const s=[412].includes(r.status)?null:await r.text();throw new t.FetchError(s?JSON.parse(s):{},r.status,r.headers)}const o=[204,205,304].includes(r.status)?null:await r.text();return{body:o?JSON.parse(o):{},status:r.status,headers:r.headers}},getOAuthAuthorizationServer:async e=>{const n=`${s}/.well-known/oauth-authorization-server`,r=await a(n,{...e,method:"GET",headers:{...e?.headers}});if(r.status>=300){const s=[412].includes(r.status)?null:await r.text();throw new t.FetchError(s?JSON.parse(s):{},r.status,r.headers)}const o=[204,205,304].includes(r.status)?null:await r.text();return{body:o?JSON.parse(o):{},status:r.status,headers:r.headers}},oauth2AuthorizeURL:t=>{const e=t&&Object.entries(t).flatMap((([t,s])=>{const e=Array.isArray(s)?s.join(","):"object"==typeof s&&null!==s?JSON.stringify(s):String(s);return[`${t}=${encodeURIComponent(e)}`]})).join("&");return e?`${s}/oauth2/authorize?${e}`:`${s}/oauth2/authorize`},oauth2AuthorizePostURL:()=>`${s}/oauth2/authorize`,oauth2Token:async(e,n)=>{const r=`${s}/oauth2/token`,o=new URLSearchParams;void 0!==e.grant_type&&o.append("grant_type",String(e.grant_type)),void 0!==e.code&&o.append("code",String(e.code)),void 0!==e.redirect_uri&&o.append("redirect_uri",String(e.redirect_uri)),void 0!==e.client_id&&o.append("client_id",String(e.client_id)),void 0!==e.client_secret&&o.append("client_secret",String(e.client_secret)),void 0!==e.code_verifier&&o.append("code_verifier",String(e.code_verifier)),void 0!==e.refresh_token&&o.append("refresh_token",String(e.refresh_token)),void 0!==e.resource&&o.append("resource",String(e.resource));const i=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded",...n?.headers},body:o.toString()});if(i.status>=300){const s=[412].includes(i.status)?null:await i.text();throw new t.FetchError(s?JSON.parse(s):{},i.status,i.headers)}const u=[204,205,304].includes(i.status)?null:await i.text();return{body:u?JSON.parse(u):{},status:i.status,headers:i.headers}},oauth2UserinfoGet:async e=>{const n=`${s}/oauth2/userinfo`,r=await a(n,{...e,method:"GET",headers:{...e?.headers}});if(r.status>=300){const s=[412].includes(r.status)?null:await r.text();throw new t.FetchError(s?JSON.parse(s):{},r.status,r.headers)}const o=[204,205,304].includes(r.status)?null:await r.text();return{body:o?JSON.parse(o):{},status:r.status,headers:r.headers}},oauth2UserinfoPost:async e=>{const n=`${s}/oauth2/userinfo`,r=await a(n,{...e,method:"POST",headers:{...e?.headers}});if(r.status>=300){const s=[412].includes(r.status)?null:await r.text();throw new t.FetchError(s?JSON.parse(s):{},r.status,r.headers)}const o=[204,205,304].includes(r.status)?null:await r.text();return{body:o?JSON.parse(o):{},status:r.status,headers:r.headers}},oauth2Jwks:async e=>{const n=`${s}/oauth2/jwks`,r=await a(n,{...e,method:"GET",headers:{...e?.headers}});if(r.status>=300){const s=[412].includes(r.status)?null:await r.text();throw new t.FetchError(s?JSON.parse(s):{},r.status,r.headers)}const o=[204,205,304].includes(r.status)?null:await r.text();return{body:o?JSON.parse(o):{},status:r.status,headers:r.headers}},oauth2Revoke:async(e,n)=>{const r=`${s}/oauth2/revoke`,o=new URLSearchParams;void 0!==e.token&&o.append("token",String(e.token)),void 0!==e.token_type_hint&&o.append("token_type_hint",String(e.token_type_hint)),void 0!==e.client_id&&o.append("client_id",String(e.client_id)),void 0!==e.client_secret&&o.append("client_secret",String(e.client_secret));const i=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded",...n?.headers},body:o.toString()});if(i.status>=300){const s=[412].includes(i.status)?null:await i.text();throw new t.FetchError(s?JSON.parse(s):{},i.status,i.headers)}return{body:void 0,status:i.status,headers:i.headers}},oauth2Introspect:async(e,n)=>{const r=`${s}/oauth2/introspect`,o=new URLSearchParams;void 0!==e.token&&o.append("token",String(e.token)),void 0!==e.token_type_hint&&o.append("token_type_hint",String(e.token_type_hint)),void 0!==e.client_id&&o.append("client_id",String(e.client_id)),void 0!==e.client_secret&&o.append("client_secret",String(e.client_secret));const i=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded",...n?.headers},body:o.toString()});if(i.status>=300){const s=[412].includes(i.status)?null:await i.text();throw new t.FetchError(s?JSON.parse(s):{},i.status,i.headers)}const u=[204,205,304].includes(i.status)?null:await i.text();return{body:u?JSON.parse(u):{},status:i.status,headers:i.headers}},oauth2LoginGet:async(e,n)=>{const r=e&&Object.entries(e).flatMap((([t,s])=>{const e=Array.isArray(s)?s.join(","):"object"==typeof s&&null!==s?JSON.stringify(s):String(s);return[`${t}=${encodeURIComponent(e)}`]})).join("&"),o=r?`${s}/oauth2/login?${r}`:`${s}/oauth2/login`,i=await a(o,{...n,method:"GET",headers:{...n?.headers}});if(i.status>=300){const s=[412].includes(i.status)?null:await i.text();throw new t.FetchError(s?JSON.parse(s):{},i.status,i.headers)}const u=[204,205,304].includes(i.status)?null:await i.text();return{body:u?JSON.parse(u):{},status:i.status,headers:i.headers}},oauth2LoginPost:async(e,n)=>{const r=`${s}/oauth2/login`,o=await a(r,{...n,method:"POST",headers:{"Content-Type":"application/json",...n?.headers},body:JSON.stringify(e)});if(o.status>=300){const s=[412].includes(o.status)?null:await o.text();throw new t.FetchError(s?JSON.parse(s):{},o.status,o.headers)}const i=[204,205,304].includes(o.status)?null:await o.text();return{body:i?JSON.parse(i):{},status:o.status,headers:o.headers}}}},exports.generateCodeChallenge=a,exports.generateCodeVerifier=e,exports.generatePKCEPair=async function(){const t=e();return{verifier:t,challenge:await a(t)}};
//# sourceMappingURL=auth.cjs.map