@ar.io/sdk 2.0.0-alpha.2 → 2.0.0-alpha.3

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.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ANT = void 0;
3
+ exports.AoANTWriteable = exports.AoANTReadable = exports.ANT = void 0;
4
4
  /**
5
5
  * Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
6
6
  *
@@ -24,11 +24,302 @@ class ANT {
24
24
  // ao supported implementation
25
25
  if ((0, types_js_1.isProcessConfiguration)(config) || (0, types_js_1.isProcessIdConfiguration)(config)) {
26
26
  if (!signer) {
27
- return new index_js_1.AoANTReadable(config);
27
+ return new AoANTReadable(config);
28
28
  }
29
- return new index_js_1.AoANTWriteable({ signer, ...config });
29
+ return new AoANTWriteable({ signer, ...config });
30
30
  }
31
31
  throw new index_js_1.InvalidContractConfigurationError();
32
32
  }
33
33
  }
34
34
  exports.ANT = ANT;
35
+ class AoANTReadable {
36
+ process;
37
+ constructor(config) {
38
+ if ((0, types_js_1.isProcessConfiguration)(config)) {
39
+ this.process = config.process;
40
+ }
41
+ else if ((0, types_js_1.isProcessIdConfiguration)(config)) {
42
+ this.process = new index_js_1.AOProcess({
43
+ processId: config.processId,
44
+ });
45
+ }
46
+ else {
47
+ throw new index_js_1.InvalidContractConfigurationError();
48
+ }
49
+ }
50
+ async getState() {
51
+ const tags = [{ name: 'Action', value: 'State' }];
52
+ const res = await this.process.read({
53
+ tags,
54
+ });
55
+ return res;
56
+ }
57
+ async getInfo() {
58
+ const tags = [{ name: 'Action', value: 'Info' }];
59
+ const info = await this.process.read({
60
+ tags,
61
+ });
62
+ return info;
63
+ }
64
+ /**
65
+ * @param undername @type {string} The domain name.
66
+ * @returns {Promise<ANTRecord>} The record of the undername domain.
67
+ * @example
68
+ * Get the current record
69
+ * ```ts
70
+ * ant.getRecord({ undername: "john" });
71
+ * ```
72
+ */
73
+ async getRecord({ undername }) {
74
+ const tags = [
75
+ { name: 'Sub-Domain', value: undername },
76
+ { name: 'Action', value: 'Record' },
77
+ ];
78
+ const record = await this.process.read({
79
+ tags,
80
+ });
81
+ return record;
82
+ }
83
+ /**
84
+ * @returns {Promise<Record<string, ANTRecord>>} All the undernames managed by the ANT.
85
+ * @example
86
+ * Get the current records
87
+ * ```ts
88
+ * ant.getRecords();
89
+ * ````
90
+ */
91
+ async getRecords() {
92
+ const tags = [{ name: 'Action', value: 'Records' }];
93
+ const records = await this.process.read({
94
+ tags,
95
+ });
96
+ return records;
97
+ }
98
+ /**
99
+ * @returns {Promise<string>} The owner of the ANT.
100
+ * @example
101
+ * Get the current owner
102
+ * ```ts
103
+ * ant.getOwner();
104
+ * ```
105
+ */
106
+ async getOwner() {
107
+ const info = await this.getInfo();
108
+ return info.Owner;
109
+ }
110
+ /**
111
+ * @returns {Promise<string[]>} The controllers of the ANT.
112
+ * @example
113
+ * Get the controllers of the ANT.
114
+ * ```ts
115
+ * ant.getControllers();
116
+ * ```
117
+ */
118
+ async getControllers() {
119
+ const tags = [{ name: 'Action', value: 'Controllers' }];
120
+ const controllers = await this.process.read({
121
+ tags,
122
+ });
123
+ return controllers;
124
+ }
125
+ /**
126
+ * @returns {Promise<string>} The name of the ANT (not the same as ArNS name).
127
+ * @example
128
+ * Get the current name
129
+ * ```ts
130
+ * ant.getName();
131
+ * ```
132
+ */
133
+ async getName() {
134
+ const info = await this.getInfo();
135
+ return info.Name;
136
+ }
137
+ /**
138
+ * @returns {Promise<string>} The name of the ANT (not the same as ArNS name).
139
+ * @example
140
+ * The current ticker of the ANT.
141
+ * ```ts
142
+ * ant.getTicker();
143
+ * ```
144
+ */
145
+ async getTicker() {
146
+ const info = await this.getInfo();
147
+ return info.Ticker;
148
+ }
149
+ /**
150
+ * @returns {Promise<Record<WalletAddress, number>>} The balances of the ANT
151
+ * @example
152
+ * The current balances of the ANT.
153
+ * ```ts
154
+ * ant.getBalances();
155
+ * ```
156
+ */
157
+ async getBalances() {
158
+ const tags = [{ name: 'Action', value: 'Balances' }];
159
+ const balances = await this.process.read({
160
+ tags,
161
+ });
162
+ return balances;
163
+ }
164
+ /**
165
+ * @param address @type {string} The address of the account you want the balance of.
166
+ * @returns {Promise<number>} The balance of the provided address
167
+ * @example
168
+ * The current balance of the address.
169
+ * ```ts
170
+ * ant.getBalance({ address });
171
+ * ```
172
+ */
173
+ async getBalance({ address }) {
174
+ const tags = [
175
+ { name: 'Action', value: 'Balance' },
176
+ { name: 'Recipient', value: address },
177
+ ];
178
+ const balance = await this.process.read({
179
+ tags,
180
+ });
181
+ return balance;
182
+ }
183
+ }
184
+ exports.AoANTReadable = AoANTReadable;
185
+ class AoANTWriteable extends AoANTReadable {
186
+ signer;
187
+ constructor({ signer, ...config }) {
188
+ super(config);
189
+ this.signer = signer;
190
+ }
191
+ /**
192
+ * @param target @type {string} The address of the account you want to transfer the ANT to.
193
+ * @returns {Promise<AoMessageResult>} The result of the interaction.
194
+ * @example
195
+ * ```ts
196
+ * ant.transfer({ target: "fGht8v4STuwPnTck1zFVkQqJh5K9q9Zik4Y5-5dV7nk" });
197
+ * ```
198
+ */
199
+ async transfer({ target }) {
200
+ const tags = [
201
+ { name: 'Action', value: 'Transfer' },
202
+ { name: 'Recipient', value: target },
203
+ ];
204
+ return this.process.send({
205
+ tags,
206
+ data: {},
207
+ signer: this.signer,
208
+ });
209
+ }
210
+ /**
211
+ * @param controller @type {string} The address of the account you want to set as a controller.
212
+ * @returns {Promise<AoMessageResult>} The result of the interaction.
213
+ * @example
214
+ * ```ts
215
+ * ant.setController({ controller: "fGht8v4STuwPnTck1zFVkQqJh5K9q9Zik4Y5-5dV7nk" });
216
+ * ```
217
+ */
218
+ async addController({ controller, }) {
219
+ const tags = [
220
+ { name: 'Action', value: 'Add-Controller' },
221
+ { name: 'Controller', value: controller },
222
+ ];
223
+ return this.process.send({
224
+ tags,
225
+ data: {},
226
+ signer: this.signer,
227
+ });
228
+ }
229
+ /**
230
+ * @param controller @type {string} The address of the account you want to remove from the controllers list
231
+ * @returns {Promise<AoMessageResult>} The result of the interaction.
232
+ * @example
233
+ * ```ts
234
+ * ant.removeController({ controller: "fGht8v4STuwPnTck1zFVkQqJh5K9q9Zik4Y5-5dV7nk" });
235
+ * ```
236
+ */
237
+ async removeController({ controller, }) {
238
+ const tags = [
239
+ { name: 'Action', value: 'Remove-Controller' },
240
+ { name: 'Controller', value: controller },
241
+ ];
242
+ return this.process.send({
243
+ tags,
244
+ data: {},
245
+ signer: this.signer,
246
+ });
247
+ }
248
+ /**
249
+ * @param undername @type {string} The record you want to set the transactionId and ttlSeconds of.
250
+ * @param transactionId @type {string} The transactionId of the record.
251
+ * @param ttlSeconds @type {number} The time to live of the record.
252
+ * @returns {Promise<AoMessageResult>} The result of the interaction.
253
+ * @example
254
+ * ```ts
255
+ * ant.setController({ controller: "fGht8v4STuwPnTck1zFVkQqJh5K9q9Zik4Y5-5dV7nk" });
256
+ * ```
257
+ */
258
+ async setRecord({ undername, transactionId, ttlSeconds, }) {
259
+ return this.process.send({
260
+ tags: [
261
+ { name: 'Action', value: 'Set-Record' },
262
+ { name: 'Sub-Domain', value: undername },
263
+ { name: 'Transaction-Id', value: transactionId },
264
+ { name: 'TTL-Seconds', value: ttlSeconds.toString() },
265
+ ],
266
+ data: { transactionId, ttlSeconds },
267
+ signer: this.signer,
268
+ });
269
+ }
270
+ /**
271
+ * @param undername @type {string} The record you want to remove.
272
+ * @returns {Promise<AoMessageResult>} The result of the interaction.
273
+ * @example
274
+ * ```ts
275
+ * ant.removeRecord({ subDomain: "shorts" });
276
+ * ```
277
+ */
278
+ async removeRecord({ undername, }) {
279
+ return this.process.send({
280
+ tags: [
281
+ { name: 'Action', value: 'Remove-Record' },
282
+ { name: 'Sub-Domain', value: undername },
283
+ ],
284
+ data: { undername },
285
+ signer: this.signer,
286
+ });
287
+ }
288
+ /**
289
+ * @param ticker @type {string} Sets the ANT Ticker.
290
+ * @returns {Promise<AoMessageResult>} The result of the interaction.
291
+ * @example
292
+ * ```ts
293
+ * ant.setTicker({ ticker: "KAPOW" });
294
+ * ```
295
+ */
296
+ async setTicker({ ticker }) {
297
+ return this.process.send({
298
+ tags: [
299
+ { name: 'Action', value: 'Set-Ticker' },
300
+ { name: 'Ticker', value: ticker },
301
+ ],
302
+ data: { ticker },
303
+ signer: this.signer,
304
+ });
305
+ }
306
+ /**
307
+ * @param name @type {string} Sets the Name of the ANT.
308
+ * @returns {Promise<AoMessageResult>} The result of the interaction.
309
+ * @example
310
+ * ```ts
311
+ * ant.setName({ name: "ships at sea" });
312
+ * ```
313
+ */
314
+ async setName({ name }) {
315
+ return this.process.send({
316
+ tags: [
317
+ { name: 'Action', value: 'Set-Name' },
318
+ { name: 'Name', value: name },
319
+ ],
320
+ data: { name },
321
+ signer: this.signer,
322
+ });
323
+ }
324
+ }
325
+ exports.AoANTWriteable = AoANTWriteable;
@@ -27,7 +27,7 @@ class AOProcess {
27
27
  logger;
28
28
  processId;
29
29
  ao;
30
- constructor({ processId, ao = (0, aoconnect_1.connect)(), logger = new logger_js_1.DefaultLogger({ level: 'info' }), }) {
30
+ constructor({ processId, ao = (0, aoconnect_1.connect)(), logger = logger_js_1.Logger.default, }) {
31
31
  this.processId = processId;
32
32
  this.logger = logger;
33
33
  this.ao = ao;
@@ -7,8 +7,7 @@ const logger_js_1 = require("./logger.js");
7
7
  class AxiosHTTPService {
8
8
  axios;
9
9
  logger;
10
- // TODO: re-implement axios-retry. Currently that package is broken for nodenext.
11
- constructor({ url, logger = new logger_js_1.DefaultLogger(), }) {
10
+ constructor({ url, logger = logger_js_1.Logger.default, }) {
12
11
  this.logger = logger;
13
12
  this.axios = (0, index_js_1.createAxiosInstance)({
14
13
  axiosConfig: {
@@ -35,5 +35,4 @@ __exportStar(require("./logger.js"), exports);
35
35
  __exportStar(require("./ant.js"), exports);
36
36
  // ao
37
37
  __exportStar(require("./io.js"), exports);
38
- __exportStar(require("./ant-ao.js"), exports);
39
38
  __exportStar(require("./contracts/ao-process.js"), exports);
@@ -25,7 +25,6 @@ const constants_js_1 = require("../constants.js");
25
25
  const io_js_1 = require("../io.js");
26
26
  const ao_process_js_1 = require("./contracts/ao-process.js");
27
27
  const error_js_1 = require("./error.js");
28
- const logger_js_1 = require("./logger.js");
29
28
  class IO {
30
29
  static init(config) {
31
30
  if (config && config.signer) {
@@ -54,9 +53,6 @@ class IOReadable {
54
53
  else if ((0, io_js_1.isProcessIdConfiguration)(config)) {
55
54
  this.process = new ao_process_js_1.AOProcess({
56
55
  processId: config.processId,
57
- logger: new logger_js_1.DefaultLogger({
58
- level: 'info',
59
- }),
60
56
  });
61
57
  }
62
58
  else {
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DefaultLogger = void 0;
3
+ exports.Logger = void 0;
4
4
  /**
5
5
  * Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
6
6
  *
@@ -19,9 +19,10 @@ exports.DefaultLogger = void 0;
19
19
  */
20
20
  const winston_1 = require("winston");
21
21
  const version_js_1 = require("../version.js");
22
- class DefaultLogger {
22
+ class Logger {
23
23
  logger;
24
24
  silent = false;
25
+ static default = new Logger();
25
26
  constructor({ level = 'info', } = {}) {
26
27
  if (level === 'none') {
27
28
  this.silent = true;
@@ -70,11 +71,10 @@ class DefaultLogger {
70
71
  setLogLevel(level) {
71
72
  if ('silent' in this.logger) {
72
73
  this.logger.silent = level === 'none';
73
- return;
74
74
  }
75
75
  if ('level' in this.logger) {
76
76
  this.logger.level = level;
77
77
  }
78
78
  }
79
79
  }
80
- exports.DefaultLogger = DefaultLogger;
80
+ exports.Logger = Logger;
@@ -24,7 +24,7 @@ const axios_1 = __importDefault(require("axios"));
24
24
  const axios_retry_1 = __importDefault(require("axios-retry"));
25
25
  const logger_js_1 = require("../common/logger.js");
26
26
  const version_js_1 = require("../version.js");
27
- const createAxiosInstance = ({ axiosConfig = {}, logger = new logger_js_1.DefaultLogger(), retryConfig = {
27
+ const createAxiosInstance = ({ axiosConfig = {}, logger = logger_js_1.Logger.default, retryConfig = {
28
28
  retries: 5,
29
29
  retryDelay: axios_retry_1.default.exponentialDelay,
30
30
  retryCondition: (error) => axios_retry_1.default.isRetryableError(error),
@@ -18,4 +18,4 @@
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
19
19
  exports.version = void 0;
20
20
  // AUTOMATICALLY GENERATED FILE - DO NOT TOUCH
21
- exports.version = '2.0.0-alpha.2';
21
+ exports.version = '2.0.0-alpha.3';