@nhost/nhost-js 1.13.4 → 2.0.0

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.esm.js","sources":["../src/utils/helpers.ts","../src/clients/auth.ts","../src/clients/functions/index.ts","../src/clients/graphql/index.ts","../src/clients/storage.ts","../src/clients/nhost.ts"],"sourcesContent":["import { NhostClientConstructorParams } from './types'\n\n// a port can be a number or a placeholder string with leading and trailing double underscores, f.e. \"8080\" or \"__PLACEHOLDER_NAME__\"\nconst LOCALHOST_REGEX = /^((?<protocol>http[s]?):\\/\\/)?(?<host>localhost)(:(?<port>(\\d+|__\\w+__)))?$/\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 urlFromSubdomain(\n backendOrSubdomain: Pick<NhostClientConstructorParams, 'region' | 'subdomain' | 'backendUrl'>,\n service: string\n): string {\n const { backendUrl, subdomain, region } = backendOrSubdomain\n\n if (backendUrl) {\n return `${backendUrl}/v1/${service}`\n }\n\n if (!subdomain) {\n throw new Error('Either `backendUrl` or `subdomain` must be set.')\n }\n\n // check if subdomain is [http[s]://]localhost[:port]\n const subdomainLocalhostFound = subdomain.match(LOCALHOST_REGEX)\n if (subdomainLocalhostFound?.groups) {\n const { protocol = 'http', host, port = 1337 } = subdomainLocalhostFound.groups\n\n const urlFromEnv = getValueFromEnv(service)\n if (urlFromEnv) {\n return urlFromEnv\n }\n return `${protocol}://${host}:${port}/v1/${service}`\n }\n\n if (!region) {\n throw new Error('`region` must be set when using a `subdomain` other than \"localhost\".')\n }\n\n return `https://${subdomain}.${service}.${region}.nhost.run/v1`\n}\n\n/**\n *\n * @returns whether the code is running in a browser\n */\nfunction isBrowser(): boolean {\n return typeof window !== 'undefined'\n}\n\n/**\n *\n * @returns whether the code is running in a Node.js environment\n */\nfunction environmentIsAvailable() {\n return typeof process !== 'undefined' && process.env\n}\n\n/**\n *\n * @param service auth | storage | graphql | functions\n * @returns the service's url if the corresponding env var is set\n * NHOST_${service}_URL\n */\nfunction getValueFromEnv(service: string) {\n if (isBrowser() || !environmentIsAvailable()) {\n return null\n }\n\n return process.env[`NHOST_${service.toUpperCase()}_URL`]\n}\n","import { HasuraAuthClient } from '@nhost/hasura-auth-js'\n\nimport { urlFromSubdomain } from '../utils/helpers'\nimport { NhostClientConstructorParams } from '../utils/types'\n\n/**\n * Creates a client for Auth from either a subdomain or a URL\n */\nexport function createAuthClient(params: NhostClientConstructorParams) {\n const authUrl =\n 'subdomain' in params || 'backendUrl' in params\n ? urlFromSubdomain(params, 'auth')\n : params.authUrl\n\n if (!authUrl) {\n throw new Error('Please provide `subdomain` or `authUrl`.')\n }\n\n return new HasuraAuthClient({ url: authUrl, ...params })\n}\n","import axios, {\n AxiosError,\n AxiosInstance,\n AxiosRequestConfig,\n AxiosResponse,\n RawAxiosRequestHeaders\n} from 'axios'\nimport { urlFromSubdomain } from '../../utils/helpers'\nimport { NhostClientConstructorParams } from '../../utils/types'\nimport {\n DeprecatedNhostFunctionCallResponse,\n NhostFunctionCallConfig,\n NhostFunctionCallResponse,\n NhostFunctionsConstructorParams\n} from './types'\n\nexport * from './types'\n/**\n * Creates a client for Functions from either a subdomain or a URL\n */\nexport function createFunctionsClient(params: NhostClientConstructorParams) {\n const functionsUrl =\n 'subdomain' in params || 'backendUrl' in params\n ? urlFromSubdomain(params, 'functions')\n : params.functionsUrl\n\n if (!functionsUrl) {\n throw new Error('Please provide `subdomain` or `functionsUrl`.')\n }\n\n return new NhostFunctionsClient({ url: functionsUrl, ...params })\n}\n\n/**\n * @alias Functions\n */\nexport class NhostFunctionsClient {\n readonly url: string\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.url = url\n this.accessToken = null\n this.adminSecret = adminSecret\n this.instance = axios.create({\n baseURL: url\n })\n }\n\n /** @deprecated Axios will be replaced by cross-fetch in the near future. Only the headers configuration will be kept. */\n async call<T = unknown, D = any>(\n url: string,\n data?: D,\n config?: (NhostFunctionCallConfig | AxiosRequestConfig) & { useAxios?: true }\n ): Promise<DeprecatedNhostFunctionCallResponse<T>>\n\n async call<T = unknown, D = any>(\n url: string,\n data: D,\n config?: NhostFunctionCallConfig & { useAxios: false }\n ): Promise<NhostFunctionCallResponse<T>>\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 {\n useAxios = true,\n ...config\n }: (AxiosRequestConfig | NhostFunctionCallConfig) & { useAxios?: boolean } = {}\n ): Promise<DeprecatedNhostFunctionCallResponse<T> | NhostFunctionCallResponse> {\n if (useAxios) {\n console.warn(\n 'nhost.functions.call() will no longer use Axios in the near future. Please add `useAxios: false` in the config argument to use the new implementation.'\n )\n }\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 if (useAxios) {\n return { res: null, error }\n }\n const axiosError = error as AxiosError\n return {\n res: null,\n error: {\n error: axiosError.code || 'unknown',\n status: axiosError.status || 0,\n message: axiosError.message\n }\n }\n }\n }\n\n if (!res) {\n if (useAxios) {\n return {\n res: null,\n error: new Error('Unable to make post request to function')\n }\n }\n return {\n res: null,\n error: {\n error: 'invalid-response',\n status: 0,\n message: 'Unable to make post request to function'\n }\n }\n }\n\n if (useAxios) {\n return { res, error: null }\n }\n return {\n res: {\n status: res.status,\n statusText: res.statusText,\n data: res.data\n },\n error: null\n }\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(): RawAxiosRequestHeaders {\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, { AxiosError, AxiosInstance, AxiosRequestConfig } from 'axios'\nimport { DocumentNode, GraphQLError, print } from 'graphql'\nimport { urlFromSubdomain } from '../../utils/helpers'\nimport { NhostClientConstructorParams } from '../../utils/types'\nimport {\n DeprecatedNhostGraphqlRequestResponse,\n NhostGraphqlConstructorParams,\n NhostGraphqlRequestConfig,\n NhostGraphqlRequestResponse\n} from './types'\n\n/**\n * Creates a client for GraphQL from either a subdomain or a URL\n */\nexport function createGraphqlClient(params: NhostClientConstructorParams) {\n const graphqlUrl =\n 'subdomain' in params || 'backendUrl' in params\n ? urlFromSubdomain(params, 'graphql')\n : params.graphqlUrl\n\n if (!graphqlUrl) {\n throw new Error('Please provide `subdomain` or `graphqlUrl`.')\n }\n\n return new NhostGraphqlClient({ url: graphqlUrl, ...params })\n}\n\n/**\n * @alias GraphQL\n */\nexport class NhostGraphqlClient {\n readonly 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 /** @deprecated Axios will be replaced by cross-fetch in the near future. Only the headers configuration will be kept. */\n async request<T = any, V = any>(\n document: string | DocumentNode,\n variables?: V,\n config?: (AxiosRequestConfig | NhostGraphqlRequestConfig) & { useAxios?: true }\n ): Promise<DeprecatedNhostGraphqlRequestResponse<T>>\n\n async request<T = any, V = any>(\n document: string | DocumentNode,\n variables?: V,\n config?: NhostGraphqlRequestConfig & { useAxios: false }\n ): Promise<NhostGraphqlRequestResponse<T>>\n\n /**\n * Use `nhost.graphql.request` to send a GraphQL request. For more serious GraphQL usage we recommend using a GraphQL client such as Apollo Client (https://www.apollographql.com/docs/react).\n *\n * @example\n * ```ts\n * const CUSTOMERS = gql`\n * query {\n * customers {\n * id\n * name\n * }\n * }\n * `\n * const { data, error } = await nhost.graphql.request(CUSTOMERS)\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/graphql/request\n */\n async request<T = any, V = any>(\n document: string | DocumentNode,\n variables?: V,\n {\n useAxios = true,\n ...config\n }: (AxiosRequestConfig | NhostGraphqlRequestConfig) & { useAxios?: boolean } = {}\n ): Promise<DeprecatedNhostGraphqlRequestResponse<T> | NhostGraphqlRequestResponse<T>> {\n // add auth headers if any\n const headers = {\n 'Accept-Encoding': '*',\n ...this.generateAccessTokenHeaders(),\n ...config?.headers\n }\n\n try {\n const operationName = ''\n const res = await this.instance.post<{\n errors?: GraphQLError[]\n data?: T\n }>(\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 if (useAxios) {\n return {\n data: null,\n error: new Error('incorrect response data from GraphQL server')\n }\n }\n return {\n data: null,\n error: {\n error: 'invalid-response',\n status: 0,\n message: 'incorrect response data from GraphQL server'\n }\n }\n }\n\n return { data, error: null }\n } catch (error) {\n console.error(error)\n if (useAxios) {\n if (error instanceof Error) {\n return { data: null, error }\n }\n return {\n data: null,\n error: new Error('Unable to get do GraphQL request')\n }\n }\n\n const axiosError = error as AxiosError\n return {\n data: null,\n error: {\n error: axiosError.code || 'unknown',\n status: axiosError.status || 0,\n message: axiosError.message\n }\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(): Record<string, string> {\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 { HasuraStorageClient } from '@nhost/hasura-storage-js'\n\nimport { urlFromSubdomain } from '../utils/helpers'\nimport { NhostClientConstructorParams } from '../utils/types'\n\n/**\n * Creates a client for Storage from either a subdomain or a URL\n */\nexport function createStorageClient(params: NhostClientConstructorParams) {\n const storageUrl =\n 'subdomain' in params || 'backendUrl' in params\n ? urlFromSubdomain(params, 'storage')\n : params.storageUrl\n\n if (!storageUrl) {\n throw new Error('Please provide `subdomain` or `storageUrl`.')\n }\n\n return new HasuraStorageClient({ url: storageUrl, ...params })\n}\n","import { HasuraAuthClient } from '@nhost/hasura-auth-js'\nimport { HasuraStorageClient } from '@nhost/hasura-storage-js'\nimport { NhostClientConstructorParams } from '../utils/types'\nimport { createAuthClient } from './auth'\nimport { createFunctionsClient, NhostFunctionsClient } from './functions'\nimport { createGraphqlClient, NhostGraphqlClient } from './graphql'\nimport { createStorageClient } from './storage'\n\nexport const createNhostClient = (params: NhostClientConstructorParams) => new NhostClient(params)\nexport class NhostClient {\n auth: HasuraAuthClient\n storage: HasuraStorageClient\n functions: NhostFunctionsClient\n graphql: NhostGraphqlClient\n private _adminSecret?: string\n readonly devTools?: boolean\n\n /**\n * Nhost Client\n *\n * @example\n * ```ts\n * const nhost = new NhostClient({ subdomain, region });\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript\n */\n constructor({\n refreshIntervalTime,\n clientStorageGetter,\n clientStorageSetter,\n clientStorage,\n clientStorageType,\n autoRefreshToken,\n autoSignIn,\n adminSecret,\n devTools,\n start = true,\n ...urlParams\n }: NhostClientConstructorParams) {\n // * Set clients for all services\n this.auth = createAuthClient({\n refreshIntervalTime,\n clientStorageGetter,\n clientStorageSetter,\n clientStorage,\n clientStorageType,\n autoRefreshToken,\n autoSignIn,\n start,\n ...urlParams\n })\n this.storage = createStorageClient({ adminSecret, ...urlParams })\n this.functions = createFunctionsClient({ adminSecret, ...urlParams })\n this.graphql = createGraphqlClient({ adminSecret, ...urlParams })\n\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 const accessToken = session?.accessToken\n this.storage.setAccessToken(accessToken)\n this.functions.setAccessToken(accessToken)\n this.graphql.setAccessToken(accessToken)\n })\n\n this._adminSecret = adminSecret\n this.devTools = devTools\n }\n\n get adminSecret(): string | undefined {\n return this._adminSecret\n }\n\n set adminSecret(newValue: string | undefined) {\n this._adminSecret = newValue\n this.storage.setAdminSecret(newValue)\n // TODO inconsistent API: storage can change admin secret, but functions/graphql cannot\n // this.functions.setAdminSecret(newValue)\n // this.graphql.setAdminSecret(newValue)\n }\n}\n"],"names":["LOCALHOST_REGEX","urlFromSubdomain","backendOrSubdomain","service","backendUrl","subdomain","region","subdomainLocalhostFound","protocol","host","port","urlFromEnv","getValueFromEnv","isBrowser","environmentIsAvailable","createAuthClient","params","authUrl","HasuraAuthClient","createFunctionsClient","functionsUrl","NhostFunctionsClient","url","adminSecret","axios","data","useAxios","config","headers","res","error","axiosError","accessToken","createGraphqlClient","graphqlUrl","NhostGraphqlClient","document","variables","operationName","responseData","print","createStorageClient","storageUrl","HasuraStorageClient","createNhostClient","NhostClient","refreshIntervalTime","clientStorageGetter","clientStorageSetter","clientStorage","clientStorageType","autoRefreshToken","autoSignIn","devTools","start","urlParams","_event","session","newValue"],"mappings":";;;;;;AAGA,MAAMA,IAAkB;AAUR,SAAAC,EACdC,GACAC,GACQ;AACR,QAAM,EAAE,YAAAC,GAAY,WAAAC,GAAW,QAAAC,EAAA,IAAWJ;AAE1C,MAAIE;AACF,WAAO,GAAGA,QAAiBD;AAG7B,MAAI,CAACE;AACG,UAAA,IAAI,MAAM,iDAAiD;AAI7D,QAAAE,IAA0BF,EAAU,MAAML,CAAe;AAC/D,MAAIO,KAAA,QAAAA,EAAyB,QAAQ;AACnC,UAAM,EAAE,UAAAC,IAAW,QAAQ,MAAAC,GAAM,MAAAC,IAAO,SAASH,EAAwB,QAEnEI,IAAaC,EAAgBT,CAAO;AAC1C,WAAIQ,KAGG,GAAGH,OAAcC,KAAQC,QAAWP;AAAA,EAC7C;AAEA,MAAI,CAACG;AACG,UAAA,IAAI,MAAM,uEAAuE;AAGlF,SAAA,WAAWD,KAAaF,KAAWG;AAC5C;AAMA,SAASO,IAAqB;AAC5B,SAAO,OAAO,SAAW;AAC3B;AAMA,SAASC,IAAyB;AACzB,SAAA,OAAO,UAAY,OAAe,QAAQ;AACnD;AAQA,SAASF,EAAgBT,GAAiB;AACxC,SAAIU,EAAU,KAAK,CAACC,MACX,OAGF,QAAQ,IAAI,SAASX,EAAQ,YAAY;AAClD;AClEO,SAASY,EAAiBC,GAAsC;AAC/D,QAAAC,IACJ,eAAeD,KAAU,gBAAgBA,IACr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KAAK,UAAUtB,EAAoB,EAAE,aAAAV,GAAa,GAAGgC,GAAW,GAEhE,KAAK,KAAK,mBAAmB,CAACC,GAAQC,MAAY;AAChD,MAAID,MAAW,iBACR,KAAA,QAAQ,eAAe,MAAS,GAChC,KAAA,UAAU,eAAe,MAAS,GAClC,KAAA,QAAQ,eAAe,MAAS;AAAA,IACvC,CACD,GAGI,KAAA,KAAK,eAAe,CAACC,MAAY;AACpC,YAAMzB,IAAcyB,KAAA,gBAAAA,EAAS;AACxB,WAAA,QAAQ,eAAezB,CAAW,GAClC,KAAA,UAAU,eAAeA,CAAW,GACpC,KAAA,QAAQ,eAAeA,CAAW;AAAA,IAAA,CACxC,GAED,KAAK,eAAeT,GACpB,KAAK,WAAW8B;AAAA,EAClB;AAAA,EAEA,IAAI,cAAkC;AACpC,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,IAAI,YAAYK,GAA8B;AAC5C,SAAK,eAAeA,GACf,KAAA,QAAQ,eAAeA,CAAQ;AAAA,EAItC;AACF;"}
1
+ {"version":3,"file":"index.esm.js","sources":["../src/utils/helpers.ts","../src/clients/auth.ts","../src/clients/functions/index.ts","../src/clients/graphql.ts","../src/clients/storage.ts","../src/clients/nhost.ts"],"sourcesContent":["import { NhostClientConstructorParams } from './types'\n\n// a port can be a number or a placeholder string with leading and trailing double underscores, f.e. \"8080\" or \"__PLACEHOLDER_NAME__\"\nconst LOCALHOST_REGEX = /^((?<protocol>http[s]?):\\/\\/)?(?<host>localhost)(:(?<port>(\\d+|__\\w+__)))?$/\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 urlFromSubdomain(\n backendOrSubdomain: Pick<NhostClientConstructorParams, 'region' | 'subdomain' | 'backendUrl'>,\n service: string\n): string {\n const { backendUrl, subdomain, region } = backendOrSubdomain\n\n if (backendUrl) {\n return `${backendUrl}/v1/${service}`\n }\n\n if (!subdomain) {\n throw new Error('Either `backendUrl` or `subdomain` must be set.')\n }\n\n // check if subdomain is [http[s]://]localhost[:port]\n const subdomainLocalhostFound = subdomain.match(LOCALHOST_REGEX)\n if (subdomainLocalhostFound?.groups) {\n const { protocol = 'http', host, port = 1337 } = subdomainLocalhostFound.groups\n\n const urlFromEnv = getValueFromEnv(service)\n if (urlFromEnv) {\n return urlFromEnv\n }\n return `${protocol}://${host}:${port}/v1/${service}`\n }\n\n if (!region) {\n throw new Error('`region` must be set when using a `subdomain` other than \"localhost\".')\n }\n\n return `https://${subdomain}.${service}.${region}.nhost.run/v1`\n}\n\n/**\n *\n * @returns whether the code is running in a browser\n */\nfunction isBrowser(): boolean {\n return typeof window !== 'undefined'\n}\n\n/**\n *\n * @returns whether the code is running in a Node.js environment\n */\nfunction environmentIsAvailable() {\n return typeof process !== 'undefined' && process.env\n}\n\n/**\n *\n * @param service auth | storage | graphql | functions\n * @returns the service's url if the corresponding env var is set\n * NHOST_${service}_URL\n */\nfunction getValueFromEnv(service: string) {\n if (isBrowser() || !environmentIsAvailable()) {\n return null\n }\n\n return process.env[`NHOST_${service.toUpperCase()}_URL`]\n}\n","import { HasuraAuthClient } from '@nhost/hasura-auth-js'\n\nimport { urlFromSubdomain } from '../utils/helpers'\nimport { NhostClientConstructorParams } from '../utils/types'\n\n/**\n * Creates a client for Auth from either a subdomain or a URL\n */\nexport function createAuthClient(params: NhostClientConstructorParams) {\n const authUrl =\n 'subdomain' in params || 'backendUrl' in params\n ? urlFromSubdomain(params, 'auth')\n : params.authUrl\n\n if (!authUrl) {\n throw new Error('Please provide `subdomain` or `authUrl`.')\n }\n\n return new HasuraAuthClient({ url: authUrl, ...params })\n}\n","import fetch from 'cross-fetch'\nimport { urlFromSubdomain } from '../../utils/helpers'\nimport { NhostClientConstructorParams } from '../../utils/types'\nimport {\n NhostFunctionCallConfig,\n NhostFunctionCallResponse,\n NhostFunctionsConstructorParams\n} from './types'\n/**\n * Creates a client for Functions from either a subdomain or a URL\n */\nexport function createFunctionsClient(params: NhostClientConstructorParams) {\n const functionsUrl =\n 'subdomain' in params || 'backendUrl' in params\n ? urlFromSubdomain(params, 'functions')\n : params.functionsUrl\n\n if (!functionsUrl) {\n throw new Error('Please provide `subdomain` or `functionsUrl`.')\n }\n\n return new NhostFunctionsClient({ url: functionsUrl, ...params })\n}\n\n/**\n * @alias Functions\n */\nexport class NhostFunctionsClient {\n readonly url: string\n private accessToken: string | null\n private adminSecret?: string\n\n constructor(params: NhostFunctionsConstructorParams) {\n const { url, adminSecret } = params\n\n this.url = url\n this.accessToken = null\n this.adminSecret = adminSecret\n }\n\n async call<T = unknown, D = any>(\n url: string,\n data: D,\n config?: NhostFunctionCallConfig\n ): Promise<NhostFunctionCallResponse<T>>\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 body: D,\n config?: NhostFunctionCallConfig\n ): Promise<NhostFunctionCallResponse<T>> {\n const headers: HeadersInit = {\n 'Content-Type': 'application/json',\n ...this.generateAccessTokenHeaders(),\n ...config?.headers\n }\n\n try {\n const result = await fetch(url, {\n body: JSON.stringify(body),\n headers,\n method: 'POST'\n })\n if (!result.ok) {\n throw new Error(result.statusText)\n }\n let data: T\n try {\n data = await result.json()\n } catch {\n data = (await result.text()) as unknown as T\n }\n return {\n res: { data, status: result.status, statusText: result.statusText },\n error: null\n }\n } catch (e) {\n const error = e as Error\n return {\n res: null,\n error: {\n message: error.message,\n status: error.name === 'AbortError' ? 0 : 500,\n error: error.name === 'AbortError' ? 'abort-error' : 'unknown'\n }\n }\n }\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(): NhostFunctionCallConfig['headers'] {\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 { GenericSchema, NhostGraphqlClient } from '@nhost/graphql-js'\nimport { urlFromSubdomain } from '../utils/helpers'\nimport { NhostClientConstructorParams } from '../utils/types'\n\n/**\n * Creates a client for GraphQL from either a subdomain or a URL\n */\nexport function createGraphqlClient<Schema extends GenericSchema | undefined>(\n params: NhostClientConstructorParams<Schema>\n) {\n const graphqlUrl =\n 'subdomain' in params || 'backendUrl' in params\n ? urlFromSubdomain(params, 'graphql')\n : params.graphqlUrl\n\n if (!graphqlUrl) {\n throw new Error('Please provide `subdomain` or `graphqlUrl`.')\n }\n\n return new NhostGraphqlClient({ url: graphqlUrl, ...params })\n}\n","import { HasuraStorageClient } from '@nhost/hasura-storage-js'\n\nimport { urlFromSubdomain } from '../utils/helpers'\nimport { NhostClientConstructorParams } from '../utils/types'\n\n/**\n * Creates a client for Storage from either a subdomain or a URL\n */\nexport function createStorageClient(params: NhostClientConstructorParams<undefined>) {\n const storageUrl =\n 'subdomain' in params || 'backendUrl' in params\n ? urlFromSubdomain(params, 'storage')\n : params.storageUrl\n\n if (!storageUrl) {\n throw new Error('Please provide `subdomain` or `storageUrl`.')\n }\n\n return new HasuraStorageClient({ url: storageUrl, ...params })\n}\n","import { GenericSchema, NhostGraphqlClient } from '@nhost/graphql-js'\nimport { HasuraAuthClient } from '@nhost/hasura-auth-js'\nimport { HasuraStorageClient } from '@nhost/hasura-storage-js'\nimport { NhostClientConstructorParams } from '../utils/types'\nimport { createAuthClient } from './auth'\nimport { createFunctionsClient, NhostFunctionsClient } from './functions'\nimport { createGraphqlClient } from './graphql'\nimport { createStorageClient } from './storage'\n\nexport const createNhostClient = <Schema extends GenericSchema | undefined = undefined>(\n params: NhostClientConstructorParams<Schema>\n) => new NhostClient(params)\n\nexport class NhostClient<Schema extends GenericSchema | undefined = undefined> {\n auth: HasuraAuthClient\n storage: HasuraStorageClient\n functions: NhostFunctionsClient\n graphql: NhostGraphqlClient<Schema>\n private _adminSecret?: string\n readonly devTools?: boolean\n\n /**\n * Nhost Client\n *\n * @example\n * ```ts\n * const nhost = new NhostClient({ subdomain, region });\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript\n */\n constructor({\n refreshIntervalTime,\n clientStorage,\n clientStorageType,\n autoRefreshToken,\n autoSignIn,\n adminSecret,\n devTools,\n start = true,\n schema,\n ...urlParams\n }: NhostClientConstructorParams<Schema>) {\n // * Set clients for all services\n this.auth = createAuthClient({\n refreshIntervalTime,\n clientStorage,\n clientStorageType,\n autoRefreshToken,\n autoSignIn,\n start,\n ...urlParams\n })\n this.storage = createStorageClient({ adminSecret, ...urlParams })\n this.functions = createFunctionsClient({ adminSecret, ...urlParams })\n this.graphql = createGraphqlClient({ adminSecret, schema, ...urlParams })\n\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 const accessToken = session?.accessToken\n this.storage.setAccessToken(accessToken)\n this.functions.setAccessToken(accessToken)\n this.graphql.setAccessToken(accessToken)\n })\n\n this._adminSecret = adminSecret\n this.devTools = devTools\n }\n\n get adminSecret(): string | undefined {\n return this._adminSecret\n }\n\n set adminSecret(newValue: string | undefined) {\n this._adminSecret = newValue\n this.storage.setAdminSecret(newValue)\n // TODO inconsistent API: storage can change admin secret, but functions/graphql cannot\n // this.functions.setAdminSecret(newValue)\n // this.graphql.setAdminSecret(newValue)\n }\n}\n"],"names":["LOCALHOST_REGEX","urlFromSubdomain","backendOrSubdomain","service","backendUrl","subdomain","region","subdomainLocalhostFound","protocol","host","port","urlFromEnv","getValueFromEnv","isBrowser","environmentIsAvailable","createAuthClient","params","authUrl","HasuraAuthClient","createFunctionsClient","functionsUrl","NhostFunctionsClient","url","adminSecret","body","config","headers","result","fetch","data","e","error","accessToken","createGraphqlClient","graphqlUrl","NhostGraphqlClient","createStorageClient","storageUrl","HasuraStorageClient","createNhostClient","NhostClient","refreshIntervalTime","clientStorage","clientStorageType","autoRefreshToken","autoSignIn","devTools","start","schema","urlParams","_event","session","newValue"],"mappings":";;;;;;AAGA,MAAMA,IAAkB;AAUR,SAAAC,EACdC,GACAC,GACQ;AACR,QAAM,EAAE,YAAAC,GAAY,WAAAC,GAAW,QAAAC,EAAA,IAAWJ;AAE1C,MAAIE;AACF,WAAO,GAAGA,QAAiBD;AAG7B,MAAI,CAACE;AACG,UAAA,IAAI,MAAM,iDAAiD;AAI7D,QAAAE,IAA0BF,EAAU,MAAML,CAAe;AAC/D,MAAIO,KAAA,QAAAA,EAAyB,QAAQ;AACnC,UAAM,EAAE,UAAAC,IAAW,QAAQ,MAAAC,GAAM,MAAAC,IAAO,SAASH,EAAwB,QAEnEI,IAAaC,EAAgBT,CAAO;AAC1C,WAAIQ,KAGG,GAAGH,OAAcC,KAAQC,QAAWP;AAAA,EAC7C;AAEA,MAAI,CAACG;AACG,UAAA,IAAI,MAAM,uEAAuE;AAGlF,SAAA,WAAWD,KAAaF,KAAWG;AAC5C;AAMA,SAASO,IAAqB;AAC5B,SAAO,OAAO,SAAW;AAC3B;AAMA,SAASC,IAAyB;AACzB,SAAA,OAAO,UAAY,OAAe,QAAQ;AACnD;AAQA,SAASF,EAAgBT,GAAiB;AACxC,SAAIU,EAAU,KAAK,CAACC,MACX,OAGF,QAAQ,IAAI,SAASX,EAAQ,YAAY;AAClD;AClEO,SAASY,EAAiBC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AAC;AAAA,OACGC;AAAA,EAAA,GACoC;AAEvC,SAAK,OAAOlC,EAAiB;AAAA,MAC3B,qBAAA0B;AAAA,MACA,eAAAC;AAAA,MACA,mBAAAC;AAAA,MACA,kBAAAC;AAAA,MACA,YAAAC;AAAA,MACA,OAAAE;AAAA,MACA,GAAGE;AAAA,IAAA,CACJ,GACD,KAAK,UAAUb,EAAoB,EAAE,aAAAb,GAAa,GAAG0B,GAAW,GAChE,KAAK,YAAY9B,EAAsB,EAAE,aAAAI,GAAa,GAAG0B,GAAW,GACpE,KAAK,UAAUhB,EAAoB,EAAE,aAAAV,GAAa,QAAAyB,GAAQ,GAAGC,GAAW,GAExE,KAAK,KAAK,mBAAmB,CAACC,GAAQC,MAAY;AAChD,MAAID,MAAW,iBACR,KAAA,QAAQ,eAAe,MAAS,GAChC,KAAA,UAAU,eAAe,MAAS,GAClC,KAAA,QAAQ,eAAe,MAAS;AAAA,IACvC,CACD,GAGI,KAAA,KAAK,eAAe,CAACC,MAAY;AACpC,YAAMnB,IAAcmB,KAAA,gBAAAA,EAAS;AACxB,WAAA,QAAQ,eAAenB,CAAW,GAClC,KAAA,UAAU,eAAeA,CAAW,GACpC,KAAA,QAAQ,eAAeA,CAAW;AAAA,IAAA,CACxC,GAED,KAAK,eAAeT,GACpB,KAAK,WAAWuB;AAAA,EAClB;AAAA,EAEA,IAAI,cAAkC;AACpC,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,IAAI,YAAYM,GAA8B;AAC5C,SAAK,eAAeA,GACf,KAAA,QAAQ,eAAeA,CAAQ;AAAA,EAItC;AACF;"}
@@ -1,3 +1,4 @@
1
+ import { GenericSchema } from '@nhost/graphql-js';
1
2
  import { NhostAuthConstructorParams } from '@nhost/hasura-auth-js';
2
3
  export declare type ErrorPayload = {
3
4
  error: string;
@@ -35,7 +36,8 @@ export declare type ServiceUrls = {
35
36
  functionsUrl?: string;
36
37
  };
37
38
  export declare type BackendOrSubdomain = BackendUrl | Subdomain;
38
- export interface NhostClientConstructorParams extends Partial<BackendUrl>, Partial<Subdomain>, Partial<ServiceUrls>, Omit<NhostAuthConstructorParams, 'url'> {
39
+ export interface NhostClientConstructorParams<Schema extends GenericSchema | undefined = undefined> extends Partial<BackendUrl>, Partial<Subdomain>, Partial<ServiceUrls>, Omit<NhostAuthConstructorParams, 'url'> {
40
+ schema?: Schema;
39
41
  /**
40
42
  * When set, the admin secret is sent as a header, `x-hasura-admin-secret`,
41
43
  * for all requests to GraphQL, Storage, and Serverless Functions.
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,uBAAuB,CAAA;AAElE,oBAAY,YAAY,GAAG;IACzB,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,oBAAY,UAAU,GAAG;IACvB;;;OAGG;IACH,UAAU,EAAE,MAAM,CAAA;CACnB,CAAA;AAED,oBAAY,SAAS,GAAG;IACtB;;;OAGG;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,WAAW,GAAG;IACxB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB,CAAA;AAED,oBAAY,kBAAkB,GAAG,UAAU,GAAG,SAAS,CAAA;AAEvD,MAAM,WAAW,4BACf,SAAQ,OAAO,CAAC,UAAU,CAAC,EACzB,OAAO,CAAC,SAAS,CAAC,EAClB,OAAO,CAAC,WAAW,CAAC,EACpB,IAAI,CAAC,0BAA0B,EAAE,KAAK,CAAC;IACzC;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACjD,OAAO,EAAE,0BAA0B,EAAE,MAAM,uBAAuB,CAAA;AAElE,oBAAY,YAAY,GAAG;IACzB,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,oBAAY,UAAU,GAAG;IACvB;;;OAGG;IACH,UAAU,EAAE,MAAM,CAAA;CACnB,CAAA;AAED,oBAAY,SAAS,GAAG;IACtB;;;OAGG;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,WAAW,GAAG;IACxB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB,CAAA;AAED,oBAAY,kBAAkB,GAAG,UAAU,GAAG,SAAS,CAAA;AAEvD,MAAM,WAAW,4BAA4B,CAAC,MAAM,SAAS,aAAa,GAAG,SAAS,GAAG,SAAS,CAChG,SAAQ,OAAO,CAAC,UAAU,CAAC,EACzB,OAAO,CAAC,SAAS,CAAC,EAClB,OAAO,CAAC,WAAW,CAAC,EACpB,IAAI,CAAC,0BAA0B,EAAE,KAAK,CAAC;IACzC,MAAM,CAAC,EAAE,MAAM,CAAA;IACf;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nhost/nhost-js",
3
- "version": "1.13.4",
3
+ "version": "2.0.0",
4
4
  "description": "Nhost JavaScript SDK",
5
5
  "license": "MIT",
6
6
  "keywords": [
@@ -43,16 +43,14 @@
43
43
  "access": "public"
44
44
  },
45
45
  "dependencies": {
46
- "axios": "^1.2.0",
47
- "jwt-decode": "^3.1.2",
48
- "@nhost/hasura-auth-js": "1.12.4",
49
- "@nhost/hasura-storage-js": "1.13.2"
46
+ "cross-fetch": "^3.1.5",
47
+ "@nhost/hasura-auth-js": "2.0.0",
48
+ "@nhost/hasura-storage-js": "2.0.0",
49
+ "@nhost/graphql-js": "0.0.1"
50
50
  },
51
51
  "devDependencies": {
52
- "@faker-js/faker": "^7.6.0",
53
52
  "graphql": "16.6.0",
54
- "start-server-and-test": "^1.15.2",
55
- "@nhost/docgen": "0.1.6"
53
+ "start-server-and-test": "^1.15.2"
56
54
  },
57
55
  "peerDependencies": {
58
56
  "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
@@ -64,17 +62,12 @@
64
62
  "build:umd": "vite build --config ../../config/vite.lib.umd.config.js",
65
63
  "test": "vitest run",
66
64
  "test:watch": "vitest",
67
- "e2e": "start-test e2e:backend http-get://localhost:9695 ci:test",
68
- "ci:test": "vitest run --config vite.config.e2e.js",
69
- "e2e:backend": "nhost dev --no-browser",
70
65
  "test:coverage": "vitest run --coverage",
71
66
  "prettier": "prettier --check src/",
72
67
  "prettier:fix": "prettier --write src/",
73
68
  "lint": "eslint . --ext .ts,.tsx",
74
69
  "lint:fix": "eslint . --ext .ts,.tsx --fix",
75
70
  "verify": "run-p prettier lint",
76
- "verify:fix": "run-p prettier:fix lint:fix",
77
- "typedoc": "typedoc --options ./nhost-js.typedoc.json --tsconfig ./typedoc.tsconfig.json",
78
- "docgen": "pnpm typedoc && docgen --config ./nhost-js.docgen.json"
71
+ "verify:fix": "run-p prettier:fix lint:fix"
79
72
  }
80
73
  }