{"version":3,"file":"client-manager.mjs","names":[],"sources":["../../src/types/client-manager.ts"],"sourcesContent":["import algosdk, { SuggestedParams } from 'algosdk'\nimport { AlgoHttpClientWithRetry } from './algo-http-client-with-retry'\nimport { type AlgorandClient } from './algorand-client'\nimport { AppClient, AppClientParams, ResolveAppClientByCreatorAndName } from './app-client'\nimport { AppFactory, AppFactoryParams } from './app-factory'\nimport { TestNetDispenserApiClient, TestNetDispenserApiClientParams } from './dispenser-client'\nimport { Expand } from './expand'\nimport { AlgoClientConfig, AlgoConfig, NetworkDetails, genesisIdIsLocalNet } from './network-client'\nimport Kmd = algosdk.Kmd\nimport Indexer = algosdk.Indexer\nimport Algodv2 = algosdk.Algodv2\n\n/** Clients from algosdk that interact with the official Algorand APIs */\nexport interface AlgoSdkClients {\n  /** Algod client, see https://dev.algorand.co/reference/rest-api/algod/ */\n  algod: algosdk.Algodv2\n  /** Optional indexer client, see https://dev.algorand.co/reference/rest-api/indexer */\n  indexer?: algosdk.Indexer\n  /** Optional KMD client, see https://dev.algorand.co/reference/rest-api/kmd/ */\n  kmd?: algosdk.Kmd\n}\n\n/** Params to get an app factory from `ClientManager`. */\nexport type ClientAppFactoryParams = Expand<Omit<AppFactoryParams, 'algorand'>>\n\n/** Params to get an app client by creator address and name from `ClientManager`. */\nexport type ClientResolveAppClientByCreatorAndNameParams = Expand<Omit<ResolveAppClientByCreatorAndName, 'algorand'>>\n\n/** Params to get an app client by ID from `ClientManager`. */\nexport type ClientAppClientParams = Expand<Omit<AppClientParams, 'algorand'>>\n\n/** Params to get an app client by network from `ClientManager`. */\nexport type ClientAppClientByNetworkParams = Expand<Omit<AppClientParams, 'algorand' | 'appId'>>\n\n/** Params to get a typed app client by creator address and name from `ClientManager`. */\nexport type ClientTypedAppClientByCreatorAndNameParams = Expand<Omit<ResolveAppClientByCreatorAndName, 'algorand' | 'appSpec'>>\n\n/** Params to get a typed app client by ID from `ClientManager`. */\nexport type ClientTypedAppClientParams = Expand<Omit<AppClientParams, 'algorand' | 'appSpec'>>\n\n/** Params to get a typed app client by network from `ClientManager`. */\nexport type ClientTypedAppClientByNetworkParams = Expand<Omit<AppClientParams, 'algorand' | 'appSpec' | 'appId'>>\n\n/** Params to get a typed app factory from `ClientManager`. */\nexport type ClientTypedAppFactoryParams = Expand<Omit<AppFactoryParams, 'algorand' | 'appSpec'>>\n\n/** Exposes access to various API clients. */\nexport class ClientManager {\n  private _algod: algosdk.Algodv2\n  private _indexer?: algosdk.Indexer\n  private _kmd?: algosdk.Kmd\n  private _algorand?: AlgorandClient\n\n  /**\n   * algosdk clients or config for interacting with the official Algorand APIs.\n   * @param clientsOrConfig The clients or config to use\n   * @example Algod client only\n   * ```typescript\n   * const clientManager = new ClientManager({ algod: algodClient })\n   * ```\n   * @example All clients\n   * ```typescript\n   * const clientManager = new ClientManager({ algod: algodClient, indexer: indexerClient, kmd: kmdClient })\n   * ```\n   * @example Algod config only\n   * ```typescript\n   * const clientManager = new ClientManager({ algodConfig })\n   * ```\n   * @example All client configs\n   * ```typescript\n   * const clientManager = new ClientManager({ algodConfig, indexerConfig, kmdConfig })\n   * ```\n   */\n  constructor(clientsOrConfig: AlgoConfig | AlgoSdkClients, algorandClient?: AlgorandClient) {\n    const _clients =\n      'algod' in clientsOrConfig\n        ? clientsOrConfig\n        : {\n            algod: ClientManager.getAlgodClient(clientsOrConfig.algodConfig),\n            indexer: clientsOrConfig.indexerConfig ? ClientManager.getIndexerClient(clientsOrConfig.indexerConfig) : undefined,\n            kmd: clientsOrConfig.kmdConfig ? ClientManager.getKmdClient(clientsOrConfig.kmdConfig) : undefined,\n          }\n    this._algod = _clients.algod\n    this._indexer = _clients.indexer\n    this._kmd = _clients.kmd\n    this._algorand = algorandClient\n  }\n\n  /**\n   * Returns an algosdk Algod API client.\n   * @returns The Algod client\n   */\n  public get algod(): algosdk.Algodv2 {\n    return this._algod\n  }\n\n  /**\n   * Returns an algosdk Indexer API client or throws an error if it's not been provided.\n   * @returns The Indexer client\n   * @throws Error if no Indexer client is configured\n   */\n  public get indexer(): algosdk.Indexer {\n    if (!this._indexer) throw new Error('Attempt to use Indexer client in AlgoKit instance with no Indexer configured')\n    return this._indexer\n  }\n\n  /**\n   * Returns an algosdk Indexer API client or `undefined` if it's not been provided.\n   * @returns The Indexer client or `undefined`\n   */\n  public get indexerIfPresent(): algosdk.Indexer | undefined {\n    return this._indexer\n  }\n\n  /**\n   * Returns an algosdk KMD API client or throws an error if it's not been provided.\n   * @returns The KMD client\n   * @throws Error if no KMD client is configured\n   */\n  public get kmd(): algosdk.Kmd {\n    if (!this._kmd) throw new Error('Attempt to use Kmd client in AlgoKit instance with no Kmd configured')\n    return this._kmd\n  }\n\n  private _getNetworkPromise: Promise<SuggestedParams> | undefined\n  /**\n   * Get details about the current network.\n   * @example Getting genesis ID\n   * ```typescript\n   * const network = await networkClient.network()\n   * const genesisId = network.genesisId\n   * ```\n   * @returns The current network details\n   */\n  public async network(): Promise<NetworkDetails> {\n    if (!this._getNetworkPromise) {\n      this._getNetworkPromise = this._algod.getTransactionParams().do()\n    }\n\n    const params = await this._getNetworkPromise\n    return {\n      isTestNet: ['testnet-v1.0', 'testnet-v1', 'testnet'].includes(params.genesisID ?? 'unknown'),\n      isMainNet: ['mainnet-v1.0', 'mainnet-v1', 'mainnet'].includes(params.genesisID ?? 'unknown'),\n      isLocalNet: ClientManager.genesisIdIsLocalNet(params.genesisID ?? 'unknown'),\n      genesisId: params.genesisID ?? 'unknown',\n      genesisHash: params.genesisHash ? Buffer.from(params.genesisHash).toString('base64') : 'unknown',\n    }\n  }\n\n  /**\n   * Returns true if the given network genesisId is associated with a LocalNet network.\n   * @param genesisId The network genesis ID\n   * @returns Whether the given genesis ID is associated with a LocalNet network\n   * @example\n   * ```typescript\n   * const isLocalNet = ClientManager.genesisIdIsLocalNet('testnet-v1.0')\n   * ```\n   */\n  public static genesisIdIsLocalNet(genesisId: string) {\n    return genesisIdIsLocalNet(genesisId)\n  }\n\n  /**\n   * Returns true if the current network is LocalNet.\n   * @returns True if the current network is LocalNet.\n   * @example\n   * ```typescript\n   * const isLocalNet = await clientManager.isLocalNet()\n   * ```\n   */\n  public async isLocalNet() {\n    return (await this.network()).isLocalNet\n  }\n\n  /**\n   * Returns true if the current network is TestNet.\n   * @returns True if the current network is TestNet.\n   * @example\n   * ```typescript\n   * const isTestNet = await clientManager.isTestNet()\n   * ```\n   */\n  public async isTestNet() {\n    return (await this.network()).isTestNet\n  }\n\n  /**\n   * Returns true if the current network is MainNet.\n   * @returns True if the current network is MainNet.\n   * @example\n   * ```typescript\n   * const isMainNet = await clientManager.isMainNet()\n   * ```\n   */\n  public async isMainNet() {\n    return (await this.network()).isMainNet\n  }\n\n  /**\n   * Returns a TestNet Dispenser API client.\n   *\n   * Refer to [docs](https://github.com/algorandfoundation/algokit/blob/main/docs/testnet_api.md) on guidance to obtain an access token.\n   *\n   * @param params An object containing parameters for the TestNetDispenserApiClient class.\n   * @example\n   * const client = clientManager.getTestNetDispenser(\n   *     {\n   *       authToken: 'your_auth_token',\n   *       requestTimeout: 15,\n   *     }\n   * )\n   *\n   * @returns An instance of the TestNetDispenserApiClient class.\n   */\n  public getTestNetDispenser(params: TestNetDispenserApiClientParams) {\n    return new TestNetDispenserApiClient(params)\n  }\n\n  /**\n   * Returns a TestNet Dispenser API client, loading the auth token from `process.env.ALGOKIT_DISPENSER_ACCESS_TOKEN`.\n   *\n   * Refer to [docs](https://github.com/algorandfoundation/algokit/blob/main/docs/testnet_api.md) on guidance to obtain an access token.\n   *\n   * @param params An object containing parameters for the TestNetDispenserApiClient class.\n   * @example\n   * const client = clientManager.getTestNetDispenserFromEnvironment(\n   *     {\n   *       requestTimeout: 15,\n   *     }\n   * )\n   *\n   * @returns An instance of the TestNetDispenserApiClient class.\n   */\n  public getTestNetDispenserFromEnvironment(params?: Omit<TestNetDispenserApiClientParams, 'authToken'>) {\n    return new TestNetDispenserApiClient(params ? { ...params, authToken: '' } : undefined)\n  }\n\n  /**\n   * Returns a new `AppFactory` client\n   * @param params The parameters to create the app factory\n   * @example Basic example\n   * ```typescript\n   * const factory = clientManager.getAppFactory({\n   *   appSpec: '{/* ARC-56 or ARC-32 compatible JSON *\\/}',\n   * })\n   * ```\n   * @example Advanced example\n   * ```typescript\n   * const factory = clientManager.getAppFactory({\n   *   appSpec: parsedAppSpec_AppSpec_or_Arc56Contract,\n   *   defaultSender: \"SENDERADDRESS\",\n   *   appName: \"OverriddenAppName\",\n   *   version: \"2.0.0\",\n   *   updatable: true,\n   *   deletable: false,\n   *   deployTimeParams: { ONE: 1, TWO: 'value' }\n   * })\n   * ```\n   * @returns The `AppFactory` instance\n   */\n  public getAppFactory(params: ClientAppFactoryParams) {\n    if (!this._algorand) {\n      throw new Error('Attempt to get app factory from a ClientManager without an Algorand client')\n    }\n\n    return new AppFactory({ ...params, algorand: this._algorand })\n  }\n\n  /**\n   * Returns a new `AppClient` client for managing calls and state for an ARC-32/ARC-56 app.\n   * This method resolves the app ID by looking up the creator address and name\n   * using AlgoKit app deployment semantics (i.e. looking for the app creation transaction note).\n   * @param params The parameters to create the app client\n   * @example Basic\n   * ```typescript\n   * const appClient = clientManager.getAppClientByCreatorAndName({\n   *   appSpec: '{/* ARC-56 or ARC-32 compatible JSON *\\}',\n   *   // appId resolved by looking for app ID of named app by this creator\n   *   creatorAddress: 'CREATORADDRESS',\n   * })\n   * ```\n   * @returns The `AppClient` instance\n   */\n  public getAppClientByCreatorAndName(params: ClientResolveAppClientByCreatorAndNameParams) {\n    if (!this._algorand) {\n      throw new Error('Attempt to get app client from a ClientManager without an Algorand client')\n    }\n\n    return AppClient.fromCreatorAndName({\n      ...params,\n      algorand: this._algorand,\n    })\n  }\n\n  /**\n   * Returns a new `AppClient` client for managing calls and state for an ARC-32/ARC-56 app.\n   * @param params The parameters to create the app client\n   * @example Basic\n   * ```typescript\n   * const appClient = clientManager.getAppClientById({\n   *   appSpec: '{/* ARC-56 or ARC-32 compatible JSON *\\}',\n   *   appId: 12345n,\n   * })\n   * ```\n   * @returns The `AppClient` instance\n   */\n  public getAppClientById(params: ClientAppClientParams) {\n    if (!this._algorand) {\n      throw new Error('Attempt to get app client from a ClientManager without an Algorand client')\n    }\n    return new AppClient({ ...params, algorand: this._algorand })\n  }\n\n  /**\n   * Returns a new `AppClient` client for managing calls and state for an ARC-56 app.\n   * This method resolves the app ID for the current network based on\n   * pre-determined network-specific app IDs specified in the ARC-56 app spec.\n   *\n   * If no IDs are in the app spec or the network isn't recognised, an error is thrown.\n   * @param params The parameters to create the app client\n   * @example Basic\n   * ```typescript\n   * const appClient = clientManager.getAppClientByNetwork({\n   *   appSpec: '{/* ARC-56 or ARC-32 compatible JSON *\\}',\n   *   // appId resolved by using ARC-56 spec to find app ID for current network\n   * })\n   * ```\n   * @returns The `AppClient` instance\n   */\n  public async getAppClientByNetwork(params: ClientAppClientByNetworkParams) {\n    if (!this._algorand) {\n      throw new Error('Attempt to get app client from a ClientManager without an Algorand client')\n    }\n    return AppClient.fromNetwork({ ...params, algorand: this._algorand })\n  }\n\n  /**\n   * Returns a new typed client, resolving the app by creator address and name.\n   * @param typedClient The typed client type to use\n   * @param params The params to resolve the app by creator address and name\n   * @example Use name in ARC-32 / ARC-56 app spec\n   * ```typescript\n   * const appClient = clientManager.getTypedAppClientByCreatorAndName(MyContractClient, {\n   *   creatorAddress: \"CREATORADDRESS\",\n   *   defaultSender: alice,\n   * })\n   * ```\n   * @example Specify name\n   * ```typescript\n   * const appClient = clientManager.getTypedAppClientByCreatorAndName(MyContractClient, {\n   *   creatorAddress: \"CREATORADDRESS\",\n   *   name: \"contract-name\",\n   *   defaultSender: alice,\n   * })\n   * ```\n   * @returns The typed client instance\n   */\n  public async getTypedAppClientByCreatorAndName<TClient extends TypedAppClient<InstanceType<TClient>>>(\n    typedClient: TClient,\n    params: ClientTypedAppClientByCreatorAndNameParams,\n  ) {\n    if (!this._algorand) {\n      throw new Error('Attempt to get app client from a ClientManager without an Algorand client')\n    }\n\n    return typedClient.fromCreatorAndName({ ...params, algorand: this._algorand })\n  }\n\n  /**\n   * Returns a new typed client, resolving the app by app ID.\n   * @param typedClient The typed client type to use\n   * @param params The params to resolve the app by ID\n   * @example\n   * ```typescript\n   * const appClient = clientManager.getTypedAppClientById(MyContractClient, {\n   *   appId: 12345n,\n   *   defaultSender: alice,\n   * })\n   * ```\n   * @returns The typed client instance\n   */\n  public getTypedAppClientById<TClient extends TypedAppClient<InstanceType<TClient>>>(\n    typedClient: TClient,\n    params: ClientTypedAppClientParams,\n  ) {\n    if (!this._algorand) {\n      throw new Error('Attempt to get app client from a ClientManager without an Algorand client')\n    }\n\n    return new typedClient({ ...params, algorand: this._algorand })\n  }\n\n  /**\n   * Returns a new typed client, resolves the app ID for the current network based on\n   * pre-determined network-specific app IDs specified in the ARC-56 app spec.\n   *\n   * If no IDs are in the app spec or the network isn't recognised, an error is thrown.\n   * @param typedClient The typed client type to use\n   * @param params The params to resolve the app by network\n   * @example\n   * ```typescript\n   * const appClient = clientManager.getTypedAppClientByNetwork(MyContractClient, {\n   *   defaultSender: alice,\n   * })\n   * ```\n   * @returns The typed client instance\n   */\n  public getTypedAppClientByNetwork<TClient extends TypedAppClient<InstanceType<TClient>>>(\n    typedClient: TClient,\n    params?: ClientTypedAppClientByNetworkParams,\n  ) {\n    if (!this._algorand) {\n      throw new Error('Attempt to get app client from a ClientManager without an Algorand client')\n    }\n\n    return typedClient.fromNetwork({ ...params, algorand: this._algorand })\n  }\n\n  /**\n   * Returns a new typed app factory.\n   * @param typedFactory The typed factory type to use\n   * @param params The params to resolve the factory by\n   * @example\n   * ```typescript\n   * const appFactory = clientManager.getTypedAppFactory(MyContractClient, {\n   *   sender: alice,\n   * })\n   * ```\n   * @returns The typed client instance\n   */\n  public getTypedAppFactory<TClient>(typedFactory: TypedAppFactory<TClient>, params?: ClientTypedAppFactoryParams) {\n    if (!this._algorand) {\n      throw new Error('Attempt to get app factory from a ClientManager without an Algorand client')\n    }\n\n    return new typedFactory({ ...params, algorand: this._algorand })\n  }\n\n  /**\n   * Retrieve client configurations from environment variables when defined or get defaults (expects to be called from a Node.js environment)\n   *\n   * If both `process.env.INDEXER_SERVER` and `process.env.ALGOD_SERVER` is defined it will use both along with optional `process.env.ALGOD_PORT`, `process.env.ALGOD_TOKEN`, `process.env.INDEXER_PORT` and `process.env.INDEXER_TOKEN`.\n   *\n   * If only `process.env.ALGOD_SERVER` is defined it will use this along with optional `process.env.ALGOD_PORT` and `process.env.ALGOD_TOKEN` and leave indexer as `undefined`.\n   *\n   * If only `process.env.INDEXER_SERVER` is defined it will use the default (LocalNet) configuration for both algod and indexer.\n   *\n   * It will return a KMD configuration that uses `process.env.KMD_PORT` (or port 4002) if `process.env.ALGOD_SERVER` is defined,\n   * otherwise it will use the default LocalNet config unless it detects testnet or mainnet.\n   * @example\n   * ```typescript\n   * const config = ClientManager.getConfigFromEnvironmentOrLocalNet()\n   * ```\n   * @returns The config for algod, indexer and kmd\n   */\n  public static getConfigFromEnvironmentOrLocalNet(): AlgoConfig {\n    if (!process || !process.env) {\n      throw new Error('Attempt to get default client configuration from a non Node.js context; supply the config instead')\n    }\n    const [algodConfig, indexerConfig, kmdConfig] = process.env.ALGOD_SERVER\n      ? [\n          ClientManager.getAlgodConfigFromEnvironment(),\n          process.env.INDEXER_SERVER ? ClientManager.getIndexerConfigFromEnvironment() : undefined,\n          !process.env.ALGOD_SERVER.includes('mainnet') && !process.env.ALGOD_SERVER.includes('testnet')\n            ? { ...ClientManager.getAlgodConfigFromEnvironment(), port: process?.env?.KMD_PORT ?? '4002' }\n            : undefined,\n        ]\n      : [\n          ClientManager.getDefaultLocalNetConfig('algod'),\n          ClientManager.getDefaultLocalNetConfig('indexer'),\n          ClientManager.getDefaultLocalNetConfig('kmd'),\n        ]\n\n    return {\n      algodConfig,\n      indexerConfig,\n      kmdConfig,\n    }\n  }\n\n  /**\n   * Retrieve the algod configuration from environment variables (expects to be called from a Node.js environment)\n   *\n   * Expects `process.env.ALGOD_SERVER` to be defined, and you can also specify `process.env.ALGOD_PORT` and `process.env.ALGOD_TOKEN`.\n   * @returns The Algod client configuration\n   * @throws Error if `process.env.ALGOD_SERVER` is not defined\n   * @example\n   * ```typescript\n   * const config = ClientManager.getAlgodConfigFromEnvironment()\n   * ```\n   */\n  public static getAlgodConfigFromEnvironment(): AlgoClientConfig {\n    if (!process || !process.env) {\n      throw new Error('Attempt to get default algod configuration from a non Node.js context; supply the config instead')\n    }\n\n    if (!process.env.ALGOD_SERVER) {\n      throw new Error('Attempt to get default algod configuration without specifying ALGOD_SERVER in the environment variables')\n    }\n\n    return {\n      server: process.env.ALGOD_SERVER,\n      port: process.env.ALGOD_PORT,\n      token: process.env.ALGOD_TOKEN,\n    }\n  }\n\n  /**\n   * Retrieve the indexer configuration from environment variables (expects to be called from a Node.js environment).\n   *\n   * Expects `process.env.INDEXER_SERVER` to be defined, and you can also specify `process.env.INDEXER_PORT` and `process.env.INDEXER_TOKEN`.\n   * @returns The Indexer client configuration\n   * @throws Error if `process.env.INDEXER_SERVER` is not defined\n   * @example\n   * ```typescript\n   * const config = ClientManager.getIndexerConfigFromEnvironment()\n   * ```\n   */\n  public static getIndexerConfigFromEnvironment(): AlgoClientConfig {\n    if (!process || !process.env) {\n      throw new Error('Attempt to get default indexer configuration from a non Node.js context; supply the config instead')\n    }\n\n    if (!process.env.INDEXER_SERVER) {\n      throw new Error('Attempt to get default indexer configuration without specifying INDEXER_SERVER in the environment variables')\n    }\n\n    return {\n      server: process.env.INDEXER_SERVER,\n      port: process.env.INDEXER_PORT,\n      token: process.env.INDEXER_TOKEN,\n    }\n  }\n\n  /** Returns the Algorand configuration to point to the free tier of the AlgoNode service.\n   *\n   * @param network Which network to connect to - TestNet or MainNet\n   * @param config Which algod config to return - Algod or Indexer\n   * @returns The AlgoNode client configuration\n   * @example\n   * ```typescript\n   * const config = ClientManager.getAlgoNodeConfig('testnet', 'algod')\n   * ```\n   */\n  public static getAlgoNodeConfig(network: 'testnet' | 'mainnet', config: 'algod' | 'indexer'): AlgoClientConfig {\n    return {\n      server: `https://${network}-${config === 'algod' ? 'api' : 'idx'}.algonode.cloud/`,\n      port: 443,\n    }\n  }\n\n  /** Returns the Algorand configuration to point to the default LocalNet.\n   *\n   * @param configOrPort Which algod config to return - algod, kmd, or indexer OR a port number\n   * @returns The LocalNet client configuration\n   * @example\n   * ```typescript\n   * const config = ClientManager.getDefaultLocalNetConfig('algod')\n   * ```\n   */\n  public static getDefaultLocalNetConfig(configOrPort: 'algod' | 'indexer' | 'kmd' | number): AlgoClientConfig {\n    return {\n      server: `http://localhost`,\n      port: configOrPort === 'algod' ? 4001 : configOrPort === 'indexer' ? 8980 : configOrPort === 'kmd' ? 4002 : configOrPort,\n      token: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',\n    }\n  }\n\n  /**\n   * Returns an algod SDK client that automatically retries on idempotent calls.\n   *\n   * @param config The config of the client\n   * @returns The Algod client\n   * @example AlgoNode (testnet)\n   * ```typescript\n   *  const algod = ClientManager.getAlgodClient(ClientManager.getAlgoNodeConfig('testnet', 'algod'))\n   *  await algod.healthCheck().do()\n   * ```\n   * @example AlgoNode (mainnet)\n   * ```typescript\n   *  const algod = ClientManager.getAlgodClient(ClientManager.getAlgoNodeConfig('mainnet', 'algod'))\n   *  await algod.healthCheck().do()\n   * ```\n   * @example Custom (e.g. default LocalNet)\n   * ```typescript\n   *  const algod = ClientManager.getAlgodClient({server: 'http://localhost', port: '4001', token: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'})\n   *  await algod.healthCheck().do()\n   * ```\n   */\n  public static getAlgodClient(config: AlgoClientConfig): Algodv2 {\n    const { token, server, port } = config\n    const tokenHeader = typeof token === 'string' ? { 'X-Algo-API-Token': token } : (token ?? {})\n    const httpClientWithRetry = new AlgoHttpClientWithRetry(tokenHeader, server, port)\n    return new algosdk.Algodv2(httpClientWithRetry, server)\n  }\n\n  /**\n   * Returns an algod SDK client that automatically retries on idempotent calls loaded from environment variables (expects to be called from a Node.js environment).\n   *\n   * @returns The Algod client\n   * @example\n   *  ```typescript\n   *  // Uses process.env.ALGOD_SERVER, process.env.ALGOD_PORT and process.env.ALGOD_TOKEN\n   *  const algod = ClientManager.getAlgodClientFromEnvironment()\n   *  await algod.healthCheck().do()\n   *  ```\n   */\n  public static getAlgodClientFromEnvironment(): Algodv2 {\n    return ClientManager.getAlgodClient(ClientManager.getAlgodConfigFromEnvironment())\n  }\n\n  /**\n   * Returns an indexer SDK client that automatically retries on idempotent calls\n   *\n   * @param config The config of the client\n   * @returns The Indexer client\n   * @example AlgoNode (testnet)\n   * ```typescript\n   *  const indexer = ClientManager.getIndexerClient(ClientManager.getAlgoNodeConfig('testnet', 'indexer'))\n   *  await indexer.makeHealthCheck().do()\n   * ```\n   * @example AlgoNode (mainnet)\n   * ```typescript\n   *  const indexer = ClientManager.getIndexerClient(ClientManager.getAlgoNodeConfig('mainnet', 'indexer'))\n   *  await indexer.makeHealthCheck().do()\n   * ```\n   * @example Custom (e.g. default LocalNet, although we recommend loading this into a .env and using the Default option instead)\n   * ```typescript\n   *  const indexer = ClientManager.getIndexerClient({server: 'http://localhost', port: '8980', token: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'})\n   *  await indexer.makeHealthCheck().do()\n   * ```\n   */\n  public static getIndexerClient(config: AlgoClientConfig): Indexer {\n    const { token, server, port } = config\n    const tokenHeader = typeof token === 'string' ? { 'X-Indexer-API-Token': token } : (token ?? {})\n    const httpClientWithRetry = new AlgoHttpClientWithRetry(tokenHeader, server, port)\n    return new Indexer(httpClientWithRetry)\n  }\n\n  /**\n   * Returns an indexer SDK client that automatically retries on idempotent calls loaded from environment variables (expects to be called from a Node.js environment).\n   *\n   * @returns The Indexer client\n   * @example\n   *\n   *  ```typescript\n   *  // Uses process.env.INDEXER_SERVER, process.env.INDEXER_PORT and process.env.INDEXER_TOKEN\n   *  const indexer = ClientManager.getIndexerClientFromEnvironment()\n   *  await indexer.makeHealthCheck().do()\n   *  ```\n   */\n  public static getIndexerClientFromEnvironment(): Indexer {\n    return ClientManager.getIndexerClient(ClientManager.getIndexerConfigFromEnvironment())\n  }\n\n  /**\n   * Returns a KMD SDK client.\n   *\n   * KMD client allows you to export private keys, which is useful to (for instance) get the default account in a LocalNet network.\n   *\n   * @param config The config for the client\n   * @returns The KMD client\n   * @example Custom (e.g. default LocalNet, although we recommend loading this into a .env and using the Default option instead)\n   * ```typescript\n   *  const kmd = ClientManager.getKmdClient({server: 'http://localhost', port: '4002', token: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'})\n   * ```\n   */\n  public static getKmdClient(config: AlgoClientConfig): Kmd {\n    const { token, server, port } = config\n    return new Kmd(token as string, server, port)\n  }\n\n  /**\n   * Returns a KMD SDK client that automatically retries on idempotent calls loaded from environment variables (expects to be called from a Node.js environment).\n   *\n   * @returns The KMD client\n   * @example\n   *  ```typescript\n   *  // Uses process.env.ALGOD_SERVER, process.env.KMD_PORT (or if not specified: port 4002) and process.env.ALGOD_TOKEN\n   *  const kmd = ClientManager.getKmdClientFromEnvironment()\n   *  ```\n   */\n  public static getKmdClientFromEnvironment(): Kmd {\n    // We can only use Kmd on the LocalNet otherwise it's not exposed so this makes some assumptions\n    // (e.g. same token and server as algod and port 4002 by default)\n    return ClientManager.getKmdClient({ ...ClientManager.getAlgodConfigFromEnvironment(), port: process?.env?.KMD_PORT ?? '4002' })\n  }\n}\n\n/**\n * Interface to identify a typed client that can be used to interact with an application.\n */\nexport interface TypedAppClient<TClient> {\n  new (params: Omit<AppClientParams, 'appSpec'>): TClient\n  fromNetwork(params: Omit<AppClientParams, 'appId' | 'appSpec'>): Promise<TClient>\n  fromCreatorAndName(params: Omit<ResolveAppClientByCreatorAndName, 'appSpec'>): Promise<TClient>\n}\n\n/**\n * Interface to identify a typed factory that can be used to create and deploy an application.\n */\nexport interface TypedAppFactory<TClient> {\n  new (params: Omit<AppFactoryParams, 'appSpec'>): TClient\n}\n"],"mappings":";;;;;;;AAQO,IAAA,MAAM,QAAQ;AACd,IAAA,UAAU,QAAQ;;AAsCzB,IAAa,gBAAb,MAAa,cAAc;CACzB;CACA;CACA;CACA;;;;;;;;;;;;;;;;;;;;;CAsBA,YAAY,iBAA8C,gBAAiC;EACzF,MAAM,WACJ,WAAW,kBACP,kBACA;GACE,OAAO,cAAc,eAAe,gBAAgB,WAAW;GAC/D,SAAS,gBAAgB,gBAAgB,cAAc,iBAAiB,gBAAgB,aAAa,IAAI,KAAA;GACzG,KAAK,gBAAgB,YAAY,cAAc,aAAa,gBAAgB,SAAS,IAAI,KAAA;EAC3F;EACN,KAAK,SAAS,SAAS;EACvB,KAAK,WAAW,SAAS;EACzB,KAAK,OAAO,SAAS;EACrB,KAAK,YAAY;CACnB;;;;;CAMA,IAAW,QAAyB;EAClC,OAAO,KAAK;CACd;;;;;;CAOA,IAAW,UAA2B;EACpC,IAAI,CAAC,KAAK,UAAU,MAAM,IAAI,MAAM,8EAA8E;EAClH,OAAO,KAAK;CACd;;;;;CAMA,IAAW,mBAAgD;EACzD,OAAO,KAAK;CACd;;;;;;CAOA,IAAW,MAAmB;EAC5B,IAAI,CAAC,KAAK,MAAM,MAAM,IAAI,MAAM,sEAAsE;EACtG,OAAO,KAAK;CACd;CAEA;;;;;;;;;;CAUA,MAAa,UAAmC;EAC9C,IAAI,CAAC,KAAK,oBACR,KAAK,qBAAqB,KAAK,OAAO,qBAAqB,CAAC,CAAC,GAAG;EAGlE,MAAM,SAAS,MAAM,KAAK;EAC1B,OAAO;GACL,WAAW;IAAC;IAAgB;IAAc;GAAS,CAAC,CAAC,SAAS,OAAO,aAAa,SAAS;GAC3F,WAAW;IAAC;IAAgB;IAAc;GAAS,CAAC,CAAC,SAAS,OAAO,aAAa,SAAS;GAC3F,YAAY,cAAc,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