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

68 lines (67 loc) 2.7 kB
import { PricingContext } from '../configuration/PricingContext'; import { FeatureStatus } from './pricing-evaluator'; /** * Utility class for handling JSON Web Tokens related to pricing. */ export declare class PricingJwtUtils { private static context; /** * Decodes a Pricing JSON Web Token. * * @param token - The JWT to decode. * @returns The decoded token as a Record<string, any. * @throws {PricingTokenError} If the token is not found or expired. */ static decodeToken(token: string | undefined): Record<string, any>; /** * Encodes a set of claims into a JSON Web Token (JWT). * * @param claims - The claims to encode into the token. * @returns The encoded JWT. * @throws {PricingTokenError} If required claims are missing. */ static encodeToken(claims: Record<string, any>): string; /** * Extracts the evaluated features from a Pricing JSON Web Token (JWT). * * @param token - The JWT to extract features from. * @returns The features as a Record<string, {@link FeatureStatus}>. */ static getFeaturesFromJwtToken(token: string): Record<string, FeatureStatus>; /** * Extracts the subject from a Pricing JSON Web Token (JWT). * * @param token - The JWT to extract the subject from. * @returns The subject as a string. */ static getSubjectFromJwtToken(token: string): string; /** * Updates the features in a Pricing JSON Web Token (JWT). * * @param oldToken - The JWT to update. * @param newFeatureStatuses - A *Record<string, {@link FeatureStatus}>* showcasing the new features evaluation to update in the token. * @returns The updated JWT. */ static updateTokenFeatures(oldToken: string, newFeatureStatuses: Record<string, FeatureStatus>): string; /** * Updates a specific feature in a Pricing JSON Web Token (JWT). * * @param oldToken - The JWT to update. * @param newFeatureStatuses - A *Record<string, {@link FeatureStatus}>* showcasing the new features evaluation to update in the token. * @returns The updated JWT. */ static updateEvalOfTokenFeature(oldToken: string, featureToChangeEval: string, newEval: string): string; /** * Configures the {@links PricingContext} that will be used to perform the JWT operations. * * @param context - The {@link PricingContext} to set. */ static setContext(context: PricingContext): void; /** * Checks if a JSON Web Token is expired. * * @param token - The JWT to check. * @returns *true* if the token is expired, *false* otherwise. */ private static isJwtExpired; }