import type { RequestInit, RequestInfo } from "./internal/builtin-types.mjs"; import type { PromiseOrValue, MergedRequestInit, FinalizedRequestInit } from "./internal/types.mjs"; export type { Logger, LogLevel } from "./internal/utils/log.mjs"; import * as Opts from "./internal/request-options.mjs"; import * as Errors from "./core/error.mjs"; import * as Uploads from "./core/uploads.mjs"; import * as API from "./resources/index.mjs"; import { APIPromise } from "./core/api-promise.mjs"; import { ActivateSubscriptionCheckoutSessionClientSelectSchema, AddPaymentMethodCheckoutSessionClientSelectSchema, CheckoutSessionCreateParams, CheckoutSessionCreateResponse, CheckoutSessionListParams, CheckoutSessionListResponse, CheckoutSessionRetrieveResponse, CheckoutSessions, ProductCheckoutSessionClientSelectSchema, PurchaseCheckoutSessionClientSelectSchema } from "./resources/checkout-sessions.mjs"; import { CustomerClientSelectSchema, CustomerCreateParams, CustomerCreateResponse, CustomerListParams, CustomerListResponse, CustomerRetrieveBillingResponse, CustomerRetrieveResponse, CustomerUpdateParams, CustomerUpdateResponse, Customers, NonRenewingSubscriptionDetails, StandardSubscriptionDetails, ToggleSubscriptionItemFeatureRecord, UsageCreditGrantSubscriptionItemFeatureRecord } from "./resources/customers.mjs"; import { DefaultDiscountClientSelectSchema, DiscountCreateParams, DiscountCreateResponse, DiscountListParams, DiscountListResponse, DiscountRetrieveResponse, DiscountUpdateParams, DiscountUpdateResponse, Discounts, ForeverDiscountClientSelectSchema, NumberOfPaymentsDiscountClientSelectSchema } from "./resources/discounts.mjs"; import { InvoiceLineItemListParams, InvoiceLineItemListResponse, InvoiceLineItemRetrieveResponse, InvoiceLineItems } from "./resources/invoice-line-items.mjs"; import { InvoiceListParams, InvoiceListResponse, InvoiceRetrieveResponse, Invoices } from "./resources/invoices.mjs"; import { PaymentMethodListParams, PaymentMethodListResponse, PaymentMethodRetrieveResponse, PaymentMethods } from "./resources/payment-methods.mjs"; import { PaymentClientSelectSchema, PaymentListParams, PaymentListResponse, PaymentRefundParams, PaymentRefundResponse, PaymentRetrieveResponse, Payments } from "./resources/payments.mjs"; import { PriceCreateParams, PriceCreateResponse, PriceListParams, PriceListResponse, PriceUpdateParams, PriceUpdateResponse, Prices, SinglePaymentPriceClientSelectSchema, SubscriptionPriceClientSelectSchema, UsagePriceClientSelectSchema } from "./resources/prices.mjs"; import { PricingModelClientSelectSchema, PricingModelCloneParams, PricingModelCloneResponse, PricingModelCreateParams, PricingModelCreateResponse, PricingModelListParams, PricingModelListResponse, PricingModelRetrieveDefaultResponse, PricingModelRetrieveResponse, PricingModelUpdateParams, PricingModelUpdateResponse, PricingModels } from "./resources/pricing-models.mjs"; import { ProductClientSelectSchema, ProductCreateParams, ProductCreateResponse, ProductListParams, ProductListResponse, ProductRetrieveResponse, ProductUpdateParams, ProductUpdateResponse, Products } from "./resources/products.mjs"; import { ResourceClaimClaimParams, ResourceClaimClaimResponse, ResourceClaimListUsagesParams, ResourceClaimListUsagesResponse, ResourceClaimReleaseParams, ResourceClaimReleaseResponse, ResourceClaimRetrieveUsageParams, ResourceClaimRetrieveUsageResponse, ResourceClaims } from "./resources/resource-claims.mjs"; import { ResourceCreateParams, ResourceCreateResponse, ResourceListParams, ResourceListResponse, ResourceRetrieveResponse, ResourceUpdateParams, ResourceUpdateResponse, Resources } from "./resources/resources.mjs"; import { SubscriptionAdjustParams, SubscriptionAdjustResponse, SubscriptionCancelParams, SubscriptionCancelResponse, SubscriptionCreateParams, SubscriptionCreateResponse, SubscriptionListParams, SubscriptionListResponse, SubscriptionRetrieveResponse, SubscriptionUncancelResponse, Subscriptions } from "./resources/subscriptions.mjs"; import { UsageEventCreateParams, UsageEventCreateResponse, UsageEventRetrieveResponse, UsageEvents } from "./resources/usage-events.mjs"; import { UsageMeterCreateParams, UsageMeterCreateResponse, UsageMeterListParams, UsageMeterListResponse, UsageMeterRetrieveResponse, UsageMeterUpdateParams, UsageMeterUpdateResponse, UsageMeters } from "./resources/usage-meters.mjs"; import { type Fetch } from "./internal/builtin-types.mjs"; import { HeadersLike, NullableHeaders } from "./internal/headers.mjs"; import { FinalRequestOptions, RequestOptions } from "./internal/request-options.mjs"; import { type LogLevel, type Logger } from "./internal/utils/log.mjs"; export interface ClientOptions { /** * API key for accessing the Flowglad API */ apiKey?: string | undefined; /** * Override the default base URL for the API, e.g., "https://api.example.com/v2/" * * Defaults to process.env['FLOWGLAD_BASE_URL']. */ baseURL?: string | null | undefined; /** * The maximum amount of time (in milliseconds) that the client should wait for a response * from the server before timing out a single request. * * Note that request timeouts are retried by default, so in a worst-case scenario you may wait * much longer than this timeout before the promise succeeds or fails. * * @unit milliseconds */ timeout?: number | undefined; /** * Additional `RequestInit` options to be passed to `fetch` calls. * Properties will be overridden by per-request `fetchOptions`. */ fetchOptions?: MergedRequestInit | undefined; /** * Specify a custom `fetch` function implementation. * * If not provided, we expect that `fetch` is defined globally. */ fetch?: Fetch | undefined; /** * The maximum number of times that the client will retry a request in case of a * temporary failure, like a network error or a 5XX error from the server. * * @default 2 */ maxRetries?: number | undefined; /** * Default headers to include with every request to the API. * * These can be removed in individual requests by explicitly setting the * header to `null` in request options. */ defaultHeaders?: HeadersLike | undefined; /** * Default query parameters to include with every request to the API. * * These can be removed in individual requests by explicitly setting the * param to `undefined` in request options. */ defaultQuery?: Record | undefined; /** * Set the log level. * * Defaults to process.env['FLOWGLAD_LOG'] or 'warn' if it isn't set. */ logLevel?: LogLevel | undefined; /** * Set the logger. * * Defaults to globalThis.console. */ logger?: Logger | undefined; } /** * API Client for interfacing with the Flowglad API. */ export declare class Flowglad { #private; apiKey: string; baseURL: string; maxRetries: number; timeout: number; logger: Logger; logLevel: LogLevel | undefined; fetchOptions: MergedRequestInit | undefined; private fetch; protected idempotencyHeader?: string; private _options; /** * API Client for interfacing with the Flowglad API. * * @param {string | undefined} [opts.apiKey=process.env['FLOWGLAD_SECRET_KEY'] ?? undefined] * @param {string} [opts.baseURL=process.env['FLOWGLAD_BASE_URL'] ?? https://app.flowglad.com/] - 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 {MergedRequestInit} [opts.fetchOptions] - Additional `RequestInit` options to be passed to `fetch` calls. * @param {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 {HeadersLike} opts.defaultHeaders - Default headers to include with every request to the API. * @param {Record} opts.defaultQuery - Default query parameters to include with every request to the API. */ constructor({ baseURL, apiKey, ...opts }?: ClientOptions); /** * Create a new client instance re-using the same options given to the current client with optional overriding. */ withOptions(options: Partial): this; protected defaultQuery(): Record | undefined; protected validateHeaders({ values, nulls }: NullableHeaders): void; protected authHeaders(opts: FinalRequestOptions): Promise; protected stringifyQuery(query: Record): string; private getUserAgent; protected defaultIdempotencyKey(): string; protected makeStatusError(status: number, error: Object, message: string | undefined, headers: Headers): Errors.APIError; buildURL(path: string, query: Record | null | undefined, defaultBaseURL?: string | undefined): string; /** * Used as a callback for mutating the given `FinalRequestOptions` object. */ protected prepareOptions(options: FinalRequestOptions): Promise; /** * Used as a callback for mutating the given `RequestInit` object. * * This is useful for cases where you want to add certain headers based off of * the request properties, e.g. `method` or `url`. */ protected prepareRequest(request: RequestInit, { url, options }: { url: string; options: FinalRequestOptions; }): Promise; get(path: string, opts?: PromiseOrValue): APIPromise; post(path: string, opts?: PromiseOrValue): APIPromise; patch(path: string, opts?: PromiseOrValue): APIPromise; put(path: string, opts?: PromiseOrValue): APIPromise; delete(path: string, opts?: PromiseOrValue): APIPromise; private methodRequest; request(options: PromiseOrValue, remainingRetries?: number | null): APIPromise; private makeRequest; fetchWithTimeout(url: RequestInfo, init: RequestInit | undefined, ms: number, controller: AbortController): Promise; private shouldRetry; private retryRequest; private calculateDefaultRetryTimeoutMillis; buildRequest(inputOptions: FinalRequestOptions, { retryCount }?: { retryCount?: number; }): Promise<{ req: FinalizedRequestInit; url: string; timeout: number; }>; private buildHeaders; private buildBody; static Flowglad: typeof Flowglad; static DEFAULT_TIMEOUT: number; static FlowgladError: typeof Errors.FlowgladError; static APIError: typeof Errors.APIError; static APIConnectionError: typeof Errors.APIConnectionError; static APIConnectionTimeoutError: typeof Errors.APIConnectionTimeoutError; static APIUserAbortError: typeof Errors.APIUserAbortError; static NotFoundError: typeof Errors.NotFoundError; static ConflictError: typeof Errors.ConflictError; static RateLimitError: typeof Errors.RateLimitError; static BadRequestError: typeof Errors.BadRequestError; static AuthenticationError: typeof Errors.AuthenticationError; static InternalServerError: typeof Errors.InternalServerError; static PermissionDeniedError: typeof Errors.PermissionDeniedError; static UnprocessableEntityError: typeof Errors.UnprocessableEntityError; static toFile: typeof Uploads.toFile; invoices: API.Invoices; invoiceLineItems: API.InvoiceLineItems; pricingModels: API.PricingModels; checkoutSessions: API.CheckoutSessions; products: API.Products; prices: API.Prices; discounts: API.Discounts; customers: API.Customers; payments: API.Payments; paymentMethods: API.PaymentMethods; subscriptions: API.Subscriptions; usageEvents: API.UsageEvents; usageMeters: API.UsageMeters; resources: API.Resources; resourceClaims: API.ResourceClaims; } export declare namespace Flowglad { export type RequestOptions = Opts.RequestOptions; export { Invoices as Invoices, type InvoiceRetrieveResponse as InvoiceRetrieveResponse, type InvoiceListResponse as InvoiceListResponse, type InvoiceListParams as InvoiceListParams, }; export { InvoiceLineItems as InvoiceLineItems, type InvoiceLineItemRetrieveResponse as InvoiceLineItemRetrieveResponse, type InvoiceLineItemListResponse as InvoiceLineItemListResponse, type InvoiceLineItemListParams as InvoiceLineItemListParams, }; export { PricingModels as PricingModels, type PricingModelClientSelectSchema as PricingModelClientSelectSchema, type PricingModelCreateResponse as PricingModelCreateResponse, type PricingModelRetrieveResponse as PricingModelRetrieveResponse, type PricingModelUpdateResponse as PricingModelUpdateResponse, type PricingModelListResponse as PricingModelListResponse, type PricingModelCloneResponse as PricingModelCloneResponse, type PricingModelRetrieveDefaultResponse as PricingModelRetrieveDefaultResponse, type PricingModelCreateParams as PricingModelCreateParams, type PricingModelUpdateParams as PricingModelUpdateParams, type PricingModelListParams as PricingModelListParams, type PricingModelCloneParams as PricingModelCloneParams, }; export { CheckoutSessions as CheckoutSessions, type ActivateSubscriptionCheckoutSessionClientSelectSchema as ActivateSubscriptionCheckoutSessionClientSelectSchema, type AddPaymentMethodCheckoutSessionClientSelectSchema as AddPaymentMethodCheckoutSessionClientSelectSchema, type ProductCheckoutSessionClientSelectSchema as ProductCheckoutSessionClientSelectSchema, type PurchaseCheckoutSessionClientSelectSchema as PurchaseCheckoutSessionClientSelectSchema, type CheckoutSessionCreateResponse as CheckoutSessionCreateResponse, type CheckoutSessionRetrieveResponse as CheckoutSessionRetrieveResponse, type CheckoutSessionListResponse as CheckoutSessionListResponse, type CheckoutSessionCreateParams as CheckoutSessionCreateParams, type CheckoutSessionListParams as CheckoutSessionListParams, }; export { Products as Products, type ProductClientSelectSchema as ProductClientSelectSchema, type ProductCreateResponse as ProductCreateResponse, type ProductRetrieveResponse as ProductRetrieveResponse, type ProductUpdateResponse as ProductUpdateResponse, type ProductListResponse as ProductListResponse, type ProductCreateParams as ProductCreateParams, type ProductUpdateParams as ProductUpdateParams, type ProductListParams as ProductListParams, }; export { Prices as Prices, type SinglePaymentPriceClientSelectSchema as SinglePaymentPriceClientSelectSchema, type SubscriptionPriceClientSelectSchema as SubscriptionPriceClientSelectSchema, type UsagePriceClientSelectSchema as UsagePriceClientSelectSchema, type PriceCreateResponse as PriceCreateResponse, type PriceUpdateResponse as PriceUpdateResponse, type PriceListResponse as PriceListResponse, type PriceCreateParams as PriceCreateParams, type PriceUpdateParams as PriceUpdateParams, type PriceListParams as PriceListParams, }; export { Discounts as Discounts, type DefaultDiscountClientSelectSchema as DefaultDiscountClientSelectSchema, type ForeverDiscountClientSelectSchema as ForeverDiscountClientSelectSchema, type NumberOfPaymentsDiscountClientSelectSchema as NumberOfPaymentsDiscountClientSelectSchema, type DiscountCreateResponse as DiscountCreateResponse, type DiscountRetrieveResponse as DiscountRetrieveResponse, type DiscountUpdateResponse as DiscountUpdateResponse, type DiscountListResponse as DiscountListResponse, type DiscountCreateParams as DiscountCreateParams, type DiscountUpdateParams as DiscountUpdateParams, type DiscountListParams as DiscountListParams, }; export { Customers as Customers, type CustomerClientSelectSchema as CustomerClientSelectSchema, type NonRenewingSubscriptionDetails as NonRenewingSubscriptionDetails, type StandardSubscriptionDetails as StandardSubscriptionDetails, type ToggleSubscriptionItemFeatureRecord as ToggleSubscriptionItemFeatureRecord, type UsageCreditGrantSubscriptionItemFeatureRecord as UsageCreditGrantSubscriptionItemFeatureRecord, type CustomerCreateResponse as CustomerCreateResponse, type CustomerRetrieveResponse as CustomerRetrieveResponse, type CustomerUpdateResponse as CustomerUpdateResponse, type CustomerListResponse as CustomerListResponse, type CustomerRetrieveBillingResponse as CustomerRetrieveBillingResponse, type CustomerCreateParams as CustomerCreateParams, type CustomerUpdateParams as CustomerUpdateParams, type CustomerListParams as CustomerListParams, }; export { Payments as Payments, type PaymentClientSelectSchema as PaymentClientSelectSchema, type PaymentRetrieveResponse as PaymentRetrieveResponse, type PaymentListResponse as PaymentListResponse, type PaymentRefundResponse as PaymentRefundResponse, type PaymentListParams as PaymentListParams, type PaymentRefundParams as PaymentRefundParams, }; export { PaymentMethods as PaymentMethods, type PaymentMethodRetrieveResponse as PaymentMethodRetrieveResponse, type PaymentMethodListResponse as PaymentMethodListResponse, type PaymentMethodListParams as PaymentMethodListParams, }; export { Subscriptions as Subscriptions, type SubscriptionCreateResponse as SubscriptionCreateResponse, type SubscriptionRetrieveResponse as SubscriptionRetrieveResponse, type SubscriptionListResponse as SubscriptionListResponse, type SubscriptionAdjustResponse as SubscriptionAdjustResponse, type SubscriptionCancelResponse as SubscriptionCancelResponse, type SubscriptionUncancelResponse as SubscriptionUncancelResponse, type SubscriptionCreateParams as SubscriptionCreateParams, type SubscriptionListParams as SubscriptionListParams, type SubscriptionAdjustParams as SubscriptionAdjustParams, type SubscriptionCancelParams as SubscriptionCancelParams, }; export { UsageEvents as UsageEvents, type UsageEventCreateResponse as UsageEventCreateResponse, type UsageEventRetrieveResponse as UsageEventRetrieveResponse, type UsageEventCreateParams as UsageEventCreateParams, }; export { UsageMeters as UsageMeters, type UsageMeterCreateResponse as UsageMeterCreateResponse, type UsageMeterRetrieveResponse as UsageMeterRetrieveResponse, type UsageMeterUpdateResponse as UsageMeterUpdateResponse, type UsageMeterListResponse as UsageMeterListResponse, type UsageMeterCreateParams as UsageMeterCreateParams, type UsageMeterUpdateParams as UsageMeterUpdateParams, type UsageMeterListParams as UsageMeterListParams, }; export { Resources as Resources, type ResourceCreateResponse as ResourceCreateResponse, type ResourceRetrieveResponse as ResourceRetrieveResponse, type ResourceUpdateResponse as ResourceUpdateResponse, type ResourceListResponse as ResourceListResponse, type ResourceCreateParams as ResourceCreateParams, type ResourceUpdateParams as ResourceUpdateParams, type ResourceListParams as ResourceListParams, }; export { ResourceClaims as ResourceClaims, type ResourceClaimClaimResponse as ResourceClaimClaimResponse, type ResourceClaimListUsagesResponse as ResourceClaimListUsagesResponse, type ResourceClaimReleaseResponse as ResourceClaimReleaseResponse, type ResourceClaimRetrieveUsageResponse as ResourceClaimRetrieveUsageResponse, type ResourceClaimClaimParams as ResourceClaimClaimParams, type ResourceClaimListUsagesParams as ResourceClaimListUsagesParams, type ResourceClaimReleaseParams as ResourceClaimReleaseParams, type ResourceClaimRetrieveUsageParams as ResourceClaimRetrieveUsageParams, }; export type BillingAddress = API.BillingAddress; export type NonRenewingSubscriptionRecord = API.NonRenewingSubscriptionRecord; export type PaymentMethodClientSelectSchema = API.PaymentMethodClientSelectSchema; export type PricingModelDetailsRecord = API.PricingModelDetailsRecord; export type PurchaseInvoiceClientSelectSchema = API.PurchaseInvoiceClientSelectSchema; export type StandaloneInvoiceClientSelectSchema = API.StandaloneInvoiceClientSelectSchema; export type StandardSubscriptionRecord = API.StandardSubscriptionRecord; export type StaticInvoiceLineItemClientSelectSchema = API.StaticInvoiceLineItemClientSelectSchema; export type SubscriptionInvoiceClientSelectSchema = API.SubscriptionInvoiceClientSelectSchema; export type ToggleFeatureClientSelectSchema = API.ToggleFeatureClientSelectSchema; export type UsageCreditGrantFeatureClientSelectSchema = API.UsageCreditGrantFeatureClientSelectSchema; export type UsageInvoiceLineItemClientSelectSchema = API.UsageInvoiceLineItemClientSelectSchema; export type UsageMeterClientSelectSchema = API.UsageMeterClientSelectSchema; } //# sourceMappingURL=client.d.mts.map