@chainfuse/helpers 0.5.0 → 0.6.0

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/dist/dns.d.mts ADDED
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Supported parameters for Cloudflare's 1.1.1.1 DNS over HTTPS API
3
+ */
4
+ export interface DohBodyRequest {
5
+ /** Query name (required) */
6
+ name: string;
7
+ /** Query type - either a numeric value or text. Default is 'A' */
8
+ type?: string | number;
9
+ /**
10
+ * DO bit - whether the client wants DNSSEC data.
11
+ * Either empty or one of `0`, `false`, `1`, or `true`. Default is `false`
12
+ */
13
+ do?: string | number | boolean;
14
+ /**
15
+ * CD bit - disable validation.
16
+ * Either empty or one of `0`, `false`, `1`, or `true`. Default is `false`
17
+ */
18
+ cd?: string | number | boolean;
19
+ }
20
+ /**
21
+ * A record structure with name, type, TTL, and data.
22
+ */
23
+ interface Record {
24
+ /** The record owner */
25
+ name: string;
26
+ /** The type of DNS record. Defined here: https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml#dns-parameters-4 */
27
+ type: number;
28
+ /** The number of seconds the answer can be stored in cache before it is considered stale */
29
+ TTL: number;
30
+ /** The value of the DNS record for the given name and type. The data will be in text for standardized record types and in hex for unknown types */
31
+ data: string;
32
+ }
33
+ /**
34
+ * A successful DNS response from Cloudflare's 1.1.1.1 DNS over HTTPS API
35
+ */
36
+ export interface DohSuccessfulResponse {
37
+ /** The Response Code of the DNS Query. Defined here: https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml#dns-parameters-6 */
38
+ Status: number;
39
+ /** True if the truncated bit was set. This happens when the DNS answer is larger than a single UDP or TCP packet */
40
+ TC: boolean;
41
+ /** True if the Recursive Desired bit was set. This is always set to true for Cloudflare DNS over HTTPS */
42
+ RD: boolean;
43
+ /** True if the Recursion Available bit was set. This is always set to true for Cloudflare DNS over HTTPS */
44
+ RA: boolean;
45
+ /** True if every record in the answer was verified with DNSSEC */
46
+ AD: boolean;
47
+ /** True if the client asked to disable DNSSEC validation. In this case, Cloudflare will still fetch the DNSSEC-related records, but it will not attempt to validate the records */
48
+ CD: boolean;
49
+ /** The record name requested */
50
+ Question: Record[];
51
+ /** The answer record */
52
+ Answer?: Record[];
53
+ /** The authority record */
54
+ Authority: Record[];
55
+ /** The additional record */
56
+ Additional: Record[];
57
+ /** List of EDE messages. Refer to Extended DNS error codes for more information */
58
+ Comment?: string[];
59
+ }
60
+ /**
61
+ * An error response from Cloudflare's 1.1.1.1 DNS over HTTPS API
62
+ */
63
+ export interface DohErrorResponse {
64
+ /** An explanation of the error that occurred */
65
+ error: string;
66
+ }
67
+ export declare class DnsHelpers {
68
+ private nameserver_url;
69
+ constructor(nameserver_url: string | URL);
70
+ query(qName: string, qType?: string | number, qDo?: string | number | boolean, qCd?: string | number | boolean, timeout?: number): Promise<DohSuccessfulResponse | DohErrorResponse>;
71
+ private makeGetQuery;
72
+ private sendDohMsg;
73
+ }
74
+ export {};
package/dist/dns.mjs ADDED
@@ -0,0 +1,46 @@
1
+ export class DnsHelpers {
2
+ nameserver_url;
3
+ constructor(nameserver_url) {
4
+ this.nameserver_url = new URL(nameserver_url);
5
+ }
6
+ query(qName, qType = 'A', qDo = false, qCd = false, timeout = 10 * 1000) {
7
+ return new Promise((resolve, reject) => {
8
+ this.sendDohMsg(timeout, this.makeGetQuery(this.nameserver_url, qName, qType, qDo, qCd))
9
+ .then((response) => {
10
+ if (response.ok) {
11
+ response.json().then(resolve).catch(reject);
12
+ }
13
+ else {
14
+ // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
15
+ reject(response.status);
16
+ }
17
+ })
18
+ .catch(reject);
19
+ });
20
+ }
21
+ makeGetQuery(url, qName, qType = 'A', qDo = false, qCd = false) {
22
+ url.searchParams.set('name', qName);
23
+ url.searchParams.set('type', qType.toString());
24
+ url.searchParams.set('do', qDo.toString());
25
+ url.searchParams.set('cd', qCd.toString());
26
+ return url;
27
+ }
28
+ async sendDohMsg(timeout = 10 * 1000, url = this.nameserver_url) {
29
+ const controller = new AbortController();
30
+ const timer = setTimeout(() => controller.abort(), timeout);
31
+ const response = await fetch(url, {
32
+ method: 'GET',
33
+ headers: {
34
+ Accept: 'application/dns-json',
35
+ },
36
+ signal: controller.signal,
37
+ });
38
+ clearTimeout(timer);
39
+ if (response.ok || response.status === 304) {
40
+ return response;
41
+ }
42
+ else {
43
+ throw new Error(`HTTP ${response.status}: ${response.statusText}`);
44
+ }
45
+ }
46
+ }
package/dist/index.d.mts CHANGED
@@ -2,6 +2,7 @@ import type { Chalk } from 'chalk';
2
2
  export * from './buffers.mjs';
3
3
  export * from './crypto.mjs';
4
4
  export * from './discord.mjs';
5
+ export * from './dns.mjs';
5
6
  export * from './net.mjs';
6
7
  export declare class Helpers {
7
8
  /**
package/dist/index.mjs CHANGED
@@ -1,6 +1,7 @@
1
1
  export * from './buffers.mjs';
2
2
  export * from './crypto.mjs';
3
3
  export * from './discord.mjs';
4
+ export * from './dns.mjs';
4
5
  export * from './net.mjs';
5
6
  export class Helpers {
6
7
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chainfuse/helpers",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "",
5
5
  "author": "ChainFuse",
6
6
  "homepage": "https://github.com/ChainFuse/packages/tree/main/packages/helpers#readme",
@@ -51,11 +51,11 @@
51
51
  "@discordjs/rest": "^2.4.2",
52
52
  "chalk": "^5.4.1",
53
53
  "cloudflare": "^3.5.0",
54
- "uuid": "^11.0.3"
54
+ "uuid": "^11.0.4"
55
55
  },
56
56
  "devDependencies": {
57
- "@chainfuse/types": "^1.4.0",
57
+ "@chainfuse/types": "^1.4.1",
58
58
  "@types/node": "^22.10.5"
59
59
  },
60
- "gitHead": "13881adbb875a4b1680448205ff9e0ac55577f72"
60
+ "gitHead": "75406cd04aedccc51d9972a79dfbbd5ce7fe6945"
61
61
  }