orb-billing
Version:
The official TypeScript library for the Orb API
134 lines • 6.78 kB
JavaScript
;
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
Object.defineProperty(exports, "__esModule", { value: true });
exports.Alerts = void 0;
const resource_1 = require("../core/resource.js");
const pagination_1 = require("../core/pagination.js");
const headers_1 = require("../internal/headers.js");
const path_1 = require("../internal/utils/path.js");
/**
* [Alerts within Orb](/product-catalog/configuring-alerts) monitor spending,
* usage, or credit balance and trigger webhooks when a threshold is exceeded.
*
* Alerts created through the API can be scoped to either customers or subscriptions.
*/
class Alerts extends resource_1.APIResource {
/**
* This endpoint retrieves an alert by its ID.
*/
retrieve(alertID, options) {
return this._client.get((0, path_1.path) `/alerts/${alertID}`, options);
}
/**
* This endpoint updates the thresholds of an alert. On cost alerts it also updates
* `price_filters`, and on subscription-scoped grouped cost alerts
* `threshold_overrides`; omitting either leaves it unchanged, and an empty list
* clears it.
*/
update(alertConfigurationID, body, options) {
return this._client.put((0, path_1.path) `/alerts/${alertConfigurationID}`, { body, ...options });
}
/**
* This endpoint returns a list of alerts within Orb.
*
* The request must specify one of `customer_id`, `external_customer_id`, or
* `subscription_id`.
*
* If querying by subscription_id, the endpoint will return the subscription level
* alerts as well as the plan level alerts associated with the subscription.
*
* The list of alerts is ordered starting from the most recently created alert.
* This endpoint follows Orb's
* [standardized pagination format](/api-reference/pagination).
*/
list(query = {}, options) {
return this._client.getAPIList('/alerts', (pagination_1.Page), { query, ...options });
}
/**
* This endpoint deletes a subscription or customer-scoped alert. The alert is
* soft-deleted: it stops firing immediately and no longer appears in fetch or list
* responses, while the underlying record is retained internally for audit.
*
* Plan-level alerts cannot be deleted via the API — disable them instead
* (`POST /v1/alerts/{alert_configuration_id}/disable`). Their removal would need
* to be unwound from every subscription the alert was propagated to, which isn't
* supported yet.
*/
delete(alertConfigurationID, options) {
return this._client.delete((0, path_1.path) `/alerts/${alertConfigurationID}`, {
...options,
headers: (0, headers_1.buildHeaders)([{ Accept: '*/*' }, options?.headers]),
});
}
/**
* This endpoint creates a new alert to monitor a customer's credit balance. There
* are three types of alerts that can be scoped to customers:
* `credit_balance_depleted`, `credit_balance_dropped`, and
* `credit_balance_recovered`. Customers can have a maximum of one of each type of
* alert per [credit balance currency](/product-catalog/prepurchase).
* `credit_balance_dropped` alerts require a list of thresholds to be provided
* while `credit_balance_depleted` and `credit_balance_recovered` alerts do not
* require thresholds.
*/
createForCustomer(customerID, body, options) {
return this._client.post((0, path_1.path) `/alerts/customer_id/${customerID}`, { body, ...options });
}
/**
* This endpoint creates a new alert to monitor a customer's credit balance. There
* are three types of alerts that can be scoped to customers:
* `credit_balance_depleted`, `credit_balance_dropped`, and
* `credit_balance_recovered`. Customers can have a maximum of one of each type of
* alert per [credit balance currency](/product-catalog/prepurchase).
* `credit_balance_dropped` alerts require a list of thresholds to be provided
* while `credit_balance_depleted` and `credit_balance_recovered` alerts do not
* require thresholds.
*/
createForExternalCustomer(externalCustomerID, body, options) {
return this._client.post((0, path_1.path) `/alerts/external_customer_id/${externalCustomerID}`, { body, ...options });
}
/**
* This endpoint is used to create alerts at the subscription level.
*
* Subscription level alerts can be one of three types: `usage_exceeded`,
* `cost_exceeded`, or `spend_exceeded`. A `usage_exceeded` alert is scoped to a
* particular metric and is triggered when the usage of that metric exceeds
* predefined thresholds during the current billing cycle. A `cost_exceeded` alert
* is triggered when the total amount due during the current billing cycle
* surpasses predefined thresholds. `cost_exceeded` alerts do not include burndown
* of pre-purchase credits. A `spend_exceeded` alert is triggered when the rated
* spend (the pricing subtotal, before invoice-level adjustments and credits)
* denominated in the alert's currency exceeds predefined thresholds during the
* current billing cycle; `price_filters` can scope which prices contribute. Each
* subscription can have one `cost_exceeded` alert and one `usage_exceeded` alert
* per metric that is a part of the subscription.
*/
createForSubscription(subscriptionID, body, options) {
return this._client.post((0, path_1.path) `/alerts/subscription_id/${subscriptionID}`, { body, ...options });
}
/**
* This endpoint allows you to disable an alert. To disable a plan-level alert for
* a specific subscription, you must include the `subscription_id`. The
* `subscription_id` is not required for customer or subscription level alerts.
*/
disable(alertConfigurationID, params = {}, options) {
const { subscription_id } = params ?? {};
return this._client.post((0, path_1.path) `/alerts/${alertConfigurationID}/disable`, {
query: { subscription_id },
...options,
});
}
/**
* This endpoint allows you to enable an alert. To enable a plan-level alert for a
* specific subscription, you must include the `subscription_id`. The
* `subscription_id` is not required for customer or subscription level alerts.
*/
enable(alertConfigurationID, params = {}, options) {
const { subscription_id } = params ?? {};
return this._client.post((0, path_1.path) `/alerts/${alertConfigurationID}/enable`, {
query: { subscription_id },
...options,
});
}
}
exports.Alerts = Alerts;
//# sourceMappingURL=alerts.js.map