@ar.io/sdk 3.3.0-alpha.11 → 3.3.0-alpha.13

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.
@@ -671,6 +671,7 @@ const utils_js_1 = require("./utils.js");
671
671
  action: async (options) => {
672
672
  const process = new index_js_1.AOProcess({
673
673
  processId: (0, utils_js_1.requiredProcessIdFromOptions)(options),
674
+ logger: (0, utils_js_1.getLoggerFromOptions)(options),
674
675
  });
675
676
  return process.send({
676
677
  tags: (0, utils_js_1.writeActionTagsFromOptions)(options).tags ?? [],
@@ -198,7 +198,7 @@ function paginationParamsFromOptions(options) {
198
198
  return {
199
199
  cursor,
200
200
  limit: numberLimit,
201
- sortBy,
201
+ sortBy: sortBy,
202
202
  sortOrder,
203
203
  };
204
204
  }
@@ -18,6 +18,7 @@ exports.AOProcess = void 0;
18
18
  */
19
19
  const aoconnect_1 = require("@permaweb/aoconnect");
20
20
  const base64_js_1 = require("../../utils/base64.js");
21
+ const index_js_1 = require("../../utils/index.js");
21
22
  const json_js_1 = require("../../utils/json.js");
22
23
  const version_js_1 = require("../../version.js");
23
24
  const error_js_1 = require("../error.js");
@@ -59,7 +60,7 @@ class AOProcess {
59
60
  result,
60
61
  processId: this.processId,
61
62
  });
62
- const error = errorMessageFromOutput(result);
63
+ const error = (0, index_js_1.errorMessageFromOutput)(result);
63
64
  if (error !== undefined) {
64
65
  throw new Error(error);
65
66
  }
@@ -131,7 +132,7 @@ class AOProcess {
131
132
  messageId,
132
133
  processId: this.processId,
133
134
  });
134
- const error = errorMessageFromOutput(output);
135
+ const error = (0, index_js_1.errorMessageFromOutput)(output);
135
136
  if (error !== undefined) {
136
137
  throw new error_js_1.WriteInteractionError(error);
137
138
  }
@@ -181,18 +182,3 @@ class AOProcess {
181
182
  }
182
183
  }
183
184
  exports.AOProcess = AOProcess;
184
- function errorMessageFromOutput(output) {
185
- const errorData = output.Error;
186
- // Attempt to extract error details from Messages.Tags if Error is undefined
187
- const error = errorData ??
188
- output.Messages?.[0]?.Tags?.find((tag) => tag.name === 'Error')?.value;
189
- if (error !== undefined) {
190
- // Consolidated regex to match and extract line number and AO error message or Error Tags
191
- const match = error.match(/\[string "aos"]:(\d+):\s*(.+)/);
192
- if (match) {
193
- const [, lineNumber, errorMessage] = match;
194
- return `${errorMessage.trim()} (line ${lineNumber.trim()})`.trim();
195
- }
196
- }
197
- return undefined;
198
- }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseAoEpochData = exports.initANTStateForAddress = exports.defaultTargetManifestId = exports.createAoSigner = exports.isAoSigner = exports.evolveANT = exports.spawnANT = void 0;
3
+ exports.removeUnicodeFromError = exports.errorMessageFromOutput = exports.parseAoEpochData = exports.initANTStateForAddress = exports.defaultTargetManifestId = exports.createAoSigner = exports.isAoSigner = exports.evolveANT = exports.spawnANT = void 0;
4
4
  /**
5
5
  * Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
6
6
  *
@@ -219,3 +219,30 @@ function parseAoEpochData(value) {
219
219
  return epochDataSchema.parse(value);
220
220
  }
221
221
  exports.parseAoEpochData = parseAoEpochData;
222
+ function errorMessageFromOutput(output) {
223
+ const errorData = output.Error;
224
+ // Attempt to extract error details from Messages.Tags if Error is undefined
225
+ const error = errorData ??
226
+ output.Messages?.[0]?.Tags?.find((tag) => tag.name === 'Error')?.value;
227
+ if (error !== undefined) {
228
+ // Consolidated regex to match and extract line number and AO error message or Error Tags
229
+ const match = error.match(/\[string "aos"]:(\d+):\s*(.+)/);
230
+ if (match) {
231
+ const [, lineNumber, errorMessage] = match;
232
+ const cleanError = removeUnicodeFromError(errorMessage);
233
+ return `${cleanError.trim()} (line ${lineNumber.trim()})`.trim();
234
+ }
235
+ // With no match, just remove unicode
236
+ return removeUnicodeFromError(error);
237
+ }
238
+ return undefined;
239
+ }
240
+ exports.errorMessageFromOutput = errorMessageFromOutput;
241
+ function removeUnicodeFromError(error) {
242
+ //The regular expression /[\u001b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g is designed to match ANSI escape codes used for terminal formatting. These are sequences that begin with \u001b (ESC character) and are often followed by [ and control codes.
243
+ const ESC = String.fromCharCode(27); // Represents '\u001b' or '\x1b'
244
+ return error
245
+ .replace(new RegExp(`${ESC}[\\[\\]()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]`, 'g'), '')
246
+ .trim();
247
+ }
248
+ exports.removeUnicodeFromError = removeUnicodeFromError;
@@ -35,22 +35,40 @@ exports.paginationParamsToTags = paginationParamsToTags;
35
35
  * @param arweave - The Arweave instance
36
36
  * @returns The epoch with distribution data
37
37
  */
38
- const getEpochDataFromGql = async ({ arweave, epochIndex, processId = constants_js_1.ARIO_TESTNET_PROCESS_ID, }) => {
38
+ const getEpochDataFromGql = async ({ arweave, epochIndex, processId = constants_js_1.ARIO_TESTNET_PROCESS_ID, retries = 3, }) => {
39
39
  // fetch from gql
40
40
  const query = (0, exports.epochDistributionNoticeGqlQuery)({ epochIndex, processId });
41
- const response = await arweave.api.post('graphql', query);
42
- // parse the nodes to get the id
43
- if (response.data.data.transactions?.edges?.length === 0) {
44
- return undefined;
41
+ // add three retries with exponential backoff
42
+ for (let i = 0; i < retries; i++) {
43
+ try {
44
+ const response = await arweave.api.post('graphql', query);
45
+ // parse the nodes to get the id
46
+ if (response.data?.data?.transactions?.edges?.length === 0) {
47
+ return undefined;
48
+ }
49
+ const id = response.data.data.transactions.edges[0].node.id;
50
+ // fetch the transaction from arweave
51
+ const transaction = await arweave.api.get(id);
52
+ // assert it is the correct type
53
+ return (0, ao_js_1.parseAoEpochData)(transaction.data);
54
+ }
55
+ catch (error) {
56
+ if (i === retries - 1)
57
+ throw error; // Re-throw on final attempt
58
+ // exponential backoff
59
+ await new Promise((resolve) => setTimeout(resolve, Math.pow(2, i) * 1000));
60
+ }
45
61
  }
46
- const id = response.data.data.transactions.edges[0].node.id;
47
- // fetch the transaction from arweave
48
- const transaction = await arweave.api.get(id);
49
- const data = transaction.data;
50
- // assert it is the correct type
51
- return (0, ao_js_1.parseAoEpochData)(data);
62
+ return undefined;
52
63
  };
53
64
  exports.getEpochDataFromGql = getEpochDataFromGql;
65
+ /**
66
+ * Get the epoch with distribution data for the current epoch
67
+ * @param arweave - The Arweave instance
68
+ * @param epochIndex - The index of the epoch
69
+ * @param processId - The process ID (optional, defaults to ARIO_TESTNET_PROCESS_ID)
70
+ * @returns string - The stringified GQL query
71
+ */
54
72
  const epochDistributionNoticeGqlQuery = ({ epochIndex, processId = constants_js_1.ARIO_TESTNET_PROCESS_ID, }) => {
55
73
  // write the query
56
74
  const gqlQuery = JSON.stringify({
@@ -17,4 +17,4 @@
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.version = void 0;
19
19
  // AUTOMATICALLY GENERATED FILE - DO NOT TOUCH
20
- exports.version = '3.3.0-alpha.11';
20
+ exports.version = '3.3.0-alpha.13';
@@ -669,6 +669,7 @@ makeCommand({
669
669
  action: async (options) => {
670
670
  const process = new AOProcess({
671
671
  processId: requiredProcessIdFromOptions(options),
672
+ logger: getLoggerFromOptions(options),
672
673
  });
673
674
  return process.send({
674
675
  tags: writeActionTagsFromOptions(options).tags ?? [],
@@ -176,7 +176,7 @@ export function paginationParamsFromOptions(options) {
176
176
  return {
177
177
  cursor,
178
178
  limit: numberLimit,
179
- sortBy,
179
+ sortBy: sortBy,
180
180
  sortOrder,
181
181
  };
182
182
  }
@@ -15,6 +15,7 @@
15
15
  */
16
16
  import { connect } from '@permaweb/aoconnect';
17
17
  import { getRandomText } from '../../utils/base64.js';
18
+ import { errorMessageFromOutput } from '../../utils/index.js';
18
19
  import { safeDecode } from '../../utils/json.js';
19
20
  import { version } from '../../version.js';
20
21
  import { WriteInteractionError } from '../error.js';
@@ -177,18 +178,3 @@ export class AOProcess {
177
178
  throw lastError;
178
179
  }
179
180
  }
180
- function errorMessageFromOutput(output) {
181
- const errorData = output.Error;
182
- // Attempt to extract error details from Messages.Tags if Error is undefined
183
- const error = errorData ??
184
- output.Messages?.[0]?.Tags?.find((tag) => tag.name === 'Error')?.value;
185
- if (error !== undefined) {
186
- // Consolidated regex to match and extract line number and AO error message or Error Tags
187
- const match = error.match(/\[string "aos"]:(\d+):\s*(.+)/);
188
- if (match) {
189
- const [, lineNumber, errorMessage] = match;
190
- return `${errorMessage.trim()} (line ${lineNumber.trim()})`.trim();
191
- }
192
- }
193
- return undefined;
194
- }
@@ -210,3 +210,28 @@ export function parseAoEpochData(value) {
210
210
  });
211
211
  return epochDataSchema.parse(value);
212
212
  }
213
+ export function errorMessageFromOutput(output) {
214
+ const errorData = output.Error;
215
+ // Attempt to extract error details from Messages.Tags if Error is undefined
216
+ const error = errorData ??
217
+ output.Messages?.[0]?.Tags?.find((tag) => tag.name === 'Error')?.value;
218
+ if (error !== undefined) {
219
+ // Consolidated regex to match and extract line number and AO error message or Error Tags
220
+ const match = error.match(/\[string "aos"]:(\d+):\s*(.+)/);
221
+ if (match) {
222
+ const [, lineNumber, errorMessage] = match;
223
+ const cleanError = removeUnicodeFromError(errorMessage);
224
+ return `${cleanError.trim()} (line ${lineNumber.trim()})`.trim();
225
+ }
226
+ // With no match, just remove unicode
227
+ return removeUnicodeFromError(error);
228
+ }
229
+ return undefined;
230
+ }
231
+ export function removeUnicodeFromError(error) {
232
+ //The regular expression /[\u001b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g is designed to match ANSI escape codes used for terminal formatting. These are sequences that begin with \u001b (ESC character) and are often followed by [ and control codes.
233
+ const ESC = String.fromCharCode(27); // Represents '\u001b' or '\x1b'
234
+ return error
235
+ .replace(new RegExp(`${ESC}[\\[\\]()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]`, 'g'), '')
236
+ .trim();
237
+ }
@@ -28,21 +28,39 @@ export const paginationParamsToTags = (params) => {
28
28
  * @param arweave - The Arweave instance
29
29
  * @returns The epoch with distribution data
30
30
  */
31
- export const getEpochDataFromGql = async ({ arweave, epochIndex, processId = ARIO_TESTNET_PROCESS_ID, }) => {
31
+ export const getEpochDataFromGql = async ({ arweave, epochIndex, processId = ARIO_TESTNET_PROCESS_ID, retries = 3, }) => {
32
32
  // fetch from gql
33
33
  const query = epochDistributionNoticeGqlQuery({ epochIndex, processId });
34
- const response = await arweave.api.post('graphql', query);
35
- // parse the nodes to get the id
36
- if (response.data.data.transactions?.edges?.length === 0) {
37
- return undefined;
34
+ // add three retries with exponential backoff
35
+ for (let i = 0; i < retries; i++) {
36
+ try {
37
+ const response = await arweave.api.post('graphql', query);
38
+ // parse the nodes to get the id
39
+ if (response.data?.data?.transactions?.edges?.length === 0) {
40
+ return undefined;
41
+ }
42
+ const id = response.data.data.transactions.edges[0].node.id;
43
+ // fetch the transaction from arweave
44
+ const transaction = await arweave.api.get(id);
45
+ // assert it is the correct type
46
+ return parseAoEpochData(transaction.data);
47
+ }
48
+ catch (error) {
49
+ if (i === retries - 1)
50
+ throw error; // Re-throw on final attempt
51
+ // exponential backoff
52
+ await new Promise((resolve) => setTimeout(resolve, Math.pow(2, i) * 1000));
53
+ }
38
54
  }
39
- const id = response.data.data.transactions.edges[0].node.id;
40
- // fetch the transaction from arweave
41
- const transaction = await arweave.api.get(id);
42
- const data = transaction.data;
43
- // assert it is the correct type
44
- return parseAoEpochData(data);
55
+ return undefined;
45
56
  };
57
+ /**
58
+ * Get the epoch with distribution data for the current epoch
59
+ * @param arweave - The Arweave instance
60
+ * @param epochIndex - The index of the epoch
61
+ * @param processId - The process ID (optional, defaults to ARIO_TESTNET_PROCESS_ID)
62
+ * @returns string - The stringified GQL query
63
+ */
46
64
  export const epochDistributionNoticeGqlQuery = ({ epochIndex, processId = ARIO_TESTNET_PROCESS_ID, }) => {
47
65
  // write the query
48
66
  const gqlQuery = JSON.stringify({
@@ -14,4 +14,4 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  // AUTOMATICALLY GENERATED FILE - DO NOT TOUCH
17
- export const version = '3.3.0-alpha.11';
17
+ export const version = '3.3.0-alpha.13';
@@ -13,7 +13,7 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { AoGetCostDetailsParams } from '../../types/io.js';
16
+ import { AoDelegation, AoGatewayDelegateWithAddress, AoGatewayVault, AoGetCostDetailsParams } from '../../types/io.js';
17
17
  import { AddressAndNameCLIOptions, AddressAndVaultIdCLIOptions, AddressCLIOptions, CLIOptionsFromAoParams, EpochCLIOptions, GetTokenCostCLIOptions, GlobalCLIOptions, NameCLIOptions, PaginationAddressCLIOptions, PaginationCLIOptions } from '../types.js';
18
18
  export declare function getGateway(o: AddressCLIOptions): Promise<import("../../types/io.js").AoGateway | {
19
19
  message: string;
@@ -24,10 +24,10 @@ export declare function listGateways(o: PaginationCLIOptions): Promise<import(".
24
24
  export declare function listAllDelegatesCLICommand(o: PaginationCLIOptions): Promise<import("../../types/io.js").PaginationResult<import("../../types/io.js").AoAllDelegates> | {
25
25
  message: string;
26
26
  }>;
27
- export declare function getGatewayDelegates(o: AddressCLIOptions): Promise<import("../../types/io.js").PaginationResult<import("../../types/io.js").AoGatewayDelegateWithAddress> | {
27
+ export declare function getGatewayDelegates(o: AddressCLIOptions): Promise<import("../../types/io.js").PaginationResult<AoGatewayDelegateWithAddress> | {
28
28
  message: string;
29
29
  }>;
30
- export declare function getDelegations(o: PaginationAddressCLIOptions): Promise<import("../../types/io.js").PaginationResult<import("../../types/io.js").AoDelegation> | {
30
+ export declare function getDelegations(o: PaginationAddressCLIOptions): Promise<import("../../types/io.js").PaginationResult<AoDelegation> | {
31
31
  message: string;
32
32
  }>;
33
33
  export declare function getAllowedDelegates(o: PaginationAddressCLIOptions): Promise<import("../../types/io.js").PaginationResult<string> | {
@@ -76,7 +76,7 @@ export declare function getCostDetails(o: GlobalCLIOptions & CLIOptionsFromAoPar
76
76
  export declare function getPrimaryName(o: AddressAndNameCLIOptions): Promise<import("../../types/common.js").AoPrimaryName | {
77
77
  message: string;
78
78
  }>;
79
- export declare function getGatewayVaults(o: PaginationAddressCLIOptions): Promise<import("../../types/io.js").PaginationResult<import("../../types/io.js").AoGatewayVault> | {
79
+ export declare function getGatewayVaults(o: PaginationAddressCLIOptions): Promise<import("../../types/io.js").PaginationResult<AoGatewayVault> | {
80
80
  message: string;
81
81
  }>;
82
82
  export declare function getVault(o: AddressAndVaultIdCLIOptions): Promise<import("../../types/io.js").AoVaultData | {
@@ -35,9 +35,7 @@ export declare function formatMARIOToARIOWithCommas(value: mARIOToken): string;
35
35
  /** helper to get address from --address option first, then check wallet options */
36
36
  export declare function addressFromOptions<O extends AddressCLIOptions>(options: O): string | undefined;
37
37
  export declare function requiredAddressFromOptions<O extends AddressCLIOptions>(options: O): string;
38
- export declare function paginationParamsFromOptions<O extends PaginationCLIOptions>(options: O): PaginationParams & {
39
- sortBy: any;
40
- };
38
+ export declare function paginationParamsFromOptions<O extends PaginationCLIOptions, R>(options: O): PaginationParams<R>;
41
39
  export declare function epochInputFromOptions(options: EpochCLIOptions): EpochInput;
42
40
  export declare function requiredInitiatorFromOptions(options: InitiatorCLIOptions): string;
43
41
  export declare function writeActionTagsFromOptions<O extends WriteActionCLIOptions>(options: O): WriteOptions;
@@ -16,10 +16,14 @@
16
16
  import { AOProcess } from '../common/index.js';
17
17
  import { AoMessageResult, AoPrimaryName, AoPrimaryNameRequest, AoRedelegationFeeInfo, AtLeastOne, BlockHeight, ProcessId, Timestamp, TransactionId, WalletAddress, WriteOptions } from './index.js';
18
18
  import { mARIOToken } from './token.js';
19
+ type NestedKeys<T> = T extends object ? T extends readonly unknown[] ? never : {
20
+ [K in keyof T & string]: T[K] extends object ? `${K}.${NestedKeys<T[K]>}` : K;
21
+ }[keyof T & string] : never;
22
+ export type SortBy<T> = T extends string ? string : keyof T extends never ? string : NestedKeys<T>;
19
23
  export type PaginationParams<T = Record<string, never>> = {
20
24
  cursor?: string;
21
25
  limit?: number;
22
- sortBy?: keyof T extends never ? string : keyof T;
26
+ sortBy?: SortBy<T>;
23
27
  sortOrder?: 'asc' | 'desc';
24
28
  };
25
29
  export type PaginationResult<T> = {
@@ -27,7 +31,7 @@ export type PaginationResult<T> = {
27
31
  nextCursor?: string;
28
32
  limit: number;
29
33
  totalItems: number;
30
- sortBy?: T extends string ? string : keyof T;
34
+ sortBy?: SortBy<T>;
31
35
  sortOrder: 'asc' | 'desc';
32
36
  hasMore: boolean;
33
37
  };
@@ -250,7 +254,7 @@ export type AoAddressParams = {
250
254
  address: WalletAddress;
251
255
  };
252
256
  export type AoBalanceParams = AoAddressParams;
253
- export type AoPaginatedAddressParams = PaginationParams & AoAddressParams;
257
+ export type AoPaginatedAddressParams = PaginationParams<string> & AoAddressParams;
254
258
  export type AoDelegateStakeParams = {
255
259
  target: WalletAddress;
256
260
  stakeQty: number | mARIOToken;
@@ -473,3 +477,4 @@ export interface AoARIOWrite extends AoARIORead {
473
477
  export declare function isProcessConfiguration(config: object): config is Required<ProcessConfiguration> & Record<string, never>;
474
478
  export declare function isProcessIdConfiguration(config: object): config is Required<ProcessIdConfig> & Record<string, never>;
475
479
  export declare function isLeasedArNSRecord(record: AoArNSNameData): record is AoArNSLeaseData;
480
+ export {};
@@ -52,3 +52,13 @@ export declare function initANTStateForAddress({ owner, targetId, ttlSeconds, ke
52
52
  * Uses zod schema to parse the epoch data
53
53
  */
54
54
  export declare function parseAoEpochData(value: unknown): AoEpochData;
55
+ export declare function errorMessageFromOutput(output: {
56
+ Error?: string;
57
+ Messages?: {
58
+ Tags?: {
59
+ name: string;
60
+ value: string;
61
+ }[];
62
+ }[];
63
+ }): string | undefined;
64
+ export declare function removeUnicodeFromError(error: string): string;
@@ -39,11 +39,19 @@ export declare const paginationParamsToTags: <T>(params?: PaginationParams<T>) =
39
39
  * @param arweave - The Arweave instance
40
40
  * @returns The epoch with distribution data
41
41
  */
42
- export declare const getEpochDataFromGql: ({ arweave, epochIndex, processId, }: {
42
+ export declare const getEpochDataFromGql: ({ arweave, epochIndex, processId, retries, }: {
43
43
  arweave: Arweave;
44
44
  epochIndex: number;
45
45
  processId?: string;
46
+ retries?: number;
46
47
  }) => Promise<AoEpochData | undefined>;
48
+ /**
49
+ * Get the epoch with distribution data for the current epoch
50
+ * @param arweave - The Arweave instance
51
+ * @param epochIndex - The index of the epoch
52
+ * @param processId - The process ID (optional, defaults to ARIO_TESTNET_PROCESS_ID)
53
+ * @returns string - The stringified GQL query
54
+ */
47
55
  export declare const epochDistributionNoticeGqlQuery: ({ epochIndex, processId, }: {
48
56
  epochIndex: number;
49
57
  processId?: string;
@@ -13,4 +13,4 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- export declare const version = "3.3.0-alpha.10";
16
+ export declare const version = "3.3.0-alpha.12";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ar.io/sdk",
3
- "version": "3.3.0-alpha.11",
3
+ "version": "3.3.0-alpha.13",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/ar-io/ar-io-sdk.git"