cloudflare-client
Version:
Universal HTTP client for Cloudflare API
83 lines (82 loc) • 2.71 kB
JavaScript
/* SPDX-FileCopyrightText: 2022-present Kriasoft */
/* SPDX-License-Identifier: MIT */
import { baseUrl, createFetch, HttpMethod } from "./fetch.js";
// #endregion
/**
* DNS Records for Zone
* @see https://api.cloudflare.com/#dns-records-for-a-zone-properties
*/
export function dnsRecords(options) {
const { zoneId, ...credentials } = options;
const url = `${baseUrl}/zones/${zoneId}/dns_records`;
return {
/**
* DNS Record Details
* @see https://api.cloudflare.com/#dns-records-for-a-zone-dns-record-details
*/
get: createFetch((id) => ({
method: HttpMethod.GET,
url: `${url}/${id}`,
credentials,
})).response(),
/**
* List DNS Records
* @see https://api.cloudflare.com/#dns-records-for-a-zone-list-dns-records
*/
find: createFetch((params) => ({
method: HttpMethod.GET,
url,
searchParams: {
match: params?.match,
name: params?.name,
order: params?.order,
page: params?.page,
per_page: params?.perPage,
content: params?.content,
type: params?.type,
proxied: params?.proxied,
direction: params?.direction,
},
credentials,
})).query(),
/**
* Create DNS Record
* @see https://api.cloudflare.com/#dns-records-for-a-zone-create-dns-record
*/
create: createFetch((input) => ({
method: HttpMethod.POST,
url,
body: JSON.stringify(input),
credentials,
})).response(),
/**
* Replace DNS Record
* @see https://api.cloudflare.com/#dns-records-for-a-zone-update-dns-record
*/
replace: createFetch((id, input) => ({
method: HttpMethod.PUT,
url: `${url}/${id}`,
body: JSON.stringify(input),
credentials,
})).response(),
/**
* Update DNS Record
* @see https://api.cloudflare.com/#dns-records-for-a-zone-patch-dns-record
*/
update: createFetch((id, input) => ({
method: HttpMethod.PATCH,
url: `${url}/${id}`,
body: JSON.stringify(input),
credentials,
})).response(),
/**
* Delete DNS Record
* @see https://api.cloudflare.com/#dns-records-for-a-zone-delete-dns-record
*/
delete: createFetch((id) => ({
method: HttpMethod.DELETE,
url: `${url}/${id}`,
credentials,
})).response(),
};
}