orb-billing
Version:
The official TypeScript library for the Orb API
157 lines • 8.02 kB
JavaScript
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
var _Orb_instances, _a, _Orb_baseURLOverridden;
import * as qs from "./internal/qs/index.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 { CreditNotes } from "./resources/credit-notes.mjs";
import { InvoiceLineItems, } from "./resources/invoice-line-items.mjs";
import { Invoices, } from "./resources/invoices.mjs";
import { Items, ItemsPage, } from "./resources/items.mjs";
import { BillableMetricsPage, Metrics, } from "./resources/metrics.mjs";
import { 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 { 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);
this.beta = new API.Beta(this);
this.coupons = new API.Coupons(this);
this.creditNotes = new API.CreditNotes(this);
this.customers = new API.Customers(this);
this.events = new API.Events(this);
this.invoiceLineItems = new API.InvoiceLineItems(this);
this.invoices = new API.Invoices(this);
this.items = new API.Items(this);
this.metrics = new API.Metrics(this);
this.plans = new API.Plans(this);
this.prices = new API.Prices(this);
this.subscriptions = new API.Subscriptions(this);
this.webhooks = new API.Webhooks(this);
this.alerts = new API.Alerts(this);
this.dimensionalPriceGroups = new API.DimensionalPriceGroups(this);
this.subscriptionChanges = new API.SubscriptionChanges(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 qs.stringify(query, { arrayFormat: 'brackets' });
}
}
_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.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;
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