@ar.io/sdk 3.11.1-alpha.1 → 3.12.0-alpha.2

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 (43) hide show
  1. package/bundles/web.bundle.min.js +2 -2
  2. package/lib/cjs/cli/commands/arnsPurchaseCommands.js +5 -0
  3. package/lib/cjs/cli/options.js +6 -0
  4. package/lib/cjs/cli/utils.js +11 -2
  5. package/lib/cjs/common/io.js +1 -0
  6. package/lib/cjs/common/turbo.js +2 -1
  7. package/lib/cjs/utils/json.js +0 -1
  8. package/lib/cjs/utils/url.js +10 -1
  9. package/lib/cjs/version.js +1 -1
  10. package/lib/esm/cli/commands/arnsPurchaseCommands.js +6 -1
  11. package/lib/esm/cli/options.js +6 -0
  12. package/lib/esm/cli/utils.js +10 -2
  13. package/lib/esm/common/io.js +1 -0
  14. package/lib/esm/common/turbo.js +2 -1
  15. package/lib/esm/utils/json.js +0 -1
  16. package/lib/esm/utils/url.js +10 -1
  17. package/lib/esm/version.js +1 -1
  18. package/lib/types/cli/options.d.ts +5 -0
  19. package/lib/types/cli/utils.d.ts +1 -0
  20. package/lib/types/common/turbo.d.ts +6 -6
  21. package/lib/types/types/io.d.ts +1 -0
  22. package/lib/types/utils/json.d.ts +1 -1
  23. package/lib/types/utils/url.d.ts +1 -1
  24. package/lib/types/version.d.ts +1 -1
  25. package/package.json +3 -2
  26. package/lib/cjs/types/ant.test.js +0 -150
  27. package/lib/cjs/types/token.test.js +0 -83
  28. package/lib/cjs/utils/ant.test.js +0 -111
  29. package/lib/cjs/utils/b64.test.js +0 -72
  30. package/lib/cjs/utils/url.test.js +0 -24
  31. package/lib/cjs/utils/utils.test.js +0 -194
  32. package/lib/esm/types/ant.test.js +0 -148
  33. package/lib/esm/types/token.test.js +0 -81
  34. package/lib/esm/utils/ant.test.js +0 -109
  35. package/lib/esm/utils/b64.test.js +0 -70
  36. package/lib/esm/utils/url.test.js +0 -19
  37. package/lib/esm/utils/utils.test.js +0 -192
  38. package/lib/types/types/ant.test.d.ts +0 -1
  39. package/lib/types/types/token.test.d.ts +0 -1
  40. package/lib/types/utils/ant.test.d.ts +0 -1
  41. package/lib/types/utils/b64.test.d.ts +0 -1
  42. package/lib/types/utils/url.test.d.ts +0 -1
  43. package/lib/types/utils/utils.test.d.ts +0 -1
@@ -1,109 +0,0 @@
1
- import { strict as assert } from 'node:assert';
2
- import { describe, it } from 'node:test';
3
- import { sortANTRecords } from './ant.js';
4
- describe('sortANTRecordsByPriority', () => {
5
- it('should sort records by priority and then lexicographically', () => {
6
- const records = {
7
- undername01: { priority: 1, transactionId: 'test', ttlSeconds: 1 }, // same priority, lexicographic sorting applied to the name
8
- undername1: { priority: 1, transactionId: 'test', ttlSeconds: 1 },
9
- undername11: { priority: 1, transactionId: 'test', ttlSeconds: 1 }, // same priority, lexicographic sorting applied to the name
10
- undername2: { priority: 2, transactionId: 'test', ttlSeconds: 1 },
11
- undername3: { priority: 3, transactionId: 'test', ttlSeconds: 1 }, // colliding priorities default to lexicographic sorting
12
- undername4: { priority: 3, transactionId: 'test', ttlSeconds: 1 },
13
- undername5: { priority: 100, transactionId: 'test', ttlSeconds: 1 }, // priority does not represent the index or position of the record, just the order of resolution relative to other records
14
- noPriority: { transactionId: 'test', ttlSeconds: 1 },
15
- noPriority01: { transactionId: 'test', ttlSeconds: 1 },
16
- noPriority1: { transactionId: 'test', ttlSeconds: 1 },
17
- noPriority11: { transactionId: 'test', ttlSeconds: 1 },
18
- '@': { transactionId: 'test', ttlSeconds: 1 }, // always first, even if no priority
19
- };
20
- const sorted = sortANTRecords(records);
21
- assert.deepStrictEqual(sorted, {
22
- '@': { transactionId: 'test', ttlSeconds: 1, index: 0 }, // always first, even if no priority
23
- undername01: {
24
- priority: 1,
25
- transactionId: 'test',
26
- ttlSeconds: 1,
27
- index: 1,
28
- },
29
- undername1: {
30
- priority: 1,
31
- transactionId: 'test',
32
- ttlSeconds: 1,
33
- index: 2,
34
- },
35
- undername11: {
36
- priority: 1,
37
- transactionId: 'test',
38
- ttlSeconds: 1,
39
- index: 3,
40
- },
41
- undername2: {
42
- priority: 2,
43
- transactionId: 'test',
44
- ttlSeconds: 1,
45
- index: 4,
46
- },
47
- undername3: {
48
- priority: 3,
49
- transactionId: 'test',
50
- ttlSeconds: 1,
51
- index: 5,
52
- },
53
- undername4: {
54
- priority: 3,
55
- transactionId: 'test',
56
- ttlSeconds: 1,
57
- index: 6,
58
- },
59
- undername5: {
60
- priority: 100,
61
- transactionId: 'test',
62
- ttlSeconds: 1,
63
- index: 7,
64
- },
65
- noPriority: { transactionId: 'test', ttlSeconds: 1, index: 8 },
66
- noPriority01: { transactionId: 'test', ttlSeconds: 1, index: 9 },
67
- noPriority1: { transactionId: 'test', ttlSeconds: 1, index: 10 },
68
- noPriority11: { transactionId: 'test', ttlSeconds: 1, index: 11 },
69
- });
70
- });
71
- it('should always return @ as the first, regardless of priority', () => {
72
- const scenarios = [
73
- {
74
- records: {
75
- '@': { priority: 5, transactionId: 'test', ttlSeconds: 1 }, // priorities set on '@' are ignored, they are always first
76
- undername1: { priority: 2, transactionId: 'test', ttlSeconds: 1 },
77
- },
78
- expected: {
79
- '@': { priority: 5, transactionId: 'test', ttlSeconds: 1, index: 0 },
80
- undername1: {
81
- priority: 2,
82
- transactionId: 'test',
83
- ttlSeconds: 1,
84
- index: 1,
85
- },
86
- },
87
- },
88
- {
89
- records: {
90
- '@': { transactionId: 'test', ttlSeconds: 1 }, // priority 0 is missing, but '@' is always first
91
- undername1: { priority: 2, transactionId: 'test', ttlSeconds: 1 },
92
- },
93
- expected: {
94
- '@': { transactionId: 'test', ttlSeconds: 1, index: 0 },
95
- undername1: {
96
- priority: 2,
97
- transactionId: 'test',
98
- ttlSeconds: 1,
99
- index: 1,
100
- },
101
- },
102
- },
103
- ];
104
- for (const scenario of scenarios) {
105
- const sorted = sortANTRecords(scenario.records);
106
- assert.deepStrictEqual(sorted, scenario.expected);
107
- }
108
- });
109
- });
@@ -1,70 +0,0 @@
1
- import { strict as assert } from 'node:assert';
2
- import { describe, it } from 'node:test';
3
- import { fromB64Url, getRandomText, toB64Url } from './base64.js';
4
- describe('b64utils', () => {
5
- it('should convert various strings to base64url and back', () => {
6
- const testStrings = [
7
- 'Hello, World!',
8
- 'Test123!@#',
9
- 'Base64URLEncoding',
10
- 'Special_Chars+/',
11
- '',
12
- 'A',
13
- '1234567890',
14
- ];
15
- for (const str of testStrings) {
16
- const encoded = toB64Url(Buffer.from(str));
17
- const decoded = fromB64Url(encoded);
18
- assert.deepStrictEqual(decoded, Buffer.from(str), `Failed for string: ${str}`);
19
- }
20
- });
21
- it('should convert various buffers to base64url and back', () => {
22
- const testBuffers = [
23
- Buffer.from('Hello, World!'),
24
- Buffer.from([0, 1, 2, 3, 4, 5]),
25
- Buffer.from('Test123!@#'),
26
- Buffer.from('Base64URLEncoding'),
27
- Buffer.from('Special_Chars+/'),
28
- Buffer.alloc(0),
29
- Buffer.from('A'),
30
- Buffer.from('1234567890'),
31
- ];
32
- for (const buf of testBuffers) {
33
- const encoded = toB64Url(buf);
34
- const decoded = fromB64Url(encoded);
35
- assert.deepStrictEqual(decoded, buf, `Failed for buffer: ${buf.toString()}`);
36
- }
37
- });
38
- it('should handle edge cases for base64url conversion', () => {
39
- const edgeCases = [
40
- '',
41
- 'A',
42
- 'AA',
43
- 'AAA',
44
- '====',
45
- '===',
46
- '==',
47
- '=',
48
- 'A===',
49
- 'AA==',
50
- 'AAA=',
51
- ];
52
- for (const testCase of edgeCases) {
53
- const encoded = toB64Url(Buffer.from(testCase));
54
- const decoded = Buffer.from(fromB64Url(encoded)).toString();
55
- assert.strictEqual(decoded, testCase, `Failed for edge case: ${testCase}`);
56
- }
57
- });
58
- it('should generate random text', () => {
59
- const randomText = getRandomText();
60
- const randomText2 = getRandomText();
61
- assert.strictEqual(randomText.length, 32);
62
- assert.strictEqual(randomText2.length, 32);
63
- assert.notStrictEqual(randomText, randomText2);
64
- const smallRandomText = getRandomText(16);
65
- const smallRandomText2 = getRandomText(16);
66
- assert.strictEqual(smallRandomText.length, 16);
67
- assert.strictEqual(smallRandomText2.length, 16);
68
- assert.notStrictEqual(smallRandomText, smallRandomText2);
69
- });
70
- });
@@ -1,19 +0,0 @@
1
- import assert from 'node:assert';
2
- import { test } from 'node:test';
3
- import { urlWithSearchParams } from './url.js';
4
- test('urlWithSearchParams prunes undefined values but keeps other falsey values', () => {
5
- const result = urlWithSearchParams({
6
- baseUrl: 'https://example.com',
7
- params: {
8
- number: 1,
9
- string: 'string',
10
- boolean: true,
11
- empty: '',
12
- zero: 0,
13
- false: false,
14
- null: null,
15
- undef: undefined,
16
- },
17
- });
18
- assert.strictEqual(result, 'https://example.com/?number=1&string=string&boolean=true&empty=&zero=0&false=false');
19
- });
@@ -1,192 +0,0 @@
1
- import { strict as assert } from 'node:assert';
2
- import { describe, it } from 'node:test';
3
- import { errorMessageFromOutput } from './ao.js';
4
- import { pruneTags, sortAndPaginateEpochDataIntoEligibleDistributions, } from './arweave.js';
5
- describe('pruneTags', () => {
6
- it('should remove tags with undefined values', () => {
7
- const tags = [
8
- { name: 'Tag1', value: 'value1' },
9
- { name: 'Tag2', value: undefined },
10
- { name: 'Tag3', value: 'value3' },
11
- { name: 'Tag4', value: undefined },
12
- ];
13
- const prunedTags = pruneTags(tags);
14
- assert.deepEqual(prunedTags, [
15
- { name: 'Tag1', value: 'value1' },
16
- { name: 'Tag3', value: 'value3' },
17
- ]);
18
- });
19
- it('should return empty array when all tags have undefined values', () => {
20
- const tags = [
21
- { name: 'Tag1', value: undefined },
22
- { name: 'Tag2', value: undefined },
23
- ];
24
- const prunedTags = pruneTags(tags);
25
- assert.deepEqual(prunedTags, []);
26
- });
27
- it('should return same array when no tags have undefined values', () => {
28
- const tags = [
29
- { name: 'Tag1', value: 'value1' },
30
- { name: 'Tag2', value: 'value2' },
31
- ];
32
- const prunedTags = pruneTags(tags);
33
- assert.deepEqual(prunedTags, tags);
34
- });
35
- it('should return empty array with no tags', () => {
36
- const tags = [];
37
- const prunedTags = pruneTags(tags);
38
- assert.deepEqual(prunedTags, []);
39
- });
40
- });
41
- describe('errorMessageFromOutput', () => {
42
- it('should return error message from Error field', () => {
43
- const output = {
44
- Error: 'Error message',
45
- };
46
- const errorMessage = errorMessageFromOutput(output);
47
- assert.equal(errorMessage, 'Error message');
48
- });
49
- it('should return error message from Error tag', () => {
50
- const output = {
51
- Messages: [
52
- {
53
- Tags: [{ name: 'Error', value: 'Error message' }],
54
- },
55
- ],
56
- };
57
- const errorMessage = errorMessageFromOutput(output);
58
- assert.equal(errorMessage, 'Error message');
59
- });
60
- it('should return error message from Error tag if Error field is undefined', () => {
61
- const output = {
62
- Messages: [
63
- {
64
- Tags: [{ name: 'Error', value: 'Error message' }],
65
- },
66
- ],
67
- };
68
- const errorMessage = errorMessageFromOutput(output);
69
- assert.equal(errorMessage, 'Error message');
70
- });
71
- it('should return undefined if no error message is present', () => {
72
- const output = {
73
- Messages: [
74
- {
75
- Tags: [{ name: 'Tag1', value: 'value1' }],
76
- },
77
- ],
78
- };
79
- const errorMessage = errorMessageFromOutput(output);
80
- assert.equal(errorMessage, undefined);
81
- });
82
- it('should return error message with line number', () => {
83
- const output = {
84
- Error: '[string "aos"]:123: Error message',
85
- };
86
- const errorMessage = errorMessageFromOutput(output);
87
- assert.equal(errorMessage, 'Error message (line 123)');
88
- });
89
- it('should return error message with line number and remove unicode', () => {
90
- const output = {
91
- Error: '[string "aos"]:123: Error message\u001b[0m',
92
- };
93
- const errorMessage = errorMessageFromOutput(output);
94
- assert.equal(errorMessage, 'Error message (line 123)');
95
- });
96
- const knownErrorMessages = '\u001b[31mError\u001b[90m handling message with Action = Register\u001b[0m\n\u001b[32m[string ".handlers"]:723: [string "aos"]:128: Already registered\u001b[0m\n\n\u001b[90mstack traceback:\n\t[string ".process"]:871: in function \'.process.handle\'\u001b[0m\n\n\u001b[31merror:\n\u001b[0m[string ".handlers"]:723: [string "aos"]:128: Already registered';
97
- it('should display a clean error for a known error message', () => {
98
- const output = {
99
- Error: knownErrorMessages,
100
- };
101
- const errorMessage = errorMessageFromOutput(output);
102
- assert.equal(errorMessage, 'Already registered (line 128)');
103
- });
104
- });
105
- describe('sortAndPaginateEpochDataIntoEligibleDistributions', () => {
106
- const mockEpochData = {
107
- distributions: {
108
- distributedTimestamp: 1234567890,
109
- rewards: {
110
- eligible: {
111
- gateway1: {
112
- operatorReward: 50,
113
- delegateRewards: {
114
- delegate1: 20,
115
- delegate2: 30,
116
- },
117
- },
118
- gateway2: {
119
- operatorReward: 70,
120
- delegateRewards: {
121
- delegate3: 40,
122
- },
123
- },
124
- },
125
- },
126
- },
127
- };
128
- it('sorts rewards in descending order by eligibleReward', () => {
129
- const result = sortAndPaginateEpochDataIntoEligibleDistributions(mockEpochData);
130
- assert.deepEqual(result.items, [
131
- {
132
- type: 'operatorReward',
133
- recipient: 'gateway2',
134
- eligibleReward: 70,
135
- cursorId: 'gateway2_gateway2',
136
- gatewayAddress: 'gateway2',
137
- },
138
- {
139
- type: 'operatorReward',
140
- recipient: 'gateway1',
141
- eligibleReward: 50,
142
- cursorId: 'gateway1_gateway1',
143
- gatewayAddress: 'gateway1',
144
- },
145
- {
146
- type: 'delegateReward',
147
- recipient: 'delegate3',
148
- eligibleReward: 40,
149
- cursorId: 'gateway2_delegate3',
150
- gatewayAddress: 'gateway2',
151
- },
152
- {
153
- type: 'delegateReward',
154
- recipient: 'delegate2',
155
- eligibleReward: 30,
156
- cursorId: 'gateway1_delegate2',
157
- gatewayAddress: 'gateway1',
158
- },
159
- {
160
- type: 'delegateReward',
161
- recipient: 'delegate1',
162
- eligibleReward: 20,
163
- cursorId: 'gateway1_delegate1',
164
- gatewayAddress: 'gateway1',
165
- },
166
- ]);
167
- });
168
- it('supports sorting in ascending order', () => {
169
- const result = sortAndPaginateEpochDataIntoEligibleDistributions(mockEpochData, {
170
- sortOrder: 'asc',
171
- });
172
- assert.equal(result.items[0].eligibleReward, 20);
173
- assert.equal(result.items[result.items.length - 1].eligibleReward, 70);
174
- });
175
- it('paginates results correctly', () => {
176
- const result = sortAndPaginateEpochDataIntoEligibleDistributions(mockEpochData, {
177
- limit: 2,
178
- });
179
- assert.equal(result.items.length, 2);
180
- assert.equal(result.hasMore, true);
181
- assert.equal(result.nextCursor, 'gateway2_delegate3');
182
- });
183
- it('resumes pagination from cursor', () => {
184
- const firstPage = sortAndPaginateEpochDataIntoEligibleDistributions(mockEpochData, { limit: 2 });
185
- const secondPage = sortAndPaginateEpochDataIntoEligibleDistributions(mockEpochData, {
186
- limit: 2,
187
- cursor: firstPage.nextCursor,
188
- });
189
- assert.equal(secondPage.items.length, 2);
190
- assert.equal(secondPage.items[0].cursorId, 'gateway1_delegate2');
191
- });
192
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};