@ar.io/sdk 1.2.2 → 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 (68) hide show
  1. package/README.md +148 -60
  2. package/bundles/web.bundle.min.js +132 -331
  3. package/lib/cjs/common/ant.js +147 -206
  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 -5
  7. package/lib/cjs/common/io.js +39 -31
  8. package/lib/cjs/common/logger.js +31 -19
  9. package/lib/cjs/types.js +0 -1
  10. package/lib/cjs/utils/arweave.js +1 -15
  11. package/lib/cjs/utils/http-client.js +1 -1
  12. package/lib/cjs/utils/index.js +1 -2
  13. package/lib/cjs/utils/{graphql/processes.js → processes.js} +35 -10
  14. package/lib/cjs/version.js +1 -1
  15. package/lib/esm/common/ant.js +144 -203
  16. package/lib/esm/common/contracts/ao-process.js +2 -2
  17. package/lib/esm/common/http.js +2 -3
  18. package/lib/esm/common/index.js +0 -5
  19. package/lib/esm/common/io.js +39 -28
  20. package/lib/esm/common/logger.js +29 -14
  21. package/lib/esm/types.js +0 -1
  22. package/lib/esm/utils/arweave.js +0 -12
  23. package/lib/esm/utils/http-client.js +2 -2
  24. package/lib/esm/utils/index.js +1 -2
  25. package/lib/esm/utils/{graphql/processes.js → processes.js} +33 -9
  26. package/lib/esm/version.js +1 -1
  27. package/lib/types/common/ant.d.ts +53 -175
  28. package/lib/types/common/contracts/ao-process.d.ts +2 -2
  29. package/lib/types/common/http.d.ts +3 -2
  30. package/lib/types/common/index.d.ts +0 -4
  31. package/lib/types/common/io.d.ts +5 -4
  32. package/lib/types/common/logger.d.ts +10 -3
  33. package/lib/types/common.d.ts +1 -145
  34. package/lib/types/io.d.ts +28 -3
  35. package/lib/types/types.d.ts +0 -1
  36. package/lib/types/utils/arweave.d.ts +0 -5
  37. package/lib/types/utils/http-client.d.ts +2 -2
  38. package/lib/types/utils/index.d.ts +1 -2
  39. package/lib/types/utils/{graphql/processes.d.ts → processes.d.ts} +4 -1
  40. package/lib/types/version.d.ts +1 -1
  41. package/package.json +8 -13
  42. package/lib/cjs/arns-service.js +0 -2
  43. package/lib/cjs/common/ant-ao.js +0 -297
  44. package/lib/cjs/common/ar-io.js +0 -741
  45. package/lib/cjs/common/contracts/remote-contract.js +0 -55
  46. package/lib/cjs/common/contracts/warp-contract.js +0 -176
  47. package/lib/cjs/common/warp.js +0 -25
  48. package/lib/cjs/utils/graphql/index.js +0 -34
  49. package/lib/cjs/utils/graphql/smartweave.js +0 -309
  50. package/lib/cjs/utils/smartweave.js +0 -58
  51. package/lib/esm/arns-service.js +0 -1
  52. package/lib/esm/common/ant-ao.js +0 -292
  53. package/lib/esm/common/ar-io.js +0 -735
  54. package/lib/esm/common/contracts/remote-contract.js +0 -51
  55. package/lib/esm/common/contracts/warp-contract.js +0 -172
  56. package/lib/esm/common/warp.js +0 -22
  57. package/lib/esm/utils/graphql/index.js +0 -18
  58. package/lib/esm/utils/graphql/smartweave.js +0 -303
  59. package/lib/esm/utils/smartweave.js +0 -50
  60. package/lib/types/arns-service.d.ts +0 -23
  61. package/lib/types/common/ant-ao.d.ts +0 -194
  62. package/lib/types/common/ar-io.d.ts +0 -551
  63. package/lib/types/common/contracts/remote-contract.d.ts +0 -38
  64. package/lib/types/common/contracts/warp-contract.d.ts +0 -43
  65. package/lib/types/common/warp.d.ts +0 -1
  66. package/lib/types/utils/graphql/index.d.ts +0 -18
  67. package/lib/types/utils/graphql/smartweave.d.ts +0 -47
  68. package/lib/types/utils/smartweave.d.ts +0 -41
@@ -1,31 +1,11 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.IOWriteable = exports.IOReadable = exports.IO = void 0;
7
- /**
8
- * Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
9
- *
10
- * This program is free software: you can redistribute it and/or modify
11
- * it under the terms of the GNU Affero General Public License as published by
12
- * the Free Software Foundation, either version 3 of the License, or
13
- * (at your option) any later version.
14
- *
15
- * This program is distributed in the hope that it will be useful,
16
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
- * GNU Affero General Public License for more details.
19
- *
20
- * You should have received a copy of the GNU Affero General Public License
21
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
22
- */
23
- const arweave_1 = __importDefault(require("arweave"));
24
4
  const constants_js_1 = require("../constants.js");
25
5
  const io_js_1 = require("../io.js");
6
+ const arweave_js_1 = require("./arweave.js");
26
7
  const ao_process_js_1 = require("./contracts/ao-process.js");
27
8
  const error_js_1 = require("./error.js");
28
- const logger_js_1 = require("./logger.js");
29
9
  class IO {
30
10
  static init(config) {
31
11
  if (config && config.signer) {
@@ -42,7 +22,7 @@ exports.IO = IO;
42
22
  class IOReadable {
43
23
  process;
44
24
  arweave;
45
- constructor(config, arweave = arweave_1.default.init({})) {
25
+ constructor(config, arweave = arweave_js_1.defaultArweave) {
46
26
  if (!config) {
47
27
  this.process = new ao_process_js_1.AOProcess({
48
28
  processId: constants_js_1.IO_TESTNET_PROCESS_ID,
@@ -54,9 +34,6 @@ class IOReadable {
54
34
  else if ((0, io_js_1.isProcessIdConfiguration)(config)) {
55
35
  this.process = new ao_process_js_1.AOProcess({
56
36
  processId: config.processId,
57
- logger: new logger_js_1.DefaultLogger({
58
- level: 'info',
59
- }),
60
37
  });
61
38
  }
62
39
  else {
@@ -127,9 +104,17 @@ class IOReadable {
127
104
  ],
128
105
  });
129
106
  }
130
- async getArNSRecords() {
107
+ async getArNSRecords(pageParams) {
108
+ const allTags = [
109
+ { name: 'Action', value: 'Paginated-Records' },
110
+ { name: 'Cursor', value: pageParams?.cursor?.toString() },
111
+ { name: 'Limit', value: pageParams?.limit?.toString() },
112
+ { name: 'Sort-By', value: pageParams?.sortBy },
113
+ { name: 'Sort-Order', value: pageParams?.sortOrder },
114
+ ];
115
+ const prunedTags = allTags.filter((tag) => tag.value !== undefined);
131
116
  return this.process.read({
132
- tags: [{ name: 'Action', value: 'Records' }],
117
+ tags: prunedTags,
133
118
  });
134
119
  }
135
120
  async getArNSReservedNames() {
@@ -153,9 +138,17 @@ class IOReadable {
153
138
  ],
154
139
  });
155
140
  }
156
- async getBalances() {
141
+ async getBalances(pageParams) {
142
+ const allTags = [
143
+ { name: 'Action', value: 'Paginated-Balances' },
144
+ { name: 'Cursor', value: pageParams?.cursor?.toString() },
145
+ { name: 'Limit', value: pageParams?.limit?.toString() },
146
+ { name: 'Sort-By', value: pageParams?.sortBy },
147
+ { name: 'Sort-Order', value: pageParams?.sortOrder },
148
+ ];
149
+ const prunedTags = allTags.filter((tag) => tag.value !== undefined);
157
150
  return this.process.read({
158
- tags: [{ name: 'Action', value: 'Balances' }],
151
+ tags: prunedTags,
159
152
  });
160
153
  }
161
154
  async getGateway({ address, }) {
@@ -166,9 +159,17 @@ class IOReadable {
166
159
  ],
167
160
  });
168
161
  }
169
- async getGateways() {
162
+ async getGateways(pageParams) {
163
+ const allTags = [
164
+ { name: 'Action', value: 'Paginated-Gateways' },
165
+ { name: 'Cursor', value: pageParams?.cursor?.toString() },
166
+ { name: 'Limit', value: pageParams?.limit?.toString() },
167
+ { name: 'Sort-By', value: pageParams?.sortBy },
168
+ { name: 'Sort-Order', value: pageParams?.sortOrder },
169
+ ];
170
+ const prunedTags = allTags.filter((tag) => tag.value !== undefined);
170
171
  return this.process.read({
171
- tags: [{ name: 'Action', value: 'Gateways' }],
172
+ tags: prunedTags,
172
173
  });
173
174
  }
174
175
  async getCurrentEpoch() {
@@ -436,6 +437,13 @@ class IOWriteable extends IOReadable {
436
437
  tags: prunedTags,
437
438
  });
438
439
  }
440
+ async leaveNetwork(options) {
441
+ const { tags = [] } = options || {};
442
+ return this.process.send({
443
+ signer: this.signer,
444
+ tags: [...tags, { name: 'Action', value: 'Leave-Network' }],
445
+ });
446
+ }
439
447
  async updateGatewaySettings({ allowDelegatedStaking, delegateRewardShareRatio, fqdn, label, minDelegatedStake, note, port, properties, protocol, autoStake, observerAddress, }, options) {
440
448
  const { tags = [] } = options || {};
441
449
  const allTags = [
@@ -1,9 +1,6 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.DefaultLogger = void 0;
3
+ exports.Logger = void 0;
7
4
  /**
8
5
  * Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
9
6
  *
@@ -20,49 +17,64 @@ exports.DefaultLogger = void 0;
20
17
  * You should have received a copy of the GNU Affero General Public License
21
18
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22
19
  */
23
- const bunyan_1 = __importDefault(require("bunyan"));
20
+ const winston_1 = require("winston");
24
21
  const version_js_1 = require("../version.js");
25
- class DefaultLogger {
22
+ class Logger {
26
23
  logger;
27
24
  silent = false;
25
+ static default = new Logger();
28
26
  constructor({ level = 'info', } = {}) {
29
27
  if (level === 'none') {
30
28
  this.silent = true;
31
29
  return;
32
30
  }
33
- this.logger = bunyan_1.default.createLogger({
31
+ this.logger = (0, winston_1.createLogger)({
34
32
  level,
35
- name: 'ar-io-sdk',
36
- version: version_js_1.version,
37
- serializers: bunyan_1.default.stdSerializers,
33
+ silent: this.silent,
34
+ defaultMeta: {
35
+ name: 'ar-io-sdk',
36
+ version: version_js_1.version,
37
+ },
38
+ format: winston_1.format.combine(winston_1.format.timestamp(), winston_1.format.json()),
38
39
  });
40
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
41
+ // @ts-ignore
42
+ if (typeof window !== 'undefined') {
43
+ this.logger = console;
44
+ }
45
+ else {
46
+ this.logger.add(new winston_1.transports.Console({
47
+ format: winston_1.format.combine(winston_1.format.timestamp(), winston_1.format.json()),
48
+ }));
49
+ }
39
50
  }
40
51
  info(message, ...args) {
41
52
  if (this.silent)
42
53
  return;
43
- this.logger.info(...args, message);
54
+ this.logger.info(message, ...args);
44
55
  }
45
56
  warn(message, ...args) {
46
57
  if (this.silent)
47
58
  return;
48
- this.logger.warn(...args, message);
59
+ this.logger.warn(message, ...args);
49
60
  }
50
61
  error(message, ...args) {
51
62
  if (this.silent)
52
63
  return;
53
- this.logger.error(...args, message);
64
+ this.logger.error(message, ...args);
54
65
  }
55
66
  debug(message, ...args) {
56
67
  if (this.silent)
57
68
  return;
58
- this.logger.debug(...args, message);
69
+ this.logger.debug(message, ...args);
59
70
  }
60
71
  setLogLevel(level) {
61
- if (level === 'none') {
62
- this.silent = true;
63
- return;
72
+ if ('silent' in this.logger) {
73
+ this.logger.silent = level === 'none';
74
+ }
75
+ if ('level' in this.logger) {
76
+ this.logger.level = level;
64
77
  }
65
- this.logger.level(level);
66
78
  }
67
79
  }
68
- exports.DefaultLogger = DefaultLogger;
80
+ exports.Logger = Logger;
package/lib/cjs/types.js CHANGED
@@ -30,7 +30,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
30
30
  * You should have received a copy of the GNU Affero General Public License
31
31
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
32
32
  */
33
- __exportStar(require("./arns-service.js"), exports);
34
33
  __exportStar(require("./contract-state.js"), exports);
35
34
  __exportStar(require("./common.js"), exports);
36
35
  __exportStar(require("./token.js"), exports);
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.tagsToObject = exports.isTransaction = exports.isBlockHeight = exports.validateArweaveId = void 0;
3
+ exports.isBlockHeight = exports.validateArweaveId = void 0;
4
4
  const constants_js_1 = require("../constants.js");
5
5
  const validateArweaveId = (id) => {
6
6
  return constants_js_1.ARWEAVE_TX_REGEX.test(id);
@@ -10,17 +10,3 @@ function isBlockHeight(height) {
10
10
  return height !== undefined && !isNaN(parseInt(height.toString()));
11
11
  }
12
12
  exports.isBlockHeight = isBlockHeight;
13
- const isTransaction = (tx) => {
14
- const requiredTxKeys = ['id', 'owner', 'tags', 'signature'];
15
- return requiredTxKeys.every((key) => key in tx);
16
- };
17
- exports.isTransaction = isTransaction;
18
- function tagsToObject(tags) {
19
- return tags.reduce((decodedTags, tag) => {
20
- const key = tag.get('name', { decode: true, string: true });
21
- const value = tag.get('value', { decode: true, string: true });
22
- decodedTags[key] = value;
23
- return decodedTags;
24
- }, {});
25
- }
26
- exports.tagsToObject = tagsToObject;
@@ -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),
@@ -32,7 +32,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
32
32
  */
33
33
  __exportStar(require("./arweave.js"), exports);
34
34
  __exportStar(require("./http-client.js"), exports);
35
- __exportStar(require("./smartweave.js"), exports);
36
- __exportStar(require("./graphql/index.js"), exports);
37
35
  __exportStar(require("./ao.js"), exports);
38
36
  __exportStar(require("./json.js"), exports);
37
+ __exportStar(require("./processes.js"), exports);
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ArNSEventEmitter = exports.getANTProcessesOwnedByWallet = void 0;
3
+ exports.fetchAllArNSRecords = exports.ArNSEventEmitter = exports.getANTProcessesOwnedByWallet = void 0;
4
4
  /**
5
5
  * Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
6
6
  *
@@ -19,19 +19,20 @@ exports.ArNSEventEmitter = exports.getANTProcessesOwnedByWallet = void 0;
19
19
  */
20
20
  const eventemitter3_1 = require("eventemitter3");
21
21
  const plimit_lit_1 = require("plimit-lit");
22
- const ant_js_1 = require("../../common/ant.js");
23
- const io_js_1 = require("../../common/io.js");
24
- const constants_js_1 = require("../../constants.js");
22
+ const ant_js_1 = require("../common/ant.js");
23
+ const io_js_1 = require("../common/io.js");
24
+ const constants_js_1 = require("../constants.js");
25
25
  const getANTProcessesOwnedByWallet = async ({ address, contract = io_js_1.IO.init({
26
26
  processId: constants_js_1.IO_TESTNET_PROCESS_ID,
27
27
  }), }) => {
28
28
  const throttle = (0, plimit_lit_1.pLimit)(50);
29
29
  // get the record names of the registry - TODO: this may need to be paginated
30
- const uniqueContractProcessIds = await contract
31
- .getArNSRecords()
32
- .then((records) => Object.values(records)
30
+ const records = await (0, exports.fetchAllArNSRecords)({
31
+ contract: contract,
32
+ });
33
+ const uniqueContractProcessIds = Object.values(records)
33
34
  .filter((record) => record.processId !== undefined)
34
- .map((record) => record.processId));
35
+ .map((record) => record.processId);
35
36
  // check the contract owner and controllers
36
37
  const ownedOrControlledByWallet = await Promise.all(uniqueContractProcessIds.map(async (processId) => throttle(async () => {
37
38
  const ant = ant_js_1.ANT.init({
@@ -80,10 +81,12 @@ class ArNSEventEmitter extends eventemitter3_1.EventEmitter {
80
81
  }
81
82
  async fetchProcessesOwnedByWallet({ address }) {
82
83
  const uniqueContractProcessIds = {};
83
- await timeout(this.timeoutMs, this.contract.getArNSRecords().catch((e) => {
84
+ await timeout(this.timeoutMs, (0, exports.fetchAllArNSRecords)({ contract: this.contract }))
85
+ .catch((e) => {
84
86
  this.emit('error', `Error getting ArNS records: ${e}`);
85
87
  return {};
86
- })).then((records) => {
88
+ })
89
+ .then((records) => {
87
90
  if (!records)
88
91
  return;
89
92
  Object.entries(records).forEach(([name, record]) => {
@@ -125,3 +128,25 @@ class ArNSEventEmitter extends eventemitter3_1.EventEmitter {
125
128
  }
126
129
  }
127
130
  exports.ArNSEventEmitter = ArNSEventEmitter;
131
+ const fetchAllArNSRecords = async ({ contract = io_js_1.IO.init({
132
+ processId: constants_js_1.IO_TESTNET_PROCESS_ID,
133
+ }), }) => {
134
+ let cursor;
135
+ const records = {};
136
+ do {
137
+ const pageResult = await contract.getArNSRecords({ cursor }).catch((e) => {
138
+ console.error(`Error getting ArNS records: ${e}`);
139
+ return undefined;
140
+ });
141
+ if (!pageResult) {
142
+ return {};
143
+ }
144
+ pageResult.items.forEach((record) => {
145
+ const { name, ...recordDetails } = record;
146
+ records[name] = recordDetails;
147
+ });
148
+ cursor = pageResult.nextCursor;
149
+ } while (cursor !== undefined);
150
+ return records;
151
+ };
152
+ exports.fetchAllArNSRecords = fetchAllArNSRecords;
@@ -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 = '1.2.2';
21
+ exports.version = '2.0.0-alpha.10';