@blockcore/dns 0.0.4 → 0.0.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.
@@ -1,17 +1,12 @@
1
- import { BlockcoreDnsOptions, DnsListEntry, ServiceListEntry } from './types.js';
1
+ import { DnsListEntry, ServiceListEntry } from './types.js';
2
2
  export declare class BlockcoreDns {
3
- private options;
4
- static defaultOptions: BlockcoreDnsOptions;
5
- static create(): BlockcoreDns;
3
+ /** Call this to have data to provide an instance of the Blockcore DNS. */
4
+ static getDnsServers(): Promise<DnsListEntry[]>;
6
5
  private activeServer?;
7
- constructor(options?: BlockcoreDnsOptions);
6
+ constructor(nameserver: string);
8
7
  setActiveServer(url: string): void;
9
- getDnsServers(): Promise<DnsListEntry[]>;
10
8
  getServicesByType(service: 'Indexer' | 'Explorer'): Promise<ServiceListEntry[]>;
11
9
  getServicesByTypeAndNetwork(service: 'Indexer' | 'Explorer', symbol: string): Promise<ServiceListEntry[]>;
12
10
  getServicesByNetwork(symbol: string): Promise<ServiceListEntry[]>;
13
11
  getExternalIP(): Promise<string>;
14
- private fetchText;
15
- private fetchJson;
16
- private fetchUrl;
17
12
  }
@@ -1,74 +1,37 @@
1
- import fetch from 'node-fetch';
1
+ import { WebRequest } from './Request.js';
2
2
  export class BlockcoreDns {
3
- constructor(options = BlockcoreDns.defaultOptions) {
4
- Object.defineProperty(this, "options", {
5
- enumerable: true,
6
- configurable: true,
7
- writable: true,
8
- value: options
9
- });
3
+ constructor(nameserver) {
10
4
  Object.defineProperty(this, "activeServer", {
11
5
  enumerable: true,
12
6
  configurable: true,
13
7
  writable: true,
14
8
  value: void 0
15
9
  });
10
+ this.setActiveServer(nameserver);
16
11
  }
17
- static create() {
18
- const dns = new BlockcoreDns();
19
- return dns;
12
+ /** Call this to have data to provide an instance of the Blockcore DNS. */
13
+ static async getDnsServers() {
14
+ const url = `https://chains.blockcore.net/services/DNS.json`;
15
+ const servers = await WebRequest.fetchJson(url);
16
+ return servers;
20
17
  }
21
18
  setActiveServer(url) {
22
19
  this.activeServer = url;
23
20
  }
24
- async getDnsServers() {
25
- const url = `${this.options.baseUrl}/services/DNS.json`;
26
- const servers = await this.fetchJson(url);
27
- return servers;
28
- }
29
21
  async getServicesByType(service) {
30
22
  const url = `${this.activeServer}/api/dns/services/service/${service}`;
31
- return await this.fetchJson(url);
23
+ return await WebRequest.fetchJson(url);
32
24
  }
33
25
  async getServicesByTypeAndNetwork(service, symbol) {
34
26
  const url = `${this.activeServer}/api/dns/services/symbol/${symbol}/service/${service}`;
35
- return await this.fetchJson(url);
27
+ return await WebRequest.fetchJson(url);
36
28
  }
37
29
  async getServicesByNetwork(symbol) {
38
30
  const url = `${this.activeServer}/api/dns/services/symbol/${symbol}`;
39
- return await this.fetchJson(url);
31
+ return await WebRequest.fetchJson(url);
40
32
  }
41
33
  async getExternalIP() {
42
34
  const url = `${this.activeServer}/api/dns/ipaddress`;
43
- return await this.fetchText(url);
44
- }
45
- async fetchText(url) {
46
- const response = await this.fetchUrl(url);
47
- return response.text();
48
- }
49
- async fetchJson(url) {
50
- const response = await this.fetchUrl(url);
51
- return response.json();
52
- }
53
- async fetchUrl(url) {
54
- return await fetch(url, {
55
- method: 'GET',
56
- // mode: 'cors',
57
- // cache: 'no-cache',
58
- // credentials: 'same-origin',
59
- headers: {
60
- 'Content-Type': 'application/json',
61
- },
62
- redirect: 'follow',
63
- referrerPolicy: 'no-referrer',
64
- });
35
+ return await WebRequest.fetchText(url);
65
36
  }
66
37
  }
67
- Object.defineProperty(BlockcoreDns, "defaultOptions", {
68
- enumerable: true,
69
- configurable: true,
70
- writable: true,
71
- value: {
72
- baseUrl: 'https://chains.blockcore.net',
73
- }
74
- });
@@ -0,0 +1,6 @@
1
+ import { Response } from 'node-fetch';
2
+ export declare class WebRequest {
3
+ static fetchText(url: string): Promise<string>;
4
+ static fetchJson<T>(url: string): Promise<T>;
5
+ static fetchUrl(url: string): Promise<Response>;
6
+ }
package/lib/Request.js ADDED
@@ -0,0 +1,24 @@
1
+ import fetch from 'node-fetch';
2
+ export class WebRequest {
3
+ static async fetchText(url) {
4
+ const response = await WebRequest.fetchUrl(url);
5
+ return response.text();
6
+ }
7
+ static async fetchJson(url) {
8
+ const response = await WebRequest.fetchUrl(url);
9
+ return response.json();
10
+ }
11
+ static async fetchUrl(url) {
12
+ return await fetch(url, {
13
+ method: 'GET',
14
+ // mode: 'cors',
15
+ // cache: 'no-cache',
16
+ // credentials: 'same-origin',
17
+ headers: {
18
+ 'Content-Type': 'application/json',
19
+ },
20
+ redirect: 'follow',
21
+ referrerPolicy: 'no-referrer',
22
+ });
23
+ }
24
+ }
package/lib/types.d.ts CHANGED
@@ -9,6 +9,3 @@ export interface ServiceListEntry {
9
9
  ttl: number;
10
10
  online: boolean;
11
11
  }
12
- export interface BlockcoreDnsOptions {
13
- baseUrl: string;
14
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blockcore/dns",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "type": "module",
5
5
  "exports": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -52,7 +52,6 @@
52
52
  ]
53
53
  },
54
54
  "dependencies": {
55
- "@blockcore/dns": "^0.0.3",
56
55
  "@blockcore/identity": "^0.0.1",
57
56
  "node-fetch": "^3.2.9"
58
57
  }