UNPKG

cloudflare

Version:

The official TypeScript library for the Cloudflare API

181 lines • 8.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.OriginCloudRegions = exports.BaseOriginCloudRegions = void 0; // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. const resource_1 = require("../../core/resource.js"); const pagination_1 = require("../../core/pagination.js"); const path_1 = require("../../internal/utils/path.js"); var BaseOriginCloudRegions = /* @__PURE__ */ (() => { class BaseOriginCloudRegions extends resource_1.APIResource { /** * Creates a new IP-to-cloud-region mapping or replaces the existing mapping for * the specified IP. PUT is idempotent — calling it repeatedly with the same body * produces the same result. The IP path parameter is normalized to canonical form * (RFC 5952 for IPv6) before storage. The vendor and region are validated against * the list from `GET /zones/{zone_id}/origin/cloud_regions/supported_regions`. * Returns 400 if the `origin_ip` in the body does not match the URL path * parameter. Returns 403 (code 1164) when the zone has reached the limit of 3,500 * IP mappings. * * @example * ```ts * const originCloudRegion = * await client.cache.originCloudRegions.update( * '192.0.2.1', * { * zone_id: '023e105f4ecef8ad9ca31a8372d0c353', * origin_ip: '192.0.2.1', * region: 'us-east-1', * vendor: 'aws', * }, * ); * ``` */ update(originIP, params, options) { const { zone_id, ...body } = params; return this._client.put((0, path_1.path) `/zones/${zone_id}/origin/cloud_regions/${originIP}`, { body, ...options, })._thenUnwrap((obj) => obj.result); } /** * Returns all IP-to-cloud-region mappings configured for the zone with pagination * support. Each mapping tells Cloudflare which cloud vendor and region hosts the * origin at that IP, enabling the edge to route via the nearest Tiered Cache * upper-tier co-located with that cloud provider. Returns an empty array when no * mappings exist. * * @example * ```ts * // Automatically fetches more pages as needed. * for await (const originCloudRegionListResponse of client.cache.originCloudRegions.list( * { zone_id: '023e105f4ecef8ad9ca31a8372d0c353' }, * )) { * // ... * } * ``` */ list(params, options) { const { zone_id, ...query } = params; return this._client.getAPIList((0, path_1.path) `/zones/${zone_id}/origin/cloud_regions`, (pagination_1.V4PagePaginationArray), { query, ...options }); } /** * Removes the cloud region mapping for a single origin IP address. The IP path * parameter is normalized before lookup. Returns the deleted IP on success. * Returns 404 if no mapping exists for the specified IP. When the last mapping for * the zone is removed the underlying rule record is also deleted. * * @example * ```ts * const originCloudRegion = * await client.cache.originCloudRegions.delete( * '192.0.2.1', * { zone_id: '023e105f4ecef8ad9ca31a8372d0c353' }, * ); * ``` */ delete(originIP, params, options) { const { zone_id } = params; return this._client.delete((0, path_1.path) `/zones/${zone_id}/origin/cloud_regions/${originIP}`, options)._thenUnwrap((obj) => obj.result); } /** * Removes up to 100 IP-to-cloud-region mappings in a single request. Each IP is * validated independently — successfully deleted items are returned in the * `succeeded` array and IPs that could not be found or are invalid are returned in * the `failed` array. * * @example * ```ts * const response = * await client.cache.originCloudRegions.bulkDelete({ * zone_id: '023e105f4ecef8ad9ca31a8372d0c353', * }); * ``` */ bulkDelete(params, options) { const { zone_id } = params; return this._client.delete((0, path_1.path) `/zones/${zone_id}/origin/cloud_regions/batch`, options)._thenUnwrap((obj) => obj.result); } /** * Upserts up to 100 IP-to-cloud-region mappings in a single request. Items in the * request body are created or replaced; mappings not included in the request body * are preserved unchanged (this is a merge operation, not a full collection * replacement). Each item is validated independently — valid items are applied and * invalid items are returned in the `failed` array. The vendor and region for * every item are validated against the list from * `GET /zones/{zone_id}/origin/cloud_regions/supported_regions`. * * @example * ```ts * const response = * await client.cache.originCloudRegions.bulkUpdate({ * zone_id: '023e105f4ecef8ad9ca31a8372d0c353', * body: [ * { * origin_ip: '192.0.2.1', * region: 'us-east-1', * vendor: 'aws', * }, * { * origin_ip: '2001:db8::1', * region: 'us-central1', * vendor: 'gcp', * }, * ], * }); * ``` */ bulkUpdate(params, options) { const { zone_id, body } = params; return this._client.put((0, path_1.path) `/zones/${zone_id}/origin/cloud_regions/batch`, { body: body, ...options, })._thenUnwrap((obj) => obj.result); } /** * Returns the cloud region mapping for a single origin IP address. The IP path * parameter is normalized before lookup (RFC 5952 for IPv6). Returns 404 if the * zone has no mappings or if the specified IP has no mapping. * * @example * ```ts * const originCloudRegion = * await client.cache.originCloudRegions.get('192.0.2.1', { * zone_id: '023e105f4ecef8ad9ca31a8372d0c353', * }); * ``` */ get(originIP, params, options) { const { zone_id } = params; return this._client.get((0, path_1.path) `/zones/${zone_id}/origin/cloud_regions/${originIP}`, options)._thenUnwrap((obj) => obj.result); } /** * Returns the cloud vendors and regions that are valid values for origin cloud * region mappings. Each region includes the Tiered Cache upper-tier colocation * codes that will be used for cache routing when a mapping targeting that region * is active. Requires the zone to have Tiered Cache enabled. * * @example * ```ts * const response = * await client.cache.originCloudRegions.supportedRegions({ * zone_id: '023e105f4ecef8ad9ca31a8372d0c353', * }); * ``` */ supportedRegions(params, options) { const { zone_id } = params; return this._client.get((0, path_1.path) `/zones/${zone_id}/origin/cloud_regions/supported_regions`, options)._thenUnwrap((obj) => obj.result); } } BaseOriginCloudRegions._key = Object.freeze([ 'cache', 'originCloudRegions', ]); return BaseOriginCloudRegions; })(); exports.BaseOriginCloudRegions = BaseOriginCloudRegions; class OriginCloudRegions extends BaseOriginCloudRegions { } exports.OriginCloudRegions = OriginCloudRegions; //# sourceMappingURL=origin-cloud-regions.js.map