Edit: /tmp/tsx-0/17887-9db7130b75a6dc1326930bdbcaf1a0be57a81aaa (7580B)
{"code":"__filename=\"/opt/canhelp/apps/api/src/lib/helper-capability.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 helper_capability_exports={};__export(helper_capability_exports,{clearHelperCapabilityCache:()=>clearHelperCapabilityCache,enrichUserWithHelperCapability:()=>enrichUserWithHelperCapability,getHelperCapability:()=>getHelperCapability,isAdminRole:()=>isAdminRole,mapAudienceToLegacyPlanRole:()=>mapAudienceToLegacyPlanRole,toClientRole:()=>toClientRole,toLegacyMarketRole:()=>toLegacyMarketRole,toLegacyMarketRoleFromInput:()=>toLegacyMarketRoleFromInput,toNormalizedRole:()=>toNormalizedRole});module.exports=__toCommonJS(helper_capability_exports);var import_drizzle_orm=require(\"drizzle-orm\");var import_db=require(\"@canhelp/db\");var import_db2=require(\"../db.js\");const helperCapabilityCache=new Map;const helperCapabilityCacheTtlMs=Number(process.env.HELPER_CAPABILITY_CACHE_TTL_MS??3e4);function isAdminRole(role){return role===\"admin\"}__name(isAdminRole,\"isAdminRole\");function toNormalizedRole(role){return role===\"admin\"?\"admin\":\"user\"}__name(toNormalizedRole,\"toNormalizedRole\");function toLegacyMarketRole(isHelperReady){return isHelperReady?\"specialist\":\"customer\"}__name(toLegacyMarketRole,\"toLegacyMarketRole\");function toClientRole(rawRole,isHelperReady){if(isAdminRole(rawRole))return\"admin\";return isHelperReady?\"specialist\":\"customer\"}__name(toClientRole,\"toClientRole\");function toLegacyMarketRoleFromInput(role){return role===\"specialist\"||role===\"helper\"?\"specialist\":\"customer\"}__name(toLegacyMarketRoleFromInput,\"toLegacyMarketRoleFromInput\");function mapAudienceToLegacyPlanRole(audience){return audience===\"helper\"?\"specialist\":\"customer\"}__name(mapAudienceToLegacyPlanRole,\"mapAudienceToLegacyPlanRole\");function getCachedHelperCapability(userId){const cached=helperCapabilityCache.get(userId);if(!cached)return null;if(cached.expiresAt<=Date.now()){helperCapabilityCache.delete(userId);return null}return cached.value}__name(getCachedHelperCapability,\"getCachedHelperCapability\");function setCachedHelperCapability(userId,value){const ttl=Number.isFinite(helperCapabilityCacheTtlMs)?helperCapabilityCacheTtlMs:3e4;helperCapabilityCache.set(userId,{value,expiresAt:Date.now()+Math.max(1e3,ttl)})}__name(setCachedHelperCapability,\"setCachedHelperCapability\");function clearHelperCapabilityCache(userId){if(userId){helperCapabilityCache.delete(userId);return}helperCapabilityCache.clear()}__name(clearHelperCapabilityCache,\"clearHelperCapabilityCache\");async function getHelperCapability(userId,options){if(!options?.bypassCache){const cached=getCachedHelperCapability(userId);if(cached!==null)return cached}const[userRows,cards]=await Promise.all([import_db2.db.select({id:import_db.users.id,bio:import_db.users.bio,specialistCategories:import_db.users.specialistCategories,specialistLocations:import_db.users.specialistLocations}).from(import_db.users).where((0,import_drizzle_orm.eq)(import_db.users.id,userId)).limit(1),import_db2.db.select({categories:import_db.specialistCards.categories,locations:import_db.specialistCards.locations}).from(import_db.specialistCards).where((0,import_drizzle_orm.and)((0,import_drizzle_orm.eq)(import_db.specialistCards.specialistId,userId),(0,import_drizzle_orm.eq)(import_db.specialistCards.isActive,true)))]);const[user]=userRows;if(!user){setCachedHelperCapability(userId,false);return false}const hasBio=!!user.bio?.trim();const cardCategories=cards.flatMap(c=>c.categories??[]);const cardLocations=cards.flatMap(c=>c.locations??[]);const allCategories=new Set([...user.specialistCategories??[],...cardCategories]);const allLocations=new Set([...user.specialistLocations??[],...cardLocations]);const hasActiveCards=cards.length>0;const isHelperReady=hasBio&&hasActiveCards&&allCategories.size>0&&allLocations.size>0;setCachedHelperCapability(userId,isHelperReady);return isHelperReady}__name(getHelperCapability,\"getHelperCapability\");async function enrichUserWithHelperCapability(user){const isHelperReady=await getHelperCapability(user.id);const legacyMarketRole=toLegacyMarketRole(isHelperReady);return{...user,role:toClientRole(user.role,isHelperReady),isHelperReady,legacyMarketRole}}__name(enrichUserWithHelperCapability,\"enrichUserWithHelperCapability\");0&&(module.exports={clearHelperCapabilityCache,enrichUserWithHelperCapability,getHelperCapability,isAdminRole,mapAudienceToLegacyPlanRole,toClientRole,toLegacyMarketRole,toLegacyMarketRoleFromInput,toNormalizedRole});\n})()\n","warnings":[],"map":{"version":3,"mappings":";mvBAAA,+jBAAwB,uBACxB,cAAuC,uBACvC,IAAAA,WAAmB,oBAOnB,MAAM,sBAAwB,IAAI,IAClC,MAAM,2BAA6B,OAAO,QAAQ,IAAI,gCAAkC,GAAK,EAKtF,SAAS,YAAY,KAA0C,CACpE,OAAO,OAAS,OAClB,CAFgB,kCAIT,SAAS,iBAAiB,KAAmD,CAClF,OAAO,OAAS,QAAU,QAAU,MACtC,CAFgB,4CAIT,SAAS,mBAAmB,cAA0C,CAC3E,OAAO,cAAgB,aAAe,UACxC,CAFgB,gDAST,SAAS,aACd,QACA,cACqC,CACrC,GAAI,YAAY,OAAO,EAAG,MAAO,QACjC,OAAO,cAAgB,aAAe,UACxC,CANgB,oCAQT,SAAS,4BAA4B,KAAmD,CAC7F,OAAO,OAAS,cAAgB,OAAS,SAAW,aAAe,UACrE,CAFgB,kEAIT,SAAS,4BAA4B,SAA0C,CACpF,OAAO,WAAa,SAAW,aAAe,UAChD,CAFgB,kEAIhB,SAAS,0BAA0B,OAAgC,CACjE,MAAM,OAAS,sBAAsB,IAAI,MAAM,EAC/C,GAA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