UNPKG

cloudflare

Version:

The official TypeScript library for the Cloudflare API

205 lines • 8.13 kB
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. import { APIResource } from "../../../../core/resource.mjs"; import * as AvailableAPI from "./available.mjs"; import { Available, BaseAvailable, } from "./available.mjs"; import { CloudflareError } from "../../../../core/error.mjs"; import { SinglePage } from "../../../../core/pagination.mjs"; import { path } from "../../../../internal/utils/path.mjs"; export var BaseDatasets = /* @__PURE__ */ (() => { class BaseDatasets extends APIResource { /** * Create a new Log Explorer dataset for the account or zone. * * List available account or zone datasets to see the dataset types and fields you * can use. * * The `fields` property is optional. If not specified, all available fields will * be enabled. * * For dataset field definitions, see: * https://developers.cloudflare.com/logs/logpush/logpush-job/datasets/ * * @example * ```ts * const dataset = * await client.logs.logExplorer.datasets.create({ * dataset: 'dataset', * account_id: 'account_id', * }); * ``` */ create(params, options) { const { account_id, zone_id, ...body } = params; if (!account_id && !zone_id) { throw new CloudflareError('You must provide either account_id or zone_id.'); } if (account_id && zone_id) { throw new CloudflareError('You cannot provide both account_id and zone_id.'); } const { accountOrZone, accountOrZoneId } = account_id ? { accountOrZone: 'accounts', accountOrZoneId: account_id, } : { accountOrZone: 'zones', accountOrZoneId: zone_id, }; return this._client.post(path `/${accountOrZone}/${accountOrZoneId}/logs/explorer/datasets`, { body, ...options, })._thenUnwrap((obj) => obj.result); } /** * Updates the enabled state and/or field configuration of an account or zone * dataset. * * @example * ```ts * const dataset = * await client.logs.logExplorer.datasets.update( * 'dataset_id', * { enabled: true, account_id: 'account_id' }, * ); * ``` */ update(datasetID, params, options) { const { account_id, zone_id, ...body } = params; if (!account_id && !zone_id) { throw new CloudflareError('You must provide either account_id or zone_id.'); } if (account_id && zone_id) { throw new CloudflareError('You cannot provide both account_id and zone_id.'); } const { accountOrZone, accountOrZoneId } = account_id ? { accountOrZone: 'accounts', accountOrZoneId: account_id, } : { accountOrZone: 'zones', accountOrZoneId: zone_id, }; return this._client.put(path `/${accountOrZone}/${accountOrZoneId}/logs/explorer/datasets/${datasetID}`, { body, ...options, })._thenUnwrap((obj) => obj.result); } /** * Returns all Log Explorer datasets configured for the account or zone. * * Pass `include_zones=true` to also include zone-level datasets that belong to * this account or zone. List responses omit the `fields` property; use the * single-dataset endpoint to retrieve field configuration. * * @example * ```ts * // Automatically fetches more pages as needed. * for await (const datasetSummary of client.logs.logExplorer.datasets.list( * { account_id: 'account_id' }, * )) { * // ... * } * ``` */ list(params = {}, options) { const { account_id, zone_id, ...query } = params ?? {}; if (!account_id && !zone_id) { throw new CloudflareError('You must provide either account_id or zone_id.'); } if (account_id && zone_id) { throw new CloudflareError('You cannot provide both account_id and zone_id.'); } const { accountOrZone, accountOrZoneId } = account_id ? { accountOrZone: 'accounts', accountOrZoneId: account_id, } : { accountOrZone: 'zones', accountOrZoneId: zone_id, }; return this._client.getAPIList(path `/${accountOrZone}/${accountOrZoneId}/logs/explorer/datasets`, (SinglePage), { query, ...options }); } /** * Deletes a Log Explorer dataset for the account or zone. Dataset deletion must * not be protected. * * @example * ```ts * const dataset = * await client.logs.logExplorer.datasets.delete( * 'dataset_id', * { account_id: 'account_id' }, * ); * ``` */ delete(datasetID, params = {}, options) { const { account_id, zone_id } = params ?? {}; if (!account_id && !zone_id) { throw new CloudflareError('You must provide either account_id or zone_id.'); } if (account_id && zone_id) { throw new CloudflareError('You cannot provide both account_id and zone_id.'); } const { accountOrZone, accountOrZoneId } = account_id ? { accountOrZone: 'accounts', accountOrZoneId: account_id, } : { accountOrZone: 'zones', accountOrZoneId: zone_id, }; return this._client.delete(path `/${accountOrZone}/${accountOrZoneId}/logs/explorer/datasets/${datasetID}`, options)._thenUnwrap((obj) => obj.result); } /** * Retrieve a single Log Explorer dataset by ID for the account or zone. * * @example * ```ts * const dataset = await client.logs.logExplorer.datasets.get( * 'dataset_id', * { account_id: 'account_id' }, * ); * ``` */ get(datasetID, params = {}, options) { const { account_id, zone_id } = params ?? {}; if (!account_id && !zone_id) { throw new CloudflareError('You must provide either account_id or zone_id.'); } if (account_id && zone_id) { throw new CloudflareError('You cannot provide both account_id and zone_id.'); } const { accountOrZone, accountOrZoneId } = account_id ? { accountOrZone: 'accounts', accountOrZoneId: account_id, } : { accountOrZone: 'zones', accountOrZoneId: zone_id, }; return this._client.get(path `/${accountOrZone}/${accountOrZoneId}/logs/explorer/datasets/${datasetID}`, options)._thenUnwrap((obj) => obj.result); } } BaseDatasets._key = Object.freeze([ 'logs', 'logExplorer', 'datasets', ]); return BaseDatasets; })(); export var Datasets = /* @__PURE__ */ (() => { class Datasets extends BaseDatasets { constructor() { super(...arguments); this.available = new AvailableAPI.Available(this._client); } } Datasets.Available = Available; Datasets.BaseAvailable = BaseAvailable; return Datasets; })(); //# sourceMappingURL=datasets.mjs.map