{"version":3,"sources":["../../src/api/endlessConfig.ts"],"sourcesContent":["// Copyright © Endless\n// Copyright © Aptos Foundation\n// SPDX-License-Identifier: Apache-2.0\n\nimport endlessClient from \"@endlesslab/endless-client\";\nimport miniprogramClient from \"../utils/miniprogramClient\";\nimport { EndlessSettings, ClientConfig, Client, FullNodeConfig, IndexerConfig } from \"../types\";\nimport {\n  NetworkToNodeAPI,\n  NetworkToIndexerAPI,\n  Network,\n  NetworkToIndexerAPIV2,\n  NetworkToProverAPI,\n} from \"../utils/apiEndpoints\";\nimport { EndlessApiType } from \"../utils/const\";\n\n/**\n * This class holds the config information for the SDK client instance.\n *\n * @example\n *\n * const endlessConfig = new EndlessConfig({network:Network.TESTNET})\n */\nexport class EndlessConfig {\n  /**\n   * The Network that this SDK is associated with. Defaults to DEVNET\n   */\n  readonly network: Network;\n\n  /**\n   * The client instance the SDK uses. Defaults to @endlesslab/endless-client\n   */\n  readonly client: Client;\n\n  /**\n   * The optional hardcoded fullnode URL to send requests to instead of using the network\n   */\n  readonly fullnode?: string;\n\n  /**\n   * The optional hardcoded prover service URL to send requests to instead of using the network\n   */\n  readonly prover?: string;\n\n  /**\n   * The optional hardcoded indexer URL to send requests to instead of using the network\n   */\n  readonly indexer?: string;\n\n  readonly indexerV2?: string;\n\n  /**\n   * Optional client configurations\n   */\n  readonly clientConfig?: ClientConfig;\n\n  /**\n   * Optional specific Fullnode configurations\n   */\n  readonly fullnodeConfig?: FullNodeConfig;\n\n  /**\n   * Optional specific Indexer configurations\n   */\n  readonly indexerConfig?: IndexerConfig;\n\n  readonly maxExpHorizonSecs?: number;\n\n  constructor(settings?: EndlessSettings) {\n    this.network = settings?.network ?? Network.DEVNET;\n    this.fullnode = settings?.fullnode;\n    this.indexer = settings?.indexer;\n    this.prover = settings?.prover;\n    this.client = settings?.client ?? { provider: endlessClient };\n    if (settings?.miniprogram) {\n      this.client = settings?.client ?? { provider: miniprogramClient };\n    }\n    this.clientConfig = settings?.clientConfig ?? {};\n    this.fullnodeConfig = settings?.fullnodeConfig ?? {};\n    this.indexerConfig = settings?.indexerConfig ?? {};\n    this.maxExpHorizonSecs = settings?.network === Network.TESTNET ? 10000000 : undefined;\n  }\n\n  /**\n   * Returns the URL endpoint to send the request to.\n   * If a custom URL was provided in the config, that URL is returned.\n   * If a custom URL was provided but not URL endpoints, an error is thrown.\n   * Otherwise, the URL endpoint is derived from the network.\n   *\n   * @param apiType - The type of Endless API to get the URL for.\n   *\n   * @internal\n   */\n  getRequestUrl(apiType: EndlessApiType): string {\n    switch (apiType) {\n      case EndlessApiType.FULLNODE:\n        if (this.fullnode !== undefined) return this.fullnode;\n        if (this.network === Network.CUSTOM) throw new Error(\"Please provide a custom full node url\");\n        return NetworkToNodeAPI[this.network];\n      case EndlessApiType.INDEXER:\n        if (this.indexer !== undefined) return this.indexer;\n        if (this.network === Network.CUSTOM) throw new Error(\"Please provide a custom indexer url\");\n        return NetworkToIndexerAPI[this.network];\n      case EndlessApiType.PROVER:\n        if (this.prover !== undefined) return this.prover;\n        if (this.network === Network.CUSTOM) throw new Error(\"Please provide a custom prover service url\");\n        return NetworkToProverAPI[this.network];\n      case EndlessApiType.INDEXERV2:\n        if (this.indexerV2 !== undefined) return this.indexerV2;\n        if (this.network === Network.CUSTOM) throw new Error(\"Please provide a custom indexerv2 url\");\n        return NetworkToIndexerAPIV2[this.network];\n      default:\n        throw Error(`apiType ${apiType} is not supported`);\n    }\n  }\n}\n"],"mappings":"uGAIA,OAAOA,MAAmB,6BAmBnB,IAAMC,EAAN,KAAoB,CA6CzB,YAAYC,EAA4B,CACtC,KAAK,QAAUA,GAAU,SAAW,SACpC,KAAK,SAAWA,GAAU,SAC1B,KAAK,QAAUA,GAAU,QACzB,KAAK,OAASA,GAAU,OACxB,KAAK,OAASA,GAAU,QAAU,CAAE,SAAUC,CAAc,EACxDD,GAAU,cACZ,KAAK,OAASA,GAAU,QAAU,CAAE,SAAUE,CAAkB,GAElE,KAAK,aAAeF,GAAU,cAAgB,CAAC,EAC/C,KAAK,eAAiBA,GAAU,gBAAkB,CAAC,EACnD,KAAK,cAAgBA,GAAU,eAAiB,CAAC,EACjD,KAAK,kBAAoBA,GAAU,UAAY,UAAkB,IAAW,MAC9E,CAYA,cAAcG,EAAiC,CAC7C,OAAQA,EAAS,CACf,eACE,GAAI,KAAK,WAAa,OAAW,OAAO,KAAK,SAC7C,GAAI,KAAK,UAAY,SAAgB,MAAM,IAAI,MAAM,uCAAuC,EAC5F,OAAOC,EAAiB,KAAK,OAAO,EACtC,cACE,GAAI,KAAK,UAAY,OAAW,OAAO,KAAK,QAC5C,GAAI,KAAK,UAAY,SAAgB,MAAM,IAAI,MAAM,qCAAqC,EAC1F,OAAOC,EAAoB,KAAK,OAAO,EACzC,aACE,GAAI,KAAK,SAAW,OAAW,OAAO,KAAK,OAC3C,GAAI,KAAK,UAAY,SAAgB,MAAM,IAAI,MAAM,4CAA4C,EACjG,OAAOC,EAAmB,KAAK,OAAO,EACxC,eACE,GAAI,KAAK,YAAc,OAAW,OAAO,KAAK,UAC9C,GAAI,KAAK,UAAY,SAAgB,MAAM,IAAI,MAAM,uCAAuC,EAC5F,OAAOC,EAAsB,KAAK,OAAO,EAC3C,QACE,MAAM,MAAM,WAAWJ,CAAO,mBAAmB,CACrD,CACF,CACF","names":["endlessClient","EndlessConfig","settings","endlessClient","miniprogramClient","apiType","NetworkToNodeAPI","NetworkToIndexerAPI","NetworkToProverAPI","NetworkToIndexerAPIV2"]}