@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.
Files changed (41) hide show
  1. package/README.md +144 -60
  2. package/bundles/web.bundle.min.js +131 -98
  3. package/lib/cjs/common/ant.js +294 -3
  4. package/lib/cjs/common/contracts/ao-process.js +1 -1
  5. package/lib/cjs/common/http.js +1 -2
  6. package/lib/cjs/common/index.js +0 -1
  7. package/lib/cjs/common/io.js +87 -39
  8. package/lib/cjs/common/logger.js +31 -19
  9. package/lib/cjs/utils/http-client.js +1 -1
  10. package/lib/cjs/utils/index.js +1 -1
  11. package/lib/cjs/utils/{graphql/processes.js → processes.js} +35 -10
  12. package/lib/cjs/version.js +1 -1
  13. package/lib/esm/common/ant.js +290 -1
  14. package/lib/esm/common/contracts/ao-process.js +2 -2
  15. package/lib/esm/common/http.js +2 -3
  16. package/lib/esm/common/index.js +0 -1
  17. package/lib/esm/common/io.js +87 -36
  18. package/lib/esm/common/logger.js +29 -14
  19. package/lib/esm/utils/http-client.js +2 -2
  20. package/lib/esm/utils/index.js +1 -1
  21. package/lib/esm/utils/{graphql/processes.js → processes.js} +33 -9
  22. package/lib/esm/version.js +1 -1
  23. package/lib/types/common/ant.d.ts +174 -23
  24. package/lib/types/common/contracts/ao-process.d.ts +2 -2
  25. package/lib/types/common/http.d.ts +3 -2
  26. package/lib/types/common/index.d.ts +0 -1
  27. package/lib/types/common/io.d.ts +5 -4
  28. package/lib/types/common/logger.d.ts +10 -3
  29. package/lib/types/common.d.ts +0 -7
  30. package/lib/types/io.d.ts +28 -3
  31. package/lib/types/utils/http-client.d.ts +2 -2
  32. package/lib/types/utils/index.d.ts +1 -1
  33. package/lib/types/utils/{graphql/processes.d.ts → processes.d.ts} +4 -1
  34. package/lib/types/version.d.ts +1 -1
  35. package/package.json +6 -6
  36. package/lib/cjs/common/ant-ao.js +0 -297
  37. package/lib/cjs/utils/graphql/index.js +0 -33
  38. package/lib/esm/common/ant-ao.js +0 -292
  39. package/lib/esm/utils/graphql/index.js +0 -17
  40. package/lib/types/common/ant-ao.d.ts +0 -194
  41. package/lib/types/utils/graphql/index.d.ts +0 -17
@@ -1,297 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AoANTWriteable = exports.AoANTReadable = void 0;
4
- const io_js_1 = require("../io.js");
5
- const ao_process_js_1 = require("./contracts/ao-process.js");
6
- const error_js_1 = require("./error.js");
7
- class AoANTReadable {
8
- process;
9
- constructor(config) {
10
- if ((0, io_js_1.isProcessConfiguration)(config)) {
11
- this.process = config.process;
12
- }
13
- else if ((0, io_js_1.isProcessIdConfiguration)(config)) {
14
- this.process = new ao_process_js_1.AOProcess({
15
- processId: config.processId,
16
- });
17
- }
18
- else {
19
- throw new error_js_1.InvalidContractConfigurationError();
20
- }
21
- }
22
- async getState() {
23
- const tags = [{ name: 'Action', value: 'State' }];
24
- const res = await this.process.read({
25
- tags,
26
- });
27
- return res;
28
- }
29
- async getInfo() {
30
- const tags = [{ name: 'Action', value: 'Info' }];
31
- const info = await this.process.read({
32
- tags,
33
- });
34
- return info;
35
- }
36
- /**
37
- * @param undername @type {string} The domain name.
38
- * @returns {Promise<ANTRecord>} The record of the undername domain.
39
- * @example
40
- * Get the current record
41
- * ```ts
42
- * ant.getRecord({ undername: "john" });
43
- * ```
44
- */
45
- async getRecord({ undername }) {
46
- const tags = [
47
- { name: 'Sub-Domain', value: undername },
48
- { name: 'Action', value: 'Record' },
49
- ];
50
- const record = await this.process.read({
51
- tags,
52
- });
53
- return record;
54
- }
55
- /**
56
- * @returns {Promise<Record<string, ANTRecord>>} All the undernames managed by the ANT.
57
- * @example
58
- * Get the current records
59
- * ```ts
60
- * ant.getRecords();
61
- * ````
62
- */
63
- async getRecords() {
64
- const tags = [{ name: 'Action', value: 'Records' }];
65
- const records = await this.process.read({
66
- tags,
67
- });
68
- return records;
69
- }
70
- /**
71
- * @returns {Promise<string>} The owner of the ANT.
72
- * @example
73
- * Get the current owner
74
- * ```ts
75
- * ant.getOwner();
76
- * ```
77
- */
78
- async getOwner() {
79
- const info = await this.getInfo();
80
- return info.Owner;
81
- }
82
- /**
83
- * @returns {Promise<string[]>} The controllers of the ANT.
84
- * @example
85
- * Get the controllers of the ANT.
86
- * ```ts
87
- * ant.getControllers();
88
- * ```
89
- */
90
- async getControllers() {
91
- const tags = [{ name: 'Action', value: 'Controllers' }];
92
- const controllers = await this.process.read({
93
- tags,
94
- });
95
- return controllers;
96
- }
97
- /**
98
- * @returns {Promise<string>} The name of the ANT (not the same as ArNS name).
99
- * @example
100
- * Get the current name
101
- * ```ts
102
- * ant.getName();
103
- * ```
104
- */
105
- async getName() {
106
- const info = await this.getInfo();
107
- return info.Name;
108
- }
109
- /**
110
- * @returns {Promise<string>} The name of the ANT (not the same as ArNS name).
111
- * @example
112
- * The current ticker of the ANT.
113
- * ```ts
114
- * ant.getTicker();
115
- * ```
116
- */
117
- async getTicker() {
118
- const info = await this.getInfo();
119
- return info.Ticker;
120
- }
121
- /**
122
- * @returns {Promise<Record<WalletAddress, number>>} The balances of the ANT
123
- * @example
124
- * The current balances of the ANT.
125
- * ```ts
126
- * ant.getBalances();
127
- * ```
128
- */
129
- async getBalances() {
130
- const tags = [{ name: 'Action', value: 'Balances' }];
131
- const balances = await this.process.read({
132
- tags,
133
- });
134
- return balances;
135
- }
136
- /**
137
- * @param address @type {string} The address of the account you want the balance of.
138
- * @returns {Promise<number>} The balance of the provided address
139
- * @example
140
- * The current balance of the address.
141
- * ```ts
142
- * ant.getBalance({ address });
143
- * ```
144
- */
145
- async getBalance({ address }) {
146
- const tags = [
147
- { name: 'Action', value: 'Balance' },
148
- { name: 'Recipient', value: address },
149
- ];
150
- const balance = await this.process.read({
151
- tags,
152
- });
153
- return balance;
154
- }
155
- }
156
- exports.AoANTReadable = AoANTReadable;
157
- class AoANTWriteable extends AoANTReadable {
158
- signer;
159
- constructor({ signer, ...config }) {
160
- super(config);
161
- this.signer = signer;
162
- }
163
- /**
164
- * @param target @type {string} The address of the account you want to transfer the ANT to.
165
- * @returns {Promise<AoMessageResult>} The result of the interaction.
166
- * @example
167
- * ```ts
168
- * ant.transfer({ target: "fGht8v4STuwPnTck1zFVkQqJh5K9q9Zik4Y5-5dV7nk" });
169
- * ```
170
- */
171
- async transfer({ target }) {
172
- const tags = [
173
- { name: 'Action', value: 'Transfer' },
174
- { name: 'Recipient', value: target },
175
- ];
176
- return this.process.send({
177
- tags,
178
- data: {},
179
- signer: this.signer,
180
- });
181
- }
182
- /**
183
- * @param controller @type {string} The address of the account you want to set as a controller.
184
- * @returns {Promise<AoMessageResult>} The result of the interaction.
185
- * @example
186
- * ```ts
187
- * ant.setController({ controller: "fGht8v4STuwPnTck1zFVkQqJh5K9q9Zik4Y5-5dV7nk" });
188
- * ```
189
- */
190
- async addController({ controller, }) {
191
- const tags = [
192
- { name: 'Action', value: 'Add-Controller' },
193
- { name: 'Controller', value: controller },
194
- ];
195
- return this.process.send({
196
- tags,
197
- data: {},
198
- signer: this.signer,
199
- });
200
- }
201
- /**
202
- * @param controller @type {string} The address of the account you want to remove from the controllers list
203
- * @returns {Promise<AoMessageResult>} The result of the interaction.
204
- * @example
205
- * ```ts
206
- * ant.removeController({ controller: "fGht8v4STuwPnTck1zFVkQqJh5K9q9Zik4Y5-5dV7nk" });
207
- * ```
208
- */
209
- async removeController({ controller, }) {
210
- const tags = [
211
- { name: 'Action', value: 'Remove-Controller' },
212
- { name: 'Controller', value: controller },
213
- ];
214
- return this.process.send({
215
- tags,
216
- data: {},
217
- signer: this.signer,
218
- });
219
- }
220
- /**
221
- * @param undername @type {string} The record you want to set the transactionId and ttlSeconds of.
222
- * @param transactionId @type {string} The transactionId of the record.
223
- * @param ttlSeconds @type {number} The time to live of the record.
224
- * @returns {Promise<AoMessageResult>} The result of the interaction.
225
- * @example
226
- * ```ts
227
- * ant.setController({ controller: "fGht8v4STuwPnTck1zFVkQqJh5K9q9Zik4Y5-5dV7nk" });
228
- * ```
229
- */
230
- async setRecord({ undername, transactionId, ttlSeconds, }) {
231
- return this.process.send({
232
- tags: [
233
- { name: 'Action', value: 'Set-Record' },
234
- { name: 'Sub-Domain', value: undername },
235
- { name: 'Transaction-Id', value: transactionId },
236
- { name: 'TTL-Seconds', value: ttlSeconds.toString() },
237
- ],
238
- data: { transactionId, ttlSeconds },
239
- signer: this.signer,
240
- });
241
- }
242
- /**
243
- * @param undername @type {string} The record you want to remove.
244
- * @returns {Promise<AoMessageResult>} The result of the interaction.
245
- * @example
246
- * ```ts
247
- * ant.removeRecord({ subDomain: "shorts" });
248
- * ```
249
- */
250
- async removeRecord({ undername, }) {
251
- return this.process.send({
252
- tags: [
253
- { name: 'Action', value: 'Remove-Record' },
254
- { name: 'Sub-Domain', value: undername },
255
- ],
256
- data: { undername },
257
- signer: this.signer,
258
- });
259
- }
260
- /**
261
- * @param ticker @type {string} Sets the ANT Ticker.
262
- * @returns {Promise<AoMessageResult>} The result of the interaction.
263
- * @example
264
- * ```ts
265
- * ant.setTicker({ ticker: "KAPOW" });
266
- * ```
267
- */
268
- async setTicker({ ticker }) {
269
- return this.process.send({
270
- tags: [
271
- { name: 'Action', value: 'Set-Ticker' },
272
- { name: 'Ticker', value: ticker },
273
- ],
274
- data: { ticker },
275
- signer: this.signer,
276
- });
277
- }
278
- /**
279
- * @param name @type {string} Sets the Name of the ANT.
280
- * @returns {Promise<AoMessageResult>} The result of the interaction.
281
- * @example
282
- * ```ts
283
- * ant.setName({ name: "ships at sea" });
284
- * ```
285
- */
286
- async setName({ name }) {
287
- return this.process.send({
288
- tags: [
289
- { name: 'Action', value: 'Set-Name' },
290
- { name: 'Name', value: name },
291
- ],
292
- data: { name },
293
- signer: this.signer,
294
- });
295
- }
296
- }
297
- exports.AoANTWriteable = AoANTWriteable;
@@ -1,33 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- /**
18
- * Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
19
- *
20
- * This program is free software: you can redistribute it and/or modify
21
- * it under the terms of the GNU Affero General Public License as published by
22
- * the Free Software Foundation, either version 3 of the License, or
23
- * (at your option) any later version.
24
- *
25
- * This program is distributed in the hope that it will be useful,
26
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
27
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28
- * GNU Affero General Public License for more details.
29
- *
30
- * You should have received a copy of the GNU Affero General Public License
31
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
32
- */
33
- __exportStar(require("./processes.js"), exports);
@@ -1,292 +0,0 @@
1
- import { isProcessConfiguration, isProcessIdConfiguration, } from '../io.js';
2
- import { AOProcess } from './contracts/ao-process.js';
3
- import { InvalidContractConfigurationError } from './error.js';
4
- export class AoANTReadable {
5
- process;
6
- constructor(config) {
7
- if (isProcessConfiguration(config)) {
8
- this.process = config.process;
9
- }
10
- else if (isProcessIdConfiguration(config)) {
11
- this.process = new AOProcess({
12
- processId: config.processId,
13
- });
14
- }
15
- else {
16
- throw new InvalidContractConfigurationError();
17
- }
18
- }
19
- async getState() {
20
- const tags = [{ name: 'Action', value: 'State' }];
21
- const res = await this.process.read({
22
- tags,
23
- });
24
- return res;
25
- }
26
- async getInfo() {
27
- const tags = [{ name: 'Action', value: 'Info' }];
28
- const info = await this.process.read({
29
- tags,
30
- });
31
- return info;
32
- }
33
- /**
34
- * @param undername @type {string} The domain name.
35
- * @returns {Promise<ANTRecord>} The record of the undername domain.
36
- * @example
37
- * Get the current record
38
- * ```ts
39
- * ant.getRecord({ undername: "john" });
40
- * ```
41
- */
42
- async getRecord({ undername }) {
43
- const tags = [
44
- { name: 'Sub-Domain', value: undername },
45
- { name: 'Action', value: 'Record' },
46
- ];
47
- const record = await this.process.read({
48
- tags,
49
- });
50
- return record;
51
- }
52
- /**
53
- * @returns {Promise<Record<string, ANTRecord>>} All the undernames managed by the ANT.
54
- * @example
55
- * Get the current records
56
- * ```ts
57
- * ant.getRecords();
58
- * ````
59
- */
60
- async getRecords() {
61
- const tags = [{ name: 'Action', value: 'Records' }];
62
- const records = await this.process.read({
63
- tags,
64
- });
65
- return records;
66
- }
67
- /**
68
- * @returns {Promise<string>} The owner of the ANT.
69
- * @example
70
- * Get the current owner
71
- * ```ts
72
- * ant.getOwner();
73
- * ```
74
- */
75
- async getOwner() {
76
- const info = await this.getInfo();
77
- return info.Owner;
78
- }
79
- /**
80
- * @returns {Promise<string[]>} The controllers of the ANT.
81
- * @example
82
- * Get the controllers of the ANT.
83
- * ```ts
84
- * ant.getControllers();
85
- * ```
86
- */
87
- async getControllers() {
88
- const tags = [{ name: 'Action', value: 'Controllers' }];
89
- const controllers = await this.process.read({
90
- tags,
91
- });
92
- return controllers;
93
- }
94
- /**
95
- * @returns {Promise<string>} The name of the ANT (not the same as ArNS name).
96
- * @example
97
- * Get the current name
98
- * ```ts
99
- * ant.getName();
100
- * ```
101
- */
102
- async getName() {
103
- const info = await this.getInfo();
104
- return info.Name;
105
- }
106
- /**
107
- * @returns {Promise<string>} The name of the ANT (not the same as ArNS name).
108
- * @example
109
- * The current ticker of the ANT.
110
- * ```ts
111
- * ant.getTicker();
112
- * ```
113
- */
114
- async getTicker() {
115
- const info = await this.getInfo();
116
- return info.Ticker;
117
- }
118
- /**
119
- * @returns {Promise<Record<WalletAddress, number>>} The balances of the ANT
120
- * @example
121
- * The current balances of the ANT.
122
- * ```ts
123
- * ant.getBalances();
124
- * ```
125
- */
126
- async getBalances() {
127
- const tags = [{ name: 'Action', value: 'Balances' }];
128
- const balances = await this.process.read({
129
- tags,
130
- });
131
- return balances;
132
- }
133
- /**
134
- * @param address @type {string} The address of the account you want the balance of.
135
- * @returns {Promise<number>} The balance of the provided address
136
- * @example
137
- * The current balance of the address.
138
- * ```ts
139
- * ant.getBalance({ address });
140
- * ```
141
- */
142
- async getBalance({ address }) {
143
- const tags = [
144
- { name: 'Action', value: 'Balance' },
145
- { name: 'Recipient', value: address },
146
- ];
147
- const balance = await this.process.read({
148
- tags,
149
- });
150
- return balance;
151
- }
152
- }
153
- export class AoANTWriteable extends AoANTReadable {
154
- signer;
155
- constructor({ signer, ...config }) {
156
- super(config);
157
- this.signer = signer;
158
- }
159
- /**
160
- * @param target @type {string} The address of the account you want to transfer the ANT to.
161
- * @returns {Promise<AoMessageResult>} The result of the interaction.
162
- * @example
163
- * ```ts
164
- * ant.transfer({ target: "fGht8v4STuwPnTck1zFVkQqJh5K9q9Zik4Y5-5dV7nk" });
165
- * ```
166
- */
167
- async transfer({ target }) {
168
- const tags = [
169
- { name: 'Action', value: 'Transfer' },
170
- { name: 'Recipient', value: target },
171
- ];
172
- return this.process.send({
173
- tags,
174
- data: {},
175
- signer: this.signer,
176
- });
177
- }
178
- /**
179
- * @param controller @type {string} The address of the account you want to set as a controller.
180
- * @returns {Promise<AoMessageResult>} The result of the interaction.
181
- * @example
182
- * ```ts
183
- * ant.setController({ controller: "fGht8v4STuwPnTck1zFVkQqJh5K9q9Zik4Y5-5dV7nk" });
184
- * ```
185
- */
186
- async addController({ controller, }) {
187
- const tags = [
188
- { name: 'Action', value: 'Add-Controller' },
189
- { name: 'Controller', value: controller },
190
- ];
191
- return this.process.send({
192
- tags,
193
- data: {},
194
- signer: this.signer,
195
- });
196
- }
197
- /**
198
- * @param controller @type {string} The address of the account you want to remove from the controllers list
199
- * @returns {Promise<AoMessageResult>} The result of the interaction.
200
- * @example
201
- * ```ts
202
- * ant.removeController({ controller: "fGht8v4STuwPnTck1zFVkQqJh5K9q9Zik4Y5-5dV7nk" });
203
- * ```
204
- */
205
- async removeController({ controller, }) {
206
- const tags = [
207
- { name: 'Action', value: 'Remove-Controller' },
208
- { name: 'Controller', value: controller },
209
- ];
210
- return this.process.send({
211
- tags,
212
- data: {},
213
- signer: this.signer,
214
- });
215
- }
216
- /**
217
- * @param undername @type {string} The record you want to set the transactionId and ttlSeconds of.
218
- * @param transactionId @type {string} The transactionId of the record.
219
- * @param ttlSeconds @type {number} The time to live of the record.
220
- * @returns {Promise<AoMessageResult>} The result of the interaction.
221
- * @example
222
- * ```ts
223
- * ant.setController({ controller: "fGht8v4STuwPnTck1zFVkQqJh5K9q9Zik4Y5-5dV7nk" });
224
- * ```
225
- */
226
- async setRecord({ undername, transactionId, ttlSeconds, }) {
227
- return this.process.send({
228
- tags: [
229
- { name: 'Action', value: 'Set-Record' },
230
- { name: 'Sub-Domain', value: undername },
231
- { name: 'Transaction-Id', value: transactionId },
232
- { name: 'TTL-Seconds', value: ttlSeconds.toString() },
233
- ],
234
- data: { transactionId, ttlSeconds },
235
- signer: this.signer,
236
- });
237
- }
238
- /**
239
- * @param undername @type {string} The record you want to remove.
240
- * @returns {Promise<AoMessageResult>} The result of the interaction.
241
- * @example
242
- * ```ts
243
- * ant.removeRecord({ subDomain: "shorts" });
244
- * ```
245
- */
246
- async removeRecord({ undername, }) {
247
- return this.process.send({
248
- tags: [
249
- { name: 'Action', value: 'Remove-Record' },
250
- { name: 'Sub-Domain', value: undername },
251
- ],
252
- data: { undername },
253
- signer: this.signer,
254
- });
255
- }
256
- /**
257
- * @param ticker @type {string} Sets the ANT Ticker.
258
- * @returns {Promise<AoMessageResult>} The result of the interaction.
259
- * @example
260
- * ```ts
261
- * ant.setTicker({ ticker: "KAPOW" });
262
- * ```
263
- */
264
- async setTicker({ ticker }) {
265
- return this.process.send({
266
- tags: [
267
- { name: 'Action', value: 'Set-Ticker' },
268
- { name: 'Ticker', value: ticker },
269
- ],
270
- data: { ticker },
271
- signer: this.signer,
272
- });
273
- }
274
- /**
275
- * @param name @type {string} Sets the Name of the ANT.
276
- * @returns {Promise<AoMessageResult>} The result of the interaction.
277
- * @example
278
- * ```ts
279
- * ant.setName({ name: "ships at sea" });
280
- * ```
281
- */
282
- async setName({ name }) {
283
- return this.process.send({
284
- tags: [
285
- { name: 'Action', value: 'Set-Name' },
286
- { name: 'Name', value: name },
287
- ],
288
- data: { name },
289
- signer: this.signer,
290
- });
291
- }
292
- }
@@ -1,17 +0,0 @@
1
- /**
2
- * Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
3
- *
4
- * This program is free software: you can redistribute it and/or modify
5
- * it under the terms of the GNU Affero General Public License as published by
6
- * the Free Software Foundation, either version 3 of the License, or
7
- * (at your option) any later version.
8
- *
9
- * This program is distributed in the hope that it will be useful,
10
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
- * GNU Affero General Public License for more details.
13
- *
14
- * You should have received a copy of the GNU Affero General Public License
15
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
16
- */
17
- export * from './processes.js';