Skip to content

Commit

Permalink
Merge pull request #298 from algorandfoundation/fix-config
Browse files Browse the repository at this point in the history
fix: adjust logic for resolve config
  • Loading branch information
neilcampbell authored Jul 12, 2024
2 parents 8f804ad + c0cd55a commit 2a76b78
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 38 deletions.
29 changes: 14 additions & 15 deletions docs/code/classes/types_client_manager.ClientManager.md
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ Returns the Algorand configuration to point to the free tier of the AlgoNode ser

#### Defined in

[src/types/client-manager.ts:306](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L306)
[src/types/client-manager.ts:305](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L305)

___

Expand Down Expand Up @@ -473,7 +473,7 @@ Returns an algod SDK client that automatically retries on idempotent calls.

#### Defined in

[src/types/client-manager.ts:345](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L345)
[src/types/client-manager.ts:344](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L344)

___

Expand All @@ -497,7 +497,7 @@ Returns an algod SDK client that automatically retries on idempotent calls loade

#### Defined in

[src/types/client-manager.ts:362](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L362)
[src/types/client-manager.ts:361](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L361)

___

Expand All @@ -515,7 +515,7 @@ Expects `process.env.ALGOD_SERVER` to be defined, and you can also specify `proc

#### Defined in

[src/types/client-manager.ts:264](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L264)
[src/types/client-manager.ts:263](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L263)

___

Expand All @@ -525,12 +525,11 @@ ___

Retrieve client configurations from environment variables when defined or get defaults (expects to be called from a Node.js environment)

If `process.env.ALGOD_SERVER` is defined it will use that along with optional `process.env.ALGOD_PORT` and `process.env.ALGOD_TOKEN`.
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`.

If `process.env.INDEXER_SERVER` is defined it will use that along with optional `process.env.INDEXER_PORT` and `process.env.INDEXER_TOKEN`.
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`.

If either aren't defined it will use the default LocalNet config, noting if `process.env.ALGOD_SERVER` is specified, but
`process.env.INDEXER_SERVER` isn't then it will leave indexer as `undefined`.
If only `process.env.INDEXER_SERVER` is defined it will use the default (LocalNet) configuration for both algod and indexer.

It will return a KMD configuration that uses `process.env.KMD_PORT` (or port 4002) if `process.env.ALGOD_SERVER` is defined,
otherwise it will use the default LocalNet config unless it detects testnet or mainnet.
Expand All @@ -549,7 +548,7 @@ const config = ClientManager.getConfigFromEnvironmentOrLocalNet()

#### Defined in

[src/types/client-manager.ts:235](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L235)
[src/types/client-manager.ts:234](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L234)

___

Expand All @@ -571,7 +570,7 @@ Returns the Algorand configuration to point to the default LocalNet.

#### Defined in

[src/types/client-manager.ts:317](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L317)
[src/types/client-manager.ts:316](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L316)

___

Expand Down Expand Up @@ -621,7 +620,7 @@ Returns an indexer SDK client that automatically retries on idempotent calls

#### Defined in

[src/types/client-manager.ts:391](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L391)
[src/types/client-manager.ts:390](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L390)

___

Expand Down Expand Up @@ -651,7 +650,7 @@ Returns an indexer SDK client that automatically retries on idempotent calls loa

#### Defined in

[src/types/client-manager.ts:413](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L413)
[src/types/client-manager.ts:412](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L412)

___

Expand All @@ -669,7 +668,7 @@ Expects `process.env.INDEXER_SERVER` to be defined, and you can also specify `pr

#### Defined in

[src/types/client-manager.ts:285](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L285)
[src/types/client-manager.ts:284](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L284)

___

Expand Down Expand Up @@ -699,7 +698,7 @@ KMD client allows you to export private keys, which is useful to (for instance)

#### Defined in

[src/types/client-manager.ts:428](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L428)
[src/types/client-manager.ts:427](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L427)

___

Expand All @@ -722,4 +721,4 @@ Returns a KMD SDK client that automatically retries on idempotent calls loaded f

#### Defined in

[src/types/client-manager.ts:442](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L442)
[src/types/client-manager.ts:441](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L441)
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ Interface to identify a typed client that can be used to interact with an applic

#### Defined in

[src/types/client-manager.ts:453](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L453)
[src/types/client-manager.ts:452](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L452)
8 changes: 4 additions & 4 deletions docs/code/modules/types_client_manager.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Details to resolve an app client by creator address and name.

#### Defined in

[src/types/client-manager.ts:459](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L459)
[src/types/client-manager.ts:458](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L458)

___

Expand All @@ -43,7 +43,7 @@ Details to resolve an app client by app ID.

#### Defined in

[src/types/client-manager.ts:471](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L471)
[src/types/client-manager.ts:470](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L470)

___

Expand All @@ -55,7 +55,7 @@ Details to resolve a typed app creator address and name.

#### Defined in

[src/types/client-manager.ts:466](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L466)
[src/types/client-manager.ts:465](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L465)

___

Expand All @@ -67,4 +67,4 @@ Details to resolve a typed app by app ID.

#### Defined in

[src/types/client-manager.ts:476](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L476)
[src/types/client-manager.ts:475](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/client-manager.ts#L475)
35 changes: 17 additions & 18 deletions src/types/client-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,11 @@ export class ClientManager {
/**
* Retrieve client configurations from environment variables when defined or get defaults (expects to be called from a Node.js environment)
*
* If `process.env.ALGOD_SERVER` is defined it will use that along with optional `process.env.ALGOD_PORT` and `process.env.ALGOD_TOKEN`.
* 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`.
*
* If `process.env.INDEXER_SERVER` is defined it will use that along with optional `process.env.INDEXER_PORT` and `process.env.INDEXER_TOKEN`.
* 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`.
*
* If either aren't defined it will use the default LocalNet config, noting if `process.env.ALGOD_SERVER` is specified, but
* `process.env.INDEXER_SERVER` isn't then it will leave indexer as `undefined`.
* If only `process.env.INDEXER_SERVER` is defined it will use the default (LocalNet) configuration for both algod and indexer.
*
* It will return a KMD configuration that uses `process.env.KMD_PORT` (or port 4002) if `process.env.ALGOD_SERVER` is defined,
* otherwise it will use the default LocalNet config unless it detects testnet or mainnet.
Expand All @@ -236,24 +235,24 @@ export class ClientManager {
if (!process || !process.env) {
throw new Error('Attempt to get default client configuration from a non Node.js context; supply the config instead')
}
const algodConfig = !process.env.ALGOD_SERVER
? ClientManager.getDefaultLocalNetConfig('algod')
: ClientManager.getAlgodConfigFromEnvironment()

const indexerConfig = !process.env.INDEXER_SERVER
? ClientManager.getDefaultLocalNetConfig('indexer')
: !process.env.ALGOD_SERVER
? ClientManager.getIndexerConfigFromEnvironment()
: undefined
const [algodConfig, indexerConfig, kmdConfig] = process.env.ALGOD_SERVER
? [
ClientManager.getAlgodConfigFromEnvironment(),
process.env.INDEXER_SERVER ? ClientManager.getIndexerConfigFromEnvironment() : undefined,
!process.env.ALGOD_SERVER.includes('mainnet') && !process.env.ALGOD_SERVER.includes('testnet')
? { ...ClientManager.getAlgodConfigFromEnvironment(), port: process?.env?.KMD_PORT ?? '4002' }
: undefined,
]
: [
ClientManager.getDefaultLocalNetConfig('algod'),
ClientManager.getDefaultLocalNetConfig('indexer'),
ClientManager.getDefaultLocalNetConfig('kmd'),
]

return {
algodConfig,
indexerConfig,
kmdConfig: process.env.ALGOD_SERVER
? process.env.ALGOD_SERVER.includes('mainnet') || process.env.ALGOD_SERVER.includes('testnet')
? undefined
: { ...algodConfig, port: process?.env?.KMD_PORT ?? '4002' }
: ClientManager.getDefaultLocalNetConfig('kmd'),
kmdConfig,
}
}

Expand Down

0 comments on commit 2a76b78

Please sign in to comment.