orb-billing
Version:
The official TypeScript library for the Orb API
74 lines • 2.63 kB
JavaScript
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
import { APIResource } from "../core/resource.mjs";
import { Page } from "../core/pagination.mjs";
import { path } from "../internal/utils/path.mjs";
/**
* 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.
*/
export class Metrics extends 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(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', (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(path `/metrics/${metricID}`, options);
}
}
//# sourceMappingURL=metrics.mjs.map