@nhost/nhost-js 1.5.0 → 1.5.2

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/index.cjs.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var E=Object.defineProperty,$=Object.defineProperties;var _=Object.getOwnPropertyDescriptors;var d=Object.getOwnPropertySymbols;var A=Object.prototype.hasOwnProperty,m=Object.prototype.propertyIsEnumerable;var p=(t,e,s)=>e in t?E(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s,h=(t,e)=>{for(var s in e||(e={}))A.call(e,s)&&p(t,s,e[s]);if(d)for(var s of d(e))m.call(e,s)&&p(t,s,e[s]);return t},T=(t,e)=>$(t,_(e));var b=(t,e)=>{var s={};for(var r in t)A.call(t,r)&&e.indexOf(r)<0&&(s[r]=t[r]);if(t!=null&&d)for(var r of d(t))e.indexOf(r)<0&&m.call(t,r)&&(s[r]=t[r]);return s};Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var N=require("@nhost/hasura-auth-js"),U=require("@nhost/hasura-storage-js"),L=require("axios"),H=require("graphql");function G(t){return t&&typeof t=="object"&&"default"in t?t:{default:t}}var S=G(L);class q{constructor(e){const{url:s,adminSecret:r}=e;this.accessToken=null,this.adminSecret=r,this.instance=S.default.create({baseURL:s})}async call(e,s,r){const c=h(h({},this.generateAccessTokenHeaders()),r==null?void 0:r.headers);let n;try{n=await this.instance.post(e,s,T(h({},r),{headers:c}))}catch(i){if(i instanceof Error)return{res:null,error:i}}return n?{res:n,error:null}:{res:null,error:new Error("Unable to make post request to funtion")}}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}`}:{}}}class w{constructor(e){const{url:s,adminSecret:r}=e;this.url=s,this.accessToken=null,this.adminSecret=r,this.instance=S.default.create({baseURL:s})}async request(e,s,r){const c=h(h({},this.generateAccessTokenHeaders()),r==null?void 0:r.headers);try{const n="",u=(await this.instance.post("",{operationName:n||void 0,query:typeof e=="string"?e:H.print(e),variables:s},T(h({},r),{headers:c}))).data,{data:o}=u;return u.errors?{data:null,error:u.errors}:typeof o!="object"||Array.isArray(o)||o===null?{data:null,error:new Error("incorrect response data from GraphQL server")}:{data:o,error:null}}catch(n){return n instanceof Error?{data:null,error:n}:(console.error(n),{data:null,error:new Error("Unable to get do GraphQL request")})}}getUrl(){return this.url}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}`}:{}}}const j=/^localhost(:\d+)*$/g;function k(t,e){const{backendUrl:s,subdomain:r,region:c}=t;if(!s&&!r)throw new Error("Either `backendUrl` or `subdomain` must be set.");if(s)return`${s}/v1/${e}`;if(!r)throw new Error("`subdomain` must be set if `backendUrl` is not set.");const n=r.match(j);if(n&&n.length>0){const i=n[0];return i==="localhost"?`http://localhost:1337/v1/${e}`:`http://${i}/v1/${e}`}if(!c)throw new Error('`region` must be set when using a `subdomain` other than "localhost".');return`https://${r}.${e}.${c}.nhost.run/v1`}class v{constructor(F){var f=F,{refreshIntervalTime:e,clientStorageGetter:s,clientStorageSetter:r,clientStorage:c,clientStorageType:n,autoRefreshToken:i,autoSignIn:u,adminSecret:o,devTools:C,start:y=!0}=f,l=b(f,["refreshIntervalTime","clientStorageGetter","clientStorageSetter","clientStorage","clientStorageType","autoRefreshToken","autoSignIn","adminSecret","devTools","start"]);var g;this.auth=new N.HasuraAuthClient({url:k(l,"auth"),refreshIntervalTime:e,clientStorageGetter:s,clientStorageSetter:r,clientStorage:c,clientStorageType:n,autoRefreshToken:i,autoSignIn:u,start:y}),this.storage=new U.HasuraStorageClient({url:k(l,"storage"),adminSecret:o}),this.functions=new q({url:k(l,"functions"),adminSecret:o}),this.graphql=new w({url:k(l,"graphql"),adminSecret:o}),this.storage.setAccessToken(this.auth.getAccessToken()),this.functions.setAccessToken(this.auth.getAccessToken()),this.graphql.setAccessToken(this.auth.getAccessToken()),(g=this.auth.client)==null||g.onStart(()=>{this.auth.onAuthStateChanged((a,O)=>{a==="SIGNED_OUT"&&(this.storage.setAccessToken(void 0),this.functions.setAccessToken(void 0),this.graphql.setAccessToken(void 0))}),this.auth.onTokenChanged(a=>{this.storage.setAccessToken(a==null?void 0:a.accessToken),this.functions.setAccessToken(a==null?void 0:a.accessToken),this.graphql.setAccessToken(a==null?void 0:a.accessToken)})}),this._adminSecret=o,this.devTools=C}get adminSecret(){return this._adminSecret}set adminSecret(e){this._adminSecret=e,this.storage.setAdminSecret(e)}}const x=t=>new v(t);exports.NhostClient=v;exports.NhostFunctionsClient=q;exports.NhostGraphqlClient=w;exports.createClient=x;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var m=require("@nhost/hasura-auth-js"),b=require("@nhost/hasura-storage-js"),S=require("axios"),q=require("graphql");function w(n){return n&&typeof n=="object"&&"default"in n?n:{default:n}}var k=w(S);class T{constructor(e){const{url:s,adminSecret:t}=e;this.accessToken=null,this.adminSecret=t,this.instance=k.default.create({baseURL:s})}async call(e,s,t){const c={...this.generateAccessTokenHeaders(),...t==null?void 0:t.headers};let r;try{r=await this.instance.post(e,s,{...t,headers:c})}catch(i){if(i instanceof Error)return{res:null,error:i}}return r?{res:r,error:null}:{res:null,error:new Error("Unable to make post request to funtion")}}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}`}:{}}}class f{constructor(e){const{url:s,adminSecret:t}=e;this.url=s,this.accessToken=null,this.adminSecret=t,this.instance=k.default.create({baseURL:s})}async request(e,s,t){const c={...this.generateAccessTokenHeaders(),...t==null?void 0:t.headers};try{const r="",h=(await this.instance.post("",{operationName:r||void 0,query:typeof e=="string"?e:q.print(e),variables:s},{...t,headers:c})).data,{data:o}=h;return h.errors?{data:null,error:h.errors}:typeof o!="object"||Array.isArray(o)||o===null?{data:null,error:new Error("incorrect response data from GraphQL server")}:{data:o,error:null}}catch(r){return r instanceof Error?{data:null,error:r}:(console.error(r),{data:null,error:new Error("Unable to get do GraphQL request")})}}getUrl(){return this.url}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}`}:{}}}const v=/^localhost(:\d+)*$/g;function l(n,e){const{backendUrl:s,subdomain:t,region:c}=n;if(!s&&!t)throw new Error("Either `backendUrl` or `subdomain` must be set.");if(s)return`${s}/v1/${e}`;if(!t)throw new Error("`subdomain` must be set if `backendUrl` is not set.");const r=t.match(v);if(r&&r.length>0){const i=r[0];return i==="localhost"?`http://localhost:1337/v1/${e}`:`http://${i}/v1/${e}`}if(!c)throw new Error('`region` must be set when using a `subdomain` other than "localhost".');return`https://${t}.${e}.${c}.nhost.run/v1`}class g{constructor({refreshIntervalTime:e,clientStorageGetter:s,clientStorageSetter:t,clientStorage:c,clientStorageType:r,autoRefreshToken:i,autoSignIn:h,adminSecret:o,devTools:p,start:A=!0,...u}){var d;this.auth=new m.HasuraAuthClient({url:l(u,"auth"),refreshIntervalTime:e,clientStorageGetter:s,clientStorageSetter:t,clientStorage:c,clientStorageType:r,autoRefreshToken:i,autoSignIn:h,start:A}),this.storage=new b.HasuraStorageClient({url:l(u,"storage"),adminSecret:o}),this.functions=new T({url:l(u,"functions"),adminSecret:o}),this.graphql=new f({url:l(u,"graphql"),adminSecret:o}),this.storage.setAccessToken(this.auth.getAccessToken()),this.functions.setAccessToken(this.auth.getAccessToken()),this.graphql.setAccessToken(this.auth.getAccessToken()),(d=this.auth.client)==null||d.onStart(()=>{this.auth.onAuthStateChanged((a,y)=>{a==="SIGNED_OUT"&&(this.storage.setAccessToken(void 0),this.functions.setAccessToken(void 0),this.graphql.setAccessToken(void 0))}),this.auth.onTokenChanged(a=>{this.storage.setAccessToken(a==null?void 0:a.accessToken),this.functions.setAccessToken(a==null?void 0:a.accessToken),this.graphql.setAccessToken(a==null?void 0:a.accessToken)})}),this._adminSecret=o,this.devTools=p}get adminSecret(){return this._adminSecret}set adminSecret(e){this._adminSecret=e,this.storage.setAdminSecret(e)}}const C=n=>new g(n);exports.NhostClient=g;exports.NhostFunctionsClient=T;exports.NhostGraphqlClient=f;exports.createClient=C;
2
2
  //# sourceMappingURL=index.cjs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs.js","sources":["../src/clients/functions.ts","../src/clients/graphql.ts","../src/utils/helpers.ts","../src/core/nhost-client.ts","../src/index.ts"],"sourcesContent":["import axios, { AxiosInstance, AxiosRequestConfig, AxiosRequestHeaders, AxiosResponse } from 'axios'\n\nimport { FunctionCallResponse } from '../utils/types'\nexport interface NhostFunctionsConstructorParams {\n /**\n * Serverless Functions endpoint.\n */\n url: string\n /**\n * Admin secret. When set, it is sent as an `x-hasura-admin-secret` header for all requests.\n */\n adminSecret?: string\n}\n\n/**\n * @alias Functions\n */\nexport class NhostFunctionsClient {\n private instance: AxiosInstance\n private accessToken: string | null\n private adminSecret?: string\n\n constructor(params: NhostFunctionsConstructorParams) {\n const { url, adminSecret } = params\n\n this.accessToken = null\n this.adminSecret = adminSecret\n this.instance = axios.create({\n baseURL: url\n })\n }\n\n /**\n * Use `nhost.functions.call` to call (sending a POST request to) a serverless function.\n *\n * @example\n * ```ts\n * await nhost.functions.call('send-welcome-email', { email: 'joe@example.com', name: 'Joe Doe' })\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/functions/call\n */\n async call<T = unknown, D = any>(\n url: string,\n data: D,\n config?: AxiosRequestConfig\n ): Promise<FunctionCallResponse<T>> {\n const headers = {\n ...this.generateAccessTokenHeaders(),\n ...config?.headers\n }\n\n let res\n try {\n res = await this.instance.post<T, AxiosResponse<T>, D>(url, data, { ...config, headers })\n } catch (error) {\n if (error instanceof Error) {\n return { res: null, error }\n }\n }\n\n if (!res) {\n return {\n res: null,\n error: new Error('Unable to make post request to funtion')\n }\n }\n\n return { res, error: null }\n }\n\n /**\n * Use `nhost.functions.setAccessToken` to a set an access token to be used in subsequent functions requests. Note that if you're signin in users with `nhost.auth.signIn()` the access token will be set automatically.\n *\n * @example\n * ```ts\n * nhost.functions.setAccessToken('some-access-token')\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/functions/set-access-token\n */\n setAccessToken(accessToken: string | undefined) {\n if (!accessToken) {\n this.accessToken = null\n return\n }\n\n this.accessToken = accessToken\n }\n\n private generateAccessTokenHeaders(): AxiosRequestHeaders {\n if (this.adminSecret) {\n return {\n 'x-hasura-admin-secret': this.adminSecret\n }\n }\n if (this.accessToken) {\n return {\n Authorization: `Bearer ${this.accessToken}`\n }\n }\n return {}\n }\n}\n","import axios, { AxiosInstance, AxiosRequestConfig, AxiosRequestHeaders } from 'axios'\nimport { DocumentNode, print } from 'graphql'\n\nimport { GraphqlRequestResponse, GraphqlResponse } from '../utils/types'\n\nexport interface NhostGraphqlConstructorParams {\n /**\n * GraphQL endpoint.\n */\n url: string\n /**\n * Admin secret. When set, it is sent as an `x-hasura-admin-secret` header for all requests.\n */\n adminSecret?: string\n}\n\n/**\n * @alias GraphQL\n */\nexport class NhostGraphqlClient {\n private url: string\n private instance: AxiosInstance\n private accessToken: string | null\n private adminSecret?: string\n\n constructor(params: NhostGraphqlConstructorParams) {\n const { url, adminSecret } = params\n\n this.url = url\n this.accessToken = null\n this.adminSecret = adminSecret\n this.instance = axios.create({\n baseURL: url\n })\n }\n\n /**\n * Use `nhost.graphql.request` to send a GraphQL request. For more serious GraphQL usage we recommend using a GraphQL client such as Apollo Client (https://www.apollographql.com/docs/react).\n *\n * @example\n * ```ts\n * const CUSTOMERS = gql`\n * query {\n * customers {\n * id\n * name\n * }\n * }\n * `\n * const { data, error } = await nhost.graphql.request(CUSTOMERS)\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/graphql/request\n */\n async request<T = any, V = any>(\n document: string | DocumentNode,\n variables?: V,\n config?: AxiosRequestConfig\n ): Promise<GraphqlRequestResponse<T>> {\n // add auth headers if any\n const headers = {\n ...this.generateAccessTokenHeaders(),\n ...config?.headers\n }\n\n try {\n const operationName = ''\n const res = await this.instance.post<GraphqlResponse<T>>(\n '',\n {\n operationName: operationName || undefined,\n query: typeof document === 'string' ? document : print(document),\n variables\n },\n { ...config, headers }\n )\n\n const responseData = res.data\n const { data } = responseData\n\n if (responseData.errors) {\n return {\n data: null,\n error: responseData.errors\n }\n }\n\n if (typeof data !== 'object' || Array.isArray(data) || data === null) {\n return {\n data: null,\n error: new Error('incorrect response data from GraphQL server')\n }\n }\n\n return { data, error: null }\n } catch (error) {\n if (error instanceof Error) {\n return { data: null, error }\n }\n console.error(error)\n return {\n data: null,\n error: new Error('Unable to get do GraphQL request')\n }\n }\n }\n\n /**\n * Use `nhost.graphql.getUrl` to get the GraphQL URL.\n *\n * @example\n * ```ts\n * const url = nhost.graphql.getUrl();\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/graphql/get-url\n */\n getUrl(): string {\n return this.url\n }\n\n /**\n * Use `nhost.graphql.setAccessToken` to a set an access token to be used in subsequent graphql requests. Note that if you're signin in users with `nhost.auth.signIn()` the access token will be set automatically.\n *\n * @example\n * ```ts\n * nhost.graphql.setAccessToken('some-access-token')\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/graphql/set-access-token\n */\n setAccessToken(accessToken: string | undefined) {\n if (!accessToken) {\n this.accessToken = null\n return\n }\n\n this.accessToken = accessToken\n }\n\n private generateAccessTokenHeaders(): AxiosRequestHeaders {\n if (this.adminSecret) {\n return {\n 'x-hasura-admin-secret': this.adminSecret\n }\n }\n if (this.accessToken) {\n return {\n Authorization: `Bearer ${this.accessToken}`\n }\n }\n return {}\n }\n}\n","import { NhostClientConstructorParams } from './types'\n\nconst LOCALHOST_REGEX = /^localhost(:\\d+)*$/g\n\n/**\n * `backendUrl` should now be used only when self-hosting\n * `subdomain` and `region` should be used instead when using the Nhost platform\n * `\n * @param backendOrSubdomain\n * @param service\n * @returns\n */\nexport function urlFromParams(\n backendOrSubdomain: Pick<NhostClientConstructorParams, 'region' | 'subdomain' | 'backendUrl'>,\n service: string\n) {\n const { backendUrl, subdomain, region } = backendOrSubdomain\n\n if (!backendUrl && !subdomain) {\n throw new Error('Either `backendUrl` or `subdomain` must be set.')\n }\n\n if (backendUrl) {\n return `${backendUrl}/v1/${service}`\n }\n\n // to make TS happy\n if (!subdomain) {\n throw new Error('`subdomain` must be set if `backendUrl` is not set.')\n }\n\n // check if subdomain is localhost[:port]\n const subdomainLocalhostFound = subdomain.match(LOCALHOST_REGEX)\n if (subdomainLocalhostFound && subdomainLocalhostFound.length > 0) {\n const localhostFound = subdomainLocalhostFound[0]\n\n // no port specified, use standard port 1337\n if (localhostFound === 'localhost') {\n return `http://localhost:1337/v1/${service}`\n }\n\n // port specified\n return `http://${localhostFound}/v1/${service}`\n }\n\n if (!region) {\n throw new Error('`region` must be set when using a `subdomain` other than \"localhost\".')\n }\n\n return `https://${subdomain}.${service}.${region}.nhost.run/v1`\n}\n","import { HasuraAuthClient } from '@nhost/hasura-auth-js'\nimport { HasuraStorageClient } from '@nhost/hasura-storage-js'\n\nimport { NhostFunctionsClient } from '../clients/functions'\nimport { NhostGraphqlClient } from '../clients/graphql'\nimport { urlFromParams } from '../utils/helpers'\nimport { NhostClientConstructorParams } from '../utils/types'\nexport class NhostClient {\n auth: HasuraAuthClient\n storage: HasuraStorageClient\n functions: NhostFunctionsClient\n graphql: NhostGraphqlClient\n private _adminSecret?: string\n readonly devTools?: boolean\n\n /**\n * Nhost Client\n *\n * @example\n * ```ts\n * const nhost = new NhostClient({ subdomain, region });\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript\n */\n constructor({\n refreshIntervalTime,\n clientStorageGetter,\n clientStorageSetter,\n clientStorage,\n clientStorageType,\n autoRefreshToken,\n autoSignIn,\n adminSecret,\n devTools,\n start = true,\n ...urlParams\n }: NhostClientConstructorParams) {\n this.auth = new HasuraAuthClient({\n url: urlFromParams(urlParams, 'auth'),\n refreshIntervalTime,\n clientStorageGetter,\n clientStorageSetter,\n clientStorage,\n clientStorageType,\n autoRefreshToken,\n autoSignIn,\n start\n })\n\n this.storage = new HasuraStorageClient({\n url: urlFromParams(urlParams, 'storage'),\n adminSecret\n })\n\n this.functions = new NhostFunctionsClient({\n url: urlFromParams(urlParams, 'functions'),\n adminSecret\n })\n\n this.graphql = new NhostGraphqlClient({\n url: urlFromParams(urlParams, 'graphql'),\n adminSecret\n })\n\n // * Set current token if token is already accessable\n this.storage.setAccessToken(this.auth.getAccessToken())\n this.functions.setAccessToken(this.auth.getAccessToken())\n this.graphql.setAccessToken(this.auth.getAccessToken())\n\n this.auth.client?.onStart(() => {\n // * Set access token when signing out\n this.auth.onAuthStateChanged((_event, session) => {\n if (_event === 'SIGNED_OUT') {\n this.storage.setAccessToken(undefined)\n this.functions.setAccessToken(undefined)\n this.graphql.setAccessToken(undefined)\n }\n })\n\n // * Update access token for clients, including when signin in\n this.auth.onTokenChanged((session) => {\n this.storage.setAccessToken(session?.accessToken)\n this.functions.setAccessToken(session?.accessToken)\n this.graphql.setAccessToken(session?.accessToken)\n })\n })\n this._adminSecret = adminSecret\n this.devTools = devTools\n }\n\n get adminSecret(): string | undefined {\n return this._adminSecret\n }\n\n set adminSecret(newValue: string | undefined) {\n this._adminSecret = newValue\n this.storage.setAdminSecret(newValue)\n // TODO inconsistent API: storage can change admin secret, but functions/graphql cannot\n // this.functions.setAdminSecret(newValue)\n // this.graphql.setAdminSecret(newValue)\n }\n}\n","import { NhostClientConstructorParams } from './utils/types'\nimport { NhostClient } from './core'\n\nconst createClient = (config: NhostClientConstructorParams) => new NhostClient(config)\n\nexport * from './clients'\nexport * from './core'\nexport * from './utils/types'\nexport { createClient }\n"],"names":["axios","print","HasuraAuthClient","HasuraStorageClient"],"mappings":"m4BAiBO,MAAM,CAAqB,CAKhC,YAAY,EAAyC,CAC7C,KAAA,CAAE,MAAK,eAAgB,EAE7B,KAAK,YAAc,KACnB,KAAK,YAAc,EACd,KAAA,SAAWA,UAAM,OAAO,CAC3B,QAAS,CAAA,CACV,CACH,MAYM,MACJ,EACA,EACA,EACkC,CAClC,KAAM,GAAU,OACX,KAAK,2BAA2B,GAChC,iBAAQ,SAGT,GAAA,GACA,GAAA,CACI,EAAA,KAAM,MAAK,SAAS,KAA6B,EAAK,EAAM,OAAK,GAAL,CAAa,SAAA,EAAS,QACjF,GACP,GAAI,YAAiB,OACZ,MAAA,CAAE,IAAK,KAAM,QAExB,CAEA,MAAK,GAOE,CAAE,MAAK,MAAO,MANZ,CACL,IAAK,KACL,MAAO,GAAI,OAAM,wCAAwC,CAAA,CAK/D,CAYA,eAAe,EAAiC,CAC9C,GAAI,CAAC,EAAa,CAChB,KAAK,YAAc,KACnB,MACF,CAEA,KAAK,YAAc,CACrB,CAEQ,4BAAkD,CACxD,MAAI,MAAK,YACA,CACL,wBAAyB,KAAK,WAAA,EAG9B,KAAK,YACA,CACL,cAAe,UAAU,KAAK,aAAA,EAG3B,EACT,CACF,CCpFO,MAAM,CAAmB,CAM9B,YAAY,EAAuC,CAC3C,KAAA,CAAE,MAAK,eAAgB,EAE7B,KAAK,IAAM,EACX,KAAK,YAAc,KACnB,KAAK,YAAc,EACd,KAAA,SAAWA,UAAM,OAAO,CAC3B,QAAS,CAAA,CACV,CACH,MAoBM,SACJ,EACA,EACA,EACoC,CAEpC,KAAM,GAAU,OACX,KAAK,2BAA2B,GAChC,iBAAQ,SAGT,GAAA,CACF,KAAM,GAAgB,GAWhB,EAAe,AAVT,MAAM,MAAK,SAAS,KAC9B,GACA,CACE,cAAe,GAAiB,OAChC,MAAO,MAAO,IA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AAM"}
1
+ {"version":3,"file":"index.cjs.js","sources":["../src/clients/functions.ts","../src/clients/graphql.ts","../src/utils/helpers.ts","../src/core/nhost-client.ts","../src/index.ts"],"sourcesContent":["import axios, { AxiosInstance, AxiosRequestConfig, AxiosRequestHeaders, AxiosResponse } from 'axios'\n\nimport { FunctionCallResponse } from '../utils/types'\nexport interface NhostFunctionsConstructorParams {\n /**\n * Serverless Functions endpoint.\n */\n url: string\n /**\n * Admin secret. When set, it is sent as an `x-hasura-admin-secret` header for all requests.\n */\n adminSecret?: string\n}\n\n/**\n * @alias Functions\n */\nexport class NhostFunctionsClient {\n private instance: AxiosInstance\n private accessToken: string | null\n private adminSecret?: string\n\n constructor(params: NhostFunctionsConstructorParams) {\n const { url, adminSecret } = params\n\n this.accessToken = null\n this.adminSecret = adminSecret\n this.instance = axios.create({\n baseURL: url\n })\n }\n\n /**\n * Use `nhost.functions.call` to call (sending a POST request to) a serverless function.\n *\n * @example\n * ```ts\n * await nhost.functions.call('send-welcome-email', { email: 'joe@example.com', name: 'Joe Doe' })\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/functions/call\n */\n async call<T = unknown, D = any>(\n url: string,\n data: D,\n config?: AxiosRequestConfig\n ): Promise<FunctionCallResponse<T>> {\n const headers = {\n ...this.generateAccessTokenHeaders(),\n ...config?.headers\n }\n\n let res\n try {\n res = await this.instance.post<T, AxiosResponse<T>, D>(url, data, { ...config, headers })\n } catch (error) {\n if (error instanceof Error) {\n return { res: null, error }\n }\n }\n\n if (!res) {\n return {\n res: null,\n error: new Error('Unable to make post request to funtion')\n }\n }\n\n return { res, error: null }\n }\n\n /**\n * Use `nhost.functions.setAccessToken` to a set an access token to be used in subsequent functions requests. Note that if you're signin in users with `nhost.auth.signIn()` the access token will be set automatically.\n *\n * @example\n * ```ts\n * nhost.functions.setAccessToken('some-access-token')\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/functions/set-access-token\n */\n setAccessToken(accessToken: string | undefined) {\n if (!accessToken) {\n this.accessToken = null\n return\n }\n\n this.accessToken = accessToken\n }\n\n private generateAccessTokenHeaders(): AxiosRequestHeaders {\n if (this.adminSecret) {\n return {\n 'x-hasura-admin-secret': this.adminSecret\n }\n }\n if (this.accessToken) {\n return {\n Authorization: `Bearer ${this.accessToken}`\n }\n }\n return {}\n }\n}\n","import axios, { AxiosInstance, AxiosRequestConfig, AxiosRequestHeaders } from 'axios'\nimport { DocumentNode, print } from 'graphql'\n\nimport { GraphqlRequestResponse, GraphqlResponse } from '../utils/types'\n\nexport interface NhostGraphqlConstructorParams {\n /**\n * GraphQL endpoint.\n */\n url: string\n /**\n * Admin secret. When set, it is sent as an `x-hasura-admin-secret` header for all requests.\n */\n adminSecret?: string\n}\n\n/**\n * @alias GraphQL\n */\nexport class NhostGraphqlClient {\n private url: string\n private instance: AxiosInstance\n private accessToken: string | null\n private adminSecret?: string\n\n constructor(params: NhostGraphqlConstructorParams) {\n const { url, adminSecret } = params\n\n this.url = url\n this.accessToken = null\n this.adminSecret = adminSecret\n this.instance = axios.create({\n baseURL: url\n })\n }\n\n /**\n * Use `nhost.graphql.request` to send a GraphQL request. For more serious GraphQL usage we recommend using a GraphQL client such as Apollo Client (https://www.apollographql.com/docs/react).\n *\n * @example\n * ```ts\n * const CUSTOMERS = gql`\n * query {\n * customers {\n * id\n * name\n * }\n * }\n * `\n * const { data, error } = await nhost.graphql.request(CUSTOMERS)\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/graphql/request\n */\n async request<T = any, V = any>(\n document: string | DocumentNode,\n variables?: V,\n config?: AxiosRequestConfig\n ): Promise<GraphqlRequestResponse<T>> {\n // add auth headers if any\n const headers = {\n ...this.generateAccessTokenHeaders(),\n ...config?.headers\n }\n\n try {\n const operationName = ''\n const res = await this.instance.post<GraphqlResponse<T>>(\n '',\n {\n operationName: operationName || undefined,\n query: typeof document === 'string' ? document : print(document),\n variables\n },\n { ...config, headers }\n )\n\n const responseData = res.data\n const { data } = responseData\n\n if (responseData.errors) {\n return {\n data: null,\n error: responseData.errors\n }\n }\n\n if (typeof data !== 'object' || Array.isArray(data) || data === null) {\n return {\n data: null,\n error: new Error('incorrect response data from GraphQL server')\n }\n }\n\n return { data, error: null }\n } catch (error) {\n if (error instanceof Error) {\n return { data: null, error }\n }\n console.error(error)\n return {\n data: null,\n error: new Error('Unable to get do GraphQL request')\n }\n }\n }\n\n /**\n * Use `nhost.graphql.getUrl` to get the GraphQL URL.\n *\n * @example\n * ```ts\n * const url = nhost.graphql.getUrl();\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/graphql/get-url\n */\n getUrl(): string {\n return this.url\n }\n\n /**\n * Use `nhost.graphql.setAccessToken` to a set an access token to be used in subsequent graphql requests. Note that if you're signin in users with `nhost.auth.signIn()` the access token will be set automatically.\n *\n * @example\n * ```ts\n * nhost.graphql.setAccessToken('some-access-token')\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/graphql/set-access-token\n */\n setAccessToken(accessToken: string | undefined) {\n if (!accessToken) {\n this.accessToken = null\n return\n }\n\n this.accessToken = accessToken\n }\n\n private generateAccessTokenHeaders(): AxiosRequestHeaders {\n if (this.adminSecret) {\n return {\n 'x-hasura-admin-secret': this.adminSecret\n }\n }\n if (this.accessToken) {\n return {\n Authorization: `Bearer ${this.accessToken}`\n }\n }\n return {}\n }\n}\n","import { NhostClientConstructorParams } from './types'\n\nconst LOCALHOST_REGEX = /^localhost(:\\d+)*$/g\n\n/**\n * `backendUrl` should now be used only when self-hosting\n * `subdomain` and `region` should be used instead when using the Nhost platform\n * `\n * @param backendOrSubdomain\n * @param service\n * @returns\n */\nexport function urlFromParams(\n backendOrSubdomain: Pick<NhostClientConstructorParams, 'region' | 'subdomain' | 'backendUrl'>,\n service: string\n) {\n const { backendUrl, subdomain, region } = backendOrSubdomain\n\n if (!backendUrl && !subdomain) {\n throw new Error('Either `backendUrl` or `subdomain` must be set.')\n }\n\n if (backendUrl) {\n return `${backendUrl}/v1/${service}`\n }\n\n // to make TS happy\n if (!subdomain) {\n throw new Error('`subdomain` must be set if `backendUrl` is not set.')\n }\n\n // check if subdomain is localhost[:port]\n const subdomainLocalhostFound = subdomain.match(LOCALHOST_REGEX)\n if (subdomainLocalhostFound && subdomainLocalhostFound.length > 0) {\n const localhostFound = subdomainLocalhostFound[0]\n\n // no port specified, use standard port 1337\n if (localhostFound === 'localhost') {\n return `http://localhost:1337/v1/${service}`\n }\n\n // port specified\n return `http://${localhostFound}/v1/${service}`\n }\n\n if (!region) {\n throw new Error('`region` must be set when using a `subdomain` other than \"localhost\".')\n }\n\n return `https://${subdomain}.${service}.${region}.nhost.run/v1`\n}\n","import { HasuraAuthClient } from '@nhost/hasura-auth-js'\nimport { HasuraStorageClient } from '@nhost/hasura-storage-js'\n\nimport { NhostFunctionsClient } from '../clients/functions'\nimport { NhostGraphqlClient } from '../clients/graphql'\nimport { urlFromParams } from '../utils/helpers'\nimport { NhostClientConstructorParams } from '../utils/types'\nexport class NhostClient {\n auth: HasuraAuthClient\n storage: HasuraStorageClient\n functions: NhostFunctionsClient\n graphql: NhostGraphqlClient\n private _adminSecret?: string\n readonly devTools?: boolean\n\n /**\n * Nhost Client\n *\n * @example\n * ```ts\n * const nhost = new NhostClient({ subdomain, region });\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript\n */\n constructor({\n refreshIntervalTime,\n clientStorageGetter,\n clientStorageSetter,\n clientStorage,\n clientStorageType,\n autoRefreshToken,\n autoSignIn,\n adminSecret,\n devTools,\n start = true,\n ...urlParams\n }: NhostClientConstructorParams) {\n this.auth = new HasuraAuthClient({\n url: urlFromParams(urlParams, 'auth'),\n refreshIntervalTime,\n clientStorageGetter,\n clientStorageSetter,\n clientStorage,\n clientStorageType,\n autoRefreshToken,\n autoSignIn,\n start\n })\n\n this.storage = new HasuraStorageClient({\n url: urlFromParams(urlParams, 'storage'),\n adminSecret\n })\n\n this.functions = new NhostFunctionsClient({\n url: urlFromParams(urlParams, 'functions'),\n adminSecret\n })\n\n this.graphql = new NhostGraphqlClient({\n url: urlFromParams(urlParams, 'graphql'),\n adminSecret\n })\n\n // * Set current token if token is already accessable\n this.storage.setAccessToken(this.auth.getAccessToken())\n this.functions.setAccessToken(this.auth.getAccessToken())\n this.graphql.setAccessToken(this.auth.getAccessToken())\n\n this.auth.client?.onStart(() => {\n // * Set access token when signing out\n this.auth.onAuthStateChanged((_event, session) => {\n if (_event === 'SIGNED_OUT') {\n this.storage.setAccessToken(undefined)\n this.functions.setAccessToken(undefined)\n this.graphql.setAccessToken(undefined)\n }\n })\n\n // * Update access token for clients, including when signin in\n this.auth.onTokenChanged((session) => {\n this.storage.setAccessToken(session?.accessToken)\n this.functions.setAccessToken(session?.accessToken)\n this.graphql.setAccessToken(session?.accessToken)\n })\n })\n this._adminSecret = adminSecret\n this.devTools = devTools\n }\n\n get adminSecret(): string | undefined {\n return this._adminSecret\n }\n\n set adminSecret(newValue: string | undefined) {\n this._adminSecret = newValue\n this.storage.setAdminSecret(newValue)\n // TODO inconsistent API: storage can change admin secret, but functions/graphql cannot\n // this.functions.setAdminSecret(newValue)\n // this.graphql.setAdminSecret(newValue)\n }\n}\n","import { NhostClientConstructorParams } from './utils/types'\nimport { NhostClient } from './core'\n\nconst createClient = (config: NhostClientConstructorParams) => new NhostClient(config)\n\nexport * from './clients'\nexport * from './core'\nexport * from './utils/types'\nexport { createClient }\n"],"names":["NhostFunctionsClient","params","url","adminSecret","axios","data","config","headers","res","error","accessToken","NhostGraphqlClient","document","variables","operationName","responseData","print","LOCALHOST_REGEX","urlFromParams","backendOrSubdomain","service","backendUrl","subdomain","region","subdomainLocalhostFound","localhostFound","NhostClient","refreshIntervalTime","clientStorageGetter","clientStorageSetter","clientStorage","clientStorageType","autoRefreshToken","autoSignIn","devTools","start","urlParams","HasuraAuthClient","HasuraStorageClient","_a","_event","session","newValue","createClient"],"mappings":"oTAiBO,MAAMA,CAAqB,CAKhC,YAAYC,EAAyC,CAC7C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KAAA,QAAQ,eAAeA,GAAA,YAAAA,EAAS,WAAW,CAAA,CACjD,CAAA,GAEH,KAAK,aAAetC,EACpB,KAAK,SAAW+B,CAClB,CAEA,IAAI,aAAkC,CACpC,OAAO,KAAK,YACd,CAEA,IAAI,YAAYQ,EAA8B,CAC5C,KAAK,aAAeA,EACf,KAAA,QAAQ,eAAeA,CAAQ,CAItC,CACF,CCnGA,MAAMC,EAAgBrC,GAAyC,IAAIoB,EAAYpB,CAAM"}
package/dist/index.esm.js CHANGED
@@ -1,34 +1,3 @@
1
- var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __spreadValues = (a, b) => {
9
- for (var prop in b || (b = {}))
10
- if (__hasOwnProp.call(b, prop))
11
- __defNormalProp(a, prop, b[prop]);
12
- if (__getOwnPropSymbols)
13
- for (var prop of __getOwnPropSymbols(b)) {
14
- if (__propIsEnum.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- }
17
- return a;
18
- };
19
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
- var __objRest = (source, exclude) => {
21
- var target = {};
22
- for (var prop in source)
23
- if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
24
- target[prop] = source[prop];
25
- if (source != null && __getOwnPropSymbols)
26
- for (var prop of __getOwnPropSymbols(source)) {
27
- if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
28
- target[prop] = source[prop];
29
- }
30
- return target;
31
- };
32
1
  import { HasuraAuthClient } from "@nhost/hasura-auth-js";
33
2
  import { HasuraStorageClient } from "@nhost/hasura-storage-js";
34
3
  import axios from "axios";
@@ -43,10 +12,13 @@ class NhostFunctionsClient {
43
12
  });
44
13
  }
45
14
  async call(url, data, config) {
46
- const headers = __spreadValues(__spreadValues({}, this.generateAccessTokenHeaders()), config == null ? void 0 : config.headers);
15
+ const headers = {
16
+ ...this.generateAccessTokenHeaders(),
17
+ ...config == null ? void 0 : config.headers
18
+ };
47
19
  let res;
48
20
  try {
49
- res = await this.instance.post(url, data, __spreadProps(__spreadValues({}, config), { headers }));
21
+ res = await this.instance.post(url, data, { ...config, headers });
50
22
  } catch (error) {
51
23
  if (error instanceof Error) {
52
24
  return { res: null, error };
@@ -92,14 +64,21 @@ class NhostGraphqlClient {
92
64
  });
93
65
  }
94
66
  async request(document, variables, config) {
95
- const headers = __spreadValues(__spreadValues({}, this.generateAccessTokenHeaders()), config == null ? void 0 : config.headers);
67
+ const headers = {
68
+ ...this.generateAccessTokenHeaders(),
69
+ ...config == null ? void 0 : config.headers
70
+ };
96
71
  try {
97
72
  const operationName = "";
98
- const res = await this.instance.post("", {
99
- operationName: operationName || void 0,
100
- query: typeof document === "string" ? document : print(document),
101
- variables
102
- }, __spreadProps(__spreadValues({}, config), { headers }));
73
+ const res = await this.instance.post(
74
+ "",
75
+ {
76
+ operationName: operationName || void 0,
77
+ query: typeof document === "string" ? document : print(document),
78
+ variables
79
+ },
80
+ { ...config, headers }
81
+ );
103
82
  const responseData = res.data;
104
83
  const { data } = responseData;
105
84
  if (responseData.errors) {
@@ -176,31 +155,20 @@ function urlFromParams(backendOrSubdomain, service) {
176
155
  return `https://${subdomain}.${service}.${region}.nhost.run/v1`;
177
156
  }
178
157
  class NhostClient {
179
- constructor(_a) {
180
- var _b = _a, {
181
- refreshIntervalTime,
182
- clientStorageGetter,
183
- clientStorageSetter,
184
- clientStorage,
185
- clientStorageType,
186
- autoRefreshToken,
187
- autoSignIn,
188
- adminSecret,
189
- devTools,
190
- start = true
191
- } = _b, urlParams = __objRest(_b, [
192
- "refreshIntervalTime",
193
- "clientStorageGetter",
194
- "clientStorageSetter",
195
- "clientStorage",
196
- "clientStorageType",
197
- "autoRefreshToken",
198
- "autoSignIn",
199
- "adminSecret",
200
- "devTools",
201
- "start"
202
- ]);
203
- var _a2;
158
+ constructor({
159
+ refreshIntervalTime,
160
+ clientStorageGetter,
161
+ clientStorageSetter,
162
+ clientStorage,
163
+ clientStorageType,
164
+ autoRefreshToken,
165
+ autoSignIn,
166
+ adminSecret,
167
+ devTools,
168
+ start = true,
169
+ ...urlParams
170
+ }) {
171
+ var _a;
204
172
  this.auth = new HasuraAuthClient({
205
173
  url: urlFromParams(urlParams, "auth"),
206
174
  refreshIntervalTime,
@@ -227,7 +195,7 @@ class NhostClient {
227
195
  this.storage.setAccessToken(this.auth.getAccessToken());
228
196
  this.functions.setAccessToken(this.auth.getAccessToken());
229
197
  this.graphql.setAccessToken(this.auth.getAccessToken());
230
- (_a2 = this.auth.client) == null ? void 0 : _a2.onStart(() => {
198
+ (_a = this.auth.client) == null ? void 0 : _a.onStart(() => {
231
199
  this.auth.onAuthStateChanged((_event, session) => {
232
200
  if (_event === "SIGNED_OUT") {
233
201
  this.storage.setAccessToken(void 0);
@@ -1 +1 @@
1
- {"version":3,"file":"index.esm.js","sources":["../src/clients/functions.ts","../src/clients/graphql.ts","../src/utils/helpers.ts","../src/core/nhost-client.ts","../src/index.ts"],"sourcesContent":["import axios, { AxiosInstance, AxiosRequestConfig, AxiosRequestHeaders, AxiosResponse } from 'axios'\n\nimport { FunctionCallResponse } from '../utils/types'\nexport interface NhostFunctionsConstructorParams {\n /**\n * Serverless Functions endpoint.\n */\n url: string\n /**\n * Admin secret. When set, it is sent as an `x-hasura-admin-secret` header for all requests.\n */\n adminSecret?: string\n}\n\n/**\n * @alias Functions\n */\nexport class NhostFunctionsClient {\n private instance: AxiosInstance\n private accessToken: string | null\n private adminSecret?: string\n\n constructor(params: NhostFunctionsConstructorParams) {\n const { url, adminSecret } = params\n\n this.accessToken = null\n this.adminSecret = adminSecret\n this.instance = axios.create({\n baseURL: url\n })\n }\n\n /**\n * Use `nhost.functions.call` to call (sending a POST request to) a serverless function.\n *\n * @example\n * ```ts\n * await nhost.functions.call('send-welcome-email', { email: 'joe@example.com', name: 'Joe Doe' })\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/functions/call\n */\n async call<T = unknown, D = any>(\n url: string,\n data: D,\n config?: AxiosRequestConfig\n ): Promise<FunctionCallResponse<T>> {\n const headers = {\n ...this.generateAccessTokenHeaders(),\n ...config?.headers\n }\n\n let res\n try {\n res = await this.instance.post<T, AxiosResponse<T>, D>(url, data, { ...config, headers })\n } catch (error) {\n if (error instanceof Error) {\n return { res: null, error }\n }\n }\n\n if (!res) {\n return {\n res: null,\n error: new Error('Unable to make post request to funtion')\n }\n }\n\n return { res, error: null }\n }\n\n /**\n * Use `nhost.functions.setAccessToken` to a set an access token to be used in subsequent functions requests. Note that if you're signin in users with `nhost.auth.signIn()` the access token will be set automatically.\n *\n * @example\n * ```ts\n * nhost.functions.setAccessToken('some-access-token')\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/functions/set-access-token\n */\n setAccessToken(accessToken: string | undefined) {\n if (!accessToken) {\n this.accessToken = null\n return\n }\n\n this.accessToken = accessToken\n }\n\n private generateAccessTokenHeaders(): AxiosRequestHeaders {\n if (this.adminSecret) {\n return {\n 'x-hasura-admin-secret': this.adminSecret\n }\n }\n if (this.accessToken) {\n return {\n Authorization: `Bearer ${this.accessToken}`\n }\n }\n return {}\n }\n}\n","import axios, { AxiosInstance, AxiosRequestConfig, AxiosRequestHeaders } from 'axios'\nimport { DocumentNode, print } from 'graphql'\n\nimport { GraphqlRequestResponse, GraphqlResponse } from '../utils/types'\n\nexport interface NhostGraphqlConstructorParams {\n /**\n * GraphQL endpoint.\n */\n url: string\n /**\n * Admin secret. When set, it is sent as an `x-hasura-admin-secret` header for all requests.\n */\n adminSecret?: string\n}\n\n/**\n * @alias GraphQL\n */\nexport class NhostGraphqlClient {\n private url: string\n private instance: AxiosInstance\n private accessToken: string | null\n private adminSecret?: string\n\n constructor(params: NhostGraphqlConstructorParams) {\n const { url, adminSecret } = params\n\n this.url = url\n this.accessToken = null\n this.adminSecret = adminSecret\n this.instance = axios.create({\n baseURL: url\n })\n }\n\n /**\n * Use `nhost.graphql.request` to send a GraphQL request. For more serious GraphQL usage we recommend using a GraphQL client such as Apollo Client (https://www.apollographql.com/docs/react).\n *\n * @example\n * ```ts\n * const CUSTOMERS = gql`\n * query {\n * customers {\n * id\n * name\n * }\n * }\n * `\n * const { data, error } = await nhost.graphql.request(CUSTOMERS)\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/graphql/request\n */\n async request<T = any, V = any>(\n document: string | DocumentNode,\n variables?: V,\n config?: AxiosRequestConfig\n ): Promise<GraphqlRequestResponse<T>> {\n // add auth headers if any\n const headers = {\n ...this.generateAccessTokenHeaders(),\n ...config?.headers\n }\n\n try {\n const operationName = ''\n const res = await this.instance.post<GraphqlResponse<T>>(\n '',\n {\n operationName: operationName || undefined,\n query: typeof document === 'string' ? document : print(document),\n variables\n },\n { ...config, headers }\n )\n\n const responseData = res.data\n const { data } = responseData\n\n if (responseData.errors) {\n return {\n data: null,\n error: responseData.errors\n }\n }\n\n if (typeof data !== 'object' || Array.isArray(data) || data === null) {\n return {\n data: null,\n error: new Error('incorrect response data from GraphQL server')\n }\n }\n\n return { data, error: null }\n } catch (error) {\n if (error instanceof Error) {\n return { data: null, error }\n }\n console.error(error)\n return {\n data: null,\n error: new Error('Unable to get do GraphQL request')\n }\n }\n }\n\n /**\n * Use `nhost.graphql.getUrl` to get the GraphQL URL.\n *\n * @example\n * ```ts\n * const url = nhost.graphql.getUrl();\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/graphql/get-url\n */\n getUrl(): string {\n return this.url\n }\n\n /**\n * Use `nhost.graphql.setAccessToken` to a set an access token to be used in subsequent graphql requests. Note that if you're signin in users with `nhost.auth.signIn()` the access token will be set automatically.\n *\n * @example\n * ```ts\n * nhost.graphql.setAccessToken('some-access-token')\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/graphql/set-access-token\n */\n setAccessToken(accessToken: string | undefined) {\n if (!accessToken) {\n this.accessToken = null\n return\n }\n\n this.accessToken = accessToken\n }\n\n private generateAccessTokenHeaders(): AxiosRequestHeaders {\n if (this.adminSecret) {\n return {\n 'x-hasura-admin-secret': this.adminSecret\n }\n }\n if (this.accessToken) {\n return {\n Authorization: `Bearer ${this.accessToken}`\n }\n }\n return {}\n }\n}\n","import { NhostClientConstructorParams } from './types'\n\nconst LOCALHOST_REGEX = /^localhost(:\\d+)*$/g\n\n/**\n * `backendUrl` should now be used only when self-hosting\n * `subdomain` and `region` should be used instead when using the Nhost platform\n * `\n * @param backendOrSubdomain\n * @param service\n * @returns\n */\nexport function urlFromParams(\n backendOrSubdomain: Pick<NhostClientConstructorParams, 'region' | 'subdomain' | 'backendUrl'>,\n service: string\n) {\n const { backendUrl, subdomain, region } = backendOrSubdomain\n\n if (!backendUrl && !subdomain) {\n throw new Error('Either `backendUrl` or `subdomain` must be set.')\n }\n\n if (backendUrl) {\n return `${backendUrl}/v1/${service}`\n }\n\n // to make TS happy\n if (!subdomain) {\n throw new Error('`subdomain` must be set if `backendUrl` is not set.')\n }\n\n // check if subdomain is localhost[:port]\n const subdomainLocalhostFound = subdomain.match(LOCALHOST_REGEX)\n if (subdomainLocalhostFound && subdomainLocalhostFound.length > 0) {\n const localhostFound = subdomainLocalhostFound[0]\n\n // no port specified, use standard port 1337\n if (localhostFound === 'localhost') {\n return `http://localhost:1337/v1/${service}`\n }\n\n // port specified\n return `http://${localhostFound}/v1/${service}`\n }\n\n if (!region) {\n throw new Error('`region` must be set when using a `subdomain` other than \"localhost\".')\n }\n\n return `https://${subdomain}.${service}.${region}.nhost.run/v1`\n}\n","import { HasuraAuthClient } from '@nhost/hasura-auth-js'\nimport { HasuraStorageClient } from '@nhost/hasura-storage-js'\n\nimport { NhostFunctionsClient } from '../clients/functions'\nimport { NhostGraphqlClient } from '../clients/graphql'\nimport { urlFromParams } from '../utils/helpers'\nimport { NhostClientConstructorParams } from '../utils/types'\nexport class NhostClient {\n auth: HasuraAuthClient\n storage: HasuraStorageClient\n functions: NhostFunctionsClient\n graphql: NhostGraphqlClient\n private _adminSecret?: string\n readonly devTools?: boolean\n\n /**\n * Nhost Client\n *\n * @example\n * ```ts\n * const nhost = new NhostClient({ subdomain, region });\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript\n */\n constructor({\n refreshIntervalTime,\n clientStorageGetter,\n clientStorageSetter,\n clientStorage,\n clientStorageType,\n autoRefreshToken,\n autoSignIn,\n adminSecret,\n devTools,\n start = true,\n ...urlParams\n }: NhostClientConstructorParams) {\n this.auth = new HasuraAuthClient({\n url: urlFromParams(urlParams, 'auth'),\n refreshIntervalTime,\n clientStorageGetter,\n clientStorageSetter,\n clientStorage,\n clientStorageType,\n autoRefreshToken,\n autoSignIn,\n start\n })\n\n this.storage = new HasuraStorageClient({\n url: urlFromParams(urlParams, 'storage'),\n adminSecret\n })\n\n this.functions = new NhostFunctionsClient({\n url: urlFromParams(urlParams, 'functions'),\n adminSecret\n })\n\n this.graphql = new NhostGraphqlClient({\n url: urlFromParams(urlParams, 'graphql'),\n adminSecret\n })\n\n // * Set current token if token is already accessable\n this.storage.setAccessToken(this.auth.getAccessToken())\n this.functions.setAccessToken(this.auth.getAccessToken())\n this.graphql.setAccessToken(this.auth.getAccessToken())\n\n this.auth.client?.onStart(() => {\n // * Set access token when signing out\n this.auth.onAuthStateChanged((_event, session) => {\n if (_event === 'SIGNED_OUT') {\n this.storage.setAccessToken(undefined)\n this.functions.setAccessToken(undefined)\n this.graphql.setAccessToken(undefined)\n }\n })\n\n // * Update access token for clients, including when signin in\n this.auth.onTokenChanged((session) => {\n this.storage.setAccessToken(session?.accessToken)\n this.functions.setAccessToken(session?.accessToken)\n this.graphql.setAccessToken(session?.accessToken)\n })\n })\n this._adminSecret = adminSecret\n this.devTools = devTools\n }\n\n get adminSecret(): string | undefined {\n return this._adminSecret\n }\n\n set adminSecret(newValue: string | undefined) {\n this._adminSecret = newValue\n this.storage.setAdminSecret(newValue)\n // TODO inconsistent API: storage can change admin secret, but functions/graphql cannot\n // this.functions.setAdminSecret(newValue)\n // this.graphql.setAdminSecret(newValue)\n }\n}\n","import { NhostClientConstructorParams } from './utils/types'\nimport { NhostClient } from './core'\n\nconst createClient = (config: NhostClientConstructorParams) => new NhostClient(config)\n\nexport * from './clients'\nexport * from './core'\nexport * from './utils/types'\nexport { createClient }\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiBO,MAAM,qBAAqB;AAAA,EAKhC,YAAY,QAAyC;AAC7C,UAAA,EAAE,KAAK,gBAAgB;AAE7B,SAAK,cAAc;AACnB,SAAK,cAAc;AACd,SAAA,WAAW,MAAM,OAAO;AAAA,MAC3B,SAAS;AAAA,IAAA,CACV;AAAA,EACH;AAAA,QAYM,KACJ,KACA,MACA,QACkC;AAClC,UAAM,UAAU,kCACX,KAAK,2BAA2B,IAChC,iCAAQ;AAGT,QAAA;AACA,QAAA;AACI,YAAA,MAAM,KAAK,SAAS,KAA6B,KAAK,MAAM,iCAAK,SAAL,EAAa,QAAA,EAAS;AAAA,aACjF;AACP,UAAI,iBAAiB,OAAO;AACnB,eAAA,EAAE,KAAK,MAAM;MACtB;AAAA,IACF;AAEA,QAAI,CAAC,KAAK;AACD,aAAA;AAAA,QACL,KAAK;AAAA,QACL,OAAO,IAAI,MAAM,wCAAwC;AAAA,MAAA;AAAA,IAE7D;AAEO,WAAA,EAAE,KAAK,OAAO;EACvB;AAAA,EAYA,eAAe,aAAiC;AAC9C,QAAI,CAAC,aAAa;AAChB,WAAK,cAAc;AACnB;AAAA,IACF;AAEA,SAAK,cAAc;AAAA,EACrB;AAAA,EAEQ,6BAAkD;AACxD,QAAI,KAAK,aAAa;AACb,aAAA;AAAA,QACL,yBAAyB,KAAK;A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nGA,MAAM,eAAe,CAAC,WAAyC,IAAI,YAAY,MAAM;;"}
1
+ {"version":3,"file":"index.esm.js","sources":["../src/clients/functions.ts","../src/clients/graphql.ts","../src/utils/helpers.ts","../src/core/nhost-client.ts","../src/index.ts"],"sourcesContent":["import axios, { AxiosInstance, AxiosRequestConfig, AxiosRequestHeaders, AxiosResponse } from 'axios'\n\nimport { FunctionCallResponse } from '../utils/types'\nexport interface NhostFunctionsConstructorParams {\n /**\n * Serverless Functions endpoint.\n */\n url: string\n /**\n * Admin secret. When set, it is sent as an `x-hasura-admin-secret` header for all requests.\n */\n adminSecret?: string\n}\n\n/**\n * @alias Functions\n */\nexport class NhostFunctionsClient {\n private instance: AxiosInstance\n private accessToken: string | null\n private adminSecret?: string\n\n constructor(params: NhostFunctionsConstructorParams) {\n const { url, adminSecret } = params\n\n this.accessToken = null\n this.adminSecret = adminSecret\n this.instance = axios.create({\n baseURL: url\n })\n }\n\n /**\n * Use `nhost.functions.call` to call (sending a POST request to) a serverless function.\n *\n * @example\n * ```ts\n * await nhost.functions.call('send-welcome-email', { email: 'joe@example.com', name: 'Joe Doe' })\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/functions/call\n */\n async call<T = unknown, D = any>(\n url: string,\n data: D,\n config?: AxiosRequestConfig\n ): Promise<FunctionCallResponse<T>> {\n const headers = {\n ...this.generateAccessTokenHeaders(),\n ...config?.headers\n }\n\n let res\n try {\n res = await this.instance.post<T, AxiosResponse<T>, D>(url, data, { ...config, headers })\n } catch (error) {\n if (error instanceof Error) {\n return { res: null, error }\n }\n }\n\n if (!res) {\n return {\n res: null,\n error: new Error('Unable to make post request to funtion')\n }\n }\n\n return { res, error: null }\n }\n\n /**\n * Use `nhost.functions.setAccessToken` to a set an access token to be used in subsequent functions requests. Note that if you're signin in users with `nhost.auth.signIn()` the access token will be set automatically.\n *\n * @example\n * ```ts\n * nhost.functions.setAccessToken('some-access-token')\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/functions/set-access-token\n */\n setAccessToken(accessToken: string | undefined) {\n if (!accessToken) {\n this.accessToken = null\n return\n }\n\n this.accessToken = accessToken\n }\n\n private generateAccessTokenHeaders(): AxiosRequestHeaders {\n if (this.adminSecret) {\n return {\n 'x-hasura-admin-secret': this.adminSecret\n }\n }\n if (this.accessToken) {\n return {\n Authorization: `Bearer ${this.accessToken}`\n }\n }\n return {}\n }\n}\n","import axios, { AxiosInstance, AxiosRequestConfig, AxiosRequestHeaders } from 'axios'\nimport { DocumentNode, print } from 'graphql'\n\nimport { GraphqlRequestResponse, GraphqlResponse } from '../utils/types'\n\nexport interface NhostGraphqlConstructorParams {\n /**\n * GraphQL endpoint.\n */\n url: string\n /**\n * Admin secret. When set, it is sent as an `x-hasura-admin-secret` header for all requests.\n */\n adminSecret?: string\n}\n\n/**\n * @alias GraphQL\n */\nexport class NhostGraphqlClient {\n private url: string\n private instance: AxiosInstance\n private accessToken: string | null\n private adminSecret?: string\n\n constructor(params: NhostGraphqlConstructorParams) {\n const { url, adminSecret } = params\n\n this.url = url\n this.accessToken = null\n this.adminSecret = adminSecret\n this.instance = axios.create({\n baseURL: url\n })\n }\n\n /**\n * Use `nhost.graphql.request` to send a GraphQL request. For more serious GraphQL usage we recommend using a GraphQL client such as Apollo Client (https://www.apollographql.com/docs/react).\n *\n * @example\n * ```ts\n * const CUSTOMERS = gql`\n * query {\n * customers {\n * id\n * name\n * }\n * }\n * `\n * const { data, error } = await nhost.graphql.request(CUSTOMERS)\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/graphql/request\n */\n async request<T = any, V = any>(\n document: string | DocumentNode,\n variables?: V,\n config?: AxiosRequestConfig\n ): Promise<GraphqlRequestResponse<T>> {\n // add auth headers if any\n const headers = {\n ...this.generateAccessTokenHeaders(),\n ...config?.headers\n }\n\n try {\n const operationName = ''\n const res = await this.instance.post<GraphqlResponse<T>>(\n '',\n {\n operationName: operationName || undefined,\n query: typeof document === 'string' ? document : print(document),\n variables\n },\n { ...config, headers }\n )\n\n const responseData = res.data\n const { data } = responseData\n\n if (responseData.errors) {\n return {\n data: null,\n error: responseData.errors\n }\n }\n\n if (typeof data !== 'object' || Array.isArray(data) || data === null) {\n return {\n data: null,\n error: new Error('incorrect response data from GraphQL server')\n }\n }\n\n return { data, error: null }\n } catch (error) {\n if (error instanceof Error) {\n return { data: null, error }\n }\n console.error(error)\n return {\n data: null,\n error: new Error('Unable to get do GraphQL request')\n }\n }\n }\n\n /**\n * Use `nhost.graphql.getUrl` to get the GraphQL URL.\n *\n * @example\n * ```ts\n * const url = nhost.graphql.getUrl();\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/graphql/get-url\n */\n getUrl(): string {\n return this.url\n }\n\n /**\n * Use `nhost.graphql.setAccessToken` to a set an access token to be used in subsequent graphql requests. Note that if you're signin in users with `nhost.auth.signIn()` the access token will be set automatically.\n *\n * @example\n * ```ts\n * nhost.graphql.setAccessToken('some-access-token')\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/graphql/set-access-token\n */\n setAccessToken(accessToken: string | undefined) {\n if (!accessToken) {\n this.accessToken = null\n return\n }\n\n this.accessToken = accessToken\n }\n\n private generateAccessTokenHeaders(): AxiosRequestHeaders {\n if (this.adminSecret) {\n return {\n 'x-hasura-admin-secret': this.adminSecret\n }\n }\n if (this.accessToken) {\n return {\n Authorization: `Bearer ${this.accessToken}`\n }\n }\n return {}\n }\n}\n","import { NhostClientConstructorParams } from './types'\n\nconst LOCALHOST_REGEX = /^localhost(:\\d+)*$/g\n\n/**\n * `backendUrl` should now be used only when self-hosting\n * `subdomain` and `region` should be used instead when using the Nhost platform\n * `\n * @param backendOrSubdomain\n * @param service\n * @returns\n */\nexport function urlFromParams(\n backendOrSubdomain: Pick<NhostClientConstructorParams, 'region' | 'subdomain' | 'backendUrl'>,\n service: string\n) {\n const { backendUrl, subdomain, region } = backendOrSubdomain\n\n if (!backendUrl && !subdomain) {\n throw new Error('Either `backendUrl` or `subdomain` must be set.')\n }\n\n if (backendUrl) {\n return `${backendUrl}/v1/${service}`\n }\n\n // to make TS happy\n if (!subdomain) {\n throw new Error('`subdomain` must be set if `backendUrl` is not set.')\n }\n\n // check if subdomain is localhost[:port]\n const subdomainLocalhostFound = subdomain.match(LOCALHOST_REGEX)\n if (subdomainLocalhostFound && subdomainLocalhostFound.length > 0) {\n const localhostFound = subdomainLocalhostFound[0]\n\n // no port specified, use standard port 1337\n if (localhostFound === 'localhost') {\n return `http://localhost:1337/v1/${service}`\n }\n\n // port specified\n return `http://${localhostFound}/v1/${service}`\n }\n\n if (!region) {\n throw new Error('`region` must be set when using a `subdomain` other than \"localhost\".')\n }\n\n return `https://${subdomain}.${service}.${region}.nhost.run/v1`\n}\n","import { HasuraAuthClient } from '@nhost/hasura-auth-js'\nimport { HasuraStorageClient } from '@nhost/hasura-storage-js'\n\nimport { NhostFunctionsClient } from '../clients/functions'\nimport { NhostGraphqlClient } from '../clients/graphql'\nimport { urlFromParams } from '../utils/helpers'\nimport { NhostClientConstructorParams } from '../utils/types'\nexport class NhostClient {\n auth: HasuraAuthClient\n storage: HasuraStorageClient\n functions: NhostFunctionsClient\n graphql: NhostGraphqlClient\n private _adminSecret?: string\n readonly devTools?: boolean\n\n /**\n * Nhost Client\n *\n * @example\n * ```ts\n * const nhost = new NhostClient({ subdomain, region });\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript\n */\n constructor({\n refreshIntervalTime,\n clientStorageGetter,\n clientStorageSetter,\n clientStorage,\n clientStorageType,\n autoRefreshToken,\n autoSignIn,\n adminSecret,\n devTools,\n start = true,\n ...urlParams\n }: NhostClientConstructorParams) {\n this.auth = new HasuraAuthClient({\n url: urlFromParams(urlParams, 'auth'),\n refreshIntervalTime,\n clientStorageGetter,\n clientStorageSetter,\n clientStorage,\n clientStorageType,\n autoRefreshToken,\n autoSignIn,\n start\n })\n\n this.storage = new HasuraStorageClient({\n url: urlFromParams(urlParams, 'storage'),\n adminSecret\n })\n\n this.functions = new NhostFunctionsClient({\n url: urlFromParams(urlParams, 'functions'),\n adminSecret\n })\n\n this.graphql = new NhostGraphqlClient({\n url: urlFromParams(urlParams, 'graphql'),\n adminSecret\n })\n\n // * Set current token if token is already accessable\n this.storage.setAccessToken(this.auth.getAccessToken())\n this.functions.setAccessToken(this.auth.getAccessToken())\n this.graphql.setAccessToken(this.auth.getAccessToken())\n\n this.auth.client?.onStart(() => {\n // * Set access token when signing out\n this.auth.onAuthStateChanged((_event, session) => {\n if (_event === 'SIGNED_OUT') {\n this.storage.setAccessToken(undefined)\n this.functions.setAccessToken(undefined)\n this.graphql.setAccessToken(undefined)\n }\n })\n\n // * Update access token for clients, including when signin in\n this.auth.onTokenChanged((session) => {\n this.storage.setAccessToken(session?.accessToken)\n this.functions.setAccessToken(session?.accessToken)\n this.graphql.setAccessToken(session?.accessToken)\n })\n })\n this._adminSecret = adminSecret\n this.devTools = devTools\n }\n\n get adminSecret(): string | undefined {\n return this._adminSecret\n }\n\n set adminSecret(newValue: string | undefined) {\n this._adminSecret = newValue\n this.storage.setAdminSecret(newValue)\n // TODO inconsistent API: storage can change admin secret, but functions/graphql cannot\n // this.functions.setAdminSecret(newValue)\n // this.graphql.setAdminSecret(newValue)\n }\n}\n","import { NhostClientConstructorParams } from './utils/types'\nimport { NhostClient } from './core'\n\nconst createClient = (config: NhostClientConstructorParams) => new NhostClient(config)\n\nexport * from './clients'\nexport * from './core'\nexport * from './utils/types'\nexport { createClient }\n"],"names":[],"mappings":";;;;AAiBO,MAAM,qBAAqB;AAAA,EAKhC,YAAY,QAAyC;AAC7C,UAAA,EAAE,KAAK,YAAgB,IAAA;AAE7B,SAAK,cAAc;AACnB,SAAK,cAAc;AACd,SAAA,WAAW,MAAM,OAAO;AAAA,MAC3B,SAAS;AAAA,IAAA,CACV;AAAA,EACH;AAAA,EAYA,MAAM,KACJ,KACA,MACA,QACkC;AAClC,UAAM,UAAU;AAAA,MACd,GAAG,KAAK,2BAA2B;A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YAAY;AAChD,YAAI,WAAW,cAAc;AACtB,eAAA,QAAQ,eAAe,MAAS;AAChC,eAAA,UAAU,eAAe,MAAS;AAClC,eAAA,QAAQ,eAAe,MAAS;AAAA,QACvC;AAAA,MAAA,CACD;AAGI,WAAA,KAAK,eAAe,CAAC,YAAY;AAC/B,aAAA,QAAQ,eAAe,mCAAS,WAAW;AAC3C,aAAA,UAAU,eAAe,mCAAS,WAAW;AAC7C,aAAA,QAAQ,eAAe,mCAAS,WAAW;AAAA,MAAA,CACjD;AAAA,IAAA;AAEH,SAAK,eAAe;AACpB,SAAK,WAAW;AAAA,EAClB;AAAA,EAEA,IAAI,cAAkC;AACpC,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,IAAI,YAAY,UAA8B;AAC5C,SAAK,eAAe;AACf,SAAA,QAAQ,eAAe,QAAQ;AAAA,EAItC;AACF;ACnGA,MAAM,eAAe,CAAC,WAAyC,IAAI,YAAY,MAAM;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nhost/nhost-js",
3
- "version": "1.5.0",
3
+ "version": "1.5.2",
4
4
  "description": "Nhost JavaScript SDK",
5
5
  "license": "MIT",
6
6
  "keywords": [
@@ -43,15 +43,15 @@
43
43
  "access": "public"
44
44
  },
45
45
  "dependencies": {
46
- "@nhost/hasura-auth-js": "1.5.0",
47
- "@nhost/hasura-storage-js": "0.6.2",
46
+ "@nhost/hasura-auth-js": "1.6.1",
47
+ "@nhost/hasura-storage-js": "0.7.1",
48
48
  "axios": "^0.27.2",
49
49
  "jwt-decode": "^3.1.2",
50
50
  "query-string": "^7.0.1"
51
51
  },
52
52
  "devDependencies": {
53
- "@nhost/docgen": "0.1.2",
54
- "graphql": "16",
53
+ "@nhost/docgen": "0.1.3",
54
+ "graphql": "15.7.2",
55
55
  "start-server-and-test": "^1.14.0"
56
56
  },
57
57
  "peerDependencies": {
@@ -75,6 +75,5 @@
75
75
  "verify:fix": "run-p prettier:fix lint:fix",
76
76
  "typedoc": "typedoc --options ./nhost-js.typedoc.json --tsconfig ./typedoc.tsconfig.json",
77
77
  "docgen": "pnpm typedoc && docgen --config ./nhost-js.docgen.json"
78
- },
79
- "readme": "<h1 align=\"center\">@nhost/nhost-js</h1>\n<h2 align=\"center\">Nhost JavaScript SDK</h2>\n\n<p align=\"center\">\n <img alt=\"npm\" src=\"https://img.shields.io/npm/v/@nhost/nhost-js\">\n <img alt=\"npm\" src=\"https://img.shields.io/npm/dm/@nhost/nhost-js\">\n <a href=\"LICENSE\">\n <img src=\"https://img.shields.io/badge/license-MIT-yellow.svg\" alt=\"license: MIT\" />\n </a>\n</p>\n\n## Documentation\n\n[Reference documentation](https://docs.nhost.io/reference/javascript)\n\n## Install\n\n```\nnpm install @nhost/nhost-js\n\n# or yarn\nyarn add @nhost/nhost-js\n```\n\n### Initialise\n\n```js\nimport { NhostClient } from '@nhost/nhost-js'\n\nconst nhost = new NhostClient({\n subdomain: '<Your Nhost project subdomain>',\n region: '<Your Nhost project region>'\n})\n```\n\n## Features\n\n### GraphQL\n\nAccess Nhost GraphQL methods using `nhost.graphql`.\n\n### Authentication\n\nAccess Nhost Auth methods using `nhost.auth`.\n\n### Storage\n\nAccess Nhost Storage methods using `nhost.storage`.\n\n### Functions\n\nAccess Nhost Functions methods via `nhost.functions`.\n"
78
+ }
80
79
  }