@blockcore/dns 0.0.4 → 0.0.7

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.
package/README.md CHANGED
@@ -30,20 +30,18 @@ npm install @blockcore/dns
30
30
  ```ts
31
31
  import { BlockcoreDns } from '@blockcore/dns';
32
32
 
33
- let dns = new BlockcoreDns();
34
- let servers = await dns.getDnsServers();
33
+ let dns = new BlockcoreDns('https://ns.blockcore.net');
34
+ let indexers = await dns.getServicesByType('Indexer');
35
35
  ```
36
36
 
37
- After getting the servers, either you can loop all of them or pick a single one:
37
+ You can retrieve the public known nameservers and use those instead of manually specifying server:
38
38
 
39
39
  ```ts
40
- let server = servers[0];
41
-
42
- dns.setActiveServer(dnsServer.url);
40
+ let dnsServers = await BlockcoreDns.getDnsServers();
41
+ dns.setActiveServer(dnsServers[0].url);
43
42
 
44
43
  await dns.getServicesByType('Indexer');
45
44
  await dns.getServicesByNetwork('CITY');
46
45
  await dns.getServicesByTypeAndNetwork('Indexer', 'CITY');
47
46
  await dns.getExternalIP();
48
47
  ```
49
-
@@ -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,5 @@
1
+ export declare class WebRequest {
2
+ static fetchText(url: string): Promise<string>;
3
+ static fetchJson<T>(url: string): Promise<T>;
4
+ static fetchUrl(url: string): Promise<Response>;
5
+ }
package/lib/Request.js ADDED
@@ -0,0 +1,20 @@
1
+ export class WebRequest {
2
+ static async fetchText(url) {
3
+ const response = await WebRequest.fetchUrl(url);
4
+ return response.text();
5
+ }
6
+ static async fetchJson(url) {
7
+ const response = await WebRequest.fetchUrl(url);
8
+ return response.json();
9
+ }
10
+ static async fetchUrl(url) {
11
+ return await fetch(url, {
12
+ method: 'GET',
13
+ mode: 'cors',
14
+ cache: 'no-cache',
15
+ credentials: 'omit',
16
+ redirect: 'follow',
17
+ referrerPolicy: 'no-referrer',
18
+ });
19
+ }
20
+ }
package/lib/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './BlockcoreDns.js';
2
+ export * from './Request.js';
2
3
  export * from './types.js';
package/lib/index.js CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './BlockcoreDns.js';
2
+ export * from './Request.js';
2
3
  export * from './types.js';
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.7",
4
4
  "type": "module",
5
5
  "exports": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -8,13 +8,14 @@
8
8
  "lib/**/*"
9
9
  ],
10
10
  "engines": {
11
- "node": ">=14.16"
11
+ "node": ">=18.*"
12
12
  },
13
13
  "scripts": {
14
14
  "build": "tsc",
15
15
  "lint": "eslint .",
16
16
  "test": "npm run lint && ava",
17
- "version": "node -p \"require('./package.json').version\""
17
+ "version": "node -p \"require('./package.json').version\"",
18
+ "changelog": "conventional-changelog -i CHANGELOG.md -s -r 0 && git add CHANGELOG.md"
18
19
  },
19
20
  "repository": {
20
21
  "type": "git",
@@ -50,10 +51,5 @@
50
51
  "nodeArguments": [
51
52
  "--loader=ts-node/esm"
52
53
  ]
53
- },
54
- "dependencies": {
55
- "@blockcore/dns": "^0.0.3",
56
- "@blockcore/identity": "^0.0.1",
57
- "node-fetch": "^3.2.9"
58
54
  }
59
55
  }