UNPKG

cloudflare

Version:

The official TypeScript library for the Cloudflare API

111 lines • 4.79 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ServiceBindings = exports.BaseServiceBindings = 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 BaseServiceBindings = /* @__PURE__ */ (() => { class BaseServiceBindings extends resource_1.APIResource { /** * Creates a new Service Binding, routing traffic to IPs within the given CIDR to a * service running on Cloudflare's network. **NOTE:** The first Service Binding * created for an IP Prefix must exactly match the IP Prefix's CIDR. Subsequent * Service Bindings may be created with a more-specific CIDR. Refer to the * [Service Bindings Documentation](https://developers.cloudflare.com/byoip/service-bindings/) * for compatibility details. * * @example * ```ts * const serviceBinding = * await client.addressing.prefixes.serviceBindings.create( * '2af39739cc4e3b5910c918468bb89828', * { * account_id: '258def64c72dae45f3e4c8516e2111f2', * cidr: '192.0.2.0/24', * service_id: '2db684ee7ca04e159946fd05b99e1bcd', * }, * ); * ``` */ create(prefixID, params, options) { const { account_id, ...body } = params; return this._client.post((0, path_1.path) `/accounts/${account_id}/addressing/prefixes/${prefixID}/bindings`, { body, ...options, })._thenUnwrap((obj) => obj.result); } /** * List the Cloudflare services this prefix is currently bound to. Traffic sent to * an address within an IP prefix will be routed to the Cloudflare service of the * most-specific Service Binding matching the address. **Example:** binding * `192.0.2.0/24` to Cloudflare Magic Transit and `192.0.2.1/32` to the Cloudflare * CDN would route traffic for `192.0.2.1` to the CDN, and traffic for all other * IPs in the prefix to Cloudflare Magic Transit. * * @example * ```ts * // Automatically fetches more pages as needed. * for await (const serviceBinding of client.addressing.prefixes.serviceBindings.list( * '2af39739cc4e3b5910c918468bb89828', * { account_id: '258def64c72dae45f3e4c8516e2111f2' }, * )) { * // ... * } * ``` */ list(prefixID, params, options) { const { account_id } = params; return this._client.getAPIList((0, path_1.path) `/accounts/${account_id}/addressing/prefixes/${prefixID}/bindings`, (pagination_1.SinglePage), options); } /** * Delete a Service Binding * * @example * ```ts * const serviceBinding = * await client.addressing.prefixes.serviceBindings.delete( * '0429b49b6a5155297b78e75a44b09e14', * { * account_id: '258def64c72dae45f3e4c8516e2111f2', * prefix_id: '2af39739cc4e3b5910c918468bb89828', * }, * ); * ``` */ delete(bindingID, params, options) { const { account_id, prefix_id } = params; return this._client.delete((0, path_1.path) `/accounts/${account_id}/addressing/prefixes/${prefix_id}/bindings/${bindingID}`, options); } /** * Fetch a single Service Binding * * @example * ```ts * const serviceBinding = * await client.addressing.prefixes.serviceBindings.get( * '0429b49b6a5155297b78e75a44b09e14', * { * account_id: '258def64c72dae45f3e4c8516e2111f2', * prefix_id: '2af39739cc4e3b5910c918468bb89828', * }, * ); * ``` */ get(bindingID, params, options) { const { account_id, prefix_id } = params; return this._client.get((0, path_1.path) `/accounts/${account_id}/addressing/prefixes/${prefix_id}/bindings/${bindingID}`, options)._thenUnwrap((obj) => obj.result); } } BaseServiceBindings._key = Object.freeze([ 'addressing', 'prefixes', 'serviceBindings', ]); return BaseServiceBindings; })(); exports.BaseServiceBindings = BaseServiceBindings; class ServiceBindings extends BaseServiceBindings { } exports.ServiceBindings = ServiceBindings; //# sourceMappingURL=service-bindings.js.map