@blockcore/dns 0.0.9 → 0.0.11
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 +4 -4
- package/lib/BlockcoreDns.d.ts +9 -3
- package/lib/BlockcoreDns.js +18 -6
- package/lib/BlockcoreDnsClient.d.ts +2 -2
- package/package.json +8 -8
package/README.md
CHANGED
@@ -55,8 +55,8 @@ You can create an load the nameservers using this static function:
|
|
55
55
|
let dnsServers = await BlockcoreDns.getDnsServers();
|
56
56
|
dns.setActiveServer(dnsServers[0].url);
|
57
57
|
|
58
|
-
await dns.getServicesByType('Indexer');
|
59
|
-
await dns.getServicesByNetwork('CITY');
|
60
|
-
await dns.getServicesByTypeAndNetwork('Indexer', 'CITY');
|
61
|
-
await dns.getExternalIP();
|
58
|
+
await dns.api.getServicesByType('Indexer');
|
59
|
+
await dns.api.getServicesByNetwork('CITY');
|
60
|
+
await dns.api.getServicesByTypeAndNetwork('Indexer', 'CITY');
|
61
|
+
await dns.api.getExternalIP();
|
62
62
|
```
|
package/lib/BlockcoreDns.d.ts
CHANGED
@@ -1,16 +1,22 @@
|
|
1
1
|
import { DnsListEntry, ServiceListEntry } from './types.js';
|
2
|
+
import { BlockcoreDnsClient } from './BlockcoreDnsClient.js';
|
2
3
|
/** The BlockcoreDns class will give you access to all known nameservers and all services registered with those nameservers. */
|
3
4
|
export declare class BlockcoreDns {
|
4
5
|
private nameservers;
|
5
6
|
private services;
|
6
|
-
|
7
|
+
api: BlockcoreDnsClient;
|
7
8
|
constructor();
|
8
|
-
|
9
|
+
getDnsServers(): Promise<DnsListEntry[]>;
|
9
10
|
getNameServers(): DnsListEntry[];
|
10
11
|
getOnlineServicesByNetwork(network: string): ServiceListEntry[];
|
11
12
|
getServices(): ServiceListEntry[];
|
12
13
|
/** Attempts to load the latest status of all services from all known nameservers. This method can be called
|
13
14
|
* at intervals to ensure latest status is available.
|
15
|
+
*
|
16
|
+
* By supplying the serviceType, a different than default list of services can be provided in the .getServices() method.
|
17
|
+
*
|
18
|
+
* Supply null as parameter for serviceType to avoid preloading services.
|
14
19
|
*/
|
15
|
-
load(nameservers?: DnsListEntry[]): Promise<void>;
|
20
|
+
load(nameservers?: DnsListEntry[], serviceType?: string): Promise<void>;
|
21
|
+
private getRandomInt;
|
16
22
|
}
|
package/lib/BlockcoreDns.js
CHANGED
@@ -15,13 +15,13 @@ export class BlockcoreDns {
|
|
15
15
|
writable: true,
|
16
16
|
value: []
|
17
17
|
});
|
18
|
-
Object.defineProperty(this, "
|
18
|
+
Object.defineProperty(this, "api", {
|
19
19
|
enumerable: true,
|
20
20
|
configurable: true,
|
21
21
|
writable: true,
|
22
22
|
value: void 0
|
23
23
|
});
|
24
|
-
this.
|
24
|
+
this.api = new BlockcoreDnsClient('');
|
25
25
|
}
|
26
26
|
async getDnsServers() {
|
27
27
|
const url = `https://chains.blockcore.net/services/DNS.json`;
|
@@ -39,8 +39,12 @@ export class BlockcoreDns {
|
|
39
39
|
}
|
40
40
|
/** Attempts to load the latest status of all services from all known nameservers. This method can be called
|
41
41
|
* at intervals to ensure latest status is available.
|
42
|
+
*
|
43
|
+
* By supplying the serviceType, a different than default list of services can be provided in the .getServices() method.
|
44
|
+
*
|
45
|
+
* Supply null as parameter for serviceType to avoid preloading services.
|
42
46
|
*/
|
43
|
-
async load(nameservers) {
|
47
|
+
async load(nameservers, serviceType = 'Indexer') {
|
44
48
|
this.nameservers = nameservers || (await this.getDnsServers());
|
45
49
|
const servicesMap = new Map();
|
46
50
|
for (let i = 0; i < this.nameservers.length; i++) {
|
@@ -48,10 +52,18 @@ export class BlockcoreDns {
|
|
48
52
|
if (!nameserver) {
|
49
53
|
continue;
|
50
54
|
}
|
51
|
-
this.
|
52
|
-
|
53
|
-
|
55
|
+
this.api.setActiveServer(nameserver.url);
|
56
|
+
if (serviceType) {
|
57
|
+
const services = await this.api.getServicesByType(serviceType);
|
58
|
+
services.forEach((item) => servicesMap.set(item.domain, { ...servicesMap.get(item.domain), ...item }));
|
59
|
+
}
|
54
60
|
}
|
55
61
|
this.services = Array.from(servicesMap.values());
|
62
|
+
// Set randomly active server after load is complete.
|
63
|
+
const randomIndex = this.getRandomInt(this.nameservers.length);
|
64
|
+
this.api.setActiveServer(this.nameservers[randomIndex].url);
|
65
|
+
}
|
66
|
+
getRandomInt(max) {
|
67
|
+
return Math.floor(Math.random() * max);
|
56
68
|
}
|
57
69
|
}
|
@@ -3,8 +3,8 @@ export declare class BlockcoreDnsClient {
|
|
3
3
|
private activeServer?;
|
4
4
|
constructor(nameserver: string);
|
5
5
|
setActiveServer(url: string): void;
|
6
|
-
getServicesByType(service:
|
7
|
-
getServicesByTypeAndNetwork(service:
|
6
|
+
getServicesByType(service: string): Promise<ServiceListEntry[]>;
|
7
|
+
getServicesByTypeAndNetwork(service: string, symbol: string): Promise<ServiceListEntry[]>;
|
8
8
|
getServicesByNetwork(symbol: string): Promise<ServiceListEntry[]>;
|
9
9
|
getExternalIP(): Promise<string>;
|
10
10
|
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@blockcore/dns",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.11",
|
4
4
|
"description": "DNS Provider package to query and resolve dynamic and decentralized DNS entries",
|
5
5
|
"type": "module",
|
6
6
|
"exports": "./lib/index.js",
|
@@ -30,16 +30,16 @@
|
|
30
30
|
"homepage": "https://github.com/block-core/blockcore-dns-js#readme",
|
31
31
|
"devDependencies": {
|
32
32
|
"@blockcore/tsconfig": "^0.0.1",
|
33
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
34
|
-
"@typescript-eslint/parser": "^5.
|
35
|
-
"ava": "^
|
36
|
-
"eslint": "^8.
|
33
|
+
"@typescript-eslint/eslint-plugin": "^5.44.0",
|
34
|
+
"@typescript-eslint/parser": "^5.44.0",
|
35
|
+
"ava": "^5.1.0",
|
36
|
+
"eslint": "^8.28.0",
|
37
37
|
"eslint-config-standard": "^17.0.0",
|
38
38
|
"eslint-plugin-import": "^2.26.0",
|
39
|
-
"eslint-plugin-n": "^15.
|
40
|
-
"eslint-plugin-promise": "^6.
|
39
|
+
"eslint-plugin-n": "^15.5.1",
|
40
|
+
"eslint-plugin-promise": "^6.1.1",
|
41
41
|
"ts-node": "^10.9.1",
|
42
|
-
"typescript": "^4.
|
42
|
+
"typescript": "^4.9.3"
|
43
43
|
},
|
44
44
|
"ava": {
|
45
45
|
"files": [
|