UNPKG

orb-billing

Version:

The official TypeScript library for the Orb API

212 lines 13.2 kB
"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 qs = __importStar(require("./internal/qs/index.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_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 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 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); 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' }); } } 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.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; 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