UNPKG

cloudflare

Version:

The official TypeScript library for the Cloudflare API

104 lines • 3.74 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Routes = exports.BaseRoutes = 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 BaseRoutes = /* @__PURE__ */ (() => { class BaseRoutes extends resource_1.APIResource { /** * Creates a route that maps a URL pattern to a Worker. * * @example * ```ts * const route = await client.workers.routes.create({ * zone_id: '023e105f4ecef8ad9ca31a8372d0c353', * pattern: 'example.com/*', * }); * ``` */ create(params, options) { const { zone_id, ...body } = params; return this._client.post((0, path_1.path) `/zones/${zone_id}/workers/routes`, { body, ...options })._thenUnwrap((obj) => obj.result); } /** * Replaces the URL pattern or Worker associated with a Worker route. * * @example * ```ts * const route = await client.workers.routes.update( * '023e105f4ecef8ad9ca31a8372d0c353', * { * zone_id: '023e105f4ecef8ad9ca31a8372d0c353', * pattern: 'example.com/*', * }, * ); * ``` */ update(routeID, params, options) { const { zone_id, ...body } = params; return this._client.put((0, path_1.path) `/zones/${zone_id}/workers/routes/${routeID}`, { body, ...options, })._thenUnwrap((obj) => obj.result); } /** * Returns Worker routes for a zone. * * @example * ```ts * // Automatically fetches more pages as needed. * for await (const routeListResponse of client.workers.routes.list( * { zone_id: '023e105f4ecef8ad9ca31a8372d0c353' }, * )) { * // ... * } * ``` */ list(params, options) { const { zone_id } = params; return this._client.getAPIList((0, path_1.path) `/zones/${zone_id}/workers/routes`, (pagination_1.SinglePage), options); } /** * Deletes a Worker route. * * @example * ```ts * const route = await client.workers.routes.delete( * '023e105f4ecef8ad9ca31a8372d0c353', * { zone_id: '023e105f4ecef8ad9ca31a8372d0c353' }, * ); * ``` */ delete(routeID, params, options) { const { zone_id } = params; return this._client.delete((0, path_1.path) `/zones/${zone_id}/workers/routes/${routeID}`, options)._thenUnwrap((obj) => obj.result); } /** * Returns information about a Worker route, including URL pattern and Worker. * * @example * ```ts * const route = await client.workers.routes.get( * '023e105f4ecef8ad9ca31a8372d0c353', * { zone_id: '023e105f4ecef8ad9ca31a8372d0c353' }, * ); * ``` */ get(routeID, params, options) { const { zone_id } = params; return this._client.get((0, path_1.path) `/zones/${zone_id}/workers/routes/${routeID}`, options)._thenUnwrap((obj) => obj.result); } } BaseRoutes._key = Object.freeze([ 'workers', 'routes', ]); return BaseRoutes; })(); exports.BaseRoutes = BaseRoutes; class Routes extends BaseRoutes { } exports.Routes = Routes; //# sourceMappingURL=routes.js.map