Edit: /tmp/tsx-0/17887-c01536b641c53ca9889a4e32b13b871d76b89231 (4609B)
{"code":"__filename=\"/opt/canhelp/apps/api/src/middleware/plan.ts\";(()=>{\n\"use strict\";var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __hasOwnProp=Object.prototype.hasOwnProperty;var __name=(target,value)=>__defProp(target,\"name\",{value,configurable:true});var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:true})};var __copyProps=(to,from,except,desc)=>{if(from&&typeof from===\"object\"||typeof from===\"function\"){for(let key of __getOwnPropNames(from))if(!__hasOwnProp.call(to,key)&&key!==except)__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable})}return to};var __toCommonJS=mod=>__copyProps(__defProp({},\"__esModule\",{value:true}),mod);var plan_exports={};__export(plan_exports,{invalidatePlanCache:()=>invalidatePlanCache,requirePlanFeature:()=>requirePlanFeature,withPlan:()=>withPlan});module.exports=__toCommonJS(plan_exports);var import_factory=require(\"hono/factory\");var import_drizzle_orm=require(\"drizzle-orm\");var import_db=require(\"../db.js\");var import_db2=require(\"@canhelp/db\");var import_redis=require(\"../redis.js\");var import_helper_capability=require(\"../lib/helper-capability.js\");const PLAN_CACHE_TTL=3600;async function fetchPlan(planId){const cacheKey=`plan:${planId}`;const cached=await import_redis.redis.get(cacheKey).catch(()=>null);if(cached){try{return JSON.parse(cached)}catch{}}const[plan]=await import_db.db.select().from(import_db2.plans).where((0,import_drizzle_orm.eq)(import_db2.plans.id,planId));if(plan){await import_redis.redis.set(cacheKey,JSON.stringify(plan),\"EX\",PLAN_CACHE_TTL).catch(()=>{})}return plan??null}__name(fetchPlan,\"fetchPlan\");async function invalidatePlanCache(planId){await import_redis.redis.del(`plan:${planId}`).catch(()=>{})}__name(invalidatePlanCache,\"invalidatePlanCache\");const withPlan=(0,import_factory.createMiddleware)(async(c,next)=>{const user=c.var.user;let planId=user.planId;if(planId&&user.planExpiresAt){const expiresAt=new Date(user.planExpiresAt);if(expiresAt
{});planId=freePlanId}}if(planId){const plan=await fetchPlan(planId);c.set(\"plan\",plan)}else{c.set(\"plan\",null)}await next()});function requirePlanFeature(feature){return(0,import_factory.createMiddleware)(async(c,next)=>{const plan=c.var.plan;if(!plan||!plan[feature]){return c.json({error:\"Your plan does not include this feature\",code:\"PLAN_FEATURE_REQUIRED\",feature,upgrade:true},403)}await next()})}__name(requirePlanFeature,\"requirePlanFeature\");0&&(module.exports={invalidatePlanCache,requirePlanFeature,withPlan});\n})()\n","warnings":[],"map":{"version":3,"mappings":";mvBAAA,sNAAiC,wBACjC,uBAAmB,uBACnB,cAAmB,oBACnB,IAAAA,WAA6B,uBAC7B,iBAAsB,uBAEtB,6BAAoC,uCAQpC,MAAM,eAAiB,KAGvB,eAAe,UAAU,OAAyC,CAChE,MAAM,SAAW,QAAQ,MAAM,GAC/B,MAAM,OAAS,MAAM,mBAAM,IAAI,QAAQ,EAAE,MAAM,IAAM,IAAI,EACzD,GAAI,OAAQ,CACV,GAAI,CACF,OAAO,KAAK,MAAM,MAAM,CAC1B,MAAQ,CAAC,CACX,CACA,KAAM,CAAC,IAAI,EAAI,MAAM,aAAG,OAAO,EAAE,KAAK,gBAAK,EAAE,SAAM,uBAAG,iBAAM,GAAI,MAAM,CAAC,EACvE,GAAI,KAAM,CACR,MAAM,mBAAM,IAAI,SAAU,KAAK,UAAU,IAAI,EAAG,KAAM,cAAc,EAAE,MAAM,IAAM,CAAC,CAAC,CACtF,CACA,OAAO,MAAQ,IACjB,CAbe,8BAgBf,eAAsB,oBAAoB,OAAgB,CACxD,MAAM,mBAAM,IAAI,QAAQ,MAAM,EAAE,EAAE,MAAM,IAAM,CAAC,CAAC,CAClD,CAFsB,kDASf,MAAM,YAAW,iCACtB,MAAO,EAAG,OAAS,CACjB,MAAM,KAAO,EAAE,IAAI,KACnB,IAAI,OAAS,KAAK,OAGlB,GAAI,QAAU,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