Skip to content

Commit fdd2689

Browse files
committed
feat: update documentation
1 parent c80fe20 commit fdd2689

3 files changed

Lines changed: 150 additions & 3 deletions

File tree

README.md

Lines changed: 95 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,11 @@ After logging in to [Netcup CCP](https://www.customercontrolpanel.de/), navigate
5757

5858
The default exported `NetcupApi` is a wrapper around the actual api. It handles authentication and passes parameters to the implemented api.
5959

60+
#### ESM
61+
6062
```javascript
6163
import NetcupApi from 'netcup-node';
62-
const api = await new Netcup().init({
64+
const api = await new NetcupApi().init({
6365
apikey: 'YOUR_API_KEY',
6466
apipassword: 'YOUR_API_PASSWORD',
6567
customernumber: 'YOUR_CUSTOMER_NUMBER',
@@ -84,3 +86,95 @@ const dnsRecords = await api.infoDnsRecords({
8486
domainname: 'YOUR.DOMAIN',
8587
});
8688
```
89+
90+
#### CJS
91+
92+
```javascript
93+
const NetcupApi = require('netcup-node').default;
94+
// or const { NetcupApi } = require('netcup-node');
95+
96+
const api = await new NetcupApi().init({
97+
apikey: 'YOUR_API_KEY',
98+
apipassword: 'YOUR_API_PASSWORD',
99+
customernumber: 'YOUR_CUSTOMER_NUMBER',
100+
});
101+
const dnsInfo = await api.infoDnsZone({ domainname: 'YOUR.DOMAIN' });
102+
```
103+
104+
### Reference
105+
106+
```javascript
107+
/**
108+
* Initializes authentication parameters
109+
*/
110+
NetcupApi.init({
111+
apikey: 'YOUR_API_KEY',
112+
apipassword: 'YOUR_API_PASSWORD',
113+
customernumber: 'YOUR_CUSTOMER_NUMBER',
114+
});
115+
116+
/**
117+
* Retrieves information about a DNS zone
118+
* */
119+
NetcupApi.infoDnsZone({
120+
domainname: 'YOUR.DOMAIN',
121+
});
122+
123+
/**
124+
* Retrieves information about DNS records of a domain
125+
* */
126+
NetcupApi.infoDnsRecords({
127+
domainname: 'YOUR.DOMAIN',
128+
});
129+
130+
/**
131+
* Updates DNS records of a domain and only those that are specified.
132+
*/
133+
NetcupApi.updateDnsRecords({
134+
domainname: 'example.com',
135+
dnsrecordset: {
136+
dnsrecords: [{ name: 'www', type: 'A', destination: 'some-ip' }],
137+
},
138+
});
139+
// can also be used for deletion
140+
NetcupApi.updateDnsRecords({
141+
domainname: 'example.com',
142+
dnsrecordset: {
143+
dnsrecords: [
144+
{ name: 'www', type: 'A', destination: 'some-ip', deleterecord: true },
145+
],
146+
},
147+
});
148+
149+
/**
150+
* Updates DNS records of a domain with the current public ip.
151+
* @example
152+
* // update ipv4 only
153+
* await api.updateDnsRecordsWithCurrentIp({ domainname: 'example.com', dnsrecords: [{ hostname: 'www' }] })
154+
* @example
155+
* // update ipv4 and ipv6
156+
* await api.updateDnsRecordsWithCurrentIp({ domainname: 'example.com', dnsrecords: [{ hostname: 'www' }], useIpv4AndIpv6: true })
157+
* @example
158+
* // update ipv6 only
159+
* await api.updateDnsRecordsWithCurrentIp({ domainname: 'example.com', dnsrecords: [{ hostname: 'www' }], useIpv6Only: true })
160+
*/
161+
// update ipv4 only
162+
NetcupApi.updateDnsRecordWithCurrentIp({
163+
domainname: 'example.com',
164+
dnsrecordset: { dnsrecords: [{ hostname: 'www' }] },
165+
});
166+
167+
// update ipv4 and ipv6
168+
NetcupApi.updateDnsRecordWithCurrentIp({
169+
domainname: 'example.com',
170+
dnsrecordset: { dnsrecords: [{ hostname: 'www' }] },
171+
useIpv4AndIpv6: true,
172+
});
173+
174+
// update ipv6 only
175+
NetcupApi.updateDnsRecordWithCurrentIp({
176+
domainname: 'example.com',
177+
dnsrecordset: { dnsrecords: [{ hostname: 'www' }] },
178+
useIpv6Only: true,
179+
});
180+
```

src/index.ts

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ class NetcupApi {
4040
}
4141
}
4242

43+
/**
44+
* Initializes authentication parameters
45+
*/
4346
public async init(params: InitParams): Promise<NetcupApi> {
4447
if (params.format && !Object.values(Formats).includes(params.format)) {
4548
throw new Error(INVALID_FORMAT_ERROR);
@@ -53,6 +56,10 @@ class NetcupApi {
5356
return this;
5457
}
5558

59+
/**
60+
* Returns information about the DNS zone of a domain
61+
* @example await api.infoDnsZone({ domainname: 'example.com' })
62+
*/
5663
public async infoDnsZone(
5764
params: Pick<InfoDNSZoneParam, 'domainname'>,
5865
): Promise<InfoDNSZoneResponse> {
@@ -65,6 +72,10 @@ class NetcupApi {
6572
});
6673
}
6774

75+
/**
76+
* Returns information about the DNS records of a domain
77+
* @example await api.infoDnsRecords({ domainname: 'example.com' })
78+
*/
6879
public async infoDnsRecords(
6980
params: Pick<InfoDNSRecordsParam, 'domainname'>,
7081
): Promise<InfoDNSRecordsResponse> {
@@ -77,6 +88,26 @@ class NetcupApi {
7788
});
7889
}
7990

91+
/**
92+
* Updates DNS records of a domain and only those that are specified.
93+
* @example
94+
* await api.updateDnsRecords({
95+
domainname: 'example.com',
96+
dnsrecordset: {
97+
dnsrecords: [{ name: 'www', type: 'A', destination: 'some-ip' }],
98+
},
99+
})
100+
* @example
101+
* // can also be used to delete records
102+
* await api.updateDnsRecords({
103+
domainname: 'example.com',
104+
dnsrecordset: {
105+
dnsrecords: [
106+
{ name: 'www', type: 'A', destination: 'some-ip', deleterecord: true },
107+
],
108+
},
109+
})
110+
*/
80111
public async updateDnsRecords(
81112
params: Pick<UpdateDNSRecordsParam, 'dnsrecordset' | 'domainname'>,
82113
): Promise<UpdateDNSRecordsResponse> {
@@ -89,6 +120,29 @@ class NetcupApi {
89120
});
90121
}
91122

123+
/**
124+
* Updates DNS records of a domain with the current public ip.
125+
* @example
126+
* // update ipv4 only
127+
* await api.updateDnsRecordsWithCurrentIp({
128+
domainname: 'example.com',
129+
dnsrecordset: { dnsrecords: [{ hostname: 'www' }] },
130+
})
131+
* @example
132+
* // update ipv4 and ipv6
133+
* await api.updateDnsRecordsWithCurrentIp({
134+
domainname: 'example.com',
135+
dnsrecordset: { dnsrecords: [{ hostname: 'www' }] },
136+
useIpv4AndIpv6: true,
137+
})
138+
* @example
139+
* // update ipv6 only
140+
* await api.updateDnsRecordsWithCurrentIp({
141+
domainname: 'example.com',
142+
dnsrecordset: { dnsrecords: [{ hostname: 'www' }] },
143+
useIpv6Only: true,
144+
})
145+
*/
92146
public async updateDnsRecordWithCurrentIp(
93147
params: UpdateDnsRecordWithCurrentIpParams,
94148
): Promise<UpdateDNSRecordsResponse> {
@@ -137,8 +191,6 @@ class NetcupApi {
137191
}
138192
}
139193

140-
// EXPORTS
141-
142194
export * from './@types';
143195
export { NetcupRestApi, NetcupApi };
144196

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"declarationDir": "lib/types",
1010
"importHelpers": true,
1111
"alwaysStrict": true,
12+
"removeComments": false,
1213
"forceConsistentCasingInFileNames": true,
1314
"noFallthroughCasesInSwitch": true,
1415
"noImplicitReturns": false,

0 commit comments

Comments
 (0)