UNPKG

cloudflare

Version:

The official TypeScript library for the Cloudflare API

130 lines • 5.16 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CustomPages = exports.BaseCustomPages = void 0; const tslib_1 = require("../../internal/tslib.js"); // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. const resource_1 = require("../../core/resource.js"); const AssetsAPI = tslib_1.__importStar(require("./assets.js")); const assets_1 = require("./assets.js"); const error_1 = require("../../core/error.js"); const pagination_1 = require("../../core/pagination.js"); const path_1 = require("../../internal/utils/path.js"); var BaseCustomPages = /* @__PURE__ */ (() => { class BaseCustomPages extends resource_1.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 error_1.CloudflareError('You must provide either account_id or zone_id.'); } if (account_id && zone_id) { throw new error_1.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((0, path_1.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 error_1.CloudflareError('You must provide either account_id or zone_id.'); } if (account_id && zone_id) { throw new error_1.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((0, path_1.path) `/${accountOrZone}/${accountOrZoneId}/custom_pages`, (pagination_1.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 error_1.CloudflareError('You must provide either account_id or zone_id.'); } if (account_id && zone_id) { throw new error_1.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((0, path_1.path) `/${accountOrZone}/${accountOrZoneId}/custom_pages/${identifier}`, options)._thenUnwrap((obj) => obj.result); } } BaseCustomPages._key = Object.freeze(['customPages']); return BaseCustomPages; })(); exports.BaseCustomPages = BaseCustomPages; var CustomPages = /* @__PURE__ */ (() => { class CustomPages extends BaseCustomPages { constructor() { super(...arguments); this.assets = new AssetsAPI.Assets(this._client); } } CustomPages.Assets = assets_1.Assets; CustomPages.BaseAssets = assets_1.BaseAssets; return CustomPages; })(); exports.CustomPages = CustomPages; //# sourceMappingURL=custom-pages.js.map