// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. import { APIResource } from '../../../core/resource'; import { APIPromise } from '../../../core/api-promise'; import { CursorPagination, type CursorPaginationParams, PagePromise } from '../../../core/pagination'; import { RequestOptions } from '../../../internal/request-options'; import { path } from '../../../internal/utils/path'; export class BasePrefixBindings extends APIResource { static override readonly _key: readonly ['dls', 'regionalServices', 'prefixBindings'] = Object.freeze([ 'dls', 'regionalServices', 'prefixBindings', ] as const); /** * Bind a CIDR from a BYOIP prefix to a region. * * This requires the **IP Prefixes Write** permission in addition to **DLS Write**, * because the binding is created against a BYOIP prefix in Addressing. * * @example * ```ts * const prefixBinding = * await client.dls.regionalServices.prefixBindings.create({ * account_id: '023e105f4ecef8ad9ca31a8372d0c353', * cidr: '10.0.1.0/24', * prefix_id: 'a1b2c3d4-e5f6-7890-abcd-ef1234567890', * region_key: 'eu', * }); * ``` */ create( params: PrefixBindingCreateParams, options?: RequestOptions, ): APIPromise { const { account_id, ...body } = params; return ( this._client.post(path`/accounts/${account_id}/dls/regional_services/prefix_bindings`, { body, ...options, }) as APIPromise<{ result: PrefixBindingCreateResponse }> )._thenUnwrap((obj) => obj.result); } /** * List the BYOIP prefix bindings configured for an account. * * @example * ```ts * // Automatically fetches more pages as needed. * for await (const prefixBindingListResponse of client.dls.regionalServices.prefixBindings.list( * { account_id: '023e105f4ecef8ad9ca31a8372d0c353' }, * )) { * // ... * } * ``` */ list( params: PrefixBindingListParams, options?: RequestOptions, ): PagePromise { const { account_id, ...query } = params; return this._client.getAPIList( path`/accounts/${account_id}/dls/regional_services/prefix_bindings`, CursorPagination, { query, ...options }, ); } /** * Delete a BYOIP prefix binding. * * Like creating a binding, this requires **IP Prefixes Write** in addition to * **DLS Write**. * * @example * ```ts * const prefixBinding = * await client.dls.regionalServices.prefixBindings.delete( * 'a1b2c3d4-e5f6-7890-abcd-ef1234567890', * { account_id: '023e105f4ecef8ad9ca31a8372d0c353' }, * ); * ``` */ delete( bindingID: string, params: PrefixBindingDeleteParams, options?: RequestOptions, ): APIPromise { const { account_id } = params; return this._client.delete( path`/accounts/${account_id}/dls/regional_services/prefix_bindings/${bindingID}`, options, ); } /** * Update the region of an existing BYOIP prefix binding. * * Like creating a binding, this requires **IP Prefixes Write** in addition to * **DLS Write**. * * @example * ```ts * const response = * await client.dls.regionalServices.prefixBindings.edit( * 'a1b2c3d4-e5f6-7890-abcd-ef1234567890', * { * account_id: '023e105f4ecef8ad9ca31a8372d0c353', * region_key: 'eu', * }, * ); * ``` */ edit( bindingID: string, params: PrefixBindingEditParams, options?: RequestOptions, ): APIPromise { const { account_id, ...body } = params; return ( this._client.patch(path`/accounts/${account_id}/dls/regional_services/prefix_bindings/${bindingID}`, { body, ...options, }) as APIPromise<{ result: PrefixBindingEditResponse }> )._thenUnwrap((obj) => obj.result); } /** * Retrieve a single BYOIP prefix binding by ID. * * @example * ```ts * const prefixBinding = * await client.dls.regionalServices.prefixBindings.get( * 'a1b2c3d4-e5f6-7890-abcd-ef1234567890', * { account_id: '023e105f4ecef8ad9ca31a8372d0c353' }, * ); * ``` */ get( bindingID: string, params: PrefixBindingGetParams, options?: RequestOptions, ): APIPromise { const { account_id } = params; return ( this._client.get( path`/accounts/${account_id}/dls/regional_services/prefix_bindings/${bindingID}`, options, ) as APIPromise<{ result: PrefixBindingGetResponse }> )._thenUnwrap((obj) => obj.result); } } export class PrefixBindings extends BasePrefixBindings {} export type PrefixBindingListResponsesCursorPagination = CursorPagination; export interface PrefixBindingCreateResponse { /** * The ID of the binding. */ id: string; /** * The CIDR that is bound. */ cidr: string; /** * The ID of the parent prefix. */ prefix_id: string; /** * The region key used for the binding. */ region_key: string; } export interface PrefixBindingListResponse { /** * The ID of the binding. */ id: string; /** * The CIDR that is bound. */ cidr: string; /** * The ID of the parent prefix. */ prefix_id: string; /** * The region key used for the binding. */ region_key: string; } export interface PrefixBindingDeleteResponse { messages: Array; success: boolean; errors?: Array; } export namespace PrefixBindingDeleteResponse { export interface Message { code: number; message: string; /** * Optional upstream error context for APIv4 errors that wrap downstream service * failures. */ error_chain?: Array; } export interface Error { code: number; message: string; /** * Optional upstream error context for APIv4 errors that wrap downstream service * failures. */ error_chain?: Array; } } export interface PrefixBindingEditResponse { /** * The ID of the binding. */ id: string; /** * The CIDR that is bound. */ cidr: string; /** * The ID of the parent prefix. */ prefix_id: string; /** * The region key used for the binding. */ region_key: string; } export interface PrefixBindingGetResponse { /** * The ID of the binding. */ id: string; /** * The CIDR that is bound. */ cidr: string; /** * The ID of the parent prefix. */ prefix_id: string; /** * The region key used for the binding. */ region_key: string; } export interface PrefixBindingCreateParams { /** * Path param: Identifier of a Cloudflare account. */ account_id: string; /** * Body param: IP prefix in CIDR notation to bind. */ cidr: string; /** * Body param: The ID of the parent IP prefix that contains the CIDR. */ prefix_id: string; /** * Body param: Region key from managed regions (e.g., "us", "eu"). */ region_key: string; } export interface PrefixBindingListParams extends CursorPaginationParams { /** * Path param: Identifier of a Cloudflare account. */ account_id: string; } export interface PrefixBindingDeleteParams { /** * Identifier of a Cloudflare account. */ account_id: string; } export interface PrefixBindingEditParams { /** * Path param: Identifier of a Cloudflare account. */ account_id: string; /** * Body param: New region key to assign (e.g., "us", "eu", "cfcanary"). */ region_key: string; } export interface PrefixBindingGetParams { /** * Identifier of a Cloudflare account. */ account_id: string; } export declare namespace PrefixBindings { export { type PrefixBindingCreateResponse as PrefixBindingCreateResponse, type PrefixBindingListResponse as PrefixBindingListResponse, type PrefixBindingDeleteResponse as PrefixBindingDeleteResponse, type PrefixBindingEditResponse as PrefixBindingEditResponse, type PrefixBindingGetResponse as PrefixBindingGetResponse, type PrefixBindingListResponsesCursorPagination as PrefixBindingListResponsesCursorPagination, type PrefixBindingCreateParams as PrefixBindingCreateParams, type PrefixBindingListParams as PrefixBindingListParams, type PrefixBindingDeleteParams as PrefixBindingDeleteParams, type PrefixBindingEditParams as PrefixBindingEditParams, type PrefixBindingGetParams as PrefixBindingGetParams, }; }