@blockcore/dns 0.0.7 → 0.0.8

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.
@@ -1,12 +1,16 @@
1
1
  import { DnsListEntry, ServiceListEntry } from './types.js';
2
+ /** The BlockcoreDns class will give you access to all known nameservers and all services registered with those nameservers. */
2
3
  export declare class BlockcoreDns {
3
- /** Call this to have data to provide an instance of the Blockcore DNS. */
4
- static getDnsServers(): Promise<DnsListEntry[]>;
5
- private activeServer?;
6
- constructor(nameserver: string);
7
- setActiveServer(url: string): void;
8
- getServicesByType(service: 'Indexer' | 'Explorer'): Promise<ServiceListEntry[]>;
9
- getServicesByTypeAndNetwork(service: 'Indexer' | 'Explorer', symbol: string): Promise<ServiceListEntry[]>;
10
- getServicesByNetwork(symbol: string): Promise<ServiceListEntry[]>;
11
- getExternalIP(): Promise<string>;
4
+ private nameservers;
5
+ private services;
6
+ private dns;
7
+ constructor();
8
+ private getDnsServers;
9
+ getNameServers(): DnsListEntry[];
10
+ getOnlineServicesByNetwork(network: string): ServiceListEntry[];
11
+ getServices(): ServiceListEntry[];
12
+ /** Attempts to load the latest status of all services from all known nameservers. This method can be called
13
+ * at intervals to ensure latest status is available.
14
+ */
15
+ load(): Promise<void>;
12
16
  }
@@ -1,37 +1,57 @@
1
1
  import { WebRequest } from './Request.js';
2
+ import { BlockcoreDnsClient } from './BlockcoreDnsClient.js';
3
+ /** The BlockcoreDns class will give you access to all known nameservers and all services registered with those nameservers. */
2
4
  export class BlockcoreDns {
3
- constructor(nameserver) {
4
- Object.defineProperty(this, "activeServer", {
5
+ constructor() {
6
+ Object.defineProperty(this, "nameservers", {
7
+ enumerable: true,
8
+ configurable: true,
9
+ writable: true,
10
+ value: []
11
+ });
12
+ Object.defineProperty(this, "services", {
13
+ enumerable: true,
14
+ configurable: true,
15
+ writable: true,
16
+ value: []
17
+ });
18
+ Object.defineProperty(this, "dns", {
5
19
  enumerable: true,
6
20
  configurable: true,
7
21
  writable: true,
8
22
  value: void 0
9
23
  });
10
- this.setActiveServer(nameserver);
24
+ this.dns = new BlockcoreDnsClient('');
11
25
  }
12
- /** Call this to have data to provide an instance of the Blockcore DNS. */
13
- static async getDnsServers() {
26
+ async getDnsServers() {
14
27
  const url = `https://chains.blockcore.net/services/DNS.json`;
15
28
  const servers = await WebRequest.fetchJson(url);
16
29
  return servers;
17
30
  }
18
- setActiveServer(url) {
19
- this.activeServer = url;
20
- }
21
- async getServicesByType(service) {
22
- const url = `${this.activeServer}/api/dns/services/service/${service}`;
23
- return await WebRequest.fetchJson(url);
31
+ getNameServers() {
32
+ return this.nameservers;
24
33
  }
25
- async getServicesByTypeAndNetwork(service, symbol) {
26
- const url = `${this.activeServer}/api/dns/services/symbol/${symbol}/service/${service}`;
27
- return await WebRequest.fetchJson(url);
34
+ getOnlineServicesByNetwork(network) {
35
+ return this.services.filter((s) => s.symbol === network && s.online === true);
28
36
  }
29
- async getServicesByNetwork(symbol) {
30
- const url = `${this.activeServer}/api/dns/services/symbol/${symbol}`;
31
- return await WebRequest.fetchJson(url);
37
+ getServices() {
38
+ return this.services;
32
39
  }
33
- async getExternalIP() {
34
- const url = `${this.activeServer}/api/dns/ipaddress`;
35
- return await WebRequest.fetchText(url);
40
+ /** Attempts to load the latest status of all services from all known nameservers. This method can be called
41
+ * at intervals to ensure latest status is available.
42
+ */
43
+ async load() {
44
+ this.nameservers = await this.getDnsServers();
45
+ const servicesMap = new Map();
46
+ for (let i = 0; i < this.nameservers.length; i++) {
47
+ const nameserver = this.nameservers[i];
48
+ if (!nameserver) {
49
+ continue;
50
+ }
51
+ this.dns.setActiveServer(nameserver.url);
52
+ const services = await this.dns.getServicesByType('Indexer');
53
+ services.forEach((item) => servicesMap.set(item.domain, { ...servicesMap.get(item.domain), ...item }));
54
+ }
55
+ this.services = Array.from(servicesMap.values());
36
56
  }
37
57
  }
@@ -0,0 +1,10 @@
1
+ import { ServiceListEntry } from './types.js';
2
+ export declare class BlockcoreDnsClient {
3
+ private activeServer?;
4
+ constructor(nameserver: string);
5
+ setActiveServer(url: string): void;
6
+ getServicesByType(service: 'Indexer' | 'Explorer'): Promise<ServiceListEntry[]>;
7
+ getServicesByTypeAndNetwork(service: 'Indexer' | 'Explorer', symbol: string): Promise<ServiceListEntry[]>;
8
+ getServicesByNetwork(symbol: string): Promise<ServiceListEntry[]>;
9
+ getExternalIP(): Promise<string>;
10
+ }
@@ -0,0 +1,31 @@
1
+ import { WebRequest } from './Request.js';
2
+ export class BlockcoreDnsClient {
3
+ constructor(nameserver) {
4
+ Object.defineProperty(this, "activeServer", {
5
+ enumerable: true,
6
+ configurable: true,
7
+ writable: true,
8
+ value: void 0
9
+ });
10
+ this.setActiveServer(nameserver);
11
+ }
12
+ setActiveServer(url) {
13
+ this.activeServer = url;
14
+ }
15
+ async getServicesByType(service) {
16
+ const url = `${this.activeServer}/api/dns/services/service/${service}`;
17
+ return await WebRequest.fetchJson(url);
18
+ }
19
+ async getServicesByTypeAndNetwork(service, symbol) {
20
+ const url = `${this.activeServer}/api/dns/services/symbol/${symbol}/service/${service}`;
21
+ return await WebRequest.fetchJson(url);
22
+ }
23
+ async getServicesByNetwork(symbol) {
24
+ const url = `${this.activeServer}/api/dns/services/symbol/${symbol}`;
25
+ return await WebRequest.fetchJson(url);
26
+ }
27
+ async getExternalIP() {
28
+ const url = `${this.activeServer}/api/dns/ipaddress`;
29
+ return await WebRequest.fetchText(url);
30
+ }
31
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blockcore/dns",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "type": "module",
5
5
  "exports": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",