@nhost/nhost-js 1.4.0 → 1.4.1
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/README.md +1 -1
- package/dist/clients/functions.d.ts +1 -1
- package/dist/clients/functions.d.ts.map +1 -1
- package/dist/clients/graphql.d.ts +1 -1
- package/dist/clients/graphql.d.ts.map +1 -1
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/nhost-client.d.ts +6 -14
- package/dist/core/nhost-client.d.ts.map +1 -1
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +55 -21
- package/dist/index.esm.js.map +1 -1
- package/dist/utils/helpers.d.ts +11 -0
- package/dist/utils/helpers.d.ts.map +1 -0
- package/dist/utils/types.d.ts +55 -0
- package/dist/utils/types.d.ts.map +1 -0
- package/package.json +2 -2
- package/umd/nhost-js.umd.js +6 -6
- package/umd/nhost-js.umd.js.map +1 -1
- package/dist/types.d.ts +0 -20
- package/dist/types.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"functions.d.ts","sourceRoot":"","sources":["functions.ts"],"names":[],"mappings":"AAAA,OAAc,EAAiB,kBAAkB,EAAsC,MAAM,OAAO,CAAA;AAEpG,OAAO,EAAE,oBAAoB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"functions.d.ts","sourceRoot":"","sources":["functions.ts"],"names":[],"mappings":"AAAA,OAAc,EAAiB,kBAAkB,EAAsC,MAAM,OAAO,CAAA;AAEpG,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAA;AACrD,MAAM,WAAW,+BAA+B;IAC9C;;OAEG;IACH,GAAG,EAAE,MAAM,CAAA;IACX;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AAED;;GAEG;AACH,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,QAAQ,CAAe;IAC/B,OAAO,CAAC,WAAW,CAAe;IAClC,OAAO,CAAC,WAAW,CAAC,CAAQ;gBAEhB,MAAM,EAAE,+BAA+B;IAUnD;;;;;;;;;OASG;IACG,IAAI,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC,GAAG,GAAG,EAC7B,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,CAAC,EACP,MAAM,CAAC,EAAE,kBAAkB,GAC1B,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC;IAyBnC;;;;;;;;;OASG;IACH,cAAc,CAAC,WAAW,EAAE,MAAM,GAAG,SAAS;IAS9C,OAAO,CAAC,0BAA0B;CAanC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AxiosRequestConfig } from 'axios';
|
|
2
2
|
import { DocumentNode } from 'graphql';
|
|
3
|
-
import { GraphqlRequestResponse } from '../types';
|
|
3
|
+
import { GraphqlRequestResponse } from '../utils/types';
|
|
4
4
|
export interface NhostGraphqlConstructorParams {
|
|
5
5
|
/**
|
|
6
6
|
* GraphQL endpoint.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphql.d.ts","sourceRoot":"","sources":["graphql.ts"],"names":[],"mappings":"AAAA,OAAc,EAAiB,kBAAkB,EAAuB,MAAM,OAAO,CAAA;AACrF,OAAO,EAAE,YAAY,EAAS,MAAM,SAAS,CAAA;AAE7C,OAAO,EAAE,sBAAsB,EAAmB,MAAM,
|
|
1
|
+
{"version":3,"file":"graphql.d.ts","sourceRoot":"","sources":["graphql.ts"],"names":[],"mappings":"AAAA,OAAc,EAAiB,kBAAkB,EAAuB,MAAM,OAAO,CAAA;AACrF,OAAO,EAAE,YAAY,EAAS,MAAM,SAAS,CAAA;AAE7C,OAAO,EAAE,sBAAsB,EAAmB,MAAM,gBAAgB,CAAA;AAExE,MAAM,WAAW,6BAA6B;IAC5C;;OAEG;IACH,GAAG,EAAE,MAAM,CAAA;IACX;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AAED;;GAEG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,GAAG,CAAQ;IACnB,OAAO,CAAC,QAAQ,CAAe;IAC/B,OAAO,CAAC,WAAW,CAAe;IAClC,OAAO,CAAC,WAAW,CAAC,CAAQ;gBAEhB,MAAM,EAAE,6BAA6B;IAWjD;;;;;;;;;;;;;;;;;OAiBG;IACG,OAAO,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,GAAG,EAC5B,QAAQ,EAAE,MAAM,GAAG,YAAY,EAC/B,SAAS,CAAC,EAAE,CAAC,EACb,MAAM,CAAC,EAAE,kBAAkB,GAC1B,OAAO,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAAC;IAiDrC;;;;;;;;;OASG;IACH,MAAM,IAAI,MAAM;IAIhB;;;;;;;;;OASG;IACH,cAAc,CAAC,WAAW,EAAE,MAAM,GAAG,SAAS;IAS9C,OAAO,CAAC,0BAA0B;CAanC"}
|
package/dist/core/index.d.ts
CHANGED
package/dist/core/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,4BAA4B,EAAE,MAAM,gBAAgB,CAAA;AAClE,cAAc,gBAAgB,CAAA"}
|
|
@@ -1,18 +1,8 @@
|
|
|
1
|
-
import { HasuraAuthClient
|
|
1
|
+
import { HasuraAuthClient } from '@nhost/hasura-auth-js';
|
|
2
2
|
import { HasuraStorageClient } from '@nhost/hasura-storage-js';
|
|
3
3
|
import { NhostFunctionsClient } from '../clients/functions';
|
|
4
4
|
import { NhostGraphqlClient } from '../clients/graphql';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Nhost backend URL.
|
|
8
|
-
*/
|
|
9
|
-
backendUrl: string;
|
|
10
|
-
/**
|
|
11
|
-
* Admin secret. When set, it is sent as an `x-hasura-admin-secret` header for all
|
|
12
|
-
* GraphQL, Storage, and Serverless Functions requests.
|
|
13
|
-
*/
|
|
14
|
-
adminSecret?: string;
|
|
15
|
-
}
|
|
5
|
+
import { NhostClientConstructorParams } from '../utils/types';
|
|
16
6
|
export declare class NhostClient {
|
|
17
7
|
auth: HasuraAuthClient;
|
|
18
8
|
storage: HasuraStorageClient;
|
|
@@ -23,10 +13,12 @@ export declare class NhostClient {
|
|
|
23
13
|
* Nhost Client
|
|
24
14
|
*
|
|
25
15
|
* @example
|
|
26
|
-
*
|
|
16
|
+
* ```ts
|
|
17
|
+
* const nhost = new NhostClient({ subdomain, region });
|
|
18
|
+
* ```
|
|
27
19
|
*
|
|
28
20
|
* @docs https://docs.nhost.io/reference/javascript
|
|
29
21
|
*/
|
|
30
|
-
constructor({
|
|
22
|
+
constructor({ refreshIntervalTime, clientStorageGetter, clientStorageSetter, clientStorage, clientStorageType, autoRefreshToken, autoSignIn, adminSecret, devTools, start, ...urlParams }: NhostClientConstructorParams);
|
|
31
23
|
}
|
|
32
24
|
//# sourceMappingURL=nhost-client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nhost-client.d.ts","sourceRoot":"","sources":["nhost-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,
|
|
1
|
+
{"version":3,"file":"nhost-client.d.ts","sourceRoot":"","sources":["nhost-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AACxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAE9D,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAA;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AAEvD,OAAO,EAAE,4BAA4B,EAAE,MAAM,gBAAgB,CAAA;AAE7D,qBAAa,WAAW;IACtB,IAAI,EAAE,gBAAgB,CAAA;IACtB,OAAO,EAAE,mBAAmB,CAAA;IAC5B,SAAS,EAAE,oBAAoB,CAAA;IAC/B,OAAO,EAAE,kBAAkB,CAAA;IAC3B,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;IAE3B;;;;;;;;;OASG;gBACS,EACV,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,aAAa,EACb,iBAAiB,EACjB,gBAAgB,EAChB,UAAU,EACV,WAAW,EACX,QAAQ,EACR,KAAY,EACZ,GAAG,SAAS,EACb,EAAE,4BAA4B;CAoDhC"}
|
package/dist/index.cjs.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var U=Object.defineProperty,E=Object.defineProperties;var H=Object.getOwnPropertyDescriptors;var T=Object.getOwnPropertySymbols;var g=Object.prototype.hasOwnProperty,q=Object.prototype.propertyIsEnumerable;var k=(e,t,r)=>t in e?U(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,c=(e,t)=>{for(var r in t||(t={}))g.call(t,r)&&k(e,r,t[r]);if(T)for(var r of T(t))q.call(t,r)&&k(e,r,t[r]);return e},f=(e,t)=>E(e,H(t));var v=(e,t)=>{var r={};for(var s in e)g.call(e,s)&&t.indexOf(s)<0&&(r[s]=e[s]);if(e!=null&&T)for(var s of T(e))t.indexOf(s)<0&&q.call(e,s)&&(r[s]=e[s]);return r};Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var L=require("@nhost/hasura-auth-js"),S=require("@nhost/hasura-storage-js"),_=require("axios"),j=require("graphql");function x(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var w=x(_);class C{constructor(t){const{url:r,adminSecret:s}=t;this.accessToken=null,this.adminSecret=s,this.instance=w.default.create({baseURL:r})}async call(t,r,s){const i=c(c({},this.generateAccessTokenHeaders()),s==null?void 0:s.headers);let a;try{a=await this.instance.post(t,r,f(c({},s),{headers:i}))}catch(h){if(h instanceof Error)return{res:null,error:h}}return a?{res:a,error:null}:{res:null,error:new Error("Unable to make post request to funtion")}}setAccessToken(t){if(!t){this.accessToken=null;return}this.accessToken=t}generateAccessTokenHeaders(){return this.adminSecret?{"x-hasura-admin-secret":this.adminSecret}:this.accessToken?{Authorization:`Bearer ${this.accessToken}`}:{}}}class y{constructor(t){const{url:r,adminSecret:s}=t;this.url=r,this.accessToken=null,this.adminSecret=s,this.instance=w.default.create({baseURL:r})}async request(t,r,s){const i=c(c({},this.generateAccessTokenHeaders()),s==null?void 0:s.headers);try{const a="",u=(await this.instance.post("",{operationName:a||void 0,query:typeof t=="string"?t:j.print(t),variables:r},f(c({},s),{headers:i}))).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(a){return a instanceof Error?{data:null,error:a}:(console.error(a),{data:null,error:new Error("Unable to get do GraphQL request")})}}getUrl(){return this.url}setAccessToken(t){if(!t){this.accessToken=null;return}this.accessToken=t}generateAccessTokenHeaders(){return this.adminSecret?{"x-hasura-admin-secret":this.adminSecret}:this.accessToken?{Authorization:`Bearer ${this.accessToken}`}:{}}}const G=/^localhost(:\d+)*$/;function d(e,t){if("backendUrl"in e)return`${e.backendUrl}/v1/${t}`;if(e.subdomain!==void 0&&e.subdomain.match(G))return`http://${e.subdomain}/v1/${t}`;if(!("region"in e))throw new Error('A region must be specified when using a `subdomain` other than "localhost".');return`https://${e.subdomain}.${t}.${e.region}.nhost.run/v1`}class m{constructor(F){var p=F,{refreshIntervalTime:t,clientStorageGetter:r,clientStorageSetter:s,clientStorage:i,clientStorageType:a,autoRefreshToken:h,autoSignIn:u,adminSecret:o,devTools:$,start:N=!0}=p,l=v(p,["refreshIntervalTime","clientStorageGetter","clientStorageSetter","clientStorage","clientStorageType","autoRefreshToken","autoSignIn","adminSecret","devTools","start"]);var A;this.auth=new L.HasuraAuthClient({url:d(l,"auth"),refreshIntervalTime:t,clientStorageGetter:r,clientStorageSetter:s,clientStorage:i,clientStorageType:a,autoRefreshToken:h,autoSignIn:u,start:N}),this.storage=new S.HasuraStorageClient({url:d(l,"storage"),adminSecret:o}),this.functions=new C({url:d(l,"functions"),adminSecret:o}),this.graphql=new y({url:d(l,"graphql"),adminSecret:o}),this.storage.setAccessToken(this.auth.getAccessToken()),this.functions.setAccessToken(this.auth.getAccessToken()),this.graphql.setAccessToken(this.auth.getAccessToken()),(A=this.auth.client)==null||A.onStart(()=>{this.auth.onAuthStateChanged((n,b)=>{n==="SIGNED_OUT"&&(this.storage.setAccessToken(void 0),this.functions.setAccessToken(void 0),this.graphql.setAccessToken(void 0))}),this.auth.onTokenChanged(n=>{this.storage.setAccessToken(n==null?void 0:n.accessToken),this.functions.setAccessToken(n==null?void 0:n.accessToken),this.graphql.setAccessToken(n==null?void 0:n.accessToken)})}),this.devTools=$}}const D=e=>new m(e);exports.NhostClient=m;exports.NhostFunctionsClient=C;exports.NhostGraphqlClient=y;exports.createClient=D;
|
|
2
2
|
//# sourceMappingURL=index.cjs.js.map
|
package/dist/index.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs.js","sources":["../src/clients/functions.ts","../src/clients/graphql.ts","../src/core/nhost-client.ts","../src/index.ts"],"sourcesContent":["import axios, { AxiosInstance, AxiosRequestConfig, AxiosRequestHeaders, AxiosResponse } from 'axios'\n\nimport { FunctionCallResponse } from '../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 '../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 in your app 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 { HasuraAuthClient, NhostAuthConstructorParams } from '@nhost/hasura-auth-js'\nimport { HasuraStorageClient } from '@nhost/hasura-storage-js'\n\nimport { NhostFunctionsClient } from '../clients/functions'\nimport { NhostGraphqlClient } from '../clients/graphql'\n\nexport interface NhostClientConstructorParams extends Omit<NhostAuthConstructorParams, 'url'> {\n /**\n * Nhost backend URL.\n */\n backendUrl: string\n /**\n * Admin secret. When set, it is sent as an `x-hasura-admin-secret` header for all\n * GraphQL, Storage, and Serverless Functions requests.\n */\n adminSecret?: string\n}\n\nexport class NhostClient {\n auth: HasuraAuthClient\n storage: HasuraStorageClient\n functions: NhostFunctionsClient\n graphql: NhostGraphqlClient\n readonly devTools?: boolean\n\n /**\n * Nhost Client\n *\n * @example\n * const nhost = new NhostClient({ url });\n *\n * @docs https://docs.nhost.io/reference/javascript\n */\n constructor({\n backendUrl,\n refreshIntervalTime,\n clientStorageGetter,\n clientStorageSetter,\n clientStorage,\n clientStorageType,\n autoRefreshToken,\n autoSignIn,\n adminSecret,\n devTools,\n start = true\n }: NhostClientConstructorParams) {\n if (!backendUrl) throw new Error('Please specify a `backendUrl`. Docs: [todo]!')\n this.auth = new HasuraAuthClient({\n url: `${backendUrl}/v1/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: `${backendUrl}/v1/storage`,\n adminSecret\n })\n\n this.functions = new NhostFunctionsClient({\n url: `${backendUrl}/v1/functions`,\n adminSecret\n })\n\n this.graphql = new NhostGraphqlClient({\n url: `${backendUrl}/v1/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.devTools = devTools\n }\n}\n","import { NhostClient, NhostClientConstructorParams } from './core'\n\nconst createClient = (config: NhostClientConstructorParams) => new NhostClient(config)\n\nexport * from './clients'\nexport * from './core'\nexport { createClient }\n"],"names":["axios","print","HasuraAuthClient","HasuraStorageClient"],"mappings":"iuBAiBO,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,I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AAC,GAAyC,GAAI,GAAY,CAAM"}
|
|
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 in your app 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 = /^localhost(:\\d+)*$/\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 if ('backendUrl' in backendOrSubdomain) {\n return `${backendOrSubdomain.backendUrl}/v1/${service}`\n }\n\n if (backendOrSubdomain.subdomain !== undefined && backendOrSubdomain.subdomain.match(LOCALHOST)) {\n return `http://${backendOrSubdomain.subdomain}/v1/${service}`\n }\n\n if (!('region' in backendOrSubdomain)) {\n throw new Error('A region must be specified when using a `subdomain` other than \"localhost\".')\n }\n\n return `https://${backendOrSubdomain.subdomain}.${service}.${backendOrSubdomain.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'\n\nexport class NhostClient {\n auth: HasuraAuthClient\n storage: HasuraStorageClient\n functions: NhostFunctionsClient\n graphql: NhostGraphqlClient\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.devTools = devTools\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,CC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CAClB,CACF,CCtFA,KAAM,GAAe,AAAC,GAAyC,GAAI,GAAY,CAAM"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { NhostClientConstructorParams } from './utils/types';
|
|
2
|
+
import { NhostClient } from './core';
|
|
2
3
|
declare const createClient: (config: NhostClientConstructorParams) => NhostClient;
|
|
3
4
|
export * from './clients';
|
|
4
5
|
export * from './core';
|
|
6
|
+
export * from './utils/types';
|
|
5
7
|
export { createClient };
|
|
6
8
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,eAAe,CAAA;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAA;AAEpC,QAAA,MAAM,YAAY,WAAY,4BAA4B,gBAA4B,CAAA;AAEtF,cAAc,WAAW,CAAA;AACzB,cAAc,QAAQ,CAAA;AACtB,cAAc,eAAe,CAAA;AAC7B,OAAO,EAAE,YAAY,EAAE,CAAA"}
|
package/dist/index.esm.js
CHANGED
|
@@ -17,6 +17,18 @@ var __spreadValues = (a, b) => {
|
|
|
17
17
|
return a;
|
|
18
18
|
};
|
|
19
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
|
+
};
|
|
20
32
|
import { HasuraAuthClient } from "@nhost/hasura-auth-js";
|
|
21
33
|
import { HasuraStorageClient } from "@nhost/hasura-storage-js";
|
|
22
34
|
import axios from "axios";
|
|
@@ -138,25 +150,47 @@ class NhostGraphqlClient {
|
|
|
138
150
|
return {};
|
|
139
151
|
}
|
|
140
152
|
}
|
|
153
|
+
const LOCALHOST = /^localhost(:\d+)*$/;
|
|
154
|
+
function urlFromParams(backendOrSubdomain, service) {
|
|
155
|
+
if ("backendUrl" in backendOrSubdomain) {
|
|
156
|
+
return `${backendOrSubdomain.backendUrl}/v1/${service}`;
|
|
157
|
+
}
|
|
158
|
+
if (backendOrSubdomain.subdomain !== void 0 && backendOrSubdomain.subdomain.match(LOCALHOST)) {
|
|
159
|
+
return `http://${backendOrSubdomain.subdomain}/v1/${service}`;
|
|
160
|
+
}
|
|
161
|
+
if (!("region" in backendOrSubdomain)) {
|
|
162
|
+
throw new Error('A region must be specified when using a `subdomain` other than "localhost".');
|
|
163
|
+
}
|
|
164
|
+
return `https://${backendOrSubdomain.subdomain}.${service}.${backendOrSubdomain.region}.nhost.run/v1`;
|
|
165
|
+
}
|
|
141
166
|
class NhostClient {
|
|
142
|
-
constructor({
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
167
|
+
constructor(_a) {
|
|
168
|
+
var _b = _a, {
|
|
169
|
+
refreshIntervalTime,
|
|
170
|
+
clientStorageGetter,
|
|
171
|
+
clientStorageSetter,
|
|
172
|
+
clientStorage,
|
|
173
|
+
clientStorageType,
|
|
174
|
+
autoRefreshToken,
|
|
175
|
+
autoSignIn,
|
|
176
|
+
adminSecret,
|
|
177
|
+
devTools,
|
|
178
|
+
start = true
|
|
179
|
+
} = _b, urlParams = __objRest(_b, [
|
|
180
|
+
"refreshIntervalTime",
|
|
181
|
+
"clientStorageGetter",
|
|
182
|
+
"clientStorageSetter",
|
|
183
|
+
"clientStorage",
|
|
184
|
+
"clientStorageType",
|
|
185
|
+
"autoRefreshToken",
|
|
186
|
+
"autoSignIn",
|
|
187
|
+
"adminSecret",
|
|
188
|
+
"devTools",
|
|
189
|
+
"start"
|
|
190
|
+
]);
|
|
191
|
+
var _a2;
|
|
158
192
|
this.auth = new HasuraAuthClient({
|
|
159
|
-
url:
|
|
193
|
+
url: urlFromParams(urlParams, "auth"),
|
|
160
194
|
refreshIntervalTime,
|
|
161
195
|
clientStorageGetter,
|
|
162
196
|
clientStorageSetter,
|
|
@@ -167,21 +201,21 @@ class NhostClient {
|
|
|
167
201
|
start
|
|
168
202
|
});
|
|
169
203
|
this.storage = new HasuraStorageClient({
|
|
170
|
-
url:
|
|
204
|
+
url: urlFromParams(urlParams, "storage"),
|
|
171
205
|
adminSecret
|
|
172
206
|
});
|
|
173
207
|
this.functions = new NhostFunctionsClient({
|
|
174
|
-
url:
|
|
208
|
+
url: urlFromParams(urlParams, "functions"),
|
|
175
209
|
adminSecret
|
|
176
210
|
});
|
|
177
211
|
this.graphql = new NhostGraphqlClient({
|
|
178
|
-
url:
|
|
212
|
+
url: urlFromParams(urlParams, "graphql"),
|
|
179
213
|
adminSecret
|
|
180
214
|
});
|
|
181
215
|
this.storage.setAccessToken(this.auth.getAccessToken());
|
|
182
216
|
this.functions.setAccessToken(this.auth.getAccessToken());
|
|
183
217
|
this.graphql.setAccessToken(this.auth.getAccessToken());
|
|
184
|
-
(
|
|
218
|
+
(_a2 = this.auth.client) == null ? void 0 : _a2.onStart(() => {
|
|
185
219
|
this.auth.onAuthStateChanged((_event, session) => {
|
|
186
220
|
if (_event === "SIGNED_OUT") {
|
|
187
221
|
this.storage.setAccessToken(void 0);
|
package/dist/index.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.esm.js","sources":["../src/clients/functions.ts","../src/clients/graphql.ts","../src/core/nhost-client.ts","../src/index.ts"],"sourcesContent":["import axios, { AxiosInstance, AxiosRequestConfig, AxiosRequestHeaders, AxiosResponse } from 'axios'\n\nimport { FunctionCallResponse } from '../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 '../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 in your app 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 { HasuraAuthClient, NhostAuthConstructorParams } from '@nhost/hasura-auth-js'\nimport { HasuraStorageClient } from '@nhost/hasura-storage-js'\n\nimport { NhostFunctionsClient } from '../clients/functions'\nimport { NhostGraphqlClient } from '../clients/graphql'\n\nexport interface NhostClientConstructorParams extends Omit<NhostAuthConstructorParams, 'url'> {\n /**\n * Nhost backend URL.\n */\n backendUrl: string\n /**\n * Admin secret. When set, it is sent as an `x-hasura-admin-secret` header for all\n * GraphQL, Storage, and Serverless Functions requests.\n */\n adminSecret?: string\n}\n\nexport class NhostClient {\n auth: HasuraAuthClient\n storage: HasuraStorageClient\n functions: NhostFunctionsClient\n graphql: NhostGraphqlClient\n readonly devTools?: boolean\n\n /**\n * Nhost Client\n *\n * @example\n * const nhost = new NhostClient({ url });\n *\n * @docs https://docs.nhost.io/reference/javascript\n */\n constructor({\n backendUrl,\n refreshIntervalTime,\n clientStorageGetter,\n clientStorageSetter,\n clientStorage,\n clientStorageType,\n autoRefreshToken,\n autoSignIn,\n adminSecret,\n devTools,\n start = true\n }: NhostClientConstructorParams) {\n if (!backendUrl) throw new Error('Please specify a `backendUrl`. Docs: [todo]!')\n this.auth = new HasuraAuthClient({\n url: `${backendUrl}/v1/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: `${backendUrl}/v1/storage`,\n adminSecret\n })\n\n this.functions = new NhostFunctionsClient({\n url: `${backendUrl}/v1/functions`,\n adminSecret\n })\n\n this.graphql = new NhostGraphqlClient({\n url: `${backendUrl}/v1/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.devTools = devTools\n }\n}\n","import { NhostClient, NhostClientConstructorParams } from './core'\n\nconst createClient = (config: NhostClientConstructorParams) => new NhostClient(config)\n\nexport * from './clients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Ae,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 in your app 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 = /^localhost(:\\d+)*$/\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 if ('backendUrl' in backendOrSubdomain) {\n return `${backendOrSubdomain.backendUrl}/v1/${service}`\n }\n\n if (backendOrSubdomain.subdomain !== undefined && backendOrSubdomain.subdomain.match(LOCALHOST)) {\n return `http://${backendOrSubdomain.subdomain}/v1/${service}`\n }\n\n if (!('region' in backendOrSubdomain)) {\n throw new Error('A region must be specified when using a `subdomain` other than \"localhost\".')\n }\n\n return `https://${backendOrSubdomain.subdomain}.${service}.${backendOrSubdomain.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'\n\nexport class NhostClient {\n auth: HasuraAuthClient\n storage: HasuraStorageClient\n functions: NhostFunctionsClient\n graphql: NhostGraphqlClient\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.devTools = devTools\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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A;AAAA,MACA;AAAA,MACA;AAAA,IAAA,CACD;AAEI,SAAA,UAAU,IAAI,oBAAoB;AAAA,MACrC,KAAK,cAAc,WAAW,SAAS;AAAA,MACvC;AAAA,IAAA,CACD;AAEI,SAAA,YAAY,IAAI,qBAAqB;AAAA,MACxC,KAAK,cAAc,WAAW,WAAW;AAAA,MACzC;AAAA,IAAA,CACD;AAEI,SAAA,UAAU,IAAI,mBAAmB;AAAA,MACpC,KAAK,cAAc,WAAW,SAAS;AAAA,MACvC;AAAA,IAAA,CACD;AAGD,SAAK,QAAQ,eAAe,KAAK,KAAK,gBAAgB;AACtD,SAAK,UAAU,eAAe,KAAK,KAAK,gBAAgB;AACxD,SAAK,QAAQ,eAAe,KAAK,KAAK,gBAAgB;AAEjD,gBAAA,KAAK,WAAL,oBAAa,QAAQ,MAAM;AAE9B,WAAK,KAAK,mBAAmB,CAAC,QAAQ,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,WAAW;AAAA,EAClB;AACF;ACtFA,MAAM,eAAe,CAAC,WAAyC,IAAI,YAAY,MAAM;;"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { NhostClientConstructorParams } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* `backendUrl` should now be used only when self-hosting
|
|
4
|
+
* `subdomain` and `region` should be used instead when using the Nhost platform
|
|
5
|
+
* `
|
|
6
|
+
* @param backendOrSubdomain
|
|
7
|
+
* @param service
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
export declare function urlFromParams(backendOrSubdomain: Pick<NhostClientConstructorParams, 'region' | 'subdomain' | 'backendUrl'>, service: string): string;
|
|
11
|
+
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,SAAS,CAAA;AAItD;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAC3B,kBAAkB,EAAE,IAAI,CAAC,4BAA4B,EAAE,QAAQ,GAAG,WAAW,GAAG,YAAY,CAAC,EAC7F,OAAO,EAAE,MAAM,UAehB"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { AxiosResponse } from 'axios';
|
|
2
|
+
import { NhostAuthConstructorParams } from '@nhost/hasura-auth-js';
|
|
3
|
+
export type { NhostAuthConstructorParams };
|
|
4
|
+
export declare type BackendUrl = {
|
|
5
|
+
/**
|
|
6
|
+
* Nhost backend URL
|
|
7
|
+
* Should only be used when self-hosting
|
|
8
|
+
*/
|
|
9
|
+
backendUrl: string;
|
|
10
|
+
/**
|
|
11
|
+
* When set, the admin secret is sent as a header, `x-hasura-admin-secret`,
|
|
12
|
+
* for all requests to GraphQL, Storage, and Functions.
|
|
13
|
+
*/
|
|
14
|
+
adminSecret?: string;
|
|
15
|
+
};
|
|
16
|
+
export declare type Subdomain = {
|
|
17
|
+
/**
|
|
18
|
+
* App subdomain (e.g, ieingiwnginwnfnegqwvdqwdwq)
|
|
19
|
+
* Should be used when using the Nhost platform
|
|
20
|
+
* Use "localhost" in development
|
|
21
|
+
*/
|
|
22
|
+
subdomain: string;
|
|
23
|
+
/**
|
|
24
|
+
* App region (e.g., eu-central-1)
|
|
25
|
+
* Not required in development (when `subdomain` is "localhost")
|
|
26
|
+
*/
|
|
27
|
+
region?: string;
|
|
28
|
+
/**
|
|
29
|
+
* When set, the admin secret is sent as a header, `x-hasura-admin-secret`,
|
|
30
|
+
* for all requests to GraphQL, Storage, and Functions.
|
|
31
|
+
*/
|
|
32
|
+
adminSecret?: string;
|
|
33
|
+
};
|
|
34
|
+
export declare type BackendOrSubdomain = BackendUrl | Subdomain;
|
|
35
|
+
export interface NhostClientConstructorParams extends Partial<BackendUrl>, Partial<Subdomain>, Omit<NhostAuthConstructorParams, 'url'> {
|
|
36
|
+
}
|
|
37
|
+
export declare type GraphqlRequestResponse<T = unknown> = {
|
|
38
|
+
data: null;
|
|
39
|
+
error: Error | object | object[];
|
|
40
|
+
} | {
|
|
41
|
+
data: T;
|
|
42
|
+
error: null;
|
|
43
|
+
};
|
|
44
|
+
export declare type FunctionCallResponse<T = unknown> = {
|
|
45
|
+
res: AxiosResponse<T>;
|
|
46
|
+
error: null;
|
|
47
|
+
} | {
|
|
48
|
+
res: null;
|
|
49
|
+
error: Error;
|
|
50
|
+
};
|
|
51
|
+
export interface GraphqlResponse<T = object> {
|
|
52
|
+
errors?: object[];
|
|
53
|
+
data?: T;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AAE1C,OAAO,EAAE,0BAA0B,EAAE,MAAM,uBAAuB,CAAA;AAElE,YAAY,EAAE,0BAA0B,EAAE,CAAA;AAE1C,oBAAY,UAAU,GAAG;IACvB;;;OAGG;IACH,UAAU,EAAE,MAAM,CAAA;IAClB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB,CAAA;AAED,oBAAY,SAAS,GAAG;IACtB;;;;OAIG;IACH,SAAS,EAAE,MAAM,CAAA;IAEjB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IACf;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB,CAAA;AAED,oBAAY,kBAAkB,GAAG,UAAU,GAAG,SAAS,CAAA;AAEvD,MAAM,WAAW,4BACf,SAAQ,OAAO,CAAC,UAAU,CAAC,EACzB,OAAO,CAAC,SAAS,CAAC,EAClB,IAAI,CAAC,0BAA0B,EAAE,KAAK,CAAC;CAAG;AAE9C,oBAAY,sBAAsB,CAAC,CAAC,GAAG,OAAO,IAC1C;IACE,IAAI,EAAE,IAAI,CAAA;IACV,KAAK,EAAE,KAAK,GAAG,MAAM,GAAG,MAAM,EAAE,CAAA;CACjC,GACD;IACE,IAAI,EAAE,CAAC,CAAA;IACP,KAAK,EAAE,IAAI,CAAA;CACZ,CAAA;AAEL,oBAAY,oBAAoB,CAAC,CAAC,GAAG,OAAO,IACxC;IACE,GAAG,EAAE,aAAa,CAAC,CAAC,CAAC,CAAA;IACrB,KAAK,EAAE,IAAI,CAAA;CACZ,GACD;IACE,GAAG,EAAE,IAAI,CAAA;IACT,KAAK,EAAE,KAAK,CAAA;CACb,CAAA;AAEL,MAAM,WAAW,eAAe,CAAC,CAAC,GAAG,MAAM;IACzC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;IACjB,IAAI,CAAC,EAAE,CAAC,CAAA;CACT"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nhost/nhost-js",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.1",
|
|
4
4
|
"description": "Nhost JavaScript SDK",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
@@ -71,5 +71,5 @@
|
|
|
71
71
|
"typedoc": "typedoc --options ./nhost-js.typedoc.json --tsconfig ./typedoc.tsconfig.json",
|
|
72
72
|
"docgen": "pnpm typedoc && docgen --config ./nhost-js.docgen.json"
|
|
73
73
|
},
|
|
74
|
-
"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 backendUrl: 'https://
|
|
74
|
+
"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 backendUrl: 'https://subdomain.nhost.run'\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\n"
|
|
75
75
|
}
|