UNPKG

cloudflare

Version:

The official TypeScript library for the Cloudflare API

113 lines • 3.86 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 BaseVariants = /* @__PURE__ */ (() => { class BaseVariants extends APIResource { /** * Create a CF Images variant that allows you to resize images for different use * cases. * * @example * ```ts * const variant = await client.images.v1.variants.create({ * account_id: '023e105f4ecef8ad9ca31a8372d0c353', * id: 'hero', * options: { * fit: 'scale-down', * height: 768, * metadata: 'none', * width: 1366, * }, * }); * ``` */ create(params, options) { const { account_id, ...body } = params; return this._client.post(path `/accounts/${account_id}/images/v1/variants`, { body, ...options, })._thenUnwrap((obj) => obj.result); } /** * List existing CF Images variants. * * @example * ```ts * const variant = await client.images.v1.variants.list({ * account_id: '023e105f4ecef8ad9ca31a8372d0c353', * }); * ``` */ list(params, options) { const { account_id } = params; return this._client.get(path `/accounts/${account_id}/images/v1/variants`, options)._thenUnwrap((obj) => obj.result); } /** * Delete a CF Images variant. This will purge the cache for all images associated * with the variant. * * @example * ```ts * const variant = await client.images.v1.variants.delete( * 'hero', * { account_id: '023e105f4ecef8ad9ca31a8372d0c353' }, * ); * ``` */ delete(variantID, params, options) { const { account_id } = params; return this._client.delete(path `/accounts/${account_id}/images/v1/variants/${variantID}`, options)._thenUnwrap((obj) => obj.result); } /** * Update a CF Images variant. This will purge the cache for all images associated * with the variant. * * @example * ```ts * const response = await client.images.v1.variants.edit( * 'hero', * { * account_id: '023e105f4ecef8ad9ca31a8372d0c353', * options: { * fit: 'scale-down', * height: 768, * metadata: 'none', * width: 1366, * }, * }, * ); * ``` */ edit(variantID, params, options) { const { account_id, ...body } = params; return this._client.patch(path `/accounts/${account_id}/images/v1/variants/${variantID}`, { body, ...options, })._thenUnwrap((obj) => obj.result); } /** * Fetch details for a CF Images variant. * * @example * ```ts * const variant = await client.images.v1.variants.get( * 'hero', * { account_id: '023e105f4ecef8ad9ca31a8372d0c353' }, * ); * ``` */ get(variantID, params, options) { const { account_id } = params; return this._client.get(path `/accounts/${account_id}/images/v1/variants/${variantID}`, options)._thenUnwrap((obj) => obj.result); } } BaseVariants._key = Object.freeze([ 'images', 'v1', 'variants', ]); return BaseVariants; })(); export class Variants extends BaseVariants { } //# sourceMappingURL=variants.mjs.map