cloudflare-client
Version:
Universal HTTP client for Cloudflare API
71 lines (70 loc) • 2.44 kB
JavaScript
/* SPDX-FileCopyrightText: 2022-present Kriasoft */
/* SPDX-License-Identifier: MIT */
import { baseUrl, createFetch, HttpMethod } from "./fetch.js";
// #endregion
/**
* Custom Hostname for a Zone
* @see https://api.cloudflare.com/#custom-hostname-for-a-zone-properties
*/
export function customHostnames(options) {
const { zoneId, ...credentials } = options;
const url = `${baseUrl}/zones/${zoneId}/custom_hostnames`;
return {
/**
* Custom Hostname Details
* @see https://api.cloudflare.com/#custom-hostname-for-a-zone-custom-hostname-details
*/
get: createFetch((id) => ({
method: HttpMethod.GET,
url: `${url}/${id}`,
credentials,
})).response(),
/**
* List Custom Hostnames
* @see https://api.cloudflare.com/#custom-hostname-for-a-zone-list-custom-hostnames
*/
find: createFetch((params) => ({
method: HttpMethod.GET,
url,
searchParams: {
hostname: params?.hostname,
id: params?.id,
ssl: params?.ssl,
page: params?.page,
per_page: params?.perPage,
order: params?.order,
direction: params?.direction,
},
credentials,
})).query(),
/**
* Create Custom Hostname
* @see https://api.cloudflare.com/#custom-hostname-for-a-zone-create-custom-hostname
*/
create: createFetch((params) => ({
method: HttpMethod.POST,
url,
body: JSON.stringify(params),
credentials,
})).response(),
/**
* Edit Custom Hostname
* @see https://api.cloudflare.com/#custom-hostname-for-a-zone-edit-custom-hostname
*/
update: createFetch((id, params) => ({
method: HttpMethod.PATCH,
url: `${url}/${id}`,
body: JSON.stringify(params),
credentials,
})).response(),
/**
* Delete Custom Hostname (and any issued SSL certificates)
* @see https://api.cloudflare.com/#custom-hostname-for-a-zone-delete-custom-hostname-and-any-issued-ssl-certificates-
*/
delete: createFetch((id) => ({
method: HttpMethod.DELETE,
url: `${url}/${id}`,
credentials,
})).response(),
};
}