@blockcore/dns 0.0.2 → 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.
- package/README.md +25 -1
- package/lib/BlockcoreDns.d.ts +12 -0
- package/lib/BlockcoreDns.js +37 -0
- package/lib/Request.d.ts +6 -0
- package/lib/Request.js +24 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +2 -0
- package/lib/types.d.ts +11 -0
- package/{dist/index.js → lib/types.js} +0 -0
- package/package.json +5 -5
- package/dist/BlockcoreDns.d.ts +0 -8
- package/dist/BlockcoreDns.js +0 -39
- package/dist/index.d.ts +0 -3
- package/dist/options.d.ts +0 -3
- package/dist/options.js +0 -1
package/README.md
CHANGED
@@ -22,4 +22,28 @@
|
|
22
22
|
npm install @blockcore/dns
|
23
23
|
```
|
24
24
|
|
25
|
-
**Warning:** This package is native [ESM](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules) and does not provide a CommonJS export. If your project uses CommonJS, you'll have to [convert to ESM](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c) or use the [dynamic `import()`](https://v8.dev/features/dynamic-import) function.
|
25
|
+
**Warning:** This package is native [ESM](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules) and does not provide a CommonJS export. If your project uses CommonJS, you'll have to [convert to ESM](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c) or use the [dynamic `import()`](https://v8.dev/features/dynamic-import) function.
|
26
|
+
|
27
|
+
|
28
|
+
## Usage
|
29
|
+
|
30
|
+
```ts
|
31
|
+
import { BlockcoreDns } from '@blockcore/dns';
|
32
|
+
|
33
|
+
let dns = new BlockcoreDns();
|
34
|
+
let servers = await dns.getDnsServers();
|
35
|
+
```
|
36
|
+
|
37
|
+
After getting the servers, either you can loop all of them or pick a single one:
|
38
|
+
|
39
|
+
```ts
|
40
|
+
let server = servers[0];
|
41
|
+
|
42
|
+
dns.setActiveServer(dnsServer.url);
|
43
|
+
|
44
|
+
await dns.getServicesByType('Indexer');
|
45
|
+
await dns.getServicesByNetwork('CITY');
|
46
|
+
await dns.getServicesByTypeAndNetwork('Indexer', 'CITY');
|
47
|
+
await dns.getExternalIP();
|
48
|
+
```
|
49
|
+
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { DnsListEntry, ServiceListEntry } from './types.js';
|
2
|
+
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>;
|
12
|
+
}
|
@@ -0,0 +1,37 @@
|
|
1
|
+
import { WebRequest } from './Request.js';
|
2
|
+
export class BlockcoreDns {
|
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
|
+
/** 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;
|
17
|
+
}
|
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);
|
24
|
+
}
|
25
|
+
async getServicesByTypeAndNetwork(service, symbol) {
|
26
|
+
const url = `${this.activeServer}/api/dns/services/symbol/${symbol}/service/${service}`;
|
27
|
+
return await WebRequest.fetchJson(url);
|
28
|
+
}
|
29
|
+
async getServicesByNetwork(symbol) {
|
30
|
+
const url = `${this.activeServer}/api/dns/services/symbol/${symbol}`;
|
31
|
+
return await WebRequest.fetchJson(url);
|
32
|
+
}
|
33
|
+
async getExternalIP() {
|
34
|
+
const url = `${this.activeServer}/api/dns/ipaddress`;
|
35
|
+
return await WebRequest.fetchText(url);
|
36
|
+
}
|
37
|
+
}
|
package/lib/Request.d.ts
ADDED
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/index.d.ts
ADDED
package/lib/index.js
ADDED
package/lib/types.d.ts
ADDED
File without changes
|
package/package.json
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
{
|
2
2
|
"name": "@blockcore/dns",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.5",
|
4
4
|
"type": "module",
|
5
|
-
"exports": "./
|
6
|
-
"types": "./
|
5
|
+
"exports": "./lib/index.js",
|
6
|
+
"types": "./lib/index.d.ts",
|
7
7
|
"files": [
|
8
|
-
"
|
8
|
+
"lib/**/*"
|
9
9
|
],
|
10
10
|
"engines": {
|
11
11
|
"node": ">=14.16"
|
@@ -52,7 +52,7 @@
|
|
52
52
|
]
|
53
53
|
},
|
54
54
|
"dependencies": {
|
55
|
-
"
|
55
|
+
"@blockcore/identity": "^0.0.1",
|
56
56
|
"node-fetch": "^3.2.9"
|
57
57
|
}
|
58
58
|
}
|
package/dist/BlockcoreDns.d.ts
DELETED
@@ -1,8 +0,0 @@
|
|
1
|
-
import { BlockcoreDnsOptions } from './options.js';
|
2
|
-
export declare class BlockcoreDns {
|
3
|
-
private options;
|
4
|
-
static defaultOptions: BlockcoreDnsOptions;
|
5
|
-
static create(): BlockcoreDns;
|
6
|
-
constructor(options?: BlockcoreDnsOptions);
|
7
|
-
getDnsServers(): Promise<unknown>;
|
8
|
-
}
|
package/dist/BlockcoreDns.js
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
import fetch from 'node-fetch';
|
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
|
-
});
|
10
|
-
}
|
11
|
-
static create() {
|
12
|
-
const dns = new BlockcoreDns();
|
13
|
-
return dns;
|
14
|
-
}
|
15
|
-
async getDnsServers() {
|
16
|
-
const url = `${this.options.baseUrl}/services/BLOCKCORE-DNS.json`;
|
17
|
-
const response = await fetch(url, {
|
18
|
-
method: 'GET',
|
19
|
-
// mode: 'cors',
|
20
|
-
// cache: 'no-cache',
|
21
|
-
// credentials: 'same-origin',
|
22
|
-
headers: {
|
23
|
-
'Content-Type': 'application/json',
|
24
|
-
},
|
25
|
-
redirect: 'follow',
|
26
|
-
referrerPolicy: 'no-referrer',
|
27
|
-
});
|
28
|
-
const servers = await response.json();
|
29
|
-
return servers;
|
30
|
-
}
|
31
|
-
}
|
32
|
-
Object.defineProperty(BlockcoreDns, "defaultOptions", {
|
33
|
-
enumerable: true,
|
34
|
-
configurable: true,
|
35
|
-
writable: true,
|
36
|
-
value: {
|
37
|
-
baseUrl: 'https://chains.blockcore.net',
|
38
|
-
}
|
39
|
-
});
|
package/dist/index.d.ts
DELETED
package/dist/options.d.ts
DELETED
package/dist/options.js
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
export {};
|