UNPKG

orb-billing

Version:

The official TypeScript library for the Orb API

250 lines 14.1 kB
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. var _Orb_instances, _a, _Orb_baseURLOverridden; import { stringifyQuery } from "./internal/utils/query.mjs"; import * as Core from "./core.mjs"; import * as Errors from "./error.mjs"; import * as Pagination from "./pagination.mjs"; import * as Uploads from "./uploads.mjs"; import * as API from "./resources/index.mjs"; import { Alerts, AlertsPage, } from "./resources/alerts.mjs"; import { CreditBlocks, } from "./resources/credit-blocks.mjs"; import { CreditNotes } from "./resources/credit-notes.mjs"; import { InvoiceLineItems, } from "./resources/invoice-line-items.mjs"; import { InvoiceListSummaryResponsesPage, Invoices, } from "./resources/invoices.mjs"; import { Items, ItemsPage, } from "./resources/items.mjs"; import { LicenseTypeListResponsesPage, LicenseTypes, } from "./resources/license-types.mjs"; import { BillableMetricsPage, Metrics, } from "./resources/metrics.mjs"; import { SubscriptionChangeListResponsesPage, SubscriptionChanges, } from "./resources/subscription-changes.mjs"; import { SubscriptionFetchScheduleResponsesPage, SubscriptionsPage, } from "./resources/subscriptions.mjs"; import { TopLevel } from "./resources/top-level.mjs"; import { Beta, } from "./resources/beta/beta.mjs"; import { Coupons, CouponsPage, } from "./resources/coupons/coupons.mjs"; import { Customers, CustomersPage, } from "./resources/customers/customers.mjs"; import { DimensionalPriceGroupsPage, } from "./resources/dimensional-price-groups/dimensional-price-groups.mjs"; import { Events, } from "./resources/events/events.mjs"; import { LicenseListResponsesPage, Licenses, } from "./resources/licenses/licenses.mjs"; import { Plans, PlansPage, } from "./resources/plans/plans.mjs"; import { Prices, } from "./resources/prices/prices.mjs"; /** * API Client for interfacing with the Orb API. */ export class Orb extends Core.APIClient { /** * API Client for interfacing with the Orb API. * * @param {string | undefined} [opts.apiKey=process.env['ORB_API_KEY'] ?? undefined] * @param {string | null | undefined} [opts.webhookSecret=process.env['ORB_WEBHOOK_SECRET'] ?? null] * @param {string} [opts.baseURL=process.env['ORB_BASE_URL'] ?? https://api.withorb.com/v1] - Override the default base URL for the API. * @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out. * @param {number} [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections. * @param {Core.Fetch} [opts.fetch] - Specify a custom `fetch` function implementation. * @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request. * @param {Core.Headers} opts.defaultHeaders - Default headers to include with every request to the API. * @param {Core.DefaultQuery} opts.defaultQuery - Default query parameters to include with every request to the API. */ constructor({ baseURL = Core.readEnv('ORB_BASE_URL'), apiKey = Core.readEnv('ORB_API_KEY'), webhookSecret = Core.readEnv('ORB_WEBHOOK_SECRET') ?? null, ...opts } = {}) { if (apiKey === undefined) { throw new Errors.OrbError("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' })."); } const options = { apiKey, webhookSecret, ...opts, baseURL: baseURL || `https://api.withorb.com/v1`, }; super({ baseURL: options.baseURL, baseURLOverridden: baseURL ? baseURL !== 'https://api.withorb.com/v1' : false, timeout: options.timeout ?? 60000 /* 1 minute */, httpAgent: options.httpAgent, maxRetries: options.maxRetries, fetch: options.fetch, }); _Orb_instances.add(this); this.topLevel = new API.TopLevel(this); /** * The [Plan](/core-concepts#plan-and-price) resource represents a plan that can be subscribed to by a * customer. Plans define the billing behavior of the subscription. You can see more about how to configure prices * in the [Price resource](/reference/price). */ this.beta = new API.Beta(this); /** * A coupon represents a reusable discount configuration that can be applied either as a fixed or percentage amount to an invoice or subscription. Coupons are activated using a redemption code, which applies the discount to a subscription or invoice. The duration of a coupon determines how long it remains available for use by end users. */ this.coupons = new API.Coupons(this); /** * The [Credit Note](/invoicing/credit-notes) resource represents a credit that has been applied to a * particular invoice. */ this.creditNotes = new API.CreditNotes(this); /** * A customer is a buyer of your products, and the other party to the billing relationship. * * In Orb, customers are assigned system generated identifiers automatically, but it's often desirable to have these * match existing identifiers in your system. To avoid having to denormalize Orb ID information, you can pass in an * `external_customer_id` with your own identifier. See * [Customer ID Aliases](/events-and-metrics/customer-aliases) for further information about how these * aliases work in Orb. * * In addition to having an identifier in your system, a customer may exist in a payment provider solution like * Stripe. Use the `payment_provider_id` and the `payment_provider` enum field to express this mapping. * * A customer also has a timezone (from the standard [IANA timezone database](https://www.iana.org/time-zones)), which * defaults to your account's timezone. See [Timezone localization](/essentials/timezones) for * information on what this timezone parameter influences within Orb. */ this.customers = new API.Customers(this); /** * The [Event](/core-concepts#event) resource represents a usage event that has been created for a * customer. Events are the core of Orb's usage-based billing model, and are used to calculate the usage charges for * a given billing period. */ this.events = new API.Events(this); /** * An [`Invoice`](/core-concepts#invoice) is a fundamental billing entity, representing the request for payment for * a single subscription. This includes a set of line items, which correspond to prices in the subscription's plan and * can represent fixed recurring fees or usage-based fees. They are generated at the end of a billing period, or as * the result of an action, such as a cancellation. */ this.invoiceLineItems = new API.InvoiceLineItems(this); /** * An [`Invoice`](/core-concepts#invoice) is a fundamental billing entity, representing the request for payment for * a single subscription. This includes a set of line items, which correspond to prices in the subscription's plan and * can represent fixed recurring fees or usage-based fees. They are generated at the end of a billing period, or as * the result of an action, such as a cancellation. */ this.invoices = new API.Invoices(this); /** * The Item resource represents a sellable product or good. Items are associated with all line items, billable metrics, * and prices and are used for defining external sync behavior for invoices and tax calculation purposes. */ this.items = new API.Items(this); /** * The Metric resource represents a calculation of a quantity based on events. * Metrics are defined by the query that transforms raw usage events into meaningful values for your customers. */ this.metrics = new API.Metrics(this); /** * The [Plan](/core-concepts#plan-and-price) resource represents a plan that can be subscribed to by a * customer. Plans define the billing behavior of the subscription. You can see more about how to configure prices * in the [Price resource](/reference/price). */ this.plans = new API.Plans(this); /** * The Price resource represents a price that can be billed on a subscription, resulting in a charge on an invoice in * the form of an invoice line item. Prices take a quantity and determine an amount to bill. * * Orb supports a few different pricing models out of the box. Each of these models is serialized differently in a * given Price object. The model_type field determines the key for the configuration object that is present. * * For more on the types of prices, see [the core concepts documentation](/core-concepts#plan-and-price) */ this.prices = new API.Prices(this); this.subscriptions = new API.Subscriptions(this); this.webhooks = new API.Webhooks(this); /** * [Alerts within Orb](/product-catalog/configuring-alerts) monitor spending, * usage, or credit balance and trigger webhooks when a threshold is exceeded. * * Alerts created through the API can be scoped to either customers or subscriptions. */ this.alerts = new API.Alerts(this); this.dimensionalPriceGroups = new API.DimensionalPriceGroups(this); this.subscriptionChanges = new API.SubscriptionChanges(this); /** * The [Credit Ledger Entry resource](/product-catalog/prepurchase) models prepaid credits within Orb. */ this.creditBlocks = new API.CreditBlocks(this); /** * The LicenseType resource represents a type of license that can be assigned to users. * License types are used during billing by grouping metrics on the configured grouping key. */ this.licenseTypes = new API.LicenseTypes(this); this.licenses = new API.Licenses(this); this._options = options; this.idempotencyHeader = 'Idempotency-Key'; this.apiKey = apiKey; this.webhookSecret = webhookSecret; } defaultQuery() { return this._options.defaultQuery; } defaultHeaders(opts) { return { ...super.defaultHeaders(opts), ...this._options.defaultHeaders, }; } authHeaders(opts) { return { Authorization: `Bearer ${this.apiKey}` }; } stringifyQuery(query) { return stringifyQuery(query); } } _a = Orb, _Orb_instances = new WeakSet(), _Orb_baseURLOverridden = function _Orb_baseURLOverridden() { return this.baseURL !== 'https://api.withorb.com/v1'; }; Orb.Orb = _a; Orb.DEFAULT_TIMEOUT = 60000; // 1 minute Orb.OrbError = Errors.OrbError; Orb.APIError = Errors.APIError; Orb.APIConnectionError = Errors.APIConnectionError; Orb.APIConnectionTimeoutError = Errors.APIConnectionTimeoutError; Orb.APIUserAbortError = Errors.APIUserAbortError; Orb.URLNotFound = Errors.URLNotFound; Orb.NotFoundError = Errors.NotFoundError; Orb.ConflictError = Errors.ConflictError; Orb.RateLimitError = Errors.RateLimitError; Orb.BadRequestError = Errors.BadRequestError; Orb.RequestTooLarge = Errors.RequestTooLarge; Orb.TooManyRequests = Errors.TooManyRequests; Orb.ResourceNotFound = Errors.ResourceNotFound; Orb.ResourceConflict = Errors.ResourceConflict; Orb.ResourceTooLarge = Errors.ResourceTooLarge; Orb.AuthenticationError = Errors.AuthenticationError; Orb.InternalServerError = Errors.InternalServerError; Orb.ConstraintViolation = Errors.ConstraintViolation; Orb.FeatureNotAvailable = Errors.FeatureNotAvailable; Orb.PermissionDeniedError = Errors.PermissionDeniedError; Orb.RequestValidationError = Errors.RequestValidationError; Orb.OrbAuthenticationError = Errors.OrbAuthenticationError; Orb.OrbInternalServerError = Errors.OrbInternalServerError; Orb.UnprocessableEntityError = Errors.UnprocessableEntityError; Orb.DuplicateResourceCreation = Errors.DuplicateResourceCreation; Orb.toFile = Uploads.toFile; Orb.fileFromPath = Uploads.fileFromPath; Orb.TopLevel = TopLevel; Orb.Beta = Beta; Orb.Coupons = Coupons; Orb.CouponsPage = CouponsPage; Orb.CreditNotes = CreditNotes; Orb.Customers = Customers; Orb.CustomersPage = CustomersPage; Orb.Events = Events; Orb.InvoiceLineItems = InvoiceLineItems; Orb.Invoices = Invoices; Orb.InvoiceListSummaryResponsesPage = InvoiceListSummaryResponsesPage; Orb.Items = Items; Orb.ItemsPage = ItemsPage; Orb.Metrics = Metrics; Orb.BillableMetricsPage = BillableMetricsPage; Orb.Plans = Plans; Orb.PlansPage = PlansPage; Orb.Prices = Prices; Orb.SubscriptionsPage = SubscriptionsPage; Orb.SubscriptionFetchScheduleResponsesPage = SubscriptionFetchScheduleResponsesPage; Orb.Alerts = Alerts; Orb.AlertsPage = AlertsPage; Orb.DimensionalPriceGroupsPage = DimensionalPriceGroupsPage; Orb.SubscriptionChanges = SubscriptionChanges; Orb.SubscriptionChangeListResponsesPage = SubscriptionChangeListResponsesPage; Orb.CreditBlocks = CreditBlocks; Orb.LicenseTypes = LicenseTypes; Orb.LicenseTypeListResponsesPage = LicenseTypeListResponsesPage; Orb.Licenses = Licenses; Orb.LicenseListResponsesPage = LicenseListResponsesPage; export { toFile, fileFromPath } from "./uploads.mjs"; export { OrbError, APIError, APIConnectionError, APIConnectionTimeoutError, APIUserAbortError, URLNotFound, NotFoundError, ConflictError, RateLimitError, BadRequestError, RequestTooLarge, TooManyRequests, ResourceNotFound, ResourceConflict, ResourceTooLarge, AuthenticationError, InternalServerError, ConstraintViolation, FeatureNotAvailable, PermissionDeniedError, RequestValidationError, OrbAuthenticationError, OrbInternalServerError, UnprocessableEntityError, DuplicateResourceCreation, } from "./error.mjs"; export default Orb; //# sourceMappingURL=index.mjs.map