@nhost/nhost-js
Advanced tools
Comparing version 2.0.1 to 2.0.2
@@ -1,2 +0,2 @@ | ||
import { GenericSchema, NhostGraphqlClient } from '@nhost/graphql-js'; | ||
import { NhostGraphqlClient } from '@nhost/graphql-js'; | ||
import { NhostClientConstructorParams } from '../utils/types'; | ||
@@ -6,3 +6,3 @@ /** | ||
*/ | ||
export declare function createGraphqlClient<Schema extends GenericSchema | undefined>(params: NhostClientConstructorParams<Schema>): NhostGraphqlClient<Schema>; | ||
export declare function createGraphqlClient(params: NhostClientConstructorParams): NhostGraphqlClient; | ||
//# sourceMappingURL=graphql.d.ts.map |
@@ -1,2 +0,2 @@ | ||
import { GenericSchema, NhostGraphqlClient } from '@nhost/graphql-js'; | ||
import { NhostGraphqlClient } from '@nhost/graphql-js'; | ||
import { HasuraAuthClient } from '@nhost/hasura-auth-js'; | ||
@@ -6,8 +6,8 @@ import { HasuraStorageClient } from '@nhost/hasura-storage-js'; | ||
import { NhostFunctionsClient } from './functions'; | ||
export declare const createNhostClient: <Schema extends GenericSchema | undefined = undefined>(params: NhostClientConstructorParams<Schema>) => NhostClient<Schema>; | ||
export declare class NhostClient<Schema extends GenericSchema | undefined = undefined> { | ||
export declare const createNhostClient: (params: NhostClientConstructorParams) => NhostClient; | ||
export declare class NhostClient { | ||
auth: HasuraAuthClient; | ||
storage: HasuraStorageClient; | ||
functions: NhostFunctionsClient; | ||
graphql: NhostGraphqlClient<Schema>; | ||
graphql: NhostGraphqlClient; | ||
private _adminSecret?; | ||
@@ -25,3 +25,3 @@ readonly devTools?: boolean; | ||
*/ | ||
constructor({ refreshIntervalTime, clientStorage, clientStorageType, autoRefreshToken, autoSignIn, adminSecret, devTools, start, schema, ...urlParams }: NhostClientConstructorParams<Schema>); | ||
constructor({ refreshIntervalTime, clientStorage, clientStorageType, autoRefreshToken, autoSignIn, adminSecret, devTools, start, ...urlParams }: NhostClientConstructorParams); | ||
get adminSecret(): string | undefined; | ||
@@ -28,0 +28,0 @@ set adminSecret(newValue: string | undefined); |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("@nhost/hasura-auth-js"),b=require("@nhost/hasura-storage-js"),A=require("cross-fetch"),S=require("@nhost/graphql-js"),y=/^((?<protocol>http[s]?):\/\/)?(?<host>localhost)(:(?<port>(\d+|__\w+__)))?$/;function h(t,e){const{backendUrl:s,subdomain:o,region:i}=t;if(s)return`${s}/v1/${e}`;if(!o)throw new Error("Either `backendUrl` or `subdomain` must be set.");const r=o.match(y);if(r!=null&&r.groups){const{protocol:n="http",host:d,port:f=1337}=r.groups,u=v(e);return u||`${n}://${d}:${f}/v1/${e}`}if(!i)throw new Error('`region` must be set when using a `subdomain` other than "localhost".');return`https://${o}.${e}.${i}.nhost.run/v1`}function m(){return typeof window<"u"}function q(){return typeof process<"u"&&process.env}function v(t){return m()||!q()?null:process.env[`NHOST_${t.toUpperCase()}_URL`]}function w(t){const e="subdomain"in t||"backendUrl"in t?h(t,"auth"):t.authUrl;if(!e)throw new Error("Please provide `subdomain` or `authUrl`.");return new g.HasuraAuthClient({url:e,...t})}function p(t){const e="subdomain"in t||"backendUrl"in t?h(t,"functions"):t.functionsUrl;if(!e)throw new Error("Please provide `subdomain` or `functionsUrl`.");return new k({url:e,...t})}class k{constructor(e){const{url:s,adminSecret:o}=e;this.url=s,this.accessToken=null,this.adminSecret=o}async call(e,s,o){const i={"Content-Type":"application/json",...this.generateAccessTokenHeaders(),...o==null?void 0:o.headers};try{const r=await A(e,{body:JSON.stringify(s),headers:i,method:"POST"});if(!r.ok)throw new Error(r.statusText);let n;try{n=await r.json()}catch{n=await r.text()}return{res:{data:n,status:r.status,statusText:r.statusText},error:null}}catch(r){const n=r;return{res:null,error:{message:n.message,status:n.name==="AbortError"?0:500,error:n.name==="AbortError"?"abort-error":"unknown"}}}}setAccessToken(e){if(!e){this.accessToken=null;return}this.accessToken=e}generateAccessTokenHeaders(){return this.adminSecret?{"x-hasura-admin-secret":this.adminSecret}:this.accessToken?{Authorization:`Bearer ${this.accessToken}`}:{}}}function T(t){const e="subdomain"in t||"backendUrl"in t?h(t,"graphql"):t.graphqlUrl;if(!e)throw new Error("Please provide `subdomain` or `graphqlUrl`.");return new S.NhostGraphqlClient({url:e,...t})}function C(t){const e="subdomain"in t||"backendUrl"in t?h(t,"storage"):t.storageUrl;if(!e)throw new Error("Please provide `subdomain` or `storageUrl`.");return new b.HasuraStorageClient({url:e,...t})}const E=t=>new U(t);class U{constructor({refreshIntervalTime:e,clientStorage:s,clientStorageType:o,autoRefreshToken:i,autoSignIn:r,adminSecret:n,devTools:d,start:f=!0,schema:u,...a}){this.auth=w({refreshIntervalTime:e,clientStorage:s,clientStorageType:o,autoRefreshToken:i,autoSignIn:r,start:f,...a}),this.storage=C({adminSecret:n,...a}),this.functions=p({adminSecret:n,...a}),this.graphql=T({adminSecret:n,schema:u,...a}),this.auth.onAuthStateChanged((c,l)=>{c==="SIGNED_OUT"&&(this.storage.setAccessToken(void 0),this.functions.setAccessToken(void 0),this.graphql.setAccessToken(void 0))}),this.auth.onTokenChanged(c=>{const l=c==null?void 0:c.accessToken;this.storage.setAccessToken(l),this.functions.setAccessToken(l),this.graphql.setAccessToken(l)}),this._adminSecret=n,this.devTools=d}get adminSecret(){return this._adminSecret}set adminSecret(e){this._adminSecret=e,this.storage.setAdminSecret(e)}}exports.NhostClient=U;exports.NhostFunctionsClient=k;exports.createAuthClient=w;exports.createFunctionsClient=p;exports.createGraphqlClient=T;exports.createNhostClient=E;exports.createStorageClient=C;for(const t in g)t!=="default"&&!Object.prototype.hasOwnProperty.call(exports,t)&&Object.defineProperty(exports,t,{enumerable:!0,get:()=>g[t]});for(const t in b)t!=="default"&&!Object.prototype.hasOwnProperty.call(exports,t)&&Object.defineProperty(exports,t,{enumerable:!0,get:()=>b[t]}); | ||
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("@nhost/hasura-auth-js"),g=require("@nhost/hasura-storage-js"),U=require("cross-fetch"),A=require("@nhost/graphql-js"),S=/^((?<protocol>http[s]?):\/\/)?(?<host>localhost)(:(?<port>(\d+|__\w+__)))?$/;function l(t,e){const{backendUrl:s,subdomain:o,region:c}=t;if(s)return`${s}/v1/${e}`;if(!o)throw new Error("Either `backendUrl` or `subdomain` must be set.");const r=o.match(S);if(r!=null&&r.groups){const{protocol:n="http",host:h,port:d=1337}=r.groups,i=q(e);return i||`${n}://${h}:${d}/v1/${e}`}if(!c)throw new Error('`region` must be set when using a `subdomain` other than "localhost".');return`https://${o}.${e}.${c}.nhost.run/v1`}function y(){return typeof window<"u"}function m(){return typeof process<"u"&&process.env}function q(t){return y()||!m()?null:process.env[`NHOST_${t.toUpperCase()}_URL`]}function b(t){const e="subdomain"in t||"backendUrl"in t?l(t,"auth"):t.authUrl;if(!e)throw new Error("Please provide `subdomain` or `authUrl`.");return new f.HasuraAuthClient({url:e,...t})}function w(t){const e="subdomain"in t||"backendUrl"in t?l(t,"functions"):t.functionsUrl;if(!e)throw new Error("Please provide `subdomain` or `functionsUrl`.");return new p({url:e,...t})}class p{constructor(e){const{url:s,adminSecret:o}=e;this.url=s,this.accessToken=null,this.adminSecret=o}async call(e,s,o){const c={"Content-Type":"application/json",...this.generateAccessTokenHeaders(),...o==null?void 0:o.headers};try{const r=await U(e,{body:JSON.stringify(s),headers:c,method:"POST"});if(!r.ok)throw new Error(r.statusText);let n;try{n=await r.json()}catch{n=await r.text()}return{res:{data:n,status:r.status,statusText:r.statusText},error:null}}catch(r){const n=r;return{res:null,error:{message:n.message,status:n.name==="AbortError"?0:500,error:n.name==="AbortError"?"abort-error":"unknown"}}}}setAccessToken(e){if(!e){this.accessToken=null;return}this.accessToken=e}generateAccessTokenHeaders(){return this.adminSecret?{"x-hasura-admin-secret":this.adminSecret}:this.accessToken?{Authorization:`Bearer ${this.accessToken}`}:{}}}function k(t){const e="subdomain"in t||"backendUrl"in t?l(t,"graphql"):t.graphqlUrl;if(!e)throw new Error("Please provide `subdomain` or `graphqlUrl`.");return new A.NhostGraphqlClient({url:e,...t})}function T(t){const e="subdomain"in t||"backendUrl"in t?l(t,"storage"):t.storageUrl;if(!e)throw new Error("Please provide `subdomain` or `storageUrl`.");return new g.HasuraStorageClient({url:e,...t})}const v=t=>new C(t);class C{constructor({refreshIntervalTime:e,clientStorage:s,clientStorageType:o,autoRefreshToken:c,autoSignIn:r,adminSecret:n,devTools:h,start:d=!0,...i}){this.auth=b({refreshIntervalTime:e,clientStorage:s,clientStorageType:o,autoRefreshToken:c,autoSignIn:r,start:d,...i}),this.storage=T({adminSecret:n,...i}),this.functions=w({adminSecret:n,...i}),this.graphql=k({adminSecret:n,...i}),this.auth.onAuthStateChanged((u,a)=>{u==="SIGNED_OUT"&&(this.storage.setAccessToken(void 0),this.functions.setAccessToken(void 0),this.graphql.setAccessToken(void 0))}),this.auth.onTokenChanged(u=>{const a=u==null?void 0:u.accessToken;this.storage.setAccessToken(a),this.functions.setAccessToken(a),this.graphql.setAccessToken(a)}),this._adminSecret=n,this.devTools=h}get adminSecret(){return this._adminSecret}set adminSecret(e){this._adminSecret=e,this.storage.setAdminSecret(e)}}exports.NhostClient=C;exports.NhostFunctionsClient=p;exports.createAuthClient=b;exports.createFunctionsClient=w;exports.createGraphqlClient=k;exports.createNhostClient=v;exports.createStorageClient=T;for(const t in f)t!=="default"&&!Object.prototype.hasOwnProperty.call(exports,t)&&Object.defineProperty(exports,t,{enumerable:!0,get:()=>f[t]});for(const t in g)t!=="default"&&!Object.prototype.hasOwnProperty.call(exports,t)&&Object.defineProperty(exports,t,{enumerable:!0,get:()=>g[t]}); | ||
//# sourceMappingURL=index.cjs.js.map |
@@ -1,10 +0,10 @@ | ||
import { HasuraAuthClient as g } from "@nhost/hasura-auth-js"; | ||
import { HasuraAuthClient as f } from "@nhost/hasura-auth-js"; | ||
export * from "@nhost/hasura-auth-js"; | ||
import { HasuraStorageClient as w } from "@nhost/hasura-storage-js"; | ||
import { HasuraStorageClient as g } from "@nhost/hasura-storage-js"; | ||
export * from "@nhost/hasura-storage-js"; | ||
import T from "cross-fetch"; | ||
import { NhostGraphqlClient as b } from "@nhost/graphql-js"; | ||
const k = /^((?<protocol>http[s]?):\/\/)?(?<host>localhost)(:(?<port>(\d+|__\w+__)))?$/; | ||
function l(t, e) { | ||
const { backendUrl: s, subdomain: o, region: i } = t; | ||
import w from "cross-fetch"; | ||
import { NhostGraphqlClient as T } from "@nhost/graphql-js"; | ||
const b = /^((?<protocol>http[s]?):\/\/)?(?<host>localhost)(:(?<port>(\d+|__\w+__)))?$/; | ||
function a(t, e) { | ||
const { backendUrl: s, subdomain: o, region: c } = t; | ||
if (s) | ||
@@ -14,33 +14,33 @@ return `${s}/v1/${e}`; | ||
throw new Error("Either `backendUrl` or `subdomain` must be set."); | ||
const r = o.match(k); | ||
const r = o.match(b); | ||
if (r != null && r.groups) { | ||
const { protocol: n = "http", host: d, port: f = 1337 } = r.groups, u = U(e); | ||
return u || `${n}://${d}:${f}/v1/${e}`; | ||
const { protocol: n = "http", host: l, port: d = 1337 } = r.groups, i = m(e); | ||
return i || `${n}://${l}:${d}/v1/${e}`; | ||
} | ||
if (!i) | ||
if (!c) | ||
throw new Error('`region` must be set when using a `subdomain` other than "localhost".'); | ||
return `https://${o}.${e}.${i}.nhost.run/v1`; | ||
return `https://${o}.${e}.${c}.nhost.run/v1`; | ||
} | ||
function p() { | ||
function k() { | ||
return typeof window < "u"; | ||
} | ||
function m() { | ||
function p() { | ||
return typeof process < "u" && process.env; | ||
} | ||
function m(t) { | ||
return k() || !p() ? null : process.env[`NHOST_${t.toUpperCase()}_URL`]; | ||
} | ||
function U(t) { | ||
return p() || !m() ? null : process.env[`NHOST_${t.toUpperCase()}_URL`]; | ||
} | ||
function A(t) { | ||
const e = "subdomain" in t || "backendUrl" in t ? l(t, "auth") : t.authUrl; | ||
const e = "subdomain" in t || "backendUrl" in t ? a(t, "auth") : t.authUrl; | ||
if (!e) | ||
throw new Error("Please provide `subdomain` or `authUrl`."); | ||
return new g({ url: e, ...t }); | ||
return new f({ url: e, ...t }); | ||
} | ||
function S(t) { | ||
const e = "subdomain" in t || "backendUrl" in t ? l(t, "functions") : t.functionsUrl; | ||
function A(t) { | ||
const e = "subdomain" in t || "backendUrl" in t ? a(t, "functions") : t.functionsUrl; | ||
if (!e) | ||
throw new Error("Please provide `subdomain` or `functionsUrl`."); | ||
return new C({ url: e, ...t }); | ||
return new S({ url: e, ...t }); | ||
} | ||
class C { | ||
class S { | ||
constructor(e) { | ||
@@ -51,3 +51,3 @@ const { url: s, adminSecret: o } = e; | ||
async call(e, s, o) { | ||
const i = { | ||
const c = { | ||
"Content-Type": "application/json", | ||
@@ -58,5 +58,5 @@ ...this.generateAccessTokenHeaders(), | ||
try { | ||
const r = await T(e, { | ||
const r = await w(e, { | ||
body: JSON.stringify(s), | ||
headers: i, | ||
headers: c, | ||
method: "POST" | ||
@@ -103,16 +103,16 @@ }); | ||
} | ||
function E(t) { | ||
const e = "subdomain" in t || "backendUrl" in t ? l(t, "graphql") : t.graphqlUrl; | ||
function C(t) { | ||
const e = "subdomain" in t || "backendUrl" in t ? a(t, "graphql") : t.graphqlUrl; | ||
if (!e) | ||
throw new Error("Please provide `subdomain` or `graphqlUrl`."); | ||
return new b({ url: e, ...t }); | ||
return new T({ url: e, ...t }); | ||
} | ||
function v(t) { | ||
const e = "subdomain" in t || "backendUrl" in t ? l(t, "storage") : t.storageUrl; | ||
function E(t) { | ||
const e = "subdomain" in t || "backendUrl" in t ? a(t, "storage") : t.storageUrl; | ||
if (!e) | ||
throw new Error("Please provide `subdomain` or `storageUrl`."); | ||
return new w({ url: e, ...t }); | ||
return new g({ url: e, ...t }); | ||
} | ||
const N = (t) => new $(t); | ||
class $ { | ||
const y = (t) => new v(t); | ||
class v { | ||
constructor({ | ||
@@ -122,24 +122,23 @@ refreshIntervalTime: e, | ||
clientStorageType: o, | ||
autoRefreshToken: i, | ||
autoRefreshToken: c, | ||
autoSignIn: r, | ||
adminSecret: n, | ||
devTools: d, | ||
start: f = !0, | ||
schema: u, | ||
...h | ||
devTools: l, | ||
start: d = !0, | ||
...i | ||
}) { | ||
this.auth = A({ | ||
this.auth = U({ | ||
refreshIntervalTime: e, | ||
clientStorage: s, | ||
clientStorageType: o, | ||
autoRefreshToken: i, | ||
autoRefreshToken: c, | ||
autoSignIn: r, | ||
start: f, | ||
...h | ||
}), this.storage = v({ adminSecret: n, ...h }), this.functions = S({ adminSecret: n, ...h }), this.graphql = E({ adminSecret: n, schema: u, ...h }), this.auth.onAuthStateChanged((c, a) => { | ||
c === "SIGNED_OUT" && (this.storage.setAccessToken(void 0), this.functions.setAccessToken(void 0), this.graphql.setAccessToken(void 0)); | ||
}), this.auth.onTokenChanged((c) => { | ||
const a = c == null ? void 0 : c.accessToken; | ||
this.storage.setAccessToken(a), this.functions.setAccessToken(a), this.graphql.setAccessToken(a); | ||
}), this._adminSecret = n, this.devTools = d; | ||
start: d, | ||
...i | ||
}), this.storage = E({ adminSecret: n, ...i }), this.functions = A({ adminSecret: n, ...i }), this.graphql = C({ adminSecret: n, ...i }), this.auth.onAuthStateChanged((u, h) => { | ||
u === "SIGNED_OUT" && (this.storage.setAccessToken(void 0), this.functions.setAccessToken(void 0), this.graphql.setAccessToken(void 0)); | ||
}), this.auth.onTokenChanged((u) => { | ||
const h = u == null ? void 0 : u.accessToken; | ||
this.storage.setAccessToken(h), this.functions.setAccessToken(h), this.graphql.setAccessToken(h); | ||
}), this._adminSecret = n, this.devTools = l; | ||
} | ||
@@ -154,10 +153,10 @@ get adminSecret() { | ||
export { | ||
$ as NhostClient, | ||
C as NhostFunctionsClient, | ||
A as createAuthClient, | ||
S as createFunctionsClient, | ||
E as createGraphqlClient, | ||
N as createNhostClient, | ||
v as createStorageClient | ||
v as NhostClient, | ||
S as NhostFunctionsClient, | ||
U as createAuthClient, | ||
A as createFunctionsClient, | ||
C as createGraphqlClient, | ||
y as createNhostClient, | ||
E as createStorageClient | ||
}; | ||
//# sourceMappingURL=index.esm.js.map |
@@ -1,2 +0,1 @@ | ||
import { GenericSchema } from '@nhost/graphql-js'; | ||
import { NhostAuthConstructorParams } from '@nhost/hasura-auth-js'; | ||
@@ -39,4 +38,3 @@ export declare type ErrorPayload = { | ||
export declare type BackendOrSubdomain = BackendUrl | Subdomain; | ||
export interface NhostClientConstructorParams<Schema extends GenericSchema | undefined = undefined> extends Partial<BackendUrl>, Partial<Subdomain>, Partial<ServiceUrls>, Omit<NhostAuthConstructorParams, 'url'> { | ||
schema?: Schema; | ||
export interface NhostClientConstructorParams extends Partial<BackendUrl>, Partial<Subdomain>, Partial<ServiceUrls>, Omit<NhostAuthConstructorParams, 'url'> { | ||
/** | ||
@@ -43,0 +41,0 @@ * When set, the admin secret is sent as a header, `x-hasura-admin-secret`, |
{ | ||
"name": "@nhost/nhost-js", | ||
"version": "2.0.1", | ||
"version": "2.0.2", | ||
"description": "Nhost JavaScript SDK", | ||
@@ -49,3 +49,3 @@ "license": "MIT", | ||
"@nhost/hasura-storage-js": "2.0.0", | ||
"@nhost/graphql-js": "0.0.2" | ||
"@nhost/graphql-js": "0.0.3" | ||
}, | ||
@@ -52,0 +52,0 @@ "devDependencies": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
687646
896
+ Added@nhost/graphql-js@0.0.3(transitive)
- Removed@nhost/graphql-js@0.0.2(transitive)
- Removedjson-to-graphql-query@2.3.0(transitive)
Updated@nhost/graphql-js@0.0.3