{"version":3,"sources":["../src/portal.ts"],"sourcesContent":["import { ensureServer } from \"@settlemint/sdk-utils/runtime\";\nimport { ApplicationAccessTokenSchema, UrlOrPathSchema, validate } from \"@settlemint/sdk-utils/validation\";\nimport { type AbstractSetupSchema, initGraphQLTada } from \"gql.tada\";\nimport { GraphQLClient } from \"graphql-request\";\nimport { z } from \"zod\";\n\n/**\n * Configuration options for the GraphQL client, excluding 'url' and 'exchanges'.\n */\nexport type RequestConfig = ConstructorParameters<typeof GraphQLClient>[1];\n\n/**\n * Schema for validating Portal client configuration options.\n */\nexport const ClientOptionsSchema = z.object({\n  instance: UrlOrPathSchema,\n  accessToken: ApplicationAccessTokenSchema,\n  cache: z.enum([\"default\", \"force-cache\", \"no-cache\", \"no-store\", \"only-if-cached\", \"reload\"]).optional(),\n});\n\n/**\n * Type representing the validated client options.\n */\nexport type ClientOptions = z.infer<typeof ClientOptionsSchema>;\n\n/**\n * Creates a Portal GraphQL client with the provided configuration.\n *\n * @param options - Configuration options for the Portal client\n * @param clientOptions - Additional GraphQL client configuration options\n * @returns An object containing the configured GraphQL client and graphql helper function\n * @throws If the provided options fail validation\n *\n * @example\n * import { createPortalClient } from '@settlemint/sdk-portal';\n * import type { introspection } from \"@schemas/portal-env\";\n * import { createLogger, requestLogger } from '@settlemint/sdk-utils/logging';\n *\n * const logger = createLogger();\n *\n * export const { client: portalClient, graphql: portalGraphql } = createPortalClient<{\n *   introspection: introspection;\n *   disableMasking: true;\n *   scalars: {\n *     // Change unknown to the type you are using to store metadata\n *     JSON: unknown;\n *   };\n * }>({\n *   instance: process.env.SETTLEMINT_PORTAL_GRAPHQL_ENDPOINT,\n *   accessToken: process.env.SETTLEMINT_ACCESS_TOKEN,\n * }, {\n *   fetch: requestLogger(logger, \"portal\", fetch) as typeof fetch,\n * });\n *\n * // Making GraphQL queries\n * const query = graphql(`\n *   query GetPendingTransactions {\n *     getPendingTransactions {\n *       count\n *     }\n *   }\n * `);\n *\n * const result = await client.request(query);\n */\nexport function createPortalClient<const Setup extends AbstractSetupSchema>(\n  options: ClientOptions,\n  clientOptions?: RequestConfig,\n): {\n  client: GraphQLClient;\n  graphql: initGraphQLTada<Setup>;\n} {\n  ensureServer();\n  const validatedOptions = validate(ClientOptionsSchema, options);\n  const graphql = initGraphQLTada<Setup>();\n  const fullUrl = new URL(validatedOptions.instance).toString();\n\n  return {\n    client: new GraphQLClient(fullUrl, {\n      ...clientOptions,\n      headers: { ...(clientOptions?.headers ?? {}), \"x-auth-token\": validatedOptions.accessToken },\n    }),\n    graphql,\n  };\n}\n\nexport { readFragment } from \"gql.tada\";\nexport type { FragmentOf, ResultOf, VariablesOf } from \"gql.tada\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA6B;AAC7B,wBAAwE;AACxE,iBAA0D;AAC1D,6BAA8B;AAC9B,iBAAkB;AAkFlB,IAAAA,cAA6B;AAxEtB,IAAM,sBAAsB,aAAE,OAAO;AAAA,EAC1C,UAAU;AAAA,EACV,aAAa;AAAA,EACb,OAAO,aAAE,KAAK,CAAC,WAAW,eAAe,YAAY,YAAY,kBAAkB,QAAQ,CAAC,EAAE,SAAS;AACzG,CAAC;AA+CM,SAAS,mBACd,SACA,eAIA;AACA,mCAAa;AACb,QAAM,uBAAmB,4BAAS,qBAAqB,OAAO;AAC9D,QAAM,cAAU,4BAAuB;AACvC,QAAM,UAAU,IAAI,IAAI,iBAAiB,QAAQ,EAAE,SAAS;AAE5D,SAAO;AAAA,IACL,QAAQ,IAAI,qCAAc,SAAS;AAAA,MACjC,GAAG;AAAA,MACH,SAAS,EAAE,GAAI,eAAe,WAAW,CAAC,GAAI,gBAAgB,iBAAiB,YAAY;AAAA,IAC7F,CAAC;AAAA,IACD;AAAA,EACF;AACF;","names":["import_gql"]}