orb-billing
Version:
The official TypeScript library for the Orb API
305 lines • 19.3 kB
JavaScript
"use strict";
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var _Orb_instances, _a, _Orb_baseURLOverridden;
Object.defineProperty(exports, "__esModule", { value: true });
exports.DuplicateResourceCreation = exports.UnprocessableEntityError = exports.OrbInternalServerError = exports.OrbAuthenticationError = exports.RequestValidationError = exports.PermissionDeniedError = exports.FeatureNotAvailable = exports.ConstraintViolation = exports.InternalServerError = exports.AuthenticationError = exports.ResourceTooLarge = exports.ResourceConflict = exports.ResourceNotFound = exports.TooManyRequests = exports.RequestTooLarge = exports.BadRequestError = exports.RateLimitError = exports.ConflictError = exports.NotFoundError = exports.URLNotFound = exports.APIUserAbortError = exports.APIConnectionTimeoutError = exports.APIConnectionError = exports.APIError = exports.OrbError = exports.fileFromPath = exports.toFile = exports.Orb = void 0;
const query_1 = require("./internal/utils/query.js");
const Core = __importStar(require("./core.js"));
const Errors = __importStar(require("./error.js"));
const Pagination = __importStar(require("./pagination.js"));
const Uploads = __importStar(require("./uploads.js"));
const API = __importStar(require("./resources/index.js"));
const alerts_1 = require("./resources/alerts.js");
const credit_blocks_1 = require("./resources/credit-blocks.js");
const credit_notes_1 = require("./resources/credit-notes.js");
const invoice_line_items_1 = require("./resources/invoice-line-items.js");
const invoices_1 = require("./resources/invoices.js");
const items_1 = require("./resources/items.js");
const license_types_1 = require("./resources/license-types.js");
const metrics_1 = require("./resources/metrics.js");
const subscription_changes_1 = require("./resources/subscription-changes.js");
const subscriptions_1 = require("./resources/subscriptions.js");
const top_level_1 = require("./resources/top-level.js");
const beta_1 = require("./resources/beta/beta.js");
const coupons_1 = require("./resources/coupons/coupons.js");
const customers_1 = require("./resources/customers/customers.js");
const dimensional_price_groups_1 = require("./resources/dimensional-price-groups/dimensional-price-groups.js");
const events_1 = require("./resources/events/events.js");
const licenses_1 = require("./resources/licenses/licenses.js");
const plans_1 = require("./resources/plans/plans.js");
const prices_1 = require("./resources/prices/prices.js");
/**
* API Client for interfacing with the Orb API.
*/
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 (0, query_1.stringifyQuery)(query);
}
}
exports.Orb = Orb;
_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 = top_level_1.TopLevel;
Orb.Beta = beta_1.Beta;
Orb.Coupons = coupons_1.Coupons;
Orb.CouponsPage = coupons_1.CouponsPage;
Orb.CreditNotes = credit_notes_1.CreditNotes;
Orb.Customers = customers_1.Customers;
Orb.CustomersPage = customers_1.CustomersPage;
Orb.Events = events_1.Events;
Orb.InvoiceLineItems = invoice_line_items_1.InvoiceLineItems;
Orb.Invoices = invoices_1.Invoices;
Orb.InvoiceListSummaryResponsesPage = invoices_1.InvoiceListSummaryResponsesPage;
Orb.Items = items_1.Items;
Orb.ItemsPage = items_1.ItemsPage;
Orb.Metrics = metrics_1.Metrics;
Orb.BillableMetricsPage = metrics_1.BillableMetricsPage;
Orb.Plans = plans_1.Plans;
Orb.PlansPage = plans_1.PlansPage;
Orb.Prices = prices_1.Prices;
Orb.SubscriptionsPage = subscriptions_1.SubscriptionsPage;
Orb.SubscriptionFetchScheduleResponsesPage = subscriptions_1.SubscriptionFetchScheduleResponsesPage;
Orb.Alerts = alerts_1.Alerts;
Orb.AlertsPage = alerts_1.AlertsPage;
Orb.DimensionalPriceGroupsPage = dimensional_price_groups_1.DimensionalPriceGroupsPage;
Orb.SubscriptionChanges = subscription_changes_1.SubscriptionChanges;
Orb.SubscriptionChangeListResponsesPage = subscription_changes_1.SubscriptionChangeListResponsesPage;
Orb.CreditBlocks = credit_blocks_1.CreditBlocks;
Orb.LicenseTypes = license_types_1.LicenseTypes;
Orb.LicenseTypeListResponsesPage = license_types_1.LicenseTypeListResponsesPage;
Orb.Licenses = licenses_1.Licenses;
Orb.LicenseListResponsesPage = licenses_1.LicenseListResponsesPage;
var uploads_1 = require("./uploads.js");
Object.defineProperty(exports, "toFile", { enumerable: true, get: function () { return uploads_1.toFile; } });
Object.defineProperty(exports, "fileFromPath", { enumerable: true, get: function () { return uploads_1.fileFromPath; } });
var error_1 = require("./error.js");
Object.defineProperty(exports, "OrbError", { enumerable: true, get: function () { return error_1.OrbError; } });
Object.defineProperty(exports, "APIError", { enumerable: true, get: function () { return error_1.APIError; } });
Object.defineProperty(exports, "APIConnectionError", { enumerable: true, get: function () { return error_1.APIConnectionError; } });
Object.defineProperty(exports, "APIConnectionTimeoutError", { enumerable: true, get: function () { return error_1.APIConnectionTimeoutError; } });
Object.defineProperty(exports, "APIUserAbortError", { enumerable: true, get: function () { return error_1.APIUserAbortError; } });
Object.defineProperty(exports, "URLNotFound", { enumerable: true, get: function () { return error_1.URLNotFound; } });
Object.defineProperty(exports, "NotFoundError", { enumerable: true, get: function () { return error_1.NotFoundError; } });
Object.defineProperty(exports, "ConflictError", { enumerable: true, get: function () { return error_1.ConflictError; } });
Object.defineProperty(exports, "RateLimitError", { enumerable: true, get: function () { return error_1.RateLimitError; } });
Object.defineProperty(exports, "BadRequestError", { enumerable: true, get: function () { return error_1.BadRequestError; } });
Object.defineProperty(exports, "RequestTooLarge", { enumerable: true, get: function () { return error_1.RequestTooLarge; } });
Object.defineProperty(exports, "TooManyRequests", { enumerable: true, get: function () { return error_1.TooManyRequests; } });
Object.defineProperty(exports, "ResourceNotFound", { enumerable: true, get: function () { return error_1.ResourceNotFound; } });
Object.defineProperty(exports, "ResourceConflict", { enumerable: true, get: function () { return error_1.ResourceConflict; } });
Object.defineProperty(exports, "ResourceTooLarge", { enumerable: true, get: function () { return error_1.ResourceTooLarge; } });
Object.defineProperty(exports, "AuthenticationError", { enumerable: true, get: function () { return error_1.AuthenticationError; } });
Object.defineProperty(exports, "InternalServerError", { enumerable: true, get: function () { return error_1.InternalServerError; } });
Object.defineProperty(exports, "ConstraintViolation", { enumerable: true, get: function () { return error_1.ConstraintViolation; } });
Object.defineProperty(exports, "FeatureNotAvailable", { enumerable: true, get: function () { return error_1.FeatureNotAvailable; } });
Object.defineProperty(exports, "PermissionDeniedError", { enumerable: true, get: function () { return error_1.PermissionDeniedError; } });
Object.defineProperty(exports, "RequestValidationError", { enumerable: true, get: function () { return error_1.RequestValidationError; } });
Object.defineProperty(exports, "OrbAuthenticationError", { enumerable: true, get: function () { return error_1.OrbAuthenticationError; } });
Object.defineProperty(exports, "OrbInternalServerError", { enumerable: true, get: function () { return error_1.OrbInternalServerError; } });
Object.defineProperty(exports, "UnprocessableEntityError", { enumerable: true, get: function () { return error_1.UnprocessableEntityError; } });
Object.defineProperty(exports, "DuplicateResourceCreation", { enumerable: true, get: function () { return error_1.DuplicateResourceCreation; } });
exports = module.exports = Orb;
exports.default = Orb;
//# sourceMappingURL=index.js.map