UNPKG

pricing4ts

Version:

![NPM Version](https://img.shields.io/npm/v/pricing4ts) Pricing4TS is a TypeScript-based toolkit designed to enhance the server-side functionality of a pricing-driven SaaS by enabling the seamless integration of pricing plans into the application logic. T

33 lines (32 loc) 1.75 kB
import { Configuration } from '../configuration/PricingContext'; import { Feature } from '../../types'; import { PaymentType } from '../../main/models/pricing2yaml/feature'; export interface FeatureStatus { eval: Boolean | string; used: string | number | boolean | null; limit: string | number | boolean | null; } export interface ExtendedFeatureStatus extends FeatureStatus { error: { code: string; message: string; } | null; } export type ContextToEval = Record<'features' | 'usageLimits', Record<string, string | boolean | number | PaymentType[]>>; export declare function generateUserPricingToken(): string; /** * Modifies the given JWT by changing the evaluation of the specified feature * using a {@link string} expression that will be evaluated on the client side * of the application. * * @param token The generated JWT returned by the * {@link generateUserPricingToken()} method. * @param featureId The ID of a feature defined within the token body. * @param expression The expression for the feature that will replace its * current evaluation. * @returns A modified version of the provided JWT containing the new expression * in the "eval" attribute of the specified feature. */ export declare function addExpressionToToken(token: string, featureId: string, expression: string): string; export declare function extractContextToEvalFromSubscriptionContext(subscriptionContext: Configuration): ContextToEval; export declare function evaluateFeature(feature: Feature | string, configuration?: Configuration | undefined, subscriptionContext?: Record<string, any> | undefined, pricingContext?: ContextToEval | undefined): ExtendedFeatureStatus;