/** * @module client */ import { Answer } from './answer.js'; import { TierError } from './tier-error.js'; import { CheckoutParams, CheckoutResponse, CurrentPhase, FeatureName, Features, Limits, LookupOrgResponse, Model, OrgInfo, OrgName, PaymentMethodsResponse, Phase, PushResponse, ReportParams, ScheduleParams, ScheduleResponse, SubscribeParams, Usage, WhoAmIResponse, WhoIsResponse } from './tier-types.js'; export { Answer } from './answer.js'; export { isErrorResponse, isTierError, TierError } from './tier-error.js'; export { isAggregate, isDivide, isFeatureDefinition, isFeatureName, isFeatureNameVersioned, isFeatures, isFeatureTier, isInterval, isMode, isModel, isOrgName, isPhase, isPlan, isPlanName, validateDivide, validateFeatureDefinition, validateFeatureTier, validateModel, validatePlan, } from './tier-types.js'; export type { Aggregate, CancelPhase, CheckoutParams, CheckoutResponse, CurrentPhase, CurrentPhaseResponse, Divide, FeatureDefinition, FeatureName, FeatureNameVersioned, Features, FeatureTier, Interval, Limits, LookupOrgResponse, Mode, Model, OrgInfo, OrgName, PaymentMethodsResponse, Phase, Plan, PlanName, PushResponse, ReportParams, ReportResponse, ScheduleParams, ScheduleResponse, SubscribeParams, Usage, WhoAmIResponse, WhoIsResponse, } from './tier-types.js'; /** * Tier constructor options for cases where the baseURL is * set by the environment. */ export interface TierGetClientOptions { baseURL?: string; apiKey?: string; fetchImpl?: typeof fetch; debug?: boolean; onError?: (er: TierError) => any; signal?: AbortSignal; userAgent?: string | false; } /** * Options for the Tier constructor. Same as {@link TierGetClientOptions}, * but baseURL is required. */ export interface TierOptions extends TierGetClientOptions { baseURL: string; } export interface TierWithClockOptions extends TierOptions { clockID: string; } /** * The Tier client, main interface provided by the SDK. * * All methods are re-exported as top level functions by the main * package export, in such a way that they create a client and * spin up a Tier sidecar process on demand. */ export declare class Tier { /** * The `fetch()` implementation in use. Will default to the Node * built-in `fetch` if available, otherwise `node-fetch` will be used. */ readonly fetch: typeof fetch; /** * The URL to the sidecar providing API endpoints */ readonly baseURL: string; /** * A method which is called on all errors, useful for logging, * or handling 401 responses from a public tier API. */ onError?: (er: TierError) => any; /** * API key for use with the hosted service on tier.run */ readonly apiKey: string; /** * AbortSignal used to cancel all requests from this client. */ signal?: AbortSignal; /** * The User-Agent header that Tier sends. * * Set to `false` to not send a user agent header. Leave blank to * send the default User-Agent header, which includes the Tier client * version, along with either Node.js process.version or browser's * navigator.userAgent */ userAgent?: string | false; /** * Create a new Tier client. Set `{ debug: true }` in the * options object to enable debugging output. */ constructor({ baseURL, apiKey, fetchImpl, debug, onError, signal, userAgent, }: TierOptions); withClock(name: string, start?: Date): Promise; protected debugLog(..._: any[]): void; protected set debug(d: boolean); protected apiGet(path: string, query?: { [k: string]: string | string[]; }): Promise; protected tryGet(path: string, query?: { [k: string]: string | string[]; }): Promise; protected apiPost(path: string, body: TReq): Promise; protected tryPost(path: string, body: TReq): Promise; /** * Look up the limits for all features for a given {@link types.OrgName} */ lookupLimits(org: OrgName): Promise; /** * Look up the payment methods on file for a given {@link types.OrgName} */ lookupPaymentMethods(org: OrgName): Promise; /** * Look up limits for a given {@link types.FeatureName} and {@link types.OrgName} */ lookupLimit(org: OrgName, feature: FeatureName): Promise; /** * Report metered feature usage */ report(org: OrgName, feature: FeatureName, n?: number, { at, clobber }?: ReportParams): Promise<{}>; /** * Generate a checkout URL to set an org's payment info, and optionally * to create a subscription on completion. * * `successUrl` param should be a URL within your application where the * user will be redirected upon completion. */ checkout(org: OrgName, successUrl: string, params?: CheckoutParams): Promise; /** * Simple interface for creating a new phase in the org's subscription * schedule. * * Setting `trialDays` will cause it to prepend a "trial" phase on the * effective date, and delay the creation of the actual non-trial * subscription phase by the specified number of days. */ subscribe(org: OrgName, features: Features | Features[], { effective, info, trialDays, paymentMethodID }?: SubscribeParams): Promise; /** * Cancel an org's subscriptions */ cancel(org: OrgName): Promise; /** * Advanced interface for creating arbitrary schedule phases in any * order. */ schedule(org: OrgName, phases?: Phase[], { info, paymentMethodID }?: ScheduleParams): Promise; /** * Update an org's metadata. Note that any fields not set (other than * `metadata`) will be reset to empty `''` values on any update. */ updateOrg(org: OrgName, info: OrgInfo): Promise; /** * Get an org's billing provider identifier */ whois(org: OrgName): Promise; /** * Look up all {@link types.OrgInfo} metadata about an org */ lookupOrg(org: OrgName): Promise; /** * Fetch the current phase for an org */ lookupPhase(org: OrgName): Promise; /** * Pull the full {@link types.Model} pushed to Tier */ pull(): Promise; /** * Similar to {@link Tier.pull}, but filters plans to only include * the highest version of each plan. Plan versions are sorted numerically * if they are decimal integers, or lexically in the `en` locale otherwise. * * So, for example, the plan version `20test` will be considered "lower" * than `9test`, because the non-numeric string causes it to be lexically * sorted. But the plan version `20` sill be considered "higher" than the * plan version `9`, because both are strictly numeric. * * **Note** Plan versions are inherently arbitrary, and as such, they really * should not be sorted or given any special priority by being "latest". * * This method will be removed in version 6 of this SDK. * * @deprecated */ pullLatest(): Promise; /** * Push a new {@link types.Model} to Tier * * Any previously pushed {@link types.PlanName} will be ignored, new * plans will be added. */ push(model: Model): Promise; /** * Get information about the current sidecare API in use */ whoami(): Promise; /** * Return an {@link answer.Answer} indicating whether an org can * access a feature, or if they are at their plan limit. */ can(org: OrgName, feature: FeatureName): Promise; /** * @deprecated alias for {@link Tier#lookupLimits} */ limits(org: OrgName): Promise; /** * @deprecated alias for {@link Tier#lookupLimit} */ limit(org: OrgName, feature: FeatureName): Promise; /** * @deprecated alias for {@link Tier#lookupPhase} */ phase(org: OrgName): Promise; } export declare class TierWithClock extends Tier { #private; /** * The ID of a stripe test clock. Set via {@link withClock} */ clockID: string; constructor(options: TierWithClockOptions); advance(t: Date): Promise; } //# sourceMappingURL=client.d.ts.map