UNPKG

cloudflare

Version:

The official TypeScript library for the Cloudflare API

211 lines • 8.56 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Datasets = exports.BaseDatasets = void 0; const tslib_1 = require("../../../../internal/tslib.js"); // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. const resource_1 = require("../../../../core/resource.js"); const AvailableAPI = tslib_1.__importStar(require("./available.js")); const available_1 = require("./available.js"); const error_1 = require("../../../../core/error.js"); const pagination_1 = require("../../../../core/pagination.js"); const path_1 = require("../../../../internal/utils/path.js"); var BaseDatasets = /* @__PURE__ */ (() => { class BaseDatasets extends resource_1.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 error_1.CloudflareError('You must provide either account_id or zone_id.'); } if (account_id && zone_id) { throw new error_1.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((0, path_1.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 error_1.CloudflareError('You must provide either account_id or zone_id.'); } if (account_id && zone_id) { throw new error_1.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((0, path_1.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 error_1.CloudflareError('You must provide either account_id or zone_id.'); } if (account_id && zone_id) { throw new error_1.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((0, path_1.path) `/${accountOrZone}/${accountOrZoneId}/logs/explorer/datasets`, (pagination_1.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 error_1.CloudflareError('You must provide either account_id or zone_id.'); } if (account_id && zone_id) { throw new error_1.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((0, path_1.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 error_1.CloudflareError('You must provide either account_id or zone_id.'); } if (account_id && zone_id) { throw new error_1.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((0, path_1.path) `/${accountOrZone}/${accountOrZoneId}/logs/explorer/datasets/${datasetID}`, options)._thenUnwrap((obj) => obj.result); } } BaseDatasets._key = Object.freeze([ 'logs', 'logExplorer', 'datasets', ]); return BaseDatasets; })(); exports.BaseDatasets = BaseDatasets; var Datasets = /* @__PURE__ */ (() => { class Datasets extends BaseDatasets { constructor() { super(...arguments); this.available = new AvailableAPI.Available(this._client); } } Datasets.Available = available_1.Available; Datasets.BaseAvailable = available_1.BaseAvailable; return Datasets; })(); exports.Datasets = Datasets; //# sourceMappingURL=datasets.js.map