UNPKG

orb-billing

Version:

The official TypeScript library for the Orb API

78 lines 2.81 kB
"use strict"; // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. Object.defineProperty(exports, "__esModule", { value: true }); exports.Metrics = void 0; const resource_1 = require("../core/resource.js"); const pagination_1 = require("../core/pagination.js"); const path_1 = require("../internal/utils/path.js"); /** * The Metric resource represents a calculation of a quantity based on events. * Metrics are defined by the query that transforms raw usage events into meaningful values for your customers. */ class Metrics extends resource_1.APIResource { /** * This endpoint is used to create a [metric](/core-concepts###metric) using a SQL * string. See [SQL support](/extensibility/advanced-metrics#sql-support) for a * description of constructing SQL queries with examples. * * @example * ```ts * const billableMetric = await client.metrics.create({ * description: 'Sum of bytes downloaded in fast mode', * item_id: 'item_id', * name: 'Bytes downloaded', * sql: "SELECT sum(bytes_downloaded) FROM events WHERE download_speed = 'fast'", * }); * ``` */ create(body, options) { return this._client.post('/metrics', { body, ...options }); } /** * This endpoint allows you to update the `metadata` property on a metric. If you * pass `null` for the metadata value, it will clear any existing metadata for that * invoice. * * @example * ```ts * const billableMetric = await client.metrics.update( * 'metric_id', * ); * ``` */ update(metricID, body, options) { return this._client.put((0, path_1.path) `/metrics/${metricID}`, { body, ...options }); } /** * This endpoint is used to list [metrics](/core-concepts#metric). It returns * information about the metrics including its name, description, and item. * * @example * ```ts * // Automatically fetches more pages as needed. * for await (const billableMetric of client.metrics.list()) { * // ... * } * ``` */ list(query = {}, options) { return this._client.getAPIList('/metrics', (pagination_1.Page), { query, ...options }); } /** * This endpoint is used to fetch [metric](/core-concepts#metric) details given a * metric identifier. It returns information about the metrics including its name, * description, and item. * * @example * ```ts * const billableMetric = await client.metrics.fetch( * 'metric_id', * ); * ``` */ fetch(metricID, options) { return this._client.get((0, path_1.path) `/metrics/${metricID}`, options); } } exports.Metrics = Metrics; //# sourceMappingURL=metrics.js.map