orb-billing 2.4.0 → 2.6.0

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 (47) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/index.d.mts +232 -5
  3. package/index.d.ts +232 -5
  4. package/index.d.ts.map +1 -1
  5. package/index.js +133 -10
  6. package/index.js.map +1 -1
  7. package/index.mjs +130 -5
  8. package/index.mjs.map +1 -1
  9. package/package.json +1 -1
  10. package/resources/alerts.d.ts +340 -0
  11. package/resources/alerts.d.ts.map +1 -0
  12. package/resources/alerts.js +134 -0
  13. package/resources/alerts.js.map +1 -0
  14. package/resources/alerts.mjs +106 -0
  15. package/resources/alerts.mjs.map +1 -0
  16. package/resources/customers/customers.d.ts +592 -432
  17. package/resources/customers/customers.d.ts.map +1 -1
  18. package/resources/customers/customers.js.map +1 -1
  19. package/resources/customers/customers.mjs.map +1 -1
  20. package/resources/index.d.ts +1 -0
  21. package/resources/index.d.ts.map +1 -1
  22. package/resources/index.js +4 -1
  23. package/resources/index.js.map +1 -1
  24. package/resources/index.mjs +1 -0
  25. package/resources/index.mjs.map +1 -1
  26. package/resources/invoices.d.ts +296 -216
  27. package/resources/invoices.d.ts.map +1 -1
  28. package/resources/invoices.js.map +1 -1
  29. package/resources/invoices.mjs.map +1 -1
  30. package/resources/subscriptions.d.ts +1 -1
  31. package/src/index.ts +311 -6
  32. package/src/resources/alerts.ts +466 -0
  33. package/src/resources/customers/customers.ts +728 -424
  34. package/src/resources/index.ts +12 -0
  35. package/src/resources/invoices.ts +364 -212
  36. package/src/resources/subscriptions.ts +1 -1
  37. package/src/version.ts +1 -1
  38. package/version.d.ts +1 -1
  39. package/version.js +1 -1
  40. package/version.mjs +1 -1
  41. package/client.d.ts +0 -222
  42. package/client.d.ts.map +0 -1
  43. package/client.js +0 -156
  44. package/client.js.map +0 -1
  45. package/client.mjs +0 -129
  46. package/client.mjs.map +0 -1
  47. package/src/client.ts +0 -301
@@ -0,0 +1,466 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import * as Core from "../core";
4
+ import { APIResource } from "../resource";
5
+ import { isRequestOptions } from "../core";
6
+ import * as AlertsAPI from "./alerts";
7
+ import { Page, type PageParams } from "../pagination";
8
+
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 all
19
+ * [`alerts`](https://docs.withorb.com/guides/product-catalog/configuring-alerts).
20
+ *
21
+ * The list of alerts is ordered starting from the most recently created alert.
22
+ * This endpoint follows Orb's
23
+ * [standardized pagination format](../reference/pagination).
24
+ *
25
+ * The request must specify one of customer_id, external_customer_id,
26
+ * subscription_id, or plan_id
27
+ *
28
+ * If querying by subscripion_id, the endpoint will return the subscription level
29
+ * alerts as well as the plan level alerts associated with the subscription.
30
+ */
31
+ list(query?: AlertListParams, options?: Core.RequestOptions): Core.PagePromise<AlertsPage, Alert>;
32
+ list(options?: Core.RequestOptions): Core.PagePromise<AlertsPage, Alert>;
33
+ list(
34
+ query: AlertListParams | Core.RequestOptions = {},
35
+ options?: Core.RequestOptions,
36
+ ): Core.PagePromise<AlertsPage, Alert> {
37
+ if (isRequestOptions(query)) {
38
+ return this.list({}, query);
39
+ }
40
+ return this._client.getAPIList('/alerts', AlertsPage, { query, ...options });
41
+ }
42
+
43
+ /**
44
+ * This endpoint creates a new alert to monitor a customer's credit balance. There
45
+ * are three types of alerts that can be scoped to customers:
46
+ * `credit_balance_depleted`, `credit_balance_dropped`, and
47
+ * `credit_balance_recovered`. Customers can have a maximum of one of each type of
48
+ * alert per
49
+ * [credit balance currency](https://docs.withorb.com/guides/product-catalog/prepurchase).
50
+ * `credit_balance_dropped` alerts require a list of thresholds to be provided
51
+ * while `credit_balance_depleted` and `credit_balance_recovered` alerts do not
52
+ * require thresholds.
53
+ */
54
+ createForCustomer(
55
+ customerId: string,
56
+ body: AlertCreateForCustomerParams,
57
+ options?: Core.RequestOptions,
58
+ ): Core.APIPromise<Alert> {
59
+ return this._client.post(`/alerts/customer_id/${customerId}`, { body, ...options });
60
+ }
61
+
62
+ /**
63
+ * This endpoint creates a new alert to monitor a customer's credit balance. There
64
+ * are three types of alerts that can be scoped to customers:
65
+ * `credit_balance_depleted`, `credit_balance_dropped`, and
66
+ * `credit_balance_recovered`. Customers can have a maximum of one of each type of
67
+ * alert per
68
+ * [credit balance currency](https://docs.withorb.com/guides/product-catalog/prepurchase).
69
+ * `credit_balance_dropped` alerts require a list of thresholds to be provided
70
+ * while `credit_balance_depleted` and `credit_balance_recovered` alerts do not
71
+ * require thresholds.
72
+ */
73
+ createForExternalCustomer(
74
+ externalCustomerId: string,
75
+ body: AlertCreateForExternalCustomerParams,
76
+ options?: Core.RequestOptions,
77
+ ): Core.APIPromise<Alert> {
78
+ return this._client.post(`/alerts/external_customer_id/${externalCustomerId}`, { body, ...options });
79
+ }
80
+
81
+ /**
82
+ * This endpoint is used to create alerts at the plan level. Plan level alerts are
83
+ * automatically propagated to all subscriptions associated with the plan. These
84
+ * alerts are scoped to a specific plan version; if no version is specified, the
85
+ * active plan version is used.
86
+ *
87
+ * Plan level alerts can be of two types: `usage_exceeded` or `cost_exceeded`. A
88
+ * `usage_exceeded` alert is scoped to a particular metric and is triggered when
89
+ * the usage of that metric exceeds a predefined thresholds during the current
90
+ * invoice cycle. A `cost_exceeded` alert is triggered when the total cost of the
91
+ * subscription on the plan surpasses predefined thresholds in the current invoice
92
+ * cycle.Each plan can have one `cost_exceeded` alert and one `usage_exceeded`
93
+ * alert per metric that is apart of the plan.
94
+ */
95
+ createForPlan(
96
+ planId: string,
97
+ body: AlertCreateForPlanParams,
98
+ options?: Core.RequestOptions,
99
+ ): Core.APIPromise<Alert> {
100
+ return this._client.post(`/alerts/plan_id/${planId}`, { body, ...options });
101
+ }
102
+
103
+ /**
104
+ * This endpoint is used to create alerts at the subscription level.
105
+ *
106
+ * Subscription level alerts can be one of two types: `usage_exceeded` or
107
+ * `cost_exceeded`. A `usage_exceeded` alert is scoped to a particular metric and
108
+ * is triggered when the usage of that metric exceeds a predefined thresholds
109
+ * during the current invoice cycle. A `cost_exceeded` alert is triggered when the
110
+ * total cost of the subscription surpasses predefined thresholds in the current
111
+ * invoice cycle. Each subscription can have one `cost_exceeded` alert and one
112
+ * `usage_exceeded` alert per metric that is apart of the subscription. Alerts are
113
+ * triggered based on usage or cost conditions met during the current invoice
114
+ * cycle.
115
+ */
116
+ createForSubscription(
117
+ subscriptionId: string,
118
+ body: AlertCreateForSubscriptionParams,
119
+ options?: Core.RequestOptions,
120
+ ): Core.APIPromise<Alert> {
121
+ return this._client.post(`/alerts/subscription_id/${subscriptionId}`, { body, ...options });
122
+ }
123
+
124
+ /**
125
+ * This endpoint can be used to disable an alert.
126
+ *
127
+ * By default, disabling a plan level alert will apply to all subscriptions on that
128
+ * plan. In order to toggle a plan level alert for a specific subscription, the
129
+ * client must provide the plan level alert id as well as the subscription_id
130
+ * parameter.
131
+ */
132
+ disable(
133
+ alertConfigurationId: string,
134
+ params?: AlertDisableParams,
135
+ options?: Core.RequestOptions,
136
+ ): Core.APIPromise<Alert>;
137
+ disable(alertConfigurationId: string, options?: Core.RequestOptions): Core.APIPromise<Alert>;
138
+ disable(
139
+ alertConfigurationId: string,
140
+ params: AlertDisableParams | Core.RequestOptions = {},
141
+ options?: Core.RequestOptions,
142
+ ): Core.APIPromise<Alert> {
143
+ if (isRequestOptions(params)) {
144
+ return this.disable(alertConfigurationId, {}, params);
145
+ }
146
+ const { subscription_id } = params;
147
+ return this._client.post(`/alerts/${alertConfigurationId}/disable`, {
148
+ query: { subscription_id },
149
+ ...options,
150
+ });
151
+ }
152
+
153
+ /**
154
+ * This endpoint can be used to enable an alert.
155
+ *
156
+ * By default, enabling a plan level alert will apply to all subscriptions on that
157
+ * plan. In order to toggle a plan level alert for a specific subscription, the
158
+ * client must provide the plan level alert id as well as the subscription_id
159
+ * parameter.
160
+ */
161
+ enable(
162
+ alertConfigurationId: string,
163
+ params?: AlertEnableParams,
164
+ options?: Core.RequestOptions,
165
+ ): Core.APIPromise<Alert>;
166
+ enable(alertConfigurationId: string, options?: Core.RequestOptions): Core.APIPromise<Alert>;
167
+ enable(
168
+ alertConfigurationId: string,
169
+ params: AlertEnableParams | Core.RequestOptions = {},
170
+ options?: Core.RequestOptions,
171
+ ): Core.APIPromise<Alert> {
172
+ if (isRequestOptions(params)) {
173
+ return this.enable(alertConfigurationId, {}, params);
174
+ }
175
+ const { subscription_id } = params;
176
+ return this._client.post(`/alerts/${alertConfigurationId}/enable`, {
177
+ query: { subscription_id },
178
+ ...options,
179
+ });
180
+ }
181
+ }
182
+
183
+ export class AlertsPage extends Page<Alert> {}
184
+
185
+ /**
186
+ * An
187
+ * [Alert within Orb](https://docs.withorb.com/guides/product-catalog/configuring-alerts)
188
+ * monitors a customer's spending, usage, or credit balance and triggers a webhook
189
+ * when a threshold is exceeded.
190
+ *
191
+ * Alerts can be configured to monitor usage, cost, or credit balance. Alerts can
192
+ * be scoped to either a customer, a plan, or a subscription.
193
+ *
194
+ * Customer scoped alerts track a customer's credit balance. Valid customer alert
195
+ * types are "credit_balance_depleted", "credit_balance_recovered", and
196
+ * "credit_balance_dropped".
197
+ *
198
+ * Subscription scoped alerts track a subscriptions's usage or cost. Valid plan
199
+ * alert types are "usage_exceeded" or "cost_exceeded".
200
+ *
201
+ * Plan scoped alerts are similar to subscriptions alerts but when a plan alert is
202
+ * created, it is propagated to all subscriptions associated with the plan.
203
+ * Disabling a plan alert will disable the alert for all subscriptions. Valid plan
204
+ * alert types are "usage_exceeded" or "cost_exceeded".
205
+ */
206
+ export interface Alert {
207
+ /**
208
+ * Also referred to as alert_id in this documentation.
209
+ */
210
+ id: string;
211
+
212
+ /**
213
+ * The creation time of the resource in Orb.
214
+ */
215
+ created_at: string;
216
+
217
+ /**
218
+ * The name of the currency the credit balance for this alert is denominated in.
219
+ */
220
+ currency: string | null;
221
+
222
+ /**
223
+ * The customer the alert applies to.
224
+ */
225
+ customer: Record<string, string | null> | null;
226
+
227
+ /**
228
+ * Whether the alert is enabled or disabled.
229
+ */
230
+ enabled: boolean;
231
+
232
+ /**
233
+ * The metric the alert applies to.
234
+ */
235
+ metric: Record<string, string | null> | null;
236
+
237
+ /**
238
+ * The plan the alert applies to.
239
+ */
240
+ plan: Record<string, string | null> | null;
241
+
242
+ /**
243
+ * The subscription the alert applies to.
244
+ */
245
+ subscription: Record<string, string | null> | null;
246
+
247
+ /**
248
+ * The thresholds that define the conditions under which the alert will be
249
+ * triggered.
250
+ */
251
+ thresholds: Array<Alert.Threshold> | null;
252
+
253
+ /**
254
+ * The type of alert. This must be a valid alert type.
255
+ */
256
+ type:
257
+ | 'usage_exceeded'
258
+ | 'cost_exceeded'
259
+ | 'credit_balance_depleted'
260
+ | 'credit_balance_dropped'
261
+ | 'credit_balance_recovered';
262
+ }
263
+
264
+ export namespace Alert {
265
+ /**
266
+ * Thresholds are used to define the conditions under which an alert will be
267
+ * triggered.
268
+ */
269
+ export interface Threshold {
270
+ /**
271
+ * The value at which an alert will fire. For credit balance alerts, the alert will fire at or below this value. For usage and
272
+ * cost alerts, the alert will fire at or above this value.
273
+ */
274
+ value: number;
275
+ }
276
+ }
277
+
278
+ export interface AlertListParams extends PageParams {
279
+ 'created_at[gt]'?: string | null;
280
+
281
+ 'created_at[gte]'?: string | null;
282
+
283
+ 'created_at[lt]'?: string | null;
284
+
285
+ 'created_at[lte]'?: string | null;
286
+
287
+ /**
288
+ * Fetch alerts scoped to this customer_id
289
+ */
290
+ customer_id?: string | null;
291
+
292
+ /**
293
+ * Fetch alerts scoped to this external_customer_id
294
+ */
295
+ external_customer_id?: string | null;
296
+
297
+ /**
298
+ * Fetch alerts scoped to this plan_id
299
+ */
300
+ plan_id?: string | null;
301
+
302
+ /**
303
+ * If provided alongside plan_id, only the alerts that are scoped to the specified plan_version will be returned.
304
+ */
305
+ plan_version?: number | null;
306
+
307
+ /**
308
+ * Fetch alerts scoped to this subscription_id
309
+ */
310
+ subscription_id?: string | null;
311
+ }
312
+
313
+ export interface AlertCreateForCustomerParams {
314
+ /**
315
+ * The case sensitive currency or custom pricing unit to use for this alert.
316
+ */
317
+ currency: string;
318
+
319
+ /**
320
+ * The thresholds that define the values at which the alert will be triggered.
321
+ */
322
+ type: string;
323
+
324
+ /**
325
+ * The thresholds for the alert.
326
+ */
327
+ thresholds?: Array<AlertCreateForCustomerParams.Threshold> | null;
328
+ }
329
+
330
+ export namespace AlertCreateForCustomerParams {
331
+ /**
332
+ * Thresholds are used to define the conditions under which an alert will be
333
+ * triggered.
334
+ */
335
+ export interface Threshold {
336
+ /**
337
+ * The value at which an alert will fire. For credit balance alerts, the alert will fire at or below this value. For usage and
338
+ * cost alerts, the alert will fire at or above this value.
339
+ */
340
+ value: number;
341
+ }
342
+ }
343
+
344
+ export interface AlertCreateForExternalCustomerParams {
345
+ /**
346
+ * The case sensitive currency or custom pricing unit to use for this alert.
347
+ */
348
+ currency: string;
349
+
350
+ /**
351
+ * The thresholds that define the values at which the alert will be triggered.
352
+ */
353
+ type: string;
354
+
355
+ /**
356
+ * The thresholds for the alert.
357
+ */
358
+ thresholds?: Array<AlertCreateForExternalCustomerParams.Threshold> | null;
359
+ }
360
+
361
+ export namespace AlertCreateForExternalCustomerParams {
362
+ /**
363
+ * Thresholds are used to define the conditions under which an alert will be
364
+ * triggered.
365
+ */
366
+ export interface Threshold {
367
+ /**
368
+ * The value at which an alert will fire. For credit balance alerts, the alert will fire at or below this value. For usage and
369
+ * cost alerts, the alert will fire at or above this value.
370
+ */
371
+ value: number;
372
+ }
373
+ }
374
+
375
+ export interface AlertCreateForPlanParams {
376
+ /**
377
+ * The thresholds for the alert.
378
+ */
379
+ thresholds: Array<AlertCreateForPlanParams.Threshold>;
380
+
381
+ /**
382
+ * The thresholds that define the values at which the alert will be triggered.
383
+ */
384
+ type: string;
385
+
386
+ /**
387
+ * The metric to track usage for.
388
+ */
389
+ metric_id?: string | null;
390
+
391
+ /**
392
+ * The plan version to create alerts for. If not specified, the default will be the plan's active plan version.
393
+ */
394
+ plan_version?: number | null;
395
+ }
396
+
397
+ export namespace AlertCreateForPlanParams {
398
+ /**
399
+ * Thresholds are used to define the conditions under which an alert will be
400
+ * triggered.
401
+ */
402
+ export interface Threshold {
403
+ /**
404
+ * The value at which an alert will fire. For credit balance alerts, the alert will fire at or below this value. For usage and
405
+ * cost alerts, the alert will fire at or above this value.
406
+ */
407
+ value: number;
408
+ }
409
+ }
410
+
411
+ export interface AlertCreateForSubscriptionParams {
412
+ /**
413
+ * The thresholds for the alert.
414
+ */
415
+ thresholds: Array<AlertCreateForSubscriptionParams.Threshold>;
416
+
417
+ /**
418
+ * The thresholds that define the values at which the alert will be triggered.
419
+ */
420
+ type: string;
421
+
422
+ /**
423
+ * The metric to track usage for.
424
+ */
425
+ metric_id?: string | null;
426
+ }
427
+
428
+ export namespace AlertCreateForSubscriptionParams {
429
+ /**
430
+ * Thresholds are used to define the conditions under which an alert will be
431
+ * triggered.
432
+ */
433
+ export interface Threshold {
434
+ /**
435
+ * The value at which an alert will fire. For credit balance alerts, the alert will fire at or below this value. For usage and
436
+ * cost alerts, the alert will fire at or above this value.
437
+ */
438
+ value: number;
439
+ }
440
+ }
441
+
442
+ export interface AlertDisableParams {
443
+ /**
444
+ * Used to update the status of a plan alert scoped to this subscription_id
445
+ */
446
+ subscription_id?: string | null;
447
+ }
448
+
449
+ export interface AlertEnableParams {
450
+ /**
451
+ * Used to update the status of a plan alert scoped to this subscription_id
452
+ */
453
+ subscription_id?: string | null;
454
+ }
455
+
456
+ export namespace Alerts {
457
+ export import Alert = AlertsAPI.Alert;
458
+ export import AlertsPage = AlertsAPI.AlertsPage;
459
+ export import AlertListParams = AlertsAPI.AlertListParams;
460
+ export import AlertCreateForCustomerParams = AlertsAPI.AlertCreateForCustomerParams;
461
+ export import AlertCreateForExternalCustomerParams = AlertsAPI.AlertCreateForExternalCustomerParams;
462
+ export import AlertCreateForPlanParams = AlertsAPI.AlertCreateForPlanParams;
463
+ export import AlertCreateForSubscriptionParams = AlertsAPI.AlertCreateForSubscriptionParams;
464
+ export import AlertDisableParams = AlertsAPI.AlertDisableParams;
465
+ export import AlertEnableParams = AlertsAPI.AlertEnableParams;
466
+ }