Skip to content

Commit 439304e

Browse files
committed
refactor: improve types and annotations
1 parent 217d447 commit 439304e

5 files changed

Lines changed: 96 additions & 28 deletions

File tree

src/@types/NetcupAuth.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
export interface NetcupAuth {
2+
/**
3+
* Your Netcup API key generated from the [customer control panel](https://www.customercontrolpanel.de/daten_aendern.php?sprung=api).
4+
*/
25
apiKey: string;
6+
/**
7+
* The associated password for the API key.
8+
*/
39
apiPassword: string;
10+
/**
11+
* Your customer number.
12+
*/
413
customerNumber: string;
14+
/**
15+
* The API session ID retrieved by a login.
16+
*/
517
apiSessionId: string;
618
}

src/@types/Requests.ts

Lines changed: 57 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,22 @@ export interface AuthParam {
55
apikey: string;
66
apisessionid: string;
77
}
8+
9+
export type WithAuthentication<R> = R & AuthParam;
10+
811
export interface InfoDNSRecordsRequest {
912
action: string;
10-
param: InfoDNSRecordsParam;
13+
param: WithAuthentication<InfoDNSRecordsParam>;
1114
}
1215

13-
export interface InfoDNSRecordsParam extends AuthParam {
14-
domainname: string;
15-
}
1616
export interface InfoDNSZoneRequest {
1717
action: string;
18-
param: InfoDNSZoneParam;
18+
param: WithAuthentication<InfoDNSZoneParam>;
1919
}
2020

21-
export interface InfoDNSZoneParam extends AuthParam {
22-
domainname: string;
21+
export interface UpdateDNSRecordsRequest {
22+
action: string;
23+
param: WithAuthentication<UpdateDNSRecordsParam>;
2324
}
2425

2526
export interface LoginRequest {
@@ -28,26 +29,63 @@ export interface LoginRequest {
2829
}
2930

3031
export interface LoginParam {
32+
/**
33+
* Your Netcup API key generated from the [customer control panel](https://www.customercontrolpanel.de/daten_aendern.php?sprung=api).
34+
*/
3135
apikey: string;
36+
/**
37+
* The associated password for the API key.
38+
*/
3239
apipassword: string;
40+
/**
41+
* Your customer number.
42+
*/
3343
customernumber: string;
3444
}
3545

36-
export interface UpdateDNSRecordsRequest {
37-
action: string;
38-
param: UpdateDNSRecordsParam;
46+
export interface InfoDNSZoneParam {
47+
/**
48+
* The name of the domain to retrieve the zone info from.
49+
* @example "example.com"
50+
*/
51+
domainname: string;
3952
}
4053

41-
export interface UpdateDNSRecordsParam extends AuthParam {
54+
export interface InfoDNSRecordsParam {
55+
/**
56+
* The name of the domain to retrieve the records from.
57+
*/
4258
domainname: string;
59+
}
60+
61+
export interface UpdateDNSRecordsParam {
62+
/**
63+
* The domain name for which the DNS records should be updated.
64+
*/
65+
domainname: string;
66+
/**
67+
* The DNS entries of the domain to update.
68+
*/
4369
dnsrecordset: { dnsrecords: DnsRecord[] };
4470
}
4571

46-
export type UpdateDnsRecordWithCurrentIpParams =
47-
// enforce domainname
48-
Pick<UpdateDNSRecordsParam, 'domainname'> &
49-
// omit id, type, state and desination
50-
Omit<DnsRecord, 'id' | 'type' | 'state' | 'destination'> & {
51-
useIpv6Only?: boolean;
52-
useIpv4AndIpv6?: boolean;
53-
};
72+
export interface UpdateDnsRecordWithCurrentIpParams {
73+
/**
74+
* The domain name for which DNS records with the current IP should be updated.
75+
* @example "example.com"
76+
*/
77+
domainname: UpdateDNSRecordsParam['domainname'];
78+
/**
79+
* The host name of the DNS entry.
80+
* @example "www" - refers to www.example.com
81+
*/
82+
hostname: DnsRecord['hostname'];
83+
/**
84+
* Indicates to update IPv6 (AAAA records) only.
85+
*/
86+
useIpv6Only?: boolean;
87+
/**
88+
* Indicates to update IPv4 (A records) and IPv6 (AAAA records) records.
89+
*/
90+
useIpv4AndIpv6?: boolean;
91+
}

src/@types/Responses.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,27 @@ export interface InfoDNSRecordsResponseData {
5252

5353
export interface DnsRecord {
5454
id?: string;
55+
/**
56+
* The name of the DNS record. If the record is a subdomain, the name is the subdomain name.
57+
* @example "www"
58+
*/
5559
hostname: string;
60+
/**
61+
* The type of the DNS record.
62+
* @example "A"
63+
* @example "AAAA"
64+
*/
5665
type: string;
5766
priority?: string;
67+
/**
68+
* The destination of the DNS record. For A and AAAA records, this is the IP address.
69+
* @example "192.168.178.1"
70+
* @example "2000::1"
71+
*/
5872
destination: string;
73+
/**
74+
* Indicates whether the DNS record should be deleted.
75+
*/
5976
deleterecord?: boolean;
6077
state?: string;
6178
}

src/api.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
LoginRequest,
1111
UpdateDNSRecordsParam,
1212
UpdateDNSRecordsRequest,
13+
WithAuthentication,
1314
} from './@types/Requests';
1415
import {
1516
InfoDNSRecordsResponse,
@@ -62,7 +63,7 @@ export default class NetcupRestApi {
6263
);
6364
}
6465

65-
public infoDnsZone(params: InfoDNSZoneParam) {
66+
public infoDnsZone(params: WithAuthentication<InfoDNSZoneParam>) {
6667
return this.postJson<InfoDNSZoneRequest, InfoDNSZoneResponse>(
6768
getFormattedUrl(this.format),
6869
{
@@ -74,7 +75,7 @@ export default class NetcupRestApi {
7475
);
7576
}
7677

77-
public infoDnsRecords(params: InfoDNSRecordsParam) {
78+
public infoDnsRecords(params: WithAuthentication<InfoDNSRecordsParam>) {
7879
return this.postJson<InfoDNSRecordsRequest, InfoDNSRecordsResponse>(
7980
getFormattedUrl(this.format),
8081
{
@@ -86,7 +87,7 @@ export default class NetcupRestApi {
8687
);
8788
}
8889

89-
public updateDnsRecords(params: UpdateDNSRecordsParam) {
90+
public updateDnsRecords(params: WithAuthentication<UpdateDNSRecordsParam>) {
9091
return this.postJson<UpdateDNSRecordsRequest, UpdateDNSRecordsResponse>(
9192
getFormattedUrl(this.format),
9293
{

src/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class NetcupApi {
6161
* @example await api.infoDnsZone({ domainname: 'example.com' })
6262
*/
6363
public async infoDnsZone(
64-
params: Pick<InfoDNSZoneParam, 'domainname'>,
64+
params: InfoDNSZoneParam,
6565
): Promise<InfoDNSZoneResponse> {
6666
await this.checkAndRefreshAuth();
6767
return this.restApi.infoDnsZone({
@@ -77,7 +77,7 @@ class NetcupApi {
7777
* @example await api.infoDnsRecords({ domainname: 'example.com' })
7878
*/
7979
public async infoDnsRecords(
80-
params: Pick<InfoDNSRecordsParam, 'domainname'>,
80+
params: InfoDNSRecordsParam,
8181
): Promise<InfoDNSRecordsResponse> {
8282
await this.checkAndRefreshAuth();
8383
return this.restApi.infoDnsRecords({
@@ -109,7 +109,7 @@ class NetcupApi {
109109
})
110110
*/
111111
public async updateDnsRecords(
112-
params: Pick<UpdateDNSRecordsParam, 'dnsrecordset' | 'domainname'>,
112+
params: UpdateDNSRecordsParam,
113113
): Promise<UpdateDNSRecordsResponse> {
114114
await this.checkAndRefreshAuth();
115115
return this.restApi.updateDnsRecords({
@@ -126,20 +126,20 @@ class NetcupApi {
126126
* // update ipv4 only
127127
* await api.updateDnsRecordsWithCurrentIp({
128128
domainname: 'example.com',
129-
dnsrecordset: { dnsrecords: [{ hostname: 'www' }] },
129+
hostname: 'www',
130130
})
131131
* @example
132132
* // update ipv4 and ipv6
133133
* await api.updateDnsRecordsWithCurrentIp({
134134
domainname: 'example.com',
135-
dnsrecordset: { dnsrecords: [{ hostname: 'www' }] },
135+
hostname: 'www',
136136
useIpv4AndIpv6: true,
137137
})
138138
* @example
139139
* // update ipv6 only
140140
* await api.updateDnsRecordsWithCurrentIp({
141141
domainname: 'example.com',
142-
dnsrecordset: { dnsrecords: [{ hostname: 'www' }] },
142+
hostname: 'www',
143143
useIpv6Only: true,
144144
})
145145
*/

0 commit comments

Comments
 (0)