Skip to content

Commit 34539cd

Browse files
committed
API response
1 parent 4757dc4 commit 34539cd

File tree

10 files changed

+196
-3
lines changed

10 files changed

+196
-3
lines changed

src/api/api_request_options.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44
export interface ApiRequestOptions {
55
/** API URL endpoint. */
6-
apiEndpoint : string,
6+
apiEndpoint? : string,
77
/** Token to access the API. */
88
token : string,
99
/** Zone ID to get records from. */

src/api/create_dns_record.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@ export default function createDnsRecord(
77
record : DnsRecord,
88
options : ApiRequestOptions
99
) : void {
10+
const {token, zoneId} = options;
11+
12+
const apiEndpoint = options.apiEndpoint ?? 'https://api.cloudflare.com/client/v4/'
13+
1014
fetch(
11-
`${options.apiEndpoint}zones/${options.zoneId}/dns_records`,
15+
`${apiEndpoint}zones/${zoneId}/dns_records`,
1216
{
1317
method: 'POST',
1418
headers: {
1519
'Content-Type': 'application/json',
16-
'Authorization': `Bearer ${options.token}`
20+
'Authorization': `Bearer ${token}`
1721
},
1822
body: JSON.stringify(record)
1923
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// deno-lint-ignore-file camelcase
2+
import type { Errors } from '../errors.ts';
3+
import type { Messages } from '../messages.ts';
4+
import type { ResultInfo } from '../result_info.ts';
5+
import type { ARecord } from './records/a_record.ts';
6+
import type { AAAARecord } from './records/aaaa_record.ts';
7+
import type { CNAMERecord } from './records/cname_record.ts';
8+
9+
/**
10+
* This interface represents the response of a DNS record that got created.
11+
*/
12+
export interface CreateNdsRecordResponse {
13+
result : (
14+
| ARecord
15+
| AAAARecord
16+
| CNAMERecord
17+
)[],
18+
errors : Errors[],
19+
messages : Messages[],
20+
success : boolean,
21+
result_info? : ResultInfo
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// deno-lint-ignore-file camelcase
2+
import type { Errors } from '../errors.ts';
3+
import type { Messages } from '../messages.ts';
4+
import type { ResultInfo } from '../result_info.ts';
5+
import type { ARecord } from './records/a_record.ts';
6+
import type { AAAARecord } from './records/aaaa_record.ts';
7+
import type { CNAMERecord } from './records/cname_record.ts';
8+
9+
/**
10+
* This interface represents the response of a DNS record list.
11+
*/
12+
export interface ListDnsRecordsResponse {
13+
result : (
14+
| ARecord
15+
| AAAARecord
16+
| CNAMERecord
17+
)[],
18+
errors : Errors[],
19+
messages : Messages[],
20+
success : boolean,
21+
result_info? : ResultInfo
22+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// deno-lint-ignore-file camelcase
2+
3+
/**
4+
* This interface represents an A record.
5+
*/
6+
export interface ARecord {
7+
/** When the record comment was last modified. Omitted if there is no comment. */
8+
comment_modified_on : string,
9+
/** When the record was created. */
10+
created_on : string,
11+
/** Identifier */
12+
id : string,
13+
/** Extra Cloudflare-specific information about the record. */
14+
meta : Record<string, unknown>,
15+
/** When the record was last modified. */
16+
modified_on : string,
17+
/** Whether the record can be proxied by Cloudflare or not. */
18+
proxiable : boolean,
19+
/** When the record tags were last modified. Omitted if there are no tags. */
20+
tags_modified_on? : string,
21+
/** Comments or notes about the DNS record. This field has no effect on DNS responses. */
22+
comment : string,
23+
/** DNS record name (or @ for the zone apex) in Punycode. */
24+
name : string,
25+
/* Whether the record is receiving the performance and security benefits of Cloudflare. */
26+
proxied : boolean,
27+
/** Settings for the DNS record. */
28+
settings : Record<string, unknown>,
29+
/** Custom tags for the DNS record. This field has no effect on DNS responses. */
30+
tags : string[],
31+
/** Time To Live (TTL) of the DNS record in seconds. Setting to 1 means 'automatic'. Value must be between 60 and 86400, with the minimum reduced to 30 for Enterprise zones. */
32+
ttl : number,
33+
/** A valid IPv4 address. */
34+
content : string,
35+
/** Record type. */
36+
type : 'A'
37+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// deno-lint-ignore-file camelcase
2+
3+
/**
4+
* This interface represents an AAAA record.
5+
*/
6+
export interface AAAARecord {
7+
/** When the record comment was last modified. Omitted if there is no comment. */
8+
comment_modified_on : string,
9+
/** When the record was created. */
10+
created_on : string,
11+
/** Identifier */
12+
id : string,
13+
/** Extra Cloudflare-specific information about the record. */
14+
meta : Record<string, unknown>,
15+
/** When the record was last modified. */
16+
modified_on : string,
17+
/** Whether the record can be proxied by Cloudflare or not. */
18+
proxiable : boolean,
19+
/** When the record tags were last modified. Omitted if there are no tags. */
20+
tags_modified_on? : string,
21+
/** Comments or notes about the DNS record. This field has no effect on DNS responses. */
22+
comment : string,
23+
/** DNS record name (or @ for the zone apex) in Punycode. */
24+
name : string,
25+
/* Whether the record is receiving the performance and security benefits of Cloudflare. */
26+
proxied : boolean,
27+
/** Settings for the DNS record. */
28+
settings : Record<string, unknown>,
29+
/** Custom tags for the DNS record. This field has no effect on DNS responses. */
30+
tags : string[],
31+
/** Time To Live (TTL) of the DNS record in seconds. Setting to 1 means 'automatic'. Value must be between 60 and 86400, with the minimum reduced to 30 for Enterprise zones. */
32+
ttl : number,
33+
/** A valid IPv6 address. */
34+
content : string,
35+
/** Record type. */
36+
type : 'AAAA'
37+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// deno-lint-ignore-file camelcase
2+
3+
/**
4+
* This interface represents a CNAME record.
5+
*/
6+
export interface CNAMERecord {
7+
/** When the record comment was last modified. Omitted if there is no comment. */
8+
comment_modified_on : string,
9+
/** When the record was created. */
10+
created_on : string,
11+
/** Identifier */
12+
id : string,
13+
/** Extra Cloudflare-specific information about the record. */
14+
meta : Record<string, unknown>,
15+
/** When the record was last modified. */
16+
modified_on : string,
17+
/** Whether the record can be proxied by Cloudflare or not. */
18+
proxiable : boolean,
19+
/** When the record tags were last modified. Omitted if there are no tags. */
20+
tags_modified_on? : string,
21+
/** Comments or notes about the DNS record. This field has no effect on DNS responses. */
22+
comment : string,
23+
/** DNS record name (or @ for the zone apex) in Punycode. */
24+
name : string,
25+
/* Whether the record is receiving the performance and security benefits of Cloudflare. */
26+
proxied : boolean,
27+
/** Settings for the DNS record. */
28+
settings :
29+
| Record<string, unknown>
30+
| {
31+
/** If enabled, causes the CNAME record to be resolved externally and the resulting address records (e.g., A and AAAA) to be returned instead of the CNAME record itself. This setting has no effect on proxied records, which are always flattened. */
32+
flatten_cname : boolean
33+
},
34+
/** Custom tags for the DNS record. This field has no effect on DNS responses. */
35+
tags : string[],
36+
/** Time To Live (TTL) of the DNS record in seconds. Setting to 1 means 'automatic'. Value must be between 60 and 86400, with the minimum reduced to 30 for Enterprise zones. */
37+
ttl : number,
38+
/** A valid IPv6 address. */
39+
content : string,
40+
/** Record type. */
41+
type : 'CNAME'
42+
}

src/api/response/errors.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* This interface represents an error for the response.
3+
*/
4+
export interface Errors {
5+
code : number,
6+
message : string
7+
}

src/api/response/messages.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* This interface represents a message for the response.
3+
*/
4+
export interface Messages {
5+
code : number,
6+
message : string
7+
}

src/api/response/result_info.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// deno-lint-ignore-file camelcase
2+
3+
/**
4+
* This interface represents the information about the result.
5+
*/
6+
export interface ResultInfo {
7+
/** Total number of results for the requested service */
8+
count : number,
9+
/** Current page within paginated list of results */
10+
page : number,
11+
/** Number of results per page of results */
12+
per_page : number,
13+
/** Total results available without any search parameters */
14+
total_count : number
15+
}

0 commit comments

Comments
 (0)