UNPKG

cloudflare

Version:

The official TypeScript library for the Cloudflare API

220 lines • 8.27 kB
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. import { APIResource } from "../../core/resource.mjs"; import { path } from "../../internal/utils/path.mjs"; export var BaseDynamicRouting = /* @__PURE__ */ (() => { class BaseDynamicRouting extends APIResource { /** * Creates a dynamic route on an AI Gateway from the specified routing elements. * Clients call the route by using `dynamic/{name}` as the model name. * * @example * ```ts * const dynamicRouting = * await client.aiGateway.dynamicRouting.create('54442216', { * account_id: '0d37909e38d3e99c29fa2cd343ac421a', * elements: [ * { * id: 'id', * outputs: { next: { elementId: 'elementId' } }, * type: 'start', * }, * ], * name: 'x', * }); * ``` */ create(gatewayID, params, options) { const { account_id, ...body } = params; return this._client.post(path `/accounts/${account_id}/ai-gateway/gateways/${gatewayID}/routes`, { body, ...options, })._thenUnwrap((obj) => obj.result); } /** * Updates the name of a dynamic route. To change routing behaviour, create and * deploy a new version. * * @example * ```ts * const dynamicRouting = * await client.aiGateway.dynamicRouting.update('54442216', { * account_id: '0d37909e38d3e99c29fa2cd343ac421a', * gateway_id: '54442216', * name: 'Route Name', * }); * ``` */ update(id, params, options) { const { account_id, gateway_id, ...body } = params; return this._client.patch(path `/accounts/${account_id}/ai-gateway/gateways/${gateway_id}/routes/${id}`, { body, ...options, }); } /** * Lists the dynamic routes configured on an AI Gateway. * * @example * ```ts * const dynamicRoutings = * await client.aiGateway.dynamicRouting.list('54442216', { * account_id: '0d37909e38d3e99c29fa2cd343ac421a', * }); * ``` */ list(gatewayID, params, options) { const { account_id, ...query } = params; return this._client.get(path `/accounts/${account_id}/ai-gateway/gateways/${gatewayID}/routes`, { query, ...options, }); } /** * Deletes a dynamic route from an AI Gateway. * * @example * ```ts * const dynamicRouting = * await client.aiGateway.dynamicRouting.delete('54442216', { * account_id: '0d37909e38d3e99c29fa2cd343ac421a', * gateway_id: '54442216', * }); * ``` */ delete(id, params, options) { const { account_id, gateway_id } = params; return this._client.delete(path `/accounts/${account_id}/ai-gateway/gateways/${gateway_id}/routes/${id}`, options)._thenUnwrap((obj) => obj.result); } /** * Deploys the specified version of a dynamic route so that it serves traffic. * Deploy an earlier version to roll back. * * @example * ```ts * const response = * await client.aiGateway.dynamicRouting.createDeployment( * '54442216', * { * account_id: '0d37909e38d3e99c29fa2cd343ac421a', * gateway_id: '54442216', * version_id: '54442216', * }, * ); * ``` */ createDeployment(id, params, options) { const { account_id, gateway_id, ...body } = params; return this._client.post(path `/accounts/${account_id}/ai-gateway/gateways/${gateway_id}/routes/${id}/deployments`, { body, ...options })._thenUnwrap((obj) => obj.result); } /** * Creates a new version of a dynamic route from the specified routing elements. * The version does not serve traffic until you deploy it. * * @example * ```ts * const response = * await client.aiGateway.dynamicRouting.createVersion( * '54442216', * { * account_id: '0d37909e38d3e99c29fa2cd343ac421a', * gateway_id: '54442216', * elements: [ * { * id: 'id', * outputs: { next: { elementId: 'elementId' } }, * type: 'start', * }, * ], * }, * ); * ``` */ createVersion(id, params, options) { const { account_id, gateway_id, ...body } = params; return this._client.post(path `/accounts/${account_id}/ai-gateway/gateways/${gateway_id}/routes/${id}/versions`, { body, ...options })._thenUnwrap((obj) => obj.result); } /** * Retrieves a dynamic route with its routing elements, active version, and current * deployment. * * @example * ```ts * const dynamicRouting = * await client.aiGateway.dynamicRouting.get('54442216', { * account_id: '0d37909e38d3e99c29fa2cd343ac421a', * gateway_id: '54442216', * }); * ``` */ get(id, params, options) { const { account_id, gateway_id } = params; return this._client.get(path `/accounts/${account_id}/ai-gateway/gateways/${gateway_id}/routes/${id}`, options)._thenUnwrap((obj) => obj.result); } /** * Retrieves a saved version of a dynamic route, including its routing elements. * * @example * ```ts * const response = * await client.aiGateway.dynamicRouting.getVersion( * '54442216', * { * account_id: '0d37909e38d3e99c29fa2cd343ac421a', * gateway_id: '54442216', * id: '54442216', * }, * ); * ``` */ getVersion(versionID, params, options) { const { account_id, gateway_id, id } = params; return this._client.get(path `/accounts/${account_id}/ai-gateway/gateways/${gateway_id}/routes/${id}/versions/${versionID}`, options)._thenUnwrap((obj) => obj.result); } /** * Lists the deployment history of a dynamic route. * * @example * ```ts * const response = * await client.aiGateway.dynamicRouting.listDeployments( * '54442216', * { * account_id: '0d37909e38d3e99c29fa2cd343ac421a', * gateway_id: '54442216', * }, * ); * ``` */ listDeployments(id, params, options) { const { account_id, gateway_id } = params; return this._client.get(path `/accounts/${account_id}/ai-gateway/gateways/${gateway_id}/routes/${id}/deployments`, options); } /** * Lists the saved versions of a dynamic route. * * @example * ```ts * const response = * await client.aiGateway.dynamicRouting.listVersions( * '54442216', * { * account_id: '0d37909e38d3e99c29fa2cd343ac421a', * gateway_id: '54442216', * }, * ); * ``` */ listVersions(id, params, options) { const { account_id, gateway_id } = params; return this._client.get(path `/accounts/${account_id}/ai-gateway/gateways/${gateway_id}/routes/${id}/versions`, options); } } BaseDynamicRouting._key = Object.freeze([ 'aiGateway', 'dynamicRouting', ]); return BaseDynamicRouting; })(); export class DynamicRouting extends BaseDynamicRouting { } //# sourceMappingURL=dynamic-routing.mjs.map