@ar.io/sdk 2.5.0-alpha.7 → 2.5.0-alpha.9

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.
@@ -455,5 +455,31 @@ class AoANTWriteable extends AoANTReadable {
455
455
  signer: this.signer,
456
456
  });
457
457
  }
458
+ /**
459
+ * Approves a primary name request for a given name or address.
460
+ */
461
+ async approvePrimaryNameRequest({ name, address, ioProcessId, }, options) {
462
+ return this.process.send({
463
+ tags: [
464
+ ...(options?.tags ?? []),
465
+ { name: 'Action', value: 'Approve-Primary-Name' },
466
+ { name: 'Name', value: name },
467
+ { name: 'Recipient', value: address },
468
+ { name: 'IO-Process-Id', value: ioProcessId },
469
+ ],
470
+ signer: this.signer,
471
+ });
472
+ }
473
+ async removePrimaryNames({ names, ioProcessId }, options) {
474
+ return this.process.send({
475
+ tags: [
476
+ ...(options?.tags ?? []),
477
+ { name: 'Action', value: 'Remove-Primary-Names' },
478
+ { name: 'Names', value: names.join(',') },
479
+ { name: 'IO-Process-Id', value: ioProcessId },
480
+ ],
481
+ signer: this.signer,
482
+ });
483
+ }
458
484
  }
459
485
  exports.AoANTWriteable = AoANTWriteable;
@@ -50,11 +50,12 @@ class AOProcess {
50
50
  this.logger.debug(`Process ${this.processId} does not support provided action.`, result, tags);
51
51
  throw new Error(`Process ${this.processId} does not support provided action.`);
52
52
  }
53
- const tagsOutput = result.Messages[0].Tags;
54
- const messageData = result.Messages[0].Data;
55
- const error = tagsOutput.find((tag) => tag.name === 'Error');
53
+ const tagsOutput = result.Messages?.[0]?.Tags;
54
+ const messageData = result.Messages?.[0]?.Data;
55
+ const errorData = result.Error;
56
+ const error = errorData || tagsOutput?.find((tag) => tag.name === 'Error')?.value;
56
57
  if (error) {
57
- throw new Error(`${error.value}${messageData ? `: ${messageData}` : ''}`);
58
+ throw new Error(`${error}${messageData ? `: ${messageData}` : ''}`);
58
59
  }
59
60
  // return empty object if no data is returned
60
61
  if (messageData === undefined) {
@@ -109,17 +110,17 @@ class AOProcess {
109
110
  messageId,
110
111
  processId: this.processId,
111
112
  });
113
+ const errorData = output.Error;
114
+ const error = errorData ||
115
+ output.Messages?.[0]?.Tags?.find((tag) => tag.name === 'Error')
116
+ ?.value;
117
+ if (error) {
118
+ throw new error_js_1.WriteInteractionError(error);
119
+ }
112
120
  // check if there are any Messages in the output
113
121
  if (output.Messages?.length === 0 || output.Messages === undefined) {
114
122
  return { id: messageId };
115
123
  }
116
- const tagsOutput = output.Messages[0].Tags;
117
- const error = tagsOutput.find((tag) => tag.name === 'Error');
118
- // if there's an Error tag, throw an error related to it
119
- if (error) {
120
- const result = output.Messages[0].Data;
121
- throw new error_js_1.WriteInteractionError(`${error.Value}: ${result}`);
122
- }
123
124
  if (output.Messages.length === 0) {
124
125
  throw new Error(`Process ${this.processId} does not support provided action.`);
125
126
  }
@@ -192,14 +192,7 @@ class IOReadable {
192
192
  { name: 'Action', value: 'Epoch' },
193
193
  {
194
194
  name: 'Timestamp',
195
- value: (await this.arweave.blocks
196
- .getCurrent()
197
- .then((block) => {
198
- return { timestamp: block.timestamp * 1000 };
199
- })
200
- .catch(() => {
201
- return { timestamp: Date.now() }; // fallback to current time
202
- })).timestamp.toString(),
195
+ value: (await (0, arweave_js_1.getCurrentBlockUnixTimestampMs)(this.arweave)).toString(),
203
196
  },
204
197
  ],
205
198
  });
@@ -356,7 +349,8 @@ class IOReadable {
356
349
  { name: 'Name', value: name },
357
350
  {
358
351
  name: 'Timestamp',
359
- value: timestamp?.toString() ?? Date.now().toString(),
352
+ value: timestamp?.toString() ??
353
+ (await (0, arweave_js_1.getCurrentBlockUnixTimestampMs)(this.arweave)).toString(),
360
354
  },
361
355
  { name: 'Purchase-Type', value: type ?? 'lease' },
362
356
  {
@@ -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 = '2.5.0-alpha.7';
20
+ exports.version = '2.5.0-alpha.9';
@@ -450,4 +450,30 @@ export class AoANTWriteable extends AoANTReadable {
450
450
  signer: this.signer,
451
451
  });
452
452
  }
453
+ /**
454
+ * Approves a primary name request for a given name or address.
455
+ */
456
+ async approvePrimaryNameRequest({ name, address, ioProcessId, }, options) {
457
+ return this.process.send({
458
+ tags: [
459
+ ...(options?.tags ?? []),
460
+ { name: 'Action', value: 'Approve-Primary-Name' },
461
+ { name: 'Name', value: name },
462
+ { name: 'Recipient', value: address },
463
+ { name: 'IO-Process-Id', value: ioProcessId },
464
+ ],
465
+ signer: this.signer,
466
+ });
467
+ }
468
+ async removePrimaryNames({ names, ioProcessId }, options) {
469
+ return this.process.send({
470
+ tags: [
471
+ ...(options?.tags ?? []),
472
+ { name: 'Action', value: 'Remove-Primary-Names' },
473
+ { name: 'Names', value: names.join(',') },
474
+ { name: 'IO-Process-Id', value: ioProcessId },
475
+ ],
476
+ signer: this.signer,
477
+ });
478
+ }
453
479
  }
@@ -47,11 +47,12 @@ export class AOProcess {
47
47
  this.logger.debug(`Process ${this.processId} does not support provided action.`, result, tags);
48
48
  throw new Error(`Process ${this.processId} does not support provided action.`);
49
49
  }
50
- const tagsOutput = result.Messages[0].Tags;
51
- const messageData = result.Messages[0].Data;
52
- const error = tagsOutput.find((tag) => tag.name === 'Error');
50
+ const tagsOutput = result.Messages?.[0]?.Tags;
51
+ const messageData = result.Messages?.[0]?.Data;
52
+ const errorData = result.Error;
53
+ const error = errorData || tagsOutput?.find((tag) => tag.name === 'Error')?.value;
53
54
  if (error) {
54
- throw new Error(`${error.value}${messageData ? `: ${messageData}` : ''}`);
55
+ throw new Error(`${error}${messageData ? `: ${messageData}` : ''}`);
55
56
  }
56
57
  // return empty object if no data is returned
57
58
  if (messageData === undefined) {
@@ -106,17 +107,17 @@ export class AOProcess {
106
107
  messageId,
107
108
  processId: this.processId,
108
109
  });
110
+ const errorData = output.Error;
111
+ const error = errorData ||
112
+ output.Messages?.[0]?.Tags?.find((tag) => tag.name === 'Error')
113
+ ?.value;
114
+ if (error) {
115
+ throw new WriteInteractionError(error);
116
+ }
109
117
  // check if there are any Messages in the output
110
118
  if (output.Messages?.length === 0 || output.Messages === undefined) {
111
119
  return { id: messageId };
112
120
  }
113
- const tagsOutput = output.Messages[0].Tags;
114
- const error = tagsOutput.find((tag) => tag.name === 'Error');
115
- // if there's an Error tag, throw an error related to it
116
- if (error) {
117
- const result = output.Messages[0].Data;
118
- throw new WriteInteractionError(`${error.Value}: ${result}`);
119
- }
120
121
  if (output.Messages.length === 0) {
121
122
  throw new Error(`Process ${this.processId} does not support provided action.`);
122
123
  }
@@ -188,14 +188,7 @@ export class IOReadable {
188
188
  { name: 'Action', value: 'Epoch' },
189
189
  {
190
190
  name: 'Timestamp',
191
- value: (await this.arweave.blocks
192
- .getCurrent()
193
- .then((block) => {
194
- return { timestamp: block.timestamp * 1000 };
195
- })
196
- .catch(() => {
197
- return { timestamp: Date.now() }; // fallback to current time
198
- })).timestamp.toString(),
191
+ value: (await getCurrentBlockUnixTimestampMs(this.arweave)).toString(),
199
192
  },
200
193
  ],
201
194
  });
@@ -352,7 +345,8 @@ export class IOReadable {
352
345
  { name: 'Name', value: name },
353
346
  {
354
347
  name: 'Timestamp',
355
- value: timestamp?.toString() ?? Date.now().toString(),
348
+ value: timestamp?.toString() ??
349
+ (await getCurrentBlockUnixTimestampMs(this.arweave)).toString(),
356
350
  },
357
351
  { name: 'Purchase-Type', value: type ?? 'lease' },
358
352
  {
@@ -14,4 +14,4 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  // AUTOMATICALLY GENERATED FILE - DO NOT TOUCH
17
- export const version = '2.5.0-alpha.7';
17
+ export const version = '2.5.0-alpha.9';
@@ -255,4 +255,16 @@ export declare class AoANTWriteable extends AoANTReadable implements AoANTWrite
255
255
  ioProcessId: string;
256
256
  antProcessId: string;
257
257
  }, options?: WriteOptions): Promise<AoMessageResult>;
258
+ /**
259
+ * Approves a primary name request for a given name or address.
260
+ */
261
+ approvePrimaryNameRequest({ name, address, ioProcessId, }: {
262
+ name: string;
263
+ address: WalletAddress;
264
+ ioProcessId: string;
265
+ }, options?: WriteOptions): Promise<AoMessageResult>;
266
+ removePrimaryNames({ names, ioProcessId }: {
267
+ names: string[];
268
+ ioProcessId: string;
269
+ }, options?: WriteOptions): Promise<AoMessageResult>;
258
270
  }
@@ -252,4 +252,13 @@ export interface AoANTWrite extends AoANTRead {
252
252
  ioProcessId: string;
253
253
  antProcessId: string;
254
254
  }, options?: WriteOptions): Promise<AoMessageResult>;
255
+ approvePrimaryNameRequest({ name, address, ioProcessId, }: {
256
+ name: string;
257
+ address: WalletAddress;
258
+ ioProcessId: string;
259
+ }, options?: WriteOptions): Promise<AoMessageResult>;
260
+ removePrimaryNames({ names, ioProcessId }: {
261
+ names: string[];
262
+ ioProcessId: string;
263
+ }, options?: WriteOptions): Promise<AoMessageResult>;
255
264
  }
@@ -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 = "2.5.0-alpha.6";
16
+ export declare const version = "2.5.0-alpha.8";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ar.io/sdk",
3
- "version": "2.5.0-alpha.7",
3
+ "version": "2.5.0-alpha.9",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/ar-io/ar-io-sdk.git"