orb-billing 2.5.1 → 2.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/index.d.mts +5 -0
  3. package/index.d.ts +5 -0
  4. package/index.d.ts.map +1 -1
  5. package/index.js +1 -0
  6. package/index.js.map +1 -1
  7. package/index.mjs +1 -0
  8. package/index.mjs.map +1 -1
  9. package/package.json +1 -1
  10. package/resources/alerts.d.ts +193 -23
  11. package/resources/alerts.d.ts.map +1 -1
  12. package/resources/alerts.js +93 -1
  13. package/resources/alerts.js.map +1 -1
  14. package/resources/alerts.mjs +68 -0
  15. package/resources/alerts.mjs.map +1 -1
  16. package/resources/customers/costs.d.ts +10 -10
  17. package/resources/events/backfills.d.ts +4 -0
  18. package/resources/events/backfills.d.ts.map +1 -1
  19. package/resources/events/backfills.js +4 -0
  20. package/resources/events/backfills.js.map +1 -1
  21. package/resources/events/backfills.mjs +4 -0
  22. package/resources/events/backfills.mjs.map +1 -1
  23. package/resources/events/events.d.ts +3 -1
  24. package/resources/events/events.d.ts.map +1 -1
  25. package/resources/events/events.js +3 -1
  26. package/resources/events/events.js.map +1 -1
  27. package/resources/events/events.mjs +3 -1
  28. package/resources/events/events.mjs.map +1 -1
  29. package/resources/index.d.ts +1 -1
  30. package/resources/index.d.ts.map +1 -1
  31. package/resources/index.js +2 -1
  32. package/resources/index.js.map +1 -1
  33. package/resources/index.mjs +1 -1
  34. package/resources/index.mjs.map +1 -1
  35. package/resources/subscriptions.d.ts +1 -1
  36. package/src/index.ts +5 -0
  37. package/src/resources/alerts.ts +255 -23
  38. package/src/resources/customers/costs.ts +10 -10
  39. package/src/resources/events/backfills.ts +4 -0
  40. package/src/resources/events/events.ts +3 -1
  41. package/src/resources/index.ts +9 -1
  42. package/src/resources/subscriptions.ts +1 -1
  43. package/src/version.ts +1 -1
  44. package/version.d.ts +1 -1
  45. package/version.js +1 -1
  46. package/version.mjs +1 -1
@@ -2,9 +2,109 @@
2
2
 
3
3
  import * as Core from "../core";
4
4
  import { APIResource } from "../resource";
5
+ import { isRequestOptions } from "../core";
5
6
  import * as AlertsAPI from "./alerts";
7
+ import { Page, type PageParams } from "../pagination";
6
8
 
7
9
  export class Alerts extends APIResource {
10
+ /**
11
+ * This endpoint retrieves an alert by its ID.
12
+ */
13
+ retrieve(alertId: string, options?: Core.RequestOptions): Core.APIPromise<Alert> {
14
+ return this._client.get(`/alerts/${alertId}`, options);
15
+ }
16
+
17
+ /**
18
+ * This endpoint returns a list of alerts within Orb.
19
+ *
20
+ * The request must specify one of `customer_id`, `external_customer_id`, or
21
+ * `subscription_id`.
22
+ *
23
+ * If querying by subscripion_id, the endpoint will return the subscription level
24
+ * alerts as well as the plan level alerts associated with the subscription.
25
+ *
26
+ * The list of alerts is ordered starting from the most recently created alert.
27
+ * This endpoint follows Orb's
28
+ * [standardized pagination format](../reference/pagination).
29
+ */
30
+ list(query?: AlertListParams, options?: Core.RequestOptions): Core.PagePromise<AlertsPage, Alert>;
31
+ list(options?: Core.RequestOptions): Core.PagePromise<AlertsPage, Alert>;
32
+ list(
33
+ query: AlertListParams | Core.RequestOptions = {},
34
+ options?: Core.RequestOptions,
35
+ ): Core.PagePromise<AlertsPage, Alert> {
36
+ if (isRequestOptions(query)) {
37
+ return this.list({}, query);
38
+ }
39
+ return this._client.getAPIList('/alerts', AlertsPage, { query, ...options });
40
+ }
41
+
42
+ /**
43
+ * This endpoint creates a new alert to monitor a customer's credit balance. There
44
+ * are three types of alerts that can be scoped to customers:
45
+ * `credit_balance_depleted`, `credit_balance_dropped`, and
46
+ * `credit_balance_recovered`. Customers can have a maximum of one of each type of
47
+ * alert per
48
+ * [credit balance currency](https://docs.withorb.com/guides/product-catalog/prepurchase).
49
+ * `credit_balance_dropped` alerts require a list of thresholds to be provided
50
+ * while `credit_balance_depleted` and `credit_balance_recovered` alerts do not
51
+ * require thresholds.
52
+ */
53
+ createForCustomer(
54
+ customerId: string,
55
+ body: AlertCreateForCustomerParams,
56
+ options?: Core.RequestOptions,
57
+ ): Core.APIPromise<Alert> {
58
+ return this._client.post(`/alerts/customer_id/${customerId}`, { body, ...options });
59
+ }
60
+
61
+ /**
62
+ * This endpoint creates a new alert to monitor a customer's credit balance. There
63
+ * are three types of alerts that can be scoped to customers:
64
+ * `credit_balance_depleted`, `credit_balance_dropped`, and
65
+ * `credit_balance_recovered`. Customers can have a maximum of one of each type of
66
+ * alert per
67
+ * [credit balance currency](https://docs.withorb.com/guides/product-catalog/prepurchase).
68
+ * `credit_balance_dropped` alerts require a list of thresholds to be provided
69
+ * while `credit_balance_depleted` and `credit_balance_recovered` alerts do not
70
+ * require thresholds.
71
+ */
72
+ createForExternalCustomer(
73
+ externalCustomerId: string,
74
+ body: AlertCreateForExternalCustomerParams,
75
+ options?: Core.RequestOptions,
76
+ ): Core.APIPromise<Alert> {
77
+ return this._client.post(`/alerts/external_customer_id/${externalCustomerId}`, { body, ...options });
78
+ }
79
+
80
+ /**
81
+ * This endpoint is used to create alerts at the subscription level.
82
+ *
83
+ * Subscription level alerts can be one of two types: `usage_exceeded` or
84
+ * `cost_exceeded`. A `usage_exceeded` alert is scoped to a particular metric and
85
+ * is triggered when the usage of that metric exceeds predefined thresholds during
86
+ * the current billing cycle. A `cost_exceeded` alert is triggered when the total
87
+ * amount due during the current billing cycle surpasses predefined thresholds.
88
+ * `cost_exceeded` alerts do not include burndown of pre-purchase credits. Each
89
+ * subscription can have one `cost_exceeded` alert and one `usage_exceeded` alert
90
+ * per metric that is a part of the subscription. Alerts are triggered based on
91
+ * usage or cost conditions met during the current billing cycle.
92
+ */
93
+ createForSubscription(
94
+ subscriptionId: string,
95
+ body: AlertCreateForSubscriptionParams,
96
+ options?: Core.RequestOptions,
97
+ ): Core.APIPromise<Alert> {
98
+ return this._client.post(`/alerts/subscription_id/${subscriptionId}`, { body, ...options });
99
+ }
100
+
101
+ /**
102
+ * This endpoint can be used to disable an alert.
103
+ */
104
+ disable(alertConfigurationId: string, options?: Core.RequestOptions): Core.APIPromise<Alert> {
105
+ return this._client.post(`/alerts/${alertConfigurationId}/disable`, options);
106
+ }
107
+
8
108
  /**
9
109
  * This endpoint can be used to enable an alert.
10
110
  */
@@ -13,26 +113,20 @@ export class Alerts extends APIResource {
13
113
  }
14
114
  }
15
115
 
116
+ export class AlertsPage extends Page<Alert> {}
117
+
16
118
  /**
17
- * An
18
- * [Alert within Orb](https://docs.withorb.com/guides/product-catalog/configuring-alerts)
19
- * monitors a customer's spending, usage, or credit balance and triggers a webhook
20
- * when a threshold is exceeded.
21
- *
22
- * Alerts can be configured to monitor usage, cost, or credit balance. Alerts can
23
- * be scoped to either a customer, a plan, or a subscription.
24
- *
25
- * Customer scoped alerts track a customer's credit balance. Valid customer alert
26
- * types are "credit_balance_depleted", "credit_balance_recovered", and
27
- * "credit_balance_dropped".
119
+ * [Alerts within Orb](https://docs.withorb.com/guides/product-catalog/configuring-alerts)
120
+ * monitor spending, usage, or credit balance and trigger webhooks when a threshold
121
+ * is exceeded.
28
122
  *
29
- * Subscription scoped alerts track a subscriptions's usage or cost. Valid plan
30
- * alert types are "usage_exceeded" or "cost_exceeded".
123
+ * Alerts created through the API can be scoped to either customers or
124
+ * subscriptions.
31
125
  *
32
- * Plan scoped alerts are similar to subscriptions alerts but when a plan alert is
33
- * created, it is propagated to all subscriptions associated with the plan.
34
- * Disabling a plan alert will disable the alert for all subscriptions. Valid plan
35
- * alert types are "usage_exceeded" or "cost_exceeded".
126
+ * | Scope | Monitors | Vaild Alert Types |
127
+ * | ------------ | ------------------------------ | ----------------------------------------------------------------------------------- |
128
+ * | Customer | A customer's credit balance | `credit_balance_depleted`, `credit_balance_recovered`, and `credit_balance_dropped` |
129
+ * | Subscription | A subscription's usage or cost | `usage_exceeded` and `cost_exceeded` |
36
130
  */
37
131
  export interface Alert {
38
132
  /**
@@ -46,12 +140,12 @@ export interface Alert {
46
140
  created_at: string;
47
141
 
48
142
  /**
49
- * The name of the currency the credit balance for this alert is denominated in.
143
+ * The name of the currency the credit balance or invoice cost is denominated in.
50
144
  */
51
145
  currency: string | null;
52
146
 
53
147
  /**
54
- * The customer that the alert is scoped to.
148
+ * The customer the alert applies to.
55
149
  */
56
150
  customer: Record<string, string | null> | null;
57
151
 
@@ -60,13 +154,19 @@ export interface Alert {
60
154
  */
61
155
  enabled: boolean;
62
156
 
157
+ /**
158
+ * The metric the alert applies to.
159
+ */
63
160
  metric: Record<string, string | null> | null;
64
161
 
65
162
  /**
66
- * The plan that the alert is scoped to.
163
+ * The plan the alert applies to.
67
164
  */
68
165
  plan: Record<string, string | null> | null;
69
166
 
167
+ /**
168
+ * The subscription the alert applies to.
169
+ */
70
170
  subscription: Record<string, string | null> | null;
71
171
 
72
172
  /**
@@ -78,7 +178,12 @@ export interface Alert {
78
178
  /**
79
179
  * The type of alert. This must be a valid alert type.
80
180
  */
81
- type: 'credit_balance_depleted' | 'credit_balance_dropped' | 'credit_balance_recovered';
181
+ type:
182
+ | 'usage_exceeded'
183
+ | 'cost_exceeded'
184
+ | 'credit_balance_depleted'
185
+ | 'credit_balance_dropped'
186
+ | 'credit_balance_recovered';
82
187
  }
83
188
 
84
189
  export namespace Alert {
@@ -88,8 +193,130 @@ export namespace Alert {
88
193
  */
89
194
  export interface Threshold {
90
195
  /**
91
- * The value at which an alert will fire. For credit balance alerts, the alert will fire at or below this value. For usage and
92
- * cost alerts, the alert will fire at or above this value.
196
+ * The value at which an alert will fire. For credit balance alerts, the alert will
197
+ * fire at or below this value. For usage and cost alerts, the alert will fire at
198
+ * or above this value.
199
+ */
200
+ value: number;
201
+ }
202
+ }
203
+
204
+ export interface AlertListParams extends PageParams {
205
+ 'created_at[gt]'?: string | null;
206
+
207
+ 'created_at[gte]'?: string | null;
208
+
209
+ 'created_at[lt]'?: string | null;
210
+
211
+ 'created_at[lte]'?: string | null;
212
+
213
+ /**
214
+ * Fetch alerts scoped to this customer_id
215
+ */
216
+ customer_id?: string | null;
217
+
218
+ /**
219
+ * Fetch alerts scoped to this external_customer_id
220
+ */
221
+ external_customer_id?: string | null;
222
+
223
+ /**
224
+ * Fetch alerts scoped to this subscription_id
225
+ */
226
+ subscription_id?: string | null;
227
+ }
228
+
229
+ export interface AlertCreateForCustomerParams {
230
+ /**
231
+ * The case sensitive currency or custom pricing unit to use for this alert.
232
+ */
233
+ currency: string;
234
+
235
+ /**
236
+ * The thresholds that define the values at which the alert will be triggered.
237
+ */
238
+ type: string;
239
+
240
+ /**
241
+ * The thresholds for the alert.
242
+ */
243
+ thresholds?: Array<AlertCreateForCustomerParams.Threshold> | null;
244
+ }
245
+
246
+ export namespace AlertCreateForCustomerParams {
247
+ /**
248
+ * Thresholds are used to define the conditions under which an alert will be
249
+ * triggered.
250
+ */
251
+ export interface Threshold {
252
+ /**
253
+ * The value at which an alert will fire. For credit balance alerts, the alert will
254
+ * fire at or below this value. For usage and cost alerts, the alert will fire at
255
+ * or above this value.
256
+ */
257
+ value: number;
258
+ }
259
+ }
260
+
261
+ export interface AlertCreateForExternalCustomerParams {
262
+ /**
263
+ * The case sensitive currency or custom pricing unit to use for this alert.
264
+ */
265
+ currency: string;
266
+
267
+ /**
268
+ * The thresholds that define the values at which the alert will be triggered.
269
+ */
270
+ type: string;
271
+
272
+ /**
273
+ * The thresholds for the alert.
274
+ */
275
+ thresholds?: Array<AlertCreateForExternalCustomerParams.Threshold> | null;
276
+ }
277
+
278
+ export namespace AlertCreateForExternalCustomerParams {
279
+ /**
280
+ * Thresholds are used to define the conditions under which an alert will be
281
+ * triggered.
282
+ */
283
+ export interface Threshold {
284
+ /**
285
+ * The value at which an alert will fire. For credit balance alerts, the alert will
286
+ * fire at or below this value. For usage and cost alerts, the alert will fire at
287
+ * or above this value.
288
+ */
289
+ value: number;
290
+ }
291
+ }
292
+
293
+ export interface AlertCreateForSubscriptionParams {
294
+ /**
295
+ * The thresholds for the alert.
296
+ */
297
+ thresholds: Array<AlertCreateForSubscriptionParams.Threshold>;
298
+
299
+ /**
300
+ * The thresholds that define the values at which the alert will be triggered.
301
+ */
302
+ type: string;
303
+
304
+ /**
305
+ * The metric to track usage for.
306
+ */
307
+ metric_id?: string | null;
308
+ }
309
+
310
+ export namespace AlertCreateForSubscriptionParams {
311
+ /**
312
+ * Thresholds are used to define the conditions under which an alert will be
313
+ * triggered.
314
+ */
315
+ export interface Threshold {
316
+ /**
317
+ * The value at which an alert will fire. For credit balance alerts, the alert will
318
+ * fire at or below this value. For usage and cost alerts, the alert will fire at
319
+ * or above this value.
93
320
  */
94
321
  value: number;
95
322
  }
@@ -97,4 +324,9 @@ export namespace Alert {
97
324
 
98
325
  export namespace Alerts {
99
326
  export import Alert = AlertsAPI.Alert;
327
+ export import AlertsPage = AlertsAPI.AlertsPage;
328
+ export import AlertListParams = AlertsAPI.AlertListParams;
329
+ export import AlertCreateForCustomerParams = AlertsAPI.AlertCreateForCustomerParams;
330
+ export import AlertCreateForExternalCustomerParams = AlertsAPI.AlertCreateForExternalCustomerParams;
331
+ export import AlertCreateForSubscriptionParams = AlertsAPI.AlertCreateForSubscriptionParams;
100
332
  }
@@ -86,11 +86,11 @@ export class Costs extends APIResource {
86
86
  *
87
87
  * ## Timeframe bounds
88
88
  *
89
- * If no timeframe bounds are specified, the response will default to the current
90
- * billing period for the customer's subscription. For subscriptions that have
91
- * ended, this will be the billing period when they were last active. If the
92
- * subscription starts or ends within the timeframe, the response will only include
93
- * windows where the subscription is active.
89
+ * For an active subscription, both timeframes should be specified in the request.
90
+ * If a subscription starts or ends within the timeframe, the response will only
91
+ * include windows where the subscription is active. If a subscription has ended,
92
+ * no timeframe bounds need to be specified and the response will default to the
93
+ * billing period when the subscription was last active.
94
94
  *
95
95
  * As noted above, `timeframe_start` for a given cumulative datapoint is always the
96
96
  * beginning of the billing period, and `timeframe_end` is incremented one day at a
@@ -239,11 +239,11 @@ export class Costs extends APIResource {
239
239
  *
240
240
  * ## Timeframe bounds
241
241
  *
242
- * If no timeframe bounds are specified, the response will default to the current
243
- * billing period for the customer's subscription. For subscriptions that have
244
- * ended, this will be the billing period when they were last active. If the
245
- * subscription starts or ends within the timeframe, the response will only include
246
- * windows where the subscription is active.
242
+ * For an active subscription, both timeframes should be specified in the request.
243
+ * If a subscription starts or ends within the timeframe, the response will only
244
+ * include windows where the subscription is active. If a subscription has ended,
245
+ * no timeframe bounds need to be specified and the response will default to the
246
+ * billing period when the subscription was last active.
247
247
  *
248
248
  * As noted above, `timeframe_start` for a given cumulative datapoint is always the
249
249
  * beginning of the billing period, and `timeframe_end` is incremented one day at a
@@ -33,6 +33,10 @@ export class Backfills extends APIResource {
33
33
  * timeframe will be replaced with the newly ingested events associated with the
34
34
  * backfill. If `false`, newly ingested events will be added to the existing
35
35
  * events.
36
+ *
37
+ * If a `customer_id` or `external_customer_id` is specified, the backfill will
38
+ * only affect events for that customer. If neither is specified, the backfill will
39
+ * affect all customers.
36
40
  */
37
41
  create(body: BackfillCreateParams, options?: Core.RequestOptions): Core.APIPromise<BackfillCreateResponse> {
38
42
  return this._client.post('/events/backfills', { body, ...options });
@@ -241,7 +241,9 @@ export class Events extends APIResource {
241
241
  * Orb's idempotency guarantees allow you to implement safe retry logic in the
242
242
  * event of network or machine failures, ensuring data fidelity. Each event in the
243
243
  * request payload is associated with an idempotency key, and Orb guarantees that a
244
- * single idempotency key will be successfully ingested at most once.
244
+ * single idempotency key will be successfully ingested at most once. Note that
245
+ * when Orb encounters events with duplicate idempotency keys and differing event
246
+ * bodies in a batch of events, the entire batch will be rejected.
245
247
  *
246
248
  * - Successful responses return a 200 HTTP status code. The response contains
247
249
  * information about previously processed events.
@@ -1,7 +1,15 @@
1
1
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
2
 
3
3
  export * from './shared';
4
- export { Alert, Alerts } from './alerts';
4
+ export {
5
+ Alert,
6
+ AlertListParams,
7
+ AlertCreateForCustomerParams,
8
+ AlertCreateForExternalCustomerParams,
9
+ AlertCreateForSubscriptionParams,
10
+ AlertsPage,
11
+ Alerts,
12
+ } from './alerts';
5
13
  export { Coupon, CouponCreateParams, CouponListParams, CouponsPage, Coupons } from './coupons/coupons';
6
14
  export { CreditNote, CreditNoteListParams, CreditNotesPage, CreditNotes } from './credit-notes';
7
15
  export {
@@ -1074,7 +1074,7 @@ export interface Subscription {
1074
1074
  /**
1075
1075
  * Determines whether issued invoices for this subscription will automatically be
1076
1076
  * charged with the saved payment method on the due date. This property defaults to
1077
- * the plan's behavior.
1077
+ * the plan's behavior. If null, defaults to the customer's setting.
1078
1078
  */
1079
1079
  auto_collection: boolean | null;
1080
1080
 
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const VERSION = '2.5.1'; // x-release-please-version
1
+ export const VERSION = '2.6.1'; // x-release-please-version
package/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "2.5.1";
1
+ export declare const VERSION = "2.6.1";
2
2
  //# sourceMappingURL=version.d.ts.map
package/version.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
- exports.VERSION = '2.5.1'; // x-release-please-version
4
+ exports.VERSION = '2.6.1'; // x-release-please-version
5
5
  //# sourceMappingURL=version.js.map
package/version.mjs CHANGED
@@ -1,2 +1,2 @@
1
- export const VERSION = '2.5.1'; // x-release-please-version
1
+ export const VERSION = '2.6.1'; // x-release-please-version
2
2
  //# sourceMappingURL=version.mjs.map