@nhost/nhost-js 4.4.0 → 4.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/nhost-js/auth.cjs +1 -1
- package/dist/nhost-js/auth.cjs.map +1 -1
- package/dist/nhost-js/auth.js +307 -1
- package/dist/nhost-js/auth.js.map +1 -1
- package/dist/nhost-js.umd.js +1 -1
- package/dist/nhost-js.umd.js.map +1 -1
- package/dist/src/auth/client.d.ts +628 -0
- package/dist/src/auth/client.d.ts.map +1 -1
- package/dist/src/auth/client.js +362 -0
- package/dist/src/auth/client.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
package/dist/nhost-js.umd.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(t,s){"object"==typeof exports&&"undefined"!=typeof module?s(exports):"function"==typeof define&&define.amd?define(["exports"],s):s((t="undefined"!=typeof globalThis?globalThis:t||self).NhostJs={})}(this,(function(t){"use strict";function s(t=[]){return t.reduceRight(((t,s)=>s(t)),fetch)}class e extends Error{body;status;headers;constructor(t,s,e){super(function(t){if(t&&"string"==typeof t)return t;if(t&&"object"==typeof t){const s=t;if("message"in s&&"string"==typeof s.message)return s.message;if("error"in s&&"string"==typeof s.error)return s.error;if("error"in s&&s.error&&"object"==typeof s.error){const t=s.error;if("message"in t&&"string"==typeof t.message)return t.message}if("errors"in s&&Array.isArray(s.errors)){const t=s.errors.filter((t=>"object"==typeof t&&null!==t&&"message"in t&&"string"==typeof t.message)).map((t=>t.message));if(t.length>0)return t.join(", ")}}return"An unexpected error occurred"}(t)),this.body=t,this.status=s,this.headers=e}}const a=t=>s=>async(e,a={})=>{const r=new Headers(a.headers||{});if(r.has("Authorization"))return s(e,a);const i=t.get();if(i?.accessToken){const t={...a,headers:n(r,i)};return s(e,t)}return s(e,a)};function n(t,s){return s.accessToken&&t.set("Authorization",`Bearer ${s.accessToken}`),t}const r="undefined"!=typeof navigator&&navigator.locks?navigator.locks:new class{async request(t,s,e){return e()}},i=async(t,s,e=60)=>{try{return await o(t,s,e)}catch(a){try{return console.warn("error refreshing session, retrying:",a),await o(t,s,e)}catch(n){const t=n;return 401===t?.status&&(console.error("session probably expired"),s.remove()),null}}},o=async(t,s,e=60)=>{const{session:a,needsRefresh:n}=await r.request("nhostSessionLock",{mode:"shared"},(async()=>u(s,e)));if(!a)return null;if(!n)return a;return await r.request("nhostSessionLock",{mode:"exclusive"},(async()=>{const{session:a,needsRefresh:n,sessionExpired:r}=u(s,e);if(!a)return null;if(!n)return a;try{const e=await t.refreshToken({refreshToken:a.refreshToken});return s.set(e.body),e.body}catch(i){if(!r)return a;throw i}}))},u=(t,s=60)=>{const e=t.get();if(!e)return{session:null,needsRefresh:!1,sessionExpired:!1};if(!e.decodedToken||!e.decodedToken.exp)return{session:e,needsRefresh:!0,sessionExpired:!0};if(0===s)return{session:e,needsRefresh:!0,sessionExpired:!1};const a=Date.now();return e.decodedToken.exp-a>1e3*s?{session:e,needsRefresh:!1,sessionExpired:!1}:{session:e,needsRefresh:!0,sessionExpired:e.decodedToken.exp<a}},d=(t,s,e)=>{const{marginSeconds:a=60}={};return e=>async(n,r={})=>{if(function(t,s){const e=new Headers(s.headers||{});if(e.has("Authorization"))return!0;if(t.endsWith("/v1/token"))return!0;return!1}(n,r))return e(n,r);try{await i(t,s,a)}catch{}return e(n,r)}};const c=t=>s=>async(e,a)=>{const n=await s(e,a);try{if(e.endsWith("/signout"))return t.remove(),n;if(e.endsWith("/token")||e.includes("/signin/")||e.includes("/signup/")){const s=n.clone(),e=await s.json().catch((()=>null));if(e){const s=(t=>"string"==typeof t?null:"session"in t?t.session||null:"accessToken"in t&&"refreshToken"in t&&"user"in t?t:null)(e);s?.accessToken&&s.refreshToken&&t.set(s)}}}catch(r){console.warn("Error in session response middleware:",r)}return n},h=t=>{const s=t.split(".");if(3!==s.length||!s[1])throw new Error("Invalid access token format");const e=JSON.parse((t=>{let s=t.replace(/-/g,"+").replace(/_/g,"/");const e=s.length%4;e&&(s+="=".repeat(4-e));const a=atob(s),n=Uint8Array.from(a,(t=>t.charCodeAt(0)));return(new TextDecoder).decode(n)})(s[1])),a="number"==typeof e.iat?1e3*e.iat:void 0,n="number"==typeof e.exp?1e3*e.exp:void 0,r=e["https://hasura.io/jwt/claims"],i=r?Object.entries(r).reduce(((t,[s,e])=>("string"==typeof e&&l(e)?t[s]=p(e):t[s]=e,t)),{}):void 0;return{...e,iat:a,exp:n,"https://hasura.io/jwt/claims":i}},l=t=>t.startsWith("{")&&t.endsWith("}"),p=t=>t&&"{}"!==t?t.slice(1,-1).split(",").map((t=>t.trim().replace(/^"(.*)"$/,"$1"))):[];class w{storageKey;constructor(t){this.storageKey=t?.storageKey||"nhostSession"}get(){try{const t=window.localStorage.getItem(this.storageKey);return t?JSON.parse(t):null}catch{return this.remove(),null}}set(t){window.localStorage.setItem(this.storageKey,JSON.stringify(t))}remove(){window.localStorage.removeItem(this.storageKey)}}class y{session=null;get(){return this.session}set(t){this.session=t}remove(){this.session=null}}class f{storage;subscribers=new Set;constructor(t){this.storage=t}get(){return this.storage.get()}set(t){const s=h(t.accessToken),e={...t,decodedToken:s};this.storage.set(e),this.notifySubscribers(e)}remove(){this.storage.remove(),this.notifySubscribers(null)}onChange(t){return this.subscribers.add(t),()=>{this.subscribers.delete(t)}}notifySubscribers(t){for(const e of this.subscribers)try{e(t)}catch(s){console.error("Error notifying subscriber:",s)}}}const S=()=>"undefined"!=typeof window?new w:new y,g=({auth:t,storage:s,graphql:e,functions:n,sessionStorage:r})=>{const i=[d(t,r),c(r),a(r)];for(const a of i)t.pushChainFunction(a),s.pushChainFunction(a),e.pushChainFunction(a),n.pushChainFunction(a)},O=({auth:t,storage:s,graphql:e,functions:n,sessionStorage:r})=>{const i=[c(r),a(r)];for(const a of i)t.pushChainFunction(a),s.pushChainFunction(a),e.pushChainFunction(a),n.pushChainFunction(a)};class b{auth;storage;graphql;functions;sessionStorage;constructor(t,s,e,a,n){this.auth=t,this.storage=s,this.graphql=e,this.functions=a,this.sessionStorage=n}getUserSession(){return this.sessionStorage.get()}async refreshSession(t=60){return i(this.auth,this.sessionStorage,t)}clearSession(){this.sessionStorage.remove()}}function m(t={}){const{subdomain:a,region:n,authUrl:r,storageUrl:i,graphqlUrl:o,functionsUrl:u,storage:d=S(),configure:c=[]}=t,h=new f(d),l=N("auth",a,n,r),p=N("storage",a,n,i),w=N("graphql",a,n,o),y=N("functions",a,n,u),g=((t,a=[])=>{let n=s(a);return{baseURL:t,pushChainFunction:t=>{a.push(t),n=s(a)},getJWKs:async s=>{const a=`${t}/.well-known/jwks.json`,r=await n(a,{...s,method:"GET",headers:{...s?.headers}});if(r.status>=300){const t=[412].includes(r.status)?null:await r.text(),s=t?JSON.parse(t):{};throw new e(s,r.status,r.headers)}const i=[204,205,304].includes(r.status)?null:await r.text();return{body:i?JSON.parse(i):{},status:r.status,headers:r.headers}},elevateWebauthn:async s=>{const a=`${t}/elevate/webauthn`,r=await n(a,{...s,method:"POST",headers:{...s?.headers}});if(r.status>=300){const t=[412].includes(r.status)?null:await r.text(),s=t?JSON.parse(t):{};throw new e(s,r.status,r.headers)}const i=[204,205,304].includes(r.status)?null:await r.text();return{body:i?JSON.parse(i):{},status:r.status,headers:r.headers}},verifyElevateWebauthn:async(s,a)=>{const r=`${t}/elevate/webauthn/verify`,i=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(i.status>=300){const t=[412].includes(i.status)?null:await i.text(),s=t?JSON.parse(t):{};throw new e(s,i.status,i.headers)}const o=[204,205,304].includes(i.status)?null:await i.text();return{body:o?JSON.parse(o):{},status:i.status,headers:i.headers}},healthCheckGet:async s=>{const a=`${t}/healthz`,r=await n(a,{...s,method:"GET",headers:{...s?.headers}});if(r.status>=300){const t=[412].includes(r.status)?null:await r.text(),s=t?JSON.parse(t):{};throw new e(s,r.status,r.headers)}const i=[204,205,304].includes(r.status)?null:await r.text();return{body:i?JSON.parse(i):{},status:r.status,headers:r.headers}},healthCheckHead:async s=>{const a=`${t}/healthz`,r=await n(a,{...s,method:"HEAD",headers:{...s?.headers}});if(r.status>=300){const t=[412].includes(r.status)?null:await r.text(),s=t?JSON.parse(t):{};throw new e(s,r.status,r.headers)}return{body:void 0,status:r.status,headers:r.headers}},linkIdToken:async(s,a)=>{const r=`${t}/link/idtoken`,i=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(i.status>=300){const t=[412].includes(i.status)?null:await i.text(),s=t?JSON.parse(t):{};throw new e(s,i.status,i.headers)}const o=[204,205,304].includes(i.status)?null:await i.text();return{body:o?JSON.parse(o):{},status:i.status,headers:i.headers}},changeUserMfa:async s=>{const a=`${t}/mfa/totp/generate`,r=await n(a,{...s,method:"GET",headers:{...s?.headers}});if(r.status>=300){const t=[412].includes(r.status)?null:await r.text(),s=t?JSON.parse(t):{};throw new e(s,r.status,r.headers)}const i=[204,205,304].includes(r.status)?null:await r.text();return{body:i?JSON.parse(i):{},status:r.status,headers:r.headers}},createPAT:async(s,a)=>{const r=`${t}/pat`,i=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(i.status>=300){const t=[412].includes(i.status)?null:await i.text(),s=t?JSON.parse(t):{};throw new e(s,i.status,i.headers)}const o=[204,205,304].includes(i.status)?null:await i.text();return{body:o?JSON.parse(o):{},status:i.status,headers:i.headers}},signInAnonymous:async(s,a)=>{const r=`${t}/signin/anonymous`,i=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(i.status>=300){const t=[412].includes(i.status)?null:await i.text(),s=t?JSON.parse(t):{};throw new e(s,i.status,i.headers)}const o=[204,205,304].includes(i.status)?null:await i.text();return{body:o?JSON.parse(o):{},status:i.status,headers:i.headers}},signInEmailPassword:async(s,a)=>{const r=`${t}/signin/email-password`,i=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(i.status>=300){const t=[412].includes(i.status)?null:await i.text(),s=t?JSON.parse(t):{};throw new e(s,i.status,i.headers)}const o=[204,205,304].includes(i.status)?null:await i.text();return{body:o?JSON.parse(o):{},status:i.status,headers:i.headers}},signInIdToken:async(s,a)=>{const r=`${t}/signin/idtoken`,i=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(i.status>=300){const t=[412].includes(i.status)?null:await i.text(),s=t?JSON.parse(t):{};throw new e(s,i.status,i.headers)}const o=[204,205,304].includes(i.status)?null:await i.text();return{body:o?JSON.parse(o):{},status:i.status,headers:i.headers}},verifySignInMfaTotp:async(s,a)=>{const r=`${t}/signin/mfa/totp`,i=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(i.status>=300){const t=[412].includes(i.status)?null:await i.text(),s=t?JSON.parse(t):{};throw new e(s,i.status,i.headers)}const o=[204,205,304].includes(i.status)?null:await i.text();return{body:o?JSON.parse(o):{},status:i.status,headers:i.headers}},signInOTPEmail:async(s,a)=>{const r=`${t}/signin/otp/email`,i=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(i.status>=300){const t=[412].includes(i.status)?null:await i.text(),s=t?JSON.parse(t):{};throw new e(s,i.status,i.headers)}const o=[204,205,304].includes(i.status)?null:await i.text();return{body:o?JSON.parse(o):{},status:i.status,headers:i.headers}},verifySignInOTPEmail:async(s,a)=>{const r=`${t}/signin/otp/email/verify`,i=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(i.status>=300){const t=[412].includes(i.status)?null:await i.text(),s=t?JSON.parse(t):{};throw new e(s,i.status,i.headers)}const o=[204,205,304].includes(i.status)?null:await i.text();return{body:o?JSON.parse(o):{},status:i.status,headers:i.headers}},signInPasswordlessEmail:async(s,a)=>{const r=`${t}/signin/passwordless/email`,i=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(i.status>=300){const t=[412].includes(i.status)?null:await i.text(),s=t?JSON.parse(t):{};throw new e(s,i.status,i.headers)}const o=[204,205,304].includes(i.status)?null:await i.text();return{body:o?JSON.parse(o):{},status:i.status,headers:i.headers}},signInPasswordlessSms:async(s,a)=>{const r=`${t}/signin/passwordless/sms`,i=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(i.status>=300){const t=[412].includes(i.status)?null:await i.text(),s=t?JSON.parse(t):{};throw new e(s,i.status,i.headers)}const o=[204,205,304].includes(i.status)?null:await i.text();return{body:o?JSON.parse(o):{},status:i.status,headers:i.headers}},verifySignInPasswordlessSms:async(s,a)=>{const r=`${t}/signin/passwordless/sms/otp`,i=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(i.status>=300){const t=[412].includes(i.status)?null:await i.text(),s=t?JSON.parse(t):{};throw new e(s,i.status,i.headers)}const o=[204,205,304].includes(i.status)?null:await i.text();return{body:o?JSON.parse(o):{},status:i.status,headers:i.headers}},signInPAT:async(s,a)=>{const r=`${t}/signin/pat`,i=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(i.status>=300){const t=[412].includes(i.status)?null:await i.text(),s=t?JSON.parse(t):{};throw new e(s,i.status,i.headers)}const o=[204,205,304].includes(i.status)?null:await i.text();return{body:o?JSON.parse(o):{},status:i.status,headers:i.headers}},signInProviderURL:(s,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))}`));const e=Array.isArray(s)?s.join(","):"object"==typeof s&&null!==s?JSON.stringify(s):String(s);return[`${t}=${encodeURIComponent(e)}`]})).join("&");return a?`${t}/signin/provider/${s}?${a}`:`${t}/signin/provider/${s}`},getProviderTokens:async(s,a)=>{const r=`${t}/signin/provider/${s}/callback/tokens`,i=await n(r,{...a,method:"GET",headers:{...a?.headers}});if(i.status>=300){const t=[412].includes(i.status)?null:await i.text(),s=t?JSON.parse(t):{};throw new e(s,i.status,i.headers)}const o=[204,205,304].includes(i.status)?null:await i.text();return{body:o?JSON.parse(o):{},status:i.status,headers:i.headers}},signInWebauthn:async(s,a)=>{const r=`${t}/signin/webauthn`,i=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(i.status>=300){const t=[412].includes(i.status)?null:await i.text(),s=t?JSON.parse(t):{};throw new e(s,i.status,i.headers)}const o=[204,205,304].includes(i.status)?null:await i.text();return{body:o?JSON.parse(o):{},status:i.status,headers:i.headers}},verifySignInWebauthn:async(s,a)=>{const r=`${t}/signin/webauthn/verify`,i=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(i.status>=300){const t=[412].includes(i.status)?null:await i.text(),s=t?JSON.parse(t):{};throw new e(s,i.status,i.headers)}const o=[204,205,304].includes(i.status)?null:await i.text();return{body:o?JSON.parse(o):{},status:i.status,headers:i.headers}},signOut:async(s,a)=>{const r=`${t}/signout`,i=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(i.status>=300){const t=[412].includes(i.status)?null:await i.text(),s=t?JSON.parse(t):{};throw new e(s,i.status,i.headers)}const o=[204,205,304].includes(i.status)?null:await i.text();return{body:o?JSON.parse(o):{},status:i.status,headers:i.headers}},signUpEmailPassword:async(s,a)=>{const r=`${t}/signup/email-password`,i=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(i.status>=300){const t=[412].includes(i.status)?null:await i.text(),s=t?JSON.parse(t):{};throw new e(s,i.status,i.headers)}const o=[204,205,304].includes(i.status)?null:await i.text();return{body:o?JSON.parse(o):{},status:i.status,headers:i.headers}},signUpWebauthn:async(s,a)=>{const r=`${t}/signup/webauthn`,i=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(i.status>=300){const t=[412].includes(i.status)?null:await i.text(),s=t?JSON.parse(t):{};throw new e(s,i.status,i.headers)}const o=[204,205,304].includes(i.status)?null:await i.text();return{body:o?JSON.parse(o):{},status:i.status,headers:i.headers}},verifySignUpWebauthn:async(s,a)=>{const r=`${t}/signup/webauthn/verify`,i=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(i.status>=300){const t=[412].includes(i.status)?null:await i.text(),s=t?JSON.parse(t):{};throw new e(s,i.status,i.headers)}const o=[204,205,304].includes(i.status)?null:await i.text();return{body:o?JSON.parse(o):{},status:i.status,headers:i.headers}},refreshToken:async(s,a)=>{const r=`${t}/token`,i=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(i.status>=300){const t=[412].includes(i.status)?null:await i.text(),s=t?JSON.parse(t):{};throw new e(s,i.status,i.headers)}const o=[204,205,304].includes(i.status)?null:await i.text();return{body:o?JSON.parse(o):{},status:i.status,headers:i.headers}},refreshProviderToken:async(s,a,r)=>{const i=`${t}/token/provider/${s}`,o=await n(i,{...r,method:"POST",headers:{"Content-Type":"application/json",...r?.headers},body:JSON.stringify(a)});if(o.status>=300){const t=[412].includes(o.status)?null:await o.text(),s=t?JSON.parse(t):{};throw new e(s,o.status,o.headers)}const u=[204,205,304].includes(o.status)?null:await o.text();return{body:u?JSON.parse(u):{},status:o.status,headers:o.headers}},verifyToken:async(s,a)=>{const r=`${t}/token/verify`,i=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(i.status>=300){const t=[412].includes(i.status)?null:await i.text(),s=t?JSON.parse(t):{};throw new e(s,i.status,i.headers)}const o=[204,205,304].includes(i.status)?null:await i.text();return{body:o?JSON.parse(o):{},status:i.status,headers:i.headers}},getUser:async s=>{const a=`${t}/user`,r=await n(a,{...s,method:"GET",headers:{...s?.headers}});if(r.status>=300){const t=[412].includes(r.status)?null:await r.text(),s=t?JSON.parse(t):{};throw new e(s,r.status,r.headers)}const i=[204,205,304].includes(r.status)?null:await r.text();return{body:i?JSON.parse(i):{},status:r.status,headers:r.headers}},deanonymizeUser:async(s,a)=>{const r=`${t}/user/deanonymize`,i=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(i.status>=300){const t=[412].includes(i.status)?null:await i.text(),s=t?JSON.parse(t):{};throw new e(s,i.status,i.headers)}const o=[204,205,304].includes(i.status)?null:await i.text();return{body:o?JSON.parse(o):{},status:i.status,headers:i.headers}},changeUserEmail:async(s,a)=>{const r=`${t}/user/email/change`,i=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(i.status>=300){const t=[412].includes(i.status)?null:await i.text(),s=t?JSON.parse(t):{};throw new e(s,i.status,i.headers)}const o=[204,205,304].includes(i.status)?null:await i.text();return{body:o?JSON.parse(o):{},status:i.status,headers:i.headers}},sendVerificationEmail:async(s,a)=>{const r=`${t}/user/email/send-verification-email`,i=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(i.status>=300){const t=[412].includes(i.status)?null:await i.text(),s=t?JSON.parse(t):{};throw new e(s,i.status,i.headers)}const o=[204,205,304].includes(i.status)?null:await i.text();return{body:o?JSON.parse(o):{},status:i.status,headers:i.headers}},verifyChangeUserMfa:async(s,a)=>{const r=`${t}/user/mfa`,i=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(i.status>=300){const t=[412].includes(i.status)?null:await i.text(),s=t?JSON.parse(t):{};throw new e(s,i.status,i.headers)}const o=[204,205,304].includes(i.status)?null:await i.text();return{body:o?JSON.parse(o):{},status:i.status,headers:i.headers}},changeUserPassword:async(s,a)=>{const r=`${t}/user/password`,i=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(i.status>=300){const t=[412].includes(i.status)?null:await i.text(),s=t?JSON.parse(t):{};throw new e(s,i.status,i.headers)}const o=[204,205,304].includes(i.status)?null:await i.text();return{body:o?JSON.parse(o):{},status:i.status,headers:i.headers}},sendPasswordResetEmail:async(s,a)=>{const r=`${t}/user/password/reset`,i=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(i.status>=300){const t=[412].includes(i.status)?null:await i.text(),s=t?JSON.parse(t):{};throw new e(s,i.status,i.headers)}const o=[204,205,304].includes(i.status)?null:await i.text();return{body:o?JSON.parse(o):{},status:i.status,headers:i.headers}},addSecurityKey:async s=>{const a=`${t}/user/webauthn/add`,r=await n(a,{...s,method:"POST",headers:{...s?.headers}});if(r.status>=300){const t=[412].includes(r.status)?null:await r.text(),s=t?JSON.parse(t):{};throw new e(s,r.status,r.headers)}const i=[204,205,304].includes(r.status)?null:await r.text();return{body:i?JSON.parse(i):{},status:r.status,headers:r.headers}},verifyAddSecurityKey:async(s,a)=>{const r=`${t}/user/webauthn/verify`,i=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(i.status>=300){const t=[412].includes(i.status)?null:await i.text(),s=t?JSON.parse(t):{};throw new e(s,i.status,i.headers)}const o=[204,205,304].includes(i.status)?null:await i.text();return{body:o?JSON.parse(o):{},status:i.status,headers:i.headers}},verifyTicketURL:s=>{const e=s&&Object.entries(s).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?`${t}/verify?${e}`:`${t}/verify`},getVersion:async s=>{const a=`${t}/version`,r=await n(a,{...s,method:"GET",headers:{...s?.headers}});if(r.status>=300){const t=[412].includes(r.status)?null:await r.text(),s=t?JSON.parse(t):{};throw new e(s,r.status,r.headers)}const i=[204,205,304].includes(r.status)?null:await r.text();return{body:i?JSON.parse(i):{},status:r.status,headers:r.headers}}}})(l),O=((t,a=[])=>{let n=s(a);return{baseURL:t,pushChainFunction:t=>{a.push(t),n=s(a)},uploadFiles:async(s,a)=>{const r=`${t}/files`,i=new FormData,o="undefined"!=typeof navigator&&"ReactNative"===navigator.product;void 0!==s["bucket-id"]&&i.append("bucket-id",s["bucket-id"]),void 0!==s["metadata[]"]&&s["metadata[]"].forEach((t=>{o?i.append("metadata[]",{string:JSON.stringify(t),type:"application/json",name:""}):i.append("metadata[]",new Blob([JSON.stringify(t)],{type:"application/json"}),"")})),void 0!==s["file[]"]&&s["file[]"].forEach((t=>{i.append("file[]",t)}));const u=await n(r,{...a,method:"POST",body:i});if(u.status>=300){const t=[412].includes(u.status)?null:await u.text(),s=t?JSON.parse(t):{};throw new e(s,u.status,u.headers)}const d=[204,205,304].includes(u.status)?null:await u.text();return{body:d?JSON.parse(d):{},status:u.status,headers:u.headers}},deleteFile:async(s,a)=>{const r=`${t}/files/${s}`,i=await n(r,{...a,method:"DELETE",headers:{...a?.headers}});if(i.status>=300){const t=[412].includes(i.status)?null:await i.text(),s=t?JSON.parse(t):{};throw new e(s,i.status,i.headers)}return{body:void 0,status:i.status,headers:i.headers}},getFile:async(s,a,r)=>{const i=a&&Object.entries(a).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=i?`${t}/files/${s}?${i}`:`${t}/files/${s}`,u=await n(o,{...r,method:"GET",headers:{...r?.headers}});if(u.status>=300){const t=[412].includes(u.status)?null:await u.text(),s=t?JSON.parse(t):{};throw new e(s,u.status,u.headers)}return{body:await u.blob(),status:u.status,headers:u.headers}},getFileMetadataHeaders:async(s,a,r)=>{const i=a&&Object.entries(a).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=i?`${t}/files/${s}?${i}`:`${t}/files/${s}`,u=await n(o,{...r,method:"HEAD",headers:{...r?.headers}});if(u.status>=300){const t=[412].includes(u.status)?null:await u.text(),s=t?JSON.parse(t):{};throw new e(s,u.status,u.headers)}return{body:void 0,status:u.status,headers:u.headers}},replaceFile:async(s,a,r)=>{const i=`${t}/files/${s}`,o=new FormData,u="undefined"!=typeof navigator&&"ReactNative"===navigator.product;void 0!==a.metadata&&(u?o.append("metadata",{string:JSON.stringify(a.metadata),type:"application/json",name:""}):o.append("metadata",new Blob([JSON.stringify(a.metadata)],{type:"application/json"}),"")),void 0!==a.file&&o.append("file",a.file);const d=await n(i,{...r,method:"PUT",body:o});if(d.status>=300){const t=[412].includes(d.status)?null:await d.text(),s=t?JSON.parse(t):{};throw new e(s,d.status,d.headers)}const c=[204,205,304].includes(d.status)?null:await d.text();return{body:c?JSON.parse(c):{},status:d.status,headers:d.headers}},getFilePresignedURL:async(s,a)=>{const r=`${t}/files/${s}/presignedurl`,i=await n(r,{...a,method:"GET",headers:{...a?.headers}});if(i.status>=300){const t=[412].includes(i.status)?null:await i.text(),s=t?JSON.parse(t):{};throw new e(s,i.status,i.headers)}const o=[204,205,304].includes(i.status)?null:await i.text();return{body:o?JSON.parse(o):{},status:i.status,headers:i.headers}},deleteBrokenMetadata:async s=>{const a=`${t}/ops/delete-broken-metadata`,r=await n(a,{...s,method:"POST",headers:{...s?.headers}});if(r.status>=300){const t=[412].includes(r.status)?null:await r.text(),s=t?JSON.parse(t):{};throw new e(s,r.status,r.headers)}const i=[204,205,304].includes(r.status)?null:await r.text();return{body:i?JSON.parse(i):{},status:r.status,headers:r.headers}},deleteOrphanedFiles:async s=>{const a=`${t}/ops/delete-orphans`,r=await n(a,{...s,method:"POST",headers:{...s?.headers}});if(r.status>=300){const t=[412].includes(r.status)?null:await r.text(),s=t?JSON.parse(t):{};throw new e(s,r.status,r.headers)}const i=[204,205,304].includes(r.status)?null:await r.text();return{body:i?JSON.parse(i):{},status:r.status,headers:r.headers}},listBrokenMetadata:async s=>{const a=`${t}/ops/list-broken-metadata`,r=await n(a,{...s,method:"POST",headers:{...s?.headers}});if(r.status>=300){const t=[412].includes(r.status)?null:await r.text(),s=t?JSON.parse(t):{};throw new e(s,r.status,r.headers)}const i=[204,205,304].includes(r.status)?null:await r.text();return{body:i?JSON.parse(i):{},status:r.status,headers:r.headers}},listFilesNotUploaded:async s=>{const a=`${t}/ops/list-not-uploaded`,r=await n(a,{...s,method:"POST",headers:{...s?.headers}});if(r.status>=300){const t=[412].includes(r.status)?null:await r.text(),s=t?JSON.parse(t):{};throw new e(s,r.status,r.headers)}const i=[204,205,304].includes(r.status)?null:await r.text();return{body:i?JSON.parse(i):{},status:r.status,headers:r.headers}},listOrphanedFiles:async s=>{const a=`${t}/ops/list-orphans`,r=await n(a,{...s,method:"POST",headers:{...s?.headers}});if(r.status>=300){const t=[412].includes(r.status)?null:await r.text(),s=t?JSON.parse(t):{};throw new e(s,r.status,r.headers)}const i=[204,205,304].includes(r.status)?null:await r.text();return{body:i?JSON.parse(i):{},status:r.status,headers:r.headers}},getVersion:async s=>{const a=`${t}/version`,r=await n(a,{...s,method:"GET",headers:{...s?.headers}});if(r.status>=300){const t=[412].includes(r.status)?null:await r.text(),s=t?JSON.parse(t):{};throw new e(s,r.status,r.headers)}const i=[204,205,304].includes(r.status)?null:await r.text();return{body:i?JSON.parse(i):{},status:r.status,headers:r.headers}}}})(p,[]),m=((t,a=[])=>{let n=s(a);const r=async(s,a)=>{const r=await n(`${t}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s),...a}),i=await r.text(),o=i?JSON.parse(i):{},u={body:o,status:r.status,headers:r.headers};if(o.errors)throw new e(o,r.status,r.headers);return u};return{request:function(t,s,e){if("object"==typeof t&&"kind"in t){const a=t.definitions[0],n={query:t.loc?.source.body||"",variables:s,operationName:a&&"name"in a?a.name?.value:void 0};return r(n,e)}return r(t,s)},url:t,pushChainFunction:t=>{a.push(t),n=s(a)}}})(w,[]),J=((t,a=[])=>{let n=s(a);const r=async(s,a)=>{const r=await n(`${t}${s}`,a);let i;if(i=r.headers.get("content-type")?.includes("application/json")?await r.json():r.headers.get("content-type")?.startsWith("text/")?await r.text():await r.blob(),!r.ok)throw new e(i,r.status,r.headers);return{status:r.status,body:i,headers:r.headers}};return{baseURL:t,fetch:r,post:async(t,s,e={})=>{const a={...e,method:"POST",headers:{Accept:"application/json","Content-Type":"application/json",...e.headers},body:s?JSON.stringify(s):void 0};return r(t,a)},pushChainFunction:t=>{a.push(t),n=s(a)}}})(y,[]);for(const s of c)s({auth:g,storage:O,graphql:m,functions:J,sessionStorage:h});return new b(g,O,m,J,h)}const N=(t,s,e,a)=>a||(s&&e?`https://${s}.${t}.${e}.nhost.run/v1`:`https://local.${t}.local.nhost.run/v1`);t.createClient=function(t={}){const s=t.storage??S();return m({...t,storage:s,configure:[g,...t.configure??[]]})},t.createNhostClient=m,t.createServerClient=function(t){return m({...t,configure:[O,...t.configure??[]]})},t.generateServiceUrl=N,t.withAdminSession=function(t){return({storage:s,graphql:e,functions:a})=>{const n=(r=t,t=>async(s,e={})=>{const a=new Headers(e.headers||{});if(a.has("x-hasura-admin-secret")||a.set("x-hasura-admin-secret",r.adminSecret),r.role&&!a.has("x-hasura-role")&&a.set("x-hasura-role",r.role),r.sessionVariables)for(const[t,n]of Object.entries(r.sessionVariables)){const s=t.startsWith("x-hasura-")?t:`x-hasura-${t}`;a.has(s)||a.set(s,n)}return t(s,{...e,headers:a})});var r;s.pushChainFunction(n),e.pushChainFunction(n),a.pushChainFunction(n)}},t.withClientSideSessionMiddleware=g,t.withServerSideSessionMiddleware=O,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})}));
|
|
1
|
+
!function(t,s){"object"==typeof exports&&"undefined"!=typeof module?s(exports):"function"==typeof define&&define.amd?define(["exports"],s):s((t="undefined"!=typeof globalThis?globalThis:t||self).NhostJs={})}(this,(function(t){"use strict";function s(t=[]){return t.reduceRight(((t,s)=>s(t)),fetch)}class e extends Error{body;status;headers;constructor(t,s,e){super(function(t){if(t&&"string"==typeof t)return t;if(t&&"object"==typeof t){const s=t;if("message"in s&&"string"==typeof s.message)return s.message;if("error"in s&&"string"==typeof s.error)return s.error;if("error"in s&&s.error&&"object"==typeof s.error){const t=s.error;if("message"in t&&"string"==typeof t.message)return t.message}if("errors"in s&&Array.isArray(s.errors)){const t=s.errors.filter((t=>"object"==typeof t&&null!==t&&"message"in t&&"string"==typeof t.message)).map((t=>t.message));if(t.length>0)return t.join(", ")}}return"An unexpected error occurred"}(t)),this.body=t,this.status=s,this.headers=e}}const a=t=>s=>async(e,a={})=>{const r=new Headers(a.headers||{});if(r.has("Authorization"))return s(e,a);const o=t.get();if(o?.accessToken){const t={...a,headers:n(r,o)};return s(e,t)}return s(e,a)};function n(t,s){return s.accessToken&&t.set("Authorization",`Bearer ${s.accessToken}`),t}const r="undefined"!=typeof navigator&&navigator.locks?navigator.locks:new class{async request(t,s,e){return e()}},o=async(t,s,e=60)=>{try{return await i(t,s,e)}catch(a){try{return console.warn("error refreshing session, retrying:",a),await i(t,s,e)}catch(n){const t=n;return 401===t?.status&&(console.error("session probably expired"),s.remove()),null}}},i=async(t,s,e=60)=>{const{session:a,needsRefresh:n}=await r.request("nhostSessionLock",{mode:"shared"},(async()=>u(s,e)));if(!a)return null;if(!n)return a;return await r.request("nhostSessionLock",{mode:"exclusive"},(async()=>{const{session:a,needsRefresh:n,sessionExpired:r}=u(s,e);if(!a)return null;if(!n)return a;try{const e=await t.refreshToken({refreshToken:a.refreshToken});return s.set(e.body),e.body}catch(o){if(!r)return a;throw o}}))},u=(t,s=60)=>{const e=t.get();if(!e)return{session:null,needsRefresh:!1,sessionExpired:!1};if(!e.decodedToken||!e.decodedToken.exp)return{session:e,needsRefresh:!0,sessionExpired:!0};if(0===s)return{session:e,needsRefresh:!0,sessionExpired:!1};const a=Date.now();return e.decodedToken.exp-a>1e3*s?{session:e,needsRefresh:!1,sessionExpired:!1}:{session:e,needsRefresh:!0,sessionExpired:e.decodedToken.exp<a}},d=(t,s,e)=>{const{marginSeconds:a=60}={};return e=>async(n,r={})=>{if(function(t,s){const e=new Headers(s.headers||{});if(e.has("Authorization"))return!0;if(t.endsWith("/v1/token"))return!0;return!1}(n,r))return e(n,r);try{await o(t,s,a)}catch{}return e(n,r)}};const c=t=>s=>async(e,a)=>{const n=await s(e,a);try{if(e.endsWith("/signout"))return t.remove(),n;if(e.endsWith("/token")||e.includes("/signin/")||e.includes("/signup/")){const s=n.clone(),e=await s.json().catch((()=>null));if(e){const s=(t=>"string"==typeof t?null:"session"in t?t.session||null:"accessToken"in t&&"refreshToken"in t&&"user"in t?t:null)(e);s?.accessToken&&s.refreshToken&&t.set(s)}}}catch(r){console.warn("Error in session response middleware:",r)}return n},h=t=>{const s=t.split(".");if(3!==s.length||!s[1])throw new Error("Invalid access token format");const e=JSON.parse((t=>{let s=t.replace(/-/g,"+").replace(/_/g,"/");const e=s.length%4;e&&(s+="=".repeat(4-e));const a=atob(s),n=Uint8Array.from(a,(t=>t.charCodeAt(0)));return(new TextDecoder).decode(n)})(s[1])),a="number"==typeof e.iat?1e3*e.iat:void 0,n="number"==typeof e.exp?1e3*e.exp:void 0,r=e["https://hasura.io/jwt/claims"],o=r?Object.entries(r).reduce(((t,[s,e])=>("string"==typeof e&&l(e)?t[s]=p(e):t[s]=e,t)),{}):void 0;return{...e,iat:a,exp:n,"https://hasura.io/jwt/claims":o}},l=t=>t.startsWith("{")&&t.endsWith("}"),p=t=>t&&"{}"!==t?t.slice(1,-1).split(",").map((t=>t.trim().replace(/^"(.*)"$/,"$1"))):[];class w{storageKey;constructor(t){this.storageKey=t?.storageKey||"nhostSession"}get(){try{const t=window.localStorage.getItem(this.storageKey);return t?JSON.parse(t):null}catch{return this.remove(),null}}set(t){window.localStorage.setItem(this.storageKey,JSON.stringify(t))}remove(){window.localStorage.removeItem(this.storageKey)}}class y{session=null;get(){return this.session}set(t){this.session=t}remove(){this.session=null}}class f{storage;subscribers=new Set;constructor(t){this.storage=t}get(){return this.storage.get()}set(t){const s=h(t.accessToken),e={...t,decodedToken:s};this.storage.set(e),this.notifySubscribers(e)}remove(){this.storage.remove(),this.notifySubscribers(null)}onChange(t){return this.subscribers.add(t),()=>{this.subscribers.delete(t)}}notifySubscribers(t){for(const e of this.subscribers)try{e(t)}catch(s){console.error("Error notifying subscriber:",s)}}}const S=()=>"undefined"!=typeof window?new w:new y,g=({auth:t,storage:s,graphql:e,functions:n,sessionStorage:r})=>{const o=[d(t,r),c(r),a(r)];for(const a of o)t.pushChainFunction(a),s.pushChainFunction(a),e.pushChainFunction(a),n.pushChainFunction(a)},O=({auth:t,storage:s,graphql:e,functions:n,sessionStorage:r})=>{const o=[c(r),a(r)];for(const a of o)t.pushChainFunction(a),s.pushChainFunction(a),e.pushChainFunction(a),n.pushChainFunction(a)};class b{auth;storage;graphql;functions;sessionStorage;constructor(t,s,e,a,n){this.auth=t,this.storage=s,this.graphql=e,this.functions=a,this.sessionStorage=n}getUserSession(){return this.sessionStorage.get()}async refreshSession(t=60){return o(this.auth,this.sessionStorage,t)}clearSession(){this.sessionStorage.remove()}}function N(t={}){const{subdomain:a,region:n,authUrl:r,storageUrl:o,graphqlUrl:i,functionsUrl:u,storage:d=S(),configure:c=[]}=t,h=new f(d),l=m("auth",a,n,r),p=m("storage",a,n,o),w=m("graphql",a,n,i),y=m("functions",a,n,u),g=((t,a=[])=>{let n=s(a);return{baseURL:t,pushChainFunction:t=>{a.push(t),n=s(a)},getJWKs:async s=>{const a=`${t}/.well-known/jwks.json`,r=await n(a,{...s,method:"GET",headers:{...s?.headers}});if(r.status>=300){const t=[412].includes(r.status)?null:await r.text(),s=t?JSON.parse(t):{};throw new e(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 s=>{const a=`${t}/elevate/webauthn`,r=await n(a,{...s,method:"POST",headers:{...s?.headers}});if(r.status>=300){const t=[412].includes(r.status)?null:await r.text(),s=t?JSON.parse(t):{};throw new e(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(s,a)=>{const r=`${t}/elevate/webauthn/verify`,o=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(o.status>=300){const t=[412].includes(o.status)?null:await o.text(),s=t?JSON.parse(t):{};throw new e(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 s=>{const a=`${t}/healthz`,r=await n(a,{...s,method:"GET",headers:{...s?.headers}});if(r.status>=300){const t=[412].includes(r.status)?null:await r.text(),s=t?JSON.parse(t):{};throw new e(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 s=>{const a=`${t}/healthz`,r=await n(a,{...s,method:"HEAD",headers:{...s?.headers}});if(r.status>=300){const t=[412].includes(r.status)?null:await r.text(),s=t?JSON.parse(t):{};throw new e(s,r.status,r.headers)}return{body:void 0,status:r.status,headers:r.headers}},linkIdToken:async(s,a)=>{const r=`${t}/link/idtoken`,o=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(o.status>=300){const t=[412].includes(o.status)?null:await o.text(),s=t?JSON.parse(t):{};throw new e(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 s=>{const a=`${t}/mfa/totp/generate`,r=await n(a,{...s,method:"GET",headers:{...s?.headers}});if(r.status>=300){const t=[412].includes(r.status)?null:await r.text(),s=t?JSON.parse(t):{};throw new e(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(s,a)=>{const r=`${t}/pat`,o=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(o.status>=300){const t=[412].includes(o.status)?null:await o.text(),s=t?JSON.parse(t):{};throw new e(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(s,a)=>{const r=`${t}/signin/anonymous`,o=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(o.status>=300){const t=[412].includes(o.status)?null:await o.text(),s=t?JSON.parse(t):{};throw new e(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(s,a)=>{const r=`${t}/signin/email-password`,o=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(o.status>=300){const t=[412].includes(o.status)?null:await o.text(),s=t?JSON.parse(t):{};throw new e(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(s,a)=>{const r=`${t}/signin/idtoken`,o=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(o.status>=300){const t=[412].includes(o.status)?null:await o.text(),s=t?JSON.parse(t):{};throw new e(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(s,a)=>{const r=`${t}/signin/mfa/totp`,o=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(o.status>=300){const t=[412].includes(o.status)?null:await o.text(),s=t?JSON.parse(t):{};throw new e(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(s,a)=>{const r=`${t}/signin/otp/email`,o=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(o.status>=300){const t=[412].includes(o.status)?null:await o.text(),s=t?JSON.parse(t):{};throw new e(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(s,a)=>{const r=`${t}/signin/otp/email/verify`,o=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(o.status>=300){const t=[412].includes(o.status)?null:await o.text(),s=t?JSON.parse(t):{};throw new e(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(s,a)=>{const r=`${t}/signin/passwordless/email`,o=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(o.status>=300){const t=[412].includes(o.status)?null:await o.text(),s=t?JSON.parse(t):{};throw new e(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(s,a)=>{const r=`${t}/signin/passwordless/sms`,o=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(o.status>=300){const t=[412].includes(o.status)?null:await o.text(),s=t?JSON.parse(t):{};throw new e(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(s,a)=>{const r=`${t}/signin/passwordless/sms/otp`,o=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(o.status>=300){const t=[412].includes(o.status)?null:await o.text(),s=t?JSON.parse(t):{};throw new e(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(s,a)=>{const r=`${t}/signin/pat`,o=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(o.status>=300){const t=[412].includes(o.status)?null:await o.text(),s=t?JSON.parse(t):{};throw new e(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:(s,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))}`));const e=Array.isArray(s)?s.join(","):"object"==typeof s&&null!==s?JSON.stringify(s):String(s);return[`${t}=${encodeURIComponent(e)}`]})).join("&");return a?`${t}/signin/provider/${s}?${a}`:`${t}/signin/provider/${s}`},getProviderTokens:async(s,a)=>{const r=`${t}/signin/provider/${s}/callback/tokens`,o=await n(r,{...a,method:"GET",headers:{...a?.headers}});if(o.status>=300){const t=[412].includes(o.status)?null:await o.text(),s=t?JSON.parse(t):{};throw new e(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(s,a)=>{const r=`${t}/signin/webauthn`,o=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(o.status>=300){const t=[412].includes(o.status)?null:await o.text(),s=t?JSON.parse(t):{};throw new e(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(s,a)=>{const r=`${t}/signin/webauthn/verify`,o=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(o.status>=300){const t=[412].includes(o.status)?null:await o.text(),s=t?JSON.parse(t):{};throw new e(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(s,a)=>{const r=`${t}/signout`,o=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(o.status>=300){const t=[412].includes(o.status)?null:await o.text(),s=t?JSON.parse(t):{};throw new e(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(s,a)=>{const r=`${t}/signup/email-password`,o=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(o.status>=300){const t=[412].includes(o.status)?null:await o.text(),s=t?JSON.parse(t):{};throw new e(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(s,a)=>{const r=`${t}/signup/webauthn`,o=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(o.status>=300){const t=[412].includes(o.status)?null:await o.text(),s=t?JSON.parse(t):{};throw new e(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(s,a)=>{const r=`${t}/signup/webauthn/verify`,o=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(o.status>=300){const t=[412].includes(o.status)?null:await o.text(),s=t?JSON.parse(t):{};throw new e(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}},refreshToken:async(s,a)=>{const r=`${t}/token`,o=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(o.status>=300){const t=[412].includes(o.status)?null:await o.text(),s=t?JSON.parse(t):{};throw new e(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(s,a,r)=>{const o=`${t}/token/provider/${s}`,i=await n(o,{...r,method:"POST",headers:{"Content-Type":"application/json",...r?.headers},body:JSON.stringify(a)});if(i.status>=300){const t=[412].includes(i.status)?null:await i.text(),s=t?JSON.parse(t):{};throw new e(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(s,a)=>{const r=`${t}/token/verify`,o=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(o.status>=300){const t=[412].includes(o.status)?null:await o.text(),s=t?JSON.parse(t):{};throw new e(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 s=>{const a=`${t}/user`,r=await n(a,{...s,method:"GET",headers:{...s?.headers}});if(r.status>=300){const t=[412].includes(r.status)?null:await r.text(),s=t?JSON.parse(t):{};throw new e(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(s,a)=>{const r=`${t}/user/deanonymize`,o=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(o.status>=300){const t=[412].includes(o.status)?null:await o.text(),s=t?JSON.parse(t):{};throw new e(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(s,a)=>{const r=`${t}/user/email/change`,o=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(o.status>=300){const t=[412].includes(o.status)?null:await o.text(),s=t?JSON.parse(t):{};throw new e(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(s,a)=>{const r=`${t}/user/email/send-verification-email`,o=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(o.status>=300){const t=[412].includes(o.status)?null:await o.text(),s=t?JSON.parse(t):{};throw new e(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(s,a)=>{const r=`${t}/user/mfa`,o=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(o.status>=300){const t=[412].includes(o.status)?null:await o.text(),s=t?JSON.parse(t):{};throw new e(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(s,a)=>{const r=`${t}/user/password`,o=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(o.status>=300){const t=[412].includes(o.status)?null:await o.text(),s=t?JSON.parse(t):{};throw new e(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(s,a)=>{const r=`${t}/user/password/reset`,o=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(o.status>=300){const t=[412].includes(o.status)?null:await o.text(),s=t?JSON.parse(t):{};throw new e(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 s=>{const a=`${t}/user/webauthn/add`,r=await n(a,{...s,method:"POST",headers:{...s?.headers}});if(r.status>=300){const t=[412].includes(r.status)?null:await r.text(),s=t?JSON.parse(t):{};throw new e(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(s,a)=>{const r=`${t}/user/webauthn/verify`,o=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(o.status>=300){const t=[412].includes(o.status)?null:await o.text(),s=t?JSON.parse(t):{};throw new e(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:s=>{const e=s&&Object.entries(s).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?`${t}/verify?${e}`:`${t}/verify`},getVersion:async s=>{const a=`${t}/version`,r=await n(a,{...s,method:"GET",headers:{...s?.headers}});if(r.status>=300){const t=[412].includes(r.status)?null:await r.text(),s=t?JSON.parse(t):{};throw new e(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 s=>{const a=`${t}/.well-known/openid-configuration`,r=await n(a,{...s,method:"GET",headers:{...s?.headers}});if(r.status>=300){const t=[412].includes(r.status)?null:await r.text(),s=t?JSON.parse(t):{};throw new e(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 s=>{const a=`${t}/.well-known/oauth-authorization-server`,r=await n(a,{...s,method:"GET",headers:{...s?.headers}});if(r.status>=300){const t=[412].includes(r.status)?null:await r.text(),s=t?JSON.parse(t):{};throw new e(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:s=>{const e=s&&Object.entries(s).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?`${t}/oauth2/authorize?${e}`:`${t}/oauth2/authorize`},oauth2AuthorizePostURL:()=>`${t}/oauth2/authorize`,oauth2Token:async(s,a)=>{const r=`${t}/oauth2/token`,o=new URLSearchParams;void 0!==s.grant_type&&o.append("grant_type",String(s.grant_type)),void 0!==s.code&&o.append("code",String(s.code)),void 0!==s.redirect_uri&&o.append("redirect_uri",String(s.redirect_uri)),void 0!==s.client_id&&o.append("client_id",String(s.client_id)),void 0!==s.client_secret&&o.append("client_secret",String(s.client_secret)),void 0!==s.code_verifier&&o.append("code_verifier",String(s.code_verifier)),void 0!==s.refresh_token&&o.append("refresh_token",String(s.refresh_token)),void 0!==s.resource&&o.append("resource",String(s.resource));const i=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded",...a?.headers},body:o.toString()});if(i.status>=300){const t=[412].includes(i.status)?null:await i.text(),s=t?JSON.parse(t):{};throw new e(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 s=>{const a=`${t}/oauth2/userinfo`,r=await n(a,{...s,method:"GET",headers:{...s?.headers}});if(r.status>=300){const t=[412].includes(r.status)?null:await r.text(),s=t?JSON.parse(t):{};throw new e(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 s=>{const a=`${t}/oauth2/userinfo`,r=await n(a,{...s,method:"POST",headers:{...s?.headers}});if(r.status>=300){const t=[412].includes(r.status)?null:await r.text(),s=t?JSON.parse(t):{};throw new e(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 s=>{const a=`${t}/oauth2/jwks`,r=await n(a,{...s,method:"GET",headers:{...s?.headers}});if(r.status>=300){const t=[412].includes(r.status)?null:await r.text(),s=t?JSON.parse(t):{};throw new e(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(s,a)=>{const r=`${t}/oauth2/revoke`,o=new URLSearchParams;void 0!==s.token&&o.append("token",String(s.token)),void 0!==s.token_type_hint&&o.append("token_type_hint",String(s.token_type_hint)),void 0!==s.client_id&&o.append("client_id",String(s.client_id)),void 0!==s.client_secret&&o.append("client_secret",String(s.client_secret));const i=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded",...a?.headers},body:o.toString()});if(i.status>=300){const t=[412].includes(i.status)?null:await i.text(),s=t?JSON.parse(t):{};throw new e(s,i.status,i.headers)}return{body:void 0,status:i.status,headers:i.headers}},oauth2Introspect:async(s,a)=>{const r=`${t}/oauth2/introspect`,o=new URLSearchParams;void 0!==s.token&&o.append("token",String(s.token)),void 0!==s.token_type_hint&&o.append("token_type_hint",String(s.token_type_hint)),void 0!==s.client_id&&o.append("client_id",String(s.client_id)),void 0!==s.client_secret&&o.append("client_secret",String(s.client_secret));const i=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded",...a?.headers},body:o.toString()});if(i.status>=300){const t=[412].includes(i.status)?null:await i.text(),s=t?JSON.parse(t):{};throw new e(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(s,a)=>{const r=s&&Object.entries(s).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?`${t}/oauth2/login?${r}`:`${t}/oauth2/login`,i=await n(o,{...a,method:"GET",headers:{...a?.headers}});if(i.status>=300){const t=[412].includes(i.status)?null:await i.text(),s=t?JSON.parse(t):{};throw new e(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(s,a)=>{const r=`${t}/oauth2/login`,o=await n(r,{...a,method:"POST",headers:{"Content-Type":"application/json",...a?.headers},body:JSON.stringify(s)});if(o.status>=300){const t=[412].includes(o.status)?null:await o.text(),s=t?JSON.parse(t):{};throw new e(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}}}})(l),O=((t,a=[])=>{let n=s(a);return{baseURL:t,pushChainFunction:t=>{a.push(t),n=s(a)},uploadFiles:async(s,a)=>{const r=`${t}/files`,o=new FormData,i="undefined"!=typeof navigator&&"ReactNative"===navigator.product;void 0!==s["bucket-id"]&&o.append("bucket-id",s["bucket-id"]),void 0!==s["metadata[]"]&&s["metadata[]"].forEach((t=>{i?o.append("metadata[]",{string:JSON.stringify(t),type:"application/json",name:""}):o.append("metadata[]",new Blob([JSON.stringify(t)],{type:"application/json"}),"")})),void 0!==s["file[]"]&&s["file[]"].forEach((t=>{o.append("file[]",t)}));const u=await n(r,{...a,method:"POST",body:o});if(u.status>=300){const t=[412].includes(u.status)?null:await u.text(),s=t?JSON.parse(t):{};throw new e(s,u.status,u.headers)}const d=[204,205,304].includes(u.status)?null:await u.text();return{body:d?JSON.parse(d):{},status:u.status,headers:u.headers}},deleteFile:async(s,a)=>{const r=`${t}/files/${s}`,o=await n(r,{...a,method:"DELETE",headers:{...a?.headers}});if(o.status>=300){const t=[412].includes(o.status)?null:await o.text(),s=t?JSON.parse(t):{};throw new e(s,o.status,o.headers)}return{body:void 0,status:o.status,headers:o.headers}},getFile:async(s,a,r)=>{const o=a&&Object.entries(a).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("&"),i=o?`${t}/files/${s}?${o}`:`${t}/files/${s}`,u=await n(i,{...r,method:"GET",headers:{...r?.headers}});if(u.status>=300){const t=[412].includes(u.status)?null:await u.text(),s=t?JSON.parse(t):{};throw new e(s,u.status,u.headers)}return{body:await u.blob(),status:u.status,headers:u.headers}},getFileMetadataHeaders:async(s,a,r)=>{const o=a&&Object.entries(a).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("&"),i=o?`${t}/files/${s}?${o}`:`${t}/files/${s}`,u=await n(i,{...r,method:"HEAD",headers:{...r?.headers}});if(u.status>=300){const t=[412].includes(u.status)?null:await u.text(),s=t?JSON.parse(t):{};throw new e(s,u.status,u.headers)}return{body:void 0,status:u.status,headers:u.headers}},replaceFile:async(s,a,r)=>{const o=`${t}/files/${s}`,i=new FormData,u="undefined"!=typeof navigator&&"ReactNative"===navigator.product;void 0!==a.metadata&&(u?i.append("metadata",{string:JSON.stringify(a.metadata),type:"application/json",name:""}):i.append("metadata",new Blob([JSON.stringify(a.metadata)],{type:"application/json"}),"")),void 0!==a.file&&i.append("file",a.file);const d=await n(o,{...r,method:"PUT",body:i});if(d.status>=300){const t=[412].includes(d.status)?null:await d.text(),s=t?JSON.parse(t):{};throw new e(s,d.status,d.headers)}const c=[204,205,304].includes(d.status)?null:await d.text();return{body:c?JSON.parse(c):{},status:d.status,headers:d.headers}},getFilePresignedURL:async(s,a)=>{const r=`${t}/files/${s}/presignedurl`,o=await n(r,{...a,method:"GET",headers:{...a?.headers}});if(o.status>=300){const t=[412].includes(o.status)?null:await o.text(),s=t?JSON.parse(t):{};throw new e(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}},deleteBrokenMetadata:async s=>{const a=`${t}/ops/delete-broken-metadata`,r=await n(a,{...s,method:"POST",headers:{...s?.headers}});if(r.status>=300){const t=[412].includes(r.status)?null:await r.text(),s=t?JSON.parse(t):{};throw new e(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}},deleteOrphanedFiles:async s=>{const a=`${t}/ops/delete-orphans`,r=await n(a,{...s,method:"POST",headers:{...s?.headers}});if(r.status>=300){const t=[412].includes(r.status)?null:await r.text(),s=t?JSON.parse(t):{};throw new e(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}},listBrokenMetadata:async s=>{const a=`${t}/ops/list-broken-metadata`,r=await n(a,{...s,method:"POST",headers:{...s?.headers}});if(r.status>=300){const t=[412].includes(r.status)?null:await r.text(),s=t?JSON.parse(t):{};throw new e(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}},listFilesNotUploaded:async s=>{const a=`${t}/ops/list-not-uploaded`,r=await n(a,{...s,method:"POST",headers:{...s?.headers}});if(r.status>=300){const t=[412].includes(r.status)?null:await r.text(),s=t?JSON.parse(t):{};throw new e(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}},listOrphanedFiles:async s=>{const a=`${t}/ops/list-orphans`,r=await n(a,{...s,method:"POST",headers:{...s?.headers}});if(r.status>=300){const t=[412].includes(r.status)?null:await r.text(),s=t?JSON.parse(t):{};throw new e(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}},getVersion:async s=>{const a=`${t}/version`,r=await n(a,{...s,method:"GET",headers:{...s?.headers}});if(r.status>=300){const t=[412].includes(r.status)?null:await r.text(),s=t?JSON.parse(t):{};throw new e(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}}}})(p,[]),N=((t,a=[])=>{let n=s(a);const r=async(s,a)=>{const r=await n(`${t}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s),...a}),o=await r.text(),i=o?JSON.parse(o):{},u={body:i,status:r.status,headers:r.headers};if(i.errors)throw new e(i,r.status,r.headers);return u};return{request:function(t,s,e){if("object"==typeof t&&"kind"in t){const a=t.definitions[0],n={query:t.loc?.source.body||"",variables:s,operationName:a&&"name"in a?a.name?.value:void 0};return r(n,e)}return r(t,s)},url:t,pushChainFunction:t=>{a.push(t),n=s(a)}}})(w,[]),J=((t,a=[])=>{let n=s(a);const r=async(s,a)=>{const r=await n(`${t}${s}`,a);let o;if(o=r.headers.get("content-type")?.includes("application/json")?await r.json():r.headers.get("content-type")?.startsWith("text/")?await r.text():await r.blob(),!r.ok)throw new e(o,r.status,r.headers);return{status:r.status,body:o,headers:r.headers}};return{baseURL:t,fetch:r,post:async(t,s,e={})=>{const a={...e,method:"POST",headers:{Accept:"application/json","Content-Type":"application/json",...e.headers},body:s?JSON.stringify(s):void 0};return r(t,a)},pushChainFunction:t=>{a.push(t),n=s(a)}}})(y,[]);for(const s of c)s({auth:g,storage:O,graphql:N,functions:J,sessionStorage:h});return new b(g,O,N,J,h)}const m=(t,s,e,a)=>a||(s&&e?`https://${s}.${t}.${e}.nhost.run/v1`:`https://local.${t}.local.nhost.run/v1`);t.createClient=function(t={}){const s=t.storage??S();return N({...t,storage:s,configure:[g,...t.configure??[]]})},t.createNhostClient=N,t.createServerClient=function(t){return N({...t,configure:[O,...t.configure??[]]})},t.generateServiceUrl=m,t.withAdminSession=function(t){return({storage:s,graphql:e,functions:a})=>{const n=(r=t,t=>async(s,e={})=>{const a=new Headers(e.headers||{});if(a.has("x-hasura-admin-secret")||a.set("x-hasura-admin-secret",r.adminSecret),r.role&&!a.has("x-hasura-role")&&a.set("x-hasura-role",r.role),r.sessionVariables)for(const[t,n]of Object.entries(r.sessionVariables)){const s=t.startsWith("x-hasura-")?t:`x-hasura-${t}`;a.has(s)||a.set(s,n)}return t(s,{...e,headers:a})});var r;s.pushChainFunction(n),e.pushChainFunction(n),a.pushChainFunction(n)}},t.withClientSideSessionMiddleware=g,t.withServerSideSessionMiddleware=O,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})}));
|
|
2
2
|
//# sourceMappingURL=nhost-js.umd.js.map
|