|
| 1 | +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. |
| 2 | + |
| 3 | +import * as Core from './core'; |
| 4 | +import * as Errors from './error'; |
| 5 | +import { type Agent } from './_shims/index'; |
| 6 | +import * as Uploads from './uploads'; |
| 7 | +import * as qs from 'qs'; |
| 8 | +import * as Pagination from 'orb-billing/pagination'; |
| 9 | +import * as API from 'orb-billing/resources/index'; |
| 10 | + |
| 11 | +export interface ClientOptions { |
| 12 | + /** |
| 13 | + * Defaults to process.env['ORB_API_KEY']. |
| 14 | + */ |
| 15 | + apiKey?: string | undefined; |
| 16 | + |
| 17 | + /** |
| 18 | + * Defaults to process.env['ORB_WEBHOOK_SECRET']. |
| 19 | + */ |
| 20 | + webhookSecret?: string | null | undefined; |
| 21 | + |
| 22 | + /** |
| 23 | + * Override the default base URL for the API, e.g., "https://api.example.com/v2/" |
| 24 | + * |
| 25 | + * Defaults to process.env['ORB_BASE_URL']. |
| 26 | + */ |
| 27 | + baseURL?: string | null | undefined; |
| 28 | + |
| 29 | + /** |
| 30 | + * The maximum amount of time (in milliseconds) that the client should wait for a response |
| 31 | + * from the server before timing out a single request. |
| 32 | + * |
| 33 | + * Note that request timeouts are retried by default, so in a worst-case scenario you may wait |
| 34 | + * much longer than this timeout before the promise succeeds or fails. |
| 35 | + */ |
| 36 | + timeout?: number; |
| 37 | + |
| 38 | + /** |
| 39 | + * An HTTP agent used to manage HTTP(S) connections. |
| 40 | + * |
| 41 | + * If not provided, an agent will be constructed by default in the Node.js environment, |
| 42 | + * otherwise no agent is used. |
| 43 | + */ |
| 44 | + httpAgent?: Agent; |
| 45 | + |
| 46 | + /** |
| 47 | + * Specify a custom `fetch` function implementation. |
| 48 | + * |
| 49 | + * If not provided, we use `node-fetch` on Node.js and otherwise expect that `fetch` is |
| 50 | + * defined globally. |
| 51 | + */ |
| 52 | + fetch?: Core.Fetch | undefined; |
| 53 | + |
| 54 | + /** |
| 55 | + * The maximum number of times that the client will retry a request in case of a |
| 56 | + * temporary failure, like a network error or a 5XX error from the server. |
| 57 | + * |
| 58 | + * @default 2 |
| 59 | + */ |
| 60 | + maxRetries?: number; |
| 61 | + |
| 62 | + /** |
| 63 | + * Default headers to include with every request to the API. |
| 64 | + * |
| 65 | + * These can be removed in individual requests by explicitly setting the |
| 66 | + * header to `undefined` or `null` in request options. |
| 67 | + */ |
| 68 | + defaultHeaders?: Core.Headers; |
| 69 | + |
| 70 | + /** |
| 71 | + * Default query parameters to include with every request to the API. |
| 72 | + * |
| 73 | + * These can be removed in individual requests by explicitly setting the |
| 74 | + * param to `undefined` in request options. |
| 75 | + */ |
| 76 | + defaultQuery?: Core.DefaultQuery; |
| 77 | +} |
| 78 | + |
| 79 | +/** API Client for interfacing with the Orb API. */ |
| 80 | +export class Orb extends Core.APIClient { |
| 81 | + apiKey: string; |
| 82 | + webhookSecret: string | null; |
| 83 | + |
| 84 | + private _options: ClientOptions; |
| 85 | + |
| 86 | + /** |
| 87 | + * API Client for interfacing with the Orb API. |
| 88 | + * |
| 89 | + * @param {string | undefined} [opts.apiKey=process.env['ORB_API_KEY'] ?? undefined] |
| 90 | + * @param {string | null | undefined} [opts.webhookSecret=process.env['ORB_WEBHOOK_SECRET'] ?? null] |
| 91 | + * @param {string} [opts.baseURL=process.env['ORB_BASE_URL'] ?? https://api.withorb.com/v1] - Override the default base URL for the API. |
| 92 | + * @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out. |
| 93 | + * @param {number} [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections. |
| 94 | + * @param {Core.Fetch} [opts.fetch] - Specify a custom `fetch` function implementation. |
| 95 | + * @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request. |
| 96 | + * @param {Core.Headers} opts.defaultHeaders - Default headers to include with every request to the API. |
| 97 | + * @param {Core.DefaultQuery} opts.defaultQuery - Default query parameters to include with every request to the API. |
| 98 | + */ |
| 99 | + constructor({ |
| 100 | + baseURL = Core.readEnv('ORB_BASE_URL'), |
| 101 | + apiKey = Core.readEnv('ORB_API_KEY'), |
| 102 | + webhookSecret = Core.readEnv('ORB_WEBHOOK_SECRET') ?? null, |
| 103 | + ...opts |
| 104 | + }: ClientOptions = {}) { |
| 105 | + if (apiKey === undefined) { |
| 106 | + throw new Errors.OrbError( |
| 107 | + "The ORB_API_KEY environment variable is missing or empty; either provide it, or instantiate the Orb client with an apiKey option, like new Orb({ apiKey: 'My API Key' }).", |
| 108 | + ); |
| 109 | + } |
| 110 | + |
| 111 | + const options: ClientOptions = { |
| 112 | + apiKey, |
| 113 | + webhookSecret, |
| 114 | + ...opts, |
| 115 | + baseURL: baseURL || `https://api.withorb.com/v1`, |
| 116 | + }; |
| 117 | + |
| 118 | + super({ |
| 119 | + baseURL: options.baseURL!, |
| 120 | + timeout: options.timeout ?? 60000 /* 1 minute */, |
| 121 | + httpAgent: options.httpAgent, |
| 122 | + maxRetries: options.maxRetries, |
| 123 | + fetch: options.fetch, |
| 124 | + }); |
| 125 | + this._options = options; |
| 126 | + this.idempotencyHeader = 'Idempotency-Key'; |
| 127 | + |
| 128 | + this.apiKey = apiKey; |
| 129 | + this.webhookSecret = webhookSecret; |
| 130 | + } |
| 131 | + |
| 132 | + topLevel: API.TopLevel = new API.TopLevel(this); |
| 133 | + coupons: API.Coupons = new API.Coupons(this); |
| 134 | + creditNotes: API.CreditNotes = new API.CreditNotes(this); |
| 135 | + customers: API.Customers = new API.Customers(this); |
| 136 | + events: API.Events = new API.Events(this); |
| 137 | + invoiceLineItems: API.InvoiceLineItems = new API.InvoiceLineItems(this); |
| 138 | + invoices: API.Invoices = new API.Invoices(this); |
| 139 | + items: API.Items = new API.Items(this); |
| 140 | + metrics: API.Metrics = new API.Metrics(this); |
| 141 | + plans: API.Plans = new API.Plans(this); |
| 142 | + prices: API.Prices = new API.Prices(this); |
| 143 | + subscriptions: API.Subscriptions = new API.Subscriptions(this); |
| 144 | + webhooks: API.Webhooks = new API.Webhooks(this); |
| 145 | + |
| 146 | + protected override defaultQuery(): Core.DefaultQuery | undefined { |
| 147 | + return this._options.defaultQuery; |
| 148 | + } |
| 149 | + |
| 150 | + protected override defaultHeaders(opts: Core.FinalRequestOptions): Core.Headers { |
| 151 | + return { |
| 152 | + ...super.defaultHeaders(opts), |
| 153 | + ...this._options.defaultHeaders, |
| 154 | + }; |
| 155 | + } |
| 156 | + |
| 157 | + protected override authHeaders(opts: Core.FinalRequestOptions): Core.Headers { |
| 158 | + return { Authorization: `Bearer ${this.apiKey}` }; |
| 159 | + } |
| 160 | + |
| 161 | + protected override stringifyQuery(query: Record<string, unknown>): string { |
| 162 | + return qs.stringify(query, { arrayFormat: 'brackets' }); |
| 163 | + } |
| 164 | + |
| 165 | + static Orb = this; |
| 166 | + |
| 167 | + static OrbError = Errors.OrbError; |
| 168 | + static APIError = Errors.APIError; |
| 169 | + static APIConnectionError = Errors.APIConnectionError; |
| 170 | + static APIConnectionTimeoutError = Errors.APIConnectionTimeoutError; |
| 171 | + static APIUserAbortError = Errors.APIUserAbortError; |
| 172 | + static URLNotFound = Errors.URLNotFound; |
| 173 | + static NotFoundError = Errors.NotFoundError; |
| 174 | + static ConflictError = Errors.ConflictError; |
| 175 | + static RateLimitError = Errors.RateLimitError; |
| 176 | + static BadRequestError = Errors.BadRequestError; |
| 177 | + static RequestTooLarge = Errors.RequestTooLarge; |
| 178 | + static TooManyRequests = Errors.TooManyRequests; |
| 179 | + static ResourceNotFound = Errors.ResourceNotFound; |
| 180 | + static ResourceConflict = Errors.ResourceConflict; |
| 181 | + static ResourceTooLarge = Errors.ResourceTooLarge; |
| 182 | + static AuthenticationError = Errors.AuthenticationError; |
| 183 | + static InternalServerError = Errors.InternalServerError; |
| 184 | + static ConstraintViolation = Errors.ConstraintViolation; |
| 185 | + static FeatureNotAvailable = Errors.FeatureNotAvailable; |
| 186 | + static PermissionDeniedError = Errors.PermissionDeniedError; |
| 187 | + static RequestValidationError = Errors.RequestValidationError; |
| 188 | + static OrbAuthenticationError = Errors.OrbAuthenticationError; |
| 189 | + static OrbInternalServerError = Errors.OrbInternalServerError; |
| 190 | + static UnprocessableEntityError = Errors.UnprocessableEntityError; |
| 191 | + static DuplicateResourceCreation = Errors.DuplicateResourceCreation; |
| 192 | + |
| 193 | + static toFile = Uploads.toFile; |
| 194 | + static fileFromPath = Uploads.fileFromPath; |
| 195 | +} |
| 196 | + |
| 197 | +export namespace Orb { |
| 198 | + export import RequestOptions = Core.RequestOptions; |
| 199 | + |
| 200 | + export import Page = Pagination.Page; |
| 201 | + export import PageParams = Pagination.PageParams; |
| 202 | + export import PageResponse = Pagination.PageResponse; |
| 203 | + |
| 204 | + export import TopLevel = API.TopLevel; |
| 205 | + export import TopLevelPingResponse = API.TopLevelPingResponse; |
| 206 | + |
| 207 | + export import Coupons = API.Coupons; |
| 208 | + export import Coupon = API.Coupon; |
| 209 | + export import CouponsPage = API.CouponsPage; |
| 210 | + export import CouponCreateParams = API.CouponCreateParams; |
| 211 | + export import CouponListParams = API.CouponListParams; |
| 212 | + |
| 213 | + export import CreditNotes = API.CreditNotes; |
| 214 | + export import CreditNote = API.CreditNote; |
| 215 | + export import CreditNotesPage = API.CreditNotesPage; |
| 216 | + export import CreditNoteListParams = API.CreditNoteListParams; |
| 217 | + |
| 218 | + export import Customers = API.Customers; |
| 219 | + export import Customer = API.Customer; |
| 220 | + export import CustomersPage = API.CustomersPage; |
| 221 | + export import CustomerCreateParams = API.CustomerCreateParams; |
| 222 | + export import CustomerUpdateParams = API.CustomerUpdateParams; |
| 223 | + export import CustomerListParams = API.CustomerListParams; |
| 224 | + export import CustomerUpdateByExternalIDParams = API.CustomerUpdateByExternalIDParams; |
| 225 | + |
| 226 | + export import Events = API.Events; |
| 227 | + export import EventUpdateResponse = API.EventUpdateResponse; |
| 228 | + export import EventDeprecateResponse = API.EventDeprecateResponse; |
| 229 | + export import EventIngestResponse = API.EventIngestResponse; |
| 230 | + export import EventSearchResponse = API.EventSearchResponse; |
| 231 | + export import EventUpdateParams = API.EventUpdateParams; |
| 232 | + export import EventIngestParams = API.EventIngestParams; |
| 233 | + export import EventSearchParams = API.EventSearchParams; |
| 234 | + |
| 235 | + export import InvoiceLineItems = API.InvoiceLineItems; |
| 236 | + export import InvoiceLineItemCreateResponse = API.InvoiceLineItemCreateResponse; |
| 237 | + export import InvoiceLineItemCreateParams = API.InvoiceLineItemCreateParams; |
| 238 | + |
| 239 | + export import Invoices = API.Invoices; |
| 240 | + export import Invoice = API.Invoice; |
| 241 | + export import InvoiceFetchUpcomingResponse = API.InvoiceFetchUpcomingResponse; |
| 242 | + export import InvoicesPage = API.InvoicesPage; |
| 243 | + export import InvoiceCreateParams = API.InvoiceCreateParams; |
| 244 | + export import InvoiceListParams = API.InvoiceListParams; |
| 245 | + export import InvoiceFetchUpcomingParams = API.InvoiceFetchUpcomingParams; |
| 246 | + export import InvoiceMarkPaidParams = API.InvoiceMarkPaidParams; |
| 247 | + |
| 248 | + export import Items = API.Items; |
| 249 | + export import Item = API.Item; |
| 250 | + export import ItemsPage = API.ItemsPage; |
| 251 | + export import ItemCreateParams = API.ItemCreateParams; |
| 252 | + export import ItemListParams = API.ItemListParams; |
| 253 | + |
| 254 | + export import Metrics = API.Metrics; |
| 255 | + export import MetricCreateResponse = API.MetricCreateResponse; |
| 256 | + export import MetricListResponse = API.MetricListResponse; |
| 257 | + export import MetricFetchResponse = API.MetricFetchResponse; |
| 258 | + export import MetricListResponsesPage = API.MetricListResponsesPage; |
| 259 | + export import MetricCreateParams = API.MetricCreateParams; |
| 260 | + export import MetricListParams = API.MetricListParams; |
| 261 | + |
| 262 | + export import Plans = API.Plans; |
| 263 | + export import Plan = API.Plan; |
| 264 | + export import PlansPage = API.PlansPage; |
| 265 | + export import PlanCreateParams = API.PlanCreateParams; |
| 266 | + export import PlanUpdateParams = API.PlanUpdateParams; |
| 267 | + export import PlanListParams = API.PlanListParams; |
| 268 | + |
| 269 | + export import Prices = API.Prices; |
| 270 | + export import EvaluatePriceGroup = API.EvaluatePriceGroup; |
| 271 | + export import Price = API.Price; |
| 272 | + export import PriceEvaluateResponse = API.PriceEvaluateResponse; |
| 273 | + export import PricesPage = API.PricesPage; |
| 274 | + export import PriceCreateParams = API.PriceCreateParams; |
| 275 | + export import PriceListParams = API.PriceListParams; |
| 276 | + export import PriceEvaluateParams = API.PriceEvaluateParams; |
| 277 | + |
| 278 | + export import Subscriptions = API.Subscriptions; |
| 279 | + export import Subscription = API.Subscription; |
| 280 | + export import SubscriptionUsage = API.SubscriptionUsage; |
| 281 | + export import SubscriptionFetchCostsResponse = API.SubscriptionFetchCostsResponse; |
| 282 | + export import SubscriptionFetchScheduleResponse = API.SubscriptionFetchScheduleResponse; |
| 283 | + export import SubscriptionsPage = API.SubscriptionsPage; |
| 284 | + export import SubscriptionFetchScheduleResponsesPage = API.SubscriptionFetchScheduleResponsesPage; |
| 285 | + export import SubscriptionCreateParams = API.SubscriptionCreateParams; |
| 286 | + export import SubscriptionUpdateParams = API.SubscriptionUpdateParams; |
| 287 | + export import SubscriptionListParams = API.SubscriptionListParams; |
| 288 | + export import SubscriptionCancelParams = API.SubscriptionCancelParams; |
| 289 | + export import SubscriptionFetchCostsParams = API.SubscriptionFetchCostsParams; |
| 290 | + export import SubscriptionFetchScheduleParams = API.SubscriptionFetchScheduleParams; |
| 291 | + export import SubscriptionFetchUsageParams = API.SubscriptionFetchUsageParams; |
| 292 | + export import SubscriptionPriceIntervalsParams = API.SubscriptionPriceIntervalsParams; |
| 293 | + export import SubscriptionSchedulePlanChangeParams = API.SubscriptionSchedulePlanChangeParams; |
| 294 | + export import SubscriptionTriggerPhaseParams = API.SubscriptionTriggerPhaseParams; |
| 295 | + export import SubscriptionUnscheduleFixedFeeQuantityUpdatesParams = API.SubscriptionUnscheduleFixedFeeQuantityUpdatesParams; |
| 296 | + export import SubscriptionUpdateFixedFeeQuantityParams = API.SubscriptionUpdateFixedFeeQuantityParams; |
| 297 | + |
| 298 | + export import BillingCycleRelativeDate = API.BillingCycleRelativeDate; |
| 299 | + export import Discount = API.Discount; |
| 300 | + export import PaginationMetadata = API.PaginationMetadata; |
| 301 | +} |
0 commit comments