UNPKG

cloudflare

Version:

The official TypeScript library for the Cloudflare API

169 lines • 6.24 kB
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. import { APIResource } from "../../../../core/resource.mjs"; import { SinglePage, V4PagePaginationArray, } from "../../../../core/pagination.mjs"; import { buildHeaders } from "../../../../internal/headers.mjs"; import { path } from "../../../../internal/utils/path.mjs"; export var BaseTargets = /* @__PURE__ */ (() => { class BaseTargets extends APIResource { /** * Creates a new infrastructure access target in the account. * * @example * ```ts * const target = * await client.zeroTrust.access.infrastructure.targets.create( * { * account_id: '023e105f4ecef8ad9ca31a8372d0c353', * hostname: 'infra-access-target', * ip: {}, * }, * ); * ``` */ create(params, options) { const { account_id, ...body } = params; return this._client.post(path `/accounts/${account_id}/infrastructure/targets`, { body, ...options, })._thenUnwrap((obj) => obj.result); } /** * Updates an existing infrastructure access target by its ID. * * @example * ```ts * const target = * await client.zeroTrust.access.infrastructure.targets.update( * '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', * { * account_id: '023e105f4ecef8ad9ca31a8372d0c353', * hostname: 'infra-access-target', * ip: {}, * }, * ); * ``` */ update(targetID, params, options) { const { account_id, ...body } = params; return this._client.put(path `/accounts/${account_id}/infrastructure/targets/${targetID}`, { body, ...options, })._thenUnwrap((obj) => obj.result); } /** * Lists and sorts an account's targets. Filters are optional and are ANDed * together. * * @example * ```ts * // Automatically fetches more pages as needed. * for await (const targetListResponse of client.zeroTrust.access.infrastructure.targets.list( * { account_id: '023e105f4ecef8ad9ca31a8372d0c353' }, * )) { * // ... * } * ``` */ list(params, options) { const { account_id, ...query } = params; return this._client.getAPIList(path `/accounts/${account_id}/infrastructure/targets`, (V4PagePaginationArray), { query, ...options }); } /** * Removes a single infrastructure access target by its ID. * * @example * ```ts * await client.zeroTrust.access.infrastructure.targets.delete( * '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', * { account_id: '023e105f4ecef8ad9ca31a8372d0c353' }, * ); * ``` */ delete(targetID, params, options) { const { account_id } = params; return this._client.delete(path `/accounts/${account_id}/infrastructure/targets/${targetID}`, { ...options, headers: buildHeaders([{ Accept: '*/*' }, options?.headers]), }); } /** * Removes one or more targets. * * @deprecated */ bulkDelete(params, options) { const { account_id } = params; return this._client.delete(path `/accounts/${account_id}/infrastructure/targets/batch`, { ...options, headers: buildHeaders([{ Accept: '*/*' }, options?.headers]), }); } /** * Removes one or more targets. * * @example * ```ts * await client.zeroTrust.access.infrastructure.targets.bulkDeleteV2( * { * account_id: '023e105f4ecef8ad9ca31a8372d0c353', * target_ids: ['182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e'], * }, * ); * ``` */ bulkDeleteV2(params, options) { const { account_id, ...body } = params; return this._client.post(path `/accounts/${account_id}/infrastructure/targets/batch_delete`, { body, ...options, headers: buildHeaders([{ Accept: '*/*' }, options?.headers]), }); } /** * Adds one or more targets. * * @example * ```ts * // Automatically fetches more pages as needed. * for await (const targetBulkUpdateResponse of client.zeroTrust.access.infrastructure.targets.bulkUpdate( * { * account_id: '023e105f4ecef8ad9ca31a8372d0c353', * body: [ * { * hostname: 'infra-access-target', * ip: {}, * }, * ], * }, * )) { * // ... * } * ``` */ bulkUpdate(params, options) { const { account_id, body } = params; return this._client.getAPIList(path `/accounts/${account_id}/infrastructure/targets/batch`, (SinglePage), { body: body, method: 'put', ...options }); } /** * Fetches a single infrastructure access target by its ID. * * @example * ```ts * const target = * await client.zeroTrust.access.infrastructure.targets.get( * '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', * { account_id: '023e105f4ecef8ad9ca31a8372d0c353' }, * ); * ``` */ get(targetID, params, options) { const { account_id } = params; return this._client.get(path `/accounts/${account_id}/infrastructure/targets/${targetID}`, options)._thenUnwrap((obj) => obj.result); } } BaseTargets._key = Object.freeze(['zeroTrust', 'access', 'infrastructure', 'targets']); return BaseTargets; })(); export class Targets extends BaseTargets { } //# sourceMappingURL=targets.mjs.map