@ar.io/sdk 3.22.0-alpha.4 → 3.22.0-alpha.5

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.
@@ -64,7 +64,7 @@ class HB {
64
64
  * const result = await hyperbeam.compute({ path: 'balances/QGWqtJdLLgm2ehFWiiPzMaoFLD50CnGuzZIPEdoDRGQ' });
65
65
  * console.log(result);
66
66
  */
67
- async compute({ path, json = false, }) {
67
+ async compute({ path, json = true, }) {
68
68
  return this.fetchHyperbeamPath({
69
69
  path: `${this.url}/${this.processId}~process@1.0/compute/${path}`,
70
70
  json,
@@ -112,7 +112,7 @@ class HB {
112
112
  return false;
113
113
  })
114
114
  .catch((error) => {
115
- this.logger.debug('Failed to check HyperBeam compatibility', {
115
+ this.logger.error('Failed to check HyperBeam compatibility', {
116
116
  cause: error,
117
117
  });
118
118
  this.isHyperBeamCompatible = false;
@@ -590,6 +590,30 @@ class ARIOReadable {
590
590
  });
591
591
  }
592
592
  async getPrimaryNameRequest(params) {
593
+ if (this.hb && (await this.hb.checkHyperBeamCompatibility())) {
594
+ this.logger.debug('Getting primary name request from HyperBEAM', {
595
+ initiator: params.initiator,
596
+ });
597
+ const res = await this.hb
598
+ .compute({
599
+ path: `/primary-names/requests/${params.initiator}`,
600
+ })
601
+ .catch((error) => {
602
+ this.logger.error('Failed to get primary name request from HyperBEAM', {
603
+ cause: error,
604
+ });
605
+ return null;
606
+ });
607
+ if (res !== null) {
608
+ // Ensure initiator is included in the result
609
+ return {
610
+ ...res,
611
+ initiator: params.initiator,
612
+ };
613
+ }
614
+ // else fall through to CU read
615
+ this.logger.info('Failed to get primary name request from HyperBEAM, failing over to CU read', { initiator: params.initiator });
616
+ }
593
617
  const allTags = [
594
618
  { name: 'Action', value: 'Primary-Name-Request' },
595
619
  {
@@ -610,6 +634,46 @@ class ARIOReadable {
610
634
  });
611
635
  }
612
636
  async getPrimaryName(params) {
637
+ if (this.hb && (await this.hb.checkHyperBeamCompatibility())) {
638
+ this.logger.debug('Getting primary name from HyperBEAM', { params });
639
+ try {
640
+ let owner;
641
+ if ('name' in params) {
642
+ // Step 1: Get owner from /primary-names/names/<name>
643
+ owner = await this.hb.compute({
644
+ path: `/primary-names/names/${params.name}`,
645
+ });
646
+ }
647
+ else {
648
+ // If given address, skip the /names/name query
649
+ owner = params.address;
650
+ }
651
+ // Step 2: Get {name, startTimestamp} from /primary-names/owners/<owner>
652
+ const ownerData = await this.hb.compute({
653
+ path: `/primary-names/owners/${owner}`,
654
+ });
655
+ const name = ownerData.name;
656
+ const startTimestamp = ownerData.startTimestamp;
657
+ // Step 3: Get processId from getArNSRecord
658
+ const record = await this.getArNSRecord({ name });
659
+ const processId = record.processId;
660
+ // Combine all data
661
+ const result = {
662
+ owner,
663
+ name,
664
+ startTimestamp,
665
+ processId,
666
+ };
667
+ return result;
668
+ }
669
+ catch (error) {
670
+ this.logger.error('Failed to get primary name from HyperBEAM', {
671
+ cause: error,
672
+ });
673
+ // Fall through to CU read
674
+ this.logger.info('Failed to get primary name from HyperBEAM, failing over to CU read', { params });
675
+ }
676
+ }
613
677
  const allTags = [
614
678
  { name: 'Action', value: 'Primary-Name' },
615
679
  {
@@ -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.22.0-alpha.4';
20
+ exports.version = '3.22.0-alpha.5';
@@ -61,7 +61,7 @@ export class HB {
61
61
  * const result = await hyperbeam.compute({ path: 'balances/QGWqtJdLLgm2ehFWiiPzMaoFLD50CnGuzZIPEdoDRGQ' });
62
62
  * console.log(result);
63
63
  */
64
- async compute({ path, json = false, }) {
64
+ async compute({ path, json = true, }) {
65
65
  return this.fetchHyperbeamPath({
66
66
  path: `${this.url}/${this.processId}~process@1.0/compute/${path}`,
67
67
  json,
@@ -109,7 +109,7 @@ export class HB {
109
109
  return false;
110
110
  })
111
111
  .catch((error) => {
112
- this.logger.debug('Failed to check HyperBeam compatibility', {
112
+ this.logger.error('Failed to check HyperBeam compatibility', {
113
113
  cause: error,
114
114
  });
115
115
  this.isHyperBeamCompatible = false;
@@ -586,6 +586,30 @@ export class ARIOReadable {
586
586
  });
587
587
  }
588
588
  async getPrimaryNameRequest(params) {
589
+ if (this.hb && (await this.hb.checkHyperBeamCompatibility())) {
590
+ this.logger.debug('Getting primary name request from HyperBEAM', {
591
+ initiator: params.initiator,
592
+ });
593
+ const res = await this.hb
594
+ .compute({
595
+ path: `/primary-names/requests/${params.initiator}`,
596
+ })
597
+ .catch((error) => {
598
+ this.logger.error('Failed to get primary name request from HyperBEAM', {
599
+ cause: error,
600
+ });
601
+ return null;
602
+ });
603
+ if (res !== null) {
604
+ // Ensure initiator is included in the result
605
+ return {
606
+ ...res,
607
+ initiator: params.initiator,
608
+ };
609
+ }
610
+ // else fall through to CU read
611
+ this.logger.info('Failed to get primary name request from HyperBEAM, failing over to CU read', { initiator: params.initiator });
612
+ }
589
613
  const allTags = [
590
614
  { name: 'Action', value: 'Primary-Name-Request' },
591
615
  {
@@ -606,6 +630,46 @@ export class ARIOReadable {
606
630
  });
607
631
  }
608
632
  async getPrimaryName(params) {
633
+ if (this.hb && (await this.hb.checkHyperBeamCompatibility())) {
634
+ this.logger.debug('Getting primary name from HyperBEAM', { params });
635
+ try {
636
+ let owner;
637
+ if ('name' in params) {
638
+ // Step 1: Get owner from /primary-names/names/<name>
639
+ owner = await this.hb.compute({
640
+ path: `/primary-names/names/${params.name}`,
641
+ });
642
+ }
643
+ else {
644
+ // If given address, skip the /names/name query
645
+ owner = params.address;
646
+ }
647
+ // Step 2: Get {name, startTimestamp} from /primary-names/owners/<owner>
648
+ const ownerData = await this.hb.compute({
649
+ path: `/primary-names/owners/${owner}`,
650
+ });
651
+ const name = ownerData.name;
652
+ const startTimestamp = ownerData.startTimestamp;
653
+ // Step 3: Get processId from getArNSRecord
654
+ const record = await this.getArNSRecord({ name });
655
+ const processId = record.processId;
656
+ // Combine all data
657
+ const result = {
658
+ owner,
659
+ name,
660
+ startTimestamp,
661
+ processId,
662
+ };
663
+ return result;
664
+ }
665
+ catch (error) {
666
+ this.logger.error('Failed to get primary name from HyperBEAM', {
667
+ cause: error,
668
+ });
669
+ // Fall through to CU read
670
+ this.logger.info('Failed to get primary name from HyperBEAM, failing over to CU read', { params });
671
+ }
672
+ }
609
673
  const allTags = [
610
674
  { name: 'Action', value: 'Primary-Name' },
611
675
  {
@@ -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.22.0-alpha.4';
17
+ export const version = '3.22.0-alpha.5';
@@ -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.22.0-alpha.3";
16
+ export declare const version = "3.22.0-alpha.4";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ar.io/sdk",
3
- "version": "3.22.0-alpha.4",
3
+ "version": "3.22.0-alpha.5",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/ar-io/ar-io-sdk.git"