@tansr/cli 0.10.2 → 0.10.3
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.
- package/package.json +1 -1
- package/tansr-artifacts.json +429 -429
- package/{tansr-bg-QY4G2SNZ.mjs → tansr-bg-EAYYM4XW.mjs} +2 -2
- package/{tansr-chunk-OB47UYHK.mjs → tansr-chunk-2X337GKC.mjs} +2 -2
- package/{tansr-chunk-LSYPDTQG.mjs → tansr-chunk-4LNN4SQL.mjs} +2 -2
- package/{tansr-chunk-53SL6W6G.mjs → tansr-chunk-5TJVZSZE.mjs} +2 -2
- package/{tansr-chunk-H6JYYWPW.mjs → tansr-chunk-74H5GQTJ.mjs} +2 -2
- package/{tansr-chunk-KSBP64Q5.mjs → tansr-chunk-7T6OLLFW.mjs} +2 -2
- package/{tansr-chunk-E67N3BDI.mjs → tansr-chunk-CJP7YEGC.mjs} +2 -2
- package/{tansr-chunk-UCG4D6ER.mjs → tansr-chunk-D7VSW2LQ.mjs} +2 -2
- package/{tansr-chunk-UAEARRRH.mjs → tansr-chunk-DN22GXHD.mjs} +2 -2
- package/{tansr-chunk-NCIMR6LB.mjs → tansr-chunk-GDJ5YVNY.mjs} +2 -2
- package/{tansr-chunk-J72JGEKH.mjs → tansr-chunk-GMPMRXL4.mjs} +3 -3
- package/tansr-chunk-GR6BWQGG.mjs +38 -0
- package/{tansr-chunk-S77B4PI7.mjs → tansr-chunk-HHL7HM62.mjs} +2 -2
- package/{tansr-chunk-BCOFZJWA.mjs → tansr-chunk-IZICOKKF.mjs} +9 -9
- package/{tansr-chunk-Q6MUMULP.mjs → tansr-chunk-J2LWM3S7.mjs} +2 -2
- package/{tansr-chunk-ZY3IR67Q.mjs → tansr-chunk-KQVXXXEF.mjs} +2 -2
- package/{tansr-chunk-QNHXB55W.mjs → tansr-chunk-M6XHWCMA.mjs} +2 -2
- package/{tansr-chunk-TYJWMSVW.mjs → tansr-chunk-N3R2URKL.mjs} +2 -2
- package/{tansr-chunk-J2ED6CI4.mjs → tansr-chunk-QUFHVA3F.mjs} +2 -2
- package/{tansr-chunk-6OXR4F5Y.mjs → tansr-chunk-X4GLXJ2Z.mjs} +2 -2
- package/{tansr-chunk-WGXWBU37.mjs → tansr-chunk-X5REV3T3.mjs} +2 -2
- package/{tansr-chunk-CI7LFRTK.mjs → tansr-chunk-ZV3NCXTD.mjs} +2 -2
- package/{tansr-main-5V46X7QH.mjs → tansr-main-STVTNYAI.mjs} +3 -3
- package/{tansr-run-acp-entry-ANNUR7IB.mjs → tansr-run-acp-entry-6J44XOYJ.mjs} +3 -3
- package/{tansr-run-approvals-entry-SLLTFTSX.mjs → tansr-run-approvals-entry-HQWSIW3P.mjs} +2 -2
- package/{tansr-run-auth-entry-X3SXNPOI.mjs → tansr-run-auth-entry-7HA4C4NJ.mjs} +2 -2
- package/{tansr-run-doctor-RYIQQOOK.mjs → tansr-run-doctor-7T6IAXYE.mjs} +3 -3
- package/{tansr-run-headless-entry-I53HJDNX.mjs → tansr-run-headless-entry-XEFQC5LE.mjs} +2 -2
- package/{tansr-run-init-entry-USPWKDRI.mjs → tansr-run-init-entry-3VKXS2WK.mjs} +2 -2
- package/{tansr-run-logout-entry-KO7ZL2M5.mjs → tansr-run-logout-entry-VNCNNCSS.mjs} +2 -2
- package/{tansr-run-mcp-serve-entry-YMQH7WSF.mjs → tansr-run-mcp-serve-entry-5KLWER3G.mjs} +2 -2
- package/{tansr-run-orchestrate-entry-YN3M6BWY.mjs → tansr-run-orchestrate-entry-AR57AZLR.mjs} +2 -2
- package/{tansr-run-org-entry-STRRZVI4.mjs → tansr-run-org-entry-TJPRLGCL.mjs} +2 -2
- package/{tansr-run-policy-entry-4ENHRAMQ.mjs → tansr-run-policy-entry-DHMQ3PAP.mjs} +2 -2
- package/{tansr-run-profile-entry-THJMZ7ZA.mjs → tansr-run-profile-entry-LOFPHFG4.mjs} +2 -2
- package/tansr-run-serve-entry-CHVKUY5J.mjs +99 -0
- package/{tansr-run-sessions-entry-KIT7PALM.mjs → tansr-run-sessions-entry-JOMFB5LJ.mjs} +2 -2
- package/{tansr-run-update-entry-HYSKHBB6.mjs → tansr-run-update-entry-XI6KG7UI.mjs} +2 -2
- package/{tansr-src-JAODAP53.mjs → tansr-src-A6WDMY6X.mjs} +3 -3
- package/{tansr-startup-account-QUJKOV6V.mjs → tansr-startup-account-7ZFSP3FV.mjs} +4 -4
- package/{tansr-startup-model-SREG5HNN.mjs → tansr-startup-model-I6LOCFDP.mjs} +3 -3
- package/{tansr-tui-DXGFMSII.mjs → tansr-tui-OWG3JNA6.mjs} +5 -5
- package/tansr.mjs +1 -1
- package/tansrd.mjs +41 -41
- package/tansr-chunk-TZJHQ3TT.mjs +0 -38
- package/tansr-run-serve-entry-N5PK7ACI.mjs +0 -99
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { createRequire as __tansrCreateRequire } from 'module';const require=__tansrCreateRequire(import.meta.url);
|
|
2
2
|
import { fileURLToPath as __tansrFileURLToPath } from 'url';import { dirname as __tansrDirname } from 'path';
|
|
3
3
|
const __filename=__tansrFileURLToPath(import.meta.url);const __dirname=__tansrDirname(__filename);
|
|
4
|
-
import{a as L,b as ee,c as ne,e as te}from"./tansr-chunk-M774GK3P.mjs";import{f as J}from"./tansr-chunk-
|
|
4
|
+
import{a as L,b as ee,c as ne,e as te}from"./tansr-chunk-M774GK3P.mjs";import{f as J}from"./tansr-chunk-HHL7HM62.mjs";import{x as Q}from"./tansr-chunk-X5REV3T3.mjs";import{m as W,n as Y}from"./tansr-chunk-HRKJLVKC.mjs";import{Wc as Z,ef as X,wb as A,xb as z}from"./tansr-chunk-IZICOKKF.mjs";import{k as G,m as d,o as H}from"./tansr-chunk-NA22YT73.mjs";import{createInterface as Xe}from"node:readline";var re={$comment:"发布签名公钥表(FX-C-27 单源):keyId → ed25519 SPKI PEM。消费方 = packages/cli/src/update/release-trust.ts(客户端验签)与 scripts/release/publish-oss.mjs(上传前验签断言)。换钥纪律:keyId 递版恒不复用(release-signing-v2…),多钥并列共存随 CLI 发版;第二把公钥候 Op-2(签名密钥托管)回执后填入。私钥恒不在仓(deploy/release-certs/,签发工装 scripts/release/sign-release.mjs)。",keys:{"release-signing-v1":`-----BEGIN PUBLIC KEY-----
|
|
5
5
|
MCowBQYDK2VwAyEAwMO8OOqVgghzvxIW8QAUHhAkFZJlpIEOa44Z58TGmmg=
|
|
6
6
|
-----END PUBLIC KEY-----
|
|
7
7
|
`}};var _e=Object.freeze({...re.keys});var F={unsignedPolicy:"reject",schemes:["https:"],hosts:[]},h=class extends Error{code;url;detail;constructor(n,t,r){super(`${n}: ${t}`),this.name="ReleaseTrustError",this.code=n,this.url=t,r!==void 0&&(this.detail=r)}};function ve(e,n){if(n.length===0)return!0;let t=e.toLowerCase();return n.some(r=>{let i=r.toLowerCase();return t===i||t.endsWith(`.${i}`)})}function q(e,n=F){let t;try{t=new URL(e)}catch{throw new h("invalid_url",e)}if(!n.schemes.includes(t.protocol))throw new h("insecure_scheme",e);if(!ve(t.hostname,n.hosts))throw new h("untrusted_host",e);return t}function R(){return{unsignedPolicy:"reject",verifiers:[z({publicKeys:_e})]}}function V(e){return e===void 0?R():{...e,unsignedPolicy:"reject"}}import{createRequire as Re}from"node:module";var Se=/^(\d+)\.(\d+)\.(\d+)$/;function P(e){let n=e.trim();(n.startsWith("v")||n.startsWith("V"))&&(n=n.slice(1));let t=n.indexOf("+");t!==-1&&(n=n.slice(0,t));let r=n.indexOf("-"),i=r===-1?n:n.slice(0,r),a=r===-1?"":n.slice(r+1),s=Se.exec(i);if(s===null)return null;let f=Number(s[1]),m=Number(s[2]),o=Number(s[3]);if(!Number.isSafeInteger(f)||!Number.isSafeInteger(m)||!Number.isSafeInteger(o))return null;let p=[];return r!==-1&&(a===""||(p=a.split(".").map(c=>/^\d+$/.test(c)?Number(c):c),p.some(c=>c==="")))?null:{major:f,minor:m,patch:o,prerelease:p}}function be(e,n){if(e.length===0&&n.length===0)return 0;if(e.length===0)return 1;if(n.length===0)return-1;let t=Math.min(e.length,n.length);for(let r=0;r<t;r++){let i=e[r],a=n[r];if(typeof i=="number"&&typeof a=="number"){if(i!==a)return i<a?-1:1}else{if(typeof i=="number")return-1;if(typeof a=="number")return 1;if(i!==a)return i<a?-1:1}}return e.length===n.length?0:e.length<n.length?-1:1}function C(e,n){let t=P(e),r=P(n);return t===null||r===null?null:t.major!==r.major?t.major<r.major?-1:1:t.minor!==r.minor?t.minor<r.minor?-1:1:t.patch!==r.patch?t.patch<r.patch?-1:1:be(t.prerelease,r.prerelease)}var T="@tansr/cli",se="https://bash.tansr.com/release/{channel}/sea/latest.signed.json",M=`https://registry.npmjs.org/${T.replace("/","%2f")}`,ke="application/vnd.npm.install-v1+json",Ue=5e3;function S(e){let n=e?.trim();return n!==void 0&&n!==""?n:void 0}function oe(e,n,t){let r=S(e.TANSR_UPDATE_PINNED_VERSION)??S(t?.pinnedVersion);if(r!==void 0)return{kind:"pinned",pinnedVersion:r};let i=e.TANSR_UPDATE_CHANNEL?.trim().toLowerCase(),s=(i==="stable"||i==="beta"||i==="none"?i:void 0)??t?.channel;if(s==="none")return{kind:"disabled",reason:"channel_none"};let f=S(e.TANSR_NO_UPDATE_CHECK);return(f!==void 0?f==="1":t?.checkEnabled===!1)?{kind:"disabled",reason:"opt_out"}:{kind:"check",channel:s==="stable"||s==="beta"?s:n??"stable"}}function le(e){return/-beta(\.|$)/.test(e)?"beta":"stable"}function ie(e,n){let t={};if(e.sequence!==void 0){if(!ne(e.sequence))throw new h("pointer_signature_invalid",n);t.sequence=e.sequence}let r=typeof e.issuedAt=="string"?e.issuedAt:e.publishedAt;return typeof r=="string"&&r!==""&&(t.issuedAt=r),t}function de(e){if(typeof e!="object"||e===null)return!1;let n=e;return Array.isArray(n.files)&&typeof n.keyId=="string"}function Ie(e,n,t,r){if(typeof e!="object"||e===null)throw new h("pointer_unsigned",n);let i=e;if(i.format!=="tansr-release-v1"||i.alg!=="ed25519"||typeof i.keyId!="string"||typeof i.signature!="string"||typeof i.payload!="string")throw new h("pointer_unsigned",n);let a=()=>new h("pointer_signature_invalid",n);if(Object.keys(i).some(u=>!["format","alg","keyId","signature","payload"].includes(u)))throw a();let s=i.payload;if(s.length>1398104||!/^[A-Za-z0-9+/]*={0,2}$/.test(s))throw a();let f=Buffer.from(s,"base64");if(f.length===0||f.length>1048576||f.toString("base64")!==s)throw a();let m=i.signature;if(Buffer.from(m,"base64").length!==64||Buffer.from(m,"base64").toString("base64")!==m)throw a();let o=(r.verifiers??[]).find(u=>u.alg===A),p;try{if(!o?.verify({payload:f,keyId:i.keyId,value:m}))throw a();p=JSON.parse(new TextDecoder("utf-8",{fatal:!0}).decode(f))}catch{throw a()}if(!de(p)||p.keyId!==i.keyId||p.channel!==t||typeof p.version!="string"||!/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/.test(p.version)||p.files.length===0||p.files.length>128)throw a();let c=new Set,v=new Set;for(let u of p.files){if(typeof u!="object"||u===null)throw a();let g=u;if(typeof g.name!="string"||!/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(g.name)||typeof g.platform!="string"||g.platform===""||typeof g.arch!="string"||g.arch===""||typeof g.sha256!="string"||!/^[a-f0-9]{64}$/.test(g.sha256)||typeof g.sig!="string"||Buffer.from(g.sig,"base64").length!==64||Buffer.from(g.sig,"base64").toString("base64")!==g.sig)throw a();let y=`${g.platform}:${g.arch}`;if(c.has(g.name)||v.has(y))throw a();c.add(g.name),v.add(y)}return p}function ae(e,n){let t=typeof e.version=="string"?e.version:"",r=e.files.filter(i=>typeof i=="object"&&i!==null).map(i=>({platform:i.platform,arch:i.arch,file:i.name,sha256:i.sha256,url:typeof i.name=="string"?new URL(`${t}/${i.name}`,n).href:void 0,signature:i.sig,keyId:e.keyId}));return{version:e.version,artifacts:r,...typeof e.minVersion=="string"?{minVersion:e.minVersion}:{},...typeof e.mandatory=="boolean"?{mandatory:e.mandatory}:{}}}async function Ee(e,n,t,r,i){let a=`${n}.sig`,s;try{let o=await e(a,{signal:AbortSignal.timeout(i)});if(!o.ok)throw new Error(`HTTP ${o.status}`);s=await o.json()}catch{throw new h("pointer_unsigned",n)}if(typeof s!="object"||s===null||s.alg!=="ed25519"||typeof s.keyId!="string"||typeof s.signature!="string")throw new h("pointer_unsigned",n);let f=(r.verifiers??[]).find(o=>o.alg===A),m=!1;try{m=f!==void 0&&f.verify({payload:t,keyId:s.keyId,value:s.signature})}catch{m=!1}if(!m)throw new h("pointer_signature_invalid",n)}function Ae(e,n){if(typeof e!="object"||e===null)return null;let t=e;if(typeof t.version!="string")return null;let r;if(Array.isArray(t.artifacts)){let i=t.artifacts.find(a=>a.platform===n.platform&&a.arch===n.arch&&typeof a.file=="string");if(i!==void 0){let a;if(typeof i.url=="string")a=i.url;else try{a=new URL(i.file,n.manifestUrl).href}catch{a=void 0}if(a!==void 0){let s=new URL(n.manifestUrl);if(q(a,{...n.trustPolicy,hosts:n.trustPolicy.hosts.length>0?n.trustPolicy.hosts:[s.hostname]}),n.trustPolicy.hosts.length===0&&new URL(a).origin!==s.origin)throw new h("untrusted_host",a)}r={file:i.file,sha256:typeof i.sha256=="string"?i.sha256:"",...a!==void 0?{url:a}:{},...typeof i.signature=="string"?{signature:i.signature}:{},...typeof i.keyId=="string"?{keyId:i.keyId}:{}}}}return{latestVersion:t.version,...r!==void 0?{artifact:r}:{},...typeof t.minVersion=="string"?{minVersion:t.minVersion}:{},...typeof t.mandatory=="boolean"?{mandatory:t.mandatory}:{}}}function Te(e,n){if(typeof e!="object"||e===null)return null;let t=e["dist-tags"];if(typeof t!="object"||t===null)return null;let r=t,i=n==="beta"?r.beta??r.latest:r.latest;return typeof i=="string"?i:null}async function ue(e){let n=e.fetch??globalThis.fetch,t=e.env??process.env,r=e.platform??process.platform,i=e.arch??process.arch,a=e.timeoutMs??Ue,s=e.trustPolicy??F,f=S(t.TANSR_UPDATE_MANIFEST_URL)??S(e.config?.manifestUrl)??S(e.defaultManifestUrl),m=f!==void 0;try{let o=m?f.replaceAll("{channel}",e.channel):M;q(o,s);let p=await n(o,{signal:AbortSignal.timeout(a),headers:m?{}:{accept:ke}});if(!p.ok)return null;let c=typeof p.text=="function"?await p.text():void 0,v=m&&new URL(o).pathname.endsWith("/latest.signed.json"),u;try{u=c!==void 0?JSON.parse(c):await p.json()}catch(_){throw v?new h("pointer_signature_invalid",o):_}let g=typeof u=="object"&&u!==null&&("format"in u&&typeof u.format=="string"&&u.format.startsWith("tansr-release-")||"payload"in u&&("signature"in u||"alg"in u||"keyId"in u)),y;if(m&&(v||g)){let _=Ie(u,o,e.channel,e.trust??R());y=ie(_,o),u=ae(_,o)}else if(m&&de(u)){if(c===void 0)throw new h("pointer_unsigned",o);await Ee(n,o,new TextEncoder().encode(c),e.trust??R(),a),y=ie(u,o),u=ae(u,o)}let $=ee(o,e.channel),I=y!==void 0&&e.sequenceState!==void 0?await e.sequenceState.read($):null;if(I!==null&&y!==void 0){if(y.sequence===void 0){if(0<I.sequence)throw new h("pointer_sequence_missing",o,{lastSeen:I.sequence})}else if(y.sequence<I.sequence)throw new h("pointer_sequence_rollback",o,{sequence:y.sequence,lastSeen:I.sequence})}let E,N,O,x;if(m){let _=Ae(u,{manifestUrl:o,platform:r,arch:i,trustPolicy:s});if(_===null)return null;E=_.latestVersion,N=_.artifact,O=_.minVersion,x=_.mandatory}else{let _=Te(u,e.channel);if(_===null)return null;E=_}let K=C(e.currentVersion,E);if(K===null)return null;e.sequenceState!==void 0&&y?.sequence!==void 0&&await e.sequenceState.write($,{sequence:y.sequence,version:E,...y.issuedAt!==void 0?{issuedAt:y.issuedAt}:{},seenAt:new Date().toISOString(),url:o});let B={currentVersion:e.currentVersion,latestVersion:E,source:m?"manifest":"npm",channel:e.channel,...y!==void 0&&y.sequence===void 0?{unsequenced:!0}:{}};return K<0?{status:"update_available",...B,...N!==void 0?{artifact:N}:{},...O!==void 0?{minVersion:O}:{},...x!==void 0?{mandatory:x}:{}}:{status:"up_to_date",...B}}catch(o){return o instanceof h?{status:"rejected",currentVersion:e.currentVersion,source:m?"manifest":"npm",channel:e.channel,reason:o.code,url:o.url,...o.detail!==void 0?{detail:o.detail}:{}}:null}}var l={pinned:"cli.update.pinned",disabledChannelNone:"cli.update.disabled.channel_none",disabledOptOut:"cli.update.disabled.opt_out",upToDate:"cli.update.up_to_date",availableNpm:"cli.update.available.npm",availableSea:"cli.update.available.sea",availableSeaGeneric:"cli.update.available.sea_generic",checkFailed:"cli.update.check_failed",checkRejected:"cli.update.check_rejected",checkRejectedSequenceRollback:"cli.update.check_rejected_sequence_rollback",checkRejectedSequenceMissing:"cli.update.check_rejected_sequence_missing",unsequencedHint:"cli.update.unsequenced_hint",confirmSource:"cli.update.confirm.source",confirmUrl:"cli.update.confirm.url",confirmVersion:"cli.update.confirm.version",confirmSha256:"cli.update.confirm.sha256",confirmSignature:"cli.update.confirm.signature",allowUnsignedWarning:"cli.update.allow_unsigned.warning",allowUnsignedPrompt:"cli.update.allow_unsigned.prompt",allowUnsignedDenied:"cli.update.allow_unsigned.denied",allowUnsignedRequiresInstall:"cli.update.allow_unsigned.requires_install",installing:"cli.update.installing",installSuccessNpm:"cli.update.install.success.npm",installSuccessSea:"cli.update.install.success.sea",installFailedBadVersion:"cli.update.install.failed.bad_version",installFailedNpm:"cli.update.install.failed.npm",installFailedTimeout:"cli.update.install.failed.timeout",installFailedDownload:"cli.update.install.failed.download",installFailedChecksum:"cli.update.install.failed.checksum",installFailedChecksumMissing:"cli.update.install.failed.checksum_missing",installFailedSignature:"cli.update.install.failed.signature",installFailedUnsigned:"cli.update.install.failed.unsigned",installFailedNoArtifact:"cli.update.install.failed.no_artifact",installFailedSwap:"cli.update.install.failed.swap",installFailedError:"cli.update.install.failed.error",installVerifyFailed:"cli.update.install.verify_failed",installHint:"cli.update.install_hint",mandatoryNotice:"cli.update.mandatory",minVersionNotice:"cli.update.min_version"},mn=Object.values(l);function Ve(){try{return Re(import.meta.url)("node:sea").isSea?.()===!0}catch{return!1}}function Pe(e){let n=[];if(e.mandatory===!0&&n.push(d(l.mandatoryNotice)),e.minVersion!==void 0){let t=C(e.currentVersion,e.minVersion);t!==null&&t<0&&n.push(d(l.minVersionNotice,{minVersion:e.minVersion}))}return n}function Ce(e,n){if(e===null)return{message:d(l.checkFailed,{channel:n.channel}),level:"error"};if(e.status==="rejected")return e.reason==="pointer_sequence_rollback"?{message:d(l.checkRejectedSequenceRollback,{sequence:e.detail?.sequence??"",lastSeen:e.detail?.lastSeen??"",url:e.url}),level:"error"}:e.reason==="pointer_sequence_missing"?{message:d(l.checkRejectedSequenceMissing,{lastSeen:e.detail?.lastSeen??"",url:e.url}),level:"error"}:{message:d(l.checkRejected,{reason:e.reason,url:e.url}),level:"error"};let t=e.unsequenced===!0?[d(l.unsequencedHint)]:[];if(e.status==="up_to_date")return{message:[d(l.upToDate,{version:e.currentVersion,channel:e.channel}),...t].join(`
|
|
8
8
|
`),level:"info"};let r=a=>({message:[a,...Pe(e),...t].join(`
|
|
9
|
-
`),level:"info"}),i={current:e.currentVersion,latest:e.latestVersion};return n.install==="sea"?e.artifact!==void 0&&e.artifact.url!==void 0?r(d(l.availableSea,{...i,url:e.artifact.url,sha256:e.artifact.sha256})):r(d(l.availableSeaGeneric,i)):r(d(l.availableNpm,i))}var Ne="0.10.
|
|
9
|
+
`),level:"info"}),i={current:e.currentVersion,latest:e.latestVersion};return n.install==="sea"?e.artifact!==void 0&&e.artifact.url!==void 0?r(d(l.availableSea,{...i,url:e.artifact.url,sha256:e.artifact.sha256})):r(d(l.availableSeaGeneric,i)):r(d(l.availableNpm,i))}var Ne="0.10.3",Oe="stable";function xe(e){return Oe==="beta"?"beta":le(e)}async function ce(e={}){let n=e.env??process.env,t=e.currentVersion??Ne,r=oe(n,xe(t),e.config);if(r.kind==="pinned")return{notice:{message:d(l.pinned,{current:t,pinned:r.pinnedVersion}),level:"info"}};if(r.kind==="disabled")return{notice:{message:d(r.reason==="channel_none"?l.disabledChannelNone:l.disabledOptOut),level:"info"}};let i=e.install??(Ve()?"sea":"npm"),a=await ue({channel:r.channel,currentVersion:t,env:n,...i==="sea"?{defaultManifestUrl:se}:{},...e.config!==void 0?{config:e.config}:{},...e.fetch!==void 0?{fetch:e.fetch}:{},...e.platform!==void 0?{platform:e.platform}:{},...e.arch!==void 0?{arch:e.arch}:{},...e.timeoutMs!==void 0?{timeoutMs:e.timeoutMs}:{},...e.trust!==void 0?{trust:e.trust}:{},sequenceState:e.sequenceState??te(e.homedir!==void 0?L(n,e.homedir):L(n))}),s=Ce(a,{install:i,channel:r.channel});return a===null||a.status!=="update_available"?{notice:s}:{notice:s,available:{currentVersion:a.currentVersion,latestVersion:a.latestVersion,channel:a.channel,source:a.source,install:i,...a.artifact!==void 0?{artifact:a.artifact}:{},...a.minVersion!==void 0?{minVersion:a.minVersion}:{},...a.mandatory!==void 0?{mandatory:a.mandatory}:{}}}}import{spawn as Le}from"node:child_process";import{createHash as Fe}from"node:crypto";import{readdir as qe}from"node:fs/promises";import j from"node:path";var Me={...W,readdir:e=>qe(e)},je=3e5,fe=400,De=/(TOKEN|SECRET|PASSWORD|PASSWD|API_?KEY|AUTH)/i,$e=/(_authToken\s*=\s*)\S+/gi,Ke=/(\/\/[^/\s:@]+):([^/\s@]+)@/g;function Be(e){let n=[];for(let[t,r]of Object.entries(e)){if(r===void 0)continue;let i=r.trim();i.length<8||De.test(t)&&n.push(i)}return n}function b(e,n){return Z(e,Be(n)).replace($e,"$1***").replace(Ke,"$1:***@")}function k(e){let n=e.replace(/\s+/g," ").trim();return n.length<=fe?n:`...${n.slice(-fe)}`}function U(e){return e instanceof Error?e.message:String(e)}function Ge(){return(e,n,t)=>new Promise(r=>{let i=Le(e,[...n],{shell:process.platform==="win32",windowsHide:!0,stdio:["ignore","pipe","pipe"]}),a="",s="",f=!1,m=!1,o=c=>{m||(m=!0,clearTimeout(p),r({code:c,stdout:a,stderr:s,timedOut:f}))},p=setTimeout(()=>{f=!0,i.kill(),setTimeout(()=>o(null),5e3).unref()},t.timeoutMs);i.stdout?.on("data",c=>{a+=c.toString()}),i.stderr?.on("data",c=>{s+=c.toString()}),i.on("error",c=>{s+=U(c),o(null)}),i.on("close",c=>o(c))})}function w(e,n){return{ok:!1,message:e,level:"error",reason:n}}function He(e){try{let t=JSON.parse(e).dependencies?.[T]?.version;return typeof t=="string"?t:null}catch{return null}}function We(e){return/\d+\.\d+\.\d+[0-9A-Za-z.+-]*/.exec(e)?.[0]??"-"}async function Ye(e,n){if(P(e.latestVersion)===null)return w(d(l.installFailedBadVersion,{version:e.latestVersion}),"bad_version");let t=`${T}@${e.latestVersion}`,r=await n.spawn("npm",["install","-g",t],{timeoutMs:n.timeoutMs});if(r.timedOut)return w(d(l.installFailedTimeout,{seconds:Math.round(n.timeoutMs/1e3)}),"timeout");if(r.code!==0){let s=r.stderr.trim()!==""?r.stderr:r.stdout;return w(d(l.installFailedNpm,{code:r.code??-1,detail:k(b(s,n.env))}),"npm_failed")}let i=await n.spawn("npm",["ls","-g",T,"--json","--depth=0"],{timeoutMs:n.timeoutMs}),a=i.timedOut?null:He(i.stdout);return a===e.latestVersion?{ok:!0,level:"info",message:d(l.installSuccessNpm,{from:e.currentVersion,to:a})}:w(d(l.installVerifyFailed,{expected:e.latestVersion,actual:a??"-"}),"verify_failed")}function ze(e){let n=e.signature?.trim(),t=e.keyId?.trim();return n===void 0||n===""||t===void 0||t===""?null:{signature:n,keyId:t}}function me(e,n){let t=ze(e);if(t===null)return{state:"unsigned"};let r=(n.verifiers??[]).find(i=>i.alg===A);if(r===void 0)return{state:"invalid",keyId:t.keyId};try{let i=new TextEncoder().encode(e.sha256.trim().toLowerCase());return r.verify({payload:i,keyId:t.keyId,value:t.signature})?{state:"verified",keyId:t.keyId}:{state:"invalid",keyId:t.keyId}}catch{return{state:"invalid",keyId:t.keyId}}}function Ze(e,n,t){let r=me(e,n);return r.state==="unsigned"?t?null:w(d(l.installFailedUnsigned),"unsigned_rejected"):r.state==="invalid"?w(d(l.installFailedSignature,{keyId:r.keyId}),"signature_invalid"):null}function pe(e,n){if(e.install==="npm")return{source:"npm",url:M,version:e.latestVersion,sha256:"-",signature:"npm-registry"};let t=e.artifact,r=t?.url??"-",i="manifest";try{let s=new URL(r).hostname.toLowerCase();s==="bash.tansr.com"?i="oss":(s==="github.com"||s.endsWith(".githubusercontent.com"))&&(i="github")}catch{}let a="UNSIGNED";if(t!==void 0){let s=me(t,n);s.state==="verified"?a=`verified:${s.keyId}`:s.state==="invalid"&&(a=`INVALID:${s.keyId}`)}return{source:i,url:r,version:e.latestVersion,sha256:t?.sha256.trim().toLowerCase()??"-",signature:a}}function ge(e,n){return[d(l.confirmSource,{source:e.source}),d(l.confirmUrl,{url:e.url}),d(l.confirmVersion,{current:n,latest:e.version}),d(l.confirmSha256,{sha256:e.sha256}),d(l.confirmSignature,{signature:e.signature})]}async function Je(e,n){let t=e.artifact;if(t===void 0||t.url===void 0||t.url==="")return w(d(l.installFailedNoArtifact),"no_artifact");let r=t.sha256.trim().toLowerCase();if(r==="")return w(d(l.installFailedChecksumMissing),"checksum_missing");let i=Ze(t,n.trust,n.allowUnsignedOnce);if(i!==null)return i;let a;try{let u=await n.fetch(t.url,{signal:AbortSignal.timeout(n.timeoutMs)});if(!u.ok)return w(d(l.installFailedDownload,{detail:`HTTP ${u.status}`}),"download_failed");a=Buffer.from(await u.arrayBuffer())}catch(u){return w(d(l.installFailedDownload,{detail:k(b(U(u),n.env))}),"download_failed")}let s=Fe("sha256").update(a).digest("hex");if(s!==r)return w(d(l.installFailedChecksum,{expected:r,actual:s}),"signature_mismatch");let f=n.execPath,m=`${f}.update-${process.pid}.new`,o=n.fs;try{await Y(m,a,{fs:o}),process.platform!=="win32"&&await o.chmod(m,493)}catch(u){return await o.rm(m,{force:!0}).catch(()=>{}),w(d(l.installFailedError,{detail:k(b(U(u),n.env))}),"error")}let p=`${f}.old-${e.currentVersion}`;try{await o.rm(p,{force:!0}),await o.rename(f,p)}catch(u){return w(d(l.installFailedSwap,{detail:k(b(U(u),n.env)),staged:m}),"swap_failed")}try{await o.rename(m,f)}catch(u){try{await o.rename(p,f)}catch{}return w(d(l.installFailedSwap,{detail:k(b(U(u),n.env)),staged:m}),"swap_failed")}await Qe(o,f,p);let c=await n.spawn(f,["--version"],{timeoutMs:n.timeoutMs});return!c.timedOut&&c.code===0&&c.stdout.includes(e.latestVersion)?{ok:!0,level:"info",message:d(l.installSuccessSea,{from:e.currentVersion,to:e.latestVersion,backup:p})}:w(d(l.installVerifyFailed,{expected:e.latestVersion,actual:We(c.stdout)}),"verify_failed")}async function Qe(e,n,t){let r=j.dirname(n),i=`${j.basename(n)}.old-`,a;try{a=await e.readdir(r)}catch{return}for(let s of a){if(!s.startsWith(i))continue;let f=j.join(r,s);f!==t&&await e.rm(f,{force:!0}).catch(()=>{})}}function ye(e){return e.install==="npm"?!0:e.artifact!==void 0&&(e.artifact.url??"")!==""&&e.artifact.sha256.trim()!==""}async function he(e,n={}){let t=n.env??process.env,r={env:t,fetch:n.fetch??globalThis.fetch,spawn:n.spawn??Ge(),execPath:n.execPath??process.execPath,timeoutMs:n.timeoutMs??je,trust:V(n.trust),allowUnsignedOnce:n.allowUnsignedOnce===!0,fs:n.fs??Me};try{return e.install==="npm"?await Ye(e,r):await Je(e,r)}catch(i){return w(d(l.installFailedError,{detail:k(b(U(i),t))}),"error")}}var D="UNSIGNED";function en(e){let n=!1,t=!1;for(let r of e){if(r==="--install"){n=!0;continue}if(r==="--allow-unsigned"){t=!0;continue}return{ok:!1,flag:r}}return t&&!n?{ok:!1,flag:"--allow-unsigned"}:{ok:!0,install:n,allowUnsigned:t}}function nn(e,n){return e.isTTY!==!0?Promise.resolve(!1):new Promise(t=>{let r=Xe({input:e,output:n,terminal:!1}),i=!1,a=s=>{i||(i=!0,r.close(),t(s!==null&&s.trim()===D))};r.question(d(l.allowUnsignedPrompt,{token:D})+" ",a),r.on("close",()=>a(null))})}async function $n(e,n={}){let t=n.stdout??process.stdout,r=n.stderr??process.stderr,i=n.env??process.env,a=n.cwd??process.cwd(),s=await Q({cwd:a,env:i,...n.loadOptions!==void 0?{loadOptions:n.loadOptions}:{}});G(H({configLocale:s.loaded.locale,env:i}));let f=en(e);if(!f.ok)return r.write((f.flag==="--allow-unsigned"?d(l.allowUnsignedRequiresInstall):d(X.unknownFlag,{flag:f.flag}))+`
|
|
10
10
|
`),1;let m=await J({env:i,policy:s.loaded.policy});for(let y of m.notices)y.level==="error"&&r.write(y.message+`
|
|
11
11
|
`);let o=V(m.verify),p=await ce({env:i,...s.loaded.update!==void 0?{config:s.loaded.update}:{},...n.version!==void 0?{currentVersion:n.version}:{},...n.fetch!==void 0?{fetch:n.fetch}:{},...n.install!==void 0?{install:n.install}:{},...n.timeoutMs!==void 0?{timeoutMs:n.timeoutMs}:{},trust:o,...n.loadOptions?.homedir!==void 0?{homedir:n.loadOptions.homedir}:{}}),c=p.available;if(!f.install||c===void 0){let y=c!==void 0&&ye(c)?`
|
|
12
12
|
`+d(l.installHint):"";return p.notice.level==="error"?(r.write(p.notice.message+`
|
|
@@ -18,4 +18,4 @@ MCowBQYDK2VwAyEAwMO8OOqVgghzvxIW8QAUHhAkFZJlpIEOa44Z58TGmmg=
|
|
|
18
18
|
`),1;u=!0}t.write(d(l.installing,{current:c.currentVersion,latest:c.latestVersion,channel:c.channel})+`
|
|
19
19
|
`);let g=await he(c,{env:i,...n.fetch!==void 0?{fetch:n.fetch}:{},...n.spawn!==void 0?{spawn:n.spawn}:{},...n.execPath!==void 0?{execPath:n.execPath}:{},...n.timeoutMs!==void 0?{timeoutMs:n.timeoutMs}:{},trust:o,allowUnsignedOnce:u});return(g.ok?t:r).write(g.message+`
|
|
20
20
|
`),g.ok?0:1}export{V as a,l as b,Pe as c,ce as d,pe as e,ge as f,ye as g,he as h,D as i,en as j,$n as k};
|
|
21
|
-
//# sourceMappingURL=tansr-chunk-
|
|
21
|
+
//# sourceMappingURL=tansr-chunk-GMPMRXL4.mjs.map
|