@nhost/nhost-js 1.1.10 → 1.1.13
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/clients/functions.d.ts +20 -0
- package/dist/clients/functions.d.ts.map +1 -1
- package/dist/clients/graphql.d.ts +38 -0
- package/dist/clients/graphql.d.ts.map +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js.map +1 -1
- package/package.json +6 -5
- package/umd/clients/functions.d.ts +20 -0
- package/umd/clients/functions.d.ts.map +1 -1
- package/umd/clients/graphql.d.ts +38 -0
- package/umd/clients/graphql.d.ts.map +1 -1
- package/umd/nhost-js.umd.js +6 -6
- package/umd/nhost-js.umd.js.map +1 -1
|
@@ -10,7 +10,27 @@ export declare class NhostFunctionsClient {
|
|
|
10
10
|
private instance;
|
|
11
11
|
private accessToken;
|
|
12
12
|
constructor(params: NhostFunctionsConstructorParams);
|
|
13
|
+
/**
|
|
14
|
+
* Use `nhost.functions.call` to call (sending a POST request to) a serverless function.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* await nhost.functions.call('send-welcome-email', { email: 'joe@example.com', name: 'Joe Doe' })
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @docs https://docs.nhost.io/reference/javascript/nhost-js/functions/call
|
|
22
|
+
*/
|
|
13
23
|
call<T = unknown, D = any>(url: string, data: D, config?: AxiosRequestConfig): Promise<FunctionCallResponse<T>>;
|
|
24
|
+
/**
|
|
25
|
+
* 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.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* nhost.functions.setAccessToken('some-access-token')
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @docs https://docs.nhost.io/reference/javascript/nhost-js/functions/set-access-token
|
|
33
|
+
*/
|
|
14
34
|
setAccessToken(accessToken: string | undefined): void;
|
|
15
35
|
private generateAccessTokenHeaders;
|
|
16
36
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"functions.d.ts","sourceRoot":"","sources":["functions.ts"],"names":[],"mappings":"AAAA,OAAc,EAAiB,kBAAkB,EAAiB,MAAM,OAAO,CAAA;AAE/E,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAA;AAC/C,MAAM,WAAW,+BAA+B;IAC9C,GAAG,EAAE,MAAM,CAAA;CACZ;AAED;;GAEG;AACH,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,QAAQ,CAAe;IAC/B,OAAO,CAAC,WAAW,CAAe;gBAEtB,MAAM,EAAE,+BAA+B;
|
|
1
|
+
{"version":3,"file":"functions.d.ts","sourceRoot":"","sources":["functions.ts"],"names":[],"mappings":"AAAA,OAAc,EAAiB,kBAAkB,EAAiB,MAAM,OAAO,CAAA;AAE/E,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAA;AAC/C,MAAM,WAAW,+BAA+B;IAC9C,GAAG,EAAE,MAAM,CAAA;CACZ;AAED;;GAEG;AACH,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,QAAQ,CAAe;IAC/B,OAAO,CAAC,WAAW,CAAe;gBAEtB,MAAM,EAAE,+BAA+B;IASnD;;;;;;;;;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;CAUnC"}
|
|
@@ -12,8 +12,46 @@ export declare class NhostGraphqlClient {
|
|
|
12
12
|
private instance;
|
|
13
13
|
private accessToken;
|
|
14
14
|
constructor(params: NhostGraphqlConstructorParams);
|
|
15
|
+
/**
|
|
16
|
+
* 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).
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* const CUSTOMERS = gql`
|
|
21
|
+
* query {
|
|
22
|
+
* customers {
|
|
23
|
+
* id
|
|
24
|
+
* name
|
|
25
|
+
* }
|
|
26
|
+
* }
|
|
27
|
+
* `
|
|
28
|
+
* const { data, error } = await nhost.graphql.request(CUSTOMERS)
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @docs https://docs.nhost.io/reference/javascript/nhost-js/graphql/request
|
|
32
|
+
*/
|
|
15
33
|
request<T = any, V = any>(document: string | DocumentNode, variables?: V, config?: AxiosRequestConfig): Promise<GraphqlRequestResponse<T>>;
|
|
34
|
+
/**
|
|
35
|
+
* Use `nhost.graphql.getUrl` to get the GraphQL URL.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* const url = nhost.graphql.getUrl();
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* @docs https://docs.nhost.io/reference/javascript/nhost-js/graphql/get-url
|
|
43
|
+
*/
|
|
16
44
|
getUrl(): string;
|
|
45
|
+
/**
|
|
46
|
+
* 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.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* nhost.graphql.setAccessToken('some-access-token')
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* @docs https://docs.nhost.io/reference/javascript/nhost-js/graphql/set-access-token
|
|
54
|
+
*/
|
|
17
55
|
setAccessToken(accessToken: string | undefined): void;
|
|
18
56
|
private generateAccessTokenHeaders;
|
|
19
57
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphql.d.ts","sourceRoot":"","sources":["graphql.ts"],"names":[],"mappings":"AAAA,OAAc,EAAiB,kBAAkB,EAAE,MAAM,OAAO,CAAA;AAChE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAG3C,OAAO,EAAE,sBAAsB,EAAmB,MAAM,UAAU,CAAA;AAElE,MAAM,WAAW,6BAA6B;IAC5C,GAAG,EAAE,MAAM,CAAA;CACZ;AAED;;GAEG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,GAAG,CAAQ;IACnB,OAAO,CAAC,QAAQ,CAAe;IAC/B,OAAO,CAAC,WAAW,CAAe;gBAEtB,MAAM,EAAE,6BAA6B;
|
|
1
|
+
{"version":3,"file":"graphql.d.ts","sourceRoot":"","sources":["graphql.ts"],"names":[],"mappings":"AAAA,OAAc,EAAiB,kBAAkB,EAAE,MAAM,OAAO,CAAA;AAChE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAG3C,OAAO,EAAE,sBAAsB,EAAmB,MAAM,UAAU,CAAA;AAElE,MAAM,WAAW,6BAA6B;IAC5C,GAAG,EAAE,MAAM,CAAA;CACZ;AAED;;GAEG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,GAAG,CAAQ;IACnB,OAAO,CAAC,QAAQ,CAAe;IAC/B,OAAO,CAAC,WAAW,CAAe;gBAEtB,MAAM,EAAE,6BAA6B;IAUjD;;;;;;;;;;;;;;;;;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;CAUnC"}
|
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, AxiosResponse } from 'axios'\n\nimport { FunctionCallResponse } from '../types'\nexport interface NhostFunctionsConstructorParams {\n url: string\n}\n\n/**\n * @alias Functions\n */\nexport class NhostFunctionsClient {\n private instance: AxiosInstance\n private accessToken: string | null\n\n constructor(params: NhostFunctionsConstructorParams) {\n const { url } = params\n\n this.accessToken = null\n this.instance = axios.create({\n baseURL: url\n })\n }\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 setAccessToken(accessToken: string | undefined) {\n if (!accessToken) {\n this.accessToken = null\n return\n }\n\n this.accessToken = accessToken\n }\n\n private generateAccessTokenHeaders(): { Authorization: string } | undefined {\n if (!this.accessToken) {\n return\n }\n\n // eslint-disable-next-line consistent-return\n return {\n Authorization: `Bearer ${this.accessToken}`\n }\n }\n}\n","import axios, { AxiosInstance, AxiosRequestConfig } from 'axios'\nimport type { DocumentNode } from 'graphql'\nimport { print } from 'graphql/language/printer'\n\nimport { GraphqlRequestResponse, GraphqlResponse } from '../types'\n\nexport interface NhostGraphqlConstructorParams {\n url: 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\n constructor(params: NhostGraphqlConstructorParams) {\n const { url } = params\n\n this.url = url\n this.accessToken = null\n this.instance = axios.create({\n baseURL: url\n })\n }\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 ...config?.headers,\n ...this.generateAccessTokenHeaders()\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 getUrl(): string {\n return this.url\n }\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() {\n if (!this.accessToken) {\n return\n }\n\n // eslint-disable-next-line consistent-return\n return {\n Authorization: `Bearer ${this.accessToken}`\n }\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\nexport class NhostClient {\n auth: HasuraAuthClient\n storage: HasuraStorageClient\n functions: NhostFunctionsClient\n graphql: NhostGraphqlClient\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 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 })\n\n this.functions = new NhostFunctionsClient({\n url: `${backendUrl}/v1/functions`\n })\n\n this.graphql = new NhostGraphqlClient({\n url: `${backendUrl}/v1/graphql`\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 }\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":"kvBAUO,MAAM,CAAqB,CAIhC,YAAY,EAAyC,CACnD,KAAM,CAAE,OAAQ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AC/B,KAAA,QAAQ,eAAe,iBAAS,WAAW,EAC3C,KAAA,UAAU,eAAe,iBAAS,WAAW,EAC7C,KAAA,QAAQ,eAAe,iBAAS,WAAW,CAAA,CACjD,CAAA,EAEL,CACF,CCpFA,KAAM,GAAe,AAAC,GAAyC,GAAI,GAAY,CAAM"}
|
|
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, AxiosResponse } from 'axios'\n\nimport { FunctionCallResponse } from '../types'\nexport interface NhostFunctionsConstructorParams {\n url: string\n}\n\n/**\n * @alias Functions\n */\nexport class NhostFunctionsClient {\n private instance: AxiosInstance\n private accessToken: string | null\n\n constructor(params: NhostFunctionsConstructorParams) {\n const { url } = params\n\n this.accessToken = null\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(): { Authorization: string } | undefined {\n if (!this.accessToken) {\n return\n }\n\n // eslint-disable-next-line consistent-return\n return {\n Authorization: `Bearer ${this.accessToken}`\n }\n }\n}\n","import axios, { AxiosInstance, AxiosRequestConfig } from 'axios'\nimport type { DocumentNode } from 'graphql'\nimport { print } from 'graphql/language/printer'\n\nimport { GraphqlRequestResponse, GraphqlResponse } from '../types'\n\nexport interface NhostGraphqlConstructorParams {\n url: 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\n constructor(params: NhostGraphqlConstructorParams) {\n const { url } = params\n\n this.url = url\n this.accessToken = null\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 ...config?.headers,\n ...this.generateAccessTokenHeaders()\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() {\n if (!this.accessToken) {\n return\n }\n\n // eslint-disable-next-line consistent-return\n return {\n Authorization: `Bearer ${this.accessToken}`\n }\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\nexport class NhostClient {\n auth: HasuraAuthClient\n storage: HasuraStorageClient\n functions: NhostFunctionsClient\n graphql: NhostGraphqlClient\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 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 })\n\n this.functions = new NhostFunctionsClient({\n url: `${backendUrl}/v1/functions`\n })\n\n this.graphql = new NhostGraphqlClient({\n url: `${backendUrl}/v1/graphql`\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 }\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":"kvBAUO,MAAM,CAAqB,CAIhC,YAAY,EAAyC,CACnD,KAAM,CAAE,OAAQ,EAEhB,KAAK,YAAc,KACd,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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+1 @@
|
|
|
1
|
-
{"version":3,"file":"index.es.js","sources":["../src/clients/functions.ts","../src/clients/graphql.ts","../src/core/nhost-client.ts","../src/index.ts"],"sourcesContent":["import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios'\n\nimport { FunctionCallResponse } from '../types'\nexport interface NhostFunctionsConstructorParams {\n url: string\n}\n\n/**\n * @alias Functions\n */\nexport class NhostFunctionsClient {\n private instance: AxiosInstance\n private accessToken: string | null\n\n constructor(params: NhostFunctionsConstructorParams) {\n const { url } = params\n\n this.accessToken = null\n this.instance = axios.create({\n baseURL: url\n })\n }\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 setAccessToken(accessToken: string | undefined) {\n if (!accessToken) {\n this.accessToken = null\n return\n }\n\n this.accessToken = accessToken\n }\n\n private generateAccessTokenHeaders(): { Authorization: string } | undefined {\n if (!this.accessToken) {\n return\n }\n\n // eslint-disable-next-line consistent-return\n return {\n Authorization: `Bearer ${this.accessToken}`\n }\n }\n}\n","import axios, { AxiosInstance, AxiosRequestConfig } from 'axios'\nimport type { DocumentNode } from 'graphql'\nimport { print } from 'graphql/language/printer'\n\nimport { GraphqlRequestResponse, GraphqlResponse } from '../types'\n\nexport interface NhostGraphqlConstructorParams {\n url: 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\n constructor(params: NhostGraphqlConstructorParams) {\n const { url } = params\n\n this.url = url\n this.accessToken = null\n this.instance = axios.create({\n baseURL: url\n })\n }\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 ...config?.headers,\n ...this.generateAccessTokenHeaders()\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 getUrl(): string {\n return this.url\n }\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() {\n if (!this.accessToken) {\n return\n }\n\n // eslint-disable-next-line consistent-return\n return {\n Authorization: `Bearer ${this.accessToken}`\n }\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\nexport class NhostClient {\n auth: HasuraAuthClient\n storage: HasuraStorageClient\n functions: NhostFunctionsClient\n graphql: NhostGraphqlClient\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 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 })\n\n this.functions = new NhostFunctionsClient({\n url: `${backendUrl}/v1/functions`\n })\n\n this.graphql = new NhostGraphqlClient({\n url: `${backendUrl}/v1/graphql`\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 }\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":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAUO,MAAM,qBAAqB;AAAA,EAIhC,YAAY,QAAyC;AACnD,UAAM,EAAE,QAAQ;AAEhB,SAAK,cAAc;AACd,SAAA,WAAW,MAAM,OAAO;AAAA,MAC3B,SAAS;AAAA,IAAA,CACV;AAAA,EACH;AAAA,QAEM,KACJ,KACA,MACA,QACkC;AAClC,UAAM,UAAU,kCACX,KAAK,2BAA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AA,UAAU,IAAI,mBAAmB;AAAA,MACpC,KAAK,GAAG;AAAA,IAAA,CACT;AAGD,SAAK,QAAQ,eAAe,KAAK,KAAK,gBAAgB;AACtD,SAAK,UAAU,eAAe,KAAK,KAAK,gBAAgB;AACxD,SAAK,QAAQ,eAAe,KAAK,KAAK,gBAAgB;AAEjD,eAAA,KAAK,WAAL,mBAAa,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;AAAA,EAEL;AACF;ACpFA,MAAM,eAAe,CAAC,WAAyC,IAAI,YAAY,MAAM;;"}
|
|
1
|
+
{"version":3,"file":"index.es.js","sources":["../src/clients/functions.ts","../src/clients/graphql.ts","../src/core/nhost-client.ts","../src/index.ts"],"sourcesContent":["import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios'\n\nimport { FunctionCallResponse } from '../types'\nexport interface NhostFunctionsConstructorParams {\n url: string\n}\n\n/**\n * @alias Functions\n */\nexport class NhostFunctionsClient {\n private instance: AxiosInstance\n private accessToken: string | null\n\n constructor(params: NhostFunctionsConstructorParams) {\n const { url } = params\n\n this.accessToken = null\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(): { Authorization: string } | undefined {\n if (!this.accessToken) {\n return\n }\n\n // eslint-disable-next-line consistent-return\n return {\n Authorization: `Bearer ${this.accessToken}`\n }\n }\n}\n","import axios, { AxiosInstance, AxiosRequestConfig } from 'axios'\nimport type { DocumentNode } from 'graphql'\nimport { print } from 'graphql/language/printer'\n\nimport { GraphqlRequestResponse, GraphqlResponse } from '../types'\n\nexport interface NhostGraphqlConstructorParams {\n url: 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\n constructor(params: NhostGraphqlConstructorParams) {\n const { url } = params\n\n this.url = url\n this.accessToken = null\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 ...config?.headers,\n ...this.generateAccessTokenHeaders()\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() {\n if (!this.accessToken) {\n return\n }\n\n // eslint-disable-next-line consistent-return\n return {\n Authorization: `Bearer ${this.accessToken}`\n }\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\nexport class NhostClient {\n auth: HasuraAuthClient\n storage: HasuraStorageClient\n functions: NhostFunctionsClient\n graphql: NhostGraphqlClient\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 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 })\n\n this.functions = new NhostFunctionsClient({\n url: `${backendUrl}/v1/functions`\n })\n\n this.graphql = new NhostGraphqlClient({\n url: `${backendUrl}/v1/graphql`\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 }\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":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAUO,MAAM,qBAAqB;AAAA,EAIhC,YAAY,QAAyC;AACnD,UAAM,EAAE,QAAQ;AAEhB,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,6BAAoE;AACtE,QAAA,CAAC,KAAK,aAAa;AACrB;AAAA,IACF;AAGO,WAAA;AAAA,MACL,eAAe,UAAU,KAAK;AAAA,IAAA;AAAA,EAElC;AACF;AC9EO,MAAM,mBAAmB;AAAA,EAK9B,YAAY,QAAuC;AACjD,UAAM,EAAE,QAAQ;AAEhB,SAAK,MAAM;AACX,SAAK,cAAc;AACd,SAAA,WAAW,MAAM,OAAO;AAAA,MAC3B,SAAS;AAAA,IAAA,CACV;AAAA,EACH;AAAA,QAoBM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|
|
3
|
+
"version": "1.1.13",
|
|
4
4
|
"description": "Nhost JavaScript SDK",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
@@ -39,9 +39,9 @@
|
|
|
39
39
|
"access": "public"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@nhost/hasura-auth-js": "1.1.
|
|
43
|
-
"@nhost/hasura-storage-js": "0.2.
|
|
44
|
-
"axios": "^0.
|
|
42
|
+
"@nhost/hasura-auth-js": "1.1.8",
|
|
43
|
+
"@nhost/hasura-storage-js": "0.2.2",
|
|
44
|
+
"axios": "^0.27.2",
|
|
45
45
|
"jwt-decode": "^3.1.2",
|
|
46
46
|
"query-string": "^7.0.1"
|
|
47
47
|
},
|
|
@@ -57,7 +57,8 @@
|
|
|
57
57
|
"build": "run-p build:lib build:umd",
|
|
58
58
|
"build:lib": "vite build --config ../../config/vite.lib.config.js",
|
|
59
59
|
"build:umd": "vite build --config ../../config/vite.lib.umd.config.js",
|
|
60
|
-
"test": "
|
|
60
|
+
"test": "vitest run --config ../../config/vite.lib.config.js",
|
|
61
|
+
"test:watch": "vitest --config ../../config/vite.lib.config.js",
|
|
61
62
|
"prettier": "prettier --check src/",
|
|
62
63
|
"prettier:fix": "prettier --write src/",
|
|
63
64
|
"lint": "eslint . --ext .ts,.tsx",
|
|
@@ -10,7 +10,27 @@ export declare class NhostFunctionsClient {
|
|
|
10
10
|
private instance;
|
|
11
11
|
private accessToken;
|
|
12
12
|
constructor(params: NhostFunctionsConstructorParams);
|
|
13
|
+
/**
|
|
14
|
+
* Use `nhost.functions.call` to call (sending a POST request to) a serverless function.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* await nhost.functions.call('send-welcome-email', { email: 'joe@example.com', name: 'Joe Doe' })
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @docs https://docs.nhost.io/reference/javascript/nhost-js/functions/call
|
|
22
|
+
*/
|
|
13
23
|
call<T = unknown, D = any>(url: string, data: D, config?: AxiosRequestConfig): Promise<FunctionCallResponse<T>>;
|
|
24
|
+
/**
|
|
25
|
+
* 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.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* nhost.functions.setAccessToken('some-access-token')
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @docs https://docs.nhost.io/reference/javascript/nhost-js/functions/set-access-token
|
|
33
|
+
*/
|
|
14
34
|
setAccessToken(accessToken: string | undefined): void;
|
|
15
35
|
private generateAccessTokenHeaders;
|
|
16
36
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"functions.d.ts","sourceRoot":"","sources":["functions.ts"],"names":[],"mappings":"AAAA,OAAc,EAAiB,kBAAkB,EAAiB,MAAM,OAAO,CAAA;AAE/E,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAA;AAC/C,MAAM,WAAW,+BAA+B;IAC9C,GAAG,EAAE,MAAM,CAAA;CACZ;AAED;;GAEG;AACH,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,QAAQ,CAAe;IAC/B,OAAO,CAAC,WAAW,CAAe;gBAEtB,MAAM,EAAE,+BAA+B;
|
|
1
|
+
{"version":3,"file":"functions.d.ts","sourceRoot":"","sources":["functions.ts"],"names":[],"mappings":"AAAA,OAAc,EAAiB,kBAAkB,EAAiB,MAAM,OAAO,CAAA;AAE/E,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAA;AAC/C,MAAM,WAAW,+BAA+B;IAC9C,GAAG,EAAE,MAAM,CAAA;CACZ;AAED;;GAEG;AACH,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,QAAQ,CAAe;IAC/B,OAAO,CAAC,WAAW,CAAe;gBAEtB,MAAM,EAAE,+BAA+B;IASnD;;;;;;;;;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;CAUnC"}
|
package/umd/clients/graphql.d.ts
CHANGED
|
@@ -12,8 +12,46 @@ export declare class NhostGraphqlClient {
|
|
|
12
12
|
private instance;
|
|
13
13
|
private accessToken;
|
|
14
14
|
constructor(params: NhostGraphqlConstructorParams);
|
|
15
|
+
/**
|
|
16
|
+
* 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).
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* const CUSTOMERS = gql`
|
|
21
|
+
* query {
|
|
22
|
+
* customers {
|
|
23
|
+
* id
|
|
24
|
+
* name
|
|
25
|
+
* }
|
|
26
|
+
* }
|
|
27
|
+
* `
|
|
28
|
+
* const { data, error } = await nhost.graphql.request(CUSTOMERS)
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @docs https://docs.nhost.io/reference/javascript/nhost-js/graphql/request
|
|
32
|
+
*/
|
|
15
33
|
request<T = any, V = any>(document: string | DocumentNode, variables?: V, config?: AxiosRequestConfig): Promise<GraphqlRequestResponse<T>>;
|
|
34
|
+
/**
|
|
35
|
+
* Use `nhost.graphql.getUrl` to get the GraphQL URL.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* const url = nhost.graphql.getUrl();
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* @docs https://docs.nhost.io/reference/javascript/nhost-js/graphql/get-url
|
|
43
|
+
*/
|
|
16
44
|
getUrl(): string;
|
|
45
|
+
/**
|
|
46
|
+
* 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.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* nhost.graphql.setAccessToken('some-access-token')
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* @docs https://docs.nhost.io/reference/javascript/nhost-js/graphql/set-access-token
|
|
54
|
+
*/
|
|
17
55
|
setAccessToken(accessToken: string | undefined): void;
|
|
18
56
|
private generateAccessTokenHeaders;
|
|
19
57
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphql.d.ts","sourceRoot":"","sources":["graphql.ts"],"names":[],"mappings":"AAAA,OAAc,EAAiB,kBAAkB,EAAE,MAAM,OAAO,CAAA;AAChE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAG3C,OAAO,EAAE,sBAAsB,EAAmB,MAAM,UAAU,CAAA;AAElE,MAAM,WAAW,6BAA6B;IAC5C,GAAG,EAAE,MAAM,CAAA;CACZ;AAED;;GAEG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,GAAG,CAAQ;IACnB,OAAO,CAAC,QAAQ,CAAe;IAC/B,OAAO,CAAC,WAAW,CAAe;gBAEtB,MAAM,EAAE,6BAA6B;
|
|
1
|
+
{"version":3,"file":"graphql.d.ts","sourceRoot":"","sources":["graphql.ts"],"names":[],"mappings":"AAAA,OAAc,EAAiB,kBAAkB,EAAE,MAAM,OAAO,CAAA;AAChE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAG3C,OAAO,EAAE,sBAAsB,EAAmB,MAAM,UAAU,CAAA;AAElE,MAAM,WAAW,6BAA6B;IAC5C,GAAG,EAAE,MAAM,CAAA;CACZ;AAED;;GAEG;AACH,qBAAa,k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