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

62 lines (61 loc) 2.18 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PricingContext = void 0; var PricingPlanEvaluationError_1 = require("../exceptions/PricingPlanEvaluationError"); var server_1 = require("../server"); /** * An abstract class from which to create a component that adapts the pricing * configuration to the application domain */ var PricingContext = /** @class */ (function () { function PricingContext() { } /** * Returns the expiration time of the JWT in milliseconds * * @returns JWT expiration time in milliseconds */ PricingContext.prototype.getJwtExpiration = function () { return 86400000; }; /** * This method can be used to determine which users are affected * by the pricing, so a pricing-driven JWT will be only generated * for them. * * @returns A boolean indicating the condition to include or exclude the pricing evaluation context in the JWT. */ PricingContext.prototype.userAffectedByPricing = function () { return true; }; /** * This method returns the plan context of the current user, represented by a * *Record<string, boolean | string | number | PaymentType[]>*. It's used to evaluate the pricing plan. * * @return current user's plan context */ PricingContext.prototype.getPlanContext = function () { var _a; var userPlan = this.getPricing().plans[this.getUserPlan()]; return { features: userPlan.features, usageLimits: (_a = userPlan.usageLimits) !== null && _a !== void 0 ? _a : {}, }; }; /** * This method returns the PricingManager object that is being used to * evaluate the pricing plan. * * @returns PricingManager object */ PricingContext.prototype.getPricing = function () { try { return (0, server_1.retrievePricingFromPath)(this.getConfigFilePath()); } catch (error) { throw new PricingPlanEvaluationError_1.PricingPlanEvaluationError(error.message); } }; return PricingContext; }()); exports.PricingContext = PricingContext;