UNPKG

@settlemint/sdk-portal

Version:

Portal API client module for SettleMint SDK, providing access to smart contract portal services and APIs

76 lines (73 loc) 2.76 kB
import { AbstractSetupSchema, initGraphQLTada } from 'gql.tada'; export { FragmentOf, ResultOf, VariablesOf, readFragment } from 'gql.tada'; import { GraphQLClient } from 'graphql-request'; import { z } from 'zod'; /** * Configuration options for the GraphQL client, excluding 'url' and 'exchanges'. */ type RequestConfig = ConstructorParameters<typeof GraphQLClient>[1]; /** * Schema for validating Portal client configuration options. */ declare const ClientOptionsSchema: z.ZodObject<{ instance: z.ZodUnion<[z.ZodString, z.ZodString]>; accessToken: z.ZodString; cache: z.ZodOptional<z.ZodEnum<["default", "force-cache", "no-cache", "no-store", "only-if-cached", "reload"]>>; }, "strip", z.ZodTypeAny, { instance: string; accessToken: string; cache?: "default" | "force-cache" | "no-cache" | "no-store" | "only-if-cached" | "reload" | undefined; }, { instance: string; accessToken: string; cache?: "default" | "force-cache" | "no-cache" | "no-store" | "only-if-cached" | "reload" | undefined; }>; /** * Type representing the validated client options. */ type ClientOptions = z.infer<typeof ClientOptionsSchema>; /** * Creates a Portal GraphQL client with the provided configuration. * * @param options - Configuration options for the Portal client * @param clientOptions - Additional GraphQL client configuration options * @returns An object containing the configured GraphQL client and graphql helper function * @throws If the provided options fail validation * * @example * import { createPortalClient } from '@settlemint/sdk-portal'; * import type { introspection } from "@schemas/portal-env"; * import { createLogger, requestLogger } from '@settlemint/sdk-utils/logging'; * * const logger = createLogger(); * * export const { client: portalClient, graphql: portalGraphql } = createPortalClient<{ * introspection: introspection; * disableMasking: true; * scalars: { * // Change unknown to the type you are using to store metadata * JSON: unknown; * }; * }>({ * instance: process.env.SETTLEMINT_PORTAL_GRAPHQL_ENDPOINT, * accessToken: process.env.SETTLEMINT_ACCESS_TOKEN, * }, { * fetch: requestLogger(logger, "portal", fetch) as typeof fetch, * }); * * // Making GraphQL queries * const query = graphql(` * query GetPendingTransactions { * getPendingTransactions { * count * } * } * `); * * const result = await client.request(query); */ declare function createPortalClient<const Setup extends AbstractSetupSchema>(options: ClientOptions, clientOptions?: RequestConfig): { client: GraphQLClient; graphql: initGraphQLTada<Setup>; }; export { type ClientOptions, ClientOptionsSchema, type RequestConfig, createPortalClient };