UNPKG

cloudflare

Version:

The official TypeScript library for the Cloudflare API

118 lines • 4.71 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AnalyticsQuery = exports.BaseAnalyticsQuery = 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 DataSecurityAPI = tslib_1.__importStar(require("./data-security/data-security.js")); const data_security_1 = require("./data-security/data-security.js"); const pagination_1 = require("../../core/pagination.js"); const path_1 = require("../../internal/utils/path.js"); var BaseAnalyticsQuery = /* @__PURE__ */ (() => { class BaseAnalyticsQuery extends resource_1.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((0, path_1.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((0, path_1.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((0, path_1.path) `/accounts/${account_id}/analytics/query/${dataset}/top-n`, (pagination_1.SinglePage), { body, method: 'post', ...options }); } } BaseAnalyticsQuery._key = Object.freeze(['analyticsQuery']); return BaseAnalyticsQuery; })(); exports.BaseAnalyticsQuery = BaseAnalyticsQuery; var AnalyticsQuery = /* @__PURE__ */ (() => { class AnalyticsQuery extends BaseAnalyticsQuery { constructor() { super(...arguments); this.dataSecurity = new DataSecurityAPI.DataSecurity(this._client); } } AnalyticsQuery.DataSecurity = data_security_1.DataSecurity; AnalyticsQuery.BaseDataSecurity = data_security_1.BaseDataSecurity; return AnalyticsQuery; })(); exports.AnalyticsQuery = AnalyticsQuery; //# sourceMappingURL=analytics-query.js.map