@algorandfoundation/algokit-utils 1.0.0-beta.6 → 1.0.0-beta.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{dist/index.js → index.js} +1 -0
- package/package.json +3 -94
- package/LICENSE +0 -21
- package/README.md +0 -31
- package/dist/account.d.ts +0 -87
- package/dist/account.d.ts.map +0 -1
- package/dist/account.js +0 -144
- package/dist/account.js.map +0 -1
- package/dist/algo-amount.d.ts +0 -18
- package/dist/algo-amount.d.ts.map +0 -1
- package/dist/algo-amount.js +0 -31
- package/dist/algo-amount.js.map +0 -1
- package/dist/algo-http-client-with-retry.d.ts +0 -14
- package/dist/algo-http-client-with-retry.d.ts.map +0 -1
- package/dist/algo-http-client-with-retry.js +0 -62
- package/dist/algo-http-client-with-retry.js.map +0 -1
- package/dist/app.d.ts +0 -189
- package/dist/app.d.ts.map +0 -1
- package/dist/app.js +0 -265
- package/dist/app.js.map +0 -1
- package/dist/application-client.d.ts +0 -108
- package/dist/application-client.d.ts.map +0 -1
- package/dist/application-client.js +0 -252
- package/dist/application-client.js.map +0 -1
- package/dist/config.d.ts +0 -27
- package/dist/config.d.ts.map +0 -1
- package/dist/config.js +0 -46
- package/dist/config.js.map +0 -1
- package/dist/deploy-app.d.ts +0 -159
- package/dist/deploy-app.d.ts.map +0 -1
- package/dist/deploy-app.js +0 -416
- package/dist/deploy-app.js.map +0 -1
- package/dist/index.d.ts +0 -11
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/indexer-lookup.d.ts +0 -31
- package/dist/indexer-lookup.d.ts.map +0 -1
- package/dist/indexer-lookup.js +0 -96
- package/dist/indexer-lookup.js.map +0 -1
- package/dist/localnet.d.ts +0 -54
- package/dist/localnet.d.ts.map +0 -1
- package/dist/localnet.js +0 -121
- package/dist/localnet.js.map +0 -1
- package/dist/network-client.d.ts +0 -102
- package/dist/network-client.d.ts.map +0 -1
- package/dist/network-client.js +0 -182
- package/dist/network-client.js.map +0 -1
- package/dist/package.json +0 -20
- package/dist/transaction.d.ts +0 -157
- package/dist/transaction.d.ts.map +0 -1
- package/dist/transaction.js +0 -306
- package/dist/transaction.js.map +0 -1
- package/dist/transfer.d.ts +0 -24
- package/dist/transfer.d.ts.map +0 -1
- package/dist/transfer.js +0 -33
- package/dist/transfer.js.map +0 -1
- package/dist/types/algod.d.ts +0 -124
- package/dist/types/algod.d.ts.map +0 -1
- package/dist/types/algod.js +0 -3
- package/dist/types/algod.js.map +0 -1
- package/dist/types/appspec.d.ts +0 -79
- package/dist/types/appspec.d.ts.map +0 -1
- package/dist/types/appspec.js +0 -15
- package/dist/types/appspec.js.map +0 -1
- package/dist/types/indexer.d.ts +0 -314
- package/dist/types/indexer.d.ts.map +0 -1
- package/dist/types/indexer.js +0 -25
- package/dist/types/indexer.js.map +0 -1
- package/dist/urlTokenBaseHTTPClient.d.ts +0 -41
- package/dist/urlTokenBaseHTTPClient.d.ts.map +0 -1
- package/dist/urlTokenBaseHTTPClient.js +0 -151
- package/dist/urlTokenBaseHTTPClient.js.map +0 -1
|
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./account"), exports);
|
|
18
18
|
__exportStar(require("./algo-amount"), exports);
|
|
19
19
|
__exportStar(require("./app"), exports);
|
|
20
|
+
__exportStar(require("./application-client"), exports);
|
|
20
21
|
__exportStar(require("./config"), exports);
|
|
21
22
|
__exportStar(require("./deploy-app"), exports);
|
|
22
23
|
__exportStar(require("./indexer-lookup"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
{
|
|
2
|
+
"main": "index.js",
|
|
3
|
+
"types": "index.d.ts",
|
|
2
4
|
"name": "@algorandfoundation/algokit-utils",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
5
|
+
"version": "1.0.0-beta.8",
|
|
4
6
|
"private": false,
|
|
5
7
|
"description": "A set of core Algorand utilities written in TypeScript and released via npm that make it easier to build solutions on Algorand.",
|
|
6
8
|
"author": "Algorand Foundation",
|
|
@@ -8,104 +10,11 @@
|
|
|
8
10
|
"engines": {
|
|
9
11
|
"node": ">=16.0"
|
|
10
12
|
},
|
|
11
|
-
"main": "./dist/index.js",
|
|
12
13
|
"files": [
|
|
13
14
|
"dist/**/*"
|
|
14
15
|
],
|
|
15
|
-
"scripts": {
|
|
16
|
-
"build": "run-s build:*",
|
|
17
|
-
"build:0-clean": "rimraf dist coverage",
|
|
18
|
-
"build:1-compile": "tsc -p tsconfig.build.json",
|
|
19
|
-
"build:2-copy-pkg-json": "npx --yes @makerx/ts-toolkit@latest copy-package-json",
|
|
20
|
-
"test": "jest --coverage --passWithNoTests",
|
|
21
|
-
"lint": "eslint ./src/ --ext .ts",
|
|
22
|
-
"lint:fix": "eslint ./src/ --ext .ts --fix",
|
|
23
|
-
"check-types": "tsc --noEmit",
|
|
24
|
-
"audit": "npm audit",
|
|
25
|
-
"format": "prettier --write .",
|
|
26
|
-
"commit-lint": "commitlint --edit -o",
|
|
27
|
-
"semantic-release": "semantic-release",
|
|
28
|
-
"generate:code-docs": "typedoc"
|
|
29
|
-
},
|
|
30
16
|
"dependencies": {
|
|
31
17
|
"algosdk": "^2.1.0",
|
|
32
18
|
"buffer": "^6.0.3"
|
|
33
|
-
},
|
|
34
|
-
"devDependencies": {
|
|
35
|
-
"@commitlint/cli": "^17.4.3",
|
|
36
|
-
"@commitlint/config-conventional": "^17.4.3",
|
|
37
|
-
"@makerx/eslint-config": "3.0.0",
|
|
38
|
-
"@makerx/prettier-config": "2.0.0",
|
|
39
|
-
"@makerx/ts-config": "1.0.1",
|
|
40
|
-
"@tsconfig/node16": "^1.0.3",
|
|
41
|
-
"@types/jest": "^29.2.3",
|
|
42
|
-
"@types/uuid": "^9.0.1",
|
|
43
|
-
"conventional-changelog-conventionalcommits": "^5.0.0",
|
|
44
|
-
"eslint": "8.36.0",
|
|
45
|
-
"npm-run-all": "^4.1.5",
|
|
46
|
-
"prettier": "2.8.4",
|
|
47
|
-
"rimraf": "^4.4.0",
|
|
48
|
-
"semantic-release": "^20.1.0",
|
|
49
|
-
"tiny-invariant": "^1.3.1",
|
|
50
|
-
"ts-jest": "^29.0.3",
|
|
51
|
-
"ts-node": "^10.9.1",
|
|
52
|
-
"typedoc": "^0.23.26",
|
|
53
|
-
"typedoc-plugin-markdown": "^3.14.0",
|
|
54
|
-
"typescript": "^4.9.3",
|
|
55
|
-
"uuid": "^9.0.0"
|
|
56
|
-
},
|
|
57
|
-
"release": {
|
|
58
|
-
"branches": [
|
|
59
|
-
{
|
|
60
|
-
"name": "main",
|
|
61
|
-
"prerelease": "beta"
|
|
62
|
-
},
|
|
63
|
-
{
|
|
64
|
-
"name": "release"
|
|
65
|
-
}
|
|
66
|
-
],
|
|
67
|
-
"plugins": [
|
|
68
|
-
[
|
|
69
|
-
"@semantic-release/commit-analyzer",
|
|
70
|
-
{
|
|
71
|
-
"preset": "conventionalcommits",
|
|
72
|
-
"releaseRules": [
|
|
73
|
-
{
|
|
74
|
-
"type": "build",
|
|
75
|
-
"release": "patch"
|
|
76
|
-
},
|
|
77
|
-
{
|
|
78
|
-
"type": "chore",
|
|
79
|
-
"release": "patch"
|
|
80
|
-
}
|
|
81
|
-
]
|
|
82
|
-
}
|
|
83
|
-
],
|
|
84
|
-
[
|
|
85
|
-
"@semantic-release/release-notes-generator",
|
|
86
|
-
{
|
|
87
|
-
"preset": "conventionalcommits",
|
|
88
|
-
"presetConfig": {
|
|
89
|
-
"types": [
|
|
90
|
-
{
|
|
91
|
-
"type": "feat",
|
|
92
|
-
"section": "Features"
|
|
93
|
-
},
|
|
94
|
-
{
|
|
95
|
-
"type": "fix",
|
|
96
|
-
"section": "Bug Fixes"
|
|
97
|
-
},
|
|
98
|
-
{
|
|
99
|
-
"type": "build",
|
|
100
|
-
"section": "Dependencies and Other Build Updates",
|
|
101
|
-
"hidden": false
|
|
102
|
-
}
|
|
103
|
-
]
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
],
|
|
107
|
-
"@semantic-release/npm",
|
|
108
|
-
"@semantic-release/github"
|
|
109
|
-
]
|
|
110
19
|
}
|
|
111
20
|
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2022 Algorand Foundation
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
package/README.md
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
# AlgoKit TypeScript Utilities
|
|
2
|
-
|
|
3
|
-
A set of core Algorand utilities written in TypeScript and released via npm that make it easier to build solutions on Algorand. This project is part of [AlgoKit](https://github.com/algorandfoundation/algokit-cli).
|
|
4
|
-
|
|
5
|
-
The goal of this library is to provide intuitive, productive utility functions that make it easier, quicker and safer to build applications on Algorand. Largely these functions wrap the underlying Algorand SDK, but provide a higher level interface with sensible defaults and capabilities for common tasks.
|
|
6
|
-
|
|
7
|
-
Note: If you prefer Python there's an equivalent [Python utility library](https://github.com/algorandfoundation/algokit-utils-py).
|
|
8
|
-
|
|
9
|
-
[Install](#install) | [Documentation](docs/README.md)
|
|
10
|
-
|
|
11
|
-
## Install
|
|
12
|
-
|
|
13
|
-
This library can be installed from NPM using your favourite npm client, e.g.:
|
|
14
|
-
|
|
15
|
-
```
|
|
16
|
-
npm install @algorandfoundation/algokit-utils
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
## Guiding principles
|
|
20
|
-
|
|
21
|
-
This library follows the [Guiding Principles of AlgoKit](https://github.com/algorandfoundation/algokit-cli#guiding-principles).
|
|
22
|
-
|
|
23
|
-
## Contributing
|
|
24
|
-
|
|
25
|
-
This is an open source project managed by the Algorand Foundation. See the [AlgoKit contributing page](https://github.com/algorandfoundation/algokit-cli/blob/main/CONTRIBUTING.MD) to learn about making improvements.
|
|
26
|
-
|
|
27
|
-
To successfully run the tests in this repository you need to be running LocalNet via [AlgoKit](https://github.com/algorandfoundation/algokit-cli):
|
|
28
|
-
|
|
29
|
-
```
|
|
30
|
-
algokit localnet start
|
|
31
|
-
```
|
package/dist/account.d.ts
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import algosdk, { Account, Algodv2, Kmd } from 'algosdk';
|
|
2
|
-
import { AlgoAmount } from './algo-amount';
|
|
3
|
-
import { SigningAccount } from './transaction';
|
|
4
|
-
/**
|
|
5
|
-
* The account name identifier used for fund dispensing in test environments
|
|
6
|
-
*/
|
|
7
|
-
export declare const DISPENSER_ACCOUNT = "DISPENSER";
|
|
8
|
-
/** Returns an Algorand account with secret key loaded (i.e. that can sign transactions) by taking the mnemonic secret.
|
|
9
|
-
*
|
|
10
|
-
* This is a wrapper around algosdk.mnemonicToSecretKey to provide a more friendly/obvious name.
|
|
11
|
-
*
|
|
12
|
-
* @param mnemonicSecret The mnemonic secret representing the private key of an account; **Note: Be careful how the mnemonic is handled**,
|
|
13
|
-
* never commit it into source control and ideally load it from the environment (ideally via a secret storage service) rather than the file system.
|
|
14
|
-
*/
|
|
15
|
-
export declare function getAccountFromMnemonic(mnemonicSecret: string): Account;
|
|
16
|
-
/**
|
|
17
|
-
* Returns an Algorand account with private key loaded by convention based on the given name identifier.
|
|
18
|
-
*
|
|
19
|
-
* Note: This function expects to run in a Node.js environment.
|
|
20
|
-
*
|
|
21
|
-
* ## Convention:
|
|
22
|
-
* * **Non-LocalNet:** will load process.env['{NAME}_MNEMONIC'] as a mnemonic secret; **Note: Be careful how the mnemonic is handled**,
|
|
23
|
-
* never commit it into source control and ideally load it via a secret storage service rather than the file system.
|
|
24
|
-
* If process.env['{NAME}_SENDER'] is defined then it will use that for the sender address (i.e. to support rekeyed accounts)
|
|
25
|
-
* * **LocalNet:** will load the account from a KMD wallet called {NAME} and if that wallet doesn't exist it will create it and fund the account for you
|
|
26
|
-
*
|
|
27
|
-
* This allows you to write code that will work seamlessly in production and local development (LocalNet) without manual config locally (including when you reset the LocalNet).
|
|
28
|
-
*
|
|
29
|
-
* @example Default
|
|
30
|
-
*
|
|
31
|
-
* If you have a mnemonic secret loaded into `process.env.ACCOUNT_MNEMONIC` then you can call the following to get that private key loaded into an account object:
|
|
32
|
-
* ```
|
|
33
|
-
* const account = await getAccount('ACCOUNT', algod)
|
|
34
|
-
* ```
|
|
35
|
-
*
|
|
36
|
-
* If that code runs against LocalNet then a wallet called `ACCOUNT` will automatically be created with an account that is automatically funded with 1000 (default) ALGOs from the default LocalNet dispenser.
|
|
37
|
-
*
|
|
38
|
-
* @param account The details of the account to get, wither the name identifier (string) or an object with:
|
|
39
|
-
* * `name`: The name identifier of the account
|
|
40
|
-
* * `fundWith`: The amount to fund the account with it it gets created (when targeting LocalNet), if not specified then 1000 Algos will be funded from the dispenser account @see {getDispenserAccount}
|
|
41
|
-
* @param algod An algod client
|
|
42
|
-
* @param kmdClient An optional KMD client to use to create an account (when targeting LocalNet), if not specified then a default KMD client will be loaded from environment variables @see {getAlgoKmdClient}
|
|
43
|
-
* @returns The requested account with private key loaded from the environment variables or when targeting LocalNet from KMD (idempotently creating and funding the account)
|
|
44
|
-
*/
|
|
45
|
-
export declare function getAccount(account: {
|
|
46
|
-
name: string;
|
|
47
|
-
fundWith?: AlgoAmount;
|
|
48
|
-
} | string, algod: Algodv2, kmdClient?: Kmd): Promise<Account | SigningAccount>;
|
|
49
|
-
/**
|
|
50
|
-
* Parameters for the getTestAccount function.
|
|
51
|
-
*/
|
|
52
|
-
interface GetTestAccountParams {
|
|
53
|
-
/** Initial funds to ensure the account has */
|
|
54
|
-
initialFunds: AlgoAmount;
|
|
55
|
-
/** Whether to suppress the log (which includes a mnemonic) or not (default: do not supress the log) */
|
|
56
|
-
suppressLog?: boolean;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Creates an ephemeral Algorand account for the purposes of testing.
|
|
60
|
-
* Returns a newly created random test account that is funded from the dispenser @see {getDispenserAccount}
|
|
61
|
-
* DO NOT USE THIS TO CREATE A MAINNET ACCOUNT!
|
|
62
|
-
* Note: By default this will log the mnemonic of the account.
|
|
63
|
-
* @param param0 The config for the test account to generate
|
|
64
|
-
* @param algod An algod client
|
|
65
|
-
* @returns The account, with private key loaded
|
|
66
|
-
*/
|
|
67
|
-
export declare function getTestAccount({ suppressLog, initialFunds }: GetTestAccountParams, algod: Algodv2): Promise<Account>;
|
|
68
|
-
/** Returns an account's address as a byte array
|
|
69
|
-
*
|
|
70
|
-
* @param account Either an account (with private key loaded) or the string address of an account
|
|
71
|
-
*/
|
|
72
|
-
export declare function getAccountAddressAsUint8Array(account: Account | string): Uint8Array;
|
|
73
|
-
/** Returns the string address of an Algorand account from a base64 encoded version of the underlying byte array of the address public key
|
|
74
|
-
*
|
|
75
|
-
* @param addressEncodedInB64 The base64 encoded version of the underlying byte array of the address public key
|
|
76
|
-
*/
|
|
77
|
-
export declare function getAccountAddressAsString(addressEncodedInB64: string): string;
|
|
78
|
-
/** Returns an account (with private key loaded) that can act as a dispenser
|
|
79
|
-
*
|
|
80
|
-
* If running on Sandbox then it will return the default dispenser account automatically,
|
|
81
|
-
* otherwise it will load the account mnemonic stored in process.env.DISPENSER_MNEMONIC @see {getAccount}
|
|
82
|
-
*
|
|
83
|
-
* @param algod An algod client
|
|
84
|
-
*/
|
|
85
|
-
export declare function getDispenserAccount(algod: Algodv2): Promise<algosdk.Account | SigningAccount>;
|
|
86
|
-
export {};
|
|
87
|
-
//# sourceMappingURL=account.d.ts.map
|
package/dist/account.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"account.d.ts","sourceRoot":"","sources":["../src/account.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,SAAS,CAAA;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAI1C,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAG9C;;GAEG;AACH,eAAO,MAAM,iBAAiB,cAAc,CAAA;AAE5C;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAGtE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAsB,UAAU,CAC9B,OAAO,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,UAAU,CAAA;CAAE,GAAG,MAAM,EACzD,KAAK,EAAE,OAAO,EACd,SAAS,CAAC,EAAE,GAAG,GACd,OAAO,CAAC,OAAO,GAAG,cAAc,CAAC,CAmCnC;AAED;;GAEG;AACH,UAAU,oBAAoB;IAC5B,8CAA8C;IAC9C,YAAY,EAAE,UAAU,CAAA;IACxB,uGAAuG;IACvG,WAAW,CAAC,EAAE,OAAO,CAAA;CACtB;AAED;;;;;;;;GAQG;AACH,wBAAsB,cAAc,CAAC,EAAE,WAAW,EAAE,YAAY,EAAE,EAAE,oBAAoB,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAmB1H;AAED;;;GAGG;AACH,wBAAgB,6BAA6B,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,cAEtE;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,mBAAmB,EAAE,MAAM,GAAG,MAAM,CAE7E;AAED;;;;;;GAMG;AACH,wBAAsB,mBAAmB,CAAC,KAAK,EAAE,OAAO,6CAIvD"}
|
package/dist/account.js
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getDispenserAccount = exports.getAccountAddressAsString = exports.getAccountAddressAsUint8Array = exports.getTestAccount = exports.getAccount = exports.getAccountFromMnemonic = exports.DISPENSER_ACCOUNT = void 0;
|
|
7
|
-
const algosdk_1 = __importDefault(require("algosdk"));
|
|
8
|
-
const config_1 = require("./config");
|
|
9
|
-
const localnet_1 = require("./localnet");
|
|
10
|
-
const network_client_1 = require("./network-client");
|
|
11
|
-
const transaction_1 = require("./transaction");
|
|
12
|
-
const transfer_1 = require("./transfer");
|
|
13
|
-
/**
|
|
14
|
-
* The account name identifier used for fund dispensing in test environments
|
|
15
|
-
*/
|
|
16
|
-
exports.DISPENSER_ACCOUNT = 'DISPENSER';
|
|
17
|
-
/** Returns an Algorand account with secret key loaded (i.e. that can sign transactions) by taking the mnemonic secret.
|
|
18
|
-
*
|
|
19
|
-
* This is a wrapper around algosdk.mnemonicToSecretKey to provide a more friendly/obvious name.
|
|
20
|
-
*
|
|
21
|
-
* @param mnemonicSecret The mnemonic secret representing the private key of an account; **Note: Be careful how the mnemonic is handled**,
|
|
22
|
-
* never commit it into source control and ideally load it from the environment (ideally via a secret storage service) rather than the file system.
|
|
23
|
-
*/
|
|
24
|
-
function getAccountFromMnemonic(mnemonicSecret) {
|
|
25
|
-
// This method is confusingly named, so this function provides a more dev friendly "wrapper" name
|
|
26
|
-
return algosdk_1.default.mnemonicToSecretKey(mnemonicSecret);
|
|
27
|
-
}
|
|
28
|
-
exports.getAccountFromMnemonic = getAccountFromMnemonic;
|
|
29
|
-
/**
|
|
30
|
-
* Returns an Algorand account with private key loaded by convention based on the given name identifier.
|
|
31
|
-
*
|
|
32
|
-
* Note: This function expects to run in a Node.js environment.
|
|
33
|
-
*
|
|
34
|
-
* ## Convention:
|
|
35
|
-
* * **Non-LocalNet:** will load process.env['{NAME}_MNEMONIC'] as a mnemonic secret; **Note: Be careful how the mnemonic is handled**,
|
|
36
|
-
* never commit it into source control and ideally load it via a secret storage service rather than the file system.
|
|
37
|
-
* If process.env['{NAME}_SENDER'] is defined then it will use that for the sender address (i.e. to support rekeyed accounts)
|
|
38
|
-
* * **LocalNet:** will load the account from a KMD wallet called {NAME} and if that wallet doesn't exist it will create it and fund the account for you
|
|
39
|
-
*
|
|
40
|
-
* This allows you to write code that will work seamlessly in production and local development (LocalNet) without manual config locally (including when you reset the LocalNet).
|
|
41
|
-
*
|
|
42
|
-
* @example Default
|
|
43
|
-
*
|
|
44
|
-
* If you have a mnemonic secret loaded into `process.env.ACCOUNT_MNEMONIC` then you can call the following to get that private key loaded into an account object:
|
|
45
|
-
* ```
|
|
46
|
-
* const account = await getAccount('ACCOUNT', algod)
|
|
47
|
-
* ```
|
|
48
|
-
*
|
|
49
|
-
* If that code runs against LocalNet then a wallet called `ACCOUNT` will automatically be created with an account that is automatically funded with 1000 (default) ALGOs from the default LocalNet dispenser.
|
|
50
|
-
*
|
|
51
|
-
* @param account The details of the account to get, wither the name identifier (string) or an object with:
|
|
52
|
-
* * `name`: The name identifier of the account
|
|
53
|
-
* * `fundWith`: The amount to fund the account with it it gets created (when targeting LocalNet), if not specified then 1000 Algos will be funded from the dispenser account @see {getDispenserAccount}
|
|
54
|
-
* @param algod An algod client
|
|
55
|
-
* @param kmdClient An optional KMD client to use to create an account (when targeting LocalNet), if not specified then a default KMD client will be loaded from environment variables @see {getAlgoKmdClient}
|
|
56
|
-
* @returns The requested account with private key loaded from the environment variables or when targeting LocalNet from KMD (idempotently creating and funding the account)
|
|
57
|
-
*/
|
|
58
|
-
async function getAccount(account, algod, kmdClient) {
|
|
59
|
-
let name;
|
|
60
|
-
let fundWith = undefined;
|
|
61
|
-
if (typeof account === 'string') {
|
|
62
|
-
name = account;
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
name = account.name;
|
|
66
|
-
fundWith = account.fundWith;
|
|
67
|
-
}
|
|
68
|
-
if (!process || !process.env) {
|
|
69
|
-
throw new Error('Attempt to get account with private key from a non Node.js context; not supported!');
|
|
70
|
-
}
|
|
71
|
-
const envKey = `${name.toUpperCase()}_MNEMONIC`;
|
|
72
|
-
if (process.env[envKey]) {
|
|
73
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
74
|
-
const signer = getAccountFromMnemonic(process.env[envKey]);
|
|
75
|
-
const senderKey = `${name.toUpperCase()}_SENDER`;
|
|
76
|
-
if (process.env[senderKey]) {
|
|
77
|
-
config_1.AlgoKitConfig.logger.debug(`Using rekeyed account ${signer.addr} for sender ${process.env[senderKey]} for ${name} account`);
|
|
78
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
79
|
-
return new transaction_1.SigningAccount(signer, process.env[senderKey]);
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
return signer;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
if (await (0, network_client_1.isLocalNet)(algod)) {
|
|
86
|
-
const account = await (0, localnet_1.getOrCreateKmdWalletAccount)({ name, fundWith }, algod, kmdClient);
|
|
87
|
-
process.env[envKey] = algosdk_1.default.secretKeyToMnemonic(account.sk);
|
|
88
|
-
return account;
|
|
89
|
-
}
|
|
90
|
-
throw `Missing environment variable ${envKey} when looking for account ${name}`;
|
|
91
|
-
}
|
|
92
|
-
exports.getAccount = getAccount;
|
|
93
|
-
/**
|
|
94
|
-
* Creates an ephemeral Algorand account for the purposes of testing.
|
|
95
|
-
* Returns a newly created random test account that is funded from the dispenser @see {getDispenserAccount}
|
|
96
|
-
* DO NOT USE THIS TO CREATE A MAINNET ACCOUNT!
|
|
97
|
-
* Note: By default this will log the mnemonic of the account.
|
|
98
|
-
* @param param0 The config for the test account to generate
|
|
99
|
-
* @param algod An algod client
|
|
100
|
-
* @returns The account, with private key loaded
|
|
101
|
-
*/
|
|
102
|
-
async function getTestAccount({ suppressLog, initialFunds }, algod) {
|
|
103
|
-
const account = algosdk_1.default.generateAccount();
|
|
104
|
-
config_1.AlgoKitConfig.getLogger(suppressLog).info(`New test account created with address '${account.addr}' and mnemonic '${algosdk_1.default.secretKeyToMnemonic(account.sk)}'.`);
|
|
105
|
-
// If we are running against LocalNet we can use the default account within it
|
|
106
|
-
// otherwise use an automation account specified via environment variables and ensure it's populated with ALGOs
|
|
107
|
-
const canFundFromDefaultAccount = await (0, network_client_1.isLocalNet)(algod);
|
|
108
|
-
const dispenser = canFundFromDefaultAccount ? await (0, localnet_1.getLocalNetDispenserAccount)(algod) : await getAccount(exports.DISPENSER_ACCOUNT, algod);
|
|
109
|
-
await (0, transfer_1.transferAlgos)({ from: dispenser, to: account.addr, amount: initialFunds, note: 'Funding test account', suppressLog }, algod);
|
|
110
|
-
const accountInfo = await algod.accountInformation(account.addr).do();
|
|
111
|
-
config_1.AlgoKitConfig.getLogger(suppressLog).info('Test account funded; account balance: %d µAlgos', accountInfo.amount);
|
|
112
|
-
return account;
|
|
113
|
-
}
|
|
114
|
-
exports.getTestAccount = getTestAccount;
|
|
115
|
-
/** Returns an account's address as a byte array
|
|
116
|
-
*
|
|
117
|
-
* @param account Either an account (with private key loaded) or the string address of an account
|
|
118
|
-
*/
|
|
119
|
-
function getAccountAddressAsUint8Array(account) {
|
|
120
|
-
return algosdk_1.default.decodeAddress(typeof account === 'string' ? account : account.addr).publicKey;
|
|
121
|
-
}
|
|
122
|
-
exports.getAccountAddressAsUint8Array = getAccountAddressAsUint8Array;
|
|
123
|
-
/** Returns the string address of an Algorand account from a base64 encoded version of the underlying byte array of the address public key
|
|
124
|
-
*
|
|
125
|
-
* @param addressEncodedInB64 The base64 encoded version of the underlying byte array of the address public key
|
|
126
|
-
*/
|
|
127
|
-
function getAccountAddressAsString(addressEncodedInB64) {
|
|
128
|
-
return algosdk_1.default.encodeAddress(Buffer.from(addressEncodedInB64, 'base64'));
|
|
129
|
-
}
|
|
130
|
-
exports.getAccountAddressAsString = getAccountAddressAsString;
|
|
131
|
-
/** Returns an account (with private key loaded) that can act as a dispenser
|
|
132
|
-
*
|
|
133
|
-
* If running on Sandbox then it will return the default dispenser account automatically,
|
|
134
|
-
* otherwise it will load the account mnemonic stored in process.env.DISPENSER_MNEMONIC @see {getAccount}
|
|
135
|
-
*
|
|
136
|
-
* @param algod An algod client
|
|
137
|
-
*/
|
|
138
|
-
async function getDispenserAccount(algod) {
|
|
139
|
-
// If we are running against a sandbox we can use the default account within it, otherwise use an automation account specified via environment variables and ensure it's populated with ALGOs
|
|
140
|
-
const canFundFromDefaultAccount = await (0, network_client_1.isLocalNet)(algod);
|
|
141
|
-
return canFundFromDefaultAccount ? await (0, localnet_1.getLocalNetDispenserAccount)(algod) : await getAccount(exports.DISPENSER_ACCOUNT, algod);
|
|
142
|
-
}
|
|
143
|
-
exports.getDispenserAccount = getDispenserAccount;
|
|
144
|
-
//# sourceMappingURL=account.js.map
|
package/dist/account.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"account.js","sourceRoot":"","sources":["../src/account.ts"],"names":[],"mappings":";;;;;;AAAA,sDAAwD;AAExD,qCAAwC;AACxC,yCAAqF;AACrF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AE,EAAE,KAAK,CAAC,CAAA;IAElI,MAAM,WAAW,GAAG,MAAM,KAAK,CAAC,kBAAkB,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,CAAA;IAErE,sBAAa,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,iDAAiD,EAAE,WAAW,CAAC,MAAM,CAAC,CAAA;IAEhH,OAAO,OAAO,CAAA;AAChB,CAAC;AAnBD,wCAmBC;AAED;;;GAGG;AACH,SAAgB,6BAA6B,CAAC,OAAyB;IACrE,OAAO,iBAAO,CAAC,aAAa,CAAC,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,SAAS,CAAA;AAC9F,CAAC;AAFD,sEAEC;AAED;;;GAGG;AACH,SAAgB,yBAAyB,CAAC,mBAA2B;IACnE,OAAO,iBAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,mBAAmB,EAAE,QAAQ,CAAC,CAAC,CAAA;AAC1E,CAAC;AAFD,8DAEC;AAED;;;;;;GAMG;AACI,KAAK,UAAU,mBAAmB,CAAC,KAAc;IACtD,6LAA6L;IAC7L,MAAM,yBAAyB,GAAG,MAAM,IAAA,2BAAU,EAAC,KAAK,CAAC,CAAA;IACzD,OAAO,yBAAyB,CAAC,CAAC,CAAC,MAAM,IAAA,sCAA2B,EAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,UAAU,CAAC,yBAAiB,EAAE,KAAK,CAAC,CAAA;AAC1H,CAAC;AAJD,kDAIC"}
|
package/dist/algo-amount.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/** Wrapper class to ensure safe, explicit conversion between µAlgos, Algos and numbers */
|
|
2
|
-
export declare class AlgoAmount {
|
|
3
|
-
private amountInMicroAlgos;
|
|
4
|
-
/** Return the amount as a number in µAlgos */
|
|
5
|
-
get microAlgos(): number;
|
|
6
|
-
/** Return the amount as a number in Algos */
|
|
7
|
-
get algos(): number;
|
|
8
|
-
constructor(amount: {
|
|
9
|
-
algos: number;
|
|
10
|
-
} | {
|
|
11
|
-
microAlgos: number;
|
|
12
|
-
});
|
|
13
|
-
/** Create a @see {AlgoAmount} object representing the given number of Algos */
|
|
14
|
-
static Algos(amount: number): AlgoAmount;
|
|
15
|
-
/** Create a @see {AlgoAmount} object representing the given number of µAlgos */
|
|
16
|
-
static MicroAlgos(amount: number): AlgoAmount;
|
|
17
|
-
}
|
|
18
|
-
//# sourceMappingURL=algo-amount.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"algo-amount.d.ts","sourceRoot":"","sources":["../src/algo-amount.ts"],"names":[],"mappings":"AAEA,0FAA0F;AAC1F,qBAAa,UAAU;IACrB,OAAO,CAAC,kBAAkB,CAAA;IAE1B,8CAA8C;IAC9C,IAAI,UAAU,WAEb;IAED,6CAA6C;IAC7C,IAAI,KAAK,WAER;gBAEW,MAAM,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,GAAG;QAAE,UAAU,EAAE,MAAM,CAAA;KAAE;IAI9D,+EAA+E;IAC/E,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,MAAM;IAI3B,gFAAgF;IAChF,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM;CAGjC"}
|
package/dist/algo-amount.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.AlgoAmount = void 0;
|
|
7
|
-
const algosdk_1 = __importDefault(require("algosdk"));
|
|
8
|
-
/** Wrapper class to ensure safe, explicit conversion between µAlgos, Algos and numbers */
|
|
9
|
-
class AlgoAmount {
|
|
10
|
-
/** Return the amount as a number in µAlgos */
|
|
11
|
-
get microAlgos() {
|
|
12
|
-
return this.amountInMicroAlgos;
|
|
13
|
-
}
|
|
14
|
-
/** Return the amount as a number in Algos */
|
|
15
|
-
get algos() {
|
|
16
|
-
return algosdk_1.default.microalgosToAlgos(this.amountInMicroAlgos);
|
|
17
|
-
}
|
|
18
|
-
constructor(amount) {
|
|
19
|
-
this.amountInMicroAlgos = 'microAlgos' in amount ? amount.microAlgos : algosdk_1.default.algosToMicroalgos(amount.algos);
|
|
20
|
-
}
|
|
21
|
-
/** Create a @see {AlgoAmount} object representing the given number of Algos */
|
|
22
|
-
static Algos(amount) {
|
|
23
|
-
return new AlgoAmount({ algos: amount });
|
|
24
|
-
}
|
|
25
|
-
/** Create a @see {AlgoAmount} object representing the given number of µAlgos */
|
|
26
|
-
static MicroAlgos(amount) {
|
|
27
|
-
return new AlgoAmount({ microAlgos: amount });
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
exports.AlgoAmount = AlgoAmount;
|
|
31
|
-
//# sourceMappingURL=algo-amount.js.map
|
package/dist/algo-amount.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"algo-amount.js","sourceRoot":"","sources":["../src/algo-amount.ts"],"names":[],"mappings":";;;;;;AAAA,sDAA6B;AAE7B,0FAA0F;AAC1F,MAAa,UAAU;IAGrB,8CAA8C;IAC9C,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,kBAAkB,CAAA;IAChC,CAAC;IAED,6CAA6C;IAC7C,IAAI,KAAK;QACP,OAAO,iBAAO,CAAC,iBAAiB,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAA;IAC3D,CAAC;IAED,YAAY,MAAkD;QAC5D,IAAI,CAAC,kBAAkB,GAAG,YAAY,IAAI,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,iBAAO,CAAC,iBAAiB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;IAChH,CAAC;IAED,+EAA+E;IAC/E,MAAM,CAAC,KAAK,CAAC,MAAc;QACzB,OAAO,IAAI,UAAU,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAA;IAC1C,CAAC;IAED,gFAAgF;IAChF,MAAM,CAAC,UAAU,CAAC,MAAc;QAC9B,OAAO,IAAI,UAAU,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC,CAAA;IAC/C,CAAC;CACF;AA1BD,gCA0BC"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { BaseHTTPClientResponse, Query } from 'algosdk/dist/types/client/baseHTTPClient';
|
|
2
|
-
import { URLTokenBaseHTTPClient } from './urlTokenBaseHTTPClient';
|
|
3
|
-
/** A HTTP Client that wraps the Algorand SDK HTTP Client with retries */
|
|
4
|
-
export declare class AlgoHttpClientWithRetry extends URLTokenBaseHTTPClient {
|
|
5
|
-
private static readonly MAX_TRIES;
|
|
6
|
-
private static readonly MAX_BACKOFF_MS;
|
|
7
|
-
private static readonly RETRY_STATUS_CODES;
|
|
8
|
-
private static readonly RETRY_ERROR_CODES;
|
|
9
|
-
private callWithRetry;
|
|
10
|
-
get(relativePath: string, query?: Query<string>, requestHeaders?: Record<string, string>): Promise<BaseHTTPClientResponse>;
|
|
11
|
-
post(relativePath: string, data: Uint8Array, query?: Query<string>, requestHeaders?: Record<string, string>): Promise<BaseHTTPClientResponse>;
|
|
12
|
-
delete(relativePath: string, data: Uint8Array, query?: Query<string>, requestHeaders?: Record<string, string>): Promise<BaseHTTPClientResponse>;
|
|
13
|
-
}
|
|
14
|
-
//# sourceMappingURL=algo-http-client-with-retry.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"algo-http-client-with-retry.d.ts","sourceRoot":"","sources":["../src/algo-http-client-with-retry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,KAAK,EAAE,MAAM,0CAA0C,CAAA;AAExF,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAA;AAEjE,yEAAyE;AACzE,qBAAa,uBAAwB,SAAQ,sBAAsB;IACjE,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAI;IACrC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,cAAc,CAAQ;IAI9C,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,kBAAkB,CAAsC;IAChF,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,iBAAiB,CAUxC;YAEa,aAAa;IA6BrB,GAAG,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,EAAE,cAAc,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GAAG,OAAO,CAAC,sBAAsB,CAAC;IAI9H,IAAI,CACR,YAAY,EAAE,MAAM,EACpB,IAAI,EAAE,UAAU,EAChB,KAAK,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,EACrB,cAAc,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GAC1C,OAAO,CAAC,sBAAsB,CAAC;IAI5B,MAAM,CACV,YAAY,EAAE,MAAM,EACpB,IAAI,EAAE,UAAU,EAChB,KAAK,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,EACrB,cAAc,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GAC1C,OAAO,CAAC,sBAAsB,CAAC;CAGnC"}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AlgoHttpClientWithRetry = void 0;
|
|
4
|
-
const config_1 = require("./config");
|
|
5
|
-
const urlTokenBaseHTTPClient_1 = require("./urlTokenBaseHTTPClient");
|
|
6
|
-
/** A HTTP Client that wraps the Algorand SDK HTTP Client with retries */
|
|
7
|
-
class AlgoHttpClientWithRetry extends urlTokenBaseHTTPClient_1.URLTokenBaseHTTPClient {
|
|
8
|
-
async callWithRetry(func) {
|
|
9
|
-
let response;
|
|
10
|
-
let numTries = 1;
|
|
11
|
-
do {
|
|
12
|
-
try {
|
|
13
|
-
response = await func();
|
|
14
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
15
|
-
}
|
|
16
|
-
catch (err) {
|
|
17
|
-
if (numTries >= AlgoHttpClientWithRetry.MAX_TRIES) {
|
|
18
|
-
throw err;
|
|
19
|
-
}
|
|
20
|
-
// Only retry for one of the hardcoded conditions
|
|
21
|
-
if (!(AlgoHttpClientWithRetry.RETRY_ERROR_CODES.includes(err.code) || AlgoHttpClientWithRetry.RETRY_STATUS_CODES.includes(err.status))) {
|
|
22
|
-
throw err;
|
|
23
|
-
}
|
|
24
|
-
// Retry immediately the first time, then exponentially backoff.
|
|
25
|
-
const delayTimeMs = numTries == 1 ? 0 : Math.min(1000 * Math.pow(2, numTries - 1), AlgoHttpClientWithRetry.MAX_BACKOFF_MS);
|
|
26
|
-
if (delayTimeMs > 0) {
|
|
27
|
-
await new Promise((r) => setTimeout(r, delayTimeMs));
|
|
28
|
-
}
|
|
29
|
-
config_1.AlgoKitConfig.logger.warn(`algosdk request failed ${numTries} times. Retrying in ${delayTimeMs}ms: ${err}`);
|
|
30
|
-
}
|
|
31
|
-
} while (!response && ++numTries <= AlgoHttpClientWithRetry.MAX_TRIES);
|
|
32
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
33
|
-
return response;
|
|
34
|
-
}
|
|
35
|
-
async get(relativePath, query, requestHeaders = {}) {
|
|
36
|
-
return await this.callWithRetry(() => super.get(relativePath, query, requestHeaders));
|
|
37
|
-
}
|
|
38
|
-
async post(relativePath, data, query, requestHeaders = {}) {
|
|
39
|
-
return await this.callWithRetry(() => super.post(relativePath, data, query, requestHeaders));
|
|
40
|
-
}
|
|
41
|
-
async delete(relativePath, data, query, requestHeaders = {}) {
|
|
42
|
-
return await this.callWithRetry(() => super.delete(relativePath, data, query, requestHeaders));
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
exports.AlgoHttpClientWithRetry = AlgoHttpClientWithRetry;
|
|
46
|
-
AlgoHttpClientWithRetry.MAX_TRIES = 5;
|
|
47
|
-
AlgoHttpClientWithRetry.MAX_BACKOFF_MS = 10000;
|
|
48
|
-
// These lists come from https://visionmedia.github.io/superagent/#retrying-requests
|
|
49
|
-
// which is the underlying library used by algosdk - but the CloudFlare specific 52X status codes have been removed
|
|
50
|
-
AlgoHttpClientWithRetry.RETRY_STATUS_CODES = [408, 413, 429, 500, 502, 503, 504];
|
|
51
|
-
AlgoHttpClientWithRetry.RETRY_ERROR_CODES = [
|
|
52
|
-
'ETIMEDOUT',
|
|
53
|
-
'ECONNRESET',
|
|
54
|
-
'EADDRINUSE',
|
|
55
|
-
'ECONNREFUSED',
|
|
56
|
-
'EPIPE',
|
|
57
|
-
'ENOTFOUND',
|
|
58
|
-
'ENETUNREACH',
|
|
59
|
-
'EAI_AGAIN',
|
|
60
|
-
'EPROTO', // We get this intermittently with AlgoNode API
|
|
61
|
-
];
|
|
62
|
-
//# sourceMappingURL=algo-http-client-with-retry.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"algo-http-client-with-retry.js","sourceRoot":"","sources":["../src/algo-http-client-with-retry.ts"],"names":[],"mappings":";;;AACA,qCAAwC;AACxC,qEAAiE;AAEjE,yEAAyE;AACzE,MAAa,uBAAwB,SAAQ,+CAAsB;IAmBzD,KAAK,CAAC,aAAa,CAAC,IAA2C;QACrE,IAAI,QAA4C,CAAA;QAChD,IAAI,QAAQ,GAAG,CAAC,CAAA;QAChB,GAAG;YACD,IAAI;gBACF,QAAQ,GAAG,MAAM,IAAI,EAAE,CAAA;gBACvB,8DAA8D;aAC/D;YAAC,OAAO,GAAQ,EAAE;gBACjB,IAAI,QAAQ,IAAI,uBAAuB,CAAC,SAAS,EAAE;oBACjD,MAAM,GAAG,CAAA;iBACV;gBACD,iDAAiD;gBACjD,IACE,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