@nhost/nhost-js 3.1.1 → 3.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,13 +13,30 @@ export declare class NhostClient {
13
13
  private _adminSecret?;
14
14
  readonly devTools?: boolean;
15
15
  /**
16
- * Nhost Client
17
16
  *
18
17
  * @example
19
18
  * ```ts
19
+ * // Create a new Nhost client from subdomain and region.
20
20
  * const nhost = new NhostClient({ subdomain, region });
21
21
  * ```
22
22
  *
23
+ *
24
+ * ```ts
25
+ * // Create a new Nhost client from individual service URLs (custom domains, self-hosting, etc).
26
+ * const nhost = new NhostClient({
27
+ * authUrl: "my-auth-service-url",
28
+ * storageUrl: "my-storage-service-url",
29
+ * graphqlUrl: "my-graphql-service-url",
30
+ * functionsUrl: "my-functions-service-url",
31
+ * });
32
+ * ```
33
+ *
34
+ *
35
+ * ```ts
36
+ * // Create a new Nhost client for local development.
37
+ * const nhost = new NhostClient({ subdomain: "local" });
38
+ * ```
39
+ *
23
40
  * @docs https://docs.nhost.io/reference/javascript
24
41
  */
25
42
  constructor({ refreshIntervalTime, clientStorage, clientStorageType, autoRefreshToken, autoSignIn, adminSecret, devTools, start, ...urlParams }: NhostClientConstructorParams);
@@ -44,7 +61,7 @@ export declare class NhostClient {
44
61
  * nhost.setRole('admin')
45
62
  * ```
46
63
  *
47
- * @docs https://docs.nhost.io/reference/javascript/set-role
64
+ * @docs https://docs.nhost.io/reference/javascript/nhost-js/set-role
48
65
  */
49
66
  setRole(role: string): void;
50
67
  /**
@@ -56,10 +73,10 @@ export declare class NhostClient {
56
73
  *
57
74
  * @example
58
75
  * ```ts
59
- * nhost.unsetRole('admin')
76
+ * nhost.unsetRole()
60
77
  * ```
61
78
  *
62
- * @docs https://docs.nhost.io/reference/javascript/set-role
79
+ * @docs https://docs.nhost.io/reference/javascript/nhost-js/unset-role
63
80
  */
64
81
  unsetRole(): void;
65
82
  }
@@ -1 +1 @@
1
- {"version":3,"file":"nhost.d.ts","sourceRoot":"","sources":["../../src/clients/nhost.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AACxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAC9D,OAAO,EAAE,4BAA4B,EAAE,MAAM,gBAAgB,CAAA;AAE7D,OAAO,EAAyB,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAIzE,eAAO,MAAM,iBAAiB,WAAY,4BAA4B,gBAA4B,CAAA;AAElG,qBAAa,WAAW;IACtB,IAAI,EAAE,gBAAgB,CAAA;IACtB,OAAO,EAAE,mBAAmB,CAAA;IAC5B,SAAS,EAAE,oBAAoB,CAAA;IAC/B,OAAO,EAAE,kBAAkB,CAAA;IAC3B,OAAO,CAAC,YAAY,CAAC,CAAQ;IAC7B,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;IAE3B;;;;;;;;;OASG;gBACS,EACV,mBAAmB,EACnB,aAAa,EACb,iBAAiB,EACjB,gBAAgB,EAChB,UAAU,EACV,WAAW,EACX,QAAQ,EACR,KAAY,EACZ,GAAG,SAAS,EACb,EAAE,4BAA4B;IA0C/B,IAAI,WAAW,IAAI,MAAM,GAAG,SAAS,CAEpC;IAED,IAAI,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,EAM3C;IAED;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM;IAMpB;;;;;;;;;;;;;OAaG;IACH,SAAS;CAOV"}
1
+ {"version":3,"file":"nhost.d.ts","sourceRoot":"","sources":["../../src/clients/nhost.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AACxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAC9D,OAAO,EAAE,4BAA4B,EAAE,MAAM,gBAAgB,CAAA;AAE7D,OAAO,EAAyB,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAIzE,eAAO,MAAM,iBAAiB,WAAY,4BAA4B,gBAA4B,CAAA;AAElG,qBAAa,WAAW;IACtB,IAAI,EAAE,gBAAgB,CAAA;IACtB,OAAO,EAAE,mBAAmB,CAAA;IAC5B,SAAS,EAAE,oBAAoB,CAAA;IAC/B,OAAO,EAAE,kBAAkB,CAAA;IAC3B,OAAO,CAAC,YAAY,CAAC,CAAQ;IAC7B,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;IAE3B;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;gBACS,EACV,mBAAmB,EACnB,aAAa,EACb,iBAAiB,EACjB,gBAAgB,EAChB,UAAU,EACV,WAAW,EACX,QAAQ,EACR,KAAY,EACZ,GAAG,SAAS,EACb,EAAE,4BAA4B;IA0C/B,IAAI,WAAW,IAAI,MAAM,GAAG,SAAS,CAEpC;IAED,IAAI,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,EAM3C;IAED;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM;IAMpB;;;;;;;;;;;;;OAaG;IACH,SAAS;CAOV"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs.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__\"\nexport const LOCALHOST_REGEX =\n /^((?<protocol>http[s]?):\\/\\/)?(?<host>(localhost|local))(:(?<port>(\\d+|__\\w+__)))?$/\n\n/**\n * \\`subdomain\\` and `region` should be used when running the Nhost platform\n *\n * @param subdomainAndRegion\n * @param service\n * @returns\n */\nexport function urlFromSubdomain(\n subdomainAndRegion: Pick<NhostClientConstructorParams, 'region' | 'subdomain'>,\n service: string\n): string {\n const { subdomain, region } = subdomainAndRegion\n\n if (!subdomain) {\n throw new Error('A `subdomain` must be set.')\n }\n\n // check if subdomain is [http[s]://]localhost[:port] or [http[s]://]local[:port]\n const subdomainLocalhostFound = subdomain.match(LOCALHOST_REGEX)\n if (subdomainLocalhostFound?.groups) {\n const { protocol, host, port } = subdomainLocalhostFound.groups\n\n const urlFromEnv = getValueFromEnv(service)\n if (urlFromEnv) {\n return urlFromEnv\n }\n\n if (host === 'localhost') {\n console.warn(\n 'The `subdomain` is set to \"localhost\". Support for this will be removed in a future release. Please use \"local\" instead.'\n )\n\n return `${protocol || 'http'}://localhost:${port || 1337}/v1/${service}`\n }\n\n return port\n ? `${protocol || 'https'}://local.${service}.nhost.run:${port}/v1`\n : `${protocol || 'https'}://local.${service}.nhost.run/v1`\n }\n\n if (!region) {\n throw new Error('`region` must be set when using a `subdomain` other than \"local\".')\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\n/**\n * Combines a base URL and a path into a single URL string.\n *\n * @param baseUrl - The base URL to use.\n * @param path - The path to append to the base URL.\n * @returns The combined URL string.\n */\nexport function buildUrl(baseUrl: string, path: string) {\n const hasLeadingSlash = path.startsWith('/')\n const urlPath = hasLeadingSlash ? path : `/${path}`\n return baseUrl + urlPath\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 = 'subdomain' in params ? urlFromSubdomain(params, 'auth') : 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 'isomorphic-unfetch'\nimport { buildUrl, 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 ? urlFromSubdomain(params, 'functions') : 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 private headers: Record<string, 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 /**\n * Use `nhost.functions.call` to call (sending a POST request to) a serverless function. Use generic\n * types to specify the expected response data, request body and error message.\n *\n * @example\n * ### Without generic types\n * ```ts\n * await nhost.functions.call('send-welcome-email', { email: 'joe@example.com', name: 'Joe Doe' })\n * ```\n *\n * @example\n * ### Using generic types\n * ```ts\n * type Data = {\n * message: string\n * }\n *\n * type Body = {\n * email: string\n * name: string\n * }\n *\n * type ErrorMessage = {\n * details: string\n * }\n *\n * // The function will only accept a body of type `Body`\n * const { res, error } = await nhost.functions.call<Data, Body, ErrorMessage>(\n * 'send-welcome-email',\n * { email: 'joe@example.com', name: 'Joe Doe' }\n * )\n *\n * // Now the response data is typed as `Data`\n * console.log(res?.data.message)\n *\n * // Now the error message is typed as `ErrorMessage`\n * console.log(error?.message.details)\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/functions/call\n */\n async call<TData = unknown, TBody = any, TErrorMessage = any>(\n url: string,\n body?: TBody | null,\n config?: NhostFunctionCallConfig\n ): Promise<NhostFunctionCallResponse<TData, TErrorMessage>> {\n const headers: HeadersInit = {\n 'Content-Type': 'application/json',\n ...this.generateAccessTokenHeaders(),\n ...config?.headers,\n ...this.headers // nhost functions client headers to be sent with all calls\n }\n\n const fullUrl = buildUrl(this.url, url)\n\n try {\n const result = await fetch(fullUrl, {\n body: body ? JSON.stringify(body) : null,\n headers,\n method: 'POST'\n })\n\n if (!result.ok) {\n let message: TErrorMessage\n\n if (result.headers.get('content-type')?.includes('application/json')) {\n message = await result.json()\n } else {\n message = (await result.text()) as unknown as TErrorMessage\n }\n\n return {\n res: null,\n error: {\n message,\n error: result.statusText,\n status: result.status\n }\n }\n }\n\n let data: TData\n\n if (result.headers.get('content-type')?.includes('application/json')) {\n data = await result.json()\n } else {\n data = (await result.text()) as unknown as TData\n }\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 as unknown as TErrorMessage,\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 /**\n * Use `nhost.functions.getHeaders` to get the global headers sent with all functions requests.\n *\n * @example\n * ```ts\n * nhost.functions.getHeaders()\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/functions/get-headers\n */\n getHeaders(): Record<string, string> {\n return this.headers\n }\n\n /**\n * Use `nhost.functions.setHeaders` to a set global headers to be sent in all subsequent functions requests.\n *\n * @example\n * ```ts\n * nhost.functions.setHeaders({\n * 'x-hasura-role': 'admin'\n * })\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/functions/set-headers\n */\n setHeaders(headers?: Record<string, string>) {\n if (!headers) {\n return\n }\n\n this.headers = {\n ...this.headers,\n ...headers\n }\n }\n\n /**\n * Use `nhost.functions.unsetHeaders` to a unset global headers sent with all functions requests.\n *\n * @example\n * ```ts\n * nhost.functions.unsetHeaders()\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/functions/unset-headers\n */\n unsetHeaders() {\n const userRole = this.headers['x-hasura-role']\n\n // preserve the user role header to avoid invalidating preceding 'setRole' call.\n this.headers = userRole ? { 'x-hasura-role': userRole } : {}\n }\n\n 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 { 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(params: NhostClientConstructorParams) {\n const graphqlUrl = 'subdomain' in params ? urlFromSubdomain(params, 'graphql') : 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) {\n const storageUrl = 'subdomain' in params ? urlFromSubdomain(params, 'storage') : 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 { 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 = (params: NhostClientConstructorParams) => new NhostClient(params)\n\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 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 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 return\n }\n\n const accessToken = session?.accessToken\n this.storage.setAccessToken(accessToken)\n this.functions.setAccessToken(accessToken)\n this.graphql.setAccessToken(accessToken)\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 /**\n * Use `nhost.setRole` to set the user role for all subsequent GraphQL, storage, and functions calls.\n * Underneath, this method sets the `x-hasura-role` header on the graphql, storage,\n * and functions clients.\n *\n * ```ts\n * nhost.graphql.setHeaders({ 'x-hasura-role': role })\n * nhost.storage.setHeaders({ 'x-hasura-role': role })\n * nhost.functions.setHeaders({ 'x-hasura-role': role })\n * ```\n *\n * Note: Exercise caution when mixing the use of `setRole` along with `setHeaders` when setting the\n * `x-hasura-role` header, as the last call will override any previous ones.\n *\n * @example\n * ```ts\n * nhost.setRole('admin')\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/set-role\n */\n setRole(role: string) {\n this.graphql.setHeaders({ 'x-hasura-role': role })\n this.storage.setHeaders({ 'x-hasura-role': role })\n this.functions.setHeaders({ 'x-hasura-role': role })\n }\n\n /**\n * Use `nhost.unsetRole` to unset the user role for all subsequent graphql, storage and functions calls.\n * Underneath, this method removes the `x-hasura-role` header from the graphql, storage and functions clients.\n *\n * Note: Exercise caution when mixing the use of `unsetRole` along with `setHeaders` when setting the\n * `x-hasura-role` header, as the last call will override any previous ones.\n *\n * @example\n * ```ts\n * nhost.unsetRole('admin')\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/set-role\n */\n unsetRole() {\n this.graphql.setHeaders((({ 'x-hasura-role': _, ...rest }) => rest)(this.graphql.getHeaders()))\n this.storage.setHeaders((({ 'x-hasura-role': _, ...rest }) => rest)(this.storage.getHeaders()))\n this.functions.setHeaders(\n (({ 'x-hasura-role': _, ...rest }) => rest)(this.functions.getHeaders())\n )\n }\n}\n"],"names":["LOCALHOST_REGEX","urlFromSubdomain","subdomainAndRegion","service","subdomain","region","subdomainLocalhostFound","protocol","host","port","urlFromEnv","getValueFromEnv","isBrowser","environmentIsAvailable","buildUrl","baseUrl","path","urlPath","createAuthClient","params","authUrl","HasuraAuthClient","createFunctionsClient","functionsUrl","NhostFunctionsClient","url","adminSecret","body","config","headers","fullUrl","result","fetch","message","_a","data","_b","e","error","accessToken","userRole","createGraphqlClient","graphqlUrl","NhostGraphqlClient","createStorageClient","storageUrl","HasuraStorageClient","createNhostClient","NhostClient","refreshIntervalTime","clientStorage","clientStorageType","autoRefreshToken","autoSignIn","devTools","start","urlParams","event","session","newValue","role","_","rest"],"mappings":"8NAGaA,EACX,sFASc,SAAAC,EACdC,EACAC,EACQ,CACF,KAAA,CAAE,UAAAC,EAAW,OAAAC,CAAW,EAAAH,EAE9B,GAAI,CAACE,EACG,MAAA,IAAI,MAAM,4BAA4B,EAIxC,MAAAE,EAA0BF,EAAU,MAAMJ,CAAe,EAC/D,GAAIM,GAAA,MAAAA,EAAyB,OAAQ,CACnC,KAAM,CAAE,SAAAC,EAAU,KAAAC,EAAM,KAAAC,CAAA,EAASH,EAAwB,OAEnDI,EAAaC,EAAgBR,CAAO,EAC1C,OAAIO,IAIAF,IAAS,aACH,QAAA,KACN,0HAAA,EAGK,GAAGD,GAAY,MAAM,gBAAgBE,GAAQ,IAAI,OAAON,CAAO,IAGjEM,EACH,GAAGF,GAAY,OAAO,YAAYJ,CAAO,cAAcM,CAAI,MAC3D,GAAGF,GAAY,OAAO,YAAYJ,CAAO,gBAC/C,C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AAS,EAClC,KAAA,QAAQ,eAAe,MAAS,EAErC,MACF,CAEA,MAAMlB,EAAcmB,GAAA,YAAAA,EAAS,YACxB,KAAA,QAAQ,eAAenB,CAAW,EAClC,KAAA,UAAU,eAAeA,CAAW,EACpC,KAAA,QAAQ,eAAeA,CAAW,CAAA,CACxC,EAGI,KAAA,KAAK,eAAgBmB,GAAY,CACpC,MAAMnB,EAAcmB,GAAA,YAAAA,EAAS,YACxB,KAAA,QAAQ,eAAenB,CAAW,EAClC,KAAA,UAAU,eAAeA,CAAW,EACpC,KAAA,QAAQ,eAAeA,CAAW,CAAA,CACxC,EAED,KAAK,aAAeb,EACpB,KAAK,SAAW4B,CAClB,CAEA,IAAI,aAAkC,CACpC,OAAO,KAAK,YACd,CAEA,IAAI,YAAYK,EAA8B,CAC5C,KAAK,aAAeA,EACf,KAAA,QAAQ,eAAeA,CAAQ,CAItC,CAuBA,QAAQC,EAAc,CACpB,KAAK,QAAQ,WAAW,CAAE,gBAAiBA,CAAM,CAAA,EACjD,KAAK,QAAQ,WAAW,CAAE,gBAAiBA,CAAM,CAAA,EACjD,KAAK,UAAU,WAAW,CAAE,gBAAiBA,CAAM,CAAA,CACrD,CAgBA,WAAY,CACV,KAAK,QAAQ,YAAY,CAAC,CAAE,gBAAiBC,EAAG,GAAGC,CAAK,IAAMA,GAAM,KAAK,QAAQ,WAAA,CAAY,CAAC,EAC9F,KAAK,QAAQ,YAAY,CAAC,CAAE,gBAAiBD,EAAG,GAAGC,CAAK,IAAMA,GAAM,KAAK,QAAQ,WAAA,CAAY,CAAC,EAC9F,KAAK,UAAU,YACZ,CAAC,CAAE,gBAAiBD,EAAG,GAAGC,KAAWA,GAAM,KAAK,UAAU,YAAY,CAAA,CAE3E,CACF"}
1
+ {"version":3,"file":"index.cjs.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__\"\nexport const LOCALHOST_REGEX =\n /^((?<protocol>http[s]?):\\/\\/)?(?<host>(localhost|local))(:(?<port>(\\d+|__\\w+__)))?$/\n\n/**\n * \\`subdomain\\` and `region` should be used when running the Nhost platform\n *\n * @param subdomainAndRegion\n * @param service\n * @returns\n */\nexport function urlFromSubdomain(\n subdomainAndRegion: Pick<NhostClientConstructorParams, 'region' | 'subdomain'>,\n service: string\n): string {\n const { subdomain, region } = subdomainAndRegion\n\n if (!subdomain) {\n throw new Error('A `subdomain` must be set.')\n }\n\n // check if subdomain is [http[s]://]localhost[:port] or [http[s]://]local[:port]\n const subdomainLocalhostFound = subdomain.match(LOCALHOST_REGEX)\n if (subdomainLocalhostFound?.groups) {\n const { protocol, host, port } = subdomainLocalhostFound.groups\n\n const urlFromEnv = getValueFromEnv(service)\n if (urlFromEnv) {\n return urlFromEnv\n }\n\n if (host === 'localhost') {\n console.warn(\n 'The `subdomain` is set to \"localhost\". Support for this will be removed in a future release. Please use \"local\" instead.'\n )\n\n return `${protocol || 'http'}://localhost:${port || 1337}/v1/${service}`\n }\n\n return port\n ? `${protocol || 'https'}://local.${service}.nhost.run:${port}/v1`\n : `${protocol || 'https'}://local.${service}.nhost.run/v1`\n }\n\n if (!region) {\n throw new Error('`region` must be set when using a `subdomain` other than \"local\".')\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\n/**\n * Combines a base URL and a path into a single URL string.\n *\n * @param baseUrl - The base URL to use.\n * @param path - The path to append to the base URL.\n * @returns The combined URL string.\n */\nexport function buildUrl(baseUrl: string, path: string) {\n const hasLeadingSlash = path.startsWith('/')\n const urlPath = hasLeadingSlash ? path : `/${path}`\n return baseUrl + urlPath\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 = 'subdomain' in params ? urlFromSubdomain(params, 'auth') : 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 'isomorphic-unfetch'\nimport { buildUrl, 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 ? urlFromSubdomain(params, 'functions') : 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 private headers: Record<string, 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 /**\n * Use `nhost.functions.call` to call (sending a POST request to) a serverless function. Use generic\n * types to specify the expected response data, request body and error message.\n *\n * @example\n * ### Without generic types\n * ```ts\n * await nhost.functions.call('send-welcome-email', { email: 'joe@example.com', name: 'Joe Doe' })\n * ```\n *\n * @example\n * ### Using generic types\n * ```ts\n * type Data = {\n * message: string\n * }\n *\n * type Body = {\n * email: string\n * name: string\n * }\n *\n * type ErrorMessage = {\n * details: string\n * }\n *\n * // The function will only accept a body of type `Body`\n * const { res, error } = await nhost.functions.call<Data, Body, ErrorMessage>(\n * 'send-welcome-email',\n * { email: 'joe@example.com', name: 'Joe Doe' }\n * )\n *\n * // Now the response data is typed as `Data`\n * console.log(res?.data.message)\n *\n * // Now the error message is typed as `ErrorMessage`\n * console.log(error?.message.details)\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/functions/call\n */\n async call<TData = unknown, TBody = any, TErrorMessage = any>(\n url: string,\n body?: TBody | null,\n config?: NhostFunctionCallConfig\n ): Promise<NhostFunctionCallResponse<TData, TErrorMessage>> {\n const headers: HeadersInit = {\n 'Content-Type': 'application/json',\n ...this.generateAccessTokenHeaders(),\n ...config?.headers,\n ...this.headers // nhost functions client headers to be sent with all calls\n }\n\n const fullUrl = buildUrl(this.url, url)\n\n try {\n const result = await fetch(fullUrl, {\n body: body ? JSON.stringify(body) : null,\n headers,\n method: 'POST'\n })\n\n if (!result.ok) {\n let message: TErrorMessage\n\n if (result.headers.get('content-type')?.includes('application/json')) {\n message = await result.json()\n } else {\n message = (await result.text()) as unknown as TErrorMessage\n }\n\n return {\n res: null,\n error: {\n message,\n error: result.statusText,\n status: result.status\n }\n }\n }\n\n let data: TData\n\n if (result.headers.get('content-type')?.includes('application/json')) {\n data = await result.json()\n } else {\n data = (await result.text()) as unknown as TData\n }\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 as unknown as TErrorMessage,\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 /**\n * Use `nhost.functions.getHeaders` to get the global headers sent with all functions requests.\n *\n * @example\n * ```ts\n * nhost.functions.getHeaders()\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/functions/get-headers\n */\n getHeaders(): Record<string, string> {\n return this.headers\n }\n\n /**\n * Use `nhost.functions.setHeaders` to a set global headers to be sent in all subsequent functions requests.\n *\n * @example\n * ```ts\n * nhost.functions.setHeaders({\n * 'x-hasura-role': 'admin'\n * })\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/functions/set-headers\n */\n setHeaders(headers?: Record<string, string>) {\n if (!headers) {\n return\n }\n\n this.headers = {\n ...this.headers,\n ...headers\n }\n }\n\n /**\n * Use `nhost.functions.unsetHeaders` to a unset global headers sent with all functions requests.\n *\n * @example\n * ```ts\n * nhost.functions.unsetHeaders()\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/functions/unset-headers\n */\n unsetHeaders() {\n const userRole = this.headers['x-hasura-role']\n\n // preserve the user role header to avoid invalidating preceding 'setRole' call.\n this.headers = userRole ? { 'x-hasura-role': userRole } : {}\n }\n\n 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 { 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(params: NhostClientConstructorParams) {\n const graphqlUrl = 'subdomain' in params ? urlFromSubdomain(params, 'graphql') : 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) {\n const storageUrl = 'subdomain' in params ? urlFromSubdomain(params, 'storage') : 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 { 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 = (params: NhostClientConstructorParams) => new NhostClient(params)\n\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 *\n * @example\n * ```ts\n * // Create a new Nhost client from subdomain and region.\n * const nhost = new NhostClient({ subdomain, region });\n * ```\n *\n *\n * ```ts\n * // Create a new Nhost client from individual service URLs (custom domains, self-hosting, etc).\n * const nhost = new NhostClient({ \n * authUrl: \"my-auth-service-url\",\n * storageUrl: \"my-storage-service-url\",\n * graphqlUrl: \"my-graphql-service-url\",\n * functionsUrl: \"my-functions-service-url\",\n * });\n * ```\n *\n *\n * ```ts\n * // Create a new Nhost client for local development.\n * const nhost = new NhostClient({ subdomain: \"local\" });\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 ...urlParams\n }: NhostClientConstructorParams) {\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, ...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 return\n }\n\n const accessToken = session?.accessToken\n this.storage.setAccessToken(accessToken)\n this.functions.setAccessToken(accessToken)\n this.graphql.setAccessToken(accessToken)\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 /**\n * Use `nhost.setRole` to set the user role for all subsequent GraphQL, storage, and functions calls.\n * Underneath, this method sets the `x-hasura-role` header on the graphql, storage,\n * and functions clients.\n *\n * ```ts\n * nhost.graphql.setHeaders({ 'x-hasura-role': role })\n * nhost.storage.setHeaders({ 'x-hasura-role': role })\n * nhost.functions.setHeaders({ 'x-hasura-role': role })\n * ```\n *\n * Note: Exercise caution when mixing the use of `setRole` along with `setHeaders` when setting the\n * `x-hasura-role` header, as the last call will override any previous ones.\n *\n * @example\n * ```ts\n * nhost.setRole('admin')\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/set-role\n */\n setRole(role: string) {\n this.graphql.setHeaders({ 'x-hasura-role': role })\n this.storage.setHeaders({ 'x-hasura-role': role })\n this.functions.setHeaders({ 'x-hasura-role': role })\n }\n\n /**\n * Use `nhost.unsetRole` to unset the user role for all subsequent graphql, storage and functions calls.\n * Underneath, this method removes the `x-hasura-role` header from the graphql, storage and functions clients.\n *\n * Note: Exercise caution when mixing the use of `unsetRole` along with `setHeaders` when setting the\n * `x-hasura-role` header, as the last call will override any previous ones.\n *\n * @example\n * ```ts\n * nhost.unsetRole()\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/unset-role\n */\n unsetRole() {\n this.graphql.setHeaders((({ 'x-hasura-role': _, ...rest }) => rest)(this.graphql.getHeaders()))\n this.storage.setHeaders((({ 'x-hasura-role': _, ...rest }) => rest)(this.storage.getHeaders()))\n this.functions.setHeaders(\n (({ 'x-hasura-role': _, ...rest }) => rest)(this.functions.getHeaders())\n )\n }\n}\n"],"names":["LOCALHOST_REGEX","urlFromSubdomain","subdomainAndRegion","service","subdomain","region","subdomainLocalhostFound","protocol","host","port","urlFromEnv","getValueFromEnv","isBrowser","environmentIsAvailable","buildUrl","baseUrl","path","urlPath","createAuthClient","params","authUrl","HasuraAuthClient","createFunctionsClient","functionsUrl","NhostFunctionsClient","url","adminSecret","body","config","headers","fullUrl","result","fetch","message","_a","data","_b","e","error","accessToken","userRole","createGraphqlClient","graphqlUrl","NhostGraphqlClient","createStorageClient","storageUrl","HasuraStorageClient","createNhostClient","NhostClient","refreshIntervalTime","clientStorage","clientStorageType","autoRefreshToken","autoSignIn","devTools","start","urlParams","event","session","newValue","role","_","rest"],"mappings":"8NAGaA,EACX,sFASc,SAAAC,EACd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,gBAAiBA,CAAM,CAAA,CACrD,CAgBA,WAAY,CACV,KAAK,QAAQ,YAAY,CAAC,CAAE,gBAAiBC,EAAG,GAAGC,CAAK,IAAMA,GAAM,KAAK,QAAQ,WAAA,CAAY,CAAC,EAC9F,KAAK,QAAQ,YAAY,CAAC,CAAE,gBAAiBD,EAAG,GAAGC,CAAK,IAAMA,GAAM,KAAK,QAAQ,WAAA,CAAY,CAAC,EAC9F,KAAK,UAAU,YACZ,CAAC,CAAE,gBAAiBD,EAAG,GAAGC,KAAWA,GAAM,KAAK,UAAU,YAAY,CAAA,CAE3E,CACF"}
package/dist/index.esm.js CHANGED
@@ -220,13 +220,30 @@ function C(e) {
220
220
  const N = (e) => new $(e);
221
221
  class $ {
222
222
  /**
223
- * Nhost Client
224
223
  *
225
224
  * @example
226
225
  * ```ts
226
+ * // Create a new Nhost client from subdomain and region.
227
227
  * const nhost = new NhostClient({ subdomain, region });
228
228
  * ```
229
229
  *
230
+ *
231
+ * ```ts
232
+ * // Create a new Nhost client from individual service URLs (custom domains, self-hosting, etc).
233
+ * const nhost = new NhostClient({
234
+ * authUrl: "my-auth-service-url",
235
+ * storageUrl: "my-storage-service-url",
236
+ * graphqlUrl: "my-graphql-service-url",
237
+ * functionsUrl: "my-functions-service-url",
238
+ * });
239
+ * ```
240
+ *
241
+ *
242
+ * ```ts
243
+ * // Create a new Nhost client for local development.
244
+ * const nhost = new NhostClient({ subdomain: "local" });
245
+ * ```
246
+ *
230
247
  * @docs https://docs.nhost.io/reference/javascript
231
248
  */
232
249
  constructor({
@@ -285,7 +302,7 @@ class $ {
285
302
  * nhost.setRole('admin')
286
303
  * ```
287
304
  *
288
- * @docs https://docs.nhost.io/reference/javascript/set-role
305
+ * @docs https://docs.nhost.io/reference/javascript/nhost-js/set-role
289
306
  */
290
307
  setRole(t) {
291
308
  this.graphql.setHeaders({ "x-hasura-role": t }), this.storage.setHeaders({ "x-hasura-role": t }), this.functions.setHeaders({ "x-hasura-role": t });
@@ -299,10 +316,10 @@ class $ {
299
316
  *
300
317
  * @example
301
318
  * ```ts
302
- * nhost.unsetRole('admin')
319
+ * nhost.unsetRole()
303
320
  * ```
304
321
  *
305
- * @docs https://docs.nhost.io/reference/javascript/set-role
322
+ * @docs https://docs.nhost.io/reference/javascript/nhost-js/unset-role
306
323
  */
307
324
  unsetRole() {
308
325
  this.graphql.setHeaders((({ "x-hasura-role": t, ...r }) => r)(this.graphql.getHeaders())), this.storage.setHeaders((({ "x-hasura-role": t, ...r }) => r)(this.storage.getHeaders())), this.functions.setHeaders(
@@ -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.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__\"\nexport const LOCALHOST_REGEX =\n /^((?<protocol>http[s]?):\\/\\/)?(?<host>(localhost|local))(:(?<port>(\\d+|__\\w+__)))?$/\n\n/**\n * \\`subdomain\\` and `region` should be used when running the Nhost platform\n *\n * @param subdomainAndRegion\n * @param service\n * @returns\n */\nexport function urlFromSubdomain(\n subdomainAndRegion: Pick<NhostClientConstructorParams, 'region' | 'subdomain'>,\n service: string\n): string {\n const { subdomain, region } = subdomainAndRegion\n\n if (!subdomain) {\n throw new Error('A `subdomain` must be set.')\n }\n\n // check if subdomain is [http[s]://]localhost[:port] or [http[s]://]local[:port]\n const subdomainLocalhostFound = subdomain.match(LOCALHOST_REGEX)\n if (subdomainLocalhostFound?.groups) {\n const { protocol, host, port } = subdomainLocalhostFound.groups\n\n const urlFromEnv = getValueFromEnv(service)\n if (urlFromEnv) {\n return urlFromEnv\n }\n\n if (host === 'localhost') {\n console.warn(\n 'The `subdomain` is set to \"localhost\". Support for this will be removed in a future release. Please use \"local\" instead.'\n )\n\n return `${protocol || 'http'}://localhost:${port || 1337}/v1/${service}`\n }\n\n return port\n ? `${protocol || 'https'}://local.${service}.nhost.run:${port}/v1`\n : `${protocol || 'https'}://local.${service}.nhost.run/v1`\n }\n\n if (!region) {\n throw new Error('`region` must be set when using a `subdomain` other than \"local\".')\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\n/**\n * Combines a base URL and a path into a single URL string.\n *\n * @param baseUrl - The base URL to use.\n * @param path - The path to append to the base URL.\n * @returns The combined URL string.\n */\nexport function buildUrl(baseUrl: string, path: string) {\n const hasLeadingSlash = path.startsWith('/')\n const urlPath = hasLeadingSlash ? path : `/${path}`\n return baseUrl + urlPath\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 = 'subdomain' in params ? urlFromSubdomain(params, 'auth') : 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 'isomorphic-unfetch'\nimport { buildUrl, 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 ? urlFromSubdomain(params, 'functions') : 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 private headers: Record<string, 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 /**\n * Use `nhost.functions.call` to call (sending a POST request to) a serverless function. Use generic\n * types to specify the expected response data, request body and error message.\n *\n * @example\n * ### Without generic types\n * ```ts\n * await nhost.functions.call('send-welcome-email', { email: 'joe@example.com', name: 'Joe Doe' })\n * ```\n *\n * @example\n * ### Using generic types\n * ```ts\n * type Data = {\n * message: string\n * }\n *\n * type Body = {\n * email: string\n * name: string\n * }\n *\n * type ErrorMessage = {\n * details: string\n * }\n *\n * // The function will only accept a body of type `Body`\n * const { res, error } = await nhost.functions.call<Data, Body, ErrorMessage>(\n * 'send-welcome-email',\n * { email: 'joe@example.com', name: 'Joe Doe' }\n * )\n *\n * // Now the response data is typed as `Data`\n * console.log(res?.data.message)\n *\n * // Now the error message is typed as `ErrorMessage`\n * console.log(error?.message.details)\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/functions/call\n */\n async call<TData = unknown, TBody = any, TErrorMessage = any>(\n url: string,\n body?: TBody | null,\n config?: NhostFunctionCallConfig\n ): Promise<NhostFunctionCallResponse<TData, TErrorMessage>> {\n const headers: HeadersInit = {\n 'Content-Type': 'application/json',\n ...this.generateAccessTokenHeaders(),\n ...config?.headers,\n ...this.headers // nhost functions client headers to be sent with all calls\n }\n\n const fullUrl = buildUrl(this.url, url)\n\n try {\n const result = await fetch(fullUrl, {\n body: body ? JSON.stringify(body) : null,\n headers,\n method: 'POST'\n })\n\n if (!result.ok) {\n let message: TErrorMessage\n\n if (result.headers.get('content-type')?.includes('application/json')) {\n message = await result.json()\n } else {\n message = (await result.text()) as unknown as TErrorMessage\n }\n\n return {\n res: null,\n error: {\n message,\n error: result.statusText,\n status: result.status\n }\n }\n }\n\n let data: TData\n\n if (result.headers.get('content-type')?.includes('application/json')) {\n data = await result.json()\n } else {\n data = (await result.text()) as unknown as TData\n }\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 as unknown as TErrorMessage,\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 /**\n * Use `nhost.functions.getHeaders` to get the global headers sent with all functions requests.\n *\n * @example\n * ```ts\n * nhost.functions.getHeaders()\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/functions/get-headers\n */\n getHeaders(): Record<string, string> {\n return this.headers\n }\n\n /**\n * Use `nhost.functions.setHeaders` to a set global headers to be sent in all subsequent functions requests.\n *\n * @example\n * ```ts\n * nhost.functions.setHeaders({\n * 'x-hasura-role': 'admin'\n * })\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/functions/set-headers\n */\n setHeaders(headers?: Record<string, string>) {\n if (!headers) {\n return\n }\n\n this.headers = {\n ...this.headers,\n ...headers\n }\n }\n\n /**\n * Use `nhost.functions.unsetHeaders` to a unset global headers sent with all functions requests.\n *\n * @example\n * ```ts\n * nhost.functions.unsetHeaders()\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/functions/unset-headers\n */\n unsetHeaders() {\n const userRole = this.headers['x-hasura-role']\n\n // preserve the user role header to avoid invalidating preceding 'setRole' call.\n this.headers = userRole ? { 'x-hasura-role': userRole } : {}\n }\n\n 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 { 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(params: NhostClientConstructorParams) {\n const graphqlUrl = 'subdomain' in params ? urlFromSubdomain(params, 'graphql') : 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) {\n const storageUrl = 'subdomain' in params ? urlFromSubdomain(params, 'storage') : 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 { 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 = (params: NhostClientConstructorParams) => new NhostClient(params)\n\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 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 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 return\n }\n\n const accessToken = session?.accessToken\n this.storage.setAccessToken(accessToken)\n this.functions.setAccessToken(accessToken)\n this.graphql.setAccessToken(accessToken)\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 /**\n * Use `nhost.setRole` to set the user role for all subsequent GraphQL, storage, and functions calls.\n * Underneath, this method sets the `x-hasura-role` header on the graphql, storage,\n * and functions clients.\n *\n * ```ts\n * nhost.graphql.setHeaders({ 'x-hasura-role': role })\n * nhost.storage.setHeaders({ 'x-hasura-role': role })\n * nhost.functions.setHeaders({ 'x-hasura-role': role })\n * ```\n *\n * Note: Exercise caution when mixing the use of `setRole` along with `setHeaders` when setting the\n * `x-hasura-role` header, as the last call will override any previous ones.\n *\n * @example\n * ```ts\n * nhost.setRole('admin')\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/set-role\n */\n setRole(role: string) {\n this.graphql.setHeaders({ 'x-hasura-role': role })\n this.storage.setHeaders({ 'x-hasura-role': role })\n this.functions.setHeaders({ 'x-hasura-role': role })\n }\n\n /**\n * Use `nhost.unsetRole` to unset the user role for all subsequent graphql, storage and functions calls.\n * Underneath, this method removes the `x-hasura-role` header from the graphql, storage and functions clients.\n *\n * Note: Exercise caution when mixing the use of `unsetRole` along with `setHeaders` when setting the\n * `x-hasura-role` header, as the last call will override any previous ones.\n *\n * @example\n * ```ts\n * nhost.unsetRole('admin')\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/set-role\n */\n unsetRole() {\n this.graphql.setHeaders((({ 'x-hasura-role': _, ...rest }) => rest)(this.graphql.getHeaders()))\n this.storage.setHeaders((({ 'x-hasura-role': _, ...rest }) => rest)(this.storage.getHeaders()))\n this.functions.setHeaders(\n (({ 'x-hasura-role': _, ...rest }) => rest)(this.functions.getHeaders())\n )\n }\n}\n"],"names":["LOCALHOST_REGEX","urlFromSubdomain","subdomainAndRegion","service","subdomain","region","subdomainLocalhostFound","protocol","host","port","urlFromEnv","getValueFromEnv","isBrowser","environmentIsAvailable","buildUrl","baseUrl","path","urlPath","createAuthClient","params","authUrl","HasuraAuthClient","createFunctionsClient","functionsUrl","NhostFunctionsClient","url","adminSecret","body","config","headers","fullUrl","result","fetch","message","_a","data","_b","e","error","accessToken","userRole","createGraphqlClient","graphqlUrl","NhostGraphqlClient","createStorageClient","storageUrl","HasuraStorageClient","createNhostClient","NhostClient","refreshIntervalTime","clientStorage","clientStorageType","autoRefreshToken","autoSignIn","devTools","start","urlParams","event","session","newValue","role","_","rest"],"mappings":";;;;;;AAGO,MAAMA,IACX;AASc,SAAAC,EACdC,GACAC,GACQ;AACF,QAAA,EAAE,WAAAC,GAAW,QAAAC,EAAW,IAAAH;AAE9B,MAAI,CAACE;AACG,UAAA,IAAI,MAAM,4BAA4B;AAIxC,QAAAE,IAA0BF,EAAU,MAAMJ,CAAe;AAC/D,MAAIM,KAAA,QAAAA,EAAyB,QAAQ;AACnC,UAAM,EAAE,UAAAC,GAAU,MAAAC,GAAM,MAAAC,EAAA,IAASH,EAAwB,QAEnDI,IAAaC,EAAgBR,CAAO;AAC1C,WAAIO,MAIAF,MAAS,eACH,QAAA;AAAA,MACN;AAAA,IAAA,GAGK,GAAGD,KAAY,MAAM,gBAAgBE,KAAQ,IAAI,OAAON,CAAO,MAGjEM,IACH,GAAGF,KAAY,OAAO,YAAYJ,CAAO,cAAcM,CAAI,QAC3D,GAAGF,KAAY,OAAO,YAAYJ,CAAO;AAAA,EAC/C;AAEA,MAAI,CAACE;AACG,UAAA,IAAI,MAAM,mEAAmE;AAGrF,SAAO,WAAWD,CAAS,IAAID,CAAO,IAAIE,CAAM;AAClD;AAMA,SAASO,IAAqB;AAC5B,SAAO,OAAO,UAAW;AAC3B;AAMA,SAASC,IAAyB;AACzB,SAAA,OAAO,WAAY,eAAe,QAAQ;AACnD;AAQA,SAASF,EAAgBR,GAAiB;AACxC,SAAIS,EAAU,KAAK,CAACC,MACX,OAGF,QAAQ,IAAI,SAASV,EAAQ,YAAa,CAAA,MAAM;AACzD;AASgB,SAAAW,EAASC,GAAiBC,GAAc;AAEtD,QAAMC,IADkBD,EAAK,WAAW,GAAG,IACTA,IAAO,IAAIA,CAAI;AACjD,SAAOD,IAAUE;AACnB;ACtFO,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AAAA,EAuBA,QAAQC,GAAc;AACpB,SAAK,QAAQ,WAAW,EAAE,iBAAiBA,EAAM,CAAA,GACjD,KAAK,QAAQ,WAAW,EAAE,iBAAiBA,EAAM,CAAA,GACjD,KAAK,UAAU,WAAW,EAAE,iBAAiBA,EAAM,CAAA;AAAA,EACrD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAgBA,YAAY;AACV,SAAK,QAAQ,YAAY,CAAC,EAAE,iBAAiBC,GAAG,GAAGC,EAAK,MAAMA,GAAM,KAAK,QAAQ,WAAA,CAAY,CAAC,GAC9F,KAAK,QAAQ,YAAY,CAAC,EAAE,iBAAiBD,GAAG,GAAGC,EAAK,MAAMA,GAAM,KAAK,QAAQ,WAAA,CAAY,CAAC,GAC9F,KAAK,UAAU;AAAA,OACZ,CAAC,EAAE,iBAAiBD,GAAG,GAAGC,QAAWA,GAAM,KAAK,UAAU,YAAY;AAAA,IAAA;AAAA,EAE3E;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__\"\nexport const LOCALHOST_REGEX =\n /^((?<protocol>http[s]?):\\/\\/)?(?<host>(localhost|local))(:(?<port>(\\d+|__\\w+__)))?$/\n\n/**\n * \\`subdomain\\` and `region` should be used when running the Nhost platform\n *\n * @param subdomainAndRegion\n * @param service\n * @returns\n */\nexport function urlFromSubdomain(\n subdomainAndRegion: Pick<NhostClientConstructorParams, 'region' | 'subdomain'>,\n service: string\n): string {\n const { subdomain, region } = subdomainAndRegion\n\n if (!subdomain) {\n throw new Error('A `subdomain` must be set.')\n }\n\n // check if subdomain is [http[s]://]localhost[:port] or [http[s]://]local[:port]\n const subdomainLocalhostFound = subdomain.match(LOCALHOST_REGEX)\n if (subdomainLocalhostFound?.groups) {\n const { protocol, host, port } = subdomainLocalhostFound.groups\n\n const urlFromEnv = getValueFromEnv(service)\n if (urlFromEnv) {\n return urlFromEnv\n }\n\n if (host === 'localhost') {\n console.warn(\n 'The `subdomain` is set to \"localhost\". Support for this will be removed in a future release. Please use \"local\" instead.'\n )\n\n return `${protocol || 'http'}://localhost:${port || 1337}/v1/${service}`\n }\n\n return port\n ? `${protocol || 'https'}://local.${service}.nhost.run:${port}/v1`\n : `${protocol || 'https'}://local.${service}.nhost.run/v1`\n }\n\n if (!region) {\n throw new Error('`region` must be set when using a `subdomain` other than \"local\".')\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\n/**\n * Combines a base URL and a path into a single URL string.\n *\n * @param baseUrl - The base URL to use.\n * @param path - The path to append to the base URL.\n * @returns The combined URL string.\n */\nexport function buildUrl(baseUrl: string, path: string) {\n const hasLeadingSlash = path.startsWith('/')\n const urlPath = hasLeadingSlash ? path : `/${path}`\n return baseUrl + urlPath\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 = 'subdomain' in params ? urlFromSubdomain(params, 'auth') : 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 'isomorphic-unfetch'\nimport { buildUrl, 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 ? urlFromSubdomain(params, 'functions') : 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 private headers: Record<string, 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 /**\n * Use `nhost.functions.call` to call (sending a POST request to) a serverless function. Use generic\n * types to specify the expected response data, request body and error message.\n *\n * @example\n * ### Without generic types\n * ```ts\n * await nhost.functions.call('send-welcome-email', { email: 'joe@example.com', name: 'Joe Doe' })\n * ```\n *\n * @example\n * ### Using generic types\n * ```ts\n * type Data = {\n * message: string\n * }\n *\n * type Body = {\n * email: string\n * name: string\n * }\n *\n * type ErrorMessage = {\n * details: string\n * }\n *\n * // The function will only accept a body of type `Body`\n * const { res, error } = await nhost.functions.call<Data, Body, ErrorMessage>(\n * 'send-welcome-email',\n * { email: 'joe@example.com', name: 'Joe Doe' }\n * )\n *\n * // Now the response data is typed as `Data`\n * console.log(res?.data.message)\n *\n * // Now the error message is typed as `ErrorMessage`\n * console.log(error?.message.details)\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/functions/call\n */\n async call<TData = unknown, TBody = any, TErrorMessage = any>(\n url: string,\n body?: TBody | null,\n config?: NhostFunctionCallConfig\n ): Promise<NhostFunctionCallResponse<TData, TErrorMessage>> {\n const headers: HeadersInit = {\n 'Content-Type': 'application/json',\n ...this.generateAccessTokenHeaders(),\n ...config?.headers,\n ...this.headers // nhost functions client headers to be sent with all calls\n }\n\n const fullUrl = buildUrl(this.url, url)\n\n try {\n const result = await fetch(fullUrl, {\n body: body ? JSON.stringify(body) : null,\n headers,\n method: 'POST'\n })\n\n if (!result.ok) {\n let message: TErrorMessage\n\n if (result.headers.get('content-type')?.includes('application/json')) {\n message = await result.json()\n } else {\n message = (await result.text()) as unknown as TErrorMessage\n }\n\n return {\n res: null,\n error: {\n message,\n error: result.statusText,\n status: result.status\n }\n }\n }\n\n let data: TData\n\n if (result.headers.get('content-type')?.includes('application/json')) {\n data = await result.json()\n } else {\n data = (await result.text()) as unknown as TData\n }\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 as unknown as TErrorMessage,\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 /**\n * Use `nhost.functions.getHeaders` to get the global headers sent with all functions requests.\n *\n * @example\n * ```ts\n * nhost.functions.getHeaders()\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/functions/get-headers\n */\n getHeaders(): Record<string, string> {\n return this.headers\n }\n\n /**\n * Use `nhost.functions.setHeaders` to a set global headers to be sent in all subsequent functions requests.\n *\n * @example\n * ```ts\n * nhost.functions.setHeaders({\n * 'x-hasura-role': 'admin'\n * })\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/functions/set-headers\n */\n setHeaders(headers?: Record<string, string>) {\n if (!headers) {\n return\n }\n\n this.headers = {\n ...this.headers,\n ...headers\n }\n }\n\n /**\n * Use `nhost.functions.unsetHeaders` to a unset global headers sent with all functions requests.\n *\n * @example\n * ```ts\n * nhost.functions.unsetHeaders()\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/functions/unset-headers\n */\n unsetHeaders() {\n const userRole = this.headers['x-hasura-role']\n\n // preserve the user role header to avoid invalidating preceding 'setRole' call.\n this.headers = userRole ? { 'x-hasura-role': userRole } : {}\n }\n\n 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 { 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(params: NhostClientConstructorParams) {\n const graphqlUrl = 'subdomain' in params ? urlFromSubdomain(params, 'graphql') : 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) {\n const storageUrl = 'subdomain' in params ? urlFromSubdomain(params, 'storage') : 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 { 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 = (params: NhostClientConstructorParams) => new NhostClient(params)\n\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 *\n * @example\n * ```ts\n * // Create a new Nhost client from subdomain and region.\n * const nhost = new NhostClient({ subdomain, region });\n * ```\n *\n *\n * ```ts\n * // Create a new Nhost client from individual service URLs (custom domains, self-hosting, etc).\n * const nhost = new NhostClient({ \n * authUrl: \"my-auth-service-url\",\n * storageUrl: \"my-storage-service-url\",\n * graphqlUrl: \"my-graphql-service-url\",\n * functionsUrl: \"my-functions-service-url\",\n * });\n * ```\n *\n *\n * ```ts\n * // Create a new Nhost client for local development.\n * const nhost = new NhostClient({ subdomain: \"local\" });\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 ...urlParams\n }: NhostClientConstructorParams) {\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, ...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 return\n }\n\n const accessToken = session?.accessToken\n this.storage.setAccessToken(accessToken)\n this.functions.setAccessToken(accessToken)\n this.graphql.setAccessToken(accessToken)\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 /**\n * Use `nhost.setRole` to set the user role for all subsequent GraphQL, storage, and functions calls.\n * Underneath, this method sets the `x-hasura-role` header on the graphql, storage,\n * and functions clients.\n *\n * ```ts\n * nhost.graphql.setHeaders({ 'x-hasura-role': role })\n * nhost.storage.setHeaders({ 'x-hasura-role': role })\n * nhost.functions.setHeaders({ 'x-hasura-role': role })\n * ```\n *\n * Note: Exercise caution when mixing the use of `setRole` along with `setHeaders` when setting the\n * `x-hasura-role` header, as the last call will override any previous ones.\n *\n * @example\n * ```ts\n * nhost.setRole('admin')\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/set-role\n */\n setRole(role: string) {\n this.graphql.setHeaders({ 'x-hasura-role': role })\n this.storage.setHeaders({ 'x-hasura-role': role })\n this.functions.setHeaders({ 'x-hasura-role': role })\n }\n\n /**\n * Use `nhost.unsetRole` to unset the user role for all subsequent graphql, storage and functions calls.\n * Underneath, this method removes the `x-hasura-role` header from the graphql, storage and functions clients.\n *\n * Note: Exercise caution when mixing the use of `unsetRole` along with `setHeaders` when setting the\n * `x-hasura-role` header, as the last call will override any previous ones.\n *\n * @example\n * ```ts\n * nhost.unsetRole()\n * ```\n *\n * @docs https://docs.nhost.io/reference/javascript/nhost-js/unset-role\n */\n unsetRole() {\n this.graphql.setHeaders((({ 'x-hasura-role': _, ...rest }) => rest)(this.graphql.getHeaders()))\n this.storage.setHeaders((({ 'x-hasura-role': _, ...rest }) => rest)(this.storage.getHeaders()))\n this.functions.setHeaders(\n (({ 'x-hasura-role': _, ...rest }) => rest)(this.functions.getHeaders())\n )\n }\n}\n"],"names":["LOCALHOST_REGEX","urlFromSubdomain","subdomainAndRegion","service","subdomain","region","subdomainLocalhostFound","protocol","host","port","urlFromEnv","getValueFromEnv","isBrowser","environmentIsAvailable","buildUrl","baseUrl","path","urlPath","createAuthClient","params","authUrl","HasuraAuthClient","createFunctionsClient","functionsUrl","NhostFunctionsClient","url","adminSecret","body","config","headers","fullUrl","result","fetch","message","_a","data","_b","e","error","accessToken","userRole","createGraphqlClient","graphqlUrl","NhostGraphqlClient","createStorageClient","storageUrl","HasuraStorageClient","createNhostClient","NhostClient","refreshIntervalTime","clientStorage","clientStorageType","autoRefreshToken","autoSignIn","devTools","start","urlParams","event","session","newValue","role","_","rest"],"mappings":";;;;;;AAGO,MAAMA,IACX;AASc,SAAAC,EACdC,GACAC,GACQ;AACF,QAAA,EAAE,WAAAC,GAAW,QAAAC,EAAW,IAAAH;AAE9B,MAAI,CAACE;AACG,UAAA,IAAI,MAAM,4BAA4B;AAIxC,QAAAE,IAA0BF,EAAU,MAAMJ,CAAe;AAC/D,MAAIM,KAAA,QAAAA,EAAyB,QAAQ;AACnC,UAAM,EAAE,UAAAC,GAAU,MAAAC,GAAM,MAAAC,EAAA,IAASH,EAAwB,QAEnDI,IAAaC,EAAgBR,CAAO;AAC1C,WAAIO,MAIAF,MAAS,eACH,QAAA;AAAA,MACN;AAAA,IAAA,GAGK,GAAGD,KAAY,MAAM,gBAAgBE,KAAQ,IAAI,OAAON,CAAO,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