@ar.io/sdk 2.0.0-alpha.1 → 2.0.0-alpha.10
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/README.md +144 -60
- package/bundles/web.bundle.min.js +131 -98
- package/lib/cjs/common/ant.js +294 -3
- package/lib/cjs/common/contracts/ao-process.js +1 -1
- package/lib/cjs/common/http.js +1 -2
- package/lib/cjs/common/index.js +0 -1
- package/lib/cjs/common/io.js +87 -39
- package/lib/cjs/common/logger.js +31 -19
- package/lib/cjs/utils/http-client.js +1 -1
- package/lib/cjs/utils/index.js +1 -1
- package/lib/cjs/utils/{graphql/processes.js → processes.js} +35 -10
- package/lib/cjs/version.js +1 -1
- package/lib/esm/common/ant.js +290 -1
- package/lib/esm/common/contracts/ao-process.js +2 -2
- package/lib/esm/common/http.js +2 -3
- package/lib/esm/common/index.js +0 -1
- package/lib/esm/common/io.js +87 -36
- package/lib/esm/common/logger.js +29 -14
- package/lib/esm/utils/http-client.js +2 -2
- package/lib/esm/utils/index.js +1 -1
- package/lib/esm/utils/{graphql/processes.js → processes.js} +33 -9
- package/lib/esm/version.js +1 -1
- package/lib/types/common/ant.d.ts +174 -23
- package/lib/types/common/contracts/ao-process.d.ts +2 -2
- package/lib/types/common/http.d.ts +3 -2
- package/lib/types/common/index.d.ts +0 -1
- package/lib/types/common/io.d.ts +5 -4
- package/lib/types/common/logger.d.ts +10 -3
- package/lib/types/common.d.ts +0 -7
- package/lib/types/io.d.ts +28 -3
- package/lib/types/utils/http-client.d.ts +2 -2
- package/lib/types/utils/index.d.ts +1 -1
- package/lib/types/utils/{graphql/processes.d.ts → processes.d.ts} +4 -1
- package/lib/types/version.d.ts +1 -1
- package/package.json +6 -6
- package/lib/cjs/common/ant-ao.js +0 -297
- package/lib/cjs/utils/graphql/index.js +0 -33
- package/lib/esm/common/ant-ao.js +0 -292
- package/lib/esm/utils/graphql/index.js +0 -17
- package/lib/types/common/ant-ao.d.ts +0 -194
- package/lib/types/utils/graphql/index.d.ts +0 -17
package/lib/esm/common/logger.js
CHANGED
|
@@ -14,48 +14,63 @@
|
|
|
14
14
|
* You should have received a copy of the GNU Affero General Public License
|
|
15
15
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
16
|
*/
|
|
17
|
-
import
|
|
17
|
+
import { createLogger, format, transports, } from 'winston';
|
|
18
18
|
import { version } from '../version.js';
|
|
19
|
-
export class
|
|
19
|
+
export class Logger {
|
|
20
20
|
logger;
|
|
21
21
|
silent = false;
|
|
22
|
+
static default = new Logger();
|
|
22
23
|
constructor({ level = 'info', } = {}) {
|
|
23
24
|
if (level === 'none') {
|
|
24
25
|
this.silent = true;
|
|
25
26
|
return;
|
|
26
27
|
}
|
|
27
|
-
this.logger =
|
|
28
|
+
this.logger = createLogger({
|
|
28
29
|
level,
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
silent: this.silent,
|
|
31
|
+
defaultMeta: {
|
|
32
|
+
name: 'ar-io-sdk',
|
|
33
|
+
version,
|
|
34
|
+
},
|
|
35
|
+
format: format.combine(format.timestamp(), format.json()),
|
|
32
36
|
});
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
38
|
+
// @ts-ignore
|
|
39
|
+
if (typeof window !== 'undefined') {
|
|
40
|
+
this.logger = console;
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
this.logger.add(new transports.Console({
|
|
44
|
+
format: format.combine(format.timestamp(), format.json()),
|
|
45
|
+
}));
|
|
46
|
+
}
|
|
33
47
|
}
|
|
34
48
|
info(message, ...args) {
|
|
35
49
|
if (this.silent)
|
|
36
50
|
return;
|
|
37
|
-
this.logger.info(...args
|
|
51
|
+
this.logger.info(message, ...args);
|
|
38
52
|
}
|
|
39
53
|
warn(message, ...args) {
|
|
40
54
|
if (this.silent)
|
|
41
55
|
return;
|
|
42
|
-
this.logger.warn(...args
|
|
56
|
+
this.logger.warn(message, ...args);
|
|
43
57
|
}
|
|
44
58
|
error(message, ...args) {
|
|
45
59
|
if (this.silent)
|
|
46
60
|
return;
|
|
47
|
-
this.logger.error(...args
|
|
61
|
+
this.logger.error(message, ...args);
|
|
48
62
|
}
|
|
49
63
|
debug(message, ...args) {
|
|
50
64
|
if (this.silent)
|
|
51
65
|
return;
|
|
52
|
-
this.logger.debug(...args
|
|
66
|
+
this.logger.debug(message, ...args);
|
|
53
67
|
}
|
|
54
68
|
setLogLevel(level) {
|
|
55
|
-
if (
|
|
56
|
-
this.silent =
|
|
57
|
-
|
|
69
|
+
if ('silent' in this.logger) {
|
|
70
|
+
this.logger.silent = level === 'none';
|
|
71
|
+
}
|
|
72
|
+
if ('level' in this.logger) {
|
|
73
|
+
this.logger.level = level;
|
|
58
74
|
}
|
|
59
|
-
this.logger.level(level);
|
|
60
75
|
}
|
|
61
76
|
}
|
|
@@ -16,9 +16,9 @@
|
|
|
16
16
|
*/
|
|
17
17
|
import axios from 'axios';
|
|
18
18
|
import axiosRetry from 'axios-retry';
|
|
19
|
-
import {
|
|
19
|
+
import { Logger } from '../common/logger.js';
|
|
20
20
|
import { version } from '../version.js';
|
|
21
|
-
export const createAxiosInstance = ({ axiosConfig = {}, logger =
|
|
21
|
+
export const createAxiosInstance = ({ axiosConfig = {}, logger = Logger.default, retryConfig = {
|
|
22
22
|
retries: 5,
|
|
23
23
|
retryDelay: axiosRetry.exponentialDelay,
|
|
24
24
|
retryCondition: (error) => axiosRetry.isRetryableError(error),
|
package/lib/esm/utils/index.js
CHANGED
|
@@ -16,19 +16,20 @@
|
|
|
16
16
|
*/
|
|
17
17
|
import { EventEmitter } from 'eventemitter3';
|
|
18
18
|
import { pLimit } from 'plimit-lit';
|
|
19
|
-
import { ANT } from '
|
|
20
|
-
import { IO } from '
|
|
21
|
-
import { IO_TESTNET_PROCESS_ID } from '
|
|
19
|
+
import { ANT } from '../common/ant.js';
|
|
20
|
+
import { IO } from '../common/io.js';
|
|
21
|
+
import { IO_TESTNET_PROCESS_ID } from '../constants.js';
|
|
22
22
|
export const getANTProcessesOwnedByWallet = async ({ address, contract = IO.init({
|
|
23
23
|
processId: IO_TESTNET_PROCESS_ID,
|
|
24
24
|
}), }) => {
|
|
25
25
|
const throttle = pLimit(50);
|
|
26
26
|
// get the record names of the registry - TODO: this may need to be paginated
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
const records = await fetchAllArNSRecords({
|
|
28
|
+
contract: contract,
|
|
29
|
+
});
|
|
30
|
+
const uniqueContractProcessIds = Object.values(records)
|
|
30
31
|
.filter((record) => record.processId !== undefined)
|
|
31
|
-
.map((record) => record.processId)
|
|
32
|
+
.map((record) => record.processId);
|
|
32
33
|
// check the contract owner and controllers
|
|
33
34
|
const ownedOrControlledByWallet = await Promise.all(uniqueContractProcessIds.map(async (processId) => throttle(async () => {
|
|
34
35
|
const ant = ANT.init({
|
|
@@ -76,10 +77,12 @@ export class ArNSEventEmitter extends EventEmitter {
|
|
|
76
77
|
}
|
|
77
78
|
async fetchProcessesOwnedByWallet({ address }) {
|
|
78
79
|
const uniqueContractProcessIds = {};
|
|
79
|
-
await timeout(this.timeoutMs, this.contract
|
|
80
|
+
await timeout(this.timeoutMs, fetchAllArNSRecords({ contract: this.contract }))
|
|
81
|
+
.catch((e) => {
|
|
80
82
|
this.emit('error', `Error getting ArNS records: ${e}`);
|
|
81
83
|
return {};
|
|
82
|
-
})
|
|
84
|
+
})
|
|
85
|
+
.then((records) => {
|
|
83
86
|
if (!records)
|
|
84
87
|
return;
|
|
85
88
|
Object.entries(records).forEach(([name, record]) => {
|
|
@@ -120,3 +123,24 @@ export class ArNSEventEmitter extends EventEmitter {
|
|
|
120
123
|
this.emit('end', uniqueContractProcessIds);
|
|
121
124
|
}
|
|
122
125
|
}
|
|
126
|
+
export const fetchAllArNSRecords = async ({ contract = IO.init({
|
|
127
|
+
processId: IO_TESTNET_PROCESS_ID,
|
|
128
|
+
}), }) => {
|
|
129
|
+
let cursor;
|
|
130
|
+
const records = {};
|
|
131
|
+
do {
|
|
132
|
+
const pageResult = await contract.getArNSRecords({ cursor }).catch((e) => {
|
|
133
|
+
console.error(`Error getting ArNS records: ${e}`);
|
|
134
|
+
return undefined;
|
|
135
|
+
});
|
|
136
|
+
if (!pageResult) {
|
|
137
|
+
return {};
|
|
138
|
+
}
|
|
139
|
+
pageResult.items.forEach((record) => {
|
|
140
|
+
const { name, ...recordDetails } = record;
|
|
141
|
+
records[name] = recordDetails;
|
|
142
|
+
});
|
|
143
|
+
cursor = pageResult.nextCursor;
|
|
144
|
+
} while (cursor !== undefined);
|
|
145
|
+
return records;
|
|
146
|
+
};
|
package/lib/esm/version.js
CHANGED
|
@@ -14,34 +14,185 @@
|
|
|
14
14
|
* You should have received a copy of the GNU Affero General Public License
|
|
15
15
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
16
|
*/
|
|
17
|
-
import { AoANTRead, AoANTWrite, ProcessConfiguration, WithSigner } from '../types.js';
|
|
17
|
+
import { ANTRecord, AoANTRead, AoANTState, AoANTWrite, AoMessageResult, ProcessConfiguration, WalletAddress, WithSigner } from '../types.js';
|
|
18
|
+
import { AOProcess } from './index.js';
|
|
18
19
|
export declare class ANT {
|
|
20
|
+
static init(config: Required<ProcessConfiguration> & {
|
|
21
|
+
signer?: undefined;
|
|
22
|
+
}): AoANTRead;
|
|
23
|
+
static init({ signer, ...config }: WithSigner<Required<ProcessConfiguration>>): AoANTWrite;
|
|
24
|
+
}
|
|
25
|
+
export declare class AoANTReadable implements AoANTRead {
|
|
26
|
+
protected process: AOProcess;
|
|
27
|
+
constructor(config: Required<ProcessConfiguration>);
|
|
28
|
+
getState(): Promise<AoANTState>;
|
|
29
|
+
getInfo(): Promise<{
|
|
30
|
+
Name: string;
|
|
31
|
+
Ticker: string;
|
|
32
|
+
Denomination: number;
|
|
33
|
+
Owner: string;
|
|
34
|
+
}>;
|
|
35
|
+
/**
|
|
36
|
+
* @param undername @type {string} The domain name.
|
|
37
|
+
* @returns {Promise<ANTRecord>} The record of the undername domain.
|
|
38
|
+
* @example
|
|
39
|
+
* Get the current record
|
|
40
|
+
* ```ts
|
|
41
|
+
* ant.getRecord({ undername: "john" });
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
getRecord({ undername }: {
|
|
45
|
+
undername: string;
|
|
46
|
+
}): Promise<ANTRecord>;
|
|
19
47
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* There are two overloads for this function:
|
|
23
|
-
* 1. When a signer is provided in the configuration, it returns an instance of ANTWritable.
|
|
24
|
-
* 2. When a signer is NOT provided in the configuration, it returns an instance of ANTReadable.
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* @param {ContractConfiguration & WithSigner} config - The configuration object.
|
|
28
|
-
* If a signer is provided, it should be an object that implements the ContractSigner interface.
|
|
29
|
-
*
|
|
30
|
-
* @returns {ANTWritable | ANTReadable} - An instance of ANTWritable if a signer is provided, otherwise an instance of ANTReadable.
|
|
31
|
-
* @throws {Error} - Throws an error if the configuration is invalid.
|
|
32
|
-
*
|
|
48
|
+
* @returns {Promise<Record<string, ANTRecord>>} All the undernames managed by the ANT.
|
|
33
49
|
* @example
|
|
34
|
-
*
|
|
50
|
+
* Get the current records
|
|
35
51
|
* ```ts
|
|
36
|
-
*
|
|
37
|
-
|
|
38
|
-
|
|
52
|
+
* ant.getRecords();
|
|
53
|
+
* ````
|
|
54
|
+
*/
|
|
55
|
+
getRecords(): Promise<Record<string, ANTRecord>>;
|
|
56
|
+
/**
|
|
57
|
+
* @returns {Promise<string>} The owner of the ANT.
|
|
58
|
+
* @example
|
|
59
|
+
* Get the current owner
|
|
39
60
|
* ```ts
|
|
40
|
-
*
|
|
61
|
+
* ant.getOwner();
|
|
41
62
|
* ```
|
|
42
63
|
*/
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
64
|
+
getOwner(): Promise<string>;
|
|
65
|
+
/**
|
|
66
|
+
* @returns {Promise<string[]>} The controllers of the ANT.
|
|
67
|
+
* @example
|
|
68
|
+
* Get the controllers of the ANT.
|
|
69
|
+
* ```ts
|
|
70
|
+
* ant.getControllers();
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
getControllers(): Promise<WalletAddress[]>;
|
|
74
|
+
/**
|
|
75
|
+
* @returns {Promise<string>} The name of the ANT (not the same as ArNS name).
|
|
76
|
+
* @example
|
|
77
|
+
* Get the current name
|
|
78
|
+
* ```ts
|
|
79
|
+
* ant.getName();
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
getName(): Promise<string>;
|
|
83
|
+
/**
|
|
84
|
+
* @returns {Promise<string>} The name of the ANT (not the same as ArNS name).
|
|
85
|
+
* @example
|
|
86
|
+
* The current ticker of the ANT.
|
|
87
|
+
* ```ts
|
|
88
|
+
* ant.getTicker();
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
getTicker(): Promise<string>;
|
|
92
|
+
/**
|
|
93
|
+
* @returns {Promise<Record<WalletAddress, number>>} The balances of the ANT
|
|
94
|
+
* @example
|
|
95
|
+
* The current balances of the ANT.
|
|
96
|
+
* ```ts
|
|
97
|
+
* ant.getBalances();
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
getBalances(): Promise<Record<string, number>>;
|
|
101
|
+
/**
|
|
102
|
+
* @param address @type {string} The address of the account you want the balance of.
|
|
103
|
+
* @returns {Promise<number>} The balance of the provided address
|
|
104
|
+
* @example
|
|
105
|
+
* The current balance of the address.
|
|
106
|
+
* ```ts
|
|
107
|
+
* ant.getBalance({ address });
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
getBalance({ address }: {
|
|
111
|
+
address: string;
|
|
112
|
+
}): Promise<number>;
|
|
113
|
+
}
|
|
114
|
+
export declare class AoANTWriteable extends AoANTReadable implements AoANTWrite {
|
|
115
|
+
private signer;
|
|
116
|
+
constructor({ signer, ...config }: WithSigner<Required<ProcessConfiguration>>);
|
|
117
|
+
/**
|
|
118
|
+
* @param target @type {string} The address of the account you want to transfer the ANT to.
|
|
119
|
+
* @returns {Promise<AoMessageResult>} The result of the interaction.
|
|
120
|
+
* @example
|
|
121
|
+
* ```ts
|
|
122
|
+
* ant.transfer({ target: "fGht8v4STuwPnTck1zFVkQqJh5K9q9Zik4Y5-5dV7nk" });
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
transfer({ target }: {
|
|
126
|
+
target: string;
|
|
127
|
+
}): Promise<AoMessageResult>;
|
|
128
|
+
/**
|
|
129
|
+
* @param controller @type {string} The address of the account you want to set as a controller.
|
|
130
|
+
* @returns {Promise<AoMessageResult>} The result of the interaction.
|
|
131
|
+
* @example
|
|
132
|
+
* ```ts
|
|
133
|
+
* ant.setController({ controller: "fGht8v4STuwPnTck1zFVkQqJh5K9q9Zik4Y5-5dV7nk" });
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
addController({ controller, }: {
|
|
137
|
+
controller: string;
|
|
138
|
+
}): Promise<AoMessageResult>;
|
|
139
|
+
/**
|
|
140
|
+
* @param controller @type {string} The address of the account you want to remove from the controllers list
|
|
141
|
+
* @returns {Promise<AoMessageResult>} The result of the interaction.
|
|
142
|
+
* @example
|
|
143
|
+
* ```ts
|
|
144
|
+
* ant.removeController({ controller: "fGht8v4STuwPnTck1zFVkQqJh5K9q9Zik4Y5-5dV7nk" });
|
|
145
|
+
* ```
|
|
146
|
+
*/
|
|
147
|
+
removeController({ controller, }: {
|
|
148
|
+
controller: string;
|
|
149
|
+
}): Promise<AoMessageResult>;
|
|
150
|
+
/**
|
|
151
|
+
* @param undername @type {string} The record you want to set the transactionId and ttlSeconds of.
|
|
152
|
+
* @param transactionId @type {string} The transactionId of the record.
|
|
153
|
+
* @param ttlSeconds @type {number} The time to live of the record.
|
|
154
|
+
* @returns {Promise<AoMessageResult>} The result of the interaction.
|
|
155
|
+
* @example
|
|
156
|
+
* ```ts
|
|
157
|
+
* ant.setController({ controller: "fGht8v4STuwPnTck1zFVkQqJh5K9q9Zik4Y5-5dV7nk" });
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
setRecord({ undername, transactionId, ttlSeconds, }: {
|
|
161
|
+
undername: string;
|
|
162
|
+
transactionId: string;
|
|
163
|
+
ttlSeconds: number;
|
|
164
|
+
}): Promise<AoMessageResult>;
|
|
165
|
+
/**
|
|
166
|
+
* @param undername @type {string} The record you want to remove.
|
|
167
|
+
* @returns {Promise<AoMessageResult>} The result of the interaction.
|
|
168
|
+
* @example
|
|
169
|
+
* ```ts
|
|
170
|
+
* ant.removeRecord({ subDomain: "shorts" });
|
|
171
|
+
* ```
|
|
172
|
+
*/
|
|
173
|
+
removeRecord({ undername, }: {
|
|
174
|
+
undername: string;
|
|
175
|
+
}): Promise<AoMessageResult>;
|
|
176
|
+
/**
|
|
177
|
+
* @param ticker @type {string} Sets the ANT Ticker.
|
|
178
|
+
* @returns {Promise<AoMessageResult>} The result of the interaction.
|
|
179
|
+
* @example
|
|
180
|
+
* ```ts
|
|
181
|
+
* ant.setTicker({ ticker: "KAPOW" });
|
|
182
|
+
* ```
|
|
183
|
+
*/
|
|
184
|
+
setTicker({ ticker }: {
|
|
185
|
+
ticker: string;
|
|
186
|
+
}): Promise<AoMessageResult>;
|
|
187
|
+
/**
|
|
188
|
+
* @param name @type {string} Sets the Name of the ANT.
|
|
189
|
+
* @returns {Promise<AoMessageResult>} The result of the interaction.
|
|
190
|
+
* @example
|
|
191
|
+
* ```ts
|
|
192
|
+
* ant.setName({ name: "ships at sea" });
|
|
193
|
+
* ```
|
|
194
|
+
*/
|
|
195
|
+
setName({ name }: {
|
|
196
|
+
name: string;
|
|
197
|
+
}): Promise<AoMessageResult>;
|
|
47
198
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { AOContract, AoClient, ContractSigner } from '../../types.js';
|
|
3
|
-
import {
|
|
3
|
+
import { ILogger } from '../logger.js';
|
|
4
4
|
export declare class AOProcess implements AOContract {
|
|
5
5
|
private logger;
|
|
6
6
|
private processId;
|
|
@@ -8,7 +8,7 @@ export declare class AOProcess implements AOContract {
|
|
|
8
8
|
constructor({ processId, ao, logger, }: {
|
|
9
9
|
processId: string;
|
|
10
10
|
ao?: AoClient;
|
|
11
|
-
logger?:
|
|
11
|
+
logger?: ILogger;
|
|
12
12
|
});
|
|
13
13
|
static createAoSigner(signer: ContractSigner): Promise<(args: {
|
|
14
14
|
data: string | Buffer;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { HTTPClient
|
|
2
|
+
import { HTTPClient } from '../types.js';
|
|
3
|
+
import { ILogger } from './logger.js';
|
|
3
4
|
export declare class AxiosHTTPService implements HTTPClient {
|
|
4
5
|
private axios;
|
|
5
6
|
private logger;
|
|
6
7
|
constructor({ url, logger, }: {
|
|
7
8
|
url: string;
|
|
8
|
-
logger?:
|
|
9
|
+
logger?: ILogger;
|
|
9
10
|
});
|
|
10
11
|
get<I, K>({ endpoint, signal, allowedStatuses, headers, params, }: {
|
|
11
12
|
endpoint: string;
|
package/lib/types/common/io.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ import Arweave from 'arweave';
|
|
|
18
18
|
import { ArNSReservedNameData, EpochDistributionData, EpochObservations, WeightedObserver } from '../contract-state.js';
|
|
19
19
|
import { AoArNSNameData, AoEpochData, AoEpochSettings, AoGateway, AoIORead, AoIOWrite, EpochInput } from '../io.js';
|
|
20
20
|
import { mIOToken } from '../token.js';
|
|
21
|
-
import { AoMessageResult, ContractSigner, JoinNetworkParams, ProcessConfiguration, TransactionId, UpdateGatewaySettingsParams, WalletAddress, WithSigner, WriteOptions } from '../types.js';
|
|
21
|
+
import { AoArNSNameDataWithName, AoBalanceWithAddress, AoGatewayWithAddress, AoMessageResult, ContractSigner, JoinNetworkParams, PaginationParams, PaginationResult, ProcessConfiguration, TransactionId, UpdateGatewaySettingsParams, WalletAddress, WithSigner, WriteOptions } from '../types.js';
|
|
22
22
|
import { AOProcess } from './contracts/ao-process.js';
|
|
23
23
|
export declare class IO {
|
|
24
24
|
static init(): AoIORead;
|
|
@@ -54,7 +54,7 @@ export declare class IOReadable implements AoIORead {
|
|
|
54
54
|
getArNSRecord({ name, }: {
|
|
55
55
|
name: string;
|
|
56
56
|
}): Promise<AoArNSNameData | undefined>;
|
|
57
|
-
getArNSRecords(): Promise<
|
|
57
|
+
getArNSRecords(pageParams?: PaginationParams): Promise<PaginationResult<AoArNSNameDataWithName>>;
|
|
58
58
|
getArNSReservedNames(): Promise<Record<string, ArNSReservedNameData> | Record<string, never>>;
|
|
59
59
|
getArNSReservedName({ name, }: {
|
|
60
60
|
name: string;
|
|
@@ -62,11 +62,11 @@ export declare class IOReadable implements AoIORead {
|
|
|
62
62
|
getBalance({ address }: {
|
|
63
63
|
address: WalletAddress;
|
|
64
64
|
}): Promise<number>;
|
|
65
|
-
getBalances(): Promise<
|
|
65
|
+
getBalances(pageParams?: PaginationParams): Promise<PaginationResult<AoBalanceWithAddress>>;
|
|
66
66
|
getGateway({ address, }: {
|
|
67
67
|
address: WalletAddress;
|
|
68
68
|
}): Promise<AoGateway | undefined>;
|
|
69
|
-
getGateways(): Promise<
|
|
69
|
+
getGateways(pageParams?: PaginationParams): Promise<PaginationResult<AoGatewayWithAddress>>;
|
|
70
70
|
getCurrentEpoch(): Promise<AoEpochData>;
|
|
71
71
|
getPrescribedObservers(epoch?: EpochInput): Promise<WeightedObserver[]>;
|
|
72
72
|
getPrescribedNames(epoch?: EpochInput): Promise<string[]>;
|
|
@@ -105,6 +105,7 @@ export declare class IOWriteable extends IOReadable implements AoIOWrite {
|
|
|
105
105
|
observerAddress: string;
|
|
106
106
|
operatorStake: number | mIOToken;
|
|
107
107
|
}, options?: WriteOptions): Promise<AoMessageResult>;
|
|
108
|
+
leaveNetwork(options?: WriteOptions): Promise<AoMessageResult>;
|
|
108
109
|
updateGatewaySettings({ allowDelegatedStaking, delegateRewardShareRatio, fqdn, label, minDelegatedStake, note, port, properties, protocol, autoStake, observerAddress, }: Omit<UpdateGatewaySettingsParams, 'observerWallet'> & {
|
|
109
110
|
observerAddress: string;
|
|
110
111
|
}, options?: WriteOptions): Promise<AoMessageResult>;
|
|
@@ -1,7 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
export interface ILogger {
|
|
2
|
+
setLogLevel: (level: 'info' | 'debug' | 'error' | 'warn' | 'none') => void;
|
|
3
|
+
info: (message: string, ...args: unknown[]) => void;
|
|
4
|
+
warn: (message: string, ...args: unknown[]) => void;
|
|
5
|
+
error: (message: string, ...args: unknown[]) => void;
|
|
6
|
+
debug: (message: string, ...args: unknown[]) => void;
|
|
7
|
+
}
|
|
8
|
+
export declare class Logger implements ILogger {
|
|
3
9
|
private logger;
|
|
4
10
|
private silent;
|
|
11
|
+
static default: Logger;
|
|
5
12
|
constructor({ level, }?: {
|
|
6
13
|
level?: 'info' | 'debug' | 'error' | 'warn' | 'none';
|
|
7
14
|
});
|
|
@@ -9,5 +16,5 @@ export declare class DefaultLogger implements Logger {
|
|
|
9
16
|
warn(message: string, ...args: unknown[]): void;
|
|
10
17
|
error(message: string, ...args: unknown[]): void;
|
|
11
18
|
debug(message: string, ...args: unknown[]): void;
|
|
12
|
-
setLogLevel(level:
|
|
19
|
+
setLogLevel(level: 'info' | 'debug' | 'error' | 'warn' | 'none'): void;
|
|
13
20
|
}
|
package/lib/types/common.d.ts
CHANGED
|
@@ -72,13 +72,6 @@ export type AtLeastOne<T, U = {
|
|
|
72
72
|
[K in keyof T]-?: Record<K, T[K]>;
|
|
73
73
|
}> = Partial<T> & U[keyof U];
|
|
74
74
|
export type UpdateGatewaySettingsParams = AtLeastOne<UpdateGatewaySettingsParamsBase>;
|
|
75
|
-
export interface Logger {
|
|
76
|
-
setLogLevel: (level: string) => void;
|
|
77
|
-
info: (message: string, ...args: unknown[]) => void;
|
|
78
|
-
warn: (message: string, ...args: unknown[]) => void;
|
|
79
|
-
error: (message: string, ...args: unknown[]) => void;
|
|
80
|
-
debug: (message: string, ...args: unknown[]) => void;
|
|
81
|
-
}
|
|
82
75
|
export interface HTTPClient {
|
|
83
76
|
get<I, K>({ endpoint, signal, headers, allowedStatuses, params, }: {
|
|
84
77
|
endpoint: string;
|
package/lib/types/io.d.ts
CHANGED
|
@@ -25,6 +25,20 @@ export declare function isProcessIdConfiguration(config: object): config is {
|
|
|
25
25
|
processId: string;
|
|
26
26
|
};
|
|
27
27
|
export declare function isLeasedArNSRecord(record: AoArNSNameData): record is AoArNSLeaseData;
|
|
28
|
+
export type PaginationParams = {
|
|
29
|
+
cursor?: string;
|
|
30
|
+
limit?: number;
|
|
31
|
+
sortBy?: string;
|
|
32
|
+
sortOrder?: 'asc' | 'desc';
|
|
33
|
+
};
|
|
34
|
+
export type PaginationResult<T> = {
|
|
35
|
+
items: T[];
|
|
36
|
+
nextCursor: string | undefined;
|
|
37
|
+
totalItems: number;
|
|
38
|
+
sortBy: keyof T;
|
|
39
|
+
sortOrder: 'asc' | 'desc';
|
|
40
|
+
hasMore: boolean;
|
|
41
|
+
};
|
|
28
42
|
export type ProcessConfiguration = {
|
|
29
43
|
process?: AOProcess;
|
|
30
44
|
} | {
|
|
@@ -66,15 +80,15 @@ export interface AoIORead {
|
|
|
66
80
|
getGateway({ address, }: {
|
|
67
81
|
address: WalletAddress;
|
|
68
82
|
}): Promise<AoGateway | undefined>;
|
|
69
|
-
getGateways(): Promise<
|
|
83
|
+
getGateways(params?: PaginationParams): Promise<PaginationResult<AoGatewayWithAddress>>;
|
|
70
84
|
getBalance(params: {
|
|
71
85
|
address: WalletAddress;
|
|
72
86
|
}): Promise<number>;
|
|
73
|
-
getBalances(): Promise<
|
|
87
|
+
getBalances(params?: PaginationParams): Promise<PaginationResult<AoBalanceWithAddress>>;
|
|
74
88
|
getArNSRecord({ name, }: {
|
|
75
89
|
name: string;
|
|
76
90
|
}): Promise<AoArNSNameData | undefined>;
|
|
77
|
-
getArNSRecords(): Promise<
|
|
91
|
+
getArNSRecords(params?: PaginationParams): Promise<PaginationResult<AoArNSNameDataWithName>>;
|
|
78
92
|
getArNSReservedNames(): Promise<Record<string, AoArNSReservedNameData> | Record<string, never>>;
|
|
79
93
|
getArNSReservedName({ name, }: {
|
|
80
94
|
name: string;
|
|
@@ -102,6 +116,7 @@ export interface AoIOWrite extends AoIORead {
|
|
|
102
116
|
observerAddress: string;
|
|
103
117
|
operatorStake: number | mIOToken;
|
|
104
118
|
}, options?: WriteOptions): Promise<AoMessageResult>;
|
|
119
|
+
leaveNetwork(options?: WriteOptions): Promise<AoMessageResult>;
|
|
105
120
|
updateGatewaySettings({ allowDelegatedStaking, delegateRewardShareRatio, fqdn, label, minDelegatedStake, note, port, properties, protocol, autoStake, observerAddress, }: Omit<UpdateGatewaySettingsParams, 'observerWallet'> & {
|
|
106
121
|
observerAddress?: WalletAddress;
|
|
107
122
|
}, options?: WriteOptions): Promise<AoMessageResult>;
|
|
@@ -200,6 +215,9 @@ export interface AoIOState {
|
|
|
200
215
|
export type AoEpochIndex = number;
|
|
201
216
|
export type AoArNSReservedNameData = ArNSReservedNameData;
|
|
202
217
|
export type AoArNSNameData = AoArNSPermabuyData | AoArNSLeaseData;
|
|
218
|
+
export type AoArNSNameDataWithName = AoArNSNameData & {
|
|
219
|
+
name: string;
|
|
220
|
+
};
|
|
203
221
|
export type AoArNSBaseNameData = {
|
|
204
222
|
processId: ProcessId;
|
|
205
223
|
startTimestamp: number;
|
|
@@ -258,6 +276,13 @@ export type AoGateway = {
|
|
|
258
276
|
operatorStake: number;
|
|
259
277
|
status: 'joined' | 'leaving';
|
|
260
278
|
};
|
|
279
|
+
export type AoBalanceWithAddress = {
|
|
280
|
+
address: WalletAddress;
|
|
281
|
+
balance: number;
|
|
282
|
+
};
|
|
283
|
+
export type AoGatewayWithAddress = AoGateway & {
|
|
284
|
+
gatewayAddress: WalletAddress;
|
|
285
|
+
};
|
|
261
286
|
export type AoANTState = {
|
|
262
287
|
Name: string;
|
|
263
288
|
Ticker: string;
|
|
@@ -16,10 +16,10 @@
|
|
|
16
16
|
*/
|
|
17
17
|
import { AxiosInstance, AxiosRequestConfig } from 'axios';
|
|
18
18
|
import { IAxiosRetryConfig } from 'axios-retry';
|
|
19
|
-
import {
|
|
19
|
+
import { ILogger } from '../common/logger.js';
|
|
20
20
|
export interface AxiosInstanceParameters {
|
|
21
21
|
axiosConfig?: Omit<AxiosRequestConfig, 'validateStatus'>;
|
|
22
22
|
retryConfig?: IAxiosRetryConfig;
|
|
23
|
-
logger?:
|
|
23
|
+
logger?: ILogger;
|
|
24
24
|
}
|
|
25
25
|
export declare const createAxiosInstance: ({ axiosConfig, logger, retryConfig, }?: AxiosInstanceParameters) => AxiosInstance;
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
16
|
*/
|
|
17
17
|
import { EventEmitter } from 'eventemitter3';
|
|
18
|
-
import { AoIORead, ProcessId, WalletAddress } from '
|
|
18
|
+
import { AoArNSNameData, AoIORead, ProcessId, WalletAddress } from '../types.js';
|
|
19
19
|
export declare const getANTProcessesOwnedByWallet: ({ address, contract, }: {
|
|
20
20
|
address: WalletAddress;
|
|
21
21
|
contract?: AoIORead;
|
|
@@ -33,3 +33,6 @@ export declare class ArNSEventEmitter extends EventEmitter {
|
|
|
33
33
|
address: WalletAddress;
|
|
34
34
|
}): Promise<void>;
|
|
35
35
|
}
|
|
36
|
+
export declare const fetchAllArNSRecords: ({ contract, }: {
|
|
37
|
+
contract?: AoIORead;
|
|
38
|
+
}) => Promise<Record<string, AoArNSNameData>>;
|
package/lib/types/version.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ar.io/sdk",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.10",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/ar-io/ar-io-sdk.git"
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
},
|
|
51
51
|
"./web": {
|
|
52
52
|
"import": "./lib/esm/web/index.js",
|
|
53
|
-
"require": "./
|
|
53
|
+
"require": "./lib/cjs/web/index.js",
|
|
54
54
|
"types": "./lib/types/web/index.d.ts",
|
|
55
55
|
"browser": "./bundles/web.bundle.min.js"
|
|
56
56
|
}
|
|
@@ -74,8 +74,8 @@
|
|
|
74
74
|
"test:e2e": "yarn test:link && yarn test:cjs && yarn test:esm && yarn test:web",
|
|
75
75
|
"prepare": "husky install",
|
|
76
76
|
"example:esm": "cd examples/esm && yarn && node index.mjs",
|
|
77
|
-
"example:cjs": "cd examples/cjs && yarn && node index.cjs",
|
|
78
|
-
"example:web": "yarn build:web && http-server --port 8080 --host -o examples/web"
|
|
77
|
+
"example:cjs": "yarn test:link && cd examples/cjs && yarn && node index.cjs",
|
|
78
|
+
"example:web": "yarn test:link && build:web && http-server --port 8080 --host -o examples/web"
|
|
79
79
|
},
|
|
80
80
|
"devDependencies": {
|
|
81
81
|
"@commitlint/cli": "^17.1.2",
|
|
@@ -123,9 +123,9 @@
|
|
|
123
123
|
"arweave": "1.14.4",
|
|
124
124
|
"axios": "1.7.2",
|
|
125
125
|
"axios-retry": "^4.3.0",
|
|
126
|
-
"bunyan": "^1.8.15",
|
|
127
126
|
"eventemitter3": "^5.0.1",
|
|
128
|
-
"plimit-lit": "^3.0.1"
|
|
127
|
+
"plimit-lit": "^3.0.1",
|
|
128
|
+
"winston": "^3.13.0"
|
|
129
129
|
},
|
|
130
130
|
"lint-staged": {
|
|
131
131
|
"**/*.{ts,js,mjs,cjs,md,json}": [
|