cloudflare
Version:
The official TypeScript library for the Cloudflare API
124 lines • 4.78 kB
JavaScript
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
import { APIResource } from "../../core/resource.mjs";
import * as AssetsAPI from "./assets.mjs";
import { Assets, BaseAssets, } from "./assets.mjs";
import { CloudflareError } from "../../core/error.mjs";
import { SinglePage } from "../../core/pagination.mjs";
import { path } from "../../internal/utils/path.mjs";
export var BaseCustomPages = /* @__PURE__ */ (() => {
class BaseCustomPages extends APIResource {
/**
* Updates the configuration for a custom page type.
*
* @example
* ```ts
* const customPage = await client.customPages.update(
* 'ratelimit_block',
* {
* state: 'default',
* url: 'http://www.example.com',
* account_id: 'account_id',
* },
* );
* ```
*/
update(identifier, params, options) {
const { account_id, zone_id, ...body } = params;
if (!account_id && !zone_id) {
throw new CloudflareError('You must provide either account_id or zone_id.');
}
if (account_id && zone_id) {
throw new CloudflareError('You cannot provide both account_id and zone_id.');
}
const { accountOrZone, accountOrZoneId } = account_id ?
{
accountOrZone: 'accounts',
accountOrZoneId: account_id,
}
: {
accountOrZone: 'zones',
accountOrZoneId: zone_id,
};
return this._client.put(path `/${accountOrZone}/${accountOrZoneId}/custom_pages/${identifier}`, {
body,
...options,
})._thenUnwrap((obj) => obj.result);
}
/**
* Lists all custom page configurations for an account or zone.
*
* @example
* ```ts
* // Automatically fetches more pages as needed.
* for await (const customPageListResponse of client.customPages.list(
* { account_id: 'account_id' },
* )) {
* // ...
* }
* ```
*/
list(params = {}, options) {
const { account_id, zone_id } = params ?? {};
if (!account_id && !zone_id) {
throw new CloudflareError('You must provide either account_id or zone_id.');
}
if (account_id && zone_id) {
throw new CloudflareError('You cannot provide both account_id and zone_id.');
}
const { accountOrZone, accountOrZoneId } = account_id ?
{
accountOrZone: 'accounts',
accountOrZoneId: account_id,
}
: {
accountOrZone: 'zones',
accountOrZoneId: zone_id,
};
return this._client.getAPIList(path `/${accountOrZone}/${accountOrZoneId}/custom_pages`, (SinglePage), options);
}
/**
* Returns the configuration for a custom page type.
*
* @example
* ```ts
* const customPage = await client.customPages.get(
* 'ratelimit_block',
* { account_id: 'account_id' },
* );
* ```
*/
get(identifier, params = {}, options) {
const { account_id, zone_id } = params ?? {};
if (!account_id && !zone_id) {
throw new CloudflareError('You must provide either account_id or zone_id.');
}
if (account_id && zone_id) {
throw new CloudflareError('You cannot provide both account_id and zone_id.');
}
const { accountOrZone, accountOrZoneId } = account_id ?
{
accountOrZone: 'accounts',
accountOrZoneId: account_id,
}
: {
accountOrZone: 'zones',
accountOrZoneId: zone_id,
};
return this._client.get(path `/${accountOrZone}/${accountOrZoneId}/custom_pages/${identifier}`, options)._thenUnwrap((obj) => obj.result);
}
}
BaseCustomPages._key = Object.freeze(['customPages']);
return BaseCustomPages;
})();
export var CustomPages = /* @__PURE__ */ (() => {
class CustomPages extends BaseCustomPages {
constructor() {
super(...arguments);
this.assets = new AssetsAPI.Assets(this._client);
}
}
CustomPages.Assets = Assets;
CustomPages.BaseAssets = BaseAssets;
return CustomPages;
})();
//# sourceMappingURL=custom-pages.mjs.map