UNPKG

@nhost/nhost-js

Version:

Nhost JavaScript SDK

83 lines (82 loc) 3.16 kB
import { NhostGraphqlClient } from '@nhost/graphql-js'; import { HasuraAuthClient } from '@nhost/hasura-auth-js'; import { HasuraStorageClient } from '@nhost/hasura-storage-js'; import { NhostClientConstructorParams } from '../utils/types'; import { NhostFunctionsClient } from './functions'; export declare const createNhostClient: (params: NhostClientConstructorParams) => NhostClient; export declare class NhostClient { auth: HasuraAuthClient; storage: HasuraStorageClient; functions: NhostFunctionsClient; graphql: NhostGraphqlClient; private _adminSecret?; readonly devTools?: boolean; /** * * @example * ```ts * // Create a new Nhost client from subdomain and region. * const nhost = new NhostClient({ subdomain, region }); * ``` * * * ```ts * // Create a new Nhost client from individual service URLs (custom domains, self-hosting, etc). * const nhost = new NhostClient({ * authUrl: "my-auth-service-url", * storageUrl: "my-storage-service-url", * graphqlUrl: "my-graphql-service-url", * functionsUrl: "my-functions-service-url", * }); * ``` * * * ```ts * // Create a new Nhost client for local development. * const nhost = new NhostClient({ subdomain: "local" }); * ``` * * @docs https://docs.nhost.io/reference/javascript */ constructor({ refreshIntervalTime, clientStorage, clientStorageType, autoRefreshToken, autoSignIn, adminSecret, devTools, start, ...urlParams }: NhostClientConstructorParams); get adminSecret(): string | undefined; set adminSecret(newValue: string | undefined); /** * Use `nhost.setRole` to set the user role for all subsequent GraphQL, storage, and functions calls. * Underneath, this method sets the `x-hasura-role` header on the graphql, storage, * and functions clients. * * ```ts * nhost.graphql.setHeaders({ 'x-hasura-role': role }) * nhost.storage.setHeaders({ 'x-hasura-role': role }) * nhost.functions.setHeaders({ 'x-hasura-role': role }) * ``` * * Note: Exercise caution when mixing the use of `setRole` along with `setHeaders` when setting the * `x-hasura-role` header, as the last call will override any previous ones. * * @example * ```ts * nhost.setRole('admin') * ``` * * @docs https://docs.nhost.io/reference/javascript/nhost-js/set-role */ setRole(role: string): void; /** * Use `nhost.unsetRole` to unset the user role for all subsequent graphql, storage and functions calls. * Underneath, this method removes the `x-hasura-role` header from the graphql, storage and functions clients. * * Note: Exercise caution when mixing the use of `unsetRole` along with `setHeaders` when setting the * `x-hasura-role` header, as the last call will override any previous ones. * * @example * ```ts * nhost.unsetRole() * ``` * * @docs https://docs.nhost.io/reference/javascript/nhost-js/unset-role */ unsetRole(): void; } //# sourceMappingURL=nhost.d.ts.map