orb-billing 4.32.0 → 4.47.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 (252) hide show
  1. package/CHANGELOG.md +184 -0
  2. package/LICENSE +1 -1
  3. package/README.md +12 -3
  4. package/core.d.ts +4 -5
  5. package/core.d.ts.map +1 -1
  6. package/core.js +16 -11
  7. package/core.js.map +1 -1
  8. package/core.mjs +16 -11
  9. package/core.mjs.map +1 -1
  10. package/error.d.ts +30 -36
  11. package/error.d.ts.map +1 -1
  12. package/error.js +24 -43
  13. package/error.js.map +1 -1
  14. package/error.mjs +24 -43
  15. package/error.mjs.map +1 -1
  16. package/index.d.mts +43 -109
  17. package/index.d.ts +43 -109
  18. package/index.d.ts.map +1 -1
  19. package/index.js +71 -33
  20. package/index.js.map +1 -1
  21. package/index.mjs +43 -32
  22. package/index.mjs.map +1 -1
  23. package/package.json +2 -2
  24. package/resources/alerts.d.ts +58 -19
  25. package/resources/alerts.d.ts.map +1 -1
  26. package/resources/alerts.js +19 -37
  27. package/resources/alerts.js.map +1 -1
  28. package/resources/alerts.mjs +19 -14
  29. package/resources/alerts.mjs.map +1 -1
  30. package/resources/coupons/coupons.d.ts +3 -7
  31. package/resources/coupons/coupons.d.ts.map +1 -1
  32. package/resources/coupons/coupons.js +3 -5
  33. package/resources/coupons/coupons.js.map +1 -1
  34. package/resources/coupons/coupons.mjs +3 -5
  35. package/resources/coupons/coupons.mjs.map +1 -1
  36. package/resources/coupons/index.d.ts +2 -2
  37. package/resources/coupons/index.d.ts.map +1 -1
  38. package/resources/coupons/index.js.map +1 -1
  39. package/resources/coupons/index.mjs.map +1 -1
  40. package/resources/coupons/subscriptions.d.ts +1 -2
  41. package/resources/coupons/subscriptions.d.ts.map +1 -1
  42. package/resources/coupons/subscriptions.js +0 -2
  43. package/resources/coupons/subscriptions.js.map +1 -1
  44. package/resources/coupons/subscriptions.mjs +0 -2
  45. package/resources/coupons/subscriptions.mjs.map +1 -1
  46. package/resources/credit-notes.d.ts +29 -4
  47. package/resources/credit-notes.d.ts.map +1 -1
  48. package/resources/credit-notes.js +8 -27
  49. package/resources/credit-notes.js.map +1 -1
  50. package/resources/credit-notes.mjs +8 -4
  51. package/resources/credit-notes.mjs.map +1 -1
  52. package/resources/customers/balance-transactions.d.ts +1 -6
  53. package/resources/customers/balance-transactions.d.ts.map +1 -1
  54. package/resources/customers/balance-transactions.js +1 -27
  55. package/resources/customers/balance-transactions.js.map +1 -1
  56. package/resources/customers/balance-transactions.mjs +1 -4
  57. package/resources/customers/balance-transactions.mjs.map +1 -1
  58. package/resources/customers/costs.d.ts +1 -5
  59. package/resources/customers/costs.d.ts.map +1 -1
  60. package/resources/customers/costs.js +0 -2
  61. package/resources/customers/costs.js.map +1 -1
  62. package/resources/customers/costs.mjs +0 -2
  63. package/resources/customers/costs.mjs.map +1 -1
  64. package/resources/customers/credits/credits.d.ts +15 -31
  65. package/resources/customers/credits/credits.d.ts.map +1 -1
  66. package/resources/customers/credits/credits.js +10 -11
  67. package/resources/customers/credits/credits.js.map +1 -1
  68. package/resources/customers/credits/credits.mjs +10 -11
  69. package/resources/customers/credits/credits.mjs.map +1 -1
  70. package/resources/customers/credits/index.d.ts +3 -3
  71. package/resources/customers/credits/index.d.ts.map +1 -1
  72. package/resources/customers/credits/index.js.map +1 -1
  73. package/resources/customers/credits/index.mjs.map +1 -1
  74. package/resources/customers/credits/ledger.d.ts +15 -23
  75. package/resources/customers/credits/ledger.d.ts.map +1 -1
  76. package/resources/customers/credits/ledger.js +12 -36
  77. package/resources/customers/credits/ledger.js.map +1 -1
  78. package/resources/customers/credits/ledger.mjs +12 -13
  79. package/resources/customers/credits/ledger.mjs.map +1 -1
  80. package/resources/customers/credits/top-ups.d.ts +1 -11
  81. package/resources/customers/credits/top-ups.d.ts.map +1 -1
  82. package/resources/customers/credits/top-ups.js +2 -28
  83. package/resources/customers/credits/top-ups.js.map +1 -1
  84. package/resources/customers/credits/top-ups.mjs +2 -5
  85. package/resources/customers/credits/top-ups.mjs.map +1 -1
  86. package/resources/customers/customers.d.ts +9 -29
  87. package/resources/customers/customers.d.ts.map +1 -1
  88. package/resources/customers/customers.js +25 -18
  89. package/resources/customers/customers.js.map +1 -1
  90. package/resources/customers/customers.mjs +25 -18
  91. package/resources/customers/customers.mjs.map +1 -1
  92. package/resources/customers/index.d.ts +4 -4
  93. package/resources/customers/index.d.ts.map +1 -1
  94. package/resources/customers/index.js.map +1 -1
  95. package/resources/customers/index.mjs.map +1 -1
  96. package/resources/dimensional-price-groups/dimensional-price-groups.d.ts +90 -0
  97. package/resources/dimensional-price-groups/dimensional-price-groups.d.ts.map +1 -0
  98. package/resources/dimensional-price-groups/dimensional-price-groups.js +73 -0
  99. package/resources/dimensional-price-groups/dimensional-price-groups.js.map +1 -0
  100. package/resources/dimensional-price-groups/dimensional-price-groups.mjs +45 -0
  101. package/resources/dimensional-price-groups/dimensional-price-groups.mjs.map +1 -0
  102. package/resources/dimensional-price-groups/external-dimensional-price-group-id.d.ts +10 -0
  103. package/resources/dimensional-price-groups/external-dimensional-price-group-id.d.ts.map +1 -0
  104. package/resources/dimensional-price-groups/external-dimensional-price-group-id.js +15 -0
  105. package/resources/dimensional-price-groups/external-dimensional-price-group-id.js.map +1 -0
  106. package/resources/dimensional-price-groups/external-dimensional-price-group-id.mjs +11 -0
  107. package/resources/dimensional-price-groups/external-dimensional-price-group-id.mjs.map +1 -0
  108. package/resources/dimensional-price-groups/index.d.ts +3 -0
  109. package/resources/dimensional-price-groups/index.d.ts.map +1 -0
  110. package/resources/dimensional-price-groups/index.js +9 -0
  111. package/resources/dimensional-price-groups/index.js.map +1 -0
  112. package/resources/dimensional-price-groups/index.mjs +4 -0
  113. package/resources/dimensional-price-groups/index.mjs.map +1 -0
  114. package/resources/events/backfills.d.ts +5 -11
  115. package/resources/events/backfills.d.ts.map +1 -1
  116. package/resources/events/backfills.js +5 -29
  117. package/resources/events/backfills.js.map +1 -1
  118. package/resources/events/backfills.mjs +5 -6
  119. package/resources/events/backfills.mjs.map +1 -1
  120. package/resources/events/events.d.ts +7 -22
  121. package/resources/events/events.d.ts.map +1 -1
  122. package/resources/events/events.js +7 -7
  123. package/resources/events/events.js.map +1 -1
  124. package/resources/events/events.mjs +7 -7
  125. package/resources/events/events.mjs.map +1 -1
  126. package/resources/events/index.d.ts +3 -3
  127. package/resources/events/index.d.ts.map +1 -1
  128. package/resources/events/index.js.map +1 -1
  129. package/resources/events/index.mjs.map +1 -1
  130. package/resources/events/volume.d.ts +9 -12
  131. package/resources/events/volume.d.ts.map +1 -1
  132. package/resources/events/volume.js +16 -7
  133. package/resources/events/volume.js.map +1 -1
  134. package/resources/events/volume.mjs +16 -7
  135. package/resources/events/volume.mjs.map +1 -1
  136. package/resources/index.d.ts +14 -13
  137. package/resources/index.d.ts.map +1 -1
  138. package/resources/index.js +10 -7
  139. package/resources/index.js.map +1 -1
  140. package/resources/index.mjs +8 -7
  141. package/resources/index.mjs.map +1 -1
  142. package/resources/invoice-line-items.d.ts +1 -3
  143. package/resources/invoice-line-items.d.ts.map +1 -1
  144. package/resources/invoice-line-items.js +0 -2
  145. package/resources/invoice-line-items.js.map +1 -1
  146. package/resources/invoice-line-items.mjs +0 -2
  147. package/resources/invoice-line-items.mjs.map +1 -1
  148. package/resources/invoices.d.ts +81 -18
  149. package/resources/invoices.d.ts.map +1 -1
  150. package/resources/invoices.js +22 -35
  151. package/resources/invoices.js.map +1 -1
  152. package/resources/invoices.mjs +22 -12
  153. package/resources/invoices.mjs.map +1 -1
  154. package/resources/items.d.ts +2 -8
  155. package/resources/items.d.ts.map +1 -1
  156. package/resources/items.js +5 -31
  157. package/resources/items.js.map +1 -1
  158. package/resources/items.mjs +5 -8
  159. package/resources/items.mjs.map +1 -1
  160. package/resources/metrics.d.ts +2 -8
  161. package/resources/metrics.d.ts.map +1 -1
  162. package/resources/metrics.js +7 -31
  163. package/resources/metrics.js.map +1 -1
  164. package/resources/metrics.mjs +7 -8
  165. package/resources/metrics.mjs.map +1 -1
  166. package/resources/plans/external-plan-id.d.ts +2 -4
  167. package/resources/plans/external-plan-id.d.ts.map +1 -1
  168. package/resources/plans/external-plan-id.js +7 -7
  169. package/resources/plans/external-plan-id.js.map +1 -1
  170. package/resources/plans/external-plan-id.mjs +7 -7
  171. package/resources/plans/external-plan-id.mjs.map +1 -1
  172. package/resources/plans/index.d.ts +2 -2
  173. package/resources/plans/index.d.ts.map +1 -1
  174. package/resources/plans/index.js.map +1 -1
  175. package/resources/plans/index.mjs +1 -1
  176. package/resources/plans/index.mjs.map +1 -1
  177. package/resources/plans/plans.d.ts +332 -11
  178. package/resources/plans/plans.d.ts.map +1 -1
  179. package/resources/plans/plans.js +10 -9
  180. package/resources/plans/plans.js.map +1 -1
  181. package/resources/plans/plans.mjs +10 -9
  182. package/resources/plans/plans.mjs.map +1 -1
  183. package/resources/prices/external-price-id.d.ts +2 -4
  184. package/resources/prices/external-price-id.d.ts.map +1 -1
  185. package/resources/prices/external-price-id.js +6 -7
  186. package/resources/prices/external-price-id.js.map +1 -1
  187. package/resources/prices/external-price-id.mjs +6 -7
  188. package/resources/prices/external-price-id.mjs.map +1 -1
  189. package/resources/prices/index.d.ts +2 -2
  190. package/resources/prices/index.d.ts.map +1 -1
  191. package/resources/prices/index.js +3 -3
  192. package/resources/prices/index.js.map +1 -1
  193. package/resources/prices/index.mjs +1 -1
  194. package/resources/prices/index.mjs.map +1 -1
  195. package/resources/prices/prices.d.ts +340 -15
  196. package/resources/prices/prices.d.ts.map +1 -1
  197. package/resources/prices/prices.js +9 -9
  198. package/resources/prices/prices.js.map +1 -1
  199. package/resources/prices/prices.mjs +9 -9
  200. package/resources/prices/prices.mjs.map +1 -1
  201. package/resources/subscriptions.d.ts +7636 -200
  202. package/resources/subscriptions.d.ts.map +1 -1
  203. package/resources/subscriptions.js +348 -47
  204. package/resources/subscriptions.js.map +1 -1
  205. package/resources/subscriptions.mjs +348 -24
  206. package/resources/subscriptions.mjs.map +1 -1
  207. package/resources/top-level.d.ts +1 -2
  208. package/resources/top-level.d.ts.map +1 -1
  209. package/resources/top-level.js +0 -2
  210. package/resources/top-level.js.map +1 -1
  211. package/resources/top-level.mjs +0 -2
  212. package/resources/top-level.mjs.map +1 -1
  213. package/src/core.ts +23 -19
  214. package/src/error.ts +82 -125
  215. package/src/index.ts +334 -130
  216. package/src/resources/alerts.ts +117 -24
  217. package/src/resources/coupons/coupons.ts +13 -8
  218. package/src/resources/coupons/index.ts +2 -2
  219. package/src/resources/coupons/subscriptions.ts +2 -3
  220. package/src/resources/credit-notes.ts +45 -5
  221. package/src/resources/customers/balance-transactions.ts +10 -7
  222. package/src/resources/customers/costs.ts +7 -6
  223. package/src/resources/customers/credits/credits.ts +82 -32
  224. package/src/resources/customers/credits/index.ts +20 -20
  225. package/src/resources/customers/credits/ledger.ts +30 -24
  226. package/src/resources/customers/credits/top-ups.ts +16 -12
  227. package/src/resources/customers/customers.ts +70 -46
  228. package/src/resources/customers/index.ts +17 -17
  229. package/src/resources/dimensional-price-groups/dimensional-price-groups.ts +146 -0
  230. package/src/resources/dimensional-price-groups/external-dimensional-price-group-id.ts +20 -0
  231. package/src/resources/dimensional-price-groups/index.ts +10 -0
  232. package/src/resources/events/backfills.ts +17 -12
  233. package/src/resources/events/events.ts +42 -23
  234. package/src/resources/events/index.ts +15 -15
  235. package/src/resources/events/volume.ts +11 -22
  236. package/src/resources/index.ts +113 -67
  237. package/src/resources/invoice-line-items.ts +5 -4
  238. package/src/resources/invoices.ts +111 -34
  239. package/src/resources/items.ts +11 -17
  240. package/src/resources/metrics.ts +11 -17
  241. package/src/resources/plans/external-plan-id.ts +3 -14
  242. package/src/resources/plans/index.ts +9 -2
  243. package/src/resources/plans/plans.ts +425 -19
  244. package/src/resources/prices/external-price-id.ts +3 -14
  245. package/src/resources/prices/index.ts +8 -8
  246. package/src/resources/prices/prices.ts +471 -24
  247. package/src/resources/subscriptions.ts +9238 -440
  248. package/src/resources/top-level.ts +2 -3
  249. package/src/version.ts +1 -1
  250. package/version.d.ts +1 -1
  251. package/version.js +1 -1
  252. package/version.mjs +1 -1
@@ -1,19 +1,273 @@
1
1
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
2
  import { APIResource } from "../resource.mjs";
3
3
  import { isRequestOptions } from "../core.mjs";
4
- import * as SubscriptionsAPI from "./subscriptions.mjs";
5
4
  import { Page } from "../pagination.mjs";
6
5
  export class Subscriptions extends APIResource {
7
- create(body = {}, options) {
8
- if (isRequestOptions(body)) {
9
- return this.create({}, body);
10
- }
6
+ /**
7
+ * A subscription represents the purchase of a plan by a customer. The customer is
8
+ * identified by either the `customer_id` or the `external_customer_id`, and
9
+ * exactly one of these fields must be provided.
10
+ *
11
+ * By default, subscriptions begin on the day that they're created and renew
12
+ * automatically for each billing cycle at the cadence that's configured in the
13
+ * plan definition.
14
+ *
15
+ * The default configuration for subscriptions in Orb is **In-advance billing** and
16
+ * **Beginning of month alignment** (see
17
+ * [Subscription](../guides/concepts#subscription) for more details).
18
+ *
19
+ * In order to change the alignment behavior, Orb also supports billing
20
+ * subscriptions on the day of the month they are created. If
21
+ * `align_billing_with_subscription_start_date = true` is specified, subscriptions
22
+ * have billing cycles that are aligned with their `start_date`. For example, a
23
+ * subscription that begins on January 15th will have a billing cycle from January
24
+ * 15th to February 15th. Every subsequent billing cycle will continue to start and
25
+ * invoice on the 15th.
26
+ *
27
+ * If the "day" value is greater than the number of days in the month, the next
28
+ * billing cycle will start at the end of the month. For example, if the start_date
29
+ * is January 31st, the next billing cycle will start on February 28th.
30
+ *
31
+ * If a customer was created with a currency, Orb only allows subscribing the
32
+ * customer to a plan with a matching `invoicing_currency`. If the customer does
33
+ * not have a currency set, on subscription creation, we set the customer's
34
+ * currency to be the `invoicing_currency` of the plan.
35
+ *
36
+ * ## Customize your customer's subscriptions
37
+ *
38
+ * Prices and adjustments in a plan can be added, removed, or replaced for the
39
+ * subscription being created. This is useful when a customer has prices that
40
+ * differ from the default prices for a specific plan.
41
+ *
42
+ * :::info This feature is only available for accounts that have migrated to
43
+ * Subscription Overrides Version 2. You can find your Subscription Overrides
44
+ * Version at the bottom of your [Plans page](https://app.withorb.com/plans) :::
45
+ *
46
+ * ### Adding Prices
47
+ *
48
+ * To add prices, provide a list of objects with the key `add_prices`. An object in
49
+ * the list must specify an existing add-on price with a `price_id` or
50
+ * `external_price_id` field, or create a new add-on price by including an object
51
+ * with the key `price`, identical to what would be used in the request body for
52
+ * the [create price endpoint](../reference/create-price). See the
53
+ * [Price resource](../reference/price) for the specification of different price
54
+ * model configurations possible in this object.
55
+ *
56
+ * If the plan has phases, each object in the list must include a number with
57
+ * `plan_phase_order` key to indicate which phase the price should be added to.
58
+ *
59
+ * An object in the list can specify an optional `start_date` and optional
60
+ * `end_date`. This is equivalent to creating a price interval with the
61
+ * [add/edit price intervals endpoint](../reference/add-edit-price-intervals). If
62
+ * unspecified, the start or end date of the phase or subscription will be used.
63
+ *
64
+ * An object in the list can specify an optional `minimum_amount`,
65
+ * `maximum_amount`, or `discounts`. This will create adjustments which apply only
66
+ * to this price.
67
+ *
68
+ * Additionally, an object in the list can specify an optional `reference_id`. This
69
+ * ID can be used to reference this price when
70
+ * [adding an adjustment](#adding-adjustments) in the same API call. However the ID
71
+ * is _transient_ and cannot be used to refer to the price in future API calls.
72
+ *
73
+ * ### Removing Prices
74
+ *
75
+ * To remove prices, provide a list of objects with the key `remove_prices`. An
76
+ * object in the list must specify a plan price with either a `price_id` or
77
+ * `external_price_id` field.
78
+ *
79
+ * ### Replacing Prices
80
+ *
81
+ * To replace prices, provide a list of objects with the key `replace_prices`. An
82
+ * object in the list must specify a plan price to replace with the
83
+ * `replaces_price_id` key, and it must specify a price to replace it with by
84
+ * either referencing an existing add-on price with a `price_id` or
85
+ * `external_price_id` field, or by creating a new add-on price by including an
86
+ * object with the key `price`, identical to what would be used in the request body
87
+ * for the [create price endpoint](../reference/create-price). See the
88
+ * [Price resource](../reference/price) for the specification of different price
89
+ * model configurations possible in this object.
90
+ *
91
+ * For fixed fees, an object in the list can supply a `fixed_price_quantity`
92
+ * instead of a `price`, `price_id`, or `external_price_id` field. This will update
93
+ * only the quantity for the price, similar to the
94
+ * [Update price quantity](../reference/update-fixed-fee-quantity) endpoint.
95
+ *
96
+ * The replacement price will have the same phase, if applicable, and the same
97
+ * start and end dates as the price it replaces.
98
+ *
99
+ * An object in the list can specify an optional `minimum_amount`,
100
+ * `maximum_amount`, or `discounts`. This will create adjustments which apply only
101
+ * to this price.
102
+ *
103
+ * Additionally, an object in the list can specify an optional `reference_id`. This
104
+ * ID can be used to reference the replacement price when
105
+ * [adding an adjustment](#adding-adjustments) in the same API call. However the ID
106
+ * is _transient_ and cannot be used to refer to the price in future API calls.
107
+ *
108
+ * ### Adding adjustments
109
+ *
110
+ * To add adjustments, provide a list of objects with the key `add_adjustments`. An
111
+ * object in the list must include an object with the key `adjustment`, identical
112
+ * to the adjustment object in the
113
+ * [add/edit price intervals endpoint](../reference/add-edit-price-intervals).
114
+ *
115
+ * If the plan has phases, each object in the list must include a number with
116
+ * `plan_phase_order` key to indicate which phase the adjustment should be added
117
+ * to.
118
+ *
119
+ * An object in the list can specify an optional `start_date` and optional
120
+ * `end_date`. If unspecified, the start or end date of the phase or subscription
121
+ * will be used.
122
+ *
123
+ * ### Removing adjustments
124
+ *
125
+ * To remove adjustments, provide a list of objects with the key
126
+ * `remove_adjustments`. An object in the list must include a key, `adjustment_id`,
127
+ * with the ID of the adjustment to be removed.
128
+ *
129
+ * ### Replacing adjustments
130
+ *
131
+ * To replace adjustments, provide a list of objects with the key
132
+ * `replace_adjustments`. An object in the list must specify a plan adjustment to
133
+ * replace with the `replaces_adjustment_id` key, and it must specify an adjustment
134
+ * to replace it with by including an object with the key `adjustment`, identical
135
+ * to the adjustment object in the
136
+ * [add/edit price intervals endpoint](../reference/add-edit-price-intervals).
137
+ *
138
+ * The replacement adjustment will have the same phase, if applicable, and the same
139
+ * start and end dates as the adjustment it replaces.
140
+ *
141
+ * ## Price overrides (DEPRECATED)
142
+ *
143
+ * :::info Price overrides are being phased out in favor adding/removing/replacing
144
+ * prices. (See
145
+ * [Customize your customer's subscriptions](../reference/create-subscription#customize-your-customers-subscriptions))
146
+ * :::
147
+ *
148
+ * Price overrides are used to update some or all prices in a plan for the specific
149
+ * subscription being created. This is useful when a new customer has negotiated a
150
+ * rate that is unique to the customer.
151
+ *
152
+ * To override prices, provide a list of objects with the key `price_overrides`.
153
+ * The price object in the list of overrides is expected to contain the existing
154
+ * price id, the `model_type` and configuration. (See the
155
+ * [Price resource](../reference/price) for the specification of different price
156
+ * model configurations.) The numerical values can be updated, but the billable
157
+ * metric, cadence, type, and name of a price can not be overridden.
158
+ *
159
+ * ### Maximums and Minimums
160
+ *
161
+ * Minimums and maximums, much like price overrides, can be useful when a new
162
+ * customer has negotiated a new or different minimum or maximum spend cap than the
163
+ * default for a given price. If one exists for a price and null is provided for
164
+ * the minimum/maximum override on creation, then there will be no minimum/maximum
165
+ * on the new subscription. If no value is provided, then the default price maximum
166
+ * or minimum is used.
167
+ *
168
+ * To add a minimum for a specific price, add `minimum_amount` to the specific
169
+ * price in the `price_overrides` object.
170
+ *
171
+ * To add a maximum for a specific price, add `maximum_amount` to the specific
172
+ * price in the `price_overrides` object.
173
+ *
174
+ * ### Minimum override example
175
+ *
176
+ * Price minimum override example:
177
+ *
178
+ * ```json
179
+ * {
180
+ * ...
181
+ * "id": "price_id",
182
+ * "model_type": "unit",
183
+ * "unit_config": {
184
+ * "unit_amount": "0.50"
185
+ * },
186
+ * "minimum_amount": "100.00"
187
+ * ...
188
+ * }
189
+ * ```
190
+ *
191
+ * Removing an existing minimum example
192
+ *
193
+ * ```json
194
+ * {
195
+ * ...
196
+ * "id": "price_id",
197
+ * "model_type": "unit",
198
+ * "unit_config": {
199
+ * "unit_amount": "0.50"
200
+ * },
201
+ * "minimum_amount": null
202
+ * ...
203
+ * }
204
+ * ```
205
+ *
206
+ * ### Discounts
207
+ *
208
+ * Discounts, like price overrides, can be useful when a new customer has
209
+ * negotiated a new or different discount than the default for a price. If a
210
+ * discount exists for a price and a null discount is provided on creation, then
211
+ * there will be no discount on the new subscription.
212
+ *
213
+ * To add a discount for a specific price, add `discount` to the price in the
214
+ * `price_overrides` object. Discount should be a dictionary of the format:
215
+ *
216
+ * ```ts
217
+ * {
218
+ * "discount_type": "amount" | "percentage" | "usage",
219
+ * "amount_discount": string,
220
+ * "percentage_discount": string,
221
+ * "usage_discount": string
222
+ * }
223
+ * ```
224
+ *
225
+ * where either `amount_discount`, `percentage_discount`, or `usage_discount` is
226
+ * provided.
227
+ *
228
+ * Price discount example
229
+ *
230
+ * ```json
231
+ * {
232
+ * ...
233
+ * "id": "price_id",
234
+ * "model_type": "unit",
235
+ * "unit_config": {
236
+ * "unit_amount": "0.50"
237
+ * },
238
+ * "discount": {"discount_type": "amount", "amount_discount": "175"},
239
+ * }
240
+ * ```
241
+ *
242
+ * Removing an existing discount example
243
+ *
244
+ * ```json
245
+ * {
246
+ * "customer_id": "customer_id",
247
+ * "plan_id": "plan_id",
248
+ * "discount": null,
249
+ * "price_overrides": [ ... ]
250
+ * ...
251
+ * }
252
+ * ```
253
+ *
254
+ * ## Threshold Billing
255
+ *
256
+ * Orb supports invoicing for a subscription when a preconfigured usage threshold
257
+ * is hit. To enable threshold billing, pass in an `invoicing_threshold`, which is
258
+ * specified in the subscription's invoicing currency, when creating a
259
+ * subscription. E.g. pass in `10.00` to issue an invoice when usage amounts hit
260
+ * $10.00 for a subscription that invoices in USD.
261
+ */
262
+ create(body, options) {
11
263
  return this._client.post('/subscriptions', { body, ...options });
12
264
  }
13
- update(subscriptionId, body = {}, options) {
14
- if (isRequestOptions(body)) {
15
- return this.update(subscriptionId, {}, body);
16
- }
265
+ /**
266
+ * This endpoint can be used to update the `metadata`, `net terms`,
267
+ * `auto_collection`, `invoicing_threshold`, and `default_invoice_memo` properties
268
+ * on a subscription.
269
+ */
270
+ update(subscriptionId, body, options) {
17
271
  return this._client.put(`/subscriptions/${subscriptionId}`, { body, ...options });
18
272
  }
19
273
  list(query = {}, options) {
@@ -113,10 +367,81 @@ export class Subscriptions extends APIResource {
113
367
  }
114
368
  return this._client.get(`/subscriptions/${subscriptionId}/usage`, { query, ...options });
115
369
  }
116
- priceIntervals(subscriptionId, body = {}, options) {
117
- if (isRequestOptions(body)) {
118
- return this.priceIntervals(subscriptionId, {}, body);
119
- }
370
+ /**
371
+ * This endpoint is used to add and edit subscription
372
+ * [price intervals](../reference/price-interval). By making modifications to a
373
+ * subscription’s price intervals, you can
374
+ * [flexibly and atomically control the billing behavior of a subscription](../guides/product-catalog/modifying-subscriptions).
375
+ *
376
+ * ## Adding price intervals
377
+ *
378
+ * Prices can be added as price intervals to a subscription by specifying them in
379
+ * the `add` array. A `price_id` or `external_price_id` from an add-on price or
380
+ * previously removed plan price can be specified to reuse an existing price
381
+ * definition (however, please note that prices from other plans cannot be added to
382
+ * the subscription). Additionally, a new price can be specified using the `price`
383
+ * field — this price will be created automatically.
384
+ *
385
+ * A `start_date` must be specified for the price interval. This is the date when
386
+ * the price will start billing on the subscription, so this will notably result in
387
+ * an immediate charge at this time for any billed in advance fixed fees. The
388
+ * `end_date` will default to null, resulting in a price interval that will bill on
389
+ * a continually recurring basis. Both of these dates can be set in the past or the
390
+ * future and Orb will generate or modify invoices to ensure the subscription’s
391
+ * invoicing behavior is correct.
392
+ *
393
+ * Additionally, a discount, minimum, or maximum can be specified on the price
394
+ * interval. This will only apply to this price interval, not any other price
395
+ * intervals on the subscription.
396
+ *
397
+ * ## Adjustment intervals
398
+ *
399
+ * An adjustment interval represents the time period that a particular adjustment
400
+ * (a discount, minimum, or maximum) applies to the prices on a subscription.
401
+ * Adjustment intervals can be added to a subscription by specifying them in the
402
+ * `add_adjustments` array, or modified via the `edit_adjustments` array. When
403
+ * creating an adjustment interval, you'll need to provide the definition of the
404
+ * new adjustment (the type of adjustment, and which prices it applies to), as well
405
+ * as the start and end dates for the adjustment interval. The start and end dates
406
+ * of an existing adjustment interval can be edited via the `edit_adjustments`
407
+ * field (just like price intervals). (To "change" the amount of a discount,
408
+ * minimum, or maximum, then, you'll need to end the existing interval, and create
409
+ * a new adjustment interval with the new amount and a start date that matches the
410
+ * end date of the previous interval.)
411
+ *
412
+ * ## Editing price intervals
413
+ *
414
+ * Price intervals can be adjusted by specifying edits to make in the `edit` array.
415
+ * A `price_interval_id` to edit must be specified — this can be retrieved from the
416
+ * `price_intervals` field on the subscription.
417
+ *
418
+ * A new `start_date` or `end_date` can be specified to change the range of the
419
+ * price interval, which will modify past or future invoices to ensure correctness.
420
+ * If either of these dates are unspecified, they will default to the existing date
421
+ * on the price interval. To remove a price interval entirely from a subscription,
422
+ * set the `end_date` to be equivalent to the `start_date`.
423
+ *
424
+ * ## Fixed fee quantity transitions
425
+ *
426
+ * The fixed fee quantity transitions for a fixed fee price interval can also be
427
+ * specified when adding or editing by passing an array for
428
+ * `fixed_fee_quantity_transitions`. A fixed fee quantity transition must have a
429
+ * `quantity` and an `effective_date`, which is the date after which the new
430
+ * quantity will be used for billing. If a fixed fee quantity transition is
431
+ * scheduled at a billing period boundary, the full quantity will be billed on an
432
+ * invoice with the other prices on the subscription. If the fixed fee quantity
433
+ * transition is scheduled mid-billing period, the difference between the existing
434
+ * quantity and quantity specified in the transition will be prorated for the rest
435
+ * of the billing period and billed immediately, which will generate a new invoice.
436
+ *
437
+ * Notably, the list of fixed fee quantity transitions passed will overwrite the
438
+ * existing fixed fee quantity transitions on the price interval, so the entire
439
+ * list of transitions must be specified to add additional transitions. The
440
+ * existing list of transitions can be retrieved using the
441
+ * `fixed_fee_quantity_transitions` property on a subscription’s serialized price
442
+ * intervals.
443
+ */
444
+ priceIntervals(subscriptionId, body, options) {
120
445
  return this._client.post(`/subscriptions/${subscriptionId}/price_intervals`, { body, ...options });
121
446
  }
122
447
  /**
@@ -164,8 +489,9 @@ export class Subscriptions extends APIResource {
164
489
  * subscription when you schedule the plan change. This is useful when a customer
165
490
  * has prices that differ from the default prices for a specific plan.
166
491
  *
167
- * :::info This feature is only available for accounts that have migrated off of
168
- * legacy subscription overrides. :::
492
+ * :::info This feature is only available for accounts that have migrated to
493
+ * Subscription Overrides Version 2. You can find your Subscription Overrides
494
+ * Version at the bottom of your [Plans page](https://app.withorb.com/plans) :::
169
495
  *
170
496
  * ### Adding Prices
171
497
  *
@@ -303,10 +629,11 @@ export class Subscriptions extends APIResource {
303
629
  schedulePlanChange(subscriptionId, body, options) {
304
630
  return this._client.post(`/subscriptions/${subscriptionId}/schedule_plan_change`, { body, ...options });
305
631
  }
306
- triggerPhase(subscriptionId, body = {}, options) {
307
- if (isRequestOptions(body)) {
308
- return this.triggerPhase(subscriptionId, {}, body);
309
- }
632
+ /**
633
+ * Manually trigger a phase, effective the given date (or the current time, if not
634
+ * specified).
635
+ */
636
+ triggerPhase(subscriptionId, body, options) {
310
637
  return this._client.post(`/subscriptions/${subscriptionId}/trigger_phase`, { body, ...options });
311
638
  }
312
639
  /**
@@ -390,9 +717,6 @@ export class SubscriptionsPage extends Page {
390
717
  }
391
718
  export class SubscriptionFetchScheduleResponsesPage extends Page {
392
719
  }
393
- (function (Subscriptions) {
394
- Subscriptions.Subscriptions = SubscriptionsAPI.Subscriptions;
395
- Subscriptions.SubscriptionsPage = SubscriptionsAPI.SubscriptionsPage;
396
- Subscriptions.SubscriptionFetchScheduleResponsesPage = SubscriptionsAPI.SubscriptionFetchScheduleResponsesPage;
397
- })(Subscriptions || (Subscriptions = {}));
720
+ Subscriptions.SubscriptionsPage = SubscriptionsPage;
721
+ Subscriptions.SubscriptionFetchScheduleResponsesPage = SubscriptionFetchScheduleResponsesPage;
398
722
  //# sourceMappingURL=subscriptions.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"subscriptions.mjs","sourceRoot":"","sources":["../src/resources/subscriptions.ts"],"names":[],"mappings":"AAAA,sFAAsF;OAE/E,EAAE,WAAW,EAAE;OACf,EAAE,gBAAgB,EAAE;OAEpB,KAAK,gBAAgB;OAKrB,EAA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,CAAC,CAAC;IACL,CAAC;IAED;;;OAGG;IACH,4BAA4B,CAC1B,cAAsB,EACtB,OAA6B;QAE7B,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,kBAAkB,cAAc,kCAAkC,EAAE,OAAO,CAAC,CAAC;IACxG,CAAC;IAED;;;;;;;;;;;;;;;OAeG;IACH,sBAAsB,CACpB,cAAsB,EACtB,IAA8C,EAC9C,OAA6B;QAE7B,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,kBAAkB,cAAc,4BAA4B,EAAE;YACrF,IAAI;YACJ,GAAG,OAAO;SACX,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;;;;;;;;;;;;;OAmBG;IACH,WAAW,CACT,cAAsB,EACtB,IAAmC,EACnC,OAA6B;QAE7B,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,kBAAkB,cAAc,eAAe,EAAE,EAAE,IAAI,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;IAClG,CAAC;CACF;AAED,MAAM,OAAO,iBAAkB,SAAQ,IAAkB;CAAG;AAE5D,MAAM,OAAO,sCAAuC,SAAQ,IAAuC;CAAG;AAg3tBtG,aAAa,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;AACpD,aAAa,CAAC,sCAAsC,GAAG,sCAAsC,CAAC"}
@@ -1,6 +1,5 @@
1
1
  import { APIResource } from "../resource.js";
2
2
  import * as Core from "../core.js";
3
- import * as TopLevelAPI from "./top-level.js";
4
3
  export declare class TopLevel extends APIResource {
5
4
  /**
6
5
  * This endpoint allows you to test your connection to the Orb API and check the
@@ -16,6 +15,6 @@ export interface TopLevelPingResponse {
16
15
  response: string;
17
16
  }
18
17
  export declare namespace TopLevel {
19
- export import TopLevelPingResponse = TopLevelAPI.TopLevelPingResponse;
18
+ export { type TopLevelPingResponse as TopLevelPingResponse };
20
19
  }
21
20
  //# sourceMappingURL=top-level.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"top-level.d.ts","sourceRoot":"","sources":["../src/resources/top-level.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,IAAI,MAAM,SAAS,CAAC;AAChC,OAAO,KAAK,WAAW,MAAM,aAAa,CAAC;AAE3C,qBAAa,QAAS,SAAQ,WAAW;IACvC;;;;;;;OAOG;IACH,IAAI,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,UAAU,CAAC,oBAAoB,CAAC;CAG3E;AAED,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,yBAAiB,QAAQ,CAAC;IACxB,MAAM,QAAQ,oBAAoB,GAAG,WAAW,CAAC,oBAAoB,CAAC;CACvE"}
1
+ {"version":3,"file":"top-level.d.ts","sourceRoot":"","sources":["../src/resources/top-level.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,IAAI,MAAM,SAAS,CAAC;AAEhC,qBAAa,QAAS,SAAQ,WAAW;IACvC;;;;;;;OAOG;IACH,IAAI,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,UAAU,CAAC,oBAAoB,CAAC;CAG3E;AAED,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,CAAC,OAAO,WAAW,QAAQ,CAAC;IAChC,OAAO,EAAE,KAAK,oBAAoB,IAAI,oBAAoB,EAAE,CAAC;CAC9D"}
@@ -17,6 +17,4 @@ class TopLevel extends resource_1.APIResource {
17
17
  }
18
18
  }
19
19
  exports.TopLevel = TopLevel;
20
- (function (TopLevel) {
21
- })(TopLevel = exports.TopLevel || (exports.TopLevel = {}));
22
20
  //# sourceMappingURL=top-level.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"top-level.js","sourceRoot":"","sources":["../src/resources/top-level.ts"],"names":[],"mappings":";AAAA,sFAAsF;;;AAEtF,6CAA0C;AAI1C,MAAa,QAAS,SAAQ,sBAAW;IACvC;;;;;;;OAOG;IACH,IAAI,CAAC,OAA6B;QAChC,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC5C,CAAC;CACF;AAZD,4BAYC;AAMD,WAAiB,QAAQ;AAEzB,CAAC,EAFgB,QAAQ,GAAR,gBAAQ,KAAR,gBAAQ,QAExB"}
1
+ {"version":3,"file":"top-level.js","sourceRoot":"","sources":["../src/resources/top-level.ts"],"names":[],"mappings":";AAAA,sFAAsF;;;AAEtF,6CAA0C;AAG1C,MAAa,QAAS,SAAQ,sBAAW;IACvC;;;;;;;OAOG;IACH,IAAI,CAAC,OAA6B;QAChC,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC5C,CAAC;CACF;AAZD,4BAYC"}
@@ -13,6 +13,4 @@ export class TopLevel extends APIResource {
13
13
  return this._client.get('/ping', options);
14
14
  }
15
15
  }
16
- (function (TopLevel) {
17
- })(TopLevel || (TopLevel = {}));
18
16
  //# sourceMappingURL=top-level.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"top-level.mjs","sourceRoot":"","sources":["../src/resources/top-level.ts"],"names":[],"mappings":"AAAA,sFAAsF;OAE/E,EAAE,WAAW,EAAE;AAItB,MAAM,OAAO,QAAS,SAAQ,WAAW;IACvC;;;;;;;OAOG;IACH,IAAI,CAAC,OAA6B;QAChC,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC5C,CAAC;CACF;AAMD,WAAiB,QAAQ;AAEzB,CAAC,EAFgB,QAAQ,KAAR,QAAQ,QAExB"}
1
+ {"version":3,"file":"top-level.mjs","sourceRoot":"","sources":["../src/resources/top-level.ts"],"names":[],"mappings":"AAAA,sFAAsF;OAE/E,EAAE,WAAW,EAAE;AAGtB,MAAM,OAAO,QAAS,SAAQ,WAAW;IACvC;;;;;;;OAOG;IACH,IAAI,CAAC,OAA6B;QAChC,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC5C,CAAC;CACF"}
package/src/core.ts CHANGED
@@ -163,7 +163,7 @@ export abstract class APIClient {
163
163
  maxRetries = 2,
164
164
  timeout = 60000, // 1 minute
165
165
  httpAgent,
166
- fetch: overridenFetch,
166
+ fetch: overriddenFetch,
167
167
  }: {
168
168
  baseURL: string;
169
169
  maxRetries?: number | undefined;
@@ -176,7 +176,7 @@ export abstract class APIClient {
176
176
  this.timeout = validatePositiveInteger('timeout', timeout);
177
177
  this.httpAgent = httpAgent;
178
178
 
179
- this.fetch = overridenFetch ?? fetch;
179
+ this.fetch = overriddenFetch ?? fetch;
180
180
  }
181
181
 
182
182
  protected authHeaders(opts: FinalRequestOptions): Headers {
@@ -396,7 +396,7 @@ export abstract class APIClient {
396
396
  error: Object | undefined,
397
397
  message: string | undefined,
398
398
  headers: Headers | undefined,
399
- ) {
399
+ ): APIError {
400
400
  return APIError.generate(status, error, message, headers);
401
401
  }
402
402
 
@@ -522,20 +522,24 @@ export abstract class APIClient {
522
522
 
523
523
  const timeout = setTimeout(() => controller.abort(), ms);
524
524
 
525
+ const fetchOptions = {
526
+ signal: controller.signal as any,
527
+ ...options,
528
+ };
529
+ if (fetchOptions.method) {
530
+ // Custom methods like 'patch' need to be uppercased
531
+ // See https://github.com/nodejs/undici/issues/2294
532
+ fetchOptions.method = fetchOptions.method.toUpperCase();
533
+ }
534
+
525
535
  return (
526
- this.getRequestClient()
527
- // use undefined this binding; fetch errors if bound to something else in browser/cloudflare
528
- .fetch.call(undefined, url, { signal: controller.signal as any, ...options })
529
- .finally(() => {
530
- clearTimeout(timeout);
531
- })
536
+ // use undefined this binding; fetch errors if bound to something else in browser/cloudflare
537
+ this.fetch.call(undefined, url, fetchOptions).finally(() => {
538
+ clearTimeout(timeout);
539
+ })
532
540
  );
533
541
  }
534
542
 
535
- protected getRequestClient(): RequestClient {
536
- return { fetch: this.fetch };
537
- }
538
-
539
543
  private shouldRetry(response: Response): boolean {
540
544
  // Note this is not a standard header.
541
545
  const shouldRetryHeader = response.headers.get('x-should-retry');
@@ -668,9 +672,9 @@ export abstract class AbstractPage<Item> implements AsyncIterable<Item> {
668
672
  return await this.#client.requestAPIList(this.constructor as any, nextOptions);
669
673
  }
670
674
 
671
- async *iterPages() {
675
+ async *iterPages(): AsyncGenerator<this> {
672
676
  // eslint-disable-next-line @typescript-eslint/no-this-alias
673
- let page: AbstractPage<Item> = this;
677
+ let page: this = this;
674
678
  yield page;
675
679
  while (page.hasNextPage()) {
676
680
  page = await page.getNextPage();
@@ -678,7 +682,7 @@ export abstract class AbstractPage<Item> implements AsyncIterable<Item> {
678
682
  }
679
683
  }
680
684
 
681
- async *[Symbol.asyncIterator]() {
685
+ async *[Symbol.asyncIterator](): AsyncGenerator<Item> {
682
686
  for await (const page of this.iterPages()) {
683
687
  for (const item of page.getPaginatedItems()) {
684
688
  yield item;
@@ -721,7 +725,7 @@ export class PagePromise<
721
725
  * console.log(item)
722
726
  * }
723
727
  */
724
- async *[Symbol.asyncIterator]() {
728
+ async *[Symbol.asyncIterator](): AsyncGenerator<Item> {
725
729
  const page = await this;
726
730
  for await (const item of page) {
727
731
  yield item;
@@ -976,8 +980,8 @@ export const safeJSON = (text: string) => {
976
980
  }
977
981
  };
978
982
 
979
- // https://stackoverflow.com/a/19709846
980
- const startsWithSchemeRegexp = new RegExp('^(?:[a-z]+:)?//', 'i');
983
+ // https://url.spec.whatwg.org/#url-scheme-string
984
+ const startsWithSchemeRegexp = /^[a-z][a-z0-9+.-]*:/i;
981
985
  const isAbsoluteURL = (url: string): boolean => {
982
986
  return startsWithSchemeRegexp.test(url);
983
987
  };