@allscale/cli 0.1.0 → 1.0.1

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.
Files changed (39) hide show
  1. package/README.md +113 -41
  2. package/bin/dev.js +11 -1
  3. package/bin/run-oclif.js +216 -27
  4. package/bin/run.js +19 -1
  5. package/dist/commands/build-info.js +13 -13
  6. package/dist/commands/claim-link/claim.js +14 -14
  7. package/dist/commands/claim-link/create.js +40 -37
  8. package/dist/commands/claim-link/get.js +26 -15
  9. package/dist/commands/claim-link/list.js +15 -15
  10. package/dist/commands/claim-link/status.js +13 -13
  11. package/dist/commands/describe.js +13 -13
  12. package/dist/commands/device-login.js +23 -24
  13. package/dist/commands/invoice/get.js +15 -15
  14. package/dist/commands/invoice/list.js +16 -16
  15. package/dist/commands/invoice/pay.js +40 -41
  16. package/dist/commands/invoice/received.js +16 -16
  17. package/dist/commands/invoice/send.js +42 -34
  18. package/dist/commands/invoice/sent.js +15 -15
  19. package/dist/commands/invoice/update.js +17 -15
  20. package/dist/commands/logout.js +14 -14
  21. package/dist/commands/operations.js +13 -13
  22. package/dist/commands/otp-login.js +21 -20
  23. package/dist/commands/otp-send.js +13 -13
  24. package/dist/commands/payout/send.js +14 -14
  25. package/dist/commands/payout/status.js +15 -15
  26. package/dist/commands/scope.js +17 -16
  27. package/dist/commands/store/create.js +17 -17
  28. package/dist/commands/transaction/get.js +15 -15
  29. package/dist/commands/transaction/list.js +15 -15
  30. package/dist/commands/wallet/list.js +15 -15
  31. package/dist/commands/wallet/send.js +40 -43
  32. package/dist/commands/whoami.js +14 -14
  33. package/dist/hooks/version-suffix.js +1 -1
  34. package/dist/index.js +14 -14
  35. package/dist/lib/help.js +7 -2
  36. package/dist/lib/output/audit-lifecycle.js +7 -0
  37. package/oclif.manifest.json +123 -292
  38. package/package.json +4 -6
  39. package/dist/commands/claim-link/preview.js +0 -18
@@ -1,18 +1,18 @@
1
- "use strict";var Vt=Object.create;var z=Object.defineProperty;var Zt=Object.getOwnPropertyDescriptor;var Qt=Object.getOwnPropertyNames;var en=Object.getPrototypeOf,tn=Object.prototype.hasOwnProperty;var nn=(e,t)=>{for(var n in t)z(e,n,{get:t[n],enumerable:!0})},ze=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Qt(t))!tn.call(e,i)&&i!==n&&z(e,i,{get:()=>t[i],enumerable:!(r=Zt(t,i))||r.enumerable});return e};var E=(e,t,n)=>(n=e!=null?Vt(en(e)):{},ze(t||!e||!e.__esModule?z(n,"default",{value:e,enumerable:!0}):n,e)),rn=e=>ze(z({},"__esModule",{value:!0}),e);var yr={};nn(yr,{default:()=>le});module.exports=rn(yr);var w=require("@oclif/core");var qe="public",Xe="https://app.allscale.io";var Ve=["https://app.allscale.io"];var ue="Override the API base URL (public builds accept only https://app.allscale.io)";var de="Only https://app.allscale.io is allowed, and URL userinfo is forbidden.";function Ze(e){try{let t=new URL(e);return t.username.length>0||t.password.length>0?null:t.protocol==="https:"?t:null}catch{return null}}function Qe(e){return Ze(e)!==null}function fe(e){let t=Ze(e);return t!==null&&Ve.includes(t.origin)}function $(){return"".trim()||void 0}function M(){return"public"}function et(e){try{let{hostname:t}=new URL(e);return t==="127.0.0.1"||t==="localhost"||t==="[::1]"}catch{return!1}}function tt(){{let e="[]".trim();if(e.length===0)return[];try{let t=JSON.parse(e);return Array.isArray(t)?t:[]}catch{return[]}}return pe()}function pe(){let e=process.env.ALLSCALE_BUILD_PAIRS?.trim()??"";if(e.length>0)try{let r=JSON.parse(e);if(!Array.isArray(r))return[];let i=[];for(let o of r){if(typeof o!="object"||o===null)continue;let{base:a,key:l,keyId:u}=o;if(typeof a!="string"||a.trim().length===0||typeof l!="string"||l.trim().length===0)continue;let d=typeof u=="string"?u.trim():"";i.push({base:a.trim(),key:l,keyId:d.length>0?d:"cli-1"})}return i}catch{return[]}let t=process.env.ALLSCALE_SIGNING_KEY??"",n=process.env.ALLSCALE_BUILD_API_BASE?.trim()??"";if(t.trim().length>0&&n.length>0){let r=process.env.ALLSCALE_SIGNING_KEY_ID?.trim();return[{base:n,key:t,keyId:r&&r.length>0?r:"cli-1"}]}return[]}var nt="drop `--headless` and use the browser-bridge flow with an agent-key session.",rt="allscale device-login";var sn="device-login";function me(e){return"allscale otp-login --profile "+(e??"<profile>")+" --email <you@example.com> --scopes <scope> --otp-stdin"}function ot(e,t="default"){return t==="headless"?`No tokens stored for profile '${e}'. Headless signing needs the user token of a legacy JWT session, which agent keys do not carry \u2014 `+nt:`No tokens stored for profile '${e}'. Run \`allscale device-login --profile <profile>\` with the same profile (recommended), use \`${me()}\` for headless automation`+"."}function st(e,t){let n=t.length>0?`Saved profiles: ${t.join(", ")}.`:"No profiles are saved on this machine yet.";return`Unknown profile '${e}' \u2014 no such profile is saved on this machine. ${n} Check the spelling first; to deliberately create '${e}', run \`allscale ${sn} --profile ${e}\`.`}var an={"input.invalid":2,"storage.unavailable":2,"transport.network":3,"transport.timeout":3,"transport.response_too_large":2,"auth.no_token":4,"auth.unknown_profile":2,"auth.token_expired":5,"auth.credential_changed":3,"auth.permission_denied":6,"auth.signature_rejected":11,"claim.not_claimable":12,"claim.expired":12,"claim.payout_ambiguous":9,"claim_link.funding_ambiguous":9,"claim_link.intent_conflict":2,"claim_link.browser_cancelled":12,"user.cancelled":12,"signing.key_unavailable":2,not_found:7,rate_limited:8,"backend.internal":9,"wallet.requires_browser_auth":6,"wallet.bridge_timeout":3,"wallet.bridge_invalid_response":9,"wallet.headless_not_supported":6,"wallet.headless_setup_required":6,"wallet.headless_config_missing":6,"wallet.headless_sign_failed":9,"raw.disabled":10,internal:1},ln=new RegExp(["\\u001b\\[[0-9;:<=>?]*[ -/]*[@-~]","\\u009b[0-9;:<=>?]*[ -/]*[@-~]","\\u001b\\][^\\u0007\\u001b\\u009c]*(?:\\u0007|\\u001b\\\\|\\u009c)","\\u009d[^\\u0007\\u001b\\u009c]*(?:\\u0007|\\u001b\\\\|\\u009c)","\\u001b[ -/]+[0-~]","\\u001b[0-Z\\x5c-~]","\\u001b\\[[0-9;:<=>?]*[ -/]*","\\u009b[0-9;:<=>?]*[ -/]*","[\\u0007\\u001b\\u0090\\u0098\\u009b\\u009c\\u009d\\u009e\\u009f]"].join("|"),"g");function _e(e){return(typeof e=="string"?e:String(e??"")).replace(ln,"")}var cn=64;function ge(e,t=new Map,n=0){if(typeof e=="string")return _e(e);if(e===null||typeof e!="object")return e;let r=t.get(e);if(r!==void 0)return r;if(n>=cn)return e;if(Array.isArray(e)){let a=[];t.set(e,a);for(let l of e)a.push(ge(l,t,n+1));return a}let i=Object.getPrototypeOf(e);if(i!==Object.prototype&&i!==null)return e;let o={};t.set(e,o);for(let[a,l]of Object.entries(e))Object.defineProperty(o,a,{value:ge(l,t,n+1),writable:!0,enumerable:!0,configurable:!0});return o}var c=class extends Error{code;details;constructor(t,n,r){super(_e(n)),this.code=t,this.details=r&&ge(r),this.name="AllscaleError"}get exitCode(){return an[this.code]}toJSON(){return{error:{code:this.code,message:this.message,...this.details?{details:this.details}:{}}}}};function at(e){if(e instanceof c)return e;if(e instanceof Error){if(fn(e)){let t=gn(e),n={};return e.name&&e.name!=="Error"&&(n.name=e.name),Object.keys(t).length>0&&(n.oclif=t),new c("input.invalid",e.message,Object.keys(n).length>0?n:void 0)}return new c("internal",e.message,{name:e.name})}return new c("internal","Unknown error",{value:String(e)})}var un=new Set(["CLIError","CLIParseError","RequiredArgsError","RequiredFlagError","UnexpectedArgsError","FlagInvalidOptionError","ArgInvalidOptionError","InvalidArgsSpecError"]),dn=[/^Missing \d+ required arg/i,/^Missing required flag/i,/^Unexpected argument/i,/^Nonexistent flag/i,/^Unexpected arguments?/i,/^Failed parsing/i,/^Parsing --[A-Za-z0-9][A-Za-z0-9-]*(?:\s|$)/i,/^Expected (?:--|-).*/i,/^Flag --[A-Za-z0-9][A-Za-z0-9-]* can only be specified once\.?$/i,/^Flag --[A-Za-z0-9][A-Za-z0-9-]* expects a value$/i,/^Flag --[A-Za-z0-9][A-Za-z0-9-]* expects one of these values: /i,/to be one of: /];function fn(e){if(pn(e))return!0;let t=e.name??"";return un.has(t)?t==="CLIError"?he(e,"parse")||it(e.message):!0:it(e.message)}function pn(e){if(!he(e,"oclif"))return!1;let t=e.oclif;return typeof t=="object"&&t!==null&&t.exit===2&&he(e,"parse")}function it(e){return e?_e(e).split(`
2
- `).some(t=>dn.some(n=>n.test(t.trim()))):!1}function he(e,t){return typeof e=="object"&&e!==null&&Object.prototype.hasOwnProperty.call(e,t)}function gn(e){let t=e,n={};for(let r of["code","exitCode","suggestions","ref"])t[r]!==void 0&&(n[r]=t[r]);return n}function lt(e){process.stdout.write(`${JSON.stringify({data:e},null,2)}
3
- `)}var f=E(require("fs")),X=E(require("path")),ht=E(require("crypto"));var hn="...<truncated>",mn=/\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]+/g,_n=/\bBearer\s+[A-Za-z0-9._~+/=-]{12,}/gi,be=String.raw`(?:(?:Bearer|Basic)\s+)?(?:"(?:\\.|[^"\\\r\n])*"|'(?:\\.|[^'\\\r\n])*'|[^\s,;)}\]]+)`,ye=String.raw`(?:proxy[_-]?)?authorization`,yn=new RegExp(String.raw`(^|[^A-Za-z0-9])((?:"${ye}"|'${ye}'|${ye})\s*[:=]\s*)((?:Bearer|Basic)\s+)?(?!<redacted(?:-jwt)?>)${be}`,"gi"),Sn=/\b(https?:\/\/)[^\s/?#]+@/gi,Se=String.raw`(?:password|passwd|passphrase|otp(?:[_-]?code)?|signature|hmac|sig|session[_-]?id|mnemonic|seed|cookie|bearer|(?:[A-Za-z0-9]+[_-])*(?:token|secret)|(?:api|access|private|signing)[_-]?key|credential|claim[_-]?url)`,En=new RegExp(String.raw`(^|[^A-Za-z0-9])((?:"${Se}"|'${Se}'|${Se})\s*[:=]\s*)(?!<redacted(?:-jwt)?>)${be}`,"gi"),Ee=String.raw`(?:[A-Za-z0-9]+(?:Token|Secret)|[Oo][Tt][Pp]Code|[Ss]essionId|(?:api|API|access|Access|private|Private|signing|Signing)Key|[Cc]laimUrl)`,An=new RegExp(String.raw`(^|[^A-Za-z0-9])((?:"${Ee}"|'${Ee}'|${Ee})\s*[:=]\s*)(?!<redacted(?:-jwt)?>)${be}`,"g");function ct(e){return e.replace(Sn,"$1<redacted>@").replace(mn,"<redacted-jwt>").replace(yn,"$1$2$3<redacted>").replace(En,"$1$2<redacted>").replace(An,"$1$2<redacted>").replace(_n,"Bearer <redacted>")}function ut(e){let t="";for(let n of e){let r=n.codePointAt(0),i=r<=8||r>=11&&r<=12||r>=14&&r<=31||r>=127&&r<=159;t+=i?`\\u${r.toString(16).padStart(4,"0")}`:n}return t}function dt(e,t,n=hn){if(t<=0)return"";if(Buffer.byteLength(e,"utf8")<=t)return e;let r=Buffer.byteLength(n,"utf8");if(r>=t){let l="",u=0;for(let d of n){let h=Buffer.byteLength(d,"utf8");if(u+h>t)break;l+=d,u+=h}return l}let i=t-r,o="",a=0;for(let l of e){let u=Buffer.byteLength(l,"utf8");if(a+u>i)break;o+=l,a+=u}return`${o}${n}`}function _(e,t=16384){return dt(ut(ct(e)),t)}var Ae=100,wn=8,bn=8*1024;function q(){return{remaining:bn}}function we(e,t){let n=Math.min(16384,t.remaining),r=dt(e,n);return t.remaining-=Buffer.byteLength(r,"utf8"),r}function N(e,t,n=0,r={}){if(n>wn)return we("<truncated>",t);if(typeof e=="string"){let i=ct(e);return we(r.escapeControls?ut(i):i,t)}if(Array.isArray(e)){let i=e.slice(0,Ae),o=i.map(a=>N(a,t,n+1,r));return e.length>i.length&&o.push(we(`<${e.length-i.length} more items truncated>`,t)),o}if(e!==null&&typeof e=="object"){let i=Object.create(null),o=Object.entries(e);for(let[a,l]of o.slice(0,Ae))i[a]=N(l,t,n+1,r);return o.length>Ae&&(i.output_truncated=!0),i}return e}var Le=require("process");var ke=!1;function Te(e){ke=e}function pt(){return ke}var ft="1";function R(e,t){if(ke){let n={...e};delete n.version;let r=q(),i={event:n.event,...n},o=N(i,r,0,{escapeControls:!0}),a=JSON.stringify({version:ft,...o});Buffer.byteLength(a,"utf8")+1>65536&&(a=JSON.stringify({version:ft,event:o.event,output_truncated:!0})),Le.stderr.write(`${a}
4
- `)}else Le.stderr.write(t)}var gt="2",x=null,y=null,v=!1;function Ln(){let e=process.env.ALLSCALE_OUTPUT_FILE_PATH;if(e)return e;let t=process.env.ALLSCALE_OUTPUT_FILE_DIRECTORY;if(t){let n=new Date().toISOString().replace(/[:.]/g,"-"),r=ht.randomBytes(4).toString("hex");return X.join(t,`allscale-output-${n}-${r}.ndjson`)}return null}var Oe=64*1024*1024,kn=null;function mt(){if(v)return;let e=Ln();if(!e)return;x=null;let t=null;try{if((kn??process.platform)==="win32")throw new Error("owner-only sidecar ACLs cannot be enforced on Windows; sidecar output is disabled");let n=X.dirname(e);if(f.mkdirSync(n,{recursive:!0,mode:448}),!process.env.ALLSCALE_OUTPUT_FILE_PATH&&process.env.ALLSCALE_OUTPUT_FILE_DIRECTORY){let l=f.statSync(n),u=l.mode&511;if(!l.isDirectory()||(u&63)!==0)throw new Error(`output directory must be owner-only (no group/other permissions); current mode is ${u.toString(8).padStart(3,"0")}`)}let r=f.constants.O_NOFOLLOW??0;t=f.openSync(e,f.constants.O_APPEND|f.constants.O_CREAT|f.constants.O_WRONLY|(f.constants.O_NONBLOCK??0)|r,384);let i=f.fstatSync(t),o=f.lstatSync(e);if(!i.isFile()||o.isSymbolicLink()||o.dev!==i.dev||o.ino!==i.ino)throw new Error("target changed while it was being opened or is not a regular file");if(typeof process.geteuid=="function"&&i.uid!==process.geteuid())throw new Error("existing sidecar file is not owned by the current effective user");let a=i.mode&511;if((a&63)!==0)throw new Error(`existing sidecar file must already be owner-only; current mode is ${a.toString(8).padStart(3,"0")}. Rotate or remove it before retrying`);f.fchmodSync(t,384)}catch(n){if(t!==null)try{f.closeSync(t)}catch{}R({event:"sidecar_disabled",reason:"open_failed",detail:_(`sidecar path '${e}' could not be opened safely (${n.message})`)},`${_(`[allscale] sidecar path '${e}' could not be opened safely (${n.message}); refusing to write. Sidecar disabled for this run.`)}
5
- `);return}x=e,y=t,v=!0}var Tn=[/password/i,/secret/i,/token/i,/api[_-]?key/i,/signing[_-]?key/i,/private[_-]?key/i,/credential/i,/otp/i,/signature/i,/(?:^|[_-])sig(?:[_-]|$)/i,/hmac/i,/session[_-]?id/i,/nonce/i,/bearer/i,/authorization/i,/^code$/i,/^auth$/i,/^state$/i];function On(e){let t=e.replace(/([a-z0-9])([A-Z])/g,"$1_$2").replace(/([A-Z]+)([A-Z][a-z])/g,"$1_$2");return Tn.some(n=>n.test(t))}function In(e){try{let t=new URL(e),n=t.username.length>0||t.password.length>0;n&&(t.username="",t.password="");let r=t.pathname;t.pathname=Cn(t.pathname);let i=n;t.pathname!==r&&(i=!0);for(let[o]of t.searchParams)On(o)&&(t.searchParams.set(o,"<redacted>"),i=!0);return i?t.toString():e}catch{return e}}function Cn(e){return e.replace(/(\/(?:api\/)?(?:v1\/)?public\/claim-links\/)([^/:]+)(:claim)?(?=\/?$)/,"$1<redacted>$3").replace(/(\/(?:api\/)?public\/claim-links\/)([^/]+)(\/claim)(?=\/?$)/,"$1<redacted>$3")}function Nn(e){return(e.type==="request"||e.type==="bridge_browser_open")&&typeof e.url=="string"?{...e,url:In(e.url)}:e}function Pn(e){let t=new Date().toISOString(),n=e,{type:r,...i}=n,o=N(i,q()),a=JSON.stringify({version:gt,timestamp:t,type:r,...o});return Buffer.byteLength(a,"utf8")+1>65536&&(a=JSON.stringify({version:gt,timestamp:t,type:r,output_truncated:!0})),a}function G(e){if(!v||!x||y===null)return;let t=Nn(e),n=Pn(t);try{if(f.fstatSync(y).size+Buffer.byteLength(n,"utf8")+1>Oe){v=!1;try{f.closeSync(y)}catch{}y=null,R({event:"sidecar_disabled",reason:"size_limit",...x===null?{}:{path:_(x)},max_bytes:Oe},`${_(`[allscale] sidecar exceeded ${Oe} bytes; disabling it for the rest of this run. Rotate or remove ${x}, or point ALLSCALE_OUTPUT_FILE_DIRECTORY at a directory so each run gets its own file.`)}
1
+ "use strict";var tn=Object.create;var V=Object.defineProperty;var nn=Object.getOwnPropertyDescriptor;var rn=Object.getOwnPropertyNames;var on=Object.getPrototypeOf,sn=Object.prototype.hasOwnProperty;var an=(e,t)=>{for(var n in t)V(e,n,{get:t[n],enumerable:!0})},Ze=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of rn(t))!sn.call(e,i)&&i!==n&&V(e,i,{get:()=>t[i],enumerable:!(r=nn(t,i))||r.enumerable});return e};var A=(e,t,n)=>(n=e!=null?tn(on(e)):{},Ze(t||!e||!e.__esModule?V(n,"default",{value:e,enumerable:!0}):n,e)),ln=e=>Ze(V({},"__esModule",{value:!0}),e);var kr={};an(kr,{default:()=>de});module.exports=ln(kr);var w=require("@oclif/core");var Ve="public",Qe="https://app.allscale.io";var et=["https://app.allscale.io"];var pe="Override the API base URL (public builds accept only https://app.allscale.io)";var ge="Only https://app.allscale.io is allowed, and URL userinfo is forbidden.";function tt(e){try{let t=new URL(e);return t.username.length>0||t.password.length>0?null:t.protocol==="https:"?t:null}catch{return null}}function nt(e){return tt(e)!==null}function he(e){let t=tt(e);return t!==null&&et.includes(t.origin)}function M(){return"".trim()||void 0}function G(){return"public"}function rt(e){try{let{hostname:t}=new URL(e);return t==="127.0.0.1"||t==="localhost"||t==="[::1]"}catch{return!1}}function it(){{let e="[]".trim();if(e.length===0)return[];try{let t=JSON.parse(e);return Array.isArray(t)?t:[]}catch{return[]}}return me()}function me(){let e=process.env.ALLSCALE_BUILD_PAIRS?.trim()??"";if(e.length>0)try{let r=JSON.parse(e);if(!Array.isArray(r))return[];let i=[];for(let o of r){if(typeof o!="object"||o===null)continue;let{base:a,key:l,keyId:u}=o;if(typeof a!="string"||a.trim().length===0||typeof l!="string"||l.trim().length===0)continue;let d=typeof u=="string"?u.trim():"";i.push({base:a.trim(),key:l,keyId:d.length>0?d:"cli-1"})}return i}catch{return[]}let t=process.env.ALLSCALE_SIGNING_KEY??"",n=process.env.ALLSCALE_BUILD_API_BASE?.trim()??"";if(t.trim().length>0&&n.length>0){let r=process.env.ALLSCALE_SIGNING_KEY_ID?.trim();return[{base:n,key:t,keyId:r&&r.length>0?r:"cli-1"}]}return[]}var cn="device-login",un=/^[A-Za-z0-9._-]{1,64}$/;function Y(e){return un.test(e)?e:"<profile>"}function Se(e){return"allscale otp-login --profile "+(e===void 0?"<profile>":Y(e))+" --email <you@example.com> --scopes <scope> --otp-stdin"}function st(e){let t=Y(e);return`No tokens stored for profile '${e}'. Run \`allscale device-login --profile ${t}\` (recommended), or use \`${Se(e)}\` for headless automation.`}function at(e){return`Unknown profile '${e}' \u2014 no such profile is saved on this machine. Check the spelling first; to deliberately create '${e}', run \`allscale ${cn} --profile ${Y(e)}\`.`}var dn={"input.invalid":2,"storage.unavailable":2,"transport.network":3,"transport.timeout":3,"transport.response_too_large":2,"auth.no_token":4,"auth.unknown_profile":2,"auth.token_expired":5,"auth.credential_changed":3,"auth.permission_denied":6,"auth.signature_rejected":11,"claim.not_claimable":12,"claim.expired":12,"claim.payout_ambiguous":9,"claim_link.funding_ambiguous":9,"claim_link.intent_conflict":2,"claim_link.browser_cancelled":12,"user.cancelled":12,"signing.key_unavailable":2,not_found:7,rate_limited:8,"backend.internal":9,"wallet.requires_browser_auth":6,"wallet.bridge_timeout":3,"wallet.bridge_op_expired":3,"wallet.bridge_invalid_response":9,"wallet.transaction_reverted":12,"wallet.transaction_status_unknown":9,"raw.disabled":10,internal:1},fn=new RegExp(["\\u001b\\[[0-9;:<=>?]*[ -/]*[@-~]","\\u009b[0-9;:<=>?]*[ -/]*[@-~]","\\u001b\\][^\\u0007\\u001b\\u009c]*(?:\\u0007|\\u001b\\\\|\\u009c)","\\u009d[^\\u0007\\u001b\\u009c]*(?:\\u0007|\\u001b\\\\|\\u009c)","\\u001b[ -/]+[0-~]","\\u001b[0-Z\\x5c-~]","\\u001b\\[[0-9;:<=>?]*[ -/]*","\\u009b[0-9;:<=>?]*[ -/]*","[\\u0007\\u001b\\u0090\\u0098\\u009b\\u009c\\u009d\\u009e\\u009f]"].join("|"),"g");function Ae(e){return(typeof e=="string"?e:String(e??"")).replace(fn,"")}var pn=64;function _e(e,t=new Map,n=0){if(typeof e=="string")return Ae(e);if(e===null||typeof e!="object")return e;let r=t.get(e);if(r!==void 0)return r;if(n>=pn)return e;if(Array.isArray(e)){let a=[];t.set(e,a);for(let l of e)a.push(_e(l,t,n+1));return a}let i=Object.getPrototypeOf(e);if(i!==Object.prototype&&i!==null)return e;let o={};t.set(e,o);for(let[a,l]of Object.entries(e))Object.defineProperty(o,a,{value:_e(l,t,n+1),writable:!0,enumerable:!0,configurable:!0});return o}var c=class extends Error{code;details;constructor(t,n,r){super(Ae(n)),this.code=t,this.details=r&&_e(r),this.name="AllscaleError"}get exitCode(){return dn[this.code]}toJSON(){return{error:{code:this.code,message:this.message,...this.details?{details:this.details}:{}}}}};function lt(e){if(e instanceof c)return e;if(e instanceof Error){if(mn(e)){let t=yn(e),n={};return e.name&&e.name!=="Error"&&(n.name=e.name),Object.keys(t).length>0&&(n.oclif=t),new c("input.invalid",e.message,Object.keys(n).length>0?n:void 0)}return new c("internal",e.message,{name:e.name})}return new c("internal","Unknown error",{value:String(e)})}var gn=new Set(["CLIError","CLIParseError","RequiredArgsError","RequiredFlagError","UnexpectedArgsError","FlagInvalidOptionError","ArgInvalidOptionError","InvalidArgsSpecError"]),hn=[/^Missing \d+ required arg/i,/^Missing required flag/i,/^Unexpected argument/i,/^Nonexistent flag/i,/^Unexpected arguments?/i,/^Failed parsing/i,/^Parsing --[A-Za-z0-9][A-Za-z0-9-]*(?:\s|$)/i,/^Expected (?:--|-).*/i,/^Flag --[A-Za-z0-9][A-Za-z0-9-]* can only be specified once\.?$/i,/^Flag --[A-Za-z0-9][A-Za-z0-9-]* expects a value$/i,/^Flag --[A-Za-z0-9][A-Za-z0-9-]* expects one of these values: /i,/to be one of: /];function mn(e){if(_n(e))return!0;let t=e.name??"";return gn.has(t)?t==="CLIError"?ye(e,"parse")||ot(e.message):!0:ot(e.message)}function _n(e){if(!ye(e,"oclif"))return!1;let t=e.oclif;return typeof t=="object"&&t!==null&&t.exit===2&&ye(e,"parse")}function ot(e){return e?Ae(e).split(`
2
+ `).some(t=>hn.some(n=>n.test(t.trim()))):!1}function ye(e,t){return typeof e=="object"&&e!==null&&Object.prototype.hasOwnProperty.call(e,t)}function yn(e){let t=e,n={};for(let r of["code","exitCode","suggestions","ref"])t[r]!==void 0&&(n[r]=t[r]);return n}function ct(e){process.stdout.write(`${JSON.stringify({data:e},null,2)}
3
+ `)}var f=A(require("fs")),ee=A(require("path")),St=A(require("crypto"));var Sn="...<truncated>",An=/\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]+/g,En=/\bBearer\s+[A-Za-z0-9._~+/=-]{12,}/gi,Te=String.raw`(?:(?:Bearer|Basic)\s+)?(?:"(?:\\.|[^"\\\r\n])*"|'(?:\\.|[^'\\\r\n])*'|[^\s,;)}\]]+)`,Ee=String.raw`(?:proxy[_-]?)?authorization`,wn=new RegExp(String.raw`(^|[^A-Za-z0-9])((?:"${Ee}"|'${Ee}'|${Ee})\s*[:=]\s*)((?:Bearer|Basic)\s+)?(?!<redacted(?:-jwt)?>)${Te}`,"gi"),bn=/\b(https?:\/\/)[^\s/?#]+@/gi,Ln=String.raw`(?:[A-Za-z0-9]+[_-])*`,Tn=String.raw`(?:[A-Za-z0-9]{1,32}[_-]){0,8}`,dt=e=>String.raw`(?:password|passwd|passphrase|otp(?:[_-]?code)?|signature|hmac|sig|session[_-]?id|mnemonic|seed|cookie|bearer|${e}(?:token|secret)|(?:api|access|private|signing)[_-]?key|credential|claim[_-]?url)`,ut=dt(Ln),kn=dt(Tn),On=new RegExp(String.raw`(^|[^A-Za-z0-9])((?:"${ut}"|'${ut}'|${kn})\s*[:=]\s*)(?!<redacted(?:-jwt)?>)${Te}`,"gi"),we=String.raw`(?:[A-Za-z0-9]+(?:Token|Secret)|[Oo][Tt][Pp]Code|[Ss]essionId|(?:api|API|access|Access|private|Private|signing|Signing)Key|[Cc]laimUrl)`,In=new RegExp(String.raw`(^|[^A-Za-z0-9])((?:"${we}"|'${we}'|${we})\s*[:=]\s*)(?!<redacted(?:-jwt)?>)${Te}`,"g");function ft(e){return e.replace(bn,"$1<redacted>@").replace(An,"<redacted-jwt>").replace(wn,"$1$2$3<redacted>").replace(On,"$1$2<redacted>").replace(In,"$1$2<redacted>").replace(En,"Bearer <redacted>")}var Cn=/(token|secret|password|passwd|passphrase|cookie|authorization|bearer|credential|mnemonic|seed|api[_-]?key|apikey|private[_-]?key|privkey|otp|signature|hmac|(?:^|[_-])sig(?:[_-]|$)|session[_-]?id|^input$)/i;function pt(e){let t=e.replace(/([a-z0-9])([A-Z])/g,"$1_$2").replace(/([A-Z]+)([A-Z][a-z])/g,"$1_$2");return Cn.test(t)}function gt(e){let t="";for(let n of e){let r=n.codePointAt(0),i=r<=8||r>=11&&r<=12||r>=14&&r<=31||r>=127&&r<=159;t+=i?`\\u${r.toString(16).padStart(4,"0")}`:n}return t}function ht(e,t,n=Sn){if(t<=0)return"";if(Buffer.byteLength(e,"utf8")<=t)return e;let r=Buffer.byteLength(n,"utf8");if(r>=t){let l="",u=0;for(let d of n){let m=Buffer.byteLength(d,"utf8");if(u+m>t)break;l+=d,u+=m}return l}let i=t-r,o="",a=0;for(let l of e){let u=Buffer.byteLength(l,"utf8");if(a+u>i)break;o+=l,a+=u}return`${o}${n}`}function h(e,t=16384){return ht(gt(ft(e)),t)}var be=100,Pn=8,Rn=8*1024;function Q(){return{remaining:Rn}}function Le(e,t){let n=Math.min(16384,t.remaining),r=ht(e,n);return t.remaining-=Buffer.byteLength(r,"utf8"),r}function R(e,t,n=0,r={}){if(n>Pn)return Le("<truncated>",t);if(typeof e=="string"){let i=ft(e);return Le(r.escapeControls?gt(i):i,t)}if(Array.isArray(e)){let i=e.slice(0,be),o=i.map(a=>R(a,t,n+1,r));return e.length>i.length&&o.push(Le(`<${e.length-i.length} more items truncated>`,t)),o}if(e!==null&&typeof e=="object"){let i=Object.create(null),o=Object.entries(e);for(let[a,l]of o.slice(0,be))i[a]=R(l,t,n+1,r);return o.length>be&&(i.output_truncated=!0),i}return e}var ke=require("process");var Oe=!1;function Ie(e){Oe=e}function _t(){return Oe}var mt="1";function x(e,t){if(Oe){let n={...e};delete n.version;let r=Q(),i={event:n.event,...n},o=R(i,r,0,{escapeControls:!0}),a=JSON.stringify({version:mt,...o});Buffer.byteLength(a,"utf8")+1>65536&&(a=JSON.stringify({version:mt,event:o.event,output_truncated:!0})),ke.stderr.write(`${a}
4
+ `)}else ke.stderr.write(t)}var yt="2",N=null,y=null,B=!1,K=!1;function vn(){let e=process.env.ALLSCALE_OUTPUT_FILE_PATH;if(e)return e;let t=process.env.ALLSCALE_OUTPUT_FILE_DIRECTORY;if(t){let n=new Date().toISOString().replace(/[:.]/g,"-"),r=St.randomBytes(4).toString("hex");return ee.join(t,`allscale-output-${n}-${r}.ndjson`)}return null}var Ce=64*1024*1024,xn=null;function Pe(e={}){if(e.quiet&&(K=!0),B)return;let t=vn();if(!t)return;N=null;let n=null;try{if((xn??process.platform)==="win32")throw new Error("owner-only sidecar ACLs cannot be enforced on Windows; sidecar output is disabled");let r=ee.dirname(t);if(f.mkdirSync(r,{recursive:!0,mode:448}),!process.env.ALLSCALE_OUTPUT_FILE_PATH&&process.env.ALLSCALE_OUTPUT_FILE_DIRECTORY){let u=f.statSync(r),d=u.mode&511;if(!u.isDirectory()||(d&63)!==0)throw new Error(`output directory must be owner-only (no group/other permissions); current mode is ${d.toString(8).padStart(3,"0")}`)}let i=f.constants.O_NOFOLLOW??0;n=f.openSync(t,f.constants.O_APPEND|f.constants.O_CREAT|f.constants.O_WRONLY|(f.constants.O_NONBLOCK??0)|i,384);let o=f.fstatSync(n),a=f.lstatSync(t);if(!o.isFile()||a.isSymbolicLink()||a.dev!==o.dev||a.ino!==o.ino)throw new Error("target changed while it was being opened or is not a regular file");if(typeof process.geteuid=="function"&&o.uid!==process.geteuid())throw new Error("existing sidecar file is not owned by the current effective user");let l=o.mode&511;if((l&63)!==0)throw new Error(`existing sidecar file must already be owner-only; current mode is ${l.toString(8).padStart(3,"0")}. Rotate or remove it before retrying`);f.fchmodSync(n,384)}catch(r){if(n!==null)try{f.closeSync(n)}catch{}K||x({event:"sidecar_disabled",reason:"open_failed",detail:h(`sidecar path '${t}' could not be opened safely (${r.message})`)},`${h(`[allscale] sidecar path '${t}' could not be opened safely (${r.message}); refusing to write. Sidecar disabled for this run.`)}
5
+ `);return}N=t,y=n,B=!0}var Nn=[/password/i,/secret/i,/token/i,/api[_-]?key/i,/signing[_-]?key/i,/private[_-]?key/i,/credential/i,/otp/i,/signature/i,/(?:^|[_-])sig(?:[_-]|$)/i,/hmac/i,/session[_-]?id/i,/nonce/i,/bearer/i,/authorization/i,/^code$/i,/^auth$/i,/^state$/i];function Bn(e){let t=e.replace(/([a-z0-9])([A-Z])/g,"$1_$2").replace(/([A-Z]+)([A-Z][a-z])/g,"$1_$2");return Nn.some(n=>n.test(t))}function Un(e){try{let t=new URL(e),n=t.username.length>0||t.password.length>0;n&&(t.username="",t.password="");let r=t.pathname;t.pathname=Dn(t.pathname);let i=n;t.pathname!==r&&(i=!0);for(let[o]of t.searchParams)Bn(o)&&(t.searchParams.set(o,"<redacted>"),i=!0);return i?t.toString():e}catch{return e}}function Dn(e){return e.replace(/(\/(?:api\/)?(?:v1\/)?public\/claim-links\/)([^/:]+)(:claim)?(?=\/?$)/,"$1<redacted>$3").replace(/(\/(?:api\/)?public\/claim-links\/)([^/]+)(\/claim)(?=\/?$)/,"$1<redacted>$3")}function Fn(e){return(e.type==="request"||e.type==="bridge_browser_open")&&typeof e.url=="string"?{...e,url:Un(e.url)}:e}function $n(e){let t=new Date().toISOString(),n=e,{type:r,...i}=n,o=R(i,Q()),a=JSON.stringify({version:yt,timestamp:t,type:r,...o});return Buffer.byteLength(a,"utf8")+1>65536&&(a=JSON.stringify({version:yt,timestamp:t,type:r,output_truncated:!0})),a}function U(e){if(!B||!N||y===null)return;let t=Fn(e),n=$n(t);try{if(f.fstatSync(y).size+Buffer.byteLength(n,"utf8")+1>Ce){B=!1;try{f.closeSync(y)}catch{}y=null,K||x({event:"sidecar_disabled",reason:"size_limit",...N===null?{}:{path:h(N)},max_bytes:Ce},`${h(`[allscale] sidecar exceeded ${Ce} bytes; disabling it for the rest of this run. Rotate or remove ${N}, or point ALLSCALE_OUTPUT_FILE_DIRECTORY at a directory so each run gets its own file.`)}
6
6
  `);return}f.appendFileSync(y,`${n}
7
- `)}catch(r){if(v=!1,y!==null){try{f.closeSync(y)}catch{}y=null}try{R({event:"sidecar_disabled",reason:"write_failed",detail:_(r.message)},`${_(`[allscale] sidecar write failed (${r.message}); disabling sidecar for the rest of this run.`)}
8
- `)}catch{}}}function _t(){return!!(process.env.ALLSCALE_OUTPUT_FILE_PATH||process.env.ALLSCALE_OUTPUT_FILE_DIRECTORY)}function V(){if(v=!1,y!==null){try{f.closeSync(y)}catch{}y=null}}function yt(e=!1){let t=process.stdin.isTTY===!0&&process.stdout.isTTY===!0;return e||_t()||!t}var Y=$()??Xe,U={TOKEN:"ALLSCALE_TOKEN",PROFILE:"ALLSCALE_PROFILE",API_BASE:"ALLSCALE_API_BASE",PAYOUT_API_BASE:"ALLSCALE_PAYOUT_API_BASE",PRETTY:"ALLSCALE_PRETTY",LOG_LEVEL:"ALLSCALE_LOG_LEVEL",INSECURE_STORAGE:"ALLSCALE_INSECURE_STORAGE",NO_KEYCHAIN:"ALLSCALE_NO_KEYCHAIN",ALLOW_RAW:"ALLSCALE_ALLOW_RAW",OUTPUT_FILE_PATH:"ALLSCALE_OUTPUT_FILE_PATH",OUTPUT_FILE_DIRECTORY:"ALLSCALE_OUTPUT_FILE_DIRECTORY",STORE_API_KEY:"ALLSCALE_STORE_API_KEY",STORE_API_SECRET:"ALLSCALE_STORE_API_SECRET"};function Z(e){return Qe(e)?new URL(e).origin:null}function D(e){try{let t=new URL(e);return`${t.protocol}//${t.host}`}catch{return"<unparseable URL>"}}function Ie(e){try{let t=new URL(e);return t.username.length===0&&t.password.length===0&&t.search.length===0&&t.hash.length===0?e:(t.username="",t.password="",t.search="",t.hash="",`${t.origin}${t.pathname}`)}catch{return"<unparseable URL>"}}function St(){let e=process.env[U.TOKEN]?.trim();return e&&e.length>0?e:void 0}function Ce(){let e=process.env[U.PROFILE]?.trim();return e&&e.length>0?e:void 0}function Q(){let e=process.env[U.API_BASE]?.trim();return e&&e.length>0?e:void 0}function Et(){let e=process.env[U.INSECURE_STORAGE]?.trim().toLowerCase();return e==="1"||e==="true"||e==="yes"}function At(){let e=process.env[U.NO_KEYCHAIN]?.trim().toLowerCase();return e==="1"||e==="true"||e==="yes"}function wt(){let e=process.env[U.ALLOW_RAW]?.trim().toLowerCase();return e==="1"||e==="true"||e==="yes"}function bt(e){let{resolvedApiBase:t,fromExplicitOverride:n,profileApiBase:r,profileApiBaseSource:i}=e;if($()===void 0&&Y!==""&&"".length!==0&&!n&&i!=="explicit"&&r===""&&t==="")return`Notice: this profile is pinned to ${""} (staging) in ~/.allscale/config.toml.
9
- The CLI default is now ${Y} (production), but a saved profile wins over the default,
7
+ `)}catch(r){if(B=!1,y!==null){try{f.closeSync(y)}catch{}y=null}try{K||x({event:"sidecar_disabled",reason:"write_failed",detail:h(r.message)},`${h(`[allscale] sidecar write failed (${r.message}); disabling sidecar for the rest of this run.`)}
8
+ `)}catch{}}}function At(){return!!(process.env.ALLSCALE_OUTPUT_FILE_PATH||process.env.ALLSCALE_OUTPUT_FILE_DIRECTORY)}function j(){if(K=!1,B=!1,y!==null){try{f.closeSync(y)}catch{}y=null}}function Et(e=!1){let t=process.stdin.isTTY===!0&&process.stdout.isTTY===!0;return e||At()||!t}var W=new Set(["--password","-p","--token","-t","--otp","--otp-id","--api-base","--payout-api-base","--browser-base","--input","-i","--claim-token","--claim-url","--api-key","--api-secret"]),Mn=new Set(Array.from(W).filter(e=>e.startsWith("-")&&!e.startsWith("--")&&e.length===2)),Gn=Array.from(W).filter(e=>e.startsWith("--")).sort((e,t)=>t.length-e.length),Yn=new Set(["--otp-stdin","--password-stdin"]);function Re(e){let t=[];for(let n=0;n<e.length;n+=1){let r=e[n];if(r.startsWith("-")){let o=r.indexOf("=");if(o!==-1){let a=r.slice(0,o);if(W.has(a)){t.push(`${a}=<redacted>`);continue}}}if(W.has(r)){t.push(r),n+1<e.length&&(W.has(e[n+1])||(t.push("<redacted>"),n+=1));continue}if(r.startsWith("-")&&!r.startsWith("--")&&r.length>2&&r[1]!=="="){let o=r.slice(0,2);if(Mn.has(o)){t.push(`${o}<redacted>`);continue}}let i=Yn.has(r)?void 0:Gn.find(o=>r.length>o.length&&r.startsWith(o));if(i){t.push(`${i}<redacted>`);continue}t.push(r)}return t}function wt(e){U({type:"error",code:e.code,message:h(e.message)}),U({type:"command-end",ok:!1,exitCode:e.exitCode}),j()}var H=M()??Qe,F={TOKEN:"ALLSCALE_TOKEN",PROFILE:"ALLSCALE_PROFILE",API_BASE:"ALLSCALE_API_BASE",PAYOUT_API_BASE:"ALLSCALE_PAYOUT_API_BASE",PRETTY:"ALLSCALE_PRETTY",LOG_LEVEL:"ALLSCALE_LOG_LEVEL",INSECURE_STORAGE:"ALLSCALE_INSECURE_STORAGE",NO_KEYCHAIN:"ALLSCALE_NO_KEYCHAIN",ALLOW_RAW:"ALLSCALE_ALLOW_RAW",OUTPUT_FILE_PATH:"ALLSCALE_OUTPUT_FILE_PATH",OUTPUT_FILE_DIRECTORY:"ALLSCALE_OUTPUT_FILE_DIRECTORY",STORE_API_KEY:"ALLSCALE_STORE_API_KEY",STORE_API_SECRET:"ALLSCALE_STORE_API_SECRET"};function te(e){return nt(e)?new URL(e).origin:null}function $(e){try{let t=new URL(e);return`${t.protocol}//${t.host}`}catch{return"<unparseable URL>"}}function ve(e){try{let t=new URL(e);return t.username.length===0&&t.password.length===0&&t.search.length===0&&t.hash.length===0?e:(t.username="",t.password="",t.search="",t.hash="",`${t.origin}${t.pathname}`)}catch{return"<unparseable URL>"}}function bt(){let e=process.env[F.TOKEN]?.trim();return e&&e.length>0?e:void 0}function xe(){let e=process.env[F.PROFILE]?.trim();return e&&e.length>0?e:void 0}function ne(){let e=process.env[F.API_BASE]?.trim();return e&&e.length>0?e:void 0}function Lt(){let e=process.env[F.INSECURE_STORAGE]?.trim().toLowerCase();return e==="1"||e==="true"||e==="yes"}function Tt(){let e=process.env[F.NO_KEYCHAIN]?.trim().toLowerCase();return e==="1"||e==="true"||e==="yes"}function kt(){let e=process.env[F.ALLOW_RAW]?.trim().toLowerCase();return e==="1"||e==="true"||e==="yes"}function Ot(e){let{resolvedApiBase:t,fromExplicitOverride:n,profileApiBase:r,profileApiBaseSource:i}=e;if(M()===void 0&&H!==""&&"".length!==0&&!n&&i!=="explicit"&&r===""&&t==="")return`Notice: this profile is pinned to ${""} (staging) in ~/.allscale/config.toml.
9
+ The CLI default is now ${H} (production), but a saved profile wins over the default,
10
10
  so this session still uses staging. That pin was written before the default changed, so it may just be
11
11
  the old default rather than a deliberate choice.
12
- To keep staging, re-run login with --api-base ${""} (recorded as deliberate, silences this).
13
- To move to production, run: ${rt} --api-base ${Y}
14
- `}var F=E(require("fs")),Lt=E(require("os")),Ne=E(require("path")),Pe=E(require("@iarna/toml"));var vn=".allscale",Bn="config.toml";function Re(){return Ne.join(Lt.homedir(),vn)}function Un(){return Ne.join(Re(),Bn)}function ee(){let e=Un();if(!F.existsSync(e))return{};let t=F.readFileSync(e,"utf-8");try{return Pe.parse(t)}catch(n){throw new c("internal",`Failed to parse ${e}: ${n.message}`)}}function kt(e){return Object.keys(e.profile??{}).sort()}function Tt(e,t){return e.profile?.[t]}function Ot(e,t,n){let r=t??n??e.default??"default";if(r.includes(":"))throw new c("input.invalid",`Invalid profile name '${r}': ':' is reserved as the keychain namespace separator \u2014 pick a name without ':'.`);return r}function xe(e){if(!fe(e))throw new c("input.invalid",`Refusing to send credentials to API base ${D(e)}. `+de)}function It(e){let t=$();if(t===void 0||et(e))return;let n=Z(e),r=tt();if(r.length>0){let o=r.map(l=>Z(l.base)).filter(l=>l!==null);if(n!==null&&o.includes(n))return;let a=r.map(l=>D(l.base)).join(", ");throw new c("input.invalid",`Refusing to send to ${D(e)} \u2014 this build only signs for: ${a}. Re-login against one of this build's environments, or use a build that includes the one you need.`)}let i=Z(t);if(!(n!==null&&n===i))throw new c("input.invalid",`Refusing to send to ${D(e)} \u2014 this build only signs for ${D(t)}. Re-login against this build's environment, or use a build for that one.`)}var Dn=require("@noble/hashes/sha3");var Ct=["USDT","USDC"];var ri=new Set([`0x${"0".repeat(40)}`,`0x${"0".repeat(36)}dead`]);var Nt=require("@oclif/core"),K=class e extends w.Command{static enableJsonFlag=!0;static legacyStagingNoticeShown=!1;static emitsOwnOutput=!1;static requiresEscapeHatch=!1;static requiresInput=!1;static isLocalOnly=!1;static baseFlags={profile:w.Flags.string({description:"Named profile from ~/.allscale/config.toml",helpGroup:"GLOBAL"}),token:w.Flags.string({description:"Override the access token for this invocation (precedence: --token > ALLSCALE_TOKEN > --profile)",helpGroup:"GLOBAL",hidden:M()==="public"}),"api-base":w.Flags.string({description:ue,helpGroup:"GLOBAL",hidden:M()==="public"}),"insecure-storage":w.Flags.boolean({description:"Force POSIX plaintext token storage at ~/.allscale/credentials.json (mode 0600) instead of the OS keychain \u2014 for headless / CI / agent use. Unavailable on Windows because Node cannot verify owner-only ACL/link safety. Also via ALLSCALE_INSECURE_STORAGE=1.",default:!1,helpGroup:"GLOBAL"})};async run(){try{Te(this.jsonEnabled()),mt(),G({type:"session-start",command:this.id??"",argv:$n(this.argv)});let t=this.constructor;if(M()==="public"){if(this.argv.some(o=>o==="--token"||o.startsWith("--token=")))throw new c("input.invalid","--token is not supported in this build. Set the ALLSCALE_TOKEN environment variable instead (it does not leak into shell history or process listings).");if(this.argv.some(o=>o==="--api-base"||o.startsWith("--api-base=")))throw new c("input.invalid","--api-base is not supported in this build; it always talks to its bound AllScale environment.");if(!t.isLocalOnly&&Q()!==void 0)throw new c("input.invalid","ALLSCALE_API_BASE is not supported in this build; unset it \u2014 this build always talks to its bound AllScale environment.")}if(t.requiresEscapeHatch&&!wt())throw this.argv.length>0&&await this.parse(),new c("raw.disabled","This command is an opt-in escape hatch and is disabled by default. Set ALLSCALE_ALLOW_RAW=1 to enable raw GraphQL/REST passthroughs and schema introspection. The real access boundary is enforced server-side by the key's scope regardless.");let n=yt(this.jsonEnabled()),r=this.argv.length===0&&!n&&Wn(t)?this.config.findCommand(this.id??""):void 0;if(r){V();let o=await(0,w.loadHelpClass)(this.config),a=this.config.pjson.oclif?.helpOptions??this.config.pjson.helpOptions;await new o(this.config,a).showCommandHelp(r,this.config.topics);return}let i=await this.runCommand();return G({type:"command-end",ok:!0}),V(),t.emitsOwnOutput?void 0:(this.jsonEnabled()||lt(i),{data:i})}catch(t){let n=at(t);G({type:"error",code:n.code,message:_(n.message)}),G({type:"command-end",ok:!1,exitCode:n.exitCode}),V(),this.emitError(n),process.exitCode=n.exitCode;return}finally{Te(!1)}}resolveSessionApiBaseChain(t){let n=ee(),r=t.profile??void 0,i=t["api-base"]??void 0,o=r!==void 0||Ce()!==void 0,a=Ot(n,r,Ce()),l=Tt(n,a),u=i??Q(),d=u??l?.api_base??Y,h=bt({resolvedApiBase:d,fromExplicitOverride:u!==void 0,profileApiBase:l?.api_base,profileApiBaseSource:l?.api_base_source});return h&&!e.legacyStagingNoticeShown&&(e.legacyStagingNoticeShown=!0,R({event:"legacy_staging_profile",api_base:d,profile:a},h)),{apiBase:d,explicitApiBase:u,profileApiBase:l?.api_base,profile:a,profileExplicit:o}}resolveSessionApiBaseForPayoutDerivation(t){let{apiBase:n}=this.resolveSessionApiBaseChain(t);return this.constructor.isLocalOnly||xe(n),n}resolveContext(t){if(M()==="public"){if(t.token!==void 0)throw new c("input.invalid","--token is not supported in this build. Set the ALLSCALE_TOKEN environment variable instead (it does not leak into shell history or process listings).");if(t["api-base"]!==void 0)throw new c("input.invalid","--api-base is not supported in this build; it always talks to its bound AllScale environment.");if(!this.constructor.isLocalOnly&&Q()!==void 0)throw new c("input.invalid","ALLSCALE_API_BASE is not supported in this build; unset it \u2014 this build always talks to its bound AllScale environment.")}let n=t.token??void 0,r=!!t["insecure-storage"],{apiBase:i,explicitApiBase:o,profile:a,profileApiBase:l,profileExplicit:u}=this.resolveSessionApiBaseChain(t);return this.constructor.isLocalOnly||(xe(i),It(i)),{apiBase:i,profile:a,token:n??St(),insecureStorage:r||Et(),apiBaseSource:o!==void 0?"explicit":l!==void 0?"profile":"default",profileExplicit:u}}emitError(t){process.stderr.write(`${Jn(t)}
15
- `)}},ne=new Set(["--password","-p","--token","-t","--otp","--otp-id","--api-base","--payout-api-base","--browser-base","--input","-i","--claim-token","--claim-url","--api-key","--api-secret"]),Fn=new Set(Array.from(ne).filter(e=>e.startsWith("-")&&!e.startsWith("--")&&e.length===2));function $n(e){let t=[];for(let n=0;n<e.length;n+=1){let r=e[n];if(r.startsWith("-")){let i=r.indexOf("=");if(i!==-1){let o=r.slice(0,i);if(ne.has(o)){t.push(`${o}=<redacted>`);continue}}}if(ne.has(r)){t.push(r),n+1<e.length&&(ne.has(e[n+1])||(t.push("<redacted>"),n+=1));continue}if(r.startsWith("-")&&!r.startsWith("--")&&r.length>2&&r[1]!=="="){let i=r.slice(0,2);if(Fn.has(i)){t.push(`${i}<redacted>`);continue}}t.push(r)}return t}var Mn=/(token|secret|password|passwd|passphrase|cookie|authorization|bearer|credential|mnemonic|seed|api[_-]?key|apikey|private[_-]?key|privkey|otp|signature|hmac|(?:^|[_-])sig(?:[_-]|$)|session[_-]?id|^input$)/i;function Gn(e){let t=e.replace(/([a-z0-9])([A-Z])/g,"$1_$2").replace(/([A-Z]+)([A-Z][a-z])/g,"$1_$2");return Mn.test(t)}var Yn=/_(removed|cleared|count|total)$/i;function Kn(e,t){return typeof t=="number"&&Yn.test(e)}var Hn=new Set(Ct);function jn(e,t){return e==="token_symbol"&&typeof t=="string"&&Hn.has(t)}var te=100;function ve(e,t=0){if(t>8)return"<truncated>";if(Array.isArray(e)){let n=e.slice(0,te),r=n.map(i=>ve(i,t+1));return e.length>n.length&&r.push(`<${e.length-n.length} more items truncated>`),r}if(e!==null&&typeof e=="object"){let n=Object.create(null),r=Object.entries(e);for(let[i,o]of r.slice(0,te))n[i]=Gn(i)&&!Kn(i,o)&&!jn(i,o)?"<redacted>":ve(o,t+1);if(r.length>te){let i="<truncated>";for(;i in n;)i=`<${i}>`;n[i]=`${r.length-te} more keys`}return n}return typeof e=="string"?_(e):e}function Jn(e){let t=pt()?void 0:2,n=ve(e.toJSON()),r=JSON.stringify(n,null,t);return Buffer.byteLength(r,"utf8")+1<=65536?r:JSON.stringify({error:{code:e.code,message:_(e.message),details:{output_truncated:!0,max_output_bytes:65536}}},null,t)}function Wn(e){if(e.requiresInput===!0)return!0;let t=i=>typeof i=="object"&&i!==null&&i.required===!0,n=e.flags??{},r=e.args??{};return Object.values(n).some(i=>t(i))||Object.values(r).some(i=>t(i))}function zn(e,t={}){let n;try{n=kt(ee())}catch{return}if(!(n.length===0||n.includes(e)))return new c("auth.unknown_profile",st(e,n)+(t.messageSuffix??""),{profile:e,known_profiles:n})}function Pt(e){if(e.profileExplicit){let t=zn(e.profile);if(t)return t}return new c("auth.no_token",ot(e.profile,e.flow))}function Be(e){let t=e.split(".");if(t.length!==3)throw new c("auth.token_expired","Stored token is not a valid JWT.");try{let n=Buffer.from(t[1].replace(/-/g,"+").replace(/_/g,"/"),"base64").toString("utf-8");return JSON.parse(n)}catch(n){throw new c("auth.token_expired",`Failed to decode JWT payload: ${n.message}`)}}function Rt(e,t=Math.floor(Date.now()/1e3)){return typeof e.exp=="number"&&e.exp<t}var jt=E(require("path"));var Fe=require("crypto"),s=E(require("fs")),g=E(require("path"));var re=1024*1024,qn=5e3,Xn=20,Vn=3e4,Ue=4096,Zn=new Int32Array(new SharedArrayBuffer(4)),H=class extends Error{constructor(){super("credential-store data file must not have hard links"),this.name="PrivateCredentialFileHardLinkError"}};function ie(e){return e instanceof H}var m=class extends Error{constructor(){super("credential-store lock changed during concurrent inspection")}},Qn=null;function k(){return new c("storage.unavailable","Owner-only plaintext credential ACLs cannot be enforced on Windows; --insecure-storage is disabled on this platform. Use Windows Credential Manager instead. `allscale logout` can still remove a legacy plaintext file when the requested profile is its only remaining profile.")}function oe(){return(Qn??process.platform)!=="win32"}function Mt(){if(!oe())throw k()}function Gt(e){try{return s.default.lstatSync(e),!1}catch(t){if(!p(t,"ENOENT"))throw t}try{let t=s.default.lstatSync(g.dirname(e));return!t.isSymbolicLink()&&t.isDirectory()}catch(t){if(p(t,"ENOENT"))return!0;throw t}}function p(e,t){return typeof e=="object"&&e!==null&&e.code===t}function j(e,t){if(typeof process.geteuid=="function"&&e.uid!==process.geteuid())throw new Error(`${t} is not owned by the current effective user`)}function J(e,t){return e.dev===t.dev&&e.ino===t.ino}function er(e){Atomics.wait(Zn,0,0,e)}function Yt(e){try{return process.kill(e,0),!0}catch(t){return!p(t,"ESRCH")}}function tr(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function xt(e,t){let n=g.dirname(e);t&&s.default.mkdirSync(n,{recursive:!0,mode:448});let r;try{r=s.default.lstatSync(n)}catch(o){if(!t&&p(o,"ENOENT"))return!1;throw o}if(r.isSymbolicLink()||!r.isDirectory())throw new Error("credential-store parent must be a real directory");if(process.platform==="win32")return!0;let i=null;try{i=s.default.openSync(n,s.default.constants.O_RDONLY|(s.default.constants.O_DIRECTORY??0)|(s.default.constants.O_NOFOLLOW??0)|(s.default.constants.O_NONBLOCK??0));let o=s.default.fstatSync(i),a=s.default.lstatSync(n);if(!o.isDirectory()||a.isSymbolicLink()||!a.isDirectory()||!J(o,a))throw new Error("credential-store parent changed while it was being inspected");j(o,"credential-store parent");let l=o;if((o.mode&63)!==0&&g.basename(n)===".allscale"&&(s.default.fchmodSync(i,448),l=s.default.fstatSync(i)),(l.mode&63)!==0)throw new Error("credential-store parent must not grant group or other permissions")}finally{i!==null&&s.default.closeSync(i)}return!0}function b(e,t,n,r={}){if(!n.isFile())throw new Error("credential-store target changed while it was being opened or is not a regular file");let i;try{i=s.default.lstatSync(e)}catch(o){throw r.retryOnPathChange&&p(o,"ENOENT")?new m:o}if(!J(n,i))throw r.retryOnPathChange?new m:new Error("credential-store target changed while it was being opened or is not a regular file");if(i.isSymbolicLink()||!i.isFile())throw new Error("credential-store target changed while it was being opened or is not a regular file");if(!r.allowMultipleLinks&&(n.nlink!==1||i.nlink!==1))throw new H;if(j(n,"credential-store file"),process.platform!=="win32"){s.default.fchmodSync(t,384);let o=s.default.fstatSync(t);if((o.mode&63)!==0)throw new Error("credential-store file could not be made owner-only");return o}return n}function nr(e,t){if(t.size>re)throw new Error("credential-store file exceeds the maximum supported size");let n=Buffer.alloc(re+1),r=0;for(;r<n.length;){let i=s.default.readSync(e,n,r,n.length-r,null);if(i===0)break;r+=i}if(r>re)throw new Error("credential-store file exceeds the maximum supported size");return n.subarray(0,r).toString("utf8")}function vt(e){let t=null;try{try{t=s.default.openSync(e,s.default.constants.O_RDONLY|(s.default.constants.O_NOFOLLOW??0)|(s.default.constants.O_NONBLOCK??0))}catch(i){if(p(i,"ENOENT"))try{if(s.default.lstatSync(e).isSymbolicLink())throw new Error("credential-store target must not be a symbolic link")}catch(o){if(p(o,"ENOENT"))return null;throw o}throw i}let n=s.default.fstatSync(t),r=b(e,t,n);return nr(t,r)}finally{t!==null&&s.default.closeSync(t)}}function Bt(e){let t=null;try{try{t=s.default.openSync(e,s.default.constants.O_RDONLY|(s.default.constants.O_NOFOLLOW??0)|(s.default.constants.O_NONBLOCK??0))}catch(i){if(p(i,"ENOENT")&&Gt(e))return;throw i}let n=s.default.fstatSync(t),r=b(e,t,n);T(e,r)}finally{t!==null&&s.default.closeSync(t)}Ht(g.dirname(e))}function rr(e){let t;try{t=s.default.lstatSync(e)}catch(n){if(p(n,"ENOENT"))return;throw n}if(t.isSymbolicLink()||!t.isFile())throw new Error("credential-store replacement target must be a regular file");if(t.nlink!==1)throw new H;j(t,"credential-store replacement target")}function ir(e,t){for(let n=0;n<8;n+=1){let r=(0,Fe.randomBytes)(12).toString("hex"),i=g.join(e,`.${t}.${process.pid}.${r}.tmp`);try{return{fd:s.default.openSync(i,s.default.constants.O_CREAT|s.default.constants.O_EXCL|s.default.constants.O_WRONLY|(s.default.constants.O_NOFOLLOW??0),384),tempPath:i}}catch(o){if(p(o,"EEXIST"))continue;throw o}}throw new Error("could not allocate a unique credential-store temp file")}function Kt(e,t){let n=0;for(;n<t.length;){let r=s.default.writeSync(e,t,n,t.length-n,null);if(!Number.isSafeInteger(r)||r<=0)throw new Error("credential-store temp file write made no progress");n+=r}}function Ht(e){if(process.platform==="win32")return;let t=null;try{t=s.default.openSync(e,s.default.constants.O_RDONLY|(s.default.constants.O_DIRECTORY??0)|(s.default.constants.O_NOFOLLOW??0)),s.default.fsyncSync(t)}catch{}finally{if(t!==null)try{s.default.closeSync(t)}catch{}}}function or(e,t){let n=Buffer.from(t,"utf8");if(n.length>re)throw new Error("credential-store file exceeds the maximum supported size");let r=g.dirname(e),i=g.basename(e),o=null,a=null,l=!1;try{let u=ir(r,i);o=u.fd,a=u.tempPath;let d=s.default.fstatSync(o);if((b(a,o,d).mode&63)!==0&&process.platform!=="win32")throw new Error("credential-store temp file is not owner-only");Kt(o,n),s.default.fsyncSync(o),b(a,o,s.default.fstatSync(o));let S=o;o=null,s.default.closeSync(S),rr(e),s.default.renameSync(a,e),l=!0}finally{if(o!==null)try{s.default.closeSync(o)}catch{}if(!l&&a!==null)try{s.default.unlinkSync(a)}catch{}}Ht(r)}function sr(e){return g.join(g.dirname(e),`.${g.basename(e)}.lock`)}function ar(e){return g.join(g.dirname(e),`.${g.basename(e)}.lock-recovery`)}function lr(e,t){if(t.size>Ue)return null;let n=Buffer.alloc(Ue+1),r=0;for(;r<n.length;){let o=s.default.readSync(e,n,r,n.length-r,null);if(o===0)break;r+=o}if(r>Ue)return null;let i;try{i=JSON.parse(n.subarray(0,r).toString("utf8"))}catch{return null}return typeof i!="object"||i===null||!Number.isSafeInteger(i.pid)||(i.pid??0)<=0||typeof i.nonce!="string"||!/^[a-f0-9]{24}$/.test(i.nonce??"")||typeof i.target!="string"?null:i}function T(e,t){let n=s.default.lstatSync(e);if(n.isSymbolicLink()||!n.isFile()||!J(n,t))throw new Error("credential-store lock changed while it was being inspected");j(n,"credential-store lock"),s.default.unlinkSync(e)}function Ut(e,t){let n=null;try{try{n=s.default.openSync(e,s.default.constants.O_RDONLY|(s.default.constants.O_NOFOLLOW??0)|(s.default.constants.O_NONBLOCK??0))}catch(u){if(p(u,"ENOENT"))try{let d=s.default.lstatSync(e);throw d.isSymbolicLink()||!d.isFile()?new Error("credential-store lock must be a real regular file"):new m}catch(d){if(p(d,"ENOENT"))return{state:"absent"};throw d}throw u}let r=s.default.fstatSync(n),i=b(e,n,r,{allowMultipleLinks:!0,retryOnPathChange:!0}),o=lr(n,i);return{state:(o?.target===t&&o?!Yt(o.pid):Date.now()-i.mtimeMs>=Vn)?"stale":"active",stats:i}}finally{n!==null&&s.default.closeSync(n)}}function cr(e,t){for(let n=0;n<8;n+=1){let r=(0,Fe.randomBytes)(12).toString("hex"),i=g.join(e,`.${t}.${process.pid}.${r}.lock-claim`),o={pid:process.pid,nonce:r,target:t},a=null;try{a=s.default.openSync(i,s.default.constants.O_CREAT|s.default.constants.O_EXCL|s.default.constants.O_WRONLY|(s.default.constants.O_NOFOLLOW??0),384);let l=s.default.fstatSync(a),u=b(i,a,l,{allowMultipleLinks:!0});return Kt(a,Buffer.from(JSON.stringify(o),"utf8")),s.default.fsyncSync(a),{claimPath:i,metadata:o,stats:u}}catch(l){if(p(l,"EEXIST"))continue;try{s.default.unlinkSync(i)}catch{}throw l}finally{a!==null&&s.default.closeSync(a)}}throw new Error("could not allocate a unique credential-store lock claim")}function ur(e,t){let n;try{n=s.default.openSync(e,s.default.constants.O_RDONLY|(s.default.constants.O_NOFOLLOW??0)|(s.default.constants.O_NONBLOCK??0))}catch(r){throw p(r,"ENOENT")?new m:r}try{let r=s.default.fstatSync(n),i=b(e,n,r,{allowMultipleLinks:!0,retryOnPathChange:!0});if(!J(i,t))throw new m;return{fd:n,lockPath:e,stats:i}}catch(r){throw s.default.closeSync(n),r}}function Dt(e){let t=null;try{try{t=s.default.openSync(e,s.default.constants.O_RDONLY|(s.default.constants.O_NOFOLLOW??0)|(s.default.constants.O_NONBLOCK??0))}catch(n){if(p(n,"ENOENT"))try{let r=s.default.lstatSync(e);throw r.isSymbolicLink()||!r.isFile()?new Error("credential-store recovery gate must be a real regular file"):new m}catch(r){if(p(r,"ENOENT"))return!1;throw r}throw n}return b(e,t,s.default.fstatSync(t),{allowMultipleLinks:!0,retryOnPathChange:!0}),!0}finally{t!==null&&s.default.closeSync(t)}}function dr(e){let t;try{t=s.default.openSync(e,s.default.constants.O_CREAT|s.default.constants.O_EXCL|s.default.constants.O_RDWR|(s.default.constants.O_NOFOLLOW??0),384)}catch(r){if(p(r,"EEXIST"))return null;throw r}let n=null;try{n=s.default.fstatSync(t);let r=b(e,t,n,{allowMultipleLinks:!0,retryOnPathChange:!0});return{fd:t,lockPath:e,stats:r}}catch(r){if(n!==null)try{T(e,n)}catch{}throw s.default.closeSync(t),r}}function L(e,t){if(Date.now()>=e)throw t?new Error("credential-store recovery gate remained present past the bounded wait; a previous lock reclaimer may have crashed, so automatic recovery is intentionally disabled and manual inspection/removal is required"):new Error("credential-store lock remained busy past the bounded wait");er(Xn)}function Ft(e){let t=g.dirname(e),n=g.basename(e),r=sr(e),i=ar(e),o=cr(t,n),a=Date.now()+qn,l=!1,u=!1,d=null,h;try{for(;d===null;)try{if(Dt(i)){L(a,!0);continue}s.default.linkSync(o.claimPath,r),u=!0,d=ur(r,o.stats),l=!0}catch(S){if(u&&!l){try{T(r,o.stats)}catch{}u=!1}if(S instanceof m){L(a,!1);continue}if(!p(S,"EEXIST"))throw S;let ce;try{ce=Ut(r,n)}catch(A){if(A instanceof m){L(a,!1);continue}throw A}if(ce.state==="absent")continue;if(ce.state==="stale"){let A;try{A=dr(i)}catch(C){if(C instanceof m){L(a,!1);continue}throw C}if(A!==null){try{let C;try{C=Ut(r,n)}catch(We){if(We instanceof m){L(a,!1);continue}throw We}C.state==="stale"&&T(r,C.stats)}finally{De(A)}continue}}let Je;try{Je=Dt(i)}catch(A){if(A instanceof m){L(a,!1);continue}throw A}L(a,Je)}}catch(S){h=S}try{T(o.claimPath,o.stats)}catch(S){!p(S,"ENOENT")&&!l&&h===void 0&&(h=S)}if(h!==void 0)throw h;if(d===null)throw new Error("credential-store lock acquisition failed");return d}function De(e){try{T(e.lockPath,e.stats)}finally{s.default.closeSync(e.fd)}}function fr(e,t){let n=tr(t),r=new RegExp(`^\\.${n}\\.(\\d+)\\.[a-f0-9]{24}\\.tmp$`).exec(e)??new RegExp(`^\\.${n}\\.(\\d+)\\.[a-f0-9]{24}\\.lock-claim$`).exec(e);if(!r)return null;let i=Number(r[1]);return Number.isSafeInteger(i)&&i>0?i:null}function $t(e){let t=g.dirname(e),n=g.basename(e);for(let r of s.default.readdirSync(t)){let i=fr(r,n);if(i===null||Yt(i))continue;let o=g.join(t,r),a=null;try{try{a=s.default.openSync(o,s.default.constants.O_RDONLY|(s.default.constants.O_NOFOLLOW??0)|(s.default.constants.O_NONBLOCK??0))}catch(d){if(p(d,"ENOENT")||p(d,"ELOOP"))continue;throw d}let l=s.default.fstatSync(a),u=s.default.lstatSync(o);if(!l.isFile()||u.isSymbolicLink()||!u.isFile()||!J(l,u))continue;try{j(l,"credential-store orphan")}catch{continue}T(o,l)}catch(l){if(!p(l,"ENOENT"))throw l}finally{a!==null&&s.default.closeSync(a)}}}function W(e,t,n){if(!oe()){if(t.allowUnsupportedPlatformCleanup){if(t.createParent)throw k();if(!xt(e,!1))return n({read:()=>null,remove:()=>{},write:()=>{throw k()}});let a=Ft(e);try{return $t(e),n({read:()=>vt(e),remove:()=>Bt(e),write:()=>{throw k()}})}finally{De(a)}}if(!t.createParent){let o=!1;try{o=Gt(e)}catch{throw k()}if(o)return n({read:()=>null,remove:()=>{},write:()=>{throw k()}})}throw k()}if(!xt(e,t.createParent))return n({read:()=>null,remove:()=>{},write:()=>{throw new Error("credential-store parent does not exist")}});let i=Ft(e);try{return $t(e),n({read:()=>vt(e),remove:()=>Bt(e),write:o=>or(e,o)})}finally{De(i)}}var $e="allscale-cli";function Ke(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Jt(e){return Ke(e)&&typeof e.access_token=="string"&&typeof e.refresh_token=="string"}function I(e){return new c("internal",`The session credential store in the ${e} exists but could not be read as valid credential data. Refusing to treat it as empty or overwrite it; session credentials may still remain on this machine.`)}function Me(){return new c("internal","The session credential store in the plaintext file has multiple hard links. Refusing to read, modify, or delete it because another directory entry may retain session credentials. Remove every extra hard link, then re-run the command. If you intentionally keep a deduplicated backup, revoke or rotate its credentials before treating logout as complete.")}function se(){return new c("internal","The session credential store in the plaintext file could not be written safely. Any previous credential file was left unchanged.")}var O,Ge=!1;function pr(){return At()?"ALLSCALE_NO_KEYCHAIN":process.env.KEYTAR_DISABLE==="1"?"KEYTAR_DISABLE":null}function gr(e){if(typeof e!="object"||e===null||e.code!=="MODULE_NOT_FOUND")return!1;let t=e.message;return typeof t=="string"&&t.split(`
16
- `,1)[0]==="Cannot find module 'keytar'"}function hr(){if(O!==void 0)return O;if(pr())return Ge=!1,O=null,O;try{O=require("keytar"),Ge=!1}catch(e){Ge=!gr(e),O=null}return O}function Wt(){let e=oe()?"Re-run with --insecure-storage (or set ALLSCALE_INSECURE_STORAGE=1) to use the owner-only plaintext credential file.":"Plaintext credential fallback is unavailable on Windows because owner-only ACLs cannot be verified; use Windows Credential Manager.";return new c("storage.unavailable","OS keychain could not be accessed on this system (keytar / libsecret may be unavailable, locked, or unusable). "+e+" Never silently downgrade in production.")}async function Ye(e){try{return await e()}catch{throw Wt()}}var He=class{constructor(t){this.keytar=t}keytar;kind="keychain";async read(t){let n=await Ye(()=>this.keytar.getPassword($e,t));if(n===null)return null;let r;try{r=JSON.parse(n)}catch{throw I("OS keychain")}if(!Jt(r))throw I("OS keychain");return r}async get(t){return this.read(t)}async set(t,n){await this.read(t),await Ye(()=>this.keytar.setPassword($e,t,JSON.stringify(n)))}async delete(t){await this.read(t),await Ye(()=>this.keytar.deletePassword($e,t))}},mr="credentials.json",je=class{kind="insecure-file";filePath;constructor(t){this.filePath=t??jt.join(Re(),mr)}read(t){let n;try{n=t.read()}catch(i){throw ie(i)?Me():I("plaintext file")}if(n===null)return{profiles:{}};let r;try{r=JSON.parse(n)}catch{throw I("plaintext file")}if(!Ke(r)||!Ke(r.profiles))throw I("plaintext file");return r}write(t,n){try{t.write(JSON.stringify(n,null,2))}catch(r){throw ie(r)?Me():se()}}profileTokens(t,n){let r=t.profiles[n];if(r!==void 0){if(!Jt(r))throw I("plaintext file");return r}}async get(t){try{return W(this.filePath,{createParent:!1},n=>this.profileTokens(this.read(n),t)??null)}catch(n){throw n instanceof c?n:I("plaintext file")}}async set(t,n){try{W(this.filePath,{createParent:!0},r=>{let i=this.read(r);this.profileTokens(i,t),i.profiles[t]=n,this.write(r,i)})}catch(r){throw r instanceof c?r:se()}}async delete(t){try{W(this.filePath,{createParent:!1},n=>{let r=this.read(n);this.profileTokens(r,t)!==void 0&&(delete r.profiles[t],this.write(n,r))})}catch(n){throw n instanceof c?n:se()}}async clearProfile(t){try{return W(this.filePath,{createParent:!1,allowUnsupportedPlatformCleanup:!0},n=>{let r=this.read(n);return this.profileTokens(r,t)===void 0?!1:(delete r.profiles[t],Object.keys(r.profiles).length===0?n.remove():this.write(n,r),!0)})}catch(n){throw n instanceof c?n:ie(n)?Me():se()}}};function zt(e){if(e.insecureStorage)return Mt(),new je(e.insecureFilePath);let t=hr();if(t)return new He(t);throw Wt()}function ae(e){if(typeof e!="string")return;let t=e.trim();if(t.length===0||t.length>254||/\s/.test(t))return;let n=t.indexOf("@");if(!(n<=0)&&t.indexOf("@",n+1)===-1&&n!==t.length-1)return t.toLowerCase()}function qt(e){if(typeof e!="string")return;let t=e.trim();return t.length===0?void 0:t}function _r(e){let t=[e.email,e.email_lower,e.user_name];for(let n of t){let r=ae(n);if(r!==void 0)return r}}var le=class e extends K{static description="Show the current authenticated identity from the stored credential (agent-key sessions report business_id / scopes / expiry; legacy password sessions decode the cached JWT). No network call.";static examples=["$ allscale whoami","$ allscale whoami --profile prod"];static isLocalOnly=!0;static flags={...K.baseFlags};async runCommand(){let{flags:t}=await this.parse(e),n=this.resolveContext(t);if(n.token)return Xt(n.profile,n.apiBase,n.token,"override");let r=zt({insecureStorage:n.insecureStorage}),i=await r.get(n.profile);if(!i)throw Pt({profile:n.profile,profileExplicit:n.profileExplicit});if(i.agent_key){let o=Math.floor(Date.now()/1e3),a=i.agent_key_expires_at;return i.business_id||process.stderr.write(`No business id stored for profile '${n.profile}' \u2014 this agent-key session predates the backend returning it. Re-run \`allscale device-login --profile ${n.profile}\` (or \`${me(n.profile)}\`) to store it (and to auto-fill --business-id on invoice/store/etc.).
17
- `),{profile:n.profile,api_base:Ie(n.apiBase),credential:"agent_key",business_id:i.business_id,user_email:ae(i.user_email),user_type:i.user_type,scopes:i.scopes??[],expires_at:typeof a=="number"?new Date(a*1e3).toISOString():void 0,expired:typeof a=="number"?a<o:!1,storage:r.kind}}return Xt(n.profile,n.apiBase,i.access_token,r.kind,i.user_email)}};function Xt(e,t,n,r,i){let o=Be(n);return{profile:e,api_base:Ie(t),credential:"cookie",user_id:qt(o.user_id),user_email:ae(i)??_r(o),expires_at:typeof o.exp=="number"?new Date(o.exp*1e3).toISOString():void 0,expired:Rt(o),storage:r}}
12
+ To keep staging, re-run \`allscale device-login\` with --api-base ${""} (recorded as deliberate, silences this).
13
+ To move to production, run: allscale device-login --api-base ${H}
14
+ `}var L=A(require("fs")),It=A(require("os")),Ne=A(require("path")),Be=A(require("@iarna/toml"));var Wn=".allscale",Hn="config.toml";function Ue(){return Ne.join(It.homedir(),Wn)}function Jn(){return Ne.join(Ue(),Hn)}function re(){let e=Jn();if(!L.existsSync(e))return{};let t=L.readFileSync(e,"utf-8");try{return Be.parse(t)}catch(n){throw new c("internal",`Failed to parse ${e}: ${n.message}`)}}function Ct(e){return Object.keys(e.profile??{}).sort()}function Pt(e,t){return e.profile?.[t]}function Rt(e,t,n){let r=t??n??e.default??"default";if(r.includes(":"))throw new c("input.invalid",`Invalid profile name '${r}': ':' is reserved as the keychain namespace separator \u2014 pick a name without ':'.`);return r}function De(e){if(!he(e))throw new c("input.invalid",`Refusing to send credentials to API base ${$(e)}. `+ge)}function vt(e){let t=M();if(t===void 0||rt(e))return;let n=te(e),r=it();if(r.length>0){let o=r.map(l=>te(l.base)).filter(l=>l!==null);if(n!==null&&o.includes(n))return;let a=r.map(l=>$(l.base)).join(", ");throw new c("input.invalid",`Refusing to send to ${$(e)} \u2014 this build only signs for: ${a}. Re-login against one of this build's environments, or use a build that includes the one you need.`)}let i=te(t);if(!(n!==null&&n===i))throw new c("input.invalid",`Refusing to send to ${$(e)} \u2014 this build only signs for ${$(t)}. Re-login against this build's environment, or use a build for that one.`)}var zn=require("@noble/hashes/sha3");var xt=["USDT","USDC"];var pi=new Set([`0x${"0".repeat(40)}`,`0x${"0".repeat(36)}dead`]);var Nt=require("@oclif/core"),J=class e extends w.Command{static enableJsonFlag=!0;static legacyStagingNoticeShown=!1;static emitsOwnOutput=!1;static requiresEscapeHatch=!1;static requiresInput=!1;static isLocalOnly=!1;static baseFlags={profile:w.Flags.string({description:"Named profile from ~/.allscale/config.toml",helpGroup:"GLOBAL"}),token:w.Flags.string({description:"Override the access token for this invocation (precedence: --token > ALLSCALE_TOKEN > --profile)",helpGroup:"GLOBAL",hidden:G()==="public"}),"api-base":w.Flags.string({description:pe,helpGroup:"GLOBAL",hidden:G()==="public"}),"insecure-storage":w.Flags.boolean({description:"Force POSIX plaintext token storage at ~/.allscale/credentials.json (mode 0600) instead of the OS keychain \u2014 for headless / CI / agent use. Unavailable on Windows because Node cannot verify owner-only ACL/link safety. Also via ALLSCALE_INSECURE_STORAGE=1.",default:!1,helpGroup:"GLOBAL"})};async run(){try{Ie(this.jsonEnabled()),Pe(),U({type:"session-start",command:this.id??"",argv:Re(this.argv)});let t=this.constructor;if(G()==="public"){if(this.argv.some(o=>o==="--token"||o.startsWith("--token=")))throw new c("input.invalid","--token is not supported in this build. Set the ALLSCALE_TOKEN environment variable instead (it does not leak into shell history or process listings).");if(this.argv.some(o=>o==="--api-base"||o.startsWith("--api-base=")))throw new c("input.invalid","--api-base is not supported in this build; it always talks to its bound AllScale environment.");if(!t.isLocalOnly&&ne()!==void 0)throw new c("input.invalid","ALLSCALE_API_BASE is not supported in this build; unset it \u2014 this build always talks to its bound AllScale environment.")}let n=Et(this.jsonEnabled()),r=this.argv.length===0&&!n&&tr(t)?this.config.findCommand(this.id??""):void 0;if(r){j();let o=await(0,w.loadHelpClass)(this.config),a=this.config.pjson.oclif?.helpOptions??this.config.pjson.helpOptions;await new o(this.config,a).showCommandHelp(r,this.config.topics);return}if(t.requiresEscapeHatch&&!kt())throw this.argv.length>0&&await this.parse(),new c("raw.disabled","This command is an opt-in escape hatch and is disabled by default. Set ALLSCALE_ALLOW_RAW=1 to enable raw GraphQL/REST passthroughs and schema introspection. Access remains governed by the key's granted scopes, which the backend checks on each request.");let i=await this.runCommand();return U({type:"command-end",ok:!0}),j(),t.emitsOwnOutput?void 0:(this.jsonEnabled()||ct(i),{data:i})}catch(t){let n=lt(t);wt({code:n.code,message:n.message,exitCode:n.exitCode}),this.emitError(n),process.exitCode=n.exitCode;return}finally{Ie(!1)}}resolveSessionApiBaseChain(t){let n=re(),r=t.profile??void 0,i=t["api-base"]??void 0,o=r!==void 0||xe()!==void 0,a=Rt(n,r,xe()),l=Pt(n,a),u=i??ne(),d=u??l?.api_base??H,m=Ot({resolvedApiBase:d,fromExplicitOverride:u!==void 0,profileApiBase:l?.api_base,profileApiBaseSource:l?.api_base_source});return m&&!e.legacyStagingNoticeShown&&(e.legacyStagingNoticeShown=!0,x({event:"legacy_staging_profile",api_base:d,profile:a},m)),{apiBase:d,explicitApiBase:u,profileApiBase:l?.api_base,profile:a,profileExplicit:o}}resolveSessionApiBaseForPayoutDerivation(t){let{apiBase:n}=this.resolveSessionApiBaseChain(t);return this.constructor.isLocalOnly||De(n),n}resolveContext(t){if(G()==="public"){if(t.token!==void 0)throw new c("input.invalid","--token is not supported in this build. Set the ALLSCALE_TOKEN environment variable instead (it does not leak into shell history or process listings).");if(t["api-base"]!==void 0)throw new c("input.invalid","--api-base is not supported in this build; it always talks to its bound AllScale environment.");if(!this.constructor.isLocalOnly&&ne()!==void 0)throw new c("input.invalid","ALLSCALE_API_BASE is not supported in this build; unset it \u2014 this build always talks to its bound AllScale environment.")}let n=t.token??void 0,r=!!t["insecure-storage"],{apiBase:i,explicitApiBase:o,profile:a,profileApiBase:l,profileExplicit:u}=this.resolveSessionApiBaseChain(t);return this.constructor.isLocalOnly||(De(i),vt(i)),{apiBase:i,profile:a,token:n??bt(),insecureStorage:r||Lt(),apiBaseSource:o!==void 0?"explicit":l!==void 0?"profile":"default",profileExplicit:u}}emitError(t){process.stderr.write(`${er(t)}
15
+ `)}};var qn=/_(removed|cleared|count|total)$/i;function Xn(e,t){return typeof t=="number"&&qn.test(e)}var Zn=new Set(xt);function Vn(e,t){return e==="token_symbol"&&typeof t=="string"&&Zn.has(t)}var ie=100;function oe(e,t=0){if(t>8)return"<truncated>";if(Array.isArray(e)){let n=e.slice(0,ie),r=n.map(i=>oe(i,t+1));return e.length>n.length&&r.push(`<${e.length-n.length} more items truncated>`),r}if(e!==null&&typeof e=="object"){let n=Object.create(null),r=Object.entries(e);for(let[i,o]of r.slice(0,ie))n[i]=pt(i)&&!Xn(i,o)&&!Vn(i,o)?"<redacted>":oe(o,t+1);if(r.length>ie){let i="<truncated>";for(;i in n;)i=`<${i}>`;n[i]=`${r.length-ie} more keys`}return n}if(typeof e=="string"){let n=Qn(e);return n!==void 0?h(JSON.stringify(oe(n,t+1))):h(e)}return e}function Qn(e){let t=e.trim();if(!t.startsWith("{")&&!t.startsWith("["))return;let n;try{n=JSON.parse(t)}catch{return}return n!==null&&typeof n=="object"?n:void 0}function er(e){let t=_t()?void 0:2,n=oe(e.toJSON()),r=JSON.stringify(n,null,t);return Buffer.byteLength(r,"utf8")+1<=65536?r:JSON.stringify({error:{code:e.code,message:h(e.message),details:{output_truncated:!0,max_output_bytes:65536}}},null,t)}function tr(e){if(e.requiresInput===!0)return!0;let t=i=>typeof i=="object"&&i!==null&&i.required===!0,n=e.flags??{},r=e.args??{};return Object.values(n).some(i=>t(i))||Object.values(r).some(i=>t(i))}function nr(e,t={}){let n;try{n=Ct(re())}catch{return}if(!(n.length===0||n.includes(e)))return new c("auth.unknown_profile",at(e)+(t.messageSuffix??""),{profile:e})}function Bt(e){if(e.profileExplicit){let t=nr(e.profile);if(t)return t}return new c("auth.no_token",st(e.profile))}function Fe(e){let t=e.split(".");if(t.length!==3)throw new c("auth.token_expired","This token is not a JWT session. Agent API keys are not JWTs \u2014 this path needs a human session token.");try{let n=Buffer.from(t[1].replace(/-/g,"+").replace(/_/g,"/"),"base64").toString("utf-8");return JSON.parse(n)}catch(n){throw new c("auth.token_expired",`Failed to decode JWT payload: ${n.message}`)}}function Ut(e,t=Math.floor(Date.now()/1e3)){return typeof e.exp=="number"&&e.exp<t}var qt=A(require("path"));var Ge=require("crypto"),s=A(require("fs")),g=A(require("path"));var se=1024*1024,rr=5e3,ir=20,or=3e4,$e=4096,sr=new Int32Array(new SharedArrayBuffer(4)),z=class extends Error{constructor(){super("credential-store data file must not have hard links"),this.name="PrivateCredentialFileHardLinkError"}};function ae(e){return e instanceof z}var _=class extends Error{constructor(){super("credential-store lock changed during concurrent inspection")}},ar=null;function k(){return new c("storage.unavailable","Owner-only plaintext credential ACLs cannot be enforced on Windows; --insecure-storage is disabled on this platform. Use Windows Credential Manager instead. `allscale logout` can still remove a legacy plaintext file when the requested profile is its only remaining profile.")}function le(){return(ar??process.platform)!=="win32"}function jt(){if(!le())throw k()}function Wt(e){try{return s.default.lstatSync(e),!1}catch(t){if(!p(t,"ENOENT"))throw t}try{let t=s.default.lstatSync(g.dirname(e));return!t.isSymbolicLink()&&t.isDirectory()}catch(t){if(p(t,"ENOENT"))return!0;throw t}}function p(e,t){return typeof e=="object"&&e!==null&&e.code===t}function q(e,t){if(typeof process.geteuid=="function"&&e.uid!==process.geteuid())throw new Error(`${t} is not owned by the current effective user`)}function X(e,t){return e.dev===t.dev&&e.ino===t.ino}function lr(e){Atomics.wait(sr,0,0,e)}function Ht(e){try{return process.kill(e,0),!0}catch(t){return!p(t,"ESRCH")}}function cr(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Dt(e,t){let n=g.dirname(e);t&&s.default.mkdirSync(n,{recursive:!0,mode:448});let r;try{r=s.default.lstatSync(n)}catch(o){if(!t&&p(o,"ENOENT"))return!1;throw o}if(r.isSymbolicLink()||!r.isDirectory())throw new Error("credential-store parent must be a real directory");if(process.platform==="win32")return!0;let i=null;try{i=s.default.openSync(n,s.default.constants.O_RDONLY|(s.default.constants.O_DIRECTORY??0)|(s.default.constants.O_NOFOLLOW??0)|(s.default.constants.O_NONBLOCK??0));let o=s.default.fstatSync(i),a=s.default.lstatSync(n);if(!o.isDirectory()||a.isSymbolicLink()||!a.isDirectory()||!X(o,a))throw new Error("credential-store parent changed while it was being inspected");q(o,"credential-store parent");let l=o;if((o.mode&63)!==0&&g.basename(n)===".allscale"&&(s.default.fchmodSync(i,448),l=s.default.fstatSync(i)),(l.mode&63)!==0)throw new Error("credential-store parent must not grant group or other permissions")}finally{i!==null&&s.default.closeSync(i)}return!0}function b(e,t,n,r={}){if(!n.isFile())throw new Error("credential-store target changed while it was being opened or is not a regular file");let i;try{i=s.default.lstatSync(e)}catch(o){throw r.retryOnPathChange&&p(o,"ENOENT")?new _:o}if(!X(n,i))throw r.retryOnPathChange?new _:new Error("credential-store target changed while it was being opened or is not a regular file");if(i.isSymbolicLink()||!i.isFile())throw new Error("credential-store target changed while it was being opened or is not a regular file");if(!r.allowMultipleLinks&&(n.nlink!==1||i.nlink!==1))throw new z;if(q(n,"credential-store file"),process.platform!=="win32"){s.default.fchmodSync(t,384);let o=s.default.fstatSync(t);if((o.mode&63)!==0)throw new Error("credential-store file could not be made owner-only");return o}return n}function ur(e,t){if(t.size>se)throw new Error("credential-store file exceeds the maximum supported size");let n=Buffer.alloc(se+1),r=0;for(;r<n.length;){let i=s.default.readSync(e,n,r,n.length-r,null);if(i===0)break;r+=i}if(r>se)throw new Error("credential-store file exceeds the maximum supported size");return n.subarray(0,r).toString("utf8")}function Ft(e){let t=null;try{try{t=s.default.openSync(e,s.default.constants.O_RDONLY|(s.default.constants.O_NOFOLLOW??0)|(s.default.constants.O_NONBLOCK??0))}catch(i){if(p(i,"ENOENT"))try{if(s.default.lstatSync(e).isSymbolicLink())throw new Error("credential-store target must not be a symbolic link")}catch(o){if(p(o,"ENOENT"))return null;throw o}throw i}let n=s.default.fstatSync(t),r=b(e,t,n);return ur(t,r)}finally{t!==null&&s.default.closeSync(t)}}function $t(e){let t=null;try{try{t=s.default.openSync(e,s.default.constants.O_RDONLY|(s.default.constants.O_NOFOLLOW??0)|(s.default.constants.O_NONBLOCK??0))}catch(i){if(p(i,"ENOENT")&&Wt(e))return;throw i}let n=s.default.fstatSync(t),r=b(e,t,n);O(e,r)}finally{t!==null&&s.default.closeSync(t)}zt(g.dirname(e))}function dr(e){let t;try{t=s.default.lstatSync(e)}catch(n){if(p(n,"ENOENT"))return;throw n}if(t.isSymbolicLink()||!t.isFile())throw new Error("credential-store replacement target must be a regular file");if(t.nlink!==1)throw new z;q(t,"credential-store replacement target")}function fr(e,t){for(let n=0;n<8;n+=1){let r=(0,Ge.randomBytes)(12).toString("hex"),i=g.join(e,`.${t}.${process.pid}.${r}.tmp`);try{return{fd:s.default.openSync(i,s.default.constants.O_CREAT|s.default.constants.O_EXCL|s.default.constants.O_WRONLY|(s.default.constants.O_NOFOLLOW??0),384),tempPath:i}}catch(o){if(p(o,"EEXIST"))continue;throw o}}throw new Error("could not allocate a unique credential-store temp file")}function Jt(e,t){let n=0;for(;n<t.length;){let r=s.default.writeSync(e,t,n,t.length-n,null);if(!Number.isSafeInteger(r)||r<=0)throw new Error("credential-store temp file write made no progress");n+=r}}function zt(e){if(process.platform==="win32")return;let t=null;try{t=s.default.openSync(e,s.default.constants.O_RDONLY|(s.default.constants.O_DIRECTORY??0)|(s.default.constants.O_NOFOLLOW??0)),s.default.fsyncSync(t)}catch{}finally{if(t!==null)try{s.default.closeSync(t)}catch{}}}function pr(e,t){let n=Buffer.from(t,"utf8");if(n.length>se)throw new Error("credential-store file exceeds the maximum supported size");let r=g.dirname(e),i=g.basename(e),o=null,a=null,l=!1;try{let u=fr(r,i);o=u.fd,a=u.tempPath;let d=s.default.fstatSync(o);if((b(a,o,d).mode&63)!==0&&process.platform!=="win32")throw new Error("credential-store temp file is not owner-only");Jt(o,n),s.default.fsyncSync(o),b(a,o,s.default.fstatSync(o));let S=o;o=null,s.default.closeSync(S),dr(e),s.default.renameSync(a,e),l=!0}finally{if(o!==null)try{s.default.closeSync(o)}catch{}if(!l&&a!==null)try{s.default.unlinkSync(a)}catch{}}zt(r)}function gr(e){return g.join(g.dirname(e),`.${g.basename(e)}.lock`)}function hr(e){return g.join(g.dirname(e),`.${g.basename(e)}.lock-recovery`)}function mr(e,t){if(t.size>$e)return null;let n=Buffer.alloc($e+1),r=0;for(;r<n.length;){let o=s.default.readSync(e,n,r,n.length-r,null);if(o===0)break;r+=o}if(r>$e)return null;let i;try{i=JSON.parse(n.subarray(0,r).toString("utf8"))}catch{return null}return typeof i!="object"||i===null||!Number.isSafeInteger(i.pid)||(i.pid??0)<=0||typeof i.nonce!="string"||!/^[a-f0-9]{24}$/.test(i.nonce??"")||typeof i.target!="string"?null:i}function O(e,t){let n=s.default.lstatSync(e);if(n.isSymbolicLink()||!n.isFile()||!X(n,t))throw new Error("credential-store lock changed while it was being inspected");q(n,"credential-store lock"),s.default.unlinkSync(e)}function Mt(e,t){let n=null;try{try{n=s.default.openSync(e,s.default.constants.O_RDONLY|(s.default.constants.O_NOFOLLOW??0)|(s.default.constants.O_NONBLOCK??0))}catch(u){if(p(u,"ENOENT"))try{let d=s.default.lstatSync(e);throw d.isSymbolicLink()||!d.isFile()?new Error("credential-store lock must be a real regular file"):new _}catch(d){if(p(d,"ENOENT"))return{state:"absent"};throw d}throw u}let r=s.default.fstatSync(n),i=b(e,n,r,{allowMultipleLinks:!0,retryOnPathChange:!0}),o=mr(n,i);return{state:(o?.target===t&&o?!Ht(o.pid):Date.now()-i.mtimeMs>=or)?"stale":"active",stats:i}}finally{n!==null&&s.default.closeSync(n)}}function _r(e,t){for(let n=0;n<8;n+=1){let r=(0,Ge.randomBytes)(12).toString("hex"),i=g.join(e,`.${t}.${process.pid}.${r}.lock-claim`),o={pid:process.pid,nonce:r,target:t},a=null;try{a=s.default.openSync(i,s.default.constants.O_CREAT|s.default.constants.O_EXCL|s.default.constants.O_WRONLY|(s.default.constants.O_NOFOLLOW??0),384);let l=s.default.fstatSync(a),u=b(i,a,l,{allowMultipleLinks:!0});return Jt(a,Buffer.from(JSON.stringify(o),"utf8")),s.default.fsyncSync(a),{claimPath:i,metadata:o,stats:u}}catch(l){if(p(l,"EEXIST"))continue;try{s.default.unlinkSync(i)}catch{}throw l}finally{a!==null&&s.default.closeSync(a)}}throw new Error("could not allocate a unique credential-store lock claim")}function yr(e,t){let n;try{n=s.default.openSync(e,s.default.constants.O_RDONLY|(s.default.constants.O_NOFOLLOW??0)|(s.default.constants.O_NONBLOCK??0))}catch(r){throw p(r,"ENOENT")?new _:r}try{let r=s.default.fstatSync(n),i=b(e,n,r,{allowMultipleLinks:!0,retryOnPathChange:!0});if(!X(i,t))throw new _;return{fd:n,lockPath:e,stats:i}}catch(r){throw s.default.closeSync(n),r}}function Gt(e){let t=null;try{try{t=s.default.openSync(e,s.default.constants.O_RDONLY|(s.default.constants.O_NOFOLLOW??0)|(s.default.constants.O_NONBLOCK??0))}catch(n){if(p(n,"ENOENT"))try{let r=s.default.lstatSync(e);throw r.isSymbolicLink()||!r.isFile()?new Error("credential-store recovery gate must be a real regular file"):new _}catch(r){if(p(r,"ENOENT"))return!1;throw r}throw n}return b(e,t,s.default.fstatSync(t),{allowMultipleLinks:!0,retryOnPathChange:!0}),!0}finally{t!==null&&s.default.closeSync(t)}}function Sr(e){let t;try{t=s.default.openSync(e,s.default.constants.O_CREAT|s.default.constants.O_EXCL|s.default.constants.O_RDWR|(s.default.constants.O_NOFOLLOW??0),384)}catch(r){if(p(r,"EEXIST"))return null;throw r}let n=null;try{n=s.default.fstatSync(t);let r=b(e,t,n,{allowMultipleLinks:!0,retryOnPathChange:!0});return{fd:t,lockPath:e,stats:r}}catch(r){if(n!==null)try{O(e,n)}catch{}throw s.default.closeSync(t),r}}function T(e,t){if(Date.now()>=e)throw t?new Error("credential-store recovery gate remained present past the bounded wait; a previous lock reclaimer may have crashed, so automatic recovery is intentionally disabled and manual inspection/removal is required"):new Error("credential-store lock remained busy past the bounded wait");lr(ir)}function Yt(e){let t=g.dirname(e),n=g.basename(e),r=gr(e),i=hr(e),o=_r(t,n),a=Date.now()+rr,l=!1,u=!1,d=null,m;try{for(;d===null;)try{if(Gt(i)){T(a,!0);continue}s.default.linkSync(o.claimPath,r),u=!0,d=yr(r,o.stats),l=!0}catch(S){if(u&&!l){try{O(r,o.stats)}catch{}u=!1}if(S instanceof _){T(a,!1);continue}if(!p(S,"EEXIST"))throw S;let fe;try{fe=Mt(r,n)}catch(E){if(E instanceof _){T(a,!1);continue}throw E}if(fe.state==="absent")continue;if(fe.state==="stale"){let E;try{E=Sr(i)}catch(P){if(P instanceof _){T(a,!1);continue}throw P}if(E!==null){try{let P;try{P=Mt(r,n)}catch(Xe){if(Xe instanceof _){T(a,!1);continue}throw Xe}P.state==="stale"&&O(r,P.stats)}finally{Me(E)}continue}}let qe;try{qe=Gt(i)}catch(E){if(E instanceof _){T(a,!1);continue}throw E}T(a,qe)}}catch(S){m=S}try{O(o.claimPath,o.stats)}catch(S){!p(S,"ENOENT")&&!l&&m===void 0&&(m=S)}if(m!==void 0)throw m;if(d===null)throw new Error("credential-store lock acquisition failed");return d}function Me(e){try{O(e.lockPath,e.stats)}finally{s.default.closeSync(e.fd)}}function Ar(e,t){let n=cr(t),r=new RegExp(`^\\.${n}\\.(\\d+)\\.[a-f0-9]{24}\\.tmp$`).exec(e)??new RegExp(`^\\.${n}\\.(\\d+)\\.[a-f0-9]{24}\\.lock-claim$`).exec(e);if(!r)return null;let i=Number(r[1]);return Number.isSafeInteger(i)&&i>0?i:null}function Kt(e){let t=g.dirname(e),n=g.basename(e);for(let r of s.default.readdirSync(t)){let i=Ar(r,n);if(i===null||Ht(i))continue;let o=g.join(t,r),a=null;try{try{a=s.default.openSync(o,s.default.constants.O_RDONLY|(s.default.constants.O_NOFOLLOW??0)|(s.default.constants.O_NONBLOCK??0))}catch(d){if(p(d,"ENOENT")||p(d,"ELOOP"))continue;throw d}let l=s.default.fstatSync(a),u=s.default.lstatSync(o);if(!l.isFile()||u.isSymbolicLink()||!u.isFile()||!X(l,u))continue;try{q(l,"credential-store orphan")}catch{continue}O(o,l)}catch(l){if(!p(l,"ENOENT"))throw l}finally{a!==null&&s.default.closeSync(a)}}}function Z(e,t,n){if(!le()){if(t.allowUnsupportedPlatformCleanup){if(t.createParent)throw k();if(!Dt(e,!1))return n({read:()=>null,remove:()=>{},write:()=>{throw k()}});let a=Yt(e);try{return Kt(e),n({read:()=>Ft(e),remove:()=>$t(e),write:()=>{throw k()}})}finally{Me(a)}}if(!t.createParent){let o=!1;try{o=Wt(e)}catch{throw k()}if(o)return n({read:()=>null,remove:()=>{},write:()=>{throw k()}})}throw k()}if(!Dt(e,t.createParent))return n({read:()=>null,remove:()=>{},write:()=>{throw new Error("credential-store parent does not exist")}});let i=Yt(e);try{return Kt(e),n({read:()=>Ft(e),remove:()=>$t(e),write:o=>pr(e,o)})}finally{Me(i)}}var Ye="allscale-cli";function He(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Xt(e){return He(e)&&typeof e.access_token=="string"&&typeof e.refresh_token=="string"}function C(e){return new c("internal",`The session credential store in the ${e} exists but could not be read as valid credential data. Refusing to treat it as empty or overwrite it; session credentials may still remain on this machine.`)}function Ke(){return new c("internal","The session credential store in the plaintext file has multiple hard links. Refusing to read, modify, or delete it because another directory entry may retain session credentials. Remove every extra hard link, then re-run the command. If you intentionally keep a deduplicated backup, revoke or rotate its credentials before treating logout as complete.")}function ce(){return new c("internal","The session credential store in the plaintext file could not be written safely. Any previous credential file was left unchanged.")}var I,je=!1;function Er(){return Tt()?"ALLSCALE_NO_KEYCHAIN":process.env.KEYTAR_DISABLE==="1"?"KEYTAR_DISABLE":null}function wr(e){if(typeof e!="object"||e===null||e.code!=="MODULE_NOT_FOUND")return!1;let t=e.message;return typeof t=="string"&&t.split(`
16
+ `,1)[0]==="Cannot find module 'keytar'"}function br(){if(I!==void 0)return I;if(Er())return je=!1,I=null,I;try{I=require("keytar"),je=!1}catch(e){je=!wr(e),I=null}return I}function Zt(){let e=le()?"Re-run with --insecure-storage (or set ALLSCALE_INSECURE_STORAGE=1) to use the owner-only plaintext credential file.":"Plaintext credential fallback is unavailable on Windows because owner-only ACLs cannot be verified; use Windows Credential Manager.";return new c("storage.unavailable","OS keychain could not be accessed on this system (keytar / libsecret may be unavailable, locked, or unusable). "+e+" Never silently downgrade in production.")}async function We(e){try{return await e()}catch{throw Zt()}}var Je=class{constructor(t){this.keytar=t}keytar;kind="keychain";async read(t){let n=await We(()=>this.keytar.getPassword(Ye,t));if(n===null)return null;let r;try{r=JSON.parse(n)}catch{throw C("OS keychain")}if(!Xt(r))throw C("OS keychain");return r}async get(t){return this.read(t)}async set(t,n){await this.read(t),await We(()=>this.keytar.setPassword(Ye,t,JSON.stringify(n)))}async delete(t){await this.read(t),await We(()=>this.keytar.deletePassword(Ye,t))}},Lr="credentials.json",ze=class{kind="insecure-file";filePath;constructor(t){this.filePath=t??qt.join(Ue(),Lr)}read(t){let n;try{n=t.read()}catch(i){throw ae(i)?Ke():C("plaintext file")}if(n===null)return{profiles:{}};let r;try{r=JSON.parse(n)}catch{throw C("plaintext file")}if(!He(r)||!He(r.profiles))throw C("plaintext file");return r}write(t,n){try{t.write(JSON.stringify(n,null,2))}catch(r){throw ae(r)?Ke():ce()}}profileTokens(t,n){let r=t.profiles[n];if(r!==void 0){if(!Xt(r))throw C("plaintext file");return r}}async get(t){try{return Z(this.filePath,{createParent:!1},n=>this.profileTokens(this.read(n),t)??null)}catch(n){throw n instanceof c?n:C("plaintext file")}}async set(t,n){try{Z(this.filePath,{createParent:!0},r=>{let i=this.read(r);this.profileTokens(i,t),i.profiles[t]=n,this.write(r,i)})}catch(r){throw r instanceof c?r:ce()}}async delete(t){try{Z(this.filePath,{createParent:!1},n=>{let r=this.read(n);this.profileTokens(r,t)!==void 0&&(delete r.profiles[t],this.write(n,r))})}catch(n){throw n instanceof c?n:ce()}}async clearProfile(t){try{return Z(this.filePath,{createParent:!1,allowUnsupportedPlatformCleanup:!0},n=>{let r=this.read(n);return this.profileTokens(r,t)===void 0?!1:(delete r.profiles[t],Object.keys(r.profiles).length===0?n.remove():this.write(n,r),!0)})}catch(n){throw n instanceof c?n:ae(n)?Ke():ce()}}};function Vt(e){if(e.insecureStorage)return jt(),new ze(e.insecureFilePath);let t=br();if(t)return new Je(t);throw Zt()}function ue(e){if(typeof e!="string")return;let t=e.trim();if(t.length===0||t.length>254||/\s/.test(t))return;let n=t.indexOf("@");if(!(n<=0)&&t.indexOf("@",n+1)===-1&&n!==t.length-1)return t.toLowerCase()}function Qt(e){if(typeof e!="string")return;let t=e.trim();return t.length===0?void 0:t}function Tr(e){let t=[e.email,e.email_lower,e.user_name];for(let n of t){let r=ue(n);if(r!==void 0)return r}}var de=class e extends J{static description="Show the current authenticated identity from the stored credential (agent-key sessions report business_id / scopes / expiry; legacy password sessions decode the cached JWT). No network call.";static examples=["$ allscale whoami","$ allscale whoami --profile prod"];static isLocalOnly=!0;static flags={...J.baseFlags};async runCommand(){let{flags:t}=await this.parse(e),n=this.resolveContext(t);if(n.token)return en(n.profile,n.apiBase,n.token,"override");let r=Vt({insecureStorage:n.insecureStorage}),i=await r.get(n.profile);if(!i)throw Bt({profile:n.profile,profileExplicit:n.profileExplicit});if(i.agent_key){let o=Math.floor(Date.now()/1e3),a=i.agent_key_expires_at;return i.business_id||process.stderr.write(`No business id stored for profile '${n.profile}' \u2014 this agent-key session predates the backend returning it. Re-run \`allscale device-login --profile ${Y(n.profile)}\` (or \`${Se(n.profile)}\`) to store it (and to auto-fill --business-id on invoice/store/etc.).
17
+ `),{profile:n.profile,api_base:ve(n.apiBase),credential:"agent_key",business_id:i.business_id,user_email:ue(i.user_email),user_type:i.user_type,scopes:i.scopes??[],expires_at:typeof a=="number"?new Date(a*1e3).toISOString():void 0,expired:typeof a=="number"?a<o:!1,storage:r.kind}}return en(n.profile,n.apiBase,i.access_token,r.kind,i.user_email)}};function en(e,t,n,r,i){let o=Fe(n);return{profile:e,api_base:ve(t),credential:"cookie",user_id:Qt(o.user_id),user_email:ue(i)??Tr(o),expires_at:typeof o.exp=="number"?new Date(o.exp*1e3).toISOString():void 0,expired:Ut(o),storage:r}}
18
18
  //# sourceMappingURL=whoami.js.map
@@ -1,2 +1,2 @@
1
- "use strict";var u=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames;var h=Object.prototype.hasOwnProperty;var S=(n,e)=>{for(var i in e)u(n,i,{get:e[i],enumerable:!0})},y=(n,e,i,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of I(e))!h.call(n,r)&&r!==i&&u(n,r,{get:()=>e[r],enumerable:!(t=f(e,r))||t.enumerable});return n};var P=n=>y(u({},"__esModule",{value:!0}),n);var B={};S(B,{default:()=>T});module.exports=P(B);var _="public",p="https://app.allscale.io";function a(){return"".trim()||void 0}function g(){return"public"}function L(){{let n="[]".trim();if(n.length===0)return[];try{let e=JSON.parse(n);return Array.isArray(e)?e:[]}catch{return[]}}return A()}function A(){let n=process.env.ALLSCALE_BUILD_PAIRS?.trim()??"";if(n.length>0)try{let t=JSON.parse(n);if(!Array.isArray(t))return[];let r=[];for(let s of t){if(typeof s!="object"||s===null)continue;let{base:o,key:l,keyId:d}=s;if(typeof o!="string"||o.trim().length===0||typeof l!="string"||l.trim().length===0)continue;let c=typeof d=="string"?d.trim():"";r.push({base:o.trim(),key:l,keyId:c.length>0?c:"cli-1"})}return r}catch{return[]}let e=process.env.ALLSCALE_SIGNING_KEY??"",i=process.env.ALLSCALE_BUILD_API_BASE?.trim()??"";if(e.trim().length>0&&i.length>0){let t=process.env.ALLSCALE_SIGNING_KEY_ID?.trim();return[{base:i,key:e,keyId:t&&t.length>0?t:"cli-1"}]}return[]}var ee=a()??p;function E(n){try{let e=new URL(n);return`${e.protocol}//${e.host}`}catch{return"<unparseable URL>"}}var b=async function(n){try{let e=n.config.pjson.oclif?.additionalVersionFlags;if(!new Set(["--version",...Array.isArray(e)?e.filter(o=>typeof o=="string"):[]]).has(n.id))return;let t=a();if(t===void 0)return;let r=L().length,s=r>1?` (bound, ${r} endpoints)`:" (bound)";this.log(`build: ${g()} \xB7 api-base ${E(t)}${s}`)}catch{}},T=b;
1
+ "use strict";var u=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames;var h=Object.prototype.hasOwnProperty;var S=(n,e)=>{for(var i in e)u(n,i,{get:e[i],enumerable:!0})},b=(n,e,i,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of I(e))!h.call(n,r)&&r!==i&&u(n,r,{get:()=>e[r],enumerable:!(t=E(e,r))||t.enumerable});return n};var y=n=>b(u({},"__esModule",{value:!0}),n);var P={};S(P,{default:()=>B});module.exports=y(P);var p="public",_="https://app.allscale.io";function a(){return"".trim()||void 0}function L(){return"public"}function g(){{let n="[]".trim();if(n.length===0)return[];try{let e=JSON.parse(n);return Array.isArray(e)?e:[]}catch{return[]}}return A()}function A(){let n=process.env.ALLSCALE_BUILD_PAIRS?.trim()??"";if(n.length>0)try{let t=JSON.parse(n);if(!Array.isArray(t))return[];let r=[];for(let o of t){if(typeof o!="object"||o===null)continue;let{base:s,key:l,keyId:c}=o;if(typeof s!="string"||s.trim().length===0||typeof l!="string"||l.trim().length===0)continue;let d=typeof c=="string"?c.trim():"";r.push({base:s.trim(),key:l,keyId:d.length>0?d:"cli-1"})}return r}catch{return[]}let e=process.env.ALLSCALE_SIGNING_KEY??"",i=process.env.ALLSCALE_BUILD_API_BASE?.trim()??"";if(e.trim().length>0&&i.length>0){let t=process.env.ALLSCALE_SIGNING_KEY_ID?.trim();return[{base:i,key:e,keyId:t&&t.length>0?t:"cli-1"}]}return[]}var X=a()??_;function f(n){try{let e=new URL(n);return`${e.protocol}//${e.host}`}catch{return"<unparseable URL>"}}var m=async function(n){try{let e=n.config.pjson.oclif?.additionalVersionFlags;if(!new Set(["--version",...Array.isArray(e)?e.filter(s=>typeof s=="string"):[]]).has(n.id))return;let t=a();if(t===void 0)return;let r=g().length,o=r>1?` (bound, ${r} endpoints)`:" (bound)";this.log(`build: ${L()} \xB7 api-base ${f(t)}${o}`)}catch{}},B=m;
2
2
  //# sourceMappingURL=version-suffix.js.map