UNPKG

cloudflare

Version:

The official TypeScript library for the Cloudflare API

112 lines • 4.34 kB
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. import { APIResource } from "../../core/resource.mjs"; import * as DataSecurityAPI from "./data-security/data-security.mjs"; import { BaseDataSecurity, DataSecurity } from "./data-security/data-security.mjs"; import { SinglePage } from "../../core/pagination.mjs"; import { path } from "../../internal/utils/path.mjs"; export var BaseAnalyticsQuery = /* @__PURE__ */ (() => { class BaseAnalyticsQuery extends APIResource { /** * Returns aggregate summary stats for a dataset. Includes current-period and * previous-period totals for trend comparison. * * @example * ```ts * const response = await client.analyticsQuery.summary( * 'access-logins', * { * account_id: '023e105f4ecef8ad9ca31a8372d0c353', * filters: [], * from: '2024-11-01T00:00:00Z', * groupBy: [], * stats: ['attemptsTotal'], * to: '2024-11-08T00:00:00Z', * }, * ); * ``` */ summary(dataset, params, options) { const { account_id, ...body } = params; return this._client.post(path `/accounts/${account_id}/analytics/query/${dataset}/summary`, { body, ...options, })._thenUnwrap((obj) => obj.result); } /** * Returns time-bucketed analytics data for a dataset. Includes time slots, each * containing the requested stats, group-by dimensions, and resolution-controlled * bucket size (e.g. `hour`, `day`). * * @example * ```ts * const response = await client.analyticsQuery.timeseries( * 'shadow_it', * { * account_id: '023e105f4ecef8ad9ca31a8372d0c353', * filters: [ * { * name: 'allowed', * op: 'eq', * values: [true], * }, * ], * from: '2024-11-01T00:00:00Z', * groupBy: ['country', 'allowed'], * resolution: 'day', * stats: ['attemptsTotal'], * to: '2024-11-08T00:00:00Z', * }, * ); * ``` */ timeseries(dataset, params, options) { const { account_id, ...body } = params; return this._client.post(path `/accounts/${account_id}/analytics/query/${dataset}/timeseries`, { body, ...options, })._thenUnwrap((obj) => obj.result); } /** * Returns the top N results for a dataset by a specified stat. Includes an array * of result rows, each containing the requested stats and group-by dimensions. * * @example * ```ts * // Automatically fetches more pages as needed. * for await (const analyticsQueryTopNResponse of client.analyticsQuery.topN( * 'gateway-http', * { * account_id: '023e105f4ecef8ad9ca31a8372d0c353', * filters: [], * from: '2024-11-05T00:00:00Z', * groupBy: ['appName', 'appCategory'], * n: 10, * orderBy: 'bytesTotal', * stats: ['bytesTotal', 'requestsTotal'], * to: '2024-11-06T00:00:00Z', * }, * )) { * // ... * } * ``` */ topN(dataset, params, options) { const { account_id, ...body } = params; return this._client.getAPIList(path `/accounts/${account_id}/analytics/query/${dataset}/top-n`, (SinglePage), { body, method: 'post', ...options }); } } BaseAnalyticsQuery._key = Object.freeze(['analyticsQuery']); return BaseAnalyticsQuery; })(); export var AnalyticsQuery = /* @__PURE__ */ (() => { class AnalyticsQuery extends BaseAnalyticsQuery { constructor() { super(...arguments); this.dataSecurity = new DataSecurityAPI.DataSecurity(this._client); } } AnalyticsQuery.DataSecurity = DataSecurity; AnalyticsQuery.BaseDataSecurity = BaseDataSecurity; return AnalyticsQuery; })(); //# sourceMappingURL=analytics-query.mjs.map