UNPKG

@balena/balena-pricing

Version:
112 lines (111 loc) 4.21 kB
import { TypedError } from 'typed-error'; export interface Credit { validFrom: Date; version: number; firstDiscountPriceCents: number; discountRate: number; discountThreshold: number; discountThresholdPriceCents: number; } interface Credits { [slug: string]: Credit[]; } interface Options { credits?: Credits; target?: 'current' | 'latest' | number | Date; } interface CreditRange { from: number; to?: number; } export declare class InvalidParametersError extends TypedError { constructor(message: string); } export declare class CreditPricing { credits: { [slug: string]: Credit[]; }; private target; constructor(options?: Options); /** * Gets and returns pricing for a given feature. * @param featureSlug - feature slug * @returns credit pricing definition * * @example * getDefinition('device:microservices'); */ getDefinition(featureSlug: string): Credit | undefined; /** * Adjust a given credit amount to be just over the line to be higher than * the given lower unit cost. This is used to handle rounding edge cases in * which the original range calculations were slightly off. * @param featureSlug - credit feature slug * @param lowerUnitCost - lower unit cost to adjust to * @param amount - starting point credit amount * @returns number of credits needed to be just above the lower unit cost * * @example * fixRange('device:microservices', 198, 1000); */ private fixRange; /** * Get credit amount range for a given unit cost. * @param featureSlug - feature slug * @param unitCost - unit cost * @param availableCredits - currently available credits * @returns credit amount range * * @example * getCreditRange('device:microservices', 190); * getCreditRange('device:microservices', 190, 1000); */ getCreditRange(featureSlug: string, unitCost: number, availableCredits?: number): CreditRange; /** * Calculates the price of a credit purchase * @param featureSlug - feature slug * @param availableCredits - total of available and currently accrued credits * @param creditsToPurchase - number of credits to purchase * @returns price of credits for purchase * * @example * getCreditPrice('device:microservices', 0, 25000); */ getCreditPrice(featureSlug: string, availableCredits: number, creditsToPurchase: number): number; /** * Calculate the total price of a credit purchase * @param featureSlug - feature slug * @param availableCredits - total of available and currently accrued credits * @param creditsToPurchase - number of credits to purchase * @returns total price of credits for purchase * * @example * getCreditTotalPrice('device:microservices', 0, 25000); */ getCreditTotalPrice(featureSlug: string, availableCredits: number, creditsToPurchase: number): number; /** * Calculate discount percentage when compared to dynamic pricing * @param featureSlug - feature slug * @param availableCredits - total of available and currently accrued credits * @param creditsToPurchase - number of credits to purchase * @param dynamicPriceCents - dynamic price in cents * @returns discount percentage * * @example * getDiscountOverDynamic('device:microservices', 0, 25000); */ getDiscountOverDynamic(featureSlug: string, availableCredits: number, creditsToPurchase: number, dynamicPriceCents: number): number; /** * Calculate the total savings of a credit purchase * @param featureSlug - feature slug * @param availableCredits - total of available and currently accrued credits * @param creditsToPurchase - number of credits to purchase * @param dynamicPriceCents - dynamic price in cents * @returns total savings of credits for purchase * * @example * getTotalSavings('device:microservices', 0, 25000, 100); */ getTotalSavings(featureSlug: string, availableCredits: number, creditsToPurchase: number, dynamicPriceCents: number): number; } export {};