@bunny.net/scriptable-dns-types 0.1.1
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 +38 -0
- package/index.d.ts +152 -0
- package/package.json +24 -0
package/README.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# @bunny.net/scriptable-dns-types
|
|
2
|
+
|
|
3
|
+
Ambient TypeScript types for the [bunny.net Scriptable DNS](https://docs.bunny.net/docs/dns-scripting) runtime.
|
|
4
|
+
|
|
5
|
+
Scriptable DNS scripts run with a set of globals injected by the runtime (`ARecord`, `Monitoring`, `RoutingEngine`, and so on). Because the runtime does not support `import`, these are provided as ambient declarations: they power editor autocomplete and an optional typecheck step, but are never imported at runtime.
|
|
6
|
+
|
|
7
|
+
## Usage
|
|
8
|
+
|
|
9
|
+
Add the package as a dev dependency, then reference it from your script or your `tsconfig.json`.
|
|
10
|
+
|
|
11
|
+
Reference from the script file:
|
|
12
|
+
|
|
13
|
+
```js
|
|
14
|
+
/// <reference types="@bunny.net/scriptable-dns-types" />
|
|
15
|
+
|
|
16
|
+
/** @param {DnsRequest} query */
|
|
17
|
+
export default function handleQuery(query) {
|
|
18
|
+
if (query.request.geoLocation.country === "DE") {
|
|
19
|
+
return new ARecord("203.0.113.20", 30);
|
|
20
|
+
}
|
|
21
|
+
return new ARecord("203.0.113.10", 30);
|
|
22
|
+
}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Or wire it up globally in `tsconfig.json`:
|
|
26
|
+
|
|
27
|
+
```jsonc
|
|
28
|
+
{
|
|
29
|
+
"compilerOptions": {
|
|
30
|
+
"allowJs": true,
|
|
31
|
+
"checkJs": true,
|
|
32
|
+
"noEmit": true,
|
|
33
|
+
"types": ["@bunny.net/scriptable-dns-types"],
|
|
34
|
+
},
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
The CLI scaffolds all of this for you with `bunny dns scripts init`.
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
// Ambient declarations for the bunny.net Scriptable DNS runtime. The runtime injects these as globals; scripts use them without importing.
|
|
2
|
+
|
|
3
|
+
/** The DNS request passed to the `handleQuery` entry function. */
|
|
4
|
+
interface DnsRequest {
|
|
5
|
+
/** The DNS query that contains the details about the request. */
|
|
6
|
+
request: DnsQuery;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/** The details of an incoming DNS query. */
|
|
10
|
+
interface DnsQuery {
|
|
11
|
+
/** The hostname that is being queried. */
|
|
12
|
+
hostname: string;
|
|
13
|
+
/** The IP of the remote client that sent the DNS query. */
|
|
14
|
+
clientIP: string;
|
|
15
|
+
/** The query question type (A, AAAA, TXT). */
|
|
16
|
+
queryType: string;
|
|
17
|
+
/** The EDNS0 IP attached by the client. */
|
|
18
|
+
ednsIP: string;
|
|
19
|
+
/** The geo location of the client. */
|
|
20
|
+
geoLocation: GeoLocation;
|
|
21
|
+
/** The server zone of the DNS server that received the query (DE, UK, SG). */
|
|
22
|
+
serverZone: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** A geographic location resolved for a client or an IP. */
|
|
26
|
+
interface GeoLocation {
|
|
27
|
+
/** The latitude of the location. */
|
|
28
|
+
latitude: number;
|
|
29
|
+
/** The longitude of the location. */
|
|
30
|
+
longitude: number;
|
|
31
|
+
/** The two letter ISO country code. */
|
|
32
|
+
country: string;
|
|
33
|
+
/** The detected ASN number. */
|
|
34
|
+
asn: number;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** An A record answer. */
|
|
38
|
+
declare class ARecord {
|
|
39
|
+
constructor(ip: string, ttl?: number);
|
|
40
|
+
/** The IP of the A record. */
|
|
41
|
+
ip: string;
|
|
42
|
+
/** The TTL of the answer. */
|
|
43
|
+
ttl: number;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** An AAAA record answer. */
|
|
47
|
+
declare class AaaaRecord {
|
|
48
|
+
constructor(ip: string, ttl?: number);
|
|
49
|
+
/** The IP of the AAAA record. */
|
|
50
|
+
ip: string;
|
|
51
|
+
/** The TTL of the answer. */
|
|
52
|
+
ttl: number;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** A CNAME record answer. */
|
|
56
|
+
declare class CnameRecord {
|
|
57
|
+
constructor(hostname: string, ttl?: number);
|
|
58
|
+
/** The hostname of the CNAME record. */
|
|
59
|
+
hostname: string;
|
|
60
|
+
/** The TTL of the answer. */
|
|
61
|
+
ttl: number;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** A TXT record answer. */
|
|
65
|
+
declare class TxtRecord {
|
|
66
|
+
constructor(value: string, ttl?: number);
|
|
67
|
+
/** The value of the TXT record. */
|
|
68
|
+
value: string;
|
|
69
|
+
/** The TTL of the answer. */
|
|
70
|
+
ttl: number;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Maps the response to a pull zone, resolving to its A or AAAA records. */
|
|
74
|
+
declare class PullZoneRecord {
|
|
75
|
+
constructor(pullzone: string);
|
|
76
|
+
/** The name of the pull zone. */
|
|
77
|
+
pullzone: string;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** A server passed to or returned from the routing helpers. */
|
|
81
|
+
declare class Server {
|
|
82
|
+
constructor(
|
|
83
|
+
ip: string,
|
|
84
|
+
latitude?: number,
|
|
85
|
+
longitude?: number,
|
|
86
|
+
weight?: number,
|
|
87
|
+
online?: boolean,
|
|
88
|
+
);
|
|
89
|
+
/** The IP of the server. */
|
|
90
|
+
ip: string;
|
|
91
|
+
/** The geographical latitude of the server. */
|
|
92
|
+
latitude: number;
|
|
93
|
+
/** The geographical longitude of the server. */
|
|
94
|
+
longitude: number;
|
|
95
|
+
/** The routing weight of the server in a weighted routing scenario. */
|
|
96
|
+
weight: number;
|
|
97
|
+
/** Whether the server is currently considered online for health routing. */
|
|
98
|
+
online: boolean;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** The uptime status returned by `Monitoring.getStatus`. */
|
|
102
|
+
interface MonitoringStatus {
|
|
103
|
+
/** Whether the IP is currently online. */
|
|
104
|
+
isOnline: boolean;
|
|
105
|
+
/** The last measured latency from the DNS server to this IP. */
|
|
106
|
+
latency: number;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** Checks and monitors the uptime status of an IP in the background. */
|
|
110
|
+
declare const Monitoring: {
|
|
111
|
+
getStatus(ip: string): MonitoringStatus;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
/** Looks up the geo location of an IP address using a GeoDNS database. */
|
|
115
|
+
declare const GeoDatabase: {
|
|
116
|
+
resolve(ip: string): GeoLocation;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
/** Calculates the distance between two geographical points. */
|
|
120
|
+
declare const GeoDistance: {
|
|
121
|
+
calculate(lat1: number, lon1: number, lat2: number, lon2: number): number;
|
|
122
|
+
calculate(loc1: GeoLocation, loc2: GeoLocation): number;
|
|
123
|
+
calculate(server: Server, location: GeoLocation): number;
|
|
124
|
+
calculate(location: GeoLocation, server: Server): number;
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
/** Dynamic geographic routing, weight calculation, and round robin logic. */
|
|
128
|
+
declare const RoutingEngine: {
|
|
129
|
+
getWeightedRandom(
|
|
130
|
+
servers: Server[],
|
|
131
|
+
onlineOnly?: boolean,
|
|
132
|
+
applyWeight?: boolean,
|
|
133
|
+
): Server;
|
|
134
|
+
getClosestServer(
|
|
135
|
+
servers: Server[],
|
|
136
|
+
location: GeoLocation,
|
|
137
|
+
onlineOnly?: boolean,
|
|
138
|
+
applyWeight?: boolean,
|
|
139
|
+
): Server;
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
/** A single response object the `handleQuery` entry function may return. */
|
|
143
|
+
type DnsResponse =
|
|
144
|
+
| ARecord
|
|
145
|
+
| AaaaRecord
|
|
146
|
+
| CnameRecord
|
|
147
|
+
| TxtRecord
|
|
148
|
+
| PullZoneRecord
|
|
149
|
+
| Server;
|
|
150
|
+
|
|
151
|
+
/** Any value the `handleQuery` entry function may return: one response or many. */
|
|
152
|
+
type DnsAnswer = DnsResponse | DnsResponse[];
|
package/package.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@bunny.net/scriptable-dns-types",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Ambient TypeScript types for the bunny.net Scriptable DNS runtime.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"types": "index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./index.d.ts"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"index.d.ts"
|
|
14
|
+
],
|
|
15
|
+
"keywords": [
|
|
16
|
+
"bunny",
|
|
17
|
+
"dns",
|
|
18
|
+
"scriptable-dns",
|
|
19
|
+
"types"
|
|
20
|
+
],
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "public"
|
|
23
|
+
}
|
|
24
|
+
}
|