(()=>{var e={};e.id=5893,e.ids=[5893],e.modules={28303:e=>{function r(e){var r=Error("Cannot find module '"+e+"'");throw r.code="MODULE_NOT_FOUND",r}r.keys=()=>[],r.resolve=r,r.id=28303,e.exports=r},10846:e=>{"use strict";e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},44870:e=>{"use strict";e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},29294:e=>{"use strict";e.exports=require("next/dist/server/app-render/work-async-storage.external.js")},63033:e=>{"use strict";e.exports=require("next/dist/server/app-render/work-unit-async-storage.external.js")},79428:e=>{"use strict";e.exports=require("buffer")},55511:e=>{"use strict";e.exports=require("crypto")},94735:e=>{"use strict";e.exports=require("events")},91645:e=>{"use strict";e.exports=require("net")},19771:e=>{"use strict";e.exports=require("process")},27910:e=>{"use strict";e.exports=require("stream")},41204:e=>{"use strict";e.exports=require("string_decoder")},66136:e=>{"use strict";e.exports=require("timers")},34631:e=>{"use strict";e.exports=require("tls")},79551:e=>{"use strict";e.exports=require("url")},28354:e=>{"use strict";e.exports=require("util")},74075:e=>{"use strict";e.exports=require("zlib")},4573:e=>{"use strict";e.exports=require("node:buffer")},77598:e=>{"use strict";e.exports=require("node:crypto")},53053:e=>{"use strict";e.exports=require("node:diagnostics_channel")},17976:(e,r,t)=>{"use strict";t.r(r),t.d(r,{patchFetch:()=>_,routeModule:()=>d,serverHooks:()=>g,workAsyncStorage:()=>m,workUnitAsyncStorage:()=>S});var s={};t.r(s),t.d(s,{GET:()=>f});var n=t(42706),i=t(28203),o=t(45994),u=t(39187),a=t(98095),c=t(53721),l=t(71747),p=t(23951);async function f(e){try{if("mysql"!==(0,a.f)())return u.NextResponse.json({error:"Users API local deshabilitada."},{status:404});let r=(0,c.Z)(e);if(!r)return u.NextResponse.json({error:"No autenticado."},{status:401});if(!(0,l.s)(r,"users:create"))return u.NextResponse.json({error:"Sin permisos para crear usuarios."},{status:403});let t=String(r.orgId||"").trim();if(!t)return u.NextResponse.json({error:"Sesion sin orgId."},{status:403});let s=(0,p.T)(),[n]=await s.query(`
        SELECT id, name
        FROM roles
        ORDER BY name ASC
      `),i=n.map(e=>({id:String(e.id||"").trim(),name:String(e.name||e.id||"").trim()})),[o]=await s.query(`
        SELECT id, name
        FROM institutions
        WHERE org_id = ?
        ORDER BY name ASC
      `,[t]),f=o.map(e=>({id:String(e.id||"").trim(),name:String(e.name||e.id||"").trim()}));return u.NextResponse.json({orgId:t,roles:i,institutions:f})}catch(e){return console.error("[GET /api/users/bootstrap] error:",e),u.NextResponse.json({error:"Error interno."},{status:500})}}let d=new n.AppRouteRouteModule({definition:{kind:i.RouteKind.APP_ROUTE,page:"/api/users/bootstrap/route",pathname:"/api/users/bootstrap",filename:"route",bundlePath:"app/api/users/bootstrap/route"},resolvedPagePath:"C:\\omrwebapp-git-roregar.cl\\src\\app\\api\\users\\bootstrap\\route.ts",nextConfigOutput:"standalone",userland:s}),{workAsyncStorage:m,workUnitAsyncStorage:S,serverHooks:g}=d;function _(){return(0,o.patchFetch)({workAsyncStorage:m,workUnitAsyncStorage:S})}},96487:()=>{},78335:()=>{},71747:(e,r,t)=>{"use strict";function s(e){return String(e||"").trim().toLowerCase()}function n(e,r){if(!e)return!1;if(function(e){let r=s(e);return"admin"===r||r.startsWith("admin_")||r.includes(":admin")}(e.roleId))return!0;let t=s(r);return(e.permissions||[]).some(e=>s(e)===t)}t.d(r,{s:()=>n})},98095:(e,r,t)=>{"use strict";function s(){return"mysql"===String(process.env.AUTH_MODE||process.env.NEXT_PUBLIC_AUTH_MODE||"").trim().toLowerCase()?"mysql":"firebase"}t.d(r,{f:()=>s})},23951:(e,r,t)=>{"use strict";t.d(r,{T:()=>a});var s=t(60820);let n=null;function i(e){for(let r of e){let e=process.env[r];if(e&&String(e).trim())return String(e).trim()}}function o(e,r){let t=i(e);if(!t)throw Error(`Missing ${r}. Set one of: ${e.join(", ")}`);return t}function u(e,r){if(!e)return r;let t=Number(e);return Number.isFinite(t)?t:r}function a(){if(n)return n;let e=o(["AUTH_DB_HOST","DB_HOST"],"database host"),r=o(["AUTH_DB_USER","DB_USERNAME","DB_USER"],"database user"),t=o(["AUTH_DB_PASSWORD","DB_PASSWORD"],"database password"),a=o(["AUTH_DB_NAME","DB_DATABASE"],"database name"),c=u(i(["AUTH_DB_PORT","DB_PORT"]),3306),l=u(i(["AUTH_DB_POOL_SIZE","DB_POOL_SIZE"]),10);return n=s.createPool({host:e,port:c,user:r,password:t,database:a,waitForConnections:!0,connectionLimit:l,queueLimit:0,charset:"utf8mb4"})}},53721:(e,r,t)=>{"use strict";t.d(r,{Z:()=>n});var s=t(89249);function n(e){let r=String(e.cookies.get(s.CA())?.value||"").trim();if(!r)return null;let t=(0,s.zP)(r);return t?.user||null}},89249:(e,r,t)=>{"use strict";t.d(r,{$G:()=>m,C0:()=>S,CA:()=>c,Q7:()=>p,zP:()=>d});var s=t(77598),n=t.n(s);let i="omr_local_session";function o(e){return(Buffer.isBuffer(e)?e:Buffer.from(e)).toString("base64").replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/g,"")}function u(e){let r=String(e||"").replace(/-/g,"+").replace(/_/g,"/"),t=r.length%4==0?"":"=".repeat(4-r.length%4);return Buffer.from(r+t,"base64")}function a(){return String(process.env.AUTH_SESSION_SECRET||process.env.NEXTAUTH_SECRET||process.env.AUTH_DB_PASSWORD||"").trim()||"omr-local-session-dev-secret-change-me"}function c(){return String(process.env.AUTH_SESSION_COOKIE_NAME||i).trim()||i}function l(){let e=Number(process.env.AUTH_SESSION_TTL_HOURS||168);return Math.round(3600*(Number.isFinite(e)&&e>0?e:168))}function p(e){let r=Math.floor(Date.now()/1e3),t={v:1,iat:r,exp:r+l(),user:e},s=o(JSON.stringify({alg:"HS256",typ:"JWT"})),i=o(JSON.stringify(t)),u=`${s}.${i}`,c=o(n().createHmac("sha256",a()).update(u).digest());return`${u}.${c}`}function f(e){try{return JSON.parse(e)}catch{return null}}function d(e){let r=String(e||"").trim().split(".");if(3!==r.length)return null;let[t,s,i]=r;if(!t||!s||!i)return null;let c=`${t}.${s}`,l=o(n().createHmac("sha256",a()).update(c).digest()),p=Buffer.from(l),d=Buffer.from(i);if(p.length!==d.length||!n().timingSafeEqual(p,d))return null;let m=f(u(t).toString("utf8"));if(!m||"HS256"!==m.alg||"JWT"!==m.typ)return null;let S=f(u(s).toString("utf8"));if(!S||1!==S.v)return null;let g=Math.floor(Date.now()/1e3);if(!Number.isFinite(S.exp)||S.exp<=g)return null;let _=S.user;return _&&String(_.id||"").trim()&&String(_.email||"").trim()?S:null}function m(e,r){e.cookies.set(c(),r,{httpOnly:!0,sameSite:"lax",secure:!0,path:"/",maxAge:l()})}function S(e){e.cookies.set(c(),"",{httpOnly:!0,sameSite:"lax",secure:!0,path:"/",maxAge:0})}}};var r=require("../../../../webpack-runtime.js");r.C(e);var t=e=>r(r.s=e),s=r.X(0,[1989,5452,820],()=>t(17976));module.exports=s})();