cloudflare
Version:
The official TypeScript library for the Cloudflare API
297 lines • 12 kB
JavaScript
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
import { APIResource } from "../../core/resource.mjs";
import { SinglePage, V4PagePaginationArray, } from "../../core/pagination.mjs";
import { buildHeaders } from "../../internal/headers.mjs";
import { multipartFormRequestOptions } from "../../internal/uploads.mjs";
import { path } from "../../internal/utils/path.mjs";
export var BaseRecords = /* @__PURE__ */ (() => {
class BaseRecords extends APIResource {
/**
* Create a new DNS record for a zone.
*
* Notes:
*
* - A/AAAA records cannot exist on the same name as CNAME records.
* - NS records cannot exist on the same name as any other record type.
* - Domain names are always represented in Punycode, even if Unicode characters
* were used when creating the record.
*
* @example
* ```ts
* const recordResponse = await client.dns.records.create({
* zone_id: '023e105f4ecef8ad9ca31a8372d0c353',
* name: 'example.com',
* ttl: 3600,
* type: 'A',
* });
* ```
*/
create(params, options) {
const { zone_id, include_shadow_metadata, ...body } = params;
return this._client.post(path `/zones/${zone_id}/dns_records`, {
query: { include_shadow_metadata },
body,
...options,
})._thenUnwrap((obj) => obj.result);
}
/**
* Overwrite an existing DNS record.
*
* Notes:
*
* - A/AAAA records cannot exist on the same name as CNAME records.
* - NS records cannot exist on the same name as any other record type.
* - Domain names are always represented in Punycode, even if Unicode characters
* were used when creating the record.
*
* @example
* ```ts
* const recordResponse = await client.dns.records.update(
* '023e105f4ecef8ad9ca31a8372d0c353',
* {
* zone_id: '023e105f4ecef8ad9ca31a8372d0c353',
* name: 'example.com',
* ttl: 3600,
* type: 'A',
* },
* );
* ```
*/
update(dnsRecordID, params, options) {
const { zone_id, include_shadow_metadata, ...body } = params;
return this._client.put(path `/zones/${zone_id}/dns_records/${dnsRecordID}`, {
query: { include_shadow_metadata },
body,
...options,
})._thenUnwrap((obj) => obj.result);
}
/**
* List, search, sort, and filter a zones' DNS records.
*
* @example
* ```ts
* // Automatically fetches more pages as needed.
* for await (const recordResponse of client.dns.records.list({
* zone_id: '023e105f4ecef8ad9ca31a8372d0c353',
* })) {
* // ...
* }
* ```
*/
list(params, options) {
const { zone_id, ...query } = params;
return this._client.getAPIList(path `/zones/${zone_id}/dns_records`, (V4PagePaginationArray), { query, ...options });
}
/**
* Permanently removes a DNS record from the zone.
*
* @example
* ```ts
* const record = await client.dns.records.delete(
* '023e105f4ecef8ad9ca31a8372d0c353',
* { zone_id: '023e105f4ecef8ad9ca31a8372d0c353' },
* );
* ```
*/
delete(dnsRecordID, params, options) {
const { zone_id } = params;
return this._client.delete(path `/zones/${zone_id}/dns_records/${dnsRecordID}`, options)._thenUnwrap((obj) => obj.result);
}
/**
* Send a Batch of DNS Record API calls to be executed together.
*
* Notes:
*
* - Although Cloudflare will execute the batched operations in a single database
* transaction, Cloudflare's distributed KV store must treat each record change
* as a single key-value pair. This means that the propagation of changes is not
* atomic. See
* [the documentation](https://developers.cloudflare.com/dns/manage-dns-records/how-to/batch-record-changes/ "Batch DNS records")
* for more information.
* - The operations you specify within the /batch request body are always executed
* in the following order:
*
* - Deletes
* - Patches
* - Puts
* - Posts
*
* @example
* ```ts
* const response = await client.dns.records.batch({
* zone_id: '023e105f4ecef8ad9ca31a8372d0c353',
* });
* ```
*/
batch(params, options) {
const { zone_id, include_shadow_metadata, ...body } = params;
return this._client.post(path `/zones/${zone_id}/dns_records/batch`, {
query: { include_shadow_metadata },
body,
...options,
})._thenUnwrap((obj) => obj.result);
}
/**
* Update an existing DNS record.
*
* Notes:
*
* - A/AAAA records cannot exist on the same name as CNAME records.
* - NS records cannot exist on the same name as any other record type.
* - Domain names are always represented in Punycode, even if Unicode characters
* were used when creating the record.
*
* @example
* ```ts
* const recordResponse = await client.dns.records.edit(
* '023e105f4ecef8ad9ca31a8372d0c353',
* {
* zone_id: '023e105f4ecef8ad9ca31a8372d0c353',
* name: 'example.com',
* ttl: 3600,
* type: 'A',
* },
* );
* ```
*/
edit(dnsRecordID, params, options) {
const { zone_id, include_shadow_metadata, ...body } = params;
return this._client.patch(path `/zones/${zone_id}/dns_records/${dnsRecordID}`, {
query: { include_shadow_metadata },
body,
...options,
})._thenUnwrap((obj) => obj.result);
}
/**
* You can export your
* [BIND config](https://en.wikipedia.org/wiki/Zone_file "Zone file") through this
* endpoint.
*
* See
* [the documentation](https://developers.cloudflare.com/dns/manage-dns-records/how-to/import-and-export/ "Import and export records")
* for more information.
*
* @example
* ```ts
* const response = await client.dns.records.export({
* zone_id: '023e105f4ecef8ad9ca31a8372d0c353',
* });
* ```
*/
export(params, options) {
const { zone_id } = params;
return this._client.get(path `/zones/${zone_id}/dns_records/export`, {
...options,
headers: buildHeaders([{ Accept: 'text/plain' }, options?.headers]),
});
}
/**
* Retrieves details for a specific DNS record in the zone.
*
* @example
* ```ts
* const recordResponse = await client.dns.records.get(
* '023e105f4ecef8ad9ca31a8372d0c353',
* { zone_id: '023e105f4ecef8ad9ca31a8372d0c353' },
* );
* ```
*/
get(dnsRecordID, params, options) {
const { zone_id, ...query } = params;
return this._client.get(path `/zones/${zone_id}/dns_records/${dnsRecordID}`, {
query,
...options,
})._thenUnwrap((obj) => obj.result);
}
/**
* You can upload your
* [BIND config](https://en.wikipedia.org/wiki/Zone_file "Zone file") through this
* endpoint. It assumes that cURL is called from a location with bind_config.txt
* (valid BIND config) present.
*
* See
* [the documentation](https://developers.cloudflare.com/dns/manage-dns-records/how-to/import-and-export/ "Import and export records")
* for more information.
*
* @example
* ```ts
* const response = await client.dns.records.import({
* zone_id: '023e105f4ecef8ad9ca31a8372d0c353',
* file: 'www.example.com. 300 IN A 127.0.0.1',
* });
* ```
*/
import(params, options) {
const { zone_id, ...body } = params;
return this._client.post(path `/zones/${zone_id}/dns_records/import`, multipartFormRequestOptions({ body, ...options }, this._client))._thenUnwrap((obj) => obj.result);
}
/**
* Scan for common DNS records on your domain and automatically add them to your
* zone. Useful if you haven't updated your nameservers yet.
*
* @deprecated This endpoint is deprecated in favor of a new asynchronous version. Please use the [/scan/trigger](https://developers.cloudflare.com/api/resources/dns/subresources/records/methods/scan/trigger) and [/scan/review](https://developers.cloudflare.com/api/resources/dns/subresources/records/methods/scan/review) endpoints instead.
*/
scan(params, options) {
const { zone_id } = params;
return this._client.post(path `/zones/${zone_id}/dns_records/scan`, options)._thenUnwrap((obj) => obj.result);
}
/**
* Retrieves the list of DNS records discovered up to this point by the
* asynchronous scan. These records are temporary until explicitly accepted or
* rejected via `POST /scan/review`. Additional records may be discovered by the
* scan later.
*
* @example
* ```ts
* // Automatically fetches more pages as needed.
* for await (const recordResponse of client.dns.records.scanList(
* { zone_id: '023e105f4ecef8ad9ca31a8372d0c353' },
* )) {
* // ...
* }
* ```
*/
scanList(params, options) {
const { zone_id } = params;
return this._client.getAPIList(path `/zones/${zone_id}/dns_records/scan/review`, (SinglePage), options);
}
/**
* Accept or reject DNS records found by the DNS records scan. Accepted records
* will be permanently added to the zone, while rejected records will be
* permanently deleted.
*
* @example
* ```ts
* const response = await client.dns.records.scanReview({
* zone_id: '023e105f4ecef8ad9ca31a8372d0c353',
* });
* ```
*/
scanReview(params, options) {
const { zone_id, ...body } = params;
return this._client.post(path `/zones/${zone_id}/dns_records/scan/review`, { body, ...options })._thenUnwrap((obj) => obj.result);
}
/**
* Initiates an asynchronous scan for common DNS records on your domain. Note that
* this **does not** automatically add records to your zone. The scan runs in the
* background, and results can be reviewed later using the `/scan/review`
* endpoints. Useful if you haven't updated your nameservers yet.
*
* @example
* ```ts
* const response = await client.dns.records.scanTrigger({
* zone_id: '023e105f4ecef8ad9ca31a8372d0c353',
* });
* ```
*/
scanTrigger(params, options) {
const { zone_id } = params;
return this._client.post(path `/zones/${zone_id}/dns_records/scan/trigger`, options);
}
}
BaseRecords._key = Object.freeze(['dns', 'records']);
return BaseRecords;
})();
export class Records extends BaseRecords {
}
//# sourceMappingURL=records.mjs.map