"use strict";exports.id=9295,exports.ids=[9295],exports.modules={69295:(a,b,c)=>{c.d(b,{startScheduler:()=>z});var d=c(67605),e=c(51455),f=c(73024),g=c(76760),h=c.n(g);let i="https://version.telemetry.bulwarkmail.org/";function j(){return process.env.VERSION_CHECK_DATA_DIR||h().join(process.cwd(),"data","version-check")}function k(){return h().join(j(),"state.json")}let l={endpoint:i,lastCheckedAt:null,lastSuccessAt:null,nextScheduledAt:null,status:null};async function m(){(0,f.existsSync)(j())||await (0,e.mkdir)(j(),{recursive:!0})}async function n(){await m();try{let a=await (0,e.readFile)(k(),"utf8"),b=JSON.parse(a);return{...l,...b}}catch(a){return"ENOENT"!==a.code&&d.v.warn("version-check: state read failed",{error:a instanceof Error?a.message:String(a)}),{...l}}}async function o(a){await m();let b=k()+".tmp";await (0,e.writeFile)(b,JSON.stringify(a,null,2),"utf8"),await (0,e.rename)(b,k())}function p(){let a=(process.env.BULWARK_UPDATE_CHECK??"").toLowerCase();return"off"===a||"false"===a||"0"===a||"no"===a}function q(a){let b=process.env.BULWARK_UPDATE_CHECK_URL;return void 0!==b?b.trim():a.endpoint||i}let r=new Set(["normal","security","deprecated","none","unknown"]);function s(a){return"string"==typeof a}function t(a){return null===a||"string"==typeof a}async function u(a,b){let c;if(!a)return{ok:!1,error:"endpoint blank"};if(!b)return{ok:!1,error:"current version blank"};try{c=new URL(a)}catch{return{ok:!1,error:"endpoint not a URL"}}c.searchParams.set("v",b);try{var e;let a=await fetch(c,{method:"GET",headers:{accept:"application/json"},cache:"no-store",signal:AbortSignal.timeout(5e3)});if(!a.ok)return{ok:!1,error:`HTTP ${a.status}`};let b=(e=await a.json())&&"object"==typeof e&&1===e.schema&&s(e.current)&&t(e.latest)&&"boolean"==typeof e.updateAvailable&&s(e.severity)&&r.has(e.severity)&&t(e.url)&&t(e.advisory)&&s(e.checkedAt)&&(!e.url||/^https?:\/\//i.test(e.url))?{schema:1,current:e.current,latest:e.latest,updateAvailable:e.updateAvailable,severity:e.severity,url:e.url,advisory:e.advisory,checkedAt:e.checkedAt}:null;if(!b)return{ok:!1,error:"malformed response"};return{ok:!0,status:b}}catch(b){let a=b instanceof Error?b.message:String(b);return d.v.warn("version-check: fetch failed",{error:a}),{ok:!1,error:a}}}let v=null;async function w(a){if(p())return{ok:!1,error:"disabled by env"};let b=q(await n());if(!b)return{ok:!1,error:"endpoint blank"};let c="1.7.7".trim();if(!c)return{ok:!1,error:"current version unset"};let e=new Date().toISOString(),f=await u(b,c),g=await n();return(g.lastCheckedAt=e,f.ok&&(g.lastSuccessAt=e,g.status=f.status),await o(g),d.v.info("version-check: ran",{ok:f.ok,severity:f.ok?f.status.severity:null,reason:a?.reason??"scheduled"}),f.ok)?{ok:!0,status:f.status}:{ok:!1,error:f.error}}async function x(a){v&&clearTimeout(v);let b=new Date(Date.now()+a).toISOString(),c=await n();c.nextScheduledAt=b,await o(c),v=setTimeout(()=>{y()},a),v.unref?.()}async function y(){let a=(await w({reason:"scheduled"})).ok?Math.max(6e4,36e5+(2*Math.random()-1)*3e5):9e5;await x(a)}async function z(){if(p())return void d.v.info("version-check: scheduler not started (disabled by env)");let a=await n();if(!q(a))return void d.v.info("version-check: scheduler not started (no endpoint)");let b=3e4;if(a.nextScheduledAt){let c=new Date(a.nextScheduledAt).getTime()-Date.now();c>0&&(b=Math.min(c,39e5))}await x(b),d.v.info("version-check: scheduler started",{nextInMs:b})}}};