@nhost/nhost-js
Version:
Nhost JavaScript SDK
2 lines • 2.38 kB
JavaScript
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./fetch-B_MCWy66.cjs"),s=require("./refreshSession-B_E2FLUs.cjs"),t=require("./nhost-js/auth.cjs"),n=require("./nhost-js/functions.cjs"),r=require("./graphql-Cg1kBTkm.cjs"),o=require("./session-MPM1dzMp.cjs"),i=require("./nhost-js/storage.cjs");var a=({auth:s,storage:t,graphql:n,functions:r,sessionStorage:o})=>{const i=[e.sessionRefreshMiddleware(s,o),e.updateSessionFromResponseMiddleware(o),e.attachAccessTokenMiddleware(o)];for(const e of i)s.pushChainFunction(e),t.pushChainFunction(e),n.pushChainFunction(e),r.pushChainFunction(e)},c=({auth:s,storage:t,graphql:n,functions:r,sessionStorage:o})=>{const i=[e.updateSessionFromResponseMiddleware(o),e.attachAccessTokenMiddleware(o)];for(const e of i)s.pushChainFunction(e),t.pushChainFunction(e),n.pushChainFunction(e),r.pushChainFunction(e)};var u=class{auth;storage;graphql;functions;sessionStorage;constructor(e,s,t,n,r){this.auth=e,this.storage=s,this.graphql=t,this.functions=n,this.sessionStorage=r}getUserSession(){return this.sessionStorage.get()}async refreshSession(e=60){return s.refreshSession(this.auth,this.sessionStorage,e)}clearSession(){this.sessionStorage.remove()}};function h(e={}){const{subdomain:s,region:a,authUrl:c,storageUrl:h,graphqlUrl:l,functionsUrl:p,storage:f=o.detectStorage(),configure:S=[]}=e,d=new o.SessionStorage(f),C=g("auth",s,a,c),q=g("storage",s,a,h),w=g("graphql",s,a,l),F=g("functions",s,a,p),j=t.createAPIClient(C),v=i.createAPIClient(q,[]),M=r.createAPIClient(w,[]),x=n.createAPIClient(F,[]);for(const t of S)t({auth:j,storage:v,graphql:M,functions:x,sessionStorage:d});return new u(j,v,M,x,d)}var g=(e,s,t,n)=>n||(s&&t?`https://${s}.${e}.${t}.nhost.run/v1`:`https://local.${e}.local.nhost.run/v1`);exports.createClient=function(e={}){const s=e.storage??o.detectStorage();return h({...e,storage:s,configure:[a,...e.configure??[]]})},exports.createNhostClient=h,exports.createServerClient=function(e){return h({...e,configure:[c,...e.configure??[]]})},exports.generateServiceUrl=g,exports.withAdminSession=function(s){return({storage:t,graphql:n,functions:r})=>{const o=e.withAdminSessionMiddleware(s);t.pushChainFunction(o),n.pushChainFunction(o),r.pushChainFunction(o)}},exports.withClientSideSessionMiddleware=a,exports.withServerSideSessionMiddleware=c;
//# sourceMappingURL=nhost-js.cjs.map