@chatpanel/gateway 0.85.5 → 0.87.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ import i from"node:tls";import d from"node:os";import{existsSync as l,readFileSync as u}from"node:fs";import{join as h}from"node:path";const y=/^(off|0|false|no)$/i;function C(s=null,e=process.env){return y.test(String(e.CHATPANEL_SYSTEM_CA||""))?!1:s?.tls?.systemCa!==!1}function w(s=process.env,e=d.homedir()){let t=null;try{const a=s.CHATPANEL_GATEWAY_CONFIG||h(e,".chatpanel","gateway.config.json");l(a)&&(t=JSON.parse(u(a,"utf8")))}catch{t=null}return C(t,s)}let r={on:!1,added:0,why:"not applied yet"};function x(){return{...r}}function p(s,e){const t=(a,n)=>s(a,n?.tls?.ca?n:{...n,tls:{...n?.tls,ca:e}});for(const a of Object.keys(s))t[a]=s[a];return t.chatpanelSystemCa=!0,t}function T({enabled:s=!0,tlsImpl:e=i,scope:t=globalThis,bun:a=!!process.versions.bun}={}){if(!s)return r={on:!1,added:0,why:"switched off (tls.systemCa: false, or CHATPANEL_SYSTEM_CA=off)"};if(typeof e.getCACertificates!="function"||typeof e.setDefaultCACertificates!="function")return r={on:!1,added:0,why:"this runtime cannot change its certificate list — Node 22.19 or newer can"};try{const n=e.getCACertificates("default"),c=new Set(n),f=e.getCACertificates("system").filter(o=>!c.has(o));if(f.length){const o=[...n,...f];e.setDefaultCACertificates(o),a&&typeof t.fetch=="function"&&!t.fetch.chatpanelSystemCa&&(t.fetch=p(t.fetch,o))}return r={on:!0,added:f.length+(r.on?r.added:0)}}catch(n){return r={on:!1,added:0,why:`the system's certificates could not be read (${String(n?.message||n).slice(0,120)})`}}}function _(){r={on:!1,added:0,why:"not applied yet"}}export{_ as _resetSystemCaState,x as systemCaState,C as systemCaWanted,w as systemCaWantedOnDisk,T as trustSystemCertificates};
package/src/update.js CHANGED
@@ -1,3 +1,7 @@
1
- import U from"node:os";import i from"node:path";import{execFile as A}from"node:child_process";import{chmod as G,rename as L,mkdir as K,readFile as V,writeFile as R,rm as W}from"node:fs/promises";import{existsSync as Y,readFileSync as q,realpathSync as z}from"node:fs";import{restartService as Q,serviceRegistered as y}from"./service.js";const g="@chatpanel/gateway",Et="chatpanel/chatpanel-gateway",j="https://dl.chatpanel.net/version/gateway",E=(process.env.CHATPANEL_NPM_REGISTRY||process.env.npm_config_registry||"https://registry.npmjs.org").replace(/\/$/,""),X=`${E}/${g}/latest`,Z=t=>`https://dl.chatpanel.net/gateway/${t.replace(/^chatpanel-gateway-/,"")}`,D=360*60*1e3,N=600*1e3,tt=Math.max(500,Number(process.env.CHATPANEL_UPDATE_TIMEOUT_MS)||5e3),et=15*6e4,k=20*6e4,_=process.env.CHATPANEL_UPDATE_CACHE||i.join(U.homedir(),".chatpanel","gateway-update-check.json"),S=String(process.env.CHATPANEL_SELF_UPDATE||"").toLowerCase()==="off",O={"User-Agent":"chatpanel-gateway-updater"},nt=new Set(["dl.chatpanel.net","github.com","api.github.com","objects.githubusercontent.com","release-assets.githubusercontent.com"]);function at(t){try{const e=new URL(t);return e.protocol==="https:"&&nt.has(e.hostname)}catch{return!1}}let m={at:0,error:""};function _t(){m={at:0,error:""}}function $(){const t=i.basename(process.execPath).toLowerCase();return!(t.startsWith("node")||t.startsWith("bun"))}function rt(){return process.platform==="darwin"?`chatpanel-gateway-macos-${process.arch==="arm64"?"arm64":"x64"}`:process.platform==="linux"?process.arch==="x64"?"chatpanel-gateway-linux-x64":null:process.platform==="win32"?"chatpanel-gateway-windows-x64.exe":null}function f(t=""){const e=/(\d+(?:\.\d+){0,3})/.exec(t||"");return e?e[1]:null}function H(t,e){const n=String(t).split(".").map(Number),a=String(e).split(".").map(Number);for(let r=0;r<Math.max(n.length,a.length);r+=1){const o=(n[r]||0)-(a[r]||0);if(o)return o>0?1:-1}return 0}async function ot(){try{return JSON.parse(await V(_,"utf8"))}catch{return null}}async function st(t){try{await K(i.dirname(_),{recursive:!0}),await R(_,JSON.stringify(t))}catch{}}async function x(t,e=tt){const n=new AbortController,a=setTimeout(()=>n.abort(),e);try{const r=await fetch(t,{headers:{Accept:"application/json, application/vnd.github+json",...O},signal:n.signal});if(!r.ok)throw new Error(r.status===403&&/github/.test(t)?"GitHub rate limit (60/hour per IP) — try again later":`HTTP ${r.status}`);return await r.json()}catch(r){const o=r?.cause?.code||r?.cause?.message||r?.message||String(r);throw new Error(n.signal.aborted?`the update server did not answer within ${Math.round(e/1e3)}s`:`${new URL(t).hostname}: ${o}`)}finally{clearTimeout(a)}}function T(t=process.argv[1]){let e=t?i.resolve(t):"";try{e=z(e)}catch{}const n=/^(.*[/\\]node_modules[/\\]@chatpanel[/\\]gateway)[/\\]/.exec(e);return n?n[1]:""}function it(){const t=T();if(!t)return"";try{return String(JSON.parse(q(i.join(t,"package.json"),"utf8")).version||"")}catch{return""}}function v(){const t=i.dirname(process.execPath);return[i.join(t,"..","lib","node_modules","npm","bin","npm-cli.js"),i.join(t,"node_modules","npm","bin","npm-cli.js")].find(n=>Y(n))||""}function lt(t=process.env,e=process.execPath){const n={...t,npm_config_registry:E,npm_config_fund:"false",npm_config_audit:"false"};delete n.ELECTRON_RUN_AS_NODE;const a=Object.keys(n).find(r=>r.toLowerCase()==="path")||"PATH";return n[a]=[i.dirname(e),...(n[a]||"").split(i.delimiter).filter(Boolean)].filter((r,o,c)=>c.indexOf(r)===o).join(i.delimiter),n}function ct(){import("./prune-install.js").then(({pruneForeignPrebuilds:t,pruneLine:e})=>{const n=e(t({log:a=>console.log(a)}));n&&console.log(`[update]${n}`)}).catch(()=>{})}function pt(){return["install","-g",`${g}@latest`,"--ignore-scripts"]}function dt(t,{home:e=U.homedir(),platform:n=process.platform}={}){if(n==="win32"||!/\b(EACCES|EPERM)\b/.test(t||""))return"";const a=(t.match(/^npm (?:error|ERR!) path (.+)$/m)||[])[1]?.trim()||"",r=a.indexOf(`${i.sep}lib${i.sep}node_modules`),o=r>0?a.slice(0,r):"";return o?o===e||o.startsWith(e+i.sep)?`npm cannot write ${o} — part of it belongs to another user, usually from an earlier \`sudo npm i -g\` (npm's hint about ~/.npm is a different folder). Fix: sudo chown -R "$(whoami)" "${o}" — then update again.`:`npm cannot write ${o}, which belongs to another user. Install the standalone build instead — it needs no npm: curl -fsSL https://dl.chatpanel.net/install.sh | bash`:""}function ut(){const t=v(),e=lt(),n=pt(),[a,r]=t?[process.execPath,[t,...n]]:["npm",n];return new Promise(o=>{A(a,r,{env:e,timeout:k,maxBuffer:8<<20,windowsHide:!0},(c,d,s)=>{const l=`${d||""}${s||""}`.trim();return c?c.killed&&!l?o({ok:!1,out:`npm was still running after ${Math.round(k/6e4)} minutes and was stopped`}):o({ok:!1,out:l||(t?c.message:"could not run npm: it is not beside the node running this gateway and not on the service's PATH")}):(ct(),o({ok:!0,out:l}))})})}async function M(t,{force:e=!1}={}){const n=$()?"binary":"npm";if(S)return{current:t,latest:null,updateAvailable:!1,mode:n,canSelfUpdate:!1,assetUrl:null,stale:!1,error:"",npmCommand:null,channel:n==="npm"?"npm":"release",service:!1,disabled:!0};const a=rt();let r=null,o=null,c=!1,d="",s=0;const l=await ot(),w=l&&l.mode===n,C=()=>{r=w&&l.latest||null,o=w&&l.assetUrl||null,s=w&&l.checkedAt||0,c=!0};if(!e&&w&&Date.now()-l.checkedAt<D)r=l.latest,o=l.assetUrl,s=l.checkedAt;else if(!e&&m.at&&Date.now()-m.at<N)d=m.error,C();else try{if(n==="npm"){let u;try{u=await x(X),r=f(u.version)}catch(J){const P=await x(j);if(r=f(P?.npm?.version)||f(P?.version),!r)throw J}}else{const u=await x(j);r=f(u.version)||f(u.release?.tag),o=a&&(u.release?.assets||[]).includes(a)?Z(a):null}s=Date.now(),await st({checkedAt:s,mode:n,latest:r,assetUrl:o}),m={at:0,error:""}}catch(u){d=u.message,m={at:Date.now(),error:d},C()}const I=!!r&&H(r,t)>0,F=n==="binary"?!!o&&(process.platform!=="win32"||y()):!!T()&&(process.platform!=="win32"||y()&&!!v()),B=n==="npm"?process.platform==="win32"?`chatpanel-gateway --stop; npm i -g ${g}@latest --ignore-scripts; chatpanel-gateway --install`:`npm i -g ${g}@latest --ignore-scripts`:null;return{current:t,latest:r,updateAvailable:I,mode:n,canSelfUpdate:F,assetUrl:o,stale:c,error:d,npmCommand:B,channel:n==="npm"?"npm":"release",service:y(),checkedAt:s}}let h=null,b=null;function St(t){const e=$()?"binary":"npm";return S?{current:t,latest:null,updateAvailable:!1,mode:e,canSelfUpdate:!1,stale:!1,error:"",npmCommand:null,channel:e==="npm"?"npm":"release",service:!1,disabled:!0}:((!h||(h.stale?!(m.at&&Date.now()-m.at<N):Date.now()-h.seenAt>D))&&!b&&(b=M(t).then(a=>{h={...a,seenAt:Date.now()}}).catch(()=>{}).finally(()=>{b=null})),h?{...h,seenAt:void 0,current:t}:{current:t,latest:null,updateAvailable:!1,mode:e,canSelfUpdate:!1,stale:!0,checking:!0,error:"",npmCommand:null,channel:e==="npm"?"npm":"release",service:y()})}function $t(){h=null,b=null}async function mt(t){const e=process.execPath,n=i.dirname(e),a=i.join(n,`.chatpanel-gateway.new-${Date.now()}`),r=new AbortController,o=setTimeout(()=>r.abort(),et);let c;try{const s=await fetch(t.assetUrl,{headers:O,redirect:"follow",signal:r.signal});if(!s.ok)throw new Error(`download failed (HTTP ${s.status})`);if(!at(s.url||t.assetUrl))throw new Error(`refused: the download was redirected to ${s.url}, which is not a ChatPanel release host`);c=Buffer.from(await s.arrayBuffer())}finally{clearTimeout(o)}if(c.length<5<<20)throw new Error(`the download was only ${(c.length/1024).toFixed(0)} KB — that is not the gateway, so nothing was replaced`);await R(a,c),process.platform!=="win32"&&await G(a,493),process.platform==="darwin"&&await new Promise(s=>A("xattr",["-c",a],()=>s()));const d=await new Promise(s=>A(a,["--version"],{timeout:6e4,windowsHide:!0},(l,w)=>s(l?"":String(w||"").trim())));if(!f(d))throw await W(a,{force:!0}),new Error("the downloaded gateway would not run, so it was discarded");return process.platform==="win32"&&await L(e,i.join(n,`chatpanel-gateway.old-${Date.now()}.exe`)),await L(a,e),f(d)}async function ft(t){if(S)throw new Error("Self-update is switched off on this gateway (CHATPANEL_SELF_UPDATE=off).");const e=await M(t,{force:!0});if(e.stale)throw new Error(`Could not reach the update server${e.error?` (${e.error})`:""}. Refusing to act on a stale check — try again in a few minutes.`);if(!e.updateAvailable)throw new Error(`Already on the latest ${e.channel} version (v${t}).`);if(!e.canSelfUpdate)throw new Error(e.mode==="npm"?`This gateway cannot update itself here. Run: ${e.npmCommand}`:"No downloadable build for this platform — install it with npm instead.");if(e.mode==="binary")return{from:t,to:await mt(e),mode:"binary"};if(process.platform==="win32")return{from:t,to:e.latest,mode:"npm",deferred:`"${process.execPath}" "${v()}" install -g ${g}@latest --registry=${E} --no-fund --no-audit`};const n=await ut();if(!n.ok){const r=dt(n.out);throw new Error(r?`${r}
1
+ import R from"node:os";import l from"node:path";import{execFile as S}from"node:child_process";import{chmod as q,rename as L,mkdir as z,readFile as Q,writeFile as I,rm as X}from"node:fs/promises";import{existsSync as Z,readFileSync as ee,realpathSync as te}from"node:fs";import{explainInstallFailure as y,adviceText as x,npmInstallCommand as ne}from"@chatpanel/events/install-advice.js";import{restartService as ae,serviceRegistered as b}from"./service.js";import{systemCaWantedOnDisk as se}from"./system-ca.js";const A="@chatpanel/gateway",De="chatpanel/chatpanel-gateway",H="https://dl.chatpanel.net/version/gateway",_=(process.env.CHATPANEL_NPM_REGISTRY||process.env.npm_config_registry||"https://registry.npmjs.org").replace(/\/$/,""),re=`${_}/${A}/latest`,oe=e=>`https://dl.chatpanel.net/gateway/${e.replace(/^chatpanel-gateway-/,"")}`,F=360*60*1e3,M=600*1e3,ie=Math.max(500,Number(process.env.CHATPANEL_UPDATE_TIMEOUT_MS)||5e3),le=15*6e4,B=20*6e4,T=process.env.CHATPANEL_UPDATE_CACHE||l.join(R.homedir(),".chatpanel","gateway-update-check.json"),C=String(process.env.CHATPANEL_SELF_UPDATE||"").toLowerCase()==="off",J={"User-Agent":"chatpanel-gateway-updater"},ce=new Set(["dl.chatpanel.net","github.com","api.github.com","objects.githubusercontent.com","release-assets.githubusercontent.com"]);function de(e){try{const t=new URL(e);return t.protocol==="https:"&&ce.has(t.hostname)}catch{return!1}}let f={at:0,error:""};function je(){f={at:0,error:""}}function P(){const e=l.basename(process.execPath).toLowerCase();return!(e.startsWith("node")||e.startsWith("bun"))}function pe(){return process.platform==="darwin"?`chatpanel-gateway-macos-${process.arch==="arm64"?"arm64":"x64"}`:process.platform==="linux"?process.arch==="x64"?"chatpanel-gateway-linux-x64":null:process.platform==="win32"?"chatpanel-gateway-windows-x64.exe":null}function h(e=""){const t=/(\d+(?:\.\d+){0,3})/.exec(e||"");return t?t[1]:null}function W(e,t){const n=String(e).split(".").map(Number),s=String(t).split(".").map(Number);for(let a=0;a<Math.max(n.length,s.length);a+=1){const r=(n[a]||0)-(s[a]||0);if(r)return r>0?1:-1}return 0}async function ue(){try{return JSON.parse(await Q(T,"utf8"))}catch{return null}}async function me(e){try{await z(l.dirname(T),{recursive:!0}),await I(T,JSON.stringify(e))}catch{}}async function N(e,t=ie){const n=new AbortController,s=setTimeout(()=>n.abort(),t);try{const a=await fetch(e,{headers:{Accept:"application/json, application/vnd.github+json",...J},signal:n.signal});if(!a.ok)throw new Error(a.status===403&&/github/.test(e)?"GitHub rate limit (60/hour per IP) — try again later":`HTTP ${a.status}`);return await a.json()}catch(a){const r=a?.cause?.code||a?.cause?.message||a?.message||String(a);throw new Error(n.signal.aborted?`the update server did not answer within ${Math.round(t/1e3)}s`:`${new URL(e).hostname}: ${r}`)}finally{clearTimeout(s)}}function k(e=process.argv[1]){let t=e?l.resolve(e):"";try{t=te(t)}catch{}const n=/^(.*[/\\]node_modules[/\\]@chatpanel[/\\]gateway)[/\\]/.exec(t);return n?n[1]:""}function fe(){const e=k();if(!e)return"";try{return String(JSON.parse(ee(l.join(e,"package.json"),"utf8")).version||"")}catch{return""}}function E(){const e=l.dirname(process.execPath);return[l.join(e,"..","lib","node_modules","npm","bin","npm-cli.js"),l.join(e,"..","libexec","lib","node_modules","npm","bin","npm-cli.js"),l.join(e,"node_modules","npm","bin","npm-cli.js")].find(n=>Z(n))||""}function he(e=process.env,t=process.execPath){const n={...e,npm_config_registry:_,npm_config_fund:"false",npm_config_audit:"false"};delete n.ELECTRON_RUN_AS_NODE;const s=Object.keys(n).find(a=>a.toLowerCase()==="path")||"PATH";return n[s]=[l.dirname(t),...(n[s]||"").split(l.delimiter).filter(Boolean)].filter((a,r,c)=>c.indexOf(a)===r).join(l.delimiter),n}function we(){import("./prune-install.js").then(({pruneForeignPrebuilds:e,pruneLine:t})=>{const n=t(e({log:s=>console.log(s)}));n&&console.log(`[update]${n}`)}).catch(()=>{})}function ge(){return["install","-g",`${A}@latest`,"--ignore-scripts"]}function ye(e,{home:t=R.homedir(),platform:n=process.platform}={}){if(n==="win32"||!/\b(EACCES|EPERM)\b/.test(e||""))return"";const s=(e.match(/^npm (?:error|ERR!) path (.+)$/m)||[])[1]?.trim()||"",a=s.indexOf(`${l.sep}lib${l.sep}node_modules`),r=a>0?s.slice(0,a):"";return r?r===t||r.startsWith(t+l.sep)?`npm cannot write ${r} — part of it belongs to another user, usually from an earlier \`sudo npm i -g\` (npm's hint about ~/.npm is a different folder). Fix: sudo chown -R "$(whoami)" "${r}" — then update again.`:`npm cannot write ${r}, which belongs to another user. Install the standalone build instead — it needs no npm: curl -fsSL https://dl.chatpanel.net/install.sh | bash`:""}function be(e=process.allowedNodeEnvironmentFlags){try{return!process.versions.bun&&e.has("--use-system-ca")}catch{return!1}}function Ae({cli:e=E(),systemCa:t=!1,env:n=he(),execPath:s=process.execPath}={}){const a=ge();return e?{cmd:s,args:[...t?["--use-system-ca"]:[],e,...a],env:n}:{cmd:"npm",args:a,env:t?{...n,NODE_OPTIONS:`${n.NODE_OPTIONS?`${n.NODE_OPTIONS} `:""}--use-system-ca`}:n}}function Ee({systemCa:e=!1}={}){const t=E(),{cmd:n,args:s,env:a}=Ae({cli:t,systemCa:e});return new Promise(r=>{S(n,s,{env:a,timeout:B,maxBuffer:8<<20,windowsHide:!0},(c,u,o)=>{const i=`${u||""}${o||""}`.trim();return c?c.killed&&!i?r({ok:!1,out:`npm was still running after ${Math.round(B/6e4)} minutes and was stopped`}):r({ok:!1,out:i||(t?c.message:"could not run npm: it is not beside the node running this gateway and not on the service's PATH")}):(we(),r({ok:!0,out:i}))})})}async function ve({run:e=Ee,canSystemCa:t=be()&&se()}={}){const n=await e({systemCa:!1});if(n.ok||!t||y(n.out)?.kind!=="certificate")return n;console.log("[update] npm refused the registry's certificate (a re-signing proxy) — trying once more with the system's certificates");const s=await e({systemCa:!0});return s.ok?{...s,via:"system-ca"}:s}function $e(e,t=process.versions.node,n=process.platform){return!e||process.versions.bun?null:y("",{node:t,needsNode:e,platform:n})}async function G(e,{force:t=!1}={}){const n=P()?"binary":"npm";if(C)return{current:e,latest:null,updateAvailable:!1,mode:n,canSelfUpdate:!1,assetUrl:null,stale:!1,error:"",npmCommand:null,channel:n==="npm"?"npm":"release",service:!1,disabled:!0};const s=pe();let a=null,r=null,c=!1,u="",o=0,i="";const d=await ue(),g=d&&d.mode===n,U=()=>{a=g&&d.latest||null,r=g&&d.assetUrl||null,o=g&&d.checkedAt||0,i=g&&d.needsNode||"",c=!0};if(!t&&g&&Date.now()-d.checkedAt<F)a=d.latest,r=d.assetUrl,o=d.checkedAt,i=d.needsNode||"";else if(!t&&f.at&&Date.now()-f.at<M)u=f.error,U();else try{if(n==="npm"){let m;try{m=await N(re),a=h(m.version),i=String(m.engines?.node||"")}catch(Y){const j=await N(H);if(a=h(j?.npm?.version)||h(j?.version),!a)throw Y}}else{const m=await N(H);a=h(m.version)||h(m.release?.tag),r=s&&(m.release?.assets||[]).includes(s)?oe(s):null}o=Date.now(),await me({checkedAt:o,mode:n,latest:a,assetUrl:r,needsNode:i}),f={at:0,error:""}}catch(m){u=m.message,f={at:Date.now(),error:u},U()}const D=!!a&&W(a,e)>0,$=n==="npm"&&D?$e(i):null,K=$?!1:n==="binary"?!!r&&(process.platform!=="win32"||b()):!!k()&&(process.platform!=="win32"||b()&&!!E()),V=n==="npm"?ne({pkg:A,platform:process.platform}):null;return{current:e,latest:a,updateAvailable:D,mode:n,canSelfUpdate:K,assetUrl:r,stale:c,error:u,npmCommand:V,channel:n==="npm"?"npm":"release",service:b(),checkedAt:o,...n==="npm"?{node:process.versions.node,...i?{needsNode:i}:{}}:{},...$?{blocked:$}:{}}}let w=null,v=null;function Re(e){const t=P()?"binary":"npm";return C?{current:e,latest:null,updateAvailable:!1,mode:t,canSelfUpdate:!1,stale:!1,error:"",npmCommand:null,channel:t==="npm"?"npm":"release",service:!1,disabled:!0}:((!w||(w.stale?!(f.at&&Date.now()-f.at<M):Date.now()-w.seenAt>F))&&!v&&(v=G(e).then(s=>{w={...s,seenAt:Date.now()}}).catch(()=>{}).finally(()=>{v=null})),w?{...w,seenAt:void 0,current:e}:{current:e,latest:null,updateAvailable:!1,mode:t,canSelfUpdate:!1,stale:!0,checking:!0,error:"",npmCommand:null,channel:t==="npm"?"npm":"release",service:b()})}function Le(){w=null,v=null}async function Se(e){const t=process.execPath,n=l.dirname(t),s=l.join(n,`.chatpanel-gateway.new-${Date.now()}`),a=new AbortController,r=setTimeout(()=>a.abort(),le);let c;try{let o;try{o=await fetch(e.assetUrl,{headers:J,redirect:"follow",signal:a.signal})}catch(i){throw new Error(`download failed: ${a.signal.aborted?"timed out":i?.cause?.code||i?.cause?.message||i?.message||i}`)}if(!o.ok)throw new Error(`download failed (HTTP ${o.status})`);if(!de(o.url||e.assetUrl))throw new Error(`refused: the download was redirected to ${o.url}, which is not a ChatPanel release host`);c=Buffer.from(await o.arrayBuffer())}finally{clearTimeout(r)}if(c.length<5<<20)throw new Error(`the download was only ${(c.length/1024).toFixed(0)} KB — that is not the gateway, so nothing was replaced`);await I(s,c),process.platform!=="win32"&&await q(s,493),process.platform==="darwin"&&await new Promise(o=>S("xattr",["-c",s],()=>o()));const u=await new Promise(o=>S(s,["--version"],{timeout:6e4,windowsHide:!0},(i,d)=>o(i?"":String(d||"").trim())));if(!h(u))throw await X(s,{force:!0}),new Error("the downloaded gateway would not run, so it was discarded");return process.platform==="win32"&&await L(t,l.join(n,`chatpanel-gateway.old-${Date.now()}.exe`)),await L(s,t),h(u)}const O=(e,t=null,n="")=>Object.assign(new Error(e),{advice:t,raw:n});async function xe(e){if(C)throw new Error("Self-update is switched off on this gateway (CHATPANEL_SELF_UPDATE=off).");const t=await G(e,{force:!0});if(t.stale)throw new Error(`Could not reach the update server${t.error?` (${t.error})`:""}. Refusing to act on a stale check — try again in a few minutes.`);if(!t.updateAvailable)throw new Error(`Already on the latest ${t.channel} version (v${e}).`);if(t.blocked)throw O(`v${t.latest} was not installed. ${x(t.blocked)}`,t.blocked);if(!t.canSelfUpdate)throw new Error(t.mode==="npm"?`This gateway cannot update itself here. Run: ${t.npmCommand}`:"No downloadable build for this platform — install it with npm instead.");if(t.mode==="binary")try{return{from:e,to:await Se(t),mode:"binary"}}catch(a){const r=y(a.message,{platform:process.platform,channel:"binary"});throw r?O(`${x(r)}
2
2
 
3
- npm said: ${n.out.slice(0,600)}`:`npm install failed: ${n.out.slice(0,800)}`)}const a=it();if(!a||H(a,t)<=0)throw new Error(`npm ran, but the install at ${T()} is still ${a||"unreadable"} — the service launches a copy npm did not update. Run: ${e.npmCommand}`);return{from:t,to:a,mode:"npm"}}const p={state:"idle",mode:"",from:"",to:"",detail:"",startedAt:0,endedAt:0};function xt(){return{...p}}function Tt(t,{restart:e=Q,apply:n=ft}={}){return p.state==="installing"||p.state==="restarting"?{...p,already:!0}:(Object.assign(p,{state:"installing",mode:$()?"binary":"npm",from:t,to:"",detail:"",startedAt:Date.now(),endedAt:0}),n(t).then(a=>{Object.assign(p,{state:"restarting",to:a.to,mode:a.mode,detail:a.deferred?`stopping to install v${a.to}, then relaunching`:`v${a.to} is installed; restarting the gateway into it`}),setTimeout(()=>{e({winInstall:a.deferred||""})||Object.assign(p,{state:"done",endedAt:Date.now(),detail:`v${a.to} is installed, but this gateway is not run by a service it can restart. Start it again yourself to run the new version.`})},400)}).catch(a=>{Object.assign(p,{state:"failed",endedAt:Date.now(),detail:String(a?.message||a).slice(0,1200)})}),{...p})}function vt(){Object.assign(p,{state:"idle",mode:"",from:"",to:"",detail:"",startedAt:0,endedAt:0})}export{vt as _resetUpdateJob,$t as _resetUpdateStatus,M as checkForUpdate,H as cmpVersions,at as downloadHostAllowed,$ as isCompiledBinary,pt as npmInstallArgs,lt as npmInstallEnv,T as npmPackageRoot,dt as npmPermissionHint,_t as resetUpdateBackoff,ft as selfUpdate,Tt as startUpdate,xt as updateJob,St as updateStatus};
3
+ The download said: ${a.message}`,r,a.message):a}if(process.platform==="win32")return{from:e,to:t.latest,mode:"npm",deferred:`"${process.execPath}" "${E()}" install -g ${A}@latest --registry=${_} --no-fund --no-audit`};const n=await ve();if(!n.ok){const a=ye(n.out),r=a?null:y(n.out,{platform:process.platform,node:process.versions.node,needsNode:t.needsNode}),c=n.out.slice(0,600);throw O(a?`${a}
4
+
5
+ npm said: ${c}`:r?`${x(r)}
6
+
7
+ npm said: ${c}`:`npm install failed: ${n.out.slice(0,800)}`,r,c)}n.via==="system-ca"&&console.log("[update] installed through the system's certificates — a proxy on this network re-signs npm's traffic");const s=fe();if(!s||W(s,e)<=0)throw new Error(`npm ran, but the install at ${k()} is still ${s||"unreadable"} — the service launches a copy npm did not update. Run: ${t.npmCommand}`);return{from:e,to:s,mode:"npm"}}const p={state:"idle",mode:"",from:"",to:"",detail:"",advice:null,raw:"",startedAt:0,endedAt:0};function Ie(){return{...p}}function He(e,{restart:t=ae,apply:n=xe}={}){return p.state==="installing"||p.state==="restarting"?{...p,already:!0}:(Object.assign(p,{state:"installing",mode:P()?"binary":"npm",from:e,to:"",detail:"",advice:null,raw:"",startedAt:Date.now(),endedAt:0}),n(e).then(s=>{Object.assign(p,{state:"restarting",to:s.to,mode:s.mode,detail:s.deferred?`stopping to install v${s.to}, then relaunching`:`v${s.to} is installed; restarting the gateway into it`}),setTimeout(()=>{t({winInstall:s.deferred||""})||Object.assign(p,{state:"done",endedAt:Date.now(),detail:`v${s.to} is installed, but this gateway is not run by a service it can restart. Start it again yourself to run the new version.`})},400)}).catch(s=>{const a=String(s?.message||s);Object.assign(p,{state:"failed",endedAt:Date.now(),detail:a.slice(0,2400),advice:s?.advice||y(a,{platform:process.platform,channel:p.mode==="binary"?"binary":"npm"}),raw:String(s?.raw||"").slice(0,800)})}),{...p})}function Fe(){Object.assign(p,{state:"idle",mode:"",from:"",to:"",detail:"",advice:null,raw:"",startedAt:0,endedAt:0})}export{Fe as _resetUpdateJob,Le as _resetUpdateStatus,G as checkForUpdate,W as cmpVersions,de as downloadHostAllowed,ve as installWithRetry,P as isCompiledBinary,$e as nodeGate,ge as npmInstallArgs,he as npmInstallEnv,k as npmPackageRoot,ye as npmPermissionHint,Ae as npmSpawn,je as resetUpdateBackoff,xe as selfUpdate,He as startUpdate,be as systemCaAvailable,Ie as updateJob,Re as updateStatus};
package/src/version.js CHANGED
@@ -1 +1 @@
1
- const o="0.85.5";export{o as VERSION};
1
+ const o="0.87.0";export{o as VERSION};