pricing4ts
Version:
 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
25 lines (24 loc) • 863 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.checkFeature = checkFeature;
var pricing_jwt_utils_1 = require("../utils/pricing-jwt-utils");
function checkFeature(feature) {
return function (req, res, next) {
var pricingToken = req.header('Pricing-Token');
try {
var decodedToken = pricing_jwt_utils_1.PricingJwtUtils.decodeToken(pricingToken);
if (!decodedToken) {
res.status(401).send('Invalid token');
}
else if (!decodedToken.features[feature].eval) {
res.status(403).send('Access to this feature is restricted. Please upgrade your plan to gain access.');
}
else {
next();
}
}
catch (e) {
res.status(401).send(e.message);
}
};
}