@allscale/cli 0.1.0 → 1.0.2

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 +144 -45
  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 +14 -14
  11. package/dist/commands/describe.js +13 -13
  12. package/dist/commands/device-login.js +29 -29
  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 +46 -43
  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 +19 -13
  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 +19 -18
  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 +17 -15
  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 +140 -296
  38. package/package.json +4 -6
  39. package/dist/commands/claim-link/preview.js +0 -18
@@ -1,17 +1,23 @@
1
- "use strict";var rn=Object.create;var ne=Object.defineProperty;var on=Object.getOwnPropertyDescriptor;var sn=Object.getOwnPropertyNames;var an=Object.getPrototypeOf,ln=Object.prototype.hasOwnProperty;var cn=(e,t)=>{for(var n in t)ne(e,n,{get:t[n],enumerable:!0})},Ve=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of sn(t))!ln.call(e,i)&&i!==n&&ne(e,i,{get:()=>t[i],enumerable:!(r=on(t,i))||r.enumerable});return e};var w=(e,t,n)=>(n=e!=null?rn(an(e)):{},Ve(t||!e||!e.__esModule?ne(n,"default",{value:e,enumerable:!0}):n,e)),un=e=>Ve(ne({},"__esModule",{value:!0}),e);var Or={};cn(Or,{default:()=>ye});module.exports=un(Or);var L=require("@oclif/core");var Xe="public",Ze="https://app.allscale.io";var Qe=["https://app.allscale.io"];var Se="Override the API base URL (public builds accept only https://app.allscale.io)";var _e="Only https://app.allscale.io is allowed, and URL userinfo is forbidden.";function et(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 tt(e){return et(e)!==null}function Ee(e){let t=et(e);return t!==null&&Qe.includes(t.origin)}function W(){return"".trim()||void 0}function J(){return"public"}function nt(e){try{let{hostname:t}=new URL(e);return t==="127.0.0.1"||t==="localhost"||t==="[::1]"}catch{return!1}}function rt(){{let e="[]".trim();if(e.length===0)return[];try{let t=JSON.parse(e);return Array.isArray(t)?t:[]}catch{return[]}}return we()}function we(){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 it="allscale device-login";var dn="device-login";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 ${dn} --profile ${e}\`.`}var fn={"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},pn=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 Le(e){return(typeof e=="string"?e:String(e??"")).replace(pn,"")}var gn=64;function Ae(e,t=new Map,n=0){if(typeof e=="string")return Le(e);if(e===null||typeof e!="object")return e;let r=t.get(e);if(r!==void 0)return r;if(n>=gn)return e;if(Array.isArray(e)){let a=[];t.set(e,a);for(let l of e)a.push(Ae(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:Ae(l,t,n+1),writable:!0,enumerable:!0,configurable:!0});return o}var c=class extends Error{code;details;constructor(t,n,r){super(Le(n)),this.code=t,this.details=r&&Ae(r),this.name="AllscaleError"}get exitCode(){return fn[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(yn(e)){let t=_n(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 hn=new Set(["CLIError","CLIParseError","RequiredArgsError","RequiredFlagError","UnexpectedArgsError","FlagInvalidOptionError","ArgInvalidOptionError","InvalidArgsSpecError"]),mn=[/^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 yn(e){if(Sn(e))return!0;let t=e.name??"";return hn.has(t)?t==="CLIError"?be(e,"parse")||ot(e.message):!0:ot(e.message)}function Sn(e){if(!be(e,"oclif"))return!1;let t=e.oclif;return typeof t=="object"&&t!==null&&t.exit===2&&be(e,"parse")}function ot(e){return e?Le(e).split(`
2
- `).some(t=>mn.some(n=>n.test(t.trim()))):!1}function be(e,t){return typeof e=="object"&&e!==null&&Object.prototype.hasOwnProperty.call(e,t)}function _n(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=w(require("fs")),ie=w(require("path")),ht=w(require("crypto"));var En="...<truncated>",wn=/\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]+/g,An=/\bBearer\s+[A-Za-z0-9._~+/=-]{12,}/gi,Pe=String.raw`(?:(?:Bearer|Basic)\s+)?(?:"(?:\\.|[^"\\\r\n])*"|'(?:\\.|[^'\\\r\n])*'|[^\s,;)}\]]+)`,ke=String.raw`(?:proxy[_-]?)?authorization`,bn=new RegExp(String.raw`(^|[^A-Za-z0-9])((?:"${ke}"|'${ke}'|${ke})\s*[:=]\s*)((?:Bearer|Basic)\s+)?(?!<redacted(?:-jwt)?>)${Pe}`,"gi"),Ln=/\b(https?:\/\/)[^\s/?#]+@/gi,Oe=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)`,kn=new RegExp(String.raw`(^|[^A-Za-z0-9])((?:"${Oe}"|'${Oe}'|${Oe})\s*[:=]\s*)(?!<redacted(?:-jwt)?>)${Pe}`,"gi"),Te=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)`,On=new RegExp(String.raw`(^|[^A-Za-z0-9])((?:"${Te}"|'${Te}'|${Te})\s*[:=]\s*)(?!<redacted(?:-jwt)?>)${Pe}`,"g");function ct(e){return e.replace(Ln,"$1<redacted>@").replace(wn,"<redacted-jwt>").replace(bn,"$1$2$3<redacted>").replace(kn,"$1$2<redacted>").replace(On,"$1$2<redacted>").replace(An,"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=En){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 _(e,t=16384){return dt(ut(ct(e)),t)}var Ie=100,Tn=8,In=8*1024;function re(){return{remaining:In}}function Ce(e,t){let n=Math.min(16384,t.remaining),r=dt(e,n);return t.remaining-=Buffer.byteLength(r,"utf8"),r}function B(e,t,n=0,r={}){if(n>Tn)return Ce("<truncated>",t);if(typeof e=="string"){let i=ct(e);return Ce(r.escapeControls?ut(i):i,t)}if(Array.isArray(e)){let i=e.slice(0,Ie),o=i.map(a=>B(a,t,n+1,r));return e.length>i.length&&o.push(Ce(`<${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,Ie))i[a]=B(l,t,n+1,r);return o.length>Ie&&(i.output_truncated=!0),i}return e}var ve=require("process");var Re=!1;function Ne(e){Re=e}function pt(){return Re}var ft="1";function D(e,t){if(Re){let n={...e};delete n.version;let r=re(),i={event:n.event,...n},o=B(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})),ve.stderr.write(`${a}
4
- `)}else ve.stderr.write(t)}var gt="2",F=null,E=null,$=!1;function Cn(){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 ie.join(t,`allscale-output-${n}-${r}.ndjson`)}return null}var xe=64*1024*1024,Pn=null;function mt(){if($)return;let e=Cn();if(!e)return;F=null;let t=null;try{if((Pn??process.platform)==="win32")throw new Error("owner-only sidecar ACLs cannot be enforced on Windows; sidecar output is disabled");let n=ie.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{}D({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}F=e,E=t,$=!0}var vn=[/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 Rn(e){let t=e.replace(/([a-z0-9])([A-Z])/g,"$1_$2").replace(/([A-Z]+)([A-Z][a-z])/g,"$1_$2");return vn.some(n=>n.test(t))}function Nn(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=xn(t.pathname);let i=n;t.pathname!==r&&(i=!0);for(let[o]of t.searchParams)Rn(o)&&(t.searchParams.set(o,"<redacted>"),i=!0);return i?t.toString():e}catch{return e}}function xn(e){return e.replace(/(\/(?:api\/)?(?:v1\/)?public\/claim-links\/)([^/:]+)(:claim)?(?=\/?$)/,"$1<redacted>$3").replace(/(\/(?:api\/)?public\/claim-links\/)([^/]+)(\/claim)(?=\/?$)/,"$1<redacted>$3")}function Bn(e){return(e.type==="request"||e.type==="bridge_browser_open")&&typeof e.url=="string"?{...e,url:Nn(e.url)}:e}function Un(e){let t=new Date().toISOString(),n=e,{type:r,...i}=n,o=B(i,re()),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 z(e){if(!$||!F||E===null)return;let t=Bn(e),n=Un(t);try{if(f.fstatSync(E).size+Buffer.byteLength(n,"utf8")+1>xe){$=!1;try{f.closeSync(E)}catch{}E=null,D({event:"sidecar_disabled",reason:"size_limit",...F===null?{}:{path:_(F)},max_bytes:xe},`${_(`[allscale] sidecar exceeded ${xe} bytes; disabling it for the rest of this run. Rotate or remove ${F}, or point ALLSCALE_OUTPUT_FILE_DIRECTORY at a directory so each run gets its own file.`)}
1
+ "use strict";var pn=Object.create;var ae=Object.defineProperty;var gn=Object.getOwnPropertyDescriptor;var hn=Object.getOwnPropertyNames;var mn=Object.getPrototypeOf,yn=Object.prototype.hasOwnProperty;var Sn=(e,t)=>{for(var n in t)ae(e,n,{get:t[n],enumerable:!0})},tt=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of hn(t))!yn.call(e,i)&&i!==n&&ae(e,i,{get:()=>t[i],enumerable:!(r=gn(t,i))||r.enumerable});return e};var A=(e,t,n)=>(n=e!=null?pn(mn(e)):{},tt(t||!e||!e.__esModule?ae(n,"default",{value:e,enumerable:!0}):n,e)),_n=e=>tt(ae({},"__esModule",{value:!0}),e);var Xr={};Sn(Xr,{default:()=>Ee});module.exports=_n(Xr);var k=require("@oclif/core");var nt="public",rt="https://app.allscale.io";var it=["https://app.allscale.io"];var Ae="Override the API base URL (public builds accept only https://app.allscale.io)";var be="Only https://app.allscale.io is allowed, and URL userinfo is forbidden.";function ot(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 st(e){return ot(e)!==null}function Le(e){let t=ot(e);return t!==null&&it.includes(t.origin)}function J(){return"".trim()||void 0}function U(){return"public"}function at(e){try{let{hostname:t}=new URL(e);return t==="127.0.0.1"||t==="localhost"||t==="[::1]"}catch{return!1}}function lt(){{let e="[]".trim();if(e.length===0)return[];try{let t=JSON.parse(e);return Array.isArray(t)?t:[]}catch{return[]}}return ke()}function ke(){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 wn="device-login",En=/^[A-Za-z0-9._-]{1,64}$/;function An(e){return En.test(e)?e:"<profile>"}function ut(e){return`Unknown profile '${e}' \u2014 no such profile is saved on this machine. Check the spelling first; to deliberately create '${e}', run \`allscale ${wn} --profile ${An(e)}\`.`}var bn={"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_invalid":5,"auth.token_expired":5,"auth.device_pairing_timeout":3,"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},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 ve(e){return(typeof e=="string"?e:String(e??"")).replace(Ln,"")}var kn=64;function Oe(e,t=new Map,n=0){if(typeof e=="string")return ve(e);if(e===null||typeof e!="object")return e;let r=t.get(e);if(r!==void 0)return r;if(n>=kn)return e;if(Array.isArray(e)){let a=[];t.set(e,a);for(let l of e)a.push(Oe(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:Oe(l,t,n+1),writable:!0,enumerable:!0,configurable:!0});return o}var c=class extends Error{code;details;constructor(t,n,r){super(ve(n)),this.code=t,this.details=r&&Oe(r),this.name="AllscaleError"}get exitCode(){return bn[this.code]}toJSON(){return{error:{code:this.code,message:this.message,...this.details?{details:this.details}:{}}}}};function dt(e){if(e instanceof c)return e;if(e instanceof Error){if(vn(e)){let t=In(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 On=new Set(["CLIError","CLIParseError","RequiredArgsError","RequiredFlagError","UnexpectedArgsError","FlagInvalidOptionError","ArgInvalidOptionError","InvalidArgsSpecError"]),Tn=[/^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 vn(e){if(Cn(e))return!0;let t=e.name??"";return On.has(t)?t==="CLIError"?Te(e,"parse")||ct(e.message):!0:ct(e.message)}function Cn(e){if(!Te(e,"oclif"))return!1;let t=e.oclif;return typeof t=="object"&&t!==null&&t.exit===2&&Te(e,"parse")}function ct(e){return e?ve(e).split(`
2
+ `).some(t=>Tn.some(n=>n.test(t.trim()))):!1}function Te(e,t){return typeof e=="object"&&e!==null&&Object.prototype.hasOwnProperty.call(e,t)}function In(e){let t=e,n={};for(let r of["code","exitCode","suggestions","ref"])t[r]!==void 0&&(n[r]=t[r]);return n}function ft(e){process.stdout.write(`${JSON.stringify({data:e},null,2)}
3
+ `)}var f=A(require("fs")),ce=A(require("path")),At=A(require("crypto"));var Pn="...<truncated>",xn=/\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]+/g,Rn=/\bBearer\s+[A-Za-z0-9._~+/=-]{12,}/gi,Re=String.raw`(?:(?:Bearer|Basic)\s+)?(?:"(?:\\.|[^"\\\r\n])*"|'(?:\\.|[^'\\\r\n])*'|[^\s,;)}\]]+)`,Ce=String.raw`(?:proxy[_-]?)?authorization`,Nn=new RegExp(String.raw`(^|[^A-Za-z0-9])((?:"${Ce}"|'${Ce}'|${Ce})\s*[:=]\s*)((?:Bearer|Basic)\s+)?(?!<redacted(?:-jwt)?>)${Re}`,"gi"),Bn=/\b(https?:\/\/)[^\s/?#]+@/gi,Dn=String.raw`(?:[A-Za-z0-9]+[_-])*`,Un=String.raw`(?:[A-Za-z0-9]{1,32}[_-]){0,8}`,gt=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)`,pt=gt(Dn),$n=gt(Un),Fn=new RegExp(String.raw`(^|[^A-Za-z0-9])((?:"${pt}"|'${pt}'|${$n})\s*[:=]\s*)(?!<redacted(?:-jwt)?>)${Re}`,"gi"),Ie=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)`,Mn=new RegExp(String.raw`(^|[^A-Za-z0-9])((?:"${Ie}"|'${Ie}'|${Ie})\s*[:=]\s*)(?!<redacted(?:-jwt)?>)${Re}`,"g");function ht(e){return e.replace(Bn,"$1<redacted>@").replace(xn,"<redacted-jwt>").replace(Nn,"$1$2$3<redacted>").replace(Fn,"$1$2<redacted>").replace(Mn,"$1$2<redacted>").replace(Rn,"Bearer <redacted>")}var Gn=/(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 mt(e){let t=e.replace(/([a-z0-9])([A-Z])/g,"$1_$2").replace(/([A-Z]+)([A-Z][a-z])/g,"$1_$2");return Gn.test(t)}function yt(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 St(e,t,n=Pn){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 S(e,t=16384){return St(yt(ht(e)),t)}var Pe=100,Yn=8,Kn=8*1024;function le(){return{remaining:Kn}}function xe(e,t){let n=Math.min(16384,t.remaining),r=St(e,n);return t.remaining-=Buffer.byteLength(r,"utf8"),r}function $(e,t,n=0,r={}){if(n>Yn)return xe("<truncated>",t);if(typeof e=="string"){let i=ht(e);return xe(r.escapeControls?yt(i):i,t)}if(Array.isArray(e)){let i=e.slice(0,Pe),o=i.map(a=>$(a,t,n+1,r));return e.length>i.length&&o.push(xe(`<${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,Pe))i[a]=$(l,t,n+1,r);return o.length>Pe&&(i.output_truncated=!0),i}return e}var Ne=require("process");var Be=!1;function De(e){Be=e}function wt(){return Be}var _t="1";function M(e,t){if(Be){let n={...e};delete n.version;let r=le(),i={event:n.event,...n},o=$(i,r,0,{escapeControls:!0}),a=JSON.stringify({version:_t,...o});Buffer.byteLength(a,"utf8")+1>65536&&(a=JSON.stringify({version:_t,event:o.event,output_truncated:!0})),Ne.stderr.write(`${a}
4
+ `)}else Ne.stderr.write(t)}var Et="2",G=null,E=null,Y=!1,z=!1;function jn(){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=At.randomBytes(4).toString("hex");return ce.join(t,`allscale-output-${n}-${r}.ndjson`)}return null}var Ue=64*1024*1024,Hn=null;function $e(e={}){if(e.quiet&&(z=!0),Y)return;let t=jn();if(!t)return;G=null;let n=null;try{if((Hn??process.platform)==="win32")throw new Error("owner-only sidecar ACLs cannot be enforced on Windows; sidecar output is disabled");let r=ce.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{}z||M({event:"sidecar_disabled",reason:"open_failed",detail:S(`sidecar path '${t}' could not be opened safely (${r.message})`)},`${S(`[allscale] sidecar path '${t}' could not be opened safely (${r.message}); refusing to write. Sidecar disabled for this run.`)}
5
+ `);return}G=t,E=n,Y=!0}var Wn=[/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 qn(e){let t=e.replace(/([a-z0-9])([A-Z])/g,"$1_$2").replace(/([A-Z]+)([A-Z][a-z])/g,"$1_$2");return Wn.some(n=>n.test(t))}function Jn(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=zn(t.pathname);let i=n;t.pathname!==r&&(i=!0);for(let[o]of t.searchParams)qn(o)&&(t.searchParams.set(o,"<redacted>"),i=!0);return i?t.toString():e}catch{return e}}function zn(e){return e.replace(/(\/(?:api\/)?(?:v1\/)?public\/claim-links\/)([^/:]+)(:claim)?(?=\/?$)/,"$1<redacted>$3").replace(/(\/(?:api\/)?public\/claim-links\/)([^/]+)(\/claim)(?=\/?$)/,"$1<redacted>$3")}function Xn(e){return(e.type==="request"||e.type==="bridge_browser_open")&&typeof e.url=="string"?{...e,url:Jn(e.url)}:e}function Vn(e){let t=new Date().toISOString(),n=e,{type:r,...i}=n,o=$(i,le()),a=JSON.stringify({version:Et,timestamp:t,type:r,...o});return Buffer.byteLength(a,"utf8")+1>65536&&(a=JSON.stringify({version:Et,timestamp:t,type:r,output_truncated:!0})),a}function K(e){if(!Y||!G||E===null)return;let t=Xn(e),n=Vn(t);try{if(f.fstatSync(E).size+Buffer.byteLength(n,"utf8")+1>Ue){Y=!1;try{f.closeSync(E)}catch{}E=null,z||M({event:"sidecar_disabled",reason:"size_limit",...G===null?{}:{path:S(G)},max_bytes:Ue},`${S(`[allscale] sidecar exceeded ${Ue} bytes; disabling it for the rest of this run. Rotate or remove ${G}, or point ALLSCALE_OUTPUT_FILE_DIRECTORY at a directory so each run gets its own file.`)}
6
6
  `);return}f.appendFileSync(E,`${n}
7
- `)}catch(r){if($=!1,E!==null){try{f.closeSync(E)}catch{}E=null}try{D({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 yt(){return!!(process.env.ALLSCALE_OUTPUT_FILE_PATH||process.env.ALLSCALE_OUTPUT_FILE_DIRECTORY)}function oe(){if($=!1,E!==null){try{f.closeSync(E)}catch{}E=null}}function St(e=!1){let t=process.stdin.isTTY===!0&&process.stdout.isTTY===!0;return e||yt()||!t}var q=W()??Ze,G={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 se(e){return tt(e)?new URL(e).origin:null}function Y(e){try{let t=new URL(e);return`${t.protocol}//${t.host}`}catch{return"<unparseable URL>"}}function _t(){let e=process.env[G.TOKEN]?.trim();return e&&e.length>0?e:void 0}function Be(){let e=process.env[G.PROFILE]?.trim();return e&&e.length>0?e:void 0}function ae(){let e=process.env[G.API_BASE]?.trim();return e&&e.length>0?e:void 0}function Et(){let e=process.env[G.INSECURE_STORAGE]?.trim().toLowerCase();return e==="1"||e==="true"||e==="yes"}function wt(){let e=process.env[G.NO_KEYCHAIN]?.trim().toLowerCase();return e==="1"||e==="true"||e==="yes"}function At(){let e=process.env[G.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(W()===void 0&&q!==""&&"".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 ${q} (production), but a saved profile wins over the default,
7
+ `)}catch(r){if(Y=!1,E!==null){try{f.closeSync(E)}catch{}E=null}try{z||M({event:"sidecar_disabled",reason:"write_failed",detail:S(r.message)},`${S(`[allscale] sidecar write failed (${r.message}); disabling sidecar for the rest of this run.`)}
8
+ `)}catch{}}}function bt(){return!!(process.env.ALLSCALE_OUTPUT_FILE_PATH||process.env.ALLSCALE_OUTPUT_FILE_DIRECTORY)}function X(){if(z=!1,Y=!1,E!==null){try{f.closeSync(E)}catch{}E=null}}function ue(e=!1){let t=process.stdin.isTTY===!0&&process.stdout.isTTY===!0;return e||bt()||!t}var V=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"]),Zn=new Set(Array.from(V).filter(e=>e.startsWith("-")&&!e.startsWith("--")&&e.length===2)),Qn=Array.from(V).filter(e=>e.startsWith("--")).sort((e,t)=>t.length-e.length),er=new Set(["--otp-stdin","--password-stdin"]);function Fe(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(V.has(a)){t.push(`${a}=<redacted>`);continue}}}if(V.has(r)){t.push(r),n+1<e.length&&(V.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(Zn.has(o)){t.push(`${o}<redacted>`);continue}}let i=er.has(r)?void 0:Qn.find(o=>r.length>o.length&&r.startsWith(o));if(i){t.push(`${i}<redacted>`);continue}t.push(r)}return t}function Lt(e){K({type:"error",code:e.code,message:S(e.message)}),K({type:"command-end",ok:!1,exitCode:e.exitCode}),X()}var Z=J()??rt,H={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 Me(e){return st(e)?new URL(e).origin:null}function Q(e){try{let t=new URL(e);return`${t.protocol}//${t.host}`}catch{return"<unparseable URL>"}}function kt(){let e=process.env[H.TOKEN]?.trim();return e&&e.length>0?e:void 0}function Ge(){let e=process.env[H.PROFILE]?.trim();return e&&e.length>0?e:void 0}function ee(){let e=process.env[H.API_BASE]?.trim();return e&&e.length>0?e:void 0}function Ot(){let e=process.env[H.INSECURE_STORAGE]?.trim().toLowerCase();return e==="1"||e==="true"||e==="yes"}function Tt(){let e=process.env[H.NO_KEYCHAIN]?.trim().toLowerCase();return e==="1"||e==="true"||e==="yes"}function vt(){let e=process.env[H.ALLOW_RAW]?.trim().toLowerCase();return e==="1"||e==="true"||e==="yes"}function Ct(e){let{resolvedApiBase:t,fromExplicitOverride:n,profileApiBase:r,profileApiBaseSource:i}=e;if(J()===void 0&&Z!==""&&"".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 ${Z} (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: ${it} --api-base ${q}
14
- `}var K=w(require("fs")),Lt=w(require("os")),Ue=w(require("path")),De=w(require("@iarna/toml"));var $n=".allscale",Mn="config.toml";function V(){return Ue.join(Lt.homedir(),$n)}function Gn(){return Ue.join(V(),Mn)}function le(){let e=Gn();if(!K.existsSync(e))return{};let t=K.readFileSync(e,"utf-8");try{return De.parse(t)}catch(n){throw new c("internal",`Failed to parse ${e}: ${n.message}`)}}function kt(e){return Object.keys(e.profile??{}).sort()}function Ot(e,t){return e.profile?.[t]}function Tt(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 Fe(e){if(!Ee(e))throw new c("input.invalid",`Refusing to send credentials to API base ${Y(e)}. `+_e)}function It(e){let t=W();if(t===void 0||nt(e))return;let n=se(e),r=rt();if(r.length>0){let o=r.map(l=>se(l.base)).filter(l=>l!==null);if(n!==null&&o.includes(n))return;let a=r.map(l=>Y(l.base)).join(", ");throw new c("input.invalid",`Refusing to send to ${Y(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=se(t);if(!(n!==null&&n===i))throw new c("input.invalid",`Refusing to send to ${Y(e)} \u2014 this build only signs for ${Y(t)}. Re-login against this build's environment, or use a build for that one.`)}var Yn=require("@noble/hashes/sha3");var Ct=["USDT","USDC"];var pi=new Set([`0x${"0".repeat(40)}`,`0x${"0".repeat(36)}dead`]);var Pt=require("@oclif/core"),X=class e extends L.Command{static enableJsonFlag=!0;static legacyStagingNoticeShown=!1;static emitsOwnOutput=!1;static requiresEscapeHatch=!1;static requiresInput=!1;static isLocalOnly=!1;static baseFlags={profile:L.Flags.string({description:"Named profile from ~/.allscale/config.toml",helpGroup:"GLOBAL"}),token:L.Flags.string({description:"Override the access token for this invocation (precedence: --token > ALLSCALE_TOKEN > --profile)",helpGroup:"GLOBAL",hidden:J()==="public"}),"api-base":L.Flags.string({description:Se,helpGroup:"GLOBAL",hidden:J()==="public"}),"insecure-storage":L.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{Ne(this.jsonEnabled()),mt(),z({type:"session-start",command:this.id??"",argv:Hn(this.argv)});let t=this.constructor;if(J()==="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&&ae()!==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&&!At())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=St(this.jsonEnabled()),r=this.argv.length===0&&!n&&Zn(t)?this.config.findCommand(this.id??""):void 0;if(r){oe();let o=await(0,L.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 z({type:"command-end",ok:!0}),oe(),t.emitsOwnOutput?void 0:(this.jsonEnabled()||lt(i),{data:i})}catch(t){let n=at(t);z({type:"error",code:n.code,message:_(n.message)}),z({type:"command-end",ok:!1,exitCode:n.exitCode}),oe(),this.emitError(n),process.exitCode=n.exitCode;return}finally{Ne(!1)}}resolveSessionApiBaseChain(t){let n=le(),r=t.profile??void 0,i=t["api-base"]??void 0,o=r!==void 0||Be()!==void 0,a=Tt(n,r,Be()),l=Ot(n,a),u=i??ae(),d=u??l?.api_base??q,m=bt({resolvedApiBase:d,fromExplicitOverride:u!==void 0,profileApiBase:l?.api_base,profileApiBaseSource:l?.api_base_source});return m&&!e.legacyStagingNoticeShown&&(e.legacyStagingNoticeShown=!0,D({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||Fe(n),n}resolveContext(t){if(J()==="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&&ae()!==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||(Fe(i),It(i)),{apiBase:i,profile:a,token:n??_t(),insecureStorage:r||Et(),apiBaseSource:o!==void 0?"explicit":l!==void 0?"profile":"default",profileExplicit:u}}emitError(t){process.stderr.write(`${Xn(t)}
15
- `)}},ue=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"]),Kn=new Set(Array.from(ue).filter(e=>e.startsWith("-")&&!e.startsWith("--")&&e.length===2));function Hn(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(ue.has(o)){t.push(`${o}=<redacted>`);continue}}}if(ue.has(r)){t.push(r),n+1<e.length&&(ue.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(Kn.has(i)){t.push(`${i}<redacted>`);continue}}t.push(r)}return t}var jn=/(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 Wn(e){let t=e.replace(/([a-z0-9])([A-Z])/g,"$1_$2").replace(/([A-Z]+)([A-Z][a-z])/g,"$1_$2");return jn.test(t)}var Jn=/_(removed|cleared|count|total)$/i;function zn(e,t){return typeof t=="number"&&Jn.test(e)}var qn=new Set(Ct);function Vn(e,t){return e==="token_symbol"&&typeof t=="string"&&qn.has(t)}var ce=100;function $e(e,t=0){if(t>8)return"<truncated>";if(Array.isArray(e)){let n=e.slice(0,ce),r=n.map(i=>$e(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,ce))n[i]=Wn(i)&&!zn(i,o)&&!Vn(i,o)?"<redacted>":$e(o,t+1);if(r.length>ce){let i="<truncated>";for(;i in n;)i=`<${i}>`;n[i]=`${r.length-ce} more keys`}return n}return typeof e=="string"?_(e):e}function Xn(e){let t=pt()?void 0:2,n=$e(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 Zn(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))}var Yt=w(require("path"));var Ye=require("crypto"),s=w(require("fs")),h=w(require("path"));var de=1024*1024,Qn=5e3,er=20,tr=3e4,Me=4096,nr=new Int32Array(new SharedArrayBuffer(4)),Z=class extends Error{constructor(){super("credential-store data file must not have hard links"),this.name="PrivateCredentialFileHardLinkError"}};function O(e){return e instanceof Z}var S=class extends Error{constructor(){super("credential-store lock changed during concurrent inspection")}},rr=null;function H(){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 j(){return(rr??process.platform)!=="win32"}function Ft(e){try{return s.default.lstatSync(e),!1}catch(t){if(!g(t,"ENOENT"))throw t}try{let t=s.default.lstatSync(h.dirname(e));return!t.isSymbolicLink()&&t.isDirectory()}catch(t){if(g(t,"ENOENT"))return!0;throw t}}function g(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 ee(e,t){return e.dev===t.dev&&e.ino===t.ino}function ir(e){Atomics.wait(nr,0,0,e)}function $t(e){try{return process.kill(e,0),!0}catch(t){return!g(t,"ESRCH")}}function or(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function vt(e,t){let n=h.dirname(e);t&&s.default.mkdirSync(n,{recursive:!0,mode:448});let r;try{r=s.default.lstatSync(n)}catch(o){if(!t&&g(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()||!ee(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&&h.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 k(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&&g(o,"ENOENT")?new S:o}if(!ee(n,i))throw r.retryOnPathChange?new S: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 sr(e,t){if(t.size>de)throw new Error("credential-store file exceeds the maximum supported size");let n=Buffer.alloc(de+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>de)throw new Error("credential-store file exceeds the maximum supported size");return n.subarray(0,r).toString("utf8")}function Rt(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(g(i,"ENOENT"))try{if(s.default.lstatSync(e).isSymbolicLink())throw new Error("credential-store target must not be a symbolic link")}catch(o){if(g(o,"ENOENT"))return null;throw o}throw i}let n=s.default.fstatSync(t),r=k(e,t,n);return sr(t,r)}finally{t!==null&&s.default.closeSync(t)}}function Nt(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(g(i,"ENOENT")&&Ft(e))return;throw i}let n=s.default.fstatSync(t),r=k(e,t,n);C(e,r)}finally{t!==null&&s.default.closeSync(t)}Gt(h.dirname(e))}function ar(e){let t;try{t=s.default.lstatSync(e)}catch(n){if(g(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 lr(e,t){for(let n=0;n<8;n+=1){let r=(0,Ye.randomBytes)(12).toString("hex"),i=h.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(g(o,"EEXIST"))continue;throw o}}throw new Error("could not allocate a unique credential-store temp file")}function Mt(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 Gt(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 cr(e,t){let n=Buffer.from(t,"utf8");if(n.length>de)throw new Error("credential-store file exceeds the maximum supported size");let r=h.dirname(e),i=h.basename(e),o=null,a=null,l=!1;try{let u=lr(r,i);o=u.fd,a=u.tempPath;let d=s.default.fstatSync(o);if((k(a,o,d).mode&63)!==0&&process.platform!=="win32")throw new Error("credential-store temp file is not owner-only");Mt(o,n),s.default.fsyncSync(o),k(a,o,s.default.fstatSync(o));let p=o;o=null,s.default.closeSync(p),ar(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{}}Gt(r)}function ur(e){return h.join(h.dirname(e),`.${h.basename(e)}.lock`)}function dr(e){return h.join(h.dirname(e),`.${h.basename(e)}.lock-recovery`)}function fr(e,t){if(t.size>Me)return null;let n=Buffer.alloc(Me+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>Me)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 C(e,t){let n=s.default.lstatSync(e);if(n.isSymbolicLink()||!n.isFile()||!ee(n,t))throw new Error("credential-store lock changed while it was being inspected");Q(n,"credential-store lock"),s.default.unlinkSync(e)}function xt(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(g(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 S}catch(d){if(g(d,"ENOENT"))return{state:"absent"};throw d}throw u}let r=s.default.fstatSync(n),i=k(e,n,r,{allowMultipleLinks:!0,retryOnPathChange:!0}),o=fr(n,i);return{state:(o?.target===t&&o?!$t(o.pid):Date.now()-i.mtimeMs>=tr)?"stale":"active",stats:i}}finally{n!==null&&s.default.closeSync(n)}}function pr(e,t){for(let n=0;n<8;n+=1){let r=(0,Ye.randomBytes)(12).toString("hex"),i=h.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=k(i,a,l,{allowMultipleLinks:!0});return Mt(a,Buffer.from(JSON.stringify(o),"utf8")),s.default.fsyncSync(a),{claimPath:i,metadata:o,stats:u}}catch(l){if(g(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 gr(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 g(r,"ENOENT")?new S:r}try{let r=s.default.fstatSync(n),i=k(e,n,r,{allowMultipleLinks:!0,retryOnPathChange:!0});if(!ee(i,t))throw new S;return{fd:n,lockPath:e,stats:i}}catch(r){throw s.default.closeSync(n),r}}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(n){if(g(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 S}catch(r){if(g(r,"ENOENT"))return!1;throw r}throw n}return k(e,t,s.default.fstatSync(t),{allowMultipleLinks:!0,retryOnPathChange:!0}),!0}finally{t!==null&&s.default.closeSync(t)}}function hr(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(g(r,"EEXIST"))return null;throw r}let n=null;try{n=s.default.fstatSync(t);let r=k(e,t,n,{allowMultipleLinks:!0,retryOnPathChange:!0});return{fd:t,lockPath:e,stats:r}}catch(r){if(n!==null)try{C(e,n)}catch{}throw s.default.closeSync(t),r}}function I(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");ir(er)}function Ut(e){let t=h.dirname(e),n=h.basename(e),r=ur(e),i=dr(e),o=pr(t,n),a=Date.now()+Qn,l=!1,u=!1,d=null,m;try{for(;d===null;)try{if(Bt(i)){I(a,!0);continue}s.default.linkSync(o.claimPath,r),u=!0,d=gr(r,o.stats),l=!0}catch(p){if(u&&!l){try{C(r,o.stats)}catch{}u=!1}if(p instanceof S){I(a,!1);continue}if(!g(p,"EEXIST"))throw p;let y;try{y=xt(r,n)}catch(b){if(b instanceof S){I(a,!1);continue}throw b}if(y.state==="absent")continue;if(y.state==="stale"){let b;try{b=hr(i)}catch(x){if(x instanceof S){I(a,!1);continue}throw x}if(b!==null){try{let x;try{x=xt(r,n)}catch(qe){if(qe instanceof S){I(a,!1);continue}throw qe}x.state==="stale"&&C(r,x.stats)}finally{Ge(b)}continue}}let ze;try{ze=Bt(i)}catch(b){if(b instanceof S){I(a,!1);continue}throw b}I(a,ze)}}catch(p){m=p}try{C(o.claimPath,o.stats)}catch(p){!g(p,"ENOENT")&&!l&&m===void 0&&(m=p)}if(m!==void 0)throw m;if(d===null)throw new Error("credential-store lock acquisition failed");return d}function Ge(e){try{C(e.lockPath,e.stats)}finally{s.default.closeSync(e.fd)}}function mr(e,t){let n=or(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 Dt(e){let t=h.dirname(e),n=h.basename(e);for(let r of s.default.readdirSync(t)){let i=mr(r,n);if(i===null||$t(i))continue;let o=h.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(g(d,"ENOENT")||g(d,"ELOOP"))continue;throw d}let l=s.default.fstatSync(a),u=s.default.lstatSync(o);if(!l.isFile()||u.isSymbolicLink()||!u.isFile()||!ee(l,u))continue;try{Q(l,"credential-store orphan")}catch{continue}C(o,l)}catch(l){if(!g(l,"ENOENT"))throw l}finally{a!==null&&s.default.closeSync(a)}}}function A(e,t,n){if(!j()){if(t.allowUnsupportedPlatformCleanup){if(t.createParent)throw H();if(!vt(e,!1))return n({read:()=>null,remove:()=>{},write:()=>{throw H()}});let a=Ut(e);try{return Dt(e),n({read:()=>Rt(e),remove:()=>Nt(e),write:()=>{throw H()}})}finally{Ge(a)}}if(!t.createParent){let o=!1;try{o=Ft(e)}catch{throw H()}if(o)return n({read:()=>null,remove:()=>{},write:()=>{throw H()}})}throw H()}if(!vt(e,t.createParent))return n({read:()=>null,remove:()=>{},write:()=>{throw new Error("credential-store parent does not exist")}});let i=Ut(e);try{return Dt(e),n({read:()=>Rt(e),remove:()=>Nt(e),write:o=>cr(e,o)})}finally{Ge(i)}}var R="allscale-cli";function He(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Kt(e){return He(e)&&typeof e.access_token=="string"&&typeof e.refresh_token=="string"}function v(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 fe(){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 P,pe=!1;function Ht(){return wt()?"ALLSCALE_NO_KEYCHAIN":process.env.KEYTAR_DISABLE==="1"?"KEYTAR_DISABLE":null}function Sr(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 jt(){if(P!==void 0)return P;if(Ht())return pe=!1,P=null,P;try{P=require("keytar"),pe=!1}catch(e){pe=!Sr(e),P=null}return P}function Wt(){let e=Ht();return e||(pe?"the installed keytar/native keychain backend failed to load":null)}function Jt(){let e=j()?"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 N(e){try{return await e()}catch{throw Jt()}}function zt(){return jt()}var je=class{constructor(t){this.keytar=t}keytar;kind="keychain";async read(t){let n=await N(()=>this.keytar.getPassword(R,t));if(n===null)return null;let r;try{r=JSON.parse(n)}catch{throw v("OS keychain")}if(!Kt(r))throw v("OS keychain");return r}async get(t){return this.read(t)}async set(t,n){await this.read(t),await N(()=>this.keytar.setPassword(R,t,JSON.stringify(n)))}async delete(t){await this.read(t),await N(()=>this.keytar.deletePassword(R,t))}},_r="credentials.json",ge=class{kind="insecure-file";filePath;constructor(t){this.filePath=t??Yt.join(V(),_r)}read(t){let n;try{n=t.read()}catch(i){throw O(i)?Ke():v("plaintext file")}if(n===null)return{profiles:{}};let r;try{r=JSON.parse(n)}catch{throw v("plaintext file")}if(!He(r)||!He(r.profiles))throw v("plaintext file");return r}write(t,n){try{t.write(JSON.stringify(n,null,2))}catch(r){throw O(r)?Ke():fe()}}profileTokens(t,n){let r=t.profiles[n];if(r!==void 0){if(!Kt(r))throw v("plaintext file");return r}}async get(t){try{return A(this.filePath,{createParent:!1},n=>this.profileTokens(this.read(n),t)??null)}catch(n){throw n instanceof c?n:v("plaintext file")}}async set(t,n){try{A(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:fe()}}async delete(t){try{A(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:fe()}}async clearProfile(t){try{return A(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:O(n)?Ke():fe()}}};function qt(e={}){let t=[new ge(e.insecureFilePath)];if(e.includeKeychain!==!1){let n=jt();n&&t.push(new je(n))}return t}function Vt(e,t){if(!(e instanceof ge))throw new c("internal","Refusing plaintext cleanup through a non-file token store.");return e.clearProfile(t)}var Xt=w(require("path"));function te(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Er(e){return te(e)&&typeof e.api_key=="string"&&typeof e.api_secret=="string"}function Zt(e){return te(e)&&te(e.stores)&&Object.values(e.stores).every(Er)}function T(e){return new c("internal",`The store-HMAC credential store in the ${e} exists but could not be read as valid credential data. Refusing to treat it as empty or overwrite it; store credentials may still remain on this machine.`)}function We(){return new c("internal","The store-HMAC credential store in the plaintext file has multiple hard links. Refusing to read, modify, or delete it because another directory entry may retain store 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 he(){return new c("internal","The store-HMAC credential store in the plaintext file could not be written safely. Any previous credential file was left unchanged.")}var wr="store-credentials:",Je=class{constructor(t){this.keytar=t}keytar;kind="keychain";account(t){return`${wr}${t}`}async read(t){let n=await N(()=>this.keytar.getPassword(R,this.account(t)));if(n===null)return{stores:{}};let r;try{r=JSON.parse(n)}catch{throw T("OS keychain")}if(!Zt(r))throw T("OS keychain");return r}async write(t,n){if(Object.keys(n.stores).length===0){await N(()=>this.keytar.deletePassword(R,this.account(t)));return}await N(()=>this.keytar.setPassword(R,this.account(t),JSON.stringify(n)))}async get(t,n){return(await this.read(t)).stores[n]??null}async set(t,n,r){let i=await this.read(t);i.stores[n]=r,await this.write(t,i)}async delete(t,n){let r=await this.read(t);delete r.stores[n],await this.write(t,r)}async list(t){return(await this.read(t)).stores}},Ar="store-credentials.json",me=class{kind="insecure-file";filePath;constructor(t){this.filePath=t??Xt.join(V(),Ar)}read(t){let n;try{n=t.read()}catch(i){throw O(i)?We():T("plaintext file")}if(n===null)return{profiles:{}};let r;try{r=JSON.parse(n)}catch{throw T("plaintext file")}if(!te(r)||!te(r.profiles))throw T("plaintext file");return r}profileBundle(t,n){let r=t.profiles[n];if(r!==void 0){if(!Zt(r))throw T("plaintext file");return r}}write(t,n){try{t.write(JSON.stringify(n,null,2))}catch(r){throw O(r)?We():he()}}async get(t,n){try{return A(this.filePath,{createParent:!1},r=>{let i=this.read(r);return this.profileBundle(i,t)?.stores[n]??null})}catch(r){throw r instanceof c?r:T("plaintext file")}}async set(t,n,r){try{A(this.filePath,{createParent:!0},i=>{let o=this.read(i),a=this.profileBundle(o,t)??{stores:{}};a.stores[n]=r,o.profiles[t]=a,this.write(i,o)})}catch(i){throw i instanceof c?i:he()}}async delete(t,n){try{A(this.filePath,{createParent:!1},r=>{let i=this.read(r),o=this.profileBundle(i,t);!o||o.stores[n]===void 0||(delete o.stores[n],Object.keys(o.stores).length===0&&delete i.profiles[t],this.write(r,i))})}catch(r){throw r instanceof c?r:he()}}async list(t){try{return A(this.filePath,{createParent:!1},n=>{let r=this.read(n);return this.profileBundle(r,t)?.stores??{}})}catch(n){throw n instanceof c?n:T("plaintext file")}}async clearProfile(t){try{return A(this.filePath,{createParent:!1,allowUnsupportedPlatformCleanup:!0},n=>{let r=this.read(n),i=this.profileBundle(r,t);if(!i)return 0;let o=Object.keys(i.stores).length;return delete r.profiles[t],Object.keys(r.profiles).length===0?n.remove():this.write(n,r),o})}catch(n){throw n instanceof c?n:O(n)?We():he()}}};function Qt(e={}){let t=[new me(e.insecureFilePath)];if(e.includeKeychain!==!1){let n=zt();n&&t.push(new Je(n))}return t}function en(e,t){if(!(e instanceof me))throw new c("internal","Refusing plaintext cleanup through a non-file store-credential backend.");return e.clearProfile(t)}function tn(e,t={}){let n;try{n=kt(le())}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})}var ye=class e extends X{static description="Clear cached credentials (session token + store keys) for a profile. By default, clears BOTH the OS keychain and plaintext file store. With --insecure-storage or ALLSCALE_INSECURE_STORAGE=1, clears only plaintext files and never probes the keychain; omit/unset that opt-in when a full-machine sweep is wanted. If the keychain is suppressed or unavailable, a bare logout fails closed after attempting the plaintext-file cleanup.";static isLocalOnly=!0;static examples=["$ allscale logout","$ allscale logout --profile staging"];static flags={...X.baseFlags};async runCommand(){let{flags:t}=await this.parse(e),n=this.resolveContext(t),r=!n.insecureStorage,i=qt({includeKeychain:r}),o=Qt({includeKeychain:r}),a=!1,l=0,u=[];for(let p of i){let y=await Lr(p,n.profile);a||=y.removed,y.error&&u.push(y.error)}for(let p of o){let y=await kr(p,n.profile);l+=y.removed,y.error&&u.push(y.error)}let d=Wt(),m=i.some(p=>p.kind==="keychain")&&o.some(p=>p.kind==="keychain");if(!n.insecureStorage&&!m){let p=d??"the native keychain backend is unavailable or failed to load",y=br(p);u.push(`Could not inspect or clear the OS keychain because ${p}. Plaintext-file cleanup was still attempted, but session or store credentials may STILL remain on this machine. ${y}, repair any file-store errors above, and re-run bare 'allscale logout'.`)}if(u.length>0)throw new c("internal",u.join(" "),{profile:n.profile,removed:a,store_credentials_removed:l});if(!a&&l===0&&n.profileExplicit){let p=tn(n.profile,{messageSuffix:" Nothing was removed."});if(p)throw p}return{profile:n.profile,removed:a,store_credentials_removed:l}}};function br(e){return e==="ALLSCALE_NO_KEYCHAIN"||e==="KEYTAR_DISABLE"?"Re-enable keychain access":"Install or repair keychain support"}async function Lr(e,t){try{return!j()&&e.kind==="insecure-file"?{removed:await Vt(e,t)}:await e.get(t)?(await e.delete(t),{removed:!0}):{removed:!1}}catch(n){return{removed:!1,error:`Could not clear the session token for profile '${t}': ${nn(n)} The session credential may STILL remain on this machine; repair the credential store and re-run 'allscale logout'.`}}}async function kr(e,t){let n=0;try{if(!j()&&e.kind==="insecure-file")return{removed:await en(e,t)};let r=Object.keys(await e.list(t));for(let i of r)await e.delete(t,i),n+=1;return{removed:n}}catch(r){return{removed:n,error:`Could not fully clear store credentials for profile '${t}': ${nn(r)}. ${n} removed; any remaining store api_secret is STILL on this machine and can still authorize 'payout send'. Re-run 'allscale logout' once the credential store is reachable.`}}}function nn(e){return e instanceof Error?e.message:String(e)}
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 ${Z}
14
+ `}var C=A(require("fs")),It=A(require("os")),Ye=A(require("path")),Ke=A(require("@iarna/toml"));var rr=".allscale",ir="config.toml";function te(){return Ye.join(It.homedir(),rr)}function or(){return Ye.join(te(),ir)}function de(){let e=or();if(!C.existsSync(e))return{};let t=C.readFileSync(e,"utf-8");try{return Ke.parse(t)}catch(n){throw new c("internal",`Failed to parse ${e}: ${n.message}`)}}function Pt(e){return Object.keys(e.profile??{}).sort()}function xt(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 je(e){if(!Le(e))throw new c("input.invalid",`Refusing to send credentials to API base ${Q(e)}. `+be)}function Nt(e){let t=ar(e);if(t)throw new c("input.invalid",t.message)}function sr(){let e=J();if(e===void 0)return;let t=lt();return t.length>0?{endpoints:t.map(n=>n.base),fromPairs:!0}:{endpoints:[e],fromPairs:!1}}function ar(e){let t=sr();if(t===void 0||at(e))return;let{endpoints:n,fromPairs:r}=t,i=Me(e),o=n.map(l=>Me(l)).filter(l=>l!==null);if(i!==null&&o.includes(i))return;let a=n.map(l=>Q(l)).join(", ");return{message:r?`Refusing to send to ${Q(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.`:`Refusing to send to ${Q(e)} \u2014 this build only signs for ${a}. Re-login against this build's environment, or use a build for that one.`}}var lr=require("@noble/hashes/sha3");var Bt=["USDT","USDC"];var Ui=new Set([`0x${"0".repeat(40)}`,`0x${"0".repeat(36)}dead`]);var cr="unknown_otp_id",ur="invalid_code",dr="expired_code";function fr(e){return`'${e.replace(/'/g,"'\\''")}'`}function Dt(e){return`Run \`allscale otp-send --email ${fr(e)}\` first \u2014 that command does report a missing account \u2014 then retry with the otp_id it returns and a fresh code.`}var pr=new Map([[cr,(e,t)=>`${e}: this environment never issued the --otp-id you passed for '${t}', so the verification code was never the problem. The backend decides this by comparing the otp_id against that address alone, so it says nothing about whether the account exists. ${Dt(t)}`],[ur,e=>`${e}: the --otp-id is one this environment issued and a live code stands behind it \u2014 the verification code you passed is what does not match. Check for a typo \u2014 the backend invalidates the code after a few wrong answers, so if you are unsure, request a fresh code instead of guessing.`],[dr,(e,t,n)=>n?`${e}: this run's send request was accepted moments ago, but this attempt could not claim a live code for the --otp-id. Delivery is asynchronous and the code is stored only after the email goes out, so it may still be in flight \u2014 or the send may have failed outright, in which case no code is coming. The code you submitted may also have expired, been used, run out of attempts, or been replaced by a newer send. Check the inbox, including spam, and retry with whatever code arrived. If nothing arrives, confirm the address and wait at least three minutes before requesting one fresh code \u2014 sends are rate-limited per address, and retrying in a tight loop spends that budget even when the send is rejected.`:`${e}: this attempt could not claim a live code for the --otp-id. The code you submitted may have expired, been used, run out of attempts, been replaced by a later send, or never have been requested for this address; the backend does not distinguish those. If a newer code was delivered after the one you entered, use that one. ${Dt(t)}`]]);var Ut=[...pr.keys()];var ge=require("@oclif/core"),ne=class e extends k.Command{static enableJsonFlag=!0;static legacyStagingNoticeShown=!1;static emitsOwnOutput=!1;static requiresEscapeHatch=!1;static requiresInput=!1;static isLocalOnly=!1;static baseFlags={profile:k.Flags.string({description:"Named profile from ~/.allscale/config.toml",helpGroup:"GLOBAL"}),token:k.Flags.string({description:"Override the access token for this invocation (precedence: --token > ALLSCALE_TOKEN > --profile)",helpGroup:"GLOBAL",hidden:U()==="public"}),"api-base":k.Flags.string({description:Ae,helpGroup:"GLOBAL",hidden:U()==="public"}),"insecure-storage":k.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{De(this.jsonEnabled()),$e(),K({type:"session-start",command:this.id??"",argv:Fe(this.argv)});let t=this.constructor;if(U()==="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&&ee()!==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=ue(this.jsonEnabled()),r=this.argv.length===0&&!n&&Ar(t)?this.config.findCommand(this.id??""):void 0;if(r){X();let o=await(0,k.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&&!vt())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 K({type:"command-end",ok:!0}),X(),t.emitsOwnOutput?void 0:(this.jsonEnabled()||ft(i),{data:i})}catch(t){let n=dt(t);Lt({code:n.code,message:n.message,exitCode:n.exitCode}),this.emitError(n),process.exitCode=n.exitCode;return}finally{De(!1)}}resolveSessionApiBaseChain(t){let n=de(),r=t.profile??void 0,i=t["api-base"]??void 0,o=r!==void 0||Ge()!==void 0,a=Rt(n,r,Ge()),l=xt(n,a),u=U()==="public"&&ee()!==void 0,d=i??(u?void 0:ee()),m=d??l?.api_base??Z,y=Ct({resolvedApiBase:m,fromExplicitOverride:d!==void 0,profileApiBase:l?.api_base,profileApiBaseSource:l?.api_base_source});return y&&!e.legacyStagingNoticeShown&&(e.legacyStagingNoticeShown=!0,M({event:"legacy_staging_profile",api_base:m,profile:a},y)),{apiBase:m,explicitApiBase:d,envApiBaseIgnored:u,profileApiBase:l?.api_base,profile:a,profileExplicit:o}}resolveSessionApiBaseForPayoutDerivation(t){let{apiBase:n}=this.resolveSessionApiBaseChain(t);return this.constructor.isLocalOnly||je(n),n}resolveContext(t){if(U()==="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&&ee()!==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,envApiBaseIgnored:a,profile:l,profileApiBase:u,profileExplicit:d}=this.resolveSessionApiBaseChain(t);return this.constructor.isLocalOnly||(je(i),Nt(i)),{apiBase:i,profile:l,token:n??kt(),insecureStorage:r||Ot(),apiBaseSource:o!==void 0?"explicit":u!==void 0?"profile":"default",profileExplicit:d,envApiBaseIgnored:a}}emitError(t){process.stderr.write(`${Er(t)}
15
+ `)}};var gr=/_(removed|cleared|count|total)$/i;function hr(e,t){return typeof t=="number"&&gr.test(e)}var mr=new Set(Bt);function yr(e,t){return e==="token_symbol"&&typeof t=="string"&&mr.has(t)}var Sr=new Set(Ut);function _r(e,t){return e==="otp_reason"&&typeof t=="string"&&Sr.has(t)}var fe=100;function pe(e,t=0){if(t>8)return"<truncated>";if(Array.isArray(e)){let n=e.slice(0,fe),r=n.map(i=>pe(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,fe))n[i]=mt(i)&&!hr(i,o)&&!yr(i,o)&&!_r(i,o)?"<redacted>":pe(o,t+1);if(r.length>fe){let i="<truncated>";for(;i in n;)i=`<${i}>`;n[i]=`${r.length-fe} more keys`}return n}if(typeof e=="string"){let n=wr(e);return n!==void 0?S(JSON.stringify(pe(n,t+1))):S(e)}return e}function wr(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=wt()?void 0:2,n=pe(e.toJSON()),r=JSON.stringify(n,null,t);return Buffer.byteLength(r,"utf8")+1<=65536?r:JSON.stringify({error:{code:e.code,message:S(e.message),details:{output_truncated:!0,max_output_bytes:65536}}},null,t)}function Ar(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))}var He=require("process"),$t=require("readline");async function Ft(e){let t=(0,$t.createInterface)({input:process.stdin,output:He.stderr}),n;try{let r=await new Promise(o=>{let a=!1,l=u=>{a||(a=!0,o(u))};t.on("SIGINT",()=>l(void 0)),t.on("close",()=>l(void 0)),n=()=>l(void 0),process.on("SIGINT",n),t.question(`${e} [Y/n] `,l)});if(r===void 0)return He.stderr.write(`
16
+ `),!1;let i=r.trim().toLowerCase();return i===""||i==="y"||i==="yes"}finally{n&&process.removeListener("SIGINT",n),t.close()}}var Vt=A(require("path"));var Je=require("crypto"),s=A(require("fs")),g=A(require("path"));var he=1024*1024,br=5e3,Lr=20,kr=3e4,We=4096,Or=new Int32Array(new SharedArrayBuffer(4)),re=class extends Error{constructor(){super("credential-store data file must not have hard links"),this.name="PrivateCredentialFileHardLinkError"}};function T(e){return e instanceof re}var _=class extends Error{constructor(){super("credential-store lock changed during concurrent inspection")}},Tr=null;function W(){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 q(){return(Tr??process.platform)!=="win32"}function qt(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 ie(e,t){if(typeof process.geteuid=="function"&&e.uid!==process.geteuid())throw new Error(`${t} is not owned by the current effective user`)}function oe(e,t){return e.dev===t.dev&&e.ino===t.ino}function vr(e){Atomics.wait(Or,0,0,e)}function Jt(e){try{return process.kill(e,0),!0}catch(t){return!p(t,"ESRCH")}}function Cr(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Mt(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()||!oe(o,a))throw new Error("credential-store parent changed while it was being inspected");ie(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 O(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(!oe(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 re;if(ie(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 Ir(e,t){if(t.size>he)throw new Error("credential-store file exceeds the maximum supported size");let n=Buffer.alloc(he+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>he)throw new Error("credential-store file exceeds the maximum supported size");return n.subarray(0,r).toString("utf8")}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(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=O(e,t,n);return Ir(t,r)}finally{t!==null&&s.default.closeSync(t)}}function Yt(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")&&qt(e))return;throw i}let n=s.default.fstatSync(t),r=O(e,t,n);P(e,r)}finally{t!==null&&s.default.closeSync(t)}Xt(g.dirname(e))}function Pr(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 re;ie(t,"credential-store replacement target")}function xr(e,t){for(let n=0;n<8;n+=1){let r=(0,Je.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 zt(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 Xt(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 Rr(e,t){let n=Buffer.from(t,"utf8");if(n.length>he)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=xr(r,i);o=u.fd,a=u.tempPath;let d=s.default.fstatSync(o);if((O(a,o,d).mode&63)!==0&&process.platform!=="win32")throw new Error("credential-store temp file is not owner-only");zt(o,n),s.default.fsyncSync(o),O(a,o,s.default.fstatSync(o));let y=o;o=null,s.default.closeSync(y),Pr(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{}}Xt(r)}function Nr(e){return g.join(g.dirname(e),`.${g.basename(e)}.lock`)}function Br(e){return g.join(g.dirname(e),`.${g.basename(e)}.lock-recovery`)}function Dr(e,t){if(t.size>We)return null;let n=Buffer.alloc(We+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>We)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 P(e,t){let n=s.default.lstatSync(e);if(n.isSymbolicLink()||!n.isFile()||!oe(n,t))throw new Error("credential-store lock changed while it was being inspected");ie(n,"credential-store lock"),s.default.unlinkSync(e)}function Kt(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=O(e,n,r,{allowMultipleLinks:!0,retryOnPathChange:!0}),o=Dr(n,i);return{state:(o?.target===t&&o?!Jt(o.pid):Date.now()-i.mtimeMs>=kr)?"stale":"active",stats:i}}finally{n!==null&&s.default.closeSync(n)}}function Ur(e,t){for(let n=0;n<8;n+=1){let r=(0,Je.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=O(i,a,l,{allowMultipleLinks:!0});return zt(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 $r(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=O(e,n,r,{allowMultipleLinks:!0,retryOnPathChange:!0});if(!oe(i,t))throw new _;return{fd:n,lockPath:e,stats:i}}catch(r){throw s.default.closeSync(n),r}}function jt(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 O(e,t,s.default.fstatSync(t),{allowMultipleLinks:!0,retryOnPathChange:!0}),!0}finally{t!==null&&s.default.closeSync(t)}}function Fr(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=O(e,t,n,{allowMultipleLinks:!0,retryOnPathChange:!0});return{fd:t,lockPath:e,stats:r}}catch(r){if(n!==null)try{P(e,n)}catch{}throw s.default.closeSync(t),r}}function I(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");vr(Lr)}function Ht(e){let t=g.dirname(e),n=g.basename(e),r=Nr(e),i=Br(e),o=Ur(t,n),a=Date.now()+br,l=!1,u=!1,d=null,m;try{for(;d===null;)try{if(jt(i)){I(a,!0);continue}s.default.linkSync(o.claimPath,r),u=!0,d=$r(r,o.stats),l=!0}catch(y){if(u&&!l){try{P(r,o.stats)}catch{}u=!1}if(y instanceof _){I(a,!1);continue}if(!p(y,"EEXIST"))throw y;let h;try{h=Kt(r,n)}catch(L){if(L instanceof _){I(a,!1);continue}throw L}if(h.state==="absent")continue;if(h.state==="stale"){let L;try{L=Fr(i)}catch(D){if(D instanceof _){I(a,!1);continue}throw D}if(L!==null){try{let D;try{D=Kt(r,n)}catch(et){if(et instanceof _){I(a,!1);continue}throw et}D.state==="stale"&&P(r,D.stats)}finally{qe(L)}continue}}let w;try{w=jt(i)}catch(L){if(L instanceof _){I(a,!1);continue}throw L}I(a,w)}}catch(y){m=y}try{P(o.claimPath,o.stats)}catch(y){!p(y,"ENOENT")&&!l&&m===void 0&&(m=y)}if(m!==void 0)throw m;if(d===null)throw new Error("credential-store lock acquisition failed");return d}function qe(e){try{P(e.lockPath,e.stats)}finally{s.default.closeSync(e.fd)}}function Mr(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 Wt(e){let t=g.dirname(e),n=g.basename(e);for(let r of s.default.readdirSync(t)){let i=Mr(r,n);if(i===null||Jt(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()||!oe(l,u))continue;try{ie(l,"credential-store orphan")}catch{continue}P(o,l)}catch(l){if(!p(l,"ENOENT"))throw l}finally{a!==null&&s.default.closeSync(a)}}}function b(e,t,n){if(!q()){if(t.allowUnsupportedPlatformCleanup){if(t.createParent)throw W();if(!Mt(e,!1))return n({read:()=>null,remove:()=>{},write:()=>{throw W()}});let a=Ht(e);try{return Wt(e),n({read:()=>Gt(e),remove:()=>Yt(e),write:()=>{throw W()}})}finally{qe(a)}}if(!t.createParent){let o=!1;try{o=qt(e)}catch{throw W()}if(o)return n({read:()=>null,remove:()=>{},write:()=>{throw W()}})}throw W()}if(!Mt(e,t.createParent))return n({read:()=>null,remove:()=>{},write:()=>{throw new Error("credential-store parent does not exist")}});let i=Ht(e);try{return Wt(e),n({read:()=>Gt(e),remove:()=>Yt(e),write:o=>Rr(e,o)})}finally{qe(i)}}var N="allscale-cli";function Xe(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Zt(e){return Xe(e)&&typeof e.access_token=="string"&&typeof e.refresh_token=="string"}function R(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 ze(){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 me(){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 x,ye=!1;function Qt(){return Tt()?"ALLSCALE_NO_KEYCHAIN":process.env.KEYTAR_DISABLE==="1"?"KEYTAR_DISABLE":null}function Yr(e){if(typeof e!="object"||e===null||e.code!=="MODULE_NOT_FOUND")return!1;let t=e.message;return typeof t=="string"&&t.split(`
17
+ `,1)[0]==="Cannot find module 'keytar'"}function en(){if(x!==void 0)return x;if(Qt())return ye=!1,x=null,x;try{x=require("keytar"),ye=!1}catch(e){ye=!Yr(e),x=null}return x}function tn(){let e=Qt();return e||(ye?"the installed keytar/native keychain backend failed to load":null)}function nn(){let e=q()?"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 B(e){try{return await e()}catch{throw nn()}}function rn(){return en()}var Ve=class{constructor(t){this.keytar=t}keytar;kind="keychain";async read(t){let n=await B(()=>this.keytar.getPassword(N,t));if(n===null)return null;let r;try{r=JSON.parse(n)}catch{throw R("OS keychain")}if(!Zt(r))throw R("OS keychain");return r}async get(t){return this.read(t)}async set(t,n){await this.read(t),await B(()=>this.keytar.setPassword(N,t,JSON.stringify(n)))}async delete(t){await this.read(t),await B(()=>this.keytar.deletePassword(N,t))}},Kr="credentials.json",Se=class{kind="insecure-file";filePath;constructor(t){this.filePath=t??Vt.join(te(),Kr)}read(t){let n;try{n=t.read()}catch(i){throw T(i)?ze():R("plaintext file")}if(n===null)return{profiles:{}};let r;try{r=JSON.parse(n)}catch{throw R("plaintext file")}if(!Xe(r)||!Xe(r.profiles))throw R("plaintext file");return r}write(t,n){try{t.write(JSON.stringify(n,null,2))}catch(r){throw T(r)?ze():me()}}profileTokens(t,n){let r=t.profiles[n];if(r!==void 0){if(!Zt(r))throw R("plaintext file");return r}}async get(t){try{return b(this.filePath,{createParent:!1},n=>this.profileTokens(this.read(n),t)??null)}catch(n){throw n instanceof c?n:R("plaintext file")}}async set(t,n){try{b(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:me()}}async delete(t){try{b(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:me()}}async clearProfile(t){try{return b(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:T(n)?ze():me()}}};function on(e={}){let t=[new Se(e.insecureFilePath)];if(e.includeKeychain!==!1){let n=en();n&&t.push(new Ve(n))}return t}function sn(e,t){if(!(e instanceof Se))throw new c("internal","Refusing plaintext cleanup through a non-file token store.");return e.clearProfile(t)}var an=A(require("path"));function se(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function jr(e){return se(e)&&typeof e.api_key=="string"&&typeof e.api_secret=="string"}function ln(e){return se(e)&&se(e.stores)&&Object.values(e.stores).every(jr)}function v(e){return new c("internal",`The store-HMAC credential store in the ${e} exists but could not be read as valid credential data. Refusing to treat it as empty or overwrite it; store credentials may still remain on this machine.`)}function Ze(){return new c("internal","The store-HMAC credential store in the plaintext file has multiple hard links. Refusing to read, modify, or delete it because another directory entry may retain store 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 _e(){return new c("internal","The store-HMAC credential store in the plaintext file could not be written safely. Any previous credential file was left unchanged.")}var Hr="store-credentials:",Qe=class{constructor(t){this.keytar=t}keytar;kind="keychain";account(t){return`${Hr}${t}`}async read(t){let n=await B(()=>this.keytar.getPassword(N,this.account(t)));if(n===null)return{stores:{}};let r;try{r=JSON.parse(n)}catch{throw v("OS keychain")}if(!ln(r))throw v("OS keychain");return r}async write(t,n){if(Object.keys(n.stores).length===0){await B(()=>this.keytar.deletePassword(N,this.account(t)));return}await B(()=>this.keytar.setPassword(N,this.account(t),JSON.stringify(n)))}async get(t,n){return(await this.read(t)).stores[n]??null}async set(t,n,r){let i=await this.read(t);i.stores[n]=r,await this.write(t,i)}async delete(t,n){let r=await this.read(t);delete r.stores[n],await this.write(t,r)}async list(t){return(await this.read(t)).stores}},Wr="store-credentials.json",we=class{kind="insecure-file";filePath;constructor(t){this.filePath=t??an.join(te(),Wr)}read(t){let n;try{n=t.read()}catch(i){throw T(i)?Ze():v("plaintext file")}if(n===null)return{profiles:{}};let r;try{r=JSON.parse(n)}catch{throw v("plaintext file")}if(!se(r)||!se(r.profiles))throw v("plaintext file");return r}profileBundle(t,n){let r=t.profiles[n];if(r!==void 0){if(!ln(r))throw v("plaintext file");return r}}write(t,n){try{t.write(JSON.stringify(n,null,2))}catch(r){throw T(r)?Ze():_e()}}async get(t,n){try{return b(this.filePath,{createParent:!1},r=>{let i=this.read(r);return this.profileBundle(i,t)?.stores[n]??null})}catch(r){throw r instanceof c?r:v("plaintext file")}}async set(t,n,r){try{b(this.filePath,{createParent:!0},i=>{let o=this.read(i),a=this.profileBundle(o,t)??{stores:{}};a.stores[n]=r,o.profiles[t]=a,this.write(i,o)})}catch(i){throw i instanceof c?i:_e()}}async delete(t,n){try{b(this.filePath,{createParent:!1},r=>{let i=this.read(r),o=this.profileBundle(i,t);!o||o.stores[n]===void 0||(delete o.stores[n],Object.keys(o.stores).length===0&&delete i.profiles[t],this.write(r,i))})}catch(r){throw r instanceof c?r:_e()}}async list(t){try{return b(this.filePath,{createParent:!1},n=>{let r=this.read(n);return this.profileBundle(r,t)?.stores??{}})}catch(n){throw n instanceof c?n:v("plaintext file")}}async clearProfile(t){try{return b(this.filePath,{createParent:!1,allowUnsupportedPlatformCleanup:!0},n=>{let r=this.read(n),i=this.profileBundle(r,t);if(!i)return 0;let o=Object.keys(i.stores).length;return delete r.profiles[t],Object.keys(r.profiles).length===0?n.remove():this.write(n,r),o})}catch(n){throw n instanceof c?n:T(n)?Ze():_e()}}};function cn(e={}){let t=[new we(e.insecureFilePath)];if(e.includeKeychain!==!1){let n=rn();n&&t.push(new Qe(n))}return t}function un(e,t){if(!(e instanceof we))throw new c("internal","Refusing plaintext cleanup through a non-file store-credential backend.");return e.clearProfile(t)}function dn(e,t={}){let n;try{n=Pt(de())}catch{return}if(!(n.length===0||n.includes(e)))return new c("auth.unknown_profile",ut(e)+(t.messageSuffix??""),{profile:e})}var Ee=class e extends ne{static description="Clear cached credentials (session token + store keys) for a profile. By default, clears BOTH the OS keychain and plaintext file store. With --insecure-storage or ALLSCALE_INSECURE_STORAGE=1, clears only plaintext files and never probes the keychain; omit/unset that opt-in when a full-machine sweep is wanted. If the keychain is suppressed or unavailable, a bare logout fails closed after attempting the plaintext-file cleanup. A bare interactive invocation asks for confirmation before anything is removed; any flag (or --yes) skips the prompt, and machine callers are never prompted.";static isLocalOnly=!0;static examples=["$ allscale logout --profile staging","$ allscale logout --yes"];static flags={yes:ge.Flags.boolean({char:"y",description:"Skip the interactive confirmation and clear the credentials immediately. Only a BARE invocation is ever prompted, so passing any flag already skips it; use this to say so explicitly. Automation that allocates a pty for stdin/stdout/stderr and runs the command bare is indistinguishable from a human \u2014 that is the case this flag exists for.",default:!1}),...ne.baseFlags};async runCommand(){let{flags:t}=await this.parse(e),n=this.resolveContext(t);if(this.argv.length===0&&!t.yes&&!ue(this.jsonEnabled())&&process.stderr.isTTY===!0&&(process.stderr.write(`\`allscale logout\` will now:
18
+ - delete the stored session credential for profile '${n.profile}'
19
+ - delete any stored store keys (payout credentials) for that profile
20
+ `+(n.insecureStorage?` - touch only the plaintext files under ~/.allscale (the OS keychain is never probed)
21
+ `:` - sweep both the OS keychain and the plaintext files under ~/.allscale
22
+ `)),!await Ft("Clear these credentials?")))throw new c("user.cancelled","Logout cancelled \u2014 no credentials were removed.");let i=!n.insecureStorage,o=on({includeKeychain:i}),a=cn({includeKeychain:i}),l=!1,u=0,d=[];for(let h of o){let w=await Jr(h,n.profile);l||=w.removed,w.error&&d.push(w.error)}for(let h of a){let w=await zr(h,n.profile);u+=w.removed,w.error&&d.push(w.error)}let m=tn(),y=o.some(h=>h.kind==="keychain")&&a.some(h=>h.kind==="keychain");if(!n.insecureStorage&&!y){let h=m??"the native keychain backend is unavailable or failed to load",w=qr(h);d.push(`Could not inspect or clear the OS keychain because ${h}. Plaintext-file cleanup was still attempted, but session or store credentials may STILL remain on this machine. ${w}, repair any file-store errors above, and re-run bare 'allscale logout'.`)}if(d.length>0)throw new c("internal",d.join(" "),{profile:n.profile,removed:l,store_credentials_removed:u});if(!l&&u===0&&n.profileExplicit){let h=dn(n.profile,{messageSuffix:" Nothing was removed."});if(h)throw h}return{profile:n.profile,removal_status:l||u>0?"removed":n.insecureStorage?"skipped":"nothing_to_remove",removed:l,store_credentials_removed:u}}};function qr(e){return e==="ALLSCALE_NO_KEYCHAIN"||e==="KEYTAR_DISABLE"?"Re-enable keychain access":"Install or repair keychain support"}async function Jr(e,t){try{return!q()&&e.kind==="insecure-file"?{removed:await sn(e,t)}:await e.get(t)?(await e.delete(t),{removed:!0}):{removed:!1}}catch(n){return{removed:!1,error:`Could not clear the session token for profile '${t}': ${fn(n)} The session credential may STILL remain on this machine; repair the credential store and re-run 'allscale logout'.`}}}async function zr(e,t){let n=0;try{if(!q()&&e.kind==="insecure-file")return{removed:await un(e,t)};let r=Object.keys(await e.list(t));for(let i of r)await e.delete(t,i),n+=1;return{removed:n}}catch(r){return{removed:n,error:`Could not fully clear store credentials for profile '${t}': ${fn(r)}. ${n} removed; any remaining store api_secret is STILL on this machine and can still authorize 'payout send'. Re-run 'allscale logout' once the credential store is reachable.`}}}function fn(e){return e instanceof Error?e.message:String(e)}
17
23
  //# sourceMappingURL=logout.js.map
@@ -1,16 +1,16 @@
1
- "use strict";var Ye=Object.create;var U=Object.defineProperty;var He=Object.getOwnPropertyDescriptor;var je=Object.getOwnPropertyNames;var qe=Object.getPrototypeOf,Ke=Object.prototype.hasOwnProperty;var ze=(e,n)=>{for(var t in n)U(e,t,{get:n[t],enumerable:!0})},pe=(e,n,t,i)=>{if(n&&typeof n=="object"||typeof n=="function")for(let a of je(n))!Ke.call(e,a)&&a!==t&&U(e,a,{get:()=>n[a],enumerable:!(i=He(n,a))||i.enumerable});return e};var y=(e,n,t)=>(t=e!=null?Ye(qe(e)):{},pe(n||!e||!e.__esModule?U(t,"default",{value:e,enumerable:!0}):t,e)),We=e=>pe(U({},"__esModule",{value:!0}),e);var Vn={};ze(Vn,{default:()=>V});module.exports=We(Vn);var f=require("@oclif/core");var ce="public",me="https://app.allscale.io";var fe=["https://app.allscale.io"];var G="Override the API base URL (public builds accept only https://app.allscale.io)";var M="Only https://app.allscale.io is allowed, and URL userinfo is forbidden.";function ye(e){try{let n=new URL(e);return n.username.length>0||n.password.length>0?null:n.protocol==="https:"?n:null}catch{return null}}function Ae(e){return ye(e)!==null}function J(e){let n=ye(e);return n!==null&&fe.includes(n.origin)}function C(){return"".trim()||void 0}function b(){return"public"}function _e(e){try{let{hostname:n}=new URL(e);return n==="127.0.0.1"||n==="localhost"||n==="[::1]"}catch{return!1}}function Le(){{let e="[]".trim();if(e.length===0)return[];try{let n=JSON.parse(e);return Array.isArray(n)?n:[]}catch{return[]}}return Y()}function Y(){let e=process.env.ALLSCALE_BUILD_PAIRS?.trim()??"";if(e.length>0)try{let i=JSON.parse(e);if(!Array.isArray(i))return[];let a=[];for(let o of i){if(typeof o!="object"||o===null)continue;let{base:r,key:s,keyId:u}=o;if(typeof r!="string"||r.trim().length===0||typeof s!="string"||s.trim().length===0)continue;let m=typeof u=="string"?u.trim():"";a.push({base:r.trim(),key:s,keyId:m.length>0?m:"cli-1"})}return a}catch{return[]}let n=process.env.ALLSCALE_SIGNING_KEY??"",t=process.env.ALLSCALE_BUILD_API_BASE?.trim()??"";if(n.trim().length>0&&t.length>0){let i=process.env.ALLSCALE_SIGNING_KEY_ID?.trim();return[{base:t,key:n,keyId:i&&i.length>0?i:"cli-1"}]}return[]}var Te="allscale device-login";var Ze={"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},Xe=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 q(e){return(typeof e=="string"?e:String(e??"")).replace(Xe,"")}var Qe=64;function H(e,n=new Map,t=0){if(typeof e=="string")return q(e);if(e===null||typeof e!="object")return e;let i=n.get(e);if(i!==void 0)return i;if(t>=Qe)return e;if(Array.isArray(e)){let r=[];n.set(e,r);for(let s of e)r.push(H(s,n,t+1));return r}let a=Object.getPrototypeOf(e);if(a!==Object.prototype&&a!==null)return e;let o={};n.set(e,o);for(let[r,s]of Object.entries(e))Object.defineProperty(o,r,{value:H(s,n,t+1),writable:!0,enumerable:!0,configurable:!0});return o}var d=class extends Error{code;details;constructor(n,t,i){super(q(t)),this.code=n,this.details=i&&H(i),this.name="AllscaleError"}get exitCode(){return Ze[this.code]}toJSON(){return{error:{code:this.code,message:this.message,...this.details?{details:this.details}:{}}}}};function Se(e){if(e instanceof d)return e;if(e instanceof Error){if(tn(e)){let n=on(e),t={};return e.name&&e.name!=="Error"&&(t.name=e.name),Object.keys(n).length>0&&(t.oclif=n),new d("input.invalid",e.message,Object.keys(t).length>0?t:void 0)}return new d("internal",e.message,{name:e.name})}return new d("internal","Unknown error",{value:String(e)})}var en=new Set(["CLIError","CLIParseError","RequiredArgsError","RequiredFlagError","UnexpectedArgsError","FlagInvalidOptionError","ArgInvalidOptionError","InvalidArgsSpecError"]),nn=[/^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 tn(e){if(an(e))return!0;let n=e.name??"";return en.has(n)?n==="CLIError"?j(e,"parse")||ge(e.message):!0:ge(e.message)}function an(e){if(!j(e,"oclif"))return!1;let n=e.oclif;return typeof n=="object"&&n!==null&&n.exit===2&&j(e,"parse")}function ge(e){return e?q(e).split(`
2
- `).some(n=>nn.some(t=>t.test(n.trim()))):!1}function j(e,n){return typeof e=="object"&&e!==null&&Object.prototype.hasOwnProperty.call(e,n)}function on(e){let n=e,t={};for(let i of["code","exitCode","suggestions","ref"])n[i]!==void 0&&(t[i]=n[i]);return t}function ke(e){process.stdout.write(`${JSON.stringify({data:e},null,2)}
3
- `)}var l=y(require("fs")),P=y(require("path")),Ie=y(require("crypto"));var rn="...<truncated>",sn=/\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]+/g,ln=/\bBearer\s+[A-Za-z0-9._~+/=-]{12,}/gi,Q=String.raw`(?:(?:Bearer|Basic)\s+)?(?:"(?:\\.|[^"\\\r\n])*"|'(?:\\.|[^'\\\r\n])*'|[^\s,;)}\]]+)`,K=String.raw`(?:proxy[_-]?)?authorization`,dn=new RegExp(String.raw`(^|[^A-Za-z0-9])((?:"${K}"|'${K}'|${K})\s*[:=]\s*)((?:Bearer|Basic)\s+)?(?!<redacted(?:-jwt)?>)${Q}`,"gi"),un=/\b(https?:\/\/)[^\s/?#]+@/gi,z=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)`,pn=new RegExp(String.raw`(^|[^A-Za-z0-9])((?:"${z}"|'${z}'|${z})\s*[:=]\s*)(?!<redacted(?:-jwt)?>)${Q}`,"gi"),W=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)`,cn=new RegExp(String.raw`(^|[^A-Za-z0-9])((?:"${W}"|'${W}'|${W})\s*[:=]\s*)(?!<redacted(?:-jwt)?>)${Q}`,"g");function he(e){return e.replace(un,"$1<redacted>@").replace(sn,"<redacted-jwt>").replace(dn,"$1$2$3<redacted>").replace(pn,"$1$2<redacted>").replace(cn,"$1$2<redacted>").replace(ln,"Bearer <redacted>")}function Ne(e){let n="";for(let t of e){let i=t.codePointAt(0),a=i<=8||i>=11&&i<=12||i>=14&&i<=31||i>=127&&i<=159;n+=a?`\\u${i.toString(16).padStart(4,"0")}`:t}return n}function Ce(e,n,t=rn){if(n<=0)return"";if(Buffer.byteLength(e,"utf8")<=n)return e;let i=Buffer.byteLength(t,"utf8");if(i>=n){let s="",u=0;for(let m of t){let A=Buffer.byteLength(m,"utf8");if(u+A>n)break;s+=m,u+=A}return s}let a=n-i,o="",r=0;for(let s of e){let u=Buffer.byteLength(s,"utf8");if(r+u>a)break;o+=s,r+=u}return`${o}${t}`}function c(e,n=16384){return Ce(Ne(he(e)),n)}var Z=100,mn=8,fn=8*1024;function B(){return{remaining:fn}}function X(e,n){let t=Math.min(16384,n.remaining),i=Ce(e,t);return n.remaining-=Buffer.byteLength(i,"utf8"),i}function _(e,n,t=0,i={}){if(t>mn)return X("<truncated>",n);if(typeof e=="string"){let a=he(e);return X(i.escapeControls?Ne(a):a,n)}if(Array.isArray(e)){let a=e.slice(0,Z),o=a.map(r=>_(r,n,t+1,i));return e.length>a.length&&o.push(X(`<${e.length-a.length} more items truncated>`,n)),o}if(e!==null&&typeof e=="object"){let a=Object.create(null),o=Object.entries(e);for(let[r,s]of o.slice(0,Z))a[r]=_(s,n,t+1,i);return o.length>Z&&(a.output_truncated=!0),a}return e}var ee=require("process");var ne=!1;function te(e){ne=e}function Ee(){return ne}var be="1";function T(e,n){if(ne){let t={...e};delete t.version;let i=B(),a={event:t.event,...t},o=_(a,i,0,{escapeControls:!0}),r=JSON.stringify({version:be,...o});Buffer.byteLength(r,"utf8")+1>65536&&(r=JSON.stringify({version:be,event:o.event,output_truncated:!0})),ee.stderr.write(`${r}
4
- `)}else ee.stderr.write(n)}var Oe="2",g=null,p=null,S=!1;function yn(){let e=process.env.ALLSCALE_OUTPUT_FILE_PATH;if(e)return e;let n=process.env.ALLSCALE_OUTPUT_FILE_DIRECTORY;if(n){let t=new Date().toISOString().replace(/[:.]/g,"-"),i=Ie.randomBytes(4).toString("hex");return P.join(n,`allscale-output-${t}-${i}.ndjson`)}return null}var ie=64*1024*1024,An=null;function Re(){if(S)return;let e=yn();if(!e)return;g=null;let n=null;try{if((An??process.platform)==="win32")throw new Error("owner-only sidecar ACLs cannot be enforced on Windows; sidecar output is disabled");let t=P.dirname(e);if(l.mkdirSync(t,{recursive:!0,mode:448}),!process.env.ALLSCALE_OUTPUT_FILE_PATH&&process.env.ALLSCALE_OUTPUT_FILE_DIRECTORY){let s=l.statSync(t),u=s.mode&511;if(!s.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 i=l.constants.O_NOFOLLOW??0;n=l.openSync(e,l.constants.O_APPEND|l.constants.O_CREAT|l.constants.O_WRONLY|(l.constants.O_NONBLOCK??0)|i,384);let a=l.fstatSync(n),o=l.lstatSync(e);if(!a.isFile()||o.isSymbolicLink()||o.dev!==a.dev||o.ino!==a.ino)throw new Error("target changed while it was being opened or is not a regular file");if(typeof process.geteuid=="function"&&a.uid!==process.geteuid())throw new Error("existing sidecar file is not owned by the current effective user");let r=a.mode&511;if((r&63)!==0)throw new Error(`existing sidecar file must already be owner-only; current mode is ${r.toString(8).padStart(3,"0")}. Rotate or remove it before retrying`);l.fchmodSync(n,384)}catch(t){if(n!==null)try{l.closeSync(n)}catch{}T({event:"sidecar_disabled",reason:"open_failed",detail:c(`sidecar path '${e}' could not be opened safely (${t.message})`)},`${c(`[allscale] sidecar path '${e}' could not be opened safely (${t.message}); refusing to write. Sidecar disabled for this run.`)}
5
- `);return}g=e,p=n,S=!0}var _n=[/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 Ln(e){let n=e.replace(/([a-z0-9])([A-Z])/g,"$1_$2").replace(/([A-Z]+)([A-Z][a-z])/g,"$1_$2");return _n.some(t=>t.test(n))}function Tn(e){try{let n=new URL(e),t=n.username.length>0||n.password.length>0;t&&(n.username="",n.password="");let i=n.pathname;n.pathname=gn(n.pathname);let a=t;n.pathname!==i&&(a=!0);for(let[o]of n.searchParams)Ln(o)&&(n.searchParams.set(o,"<redacted>"),a=!0);return a?n.toString():e}catch{return e}}function gn(e){return e.replace(/(\/(?:api\/)?(?:v1\/)?public\/claim-links\/)([^/:]+)(:claim)?(?=\/?$)/,"$1<redacted>$3").replace(/(\/(?:api\/)?public\/claim-links\/)([^/]+)(\/claim)(?=\/?$)/,"$1<redacted>$3")}function Sn(e){return(e.type==="request"||e.type==="bridge_browser_open")&&typeof e.url=="string"?{...e,url:Tn(e.url)}:e}function kn(e){let n=new Date().toISOString(),t=e,{type:i,...a}=t,o=_(a,B()),r=JSON.stringify({version:Oe,timestamp:n,type:i,...o});return Buffer.byteLength(r,"utf8")+1>65536&&(r=JSON.stringify({version:Oe,timestamp:n,type:i,output_truncated:!0})),r}function E(e){if(!S||!g||p===null)return;let n=Sn(e),t=kn(n);try{if(l.fstatSync(p).size+Buffer.byteLength(t,"utf8")+1>ie){S=!1;try{l.closeSync(p)}catch{}p=null,T({event:"sidecar_disabled",reason:"size_limit",...g===null?{}:{path:c(g)},max_bytes:ie},`${c(`[allscale] sidecar exceeded ${ie} bytes; disabling it for the rest of this run. Rotate or remove ${g}, or point ALLSCALE_OUTPUT_FILE_DIRECTORY at a directory so each run gets its own file.`)}
6
- `);return}l.appendFileSync(p,`${t}
7
- `)}catch(i){if(S=!1,p!==null){try{l.closeSync(p)}catch{}p=null}try{T({event:"sidecar_disabled",reason:"write_failed",detail:c(i.message)},`${c(`[allscale] sidecar write failed (${i.message}); disabling sidecar for the rest of this run.`)}
8
- `)}catch{}}}function we(){return!!(process.env.ALLSCALE_OUTPUT_FILE_PATH||process.env.ALLSCALE_OUTPUT_FILE_DIRECTORY)}function v(){if(S=!1,p!==null){try{l.closeSync(p)}catch{}p=null}}function Ue(e=!1){let n=process.stdin.isTTY===!0&&process.stdout.isTTY===!0;return e||we()||!n}var O=C()??me,I={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 x(e){return Ae(e)?new URL(e).origin:null}function h(e){try{let n=new URL(e);return`${n.protocol}//${n.host}`}catch{return"<unparseable URL>"}}function Be(){let e=process.env[I.TOKEN]?.trim();return e&&e.length>0?e:void 0}function ae(){let e=process.env[I.PROFILE]?.trim();return e&&e.length>0?e:void 0}function D(){let e=process.env[I.API_BASE]?.trim();return e&&e.length>0?e:void 0}function Pe(){let e=process.env[I.INSECURE_STORAGE]?.trim().toLowerCase();return e==="1"||e==="true"||e==="yes"}function ve(){let e=process.env[I.ALLOW_RAW]?.trim().toLowerCase();return e==="1"||e==="true"||e==="yes"}function xe(e){let{resolvedApiBase:n,fromExplicitOverride:t,profileApiBase:i,profileApiBaseSource:a}=e;if(C()===void 0&&O!==""&&"".length!==0&&!t&&a!=="explicit"&&i===""&&n==="")return`Notice: this profile is pinned to ${""} (staging) in ~/.allscale/config.toml.
9
- The CLI default is now ${O} (production), but a saved profile wins over the default,
1
+ "use strict";var Ze=Object.create;var x=Object.defineProperty;var Xe=Object.getOwnPropertyDescriptor;var Qe=Object.getOwnPropertyNames;var en=Object.getPrototypeOf,nn=Object.prototype.hasOwnProperty;var tn=(e,n)=>{for(var t in n)x(e,t,{get:n[t],enumerable:!0})},fe=(e,n,t,i)=>{if(n&&typeof n=="object"||typeof n=="function")for(let a of Qe(n))!nn.call(e,a)&&a!==t&&x(e,a,{get:()=>n[a],enumerable:!(i=Xe(n,a))||i.enumerable});return e};var A=(e,n,t)=>(t=e!=null?Ze(en(e)):{},fe(n||!e||!e.__esModule?x(t,"default",{value:e,enumerable:!0}):t,e)),an=e=>fe(x({},"__esModule",{value:!0}),e);var rt={};tn(rt,{default:()=>G});module.exports=an(rt);var f=require("@oclif/core");var ye="public",Ae="https://app.allscale.io";var ge=["https://app.allscale.io"];var J="Override the API base URL (public builds accept only https://app.allscale.io)";var q="Only https://app.allscale.io is allowed, and URL userinfo is forbidden.";function _e(e){try{let n=new URL(e);return n.username.length>0||n.password.length>0?null:n.protocol==="https:"?n:null}catch{return null}}function Le(e){return _e(e)!==null}function j(e){let n=_e(e);return n!==null&&ge.includes(n.origin)}function b(){return"".trim()||void 0}function _(){return"public"}function he(e){try{let{hostname:n}=new URL(e);return n==="127.0.0.1"||n==="localhost"||n==="[::1]"}catch{return!1}}function Te(){{let e="[]".trim();if(e.length===0)return[];try{let n=JSON.parse(e);return Array.isArray(n)?n:[]}catch{return[]}}return Y()}function Y(){let e=process.env.ALLSCALE_BUILD_PAIRS?.trim()??"";if(e.length>0)try{let i=JSON.parse(e);if(!Array.isArray(i))return[];let a=[];for(let o of i){if(typeof o!="object"||o===null)continue;let{base:r,key:s,keyId:u}=o;if(typeof r!="string"||r.trim().length===0||typeof s!="string"||s.trim().length===0)continue;let p=typeof u=="string"?u.trim():"";a.push({base:r.trim(),key:s,keyId:p.length>0?p:"cli-1"})}return a}catch{return[]}let n=process.env.ALLSCALE_SIGNING_KEY??"",t=process.env.ALLSCALE_BUILD_API_BASE?.trim()??"";if(n.trim().length>0&&t.length>0){let i=process.env.ALLSCALE_SIGNING_KEY_ID?.trim();return[{base:t,key:n,keyId:i&&i.length>0?i:"cli-1"}]}return[]}var on={"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_invalid":5,"auth.token_expired":5,"auth.device_pairing_timeout":3,"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},rn=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 z(e){return(typeof e=="string"?e:String(e??"")).replace(rn,"")}var sn=64;function K(e,n=new Map,t=0){if(typeof e=="string")return z(e);if(e===null||typeof e!="object")return e;let i=n.get(e);if(i!==void 0)return i;if(t>=sn)return e;if(Array.isArray(e)){let r=[];n.set(e,r);for(let s of e)r.push(K(s,n,t+1));return r}let a=Object.getPrototypeOf(e);if(a!==Object.prototype&&a!==null)return e;let o={};n.set(e,o);for(let[r,s]of Object.entries(e))Object.defineProperty(o,r,{value:K(s,n,t+1),writable:!0,enumerable:!0,configurable:!0});return o}var d=class extends Error{code;details;constructor(n,t,i){super(z(t)),this.code=n,this.details=i&&K(i),this.name="AllscaleError"}get exitCode(){return on[this.code]}toJSON(){return{error:{code:this.code,message:this.message,...this.details?{details:this.details}:{}}}}};function ke(e){if(e instanceof d)return e;if(e instanceof Error){if(un(e)){let n=cn(e),t={};return e.name&&e.name!=="Error"&&(t.name=e.name),Object.keys(n).length>0&&(t.oclif=n),new d("input.invalid",e.message,Object.keys(t).length>0?t:void 0)}return new d("internal",e.message,{name:e.name})}return new d("internal","Unknown error",{value:String(e)})}var ln=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 un(e){if(pn(e))return!0;let n=e.name??"";return ln.has(n)?n==="CLIError"?W(e,"parse")||Se(e.message):!0:Se(e.message)}function pn(e){if(!W(e,"oclif"))return!1;let n=e.oclif;return typeof n=="object"&&n!==null&&n.exit===2&&W(e,"parse")}function Se(e){return e?z(e).split(`
2
+ `).some(n=>dn.some(t=>t.test(n.trim()))):!1}function W(e,n){return typeof e=="object"&&e!==null&&Object.prototype.hasOwnProperty.call(e,n)}function cn(e){let n=e,t={};for(let i of["code","exitCode","suggestions","ref"])n[i]!==void 0&&(t[i]=n[i]);return t}function Ne(e){process.stdout.write(`${JSON.stringify({data:e},null,2)}
3
+ `)}var l=A(require("fs")),$=A(require("path")),Be=A(require("crypto"));var mn="...<truncated>",fn=/\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]+/g,yn=/\bBearer\s+[A-Za-z0-9._~+/=-]{12,}/gi,ee=String.raw`(?:(?:Bearer|Basic)\s+)?(?:"(?:\\.|[^"\\\r\n])*"|'(?:\\.|[^'\\\r\n])*'|[^\s,;)}\]]+)`,H=String.raw`(?:proxy[_-]?)?authorization`,An=new RegExp(String.raw`(^|[^A-Za-z0-9])((?:"${H}"|'${H}'|${H})\s*[:=]\s*)((?:Bearer|Basic)\s+)?(?!<redacted(?:-jwt)?>)${ee}`,"gi"),gn=/\b(https?:\/\/)[^\s/?#]+@/gi,_n=String.raw`(?:[A-Za-z0-9]+[_-])*`,Ln=String.raw`(?:[A-Za-z0-9]{1,32}[_-]){0,8}`,be=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)`,Ce=be(_n),hn=be(Ln),Tn=new RegExp(String.raw`(^|[^A-Za-z0-9])((?:"${Ce}"|'${Ce}'|${hn})\s*[:=]\s*)(?!<redacted(?:-jwt)?>)${ee}`,"gi"),Z=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)`,Sn=new RegExp(String.raw`(^|[^A-Za-z0-9])((?:"${Z}"|'${Z}'|${Z})\s*[:=]\s*)(?!<redacted(?:-jwt)?>)${ee}`,"g");function Ee(e){return e.replace(gn,"$1<redacted>@").replace(fn,"<redacted-jwt>").replace(An,"$1$2$3<redacted>").replace(Tn,"$1$2<redacted>").replace(Sn,"$1$2<redacted>").replace(yn,"Bearer <redacted>")}var kn=/(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 Oe(e){let n=e.replace(/([a-z0-9])([A-Z])/g,"$1_$2").replace(/([A-Z]+)([A-Z][a-z])/g,"$1_$2");return kn.test(n)}function Re(e){let n="";for(let t of e){let i=t.codePointAt(0),a=i<=8||i>=11&&i<=12||i>=14&&i<=31||i>=127&&i<=159;n+=a?`\\u${i.toString(16).padStart(4,"0")}`:t}return n}function Ie(e,n,t=mn){if(n<=0)return"";if(Buffer.byteLength(e,"utf8")<=n)return e;let i=Buffer.byteLength(t,"utf8");if(i>=n){let s="",u=0;for(let p of t){let y=Buffer.byteLength(p,"utf8");if(u+y>n)break;s+=p,u+=y}return s}let a=n-i,o="",r=0;for(let s of e){let u=Buffer.byteLength(s,"utf8");if(r+u>a)break;o+=s,r+=u}return`${o}${t}`}function c(e,n=16384){return Ie(Re(Ee(e)),n)}var X=100,Nn=8,Cn=8*1024;function D(){return{remaining:Cn}}function Q(e,n){let t=Math.min(16384,n.remaining),i=Ie(e,t);return n.remaining-=Buffer.byteLength(i,"utf8"),i}function L(e,n,t=0,i={}){if(t>Nn)return Q("<truncated>",n);if(typeof e=="string"){let a=Ee(e);return Q(i.escapeControls?Re(a):a,n)}if(Array.isArray(e)){let a=e.slice(0,X),o=a.map(r=>L(r,n,t+1,i));return e.length>a.length&&o.push(Q(`<${e.length-a.length} more items truncated>`,n)),o}if(e!==null&&typeof e=="object"){let a=Object.create(null),o=Object.entries(e);for(let[r,s]of o.slice(0,X))a[r]=L(s,n,t+1,i);return o.length>X&&(a.output_truncated=!0),a}return e}var ne=require("process");var te=!1;function ie(e){te=e}function Ue(){return te}var we="1";function T(e,n){if(te){let t={...e};delete t.version;let i=D(),a={event:t.event,...t},o=L(a,i,0,{escapeControls:!0}),r=JSON.stringify({version:we,...o});Buffer.byteLength(r,"utf8")+1>65536&&(r=JSON.stringify({version:we,event:o.event,output_truncated:!0})),ne.stderr.write(`${r}
4
+ `)}else ne.stderr.write(n)}var ve="2",S=null,m=null,k=!1,E=!1;function bn(){let e=process.env.ALLSCALE_OUTPUT_FILE_PATH;if(e)return e;let n=process.env.ALLSCALE_OUTPUT_FILE_DIRECTORY;if(n){let t=new Date().toISOString().replace(/[:.]/g,"-"),i=Be.randomBytes(4).toString("hex");return $.join(n,`allscale-output-${t}-${i}.ndjson`)}return null}var ae=64*1024*1024,En=null;function oe(e={}){if(e.quiet&&(E=!0),k)return;let n=bn();if(!n)return;S=null;let t=null;try{if((En??process.platform)==="win32")throw new Error("owner-only sidecar ACLs cannot be enforced on Windows; sidecar output is disabled");let i=$.dirname(n);if(l.mkdirSync(i,{recursive:!0,mode:448}),!process.env.ALLSCALE_OUTPUT_FILE_PATH&&process.env.ALLSCALE_OUTPUT_FILE_DIRECTORY){let u=l.statSync(i),p=u.mode&511;if(!u.isDirectory()||(p&63)!==0)throw new Error(`output directory must be owner-only (no group/other permissions); current mode is ${p.toString(8).padStart(3,"0")}`)}let a=l.constants.O_NOFOLLOW??0;t=l.openSync(n,l.constants.O_APPEND|l.constants.O_CREAT|l.constants.O_WRONLY|(l.constants.O_NONBLOCK??0)|a,384);let o=l.fstatSync(t),r=l.lstatSync(n);if(!o.isFile()||r.isSymbolicLink()||r.dev!==o.dev||r.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 s=o.mode&511;if((s&63)!==0)throw new Error(`existing sidecar file must already be owner-only; current mode is ${s.toString(8).padStart(3,"0")}. Rotate or remove it before retrying`);l.fchmodSync(t,384)}catch(i){if(t!==null)try{l.closeSync(t)}catch{}E||T({event:"sidecar_disabled",reason:"open_failed",detail:c(`sidecar path '${n}' could not be opened safely (${i.message})`)},`${c(`[allscale] sidecar path '${n}' could not be opened safely (${i.message}); refusing to write. Sidecar disabled for this run.`)}
5
+ `);return}S=n,m=t,k=!0}var On=[/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 Rn(e){let n=e.replace(/([a-z0-9])([A-Z])/g,"$1_$2").replace(/([A-Z]+)([A-Z][a-z])/g,"$1_$2");return On.some(t=>t.test(n))}function In(e){try{let n=new URL(e),t=n.username.length>0||n.password.length>0;t&&(n.username="",n.password="");let i=n.pathname;n.pathname=wn(n.pathname);let a=t;n.pathname!==i&&(a=!0);for(let[o]of n.searchParams)Rn(o)&&(n.searchParams.set(o,"<redacted>"),a=!0);return a?n.toString():e}catch{return e}}function wn(e){return e.replace(/(\/(?:api\/)?(?:v1\/)?public\/claim-links\/)([^/:]+)(:claim)?(?=\/?$)/,"$1<redacted>$3").replace(/(\/(?:api\/)?public\/claim-links\/)([^/]+)(\/claim)(?=\/?$)/,"$1<redacted>$3")}function Un(e){return(e.type==="request"||e.type==="bridge_browser_open")&&typeof e.url=="string"?{...e,url:In(e.url)}:e}function vn(e){let n=new Date().toISOString(),t=e,{type:i,...a}=t,o=L(a,D()),r=JSON.stringify({version:ve,timestamp:n,type:i,...o});return Buffer.byteLength(r,"utf8")+1>65536&&(r=JSON.stringify({version:ve,timestamp:n,type:i,output_truncated:!0})),r}function N(e){if(!k||!S||m===null)return;let n=Un(e),t=vn(n);try{if(l.fstatSync(m).size+Buffer.byteLength(t,"utf8")+1>ae){k=!1;try{l.closeSync(m)}catch{}m=null,E||T({event:"sidecar_disabled",reason:"size_limit",...S===null?{}:{path:c(S)},max_bytes:ae},`${c(`[allscale] sidecar exceeded ${ae} bytes; disabling it for the rest of this run. Rotate or remove ${S}, or point ALLSCALE_OUTPUT_FILE_DIRECTORY at a directory so each run gets its own file.`)}
6
+ `);return}l.appendFileSync(m,`${t}
7
+ `)}catch(i){if(k=!1,m!==null){try{l.closeSync(m)}catch{}m=null}try{E||T({event:"sidecar_disabled",reason:"write_failed",detail:c(i.message)},`${c(`[allscale] sidecar write failed (${i.message}); disabling sidecar for the rest of this run.`)}
8
+ `)}catch{}}}function Pe(){return!!(process.env.ALLSCALE_OUTPUT_FILE_PATH||process.env.ALLSCALE_OUTPUT_FILE_DIRECTORY)}function O(){if(E=!1,k=!1,m!==null){try{l.closeSync(m)}catch{}m=null}}function xe(e=!1){let n=process.stdin.isTTY===!0&&process.stdout.isTTY===!0;return e||Pe()||!n}var R=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"]),Bn=new Set(Array.from(R).filter(e=>e.startsWith("-")&&!e.startsWith("--")&&e.length===2)),Pn=Array.from(R).filter(e=>e.startsWith("--")).sort((e,n)=>n.length-e.length),xn=new Set(["--otp-stdin","--password-stdin"]);function re(e){let n=[];for(let t=0;t<e.length;t+=1){let i=e[t];if(i.startsWith("-")){let o=i.indexOf("=");if(o!==-1){let r=i.slice(0,o);if(R.has(r)){n.push(`${r}=<redacted>`);continue}}}if(R.has(i)){n.push(i),t+1<e.length&&(R.has(e[t+1])||(n.push("<redacted>"),t+=1));continue}if(i.startsWith("-")&&!i.startsWith("--")&&i.length>2&&i[1]!=="="){let o=i.slice(0,2);if(Bn.has(o)){n.push(`${o}<redacted>`);continue}}let a=xn.has(i)?void 0:Pn.find(o=>i.length>o.length&&i.startsWith(o));if(a){n.push(`${a}<redacted>`);continue}n.push(i)}return n}function De(e){N({type:"error",code:e.code,message:c(e.message)}),N({type:"command-end",ok:!1,exitCode:e.exitCode}),O()}var I=b()??Ae,w={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 se(e){return Le(e)?new URL(e).origin:null}function U(e){try{let n=new URL(e);return`${n.protocol}//${n.host}`}catch{return"<unparseable URL>"}}function $e(){let e=process.env[w.TOKEN]?.trim();return e&&e.length>0?e:void 0}function le(){let e=process.env[w.PROFILE]?.trim();return e&&e.length>0?e:void 0}function v(){let e=process.env[w.API_BASE]?.trim();return e&&e.length>0?e:void 0}function Fe(){let e=process.env[w.INSECURE_STORAGE]?.trim().toLowerCase();return e==="1"||e==="true"||e==="yes"}function Ve(){let e=process.env[w.ALLOW_RAW]?.trim().toLowerCase();return e==="1"||e==="true"||e==="yes"}function Ge(e){let{resolvedApiBase:n,fromExplicitOverride:t,profileApiBase:i,profileApiBaseSource:a}=e;if(b()===void 0&&I!==""&&"".length!==0&&!t&&a!=="explicit"&&i===""&&n==="")return`Notice: this profile is pinned to ${""} (staging) in ~/.allscale/config.toml.
9
+ The CLI default is now ${I} (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: ${Te} --api-base ${O}
14
- `}var N=y(require("fs")),De=y(require("os")),oe=y(require("path")),re=y(require("@iarna/toml"));var Cn=".allscale",bn="config.toml";function En(){return oe.join(De.homedir(),Cn)}function On(){return oe.join(En(),bn)}function Fe(){let e=On();if(!N.existsSync(e))return{};let n=N.readFileSync(e,"utf-8");try{return re.parse(n)}catch(t){throw new d("internal",`Failed to parse ${e}: ${t.message}`)}}function $e(e,n){return e.profile?.[n]}function Ve(e,n,t){let i=n??t??e.default??"default";if(i.includes(":"))throw new d("input.invalid",`Invalid profile name '${i}': ':' is reserved as the keychain namespace separator \u2014 pick a name without ':'.`);return i}function se(e){if(!J(e))throw new d("input.invalid",`Refusing to send credentials to API base ${h(e)}. `+M)}function Ge(e){let n=C();if(n===void 0||_e(e))return;let t=x(e),i=Le();if(i.length>0){let o=i.map(s=>x(s.base)).filter(s=>s!==null);if(t!==null&&o.includes(t))return;let r=i.map(s=>h(s.base)).join(", ");throw new d("input.invalid",`Refusing to send to ${h(e)} \u2014 this build only signs for: ${r}. Re-login against one of this build's environments, or use a build that includes the one you need.`)}let a=x(n);if(!(t!==null&&t===a))throw new d("input.invalid",`Refusing to send to ${h(e)} \u2014 this build only signs for ${h(n)}. Re-login against this build's environment, or use a build for that one.`)}var In=require("@noble/hashes/sha3");var Me=["USDT","USDC"];var Et=new Set([`0x${"0".repeat(40)}`,`0x${"0".repeat(36)}dead`]);var w=require("@oclif/core"),R=class e extends f.Command{static enableJsonFlag=!0;static legacyStagingNoticeShown=!1;static emitsOwnOutput=!1;static requiresEscapeHatch=!1;static requiresInput=!1;static isLocalOnly=!1;static baseFlags={profile:f.Flags.string({description:"Named profile from ~/.allscale/config.toml",helpGroup:"GLOBAL"}),token:f.Flags.string({description:"Override the access token for this invocation (precedence: --token > ALLSCALE_TOKEN > --profile)",helpGroup:"GLOBAL",hidden:b()==="public"}),"api-base":f.Flags.string({description:G,helpGroup:"GLOBAL",hidden:b()==="public"}),"insecure-storage":f.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()),Re(),E({type:"session-start",command:this.id??"",argv:wn(this.argv)});let n=this.constructor;if(b()==="public"){if(this.argv.some(o=>o==="--token"||o.startsWith("--token=")))throw new d("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 d("input.invalid","--api-base is not supported in this build; it always talks to its bound AllScale environment.");if(!n.isLocalOnly&&D()!==void 0)throw new d("input.invalid","ALLSCALE_API_BASE is not supported in this build; unset it \u2014 this build always talks to its bound AllScale environment.")}if(n.requiresEscapeHatch&&!ve())throw this.argv.length>0&&await this.parse(),new d("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 t=Ue(this.jsonEnabled()),i=this.argv.length===0&&!t&&$n(n)?this.config.findCommand(this.id??""):void 0;if(i){v();let o=await(0,f.loadHelpClass)(this.config),r=this.config.pjson.oclif?.helpOptions??this.config.pjson.helpOptions;await new o(this.config,r).showCommandHelp(i,this.config.topics);return}let a=await this.runCommand();return E({type:"command-end",ok:!0}),v(),n.emitsOwnOutput?void 0:(this.jsonEnabled()||ke(a),{data:a})}catch(n){let t=Se(n);E({type:"error",code:t.code,message:c(t.message)}),E({type:"command-end",ok:!1,exitCode:t.exitCode}),v(),this.emitError(t),process.exitCode=t.exitCode;return}finally{te(!1)}}resolveSessionApiBaseChain(n){let t=Fe(),i=n.profile??void 0,a=n["api-base"]??void 0,o=i!==void 0||ae()!==void 0,r=Ve(t,i,ae()),s=$e(t,r),u=a??D(),m=u??s?.api_base??O,A=xe({resolvedApiBase:m,fromExplicitOverride:u!==void 0,profileApiBase:s?.api_base,profileApiBaseSource:s?.api_base_source});return A&&!e.legacyStagingNoticeShown&&(e.legacyStagingNoticeShown=!0,T({event:"legacy_staging_profile",api_base:m,profile:r},A)),{apiBase:m,explicitApiBase:u,profileApiBase:s?.api_base,profile:r,profileExplicit:o}}resolveSessionApiBaseForPayoutDerivation(n){let{apiBase:t}=this.resolveSessionApiBaseChain(n);return this.constructor.isLocalOnly||se(t),t}resolveContext(n){if(b()==="public"){if(n.token!==void 0)throw new d("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(n["api-base"]!==void 0)throw new d("input.invalid","--api-base is not supported in this build; it always talks to its bound AllScale environment.");if(!this.constructor.isLocalOnly&&D()!==void 0)throw new d("input.invalid","ALLSCALE_API_BASE is not supported in this build; unset it \u2014 this build always talks to its bound AllScale environment.")}let t=n.token??void 0,i=!!n["insecure-storage"],{apiBase:a,explicitApiBase:o,profile:r,profileApiBase:s,profileExplicit:u}=this.resolveSessionApiBaseChain(n);return this.constructor.isLocalOnly||(se(a),Ge(a)),{apiBase:a,profile:r,token:t??Be(),insecureStorage:i||Pe(),apiBaseSource:o!==void 0?"explicit":s!==void 0?"profile":"default",profileExplicit:u}}emitError(n){process.stderr.write(`${Fn(n)}
15
- `)}},$=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"]),Rn=new Set(Array.from($).filter(e=>e.startsWith("-")&&!e.startsWith("--")&&e.length===2));function wn(e){let n=[];for(let t=0;t<e.length;t+=1){let i=e[t];if(i.startsWith("-")){let a=i.indexOf("=");if(a!==-1){let o=i.slice(0,a);if($.has(o)){n.push(`${o}=<redacted>`);continue}}}if($.has(i)){n.push(i),t+1<e.length&&($.has(e[t+1])||(n.push("<redacted>"),t+=1));continue}if(i.startsWith("-")&&!i.startsWith("--")&&i.length>2&&i[1]!=="="){let a=i.slice(0,2);if(Rn.has(a)){n.push(`${a}<redacted>`);continue}}n.push(i)}return n}var Un=/(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 Bn(e){let n=e.replace(/([a-z0-9])([A-Z])/g,"$1_$2").replace(/([A-Z]+)([A-Z][a-z])/g,"$1_$2");return Un.test(n)}var Pn=/_(removed|cleared|count|total)$/i;function vn(e,n){return typeof n=="number"&&Pn.test(e)}var xn=new Set(Me);function Dn(e,n){return e==="token_symbol"&&typeof n=="string"&&xn.has(n)}var F=100;function le(e,n=0){if(n>8)return"<truncated>";if(Array.isArray(e)){let t=e.slice(0,F),i=t.map(a=>le(a,n+1));return e.length>t.length&&i.push(`<${e.length-t.length} more items truncated>`),i}if(e!==null&&typeof e=="object"){let t=Object.create(null),i=Object.entries(e);for(let[a,o]of i.slice(0,F))t[a]=Bn(a)&&!vn(a,o)&&!Dn(a,o)?"<redacted>":le(o,n+1);if(i.length>F){let a="<truncated>";for(;a in t;)a=`<${a}>`;t[a]=`${i.length-F} more keys`}return t}return typeof e=="string"?c(e):e}function Fn(e){let n=Ee()?void 0:2,t=le(e.toJSON()),i=JSON.stringify(t,null,n);return Buffer.byteLength(i,"utf8")+1<=65536?i:JSON.stringify({error:{code:e.code,message:c(e.message),details:{output_truncated:!0,max_output_bytes:65536}}},null,n)}function $n(e){if(e.requiresInput===!0)return!0;let n=a=>typeof a=="object"&&a!==null&&a.required===!0,t=e.flags??{},i=e.args??{};return Object.values(t).some(a=>n(a))||Object.values(i).some(a=>n(a))}var Je=[{name:"create_claim_link",kind:"mutation",description:"Create a single App claim link. Returns the pending link, funding address, exact deposit total, and bearer claim URL. The link becomes available after the sender's deposit is confirmed. No claim-back.",args:[{name:"input",description:null,type:{kind:"NON_NULL",name:null,ofType:{kind:"INPUT_OBJECT",name:"CreateClaimLinkInput",ofType:null}},defaultValue:null}],returnType:{kind:"NON_NULL",name:null,ofType:{kind:"OBJECT",name:"CreateClaimLinkResult",ofType:null}},deprecated:null},{name:"create_contact",kind:"mutation",description:"create a new contact",args:[{name:"create_input",description:null,type:{kind:"NON_NULL",name:null,ofType:{kind:"INPUT_OBJECT",name:"CreateContactInput",ofType:null}},defaultValue:null}],returnType:{kind:"NON_NULL",name:null,ofType:{kind:"OBJECT",name:"Contact",ofType:null}},deprecated:null},{name:"create_payment",kind:"mutation",description:"create a new payment",args:[{name:"payment",description:null,type:{kind:"NON_NULL",name:null,ofType:{kind:"INPUT_OBJECT",name:"CreatePaymentInput",ofType:null}},defaultValue:null},{name:"wallet_ids",description:null,type:{kind:"LIST",name:null,ofType:{kind:"NON_NULL",name:null,ofType:{kind:"SCALAR",name:"String",ofType:null}}},defaultValue:"null"}],returnType:{kind:"NON_NULL",name:null,ofType:{kind:"OBJECT",name:"Payment",ofType:null}},deprecated:null},{name:"create_store",kind:"mutation",description:"create store",args:[{name:"input",description:null,type:{kind:"NON_NULL",name:null,ofType:{kind:"INPUT_OBJECT",name:"CreateStoreInput",ofType:null}},defaultValue:null}],returnType:{kind:"NON_NULL",name:null,ofType:{kind:"OBJECT",name:"StoreCreateResult",ofType:null}},deprecated:null},{name:"update_payment",kind:"mutation",description:"update an existing payment status by its ID",args:[{name:"id_str",description:null,type:{kind:"NON_NULL",name:null,ofType:{kind:"SCALAR",name:"String",ofType:null}},defaultValue:null},{name:"payment",description:null,type:{kind:"NON_NULL",name:null,ofType:{kind:"INPUT_OBJECT",name:"UpdatePaymentInput",ofType:null}},defaultValue:null}],returnType:{kind:"NON_NULL",name:null,ofType:{kind:"OBJECT",name:"Payment",ofType:null}},deprecated:null},{name:"activities",kind:"query",description:"Get current user's activity list with multi-dimensional filters (type, status, contact, wallet, time range, amount range)",args:[{name:"filter_input",description:null,type:{kind:"INPUT_OBJECT",name:"ActivityFilterInput",ofType:null},defaultValue:"null"},{name:"skip",description:null,type:{kind:"NON_NULL",name:null,ofType:{kind:"SCALAR",name:"Int",ofType:null}},defaultValue:"0"},{name:"limit",description:null,type:{kind:"NON_NULL",name:null,ofType:{kind:"SCALAR",name:"Int",ofType:null}},defaultValue:"20"}],returnType:{kind:"NON_NULL",name:null,ofType:{kind:"OBJECT",name:"ActivityItemPaginatedResponse",ofType:null}},deprecated:null},{name:"auto_payout_session_status",kind:"query",description:"Return the current merchant auto-payout status, expiry, total/used/remaining USD cap, per-transaction limit, and authorized chain/token pairs. Merchants without an active setup receive provisioned=false with null money/expiry fields and no pairs.",args:[],returnType:{kind:"NON_NULL",name:null,ofType:{kind:"OBJECT",name:"AutoPayoutSessionStatus",ofType:null}},deprecated:null},{name:"business",kind:"query",description:"get one business by it's id",args:[{name:"id_str",description:null,type:{kind:"NON_NULL",name:null,ofType:{kind:"SCALAR",name:"String",ofType:null}},defaultValue:null}],returnType:{kind:"NON_NULL",name:null,ofType:{kind:"OBJECT",name:"Business",ofType:null}},deprecated:null},{name:"business_transaction_records",kind:"query",description:"get transaction records for business",args:[{name:"direction",description:null,type:{kind:"SCALAR",name:"Int",ofType:null},defaultValue:"null"},{name:"transaction_type",description:null,type:{kind:"SCALAR",name:"Int",ofType:null},defaultValue:"null"},{name:"status",description:null,type:{kind:"SCALAR",name:"Int",ofType:null},defaultValue:"null"},{name:"query_input",description:null,type:{kind:"INPUT_OBJECT",name:"QueryInput",ofType:null},defaultValue:"null"}],returnType:{kind:"NON_NULL",name:null,ofType:{kind:"OBJECT",name:"TransactionPaginatedResponse",ofType:null}},deprecated:null},{name:"business_wallets",kind:"query",description:"List the CALLER'S OWN non-custodial wallets (id, chain, address, coin balances). Takes no business id \u2014 the owner is derived from the authenticated identity, so there is no caller-supplied id to mismatch and no way to read another merchant's wallets. Returns [] when the account has no wallet yet.",args:[],returnType:{kind:"NON_NULL",name:null,ofType:{kind:"LIST",name:null,ofType:{kind:"NON_NULL",name:null,ofType:{kind:"OBJECT",name:"WalletEmbedded",ofType:null}}}},deprecated:null},{name:"claim_link",kind:"query",description:"Get one of the caller's own claim links by id (sender surface). A non-owned or unknown id returns CLAIM_LINK_NOT_AVAILABLE \u2014 no existence leak.",args:[{name:"id_str",description:null,type:{kind:"NON_NULL",name:null,ofType:{kind:"SCALAR",name:"String",ofType:null}},defaultValue:null}],returnType:{kind:"NON_NULL",name:null,ofType:{kind:"OBJECT",name:"ClaimLink",ofType:null}},deprecated:null},{name:"claim_link_fee_preview",kind:"query",description:"Preview the Amount / Network fee / Service fee / Total breakdown without creating a link. Asset and precision validation matches create, but create-time amount and rate limits are enforced only when the link is created, so a successful preview does not guarantee create will succeed. per_transfer_gas is the withdrawal gas estimate in token units.",args:[{name:"amount",description:null,type:{kind:"NON_NULL",name:null,ofType:{kind:"SCALAR",name:"String",ofType:null}},defaultValue:null},{name:"chain",description:null,type:{kind:"NON_NULL",name:null,ofType:{kind:"SCALAR",name:"Int",ofType:null}},defaultValue:null},{name:"token_symbol",description:null,type:{kind:"NON_NULL",name:null,ofType:{kind:"SCALAR",name:"String",ofType:null}},defaultValue:null},{name:"per_transfer_gas",description:null,type:{kind:"NON_NULL",name:null,ofType:{kind:"SCALAR",name:"String",ofType:null}},defaultValue:null}],returnType:{kind:"NON_NULL",name:null,ofType:{kind:"OBJECT",name:"ClaimLinkFeeBreakdown",ofType:null}},deprecated:null},{name:"contact",kind:"query",description:"get one contact by it's id",args:[{name:"id_str",description:null,type:{kind:"NON_NULL",name:null,ofType:{kind:"SCALAR",name:"String",ofType:null}},defaultValue:null}],returnType:{kind:"NON_NULL",name:null,ofType:{kind:"OBJECT",name:"Contact",ofType:null}},deprecated:null},{name:"contact_by_email",kind:"query",description:"get one contact by it's email",args:[{name:"email",description:null,type:{kind:"NON_NULL",name:null,ofType:{kind:"SCALAR",name:"String",ofType:null}},defaultValue:null}],returnType:{kind:"NON_NULL",name:null,ofType:{kind:"OBJECT",name:"Contact",ofType:null}},deprecated:null},{name:"contacts",kind:"query",description:"get multi contacts by owner business id",args:[{name:"owner_business_id_str",description:null,type:{kind:"NON_NULL",name:null,ofType:{kind:"SCALAR",name:"String",ofType:null}},defaultValue:null},{name:"query_input",description:null,type:{kind:"INPUT_OBJECT",name:"QueryInput",ofType:null},defaultValue:"null"}],returnType:{kind:"NON_NULL",name:null,ofType:{kind:"OBJECT",name:"ContactPaginatedResponse",ofType:null}},deprecated:null},{name:"my_claim_links",kind:"query",description:"List the caller's claim links, newest first. Optional status and link_source filters narrow the results; query_input controls pagination, ordering, and the created_at time range.",args:[{name:"query_input",description:null,type:{kind:"INPUT_OBJECT",name:"QueryInput",ofType:null},defaultValue:"null"},{name:"status",description:null,type:{kind:"SCALAR",name:"Int",ofType:null},defaultValue:"null"},{name:"link_source",description:null,type:{kind:"SCALAR",name:"Int",ofType:null},defaultValue:"null"}],returnType:{kind:"NON_NULL",name:null,ofType:{kind:"OBJECT",name:"ClaimLinkPaginatedResponse",ofType:null}},deprecated:null},{name:"my_transactions",kind:"query",description:"get one user's successful transactions by query",args:[{name:"query_input",description:null,type:{kind:"NON_NULL",name:null,ofType:{kind:"INPUT_OBJECT",name:"QueryInput",ofType:null}},defaultValue:null}],returnType:{kind:"NON_NULL",name:null,ofType:{kind:"OBJECT",name:"TransactionPaginatedResponse",ofType:null}},deprecated:null},{name:"payment",kind:"query",description:"get one payment by its ID",args:[{name:"id_str",description:null,type:{kind:"NON_NULL",name:null,ofType:{kind:"SCALAR",name:"String",ofType:null}},defaultValue:null}],returnType:{kind:"NON_NULL",name:null,ofType:{kind:"OBJECT",name:"Payment",ofType:null}},deprecated:null},{name:"payments",kind:"query",description:"All payments by business ID as sender or recipient",args:[{name:"business_id_str",description:null,type:{kind:"NON_NULL",name:null,ofType:{kind:"SCALAR",name:"String",ofType:null}},defaultValue:null},{name:"query_input",description:null,type:{kind:"INPUT_OBJECT",name:"QueryInput",ofType:null},defaultValue:"null"}],returnType:{kind:"NON_NULL",name:null,ofType:{kind:"OBJECT",name:"PaymentPaginatedResponse",ofType:null}},deprecated:null},{name:"recipient_payments",kind:"query",description:"Get multiple payments by business ID as recipient",args:[{name:"business_id_str",description:null,type:{kind:"NON_NULL",name:null,ofType:{kind:"SCALAR",name:"String",ofType:null}},defaultValue:null},{name:"query_input",description:null,type:{kind:"INPUT_OBJECT",name:"QueryInput",ofType:null},defaultValue:"null"}],returnType:{kind:"NON_NULL",name:null,ofType:{kind:"OBJECT",name:"PaymentPaginatedResponse",ofType:null}},deprecated:null},{name:"sender_payments",kind:"query",description:"Get multiple payments by business ID as sender",args:[{name:"business_id_str",description:null,type:{kind:"NON_NULL",name:null,ofType:{kind:"SCALAR",name:"String",ofType:null}},defaultValue:null},{name:"query_input",description:null,type:{kind:"INPUT_OBJECT",name:"QueryInput",ofType:null},defaultValue:"null"}],returnType:{kind:"NON_NULL",name:null,ofType:{kind:"OBJECT",name:"PaymentPaginatedResponse",ofType:null}},deprecated:null},{name:"transaction",kind:"query",description:"get one transaction by id_str",args:[{name:"id_str",description:null,type:{kind:"NON_NULL",name:null,ofType:{kind:"SCALAR",name:"String",ofType:null}},defaultValue:null}],returnType:{kind:"NON_NULL",name:null,ofType:{kind:"OBJECT",name:"Transaction",ofType:null}},deprecated:null}];var de={source:"public-cli-contract",synced_at:"2026-08-03T03:01:54.000Z"};var V=class e extends R{static requiresEscapeHatch=!0;static isLocalOnly=!0;static description="List every operation exposed by the schema (queries and mutations). Disabled by default (exit 10); set ALLSCALE_ALLOW_RAW=1 to enable.";static examples=["$ allscale operations","$ allscale operations --kind mutation","$ allscale operations --grep invoice"];static flags={kind:w.Flags.string({char:"k",description:"Filter by operation kind",options:["query","mutation"]}),grep:w.Flags.string({char:"g",description:"Filter by substring match against name + description (case-insensitive)"}),...R.baseFlags};async runCommand(){let{flags:n}=await this.parse(e),t=n.kind,i=n.grep?.toLowerCase(),a=Je.filter(r=>!(t&&r.kind!==t||i&&!`${r.name} ${r.description??""}`.toLowerCase().includes(i))),o={query:0,mutation:0};for(let r of a)o[r.kind]=(o[r.kind]??0)+1;return{total:a.length,by_kind:o,schema_source:de.source,schema_synced_at:de.synced_at,operations:a.map(r=>({name:r.name,kind:r.kind,description:r.description,arg_names:r.args.map(s=>s.name),return_type:ue(r.returnType)}))}}};function ue(e){return e.kind==="NON_NULL"&&e.ofType?`${ue(e.ofType)}!`:e.kind==="LIST"&&e.ofType?`[${ue(e.ofType)}]`:e.name??"Unknown"}
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 ${I}
14
+ `}var g=A(require("fs")),Me=A(require("os")),de=A(require("path")),ue=A(require("@iarna/toml"));var Fn=".allscale",Vn="config.toml";function Gn(){return de.join(Me.homedir(),Fn)}function Mn(){return de.join(Gn(),Vn)}function Je(){let e=Mn();if(!g.existsSync(e))return{};let n=g.readFileSync(e,"utf-8");try{return ue.parse(n)}catch(t){throw new d("internal",`Failed to parse ${e}: ${t.message}`)}}function qe(e,n){return e.profile?.[n]}function je(e,n,t){let i=n??t??e.default??"default";if(i.includes(":"))throw new d("input.invalid",`Invalid profile name '${i}': ':' is reserved as the keychain namespace separator \u2014 pick a name without ':'.`);return i}function pe(e){if(!j(e))throw new d("input.invalid",`Refusing to send credentials to API base ${U(e)}. `+q)}function Ye(e){let n=qn(e);if(n)throw new d("input.invalid",n.message)}function Jn(){let e=b();if(e===void 0)return;let n=Te();return n.length>0?{endpoints:n.map(t=>t.base),fromPairs:!0}:{endpoints:[e],fromPairs:!1}}function qn(e){let n=Jn();if(n===void 0||he(e))return;let{endpoints:t,fromPairs:i}=n,a=se(e),o=t.map(s=>se(s)).filter(s=>s!==null);if(a!==null&&o.includes(a))return;let r=t.map(s=>U(s)).join(", ");return{message:i?`Refusing to send to ${U(e)} \u2014 this build only signs for: ${r}. Re-login against one of this build's environments, or use a build that includes the one you need.`:`Refusing to send to ${U(e)} \u2014 this build only signs for ${r}. Re-login against this build's environment, or use a build for that one.`}}var jn=require("@noble/hashes/sha3");var Ke=["USDT","USDC"];var Kt=new Set([`0x${"0".repeat(40)}`,`0x${"0".repeat(36)}dead`]);var Yn="unknown_otp_id",Kn="invalid_code",Wn="expired_code";function zn(e){return`'${e.replace(/'/g,"'\\''")}'`}function We(e){return`Run \`allscale otp-send --email ${zn(e)}\` first \u2014 that command does report a missing account \u2014 then retry with the otp_id it returns and a fresh code.`}var Hn=new Map([[Yn,(e,n)=>`${e}: this environment never issued the --otp-id you passed for '${n}', so the verification code was never the problem. The backend decides this by comparing the otp_id against that address alone, so it says nothing about whether the account exists. ${We(n)}`],[Kn,e=>`${e}: the --otp-id is one this environment issued and a live code stands behind it \u2014 the verification code you passed is what does not match. Check for a typo \u2014 the backend invalidates the code after a few wrong answers, so if you are unsure, request a fresh code instead of guessing.`],[Wn,(e,n,t)=>t?`${e}: this run's send request was accepted moments ago, but this attempt could not claim a live code for the --otp-id. Delivery is asynchronous and the code is stored only after the email goes out, so it may still be in flight \u2014 or the send may have failed outright, in which case no code is coming. The code you submitted may also have expired, been used, run out of attempts, or been replaced by a newer send. Check the inbox, including spam, and retry with whatever code arrived. If nothing arrives, confirm the address and wait at least three minutes before requesting one fresh code \u2014 sends are rate-limited per address, and retrying in a tight loop spends that budget even when the send is rejected.`:`${e}: this attempt could not claim a live code for the --otp-id. The code you submitted may have expired, been used, run out of attempts, been replaced by a later send, or never have been requested for this address; the backend does not distinguish those. If a newer code was delivered after the one you entered, use that one. ${We(n)}`]]);var ze=[...Hn.keys()];var P=require("@oclif/core"),B=class e extends f.Command{static enableJsonFlag=!0;static legacyStagingNoticeShown=!1;static emitsOwnOutput=!1;static requiresEscapeHatch=!1;static requiresInput=!1;static isLocalOnly=!1;static baseFlags={profile:f.Flags.string({description:"Named profile from ~/.allscale/config.toml",helpGroup:"GLOBAL"}),token:f.Flags.string({description:"Override the access token for this invocation (precedence: --token > ALLSCALE_TOKEN > --profile)",helpGroup:"GLOBAL",hidden:_()==="public"}),"api-base":f.Flags.string({description:J,helpGroup:"GLOBAL",hidden:_()==="public"}),"insecure-storage":f.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()),oe(),N({type:"session-start",command:this.id??"",argv:re(this.argv)});let n=this.constructor;if(_()==="public"){if(this.argv.some(o=>o==="--token"||o.startsWith("--token=")))throw new d("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 d("input.invalid","--api-base is not supported in this build; it always talks to its bound AllScale environment.");if(!n.isLocalOnly&&v()!==void 0)throw new d("input.invalid","ALLSCALE_API_BASE is not supported in this build; unset it \u2014 this build always talks to its bound AllScale environment.")}let t=xe(this.jsonEnabled()),i=this.argv.length===0&&!t&&ot(n)?this.config.findCommand(this.id??""):void 0;if(i){O();let o=await(0,f.loadHelpClass)(this.config),r=this.config.pjson.oclif?.helpOptions??this.config.pjson.helpOptions;await new o(this.config,r).showCommandHelp(i,this.config.topics);return}if(n.requiresEscapeHatch&&!Ve())throw this.argv.length>0&&await this.parse(),new d("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 a=await this.runCommand();return N({type:"command-end",ok:!0}),O(),n.emitsOwnOutput?void 0:(this.jsonEnabled()||Ne(a),{data:a})}catch(n){let t=ke(n);De({code:t.code,message:t.message,exitCode:t.exitCode}),this.emitError(t),process.exitCode=t.exitCode;return}finally{ie(!1)}}resolveSessionApiBaseChain(n){let t=Je(),i=n.profile??void 0,a=n["api-base"]??void 0,o=i!==void 0||le()!==void 0,r=je(t,i,le()),s=qe(t,r),u=_()==="public"&&v()!==void 0,p=a??(u?void 0:v()),y=p??s?.api_base??I,M=Ge({resolvedApiBase:y,fromExplicitOverride:p!==void 0,profileApiBase:s?.api_base,profileApiBaseSource:s?.api_base_source});return M&&!e.legacyStagingNoticeShown&&(e.legacyStagingNoticeShown=!0,T({event:"legacy_staging_profile",api_base:y,profile:r},M)),{apiBase:y,explicitApiBase:p,envApiBaseIgnored:u,profileApiBase:s?.api_base,profile:r,profileExplicit:o}}resolveSessionApiBaseForPayoutDerivation(n){let{apiBase:t}=this.resolveSessionApiBaseChain(n);return this.constructor.isLocalOnly||pe(t),t}resolveContext(n){if(_()==="public"){if(n.token!==void 0)throw new d("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(n["api-base"]!==void 0)throw new d("input.invalid","--api-base is not supported in this build; it always talks to its bound AllScale environment.");if(!this.constructor.isLocalOnly&&v()!==void 0)throw new d("input.invalid","ALLSCALE_API_BASE is not supported in this build; unset it \u2014 this build always talks to its bound AllScale environment.")}let t=n.token??void 0,i=!!n["insecure-storage"],{apiBase:a,explicitApiBase:o,envApiBaseIgnored:r,profile:s,profileApiBase:u,profileExplicit:p}=this.resolveSessionApiBaseChain(n);return this.constructor.isLocalOnly||(pe(a),Ye(a)),{apiBase:a,profile:s,token:t??$e(),insecureStorage:i||Fe(),apiBaseSource:o!==void 0?"explicit":u!==void 0?"profile":"default",profileExplicit:p,envApiBaseIgnored:r}}emitError(n){process.stderr.write(`${at(n)}
15
+ `)}};var Zn=/_(removed|cleared|count|total)$/i;function Xn(e,n){return typeof n=="number"&&Zn.test(e)}var Qn=new Set(Ke);function et(e,n){return e==="token_symbol"&&typeof n=="string"&&Qn.has(n)}var nt=new Set(ze);function tt(e,n){return e==="otp_reason"&&typeof n=="string"&&nt.has(n)}var F=100;function V(e,n=0){if(n>8)return"<truncated>";if(Array.isArray(e)){let t=e.slice(0,F),i=t.map(a=>V(a,n+1));return e.length>t.length&&i.push(`<${e.length-t.length} more items truncated>`),i}if(e!==null&&typeof e=="object"){let t=Object.create(null),i=Object.entries(e);for(let[a,o]of i.slice(0,F))t[a]=Oe(a)&&!Xn(a,o)&&!et(a,o)&&!tt(a,o)?"<redacted>":V(o,n+1);if(i.length>F){let a="<truncated>";for(;a in t;)a=`<${a}>`;t[a]=`${i.length-F} more keys`}return t}if(typeof e=="string"){let t=it(e);return t!==void 0?c(JSON.stringify(V(t,n+1))):c(e)}return e}function it(e){let n=e.trim();if(!n.startsWith("{")&&!n.startsWith("["))return;let t;try{t=JSON.parse(n)}catch{return}return t!==null&&typeof t=="object"?t:void 0}function at(e){let n=Ue()?void 0:2,t=V(e.toJSON()),i=JSON.stringify(t,null,n);return Buffer.byteLength(i,"utf8")+1<=65536?i:JSON.stringify({error:{code:e.code,message:c(e.message),details:{output_truncated:!0,max_output_bytes:65536}}},null,n)}function ot(e){if(e.requiresInput===!0)return!0;let n=a=>typeof a=="object"&&a!==null&&a.required===!0,t=e.flags??{},i=e.args??{};return Object.values(t).some(a=>n(a))||Object.values(i).some(a=>n(a))}var He=[{name:"create_claim_link",kind:"mutation",description:"Create a single App claim link. Returns the pending link, funding address, exact deposit total, and bearer claim URL. The link becomes available after the sender's deposit is confirmed. No claim-back.",args:[{name:"input",description:null,type:{kind:"NON_NULL",name:null,ofType:{kind:"INPUT_OBJECT",name:"CreateClaimLinkInput",ofType:null}},defaultValue:null}],returnType:{kind:"NON_NULL",name:null,ofType:{kind:"OBJECT",name:"CreateClaimLinkResult",ofType:null}},deprecated:null},{name:"create_contact",kind:"mutation",description:"create a new contact",args:[{name:"create_input",description:null,type:{kind:"NON_NULL",name:null,ofType:{kind:"INPUT_OBJECT",name:"CreateContactInput",ofType:null}},defaultValue:null}],returnType:{kind:"NON_NULL",name:null,ofType:{kind:"OBJECT",name:"Contact",ofType:null}},deprecated:null},{name:"create_payment",kind:"mutation",description:"create a new payment",args:[{name:"payment",description:null,type:{kind:"NON_NULL",name:null,ofType:{kind:"INPUT_OBJECT",name:"CreatePaymentInput",ofType:null}},defaultValue:null},{name:"wallet_ids",description:null,type:{kind:"LIST",name:null,ofType:{kind:"NON_NULL",name:null,ofType:{kind:"SCALAR",name:"String",ofType:null}}},defaultValue:"null"}],returnType:{kind:"NON_NULL",name:null,ofType:{kind:"OBJECT",name:"Payment",ofType:null}},deprecated:null},{name:"create_store",kind:"mutation",description:"create store",args:[{name:"input",description:null,type:{kind:"NON_NULL",name:null,ofType:{kind:"INPUT_OBJECT",name:"CreateStoreInput",ofType:null}},defaultValue:null}],returnType:{kind:"NON_NULL",name:null,ofType:{kind:"OBJECT",name:"StoreCreateResult",ofType:null}},deprecated:null},{name:"update_payment",kind:"mutation",description:"update an existing payment status by its ID",args:[{name:"id_str",description:null,type:{kind:"NON_NULL",name:null,ofType:{kind:"SCALAR",name:"String",ofType:null}},defaultValue:null},{name:"payment",description:null,type:{kind:"NON_NULL",name:null,ofType:{kind:"INPUT_OBJECT",name:"UpdatePaymentInput",ofType:null}},defaultValue:null}],returnType:{kind:"NON_NULL",name:null,ofType:{kind:"OBJECT",name:"Payment",ofType:null}},deprecated:null},{name:"activities",kind:"query",description:"Get current user's activity list with multi-dimensional filters (type, status, contact, wallet, time range, amount range)",args:[{name:"filter_input",description:null,type:{kind:"INPUT_OBJECT",name:"ActivityFilterInput",ofType:null},defaultValue:"null"},{name:"skip",description:null,type:{kind:"NON_NULL",name:null,ofType:{kind:"SCALAR",name:"Int",ofType:null}},defaultValue:"0"},{name:"limit",description:null,type:{kind:"NON_NULL",name:null,ofType:{kind:"SCALAR",name:"Int",ofType:null}},defaultValue:"20"}],returnType:{kind:"NON_NULL",name:null,ofType:{kind:"OBJECT",name:"ActivityItemPaginatedResponse",ofType:null}},deprecated:null},{name:"auto_payout_session_status",kind:"query",description:"Return the current merchant auto-payout status, expiry, total/used/remaining USD cap, per-transaction limit, and authorized chain/token pairs. Merchants without an active setup receive provisioned=false with null money/expiry fields and no pairs.",args:[],returnType:{kind:"NON_NULL",name:null,ofType:{kind:"OBJECT",name:"AutoPayoutSessionStatus",ofType:null}},deprecated:null},{name:"business",kind:"query",description:"get one business by it's id",args:[{name:"id_str",description:null,type:{kind:"NON_NULL",name:null,ofType:{kind:"SCALAR",name:"String",ofType:null}},defaultValue:null}],returnType:{kind:"NON_NULL",name:null,ofType:{kind:"OBJECT",name:"Business",ofType:null}},deprecated:null},{name:"business_contact_by_email",kind:"query",description:"Look up the contact card of the business whose login email is given. Used to fill the invoice header's From: block with the same name/email/phone the web editor shows.",args:[{name:"email",description:null,type:{kind:"NON_NULL",name:null,ofType:{kind:"SCALAR",name:"String",ofType:null}},defaultValue:null}],returnType:{kind:"NON_NULL",name:null,ofType:{kind:"OBJECT",name:"BusinessContact",ofType:null}},deprecated:null},{name:"business_transaction_records",kind:"query",description:"get transaction records for business",args:[{name:"direction",description:null,type:{kind:"SCALAR",name:"Int",ofType:null},defaultValue:"null"},{name:"transaction_type",description:null,type:{kind:"SCALAR",name:"Int",ofType:null},defaultValue:"null"},{name:"status",description:null,type:{kind:"SCALAR",name:"Int",ofType:null},defaultValue:"null"},{name:"query_input",description:null,type:{kind:"INPUT_OBJECT",name:"QueryInput",ofType:null},defaultValue:"null"}],returnType:{kind:"NON_NULL",name:null,ofType:{kind:"OBJECT",name:"TransactionPaginatedResponse",ofType:null}},deprecated:null},{name:"business_wallets",kind:"query",description:"List the CALLER'S OWN non-custodial wallets (id, chain, address, coin balances). Takes no business id \u2014 the owner is derived from the authenticated identity, so there is no caller-supplied id to mismatch and no way to read another merchant's wallets. Returns [] when the account has no wallet yet.",args:[],returnType:{kind:"NON_NULL",name:null,ofType:{kind:"LIST",name:null,ofType:{kind:"NON_NULL",name:null,ofType:{kind:"OBJECT",name:"WalletEmbedded",ofType:null}}}},deprecated:null},{name:"claim_link",kind:"query",description:"Get one of the caller's own claim links by id (sender surface). A non-owned or unknown id returns CLAIM_LINK_NOT_AVAILABLE \u2014 no existence leak.",args:[{name:"id_str",description:null,type:{kind:"NON_NULL",name:null,ofType:{kind:"SCALAR",name:"String",ofType:null}},defaultValue:null}],returnType:{kind:"NON_NULL",name:null,ofType:{kind:"OBJECT",name:"ClaimLink",ofType:null}},deprecated:null},{name:"contact",kind:"query",description:"get one contact by it's id",args:[{name:"id_str",description:null,type:{kind:"NON_NULL",name:null,ofType:{kind:"SCALAR",name:"String",ofType:null}},defaultValue:null}],returnType:{kind:"NON_NULL",name:null,ofType:{kind:"OBJECT",name:"Contact",ofType:null}},deprecated:null},{name:"contact_by_email",kind:"query",description:"get one contact by it's email",args:[{name:"email",description:null,type:{kind:"NON_NULL",name:null,ofType:{kind:"SCALAR",name:"String",ofType:null}},defaultValue:null}],returnType:{kind:"NON_NULL",name:null,ofType:{kind:"OBJECT",name:"Contact",ofType:null}},deprecated:null},{name:"contacts",kind:"query",description:"get multi contacts by owner business id",args:[{name:"owner_business_id_str",description:null,type:{kind:"NON_NULL",name:null,ofType:{kind:"SCALAR",name:"String",ofType:null}},defaultValue:null},{name:"query_input",description:null,type:{kind:"INPUT_OBJECT",name:"QueryInput",ofType:null},defaultValue:"null"}],returnType:{kind:"NON_NULL",name:null,ofType:{kind:"OBJECT",name:"ContactPaginatedResponse",ofType:null}},deprecated:null},{name:"my_claim_links",kind:"query",description:"List the caller's claim links, newest first. Optional status and link_source filters narrow the results; query_input controls pagination, ordering, and the created_at time range.",args:[{name:"query_input",description:null,type:{kind:"INPUT_OBJECT",name:"QueryInput",ofType:null},defaultValue:"null"},{name:"status",description:null,type:{kind:"SCALAR",name:"Int",ofType:null},defaultValue:"null"},{name:"link_source",description:null,type:{kind:"SCALAR",name:"Int",ofType:null},defaultValue:"null"}],returnType:{kind:"NON_NULL",name:null,ofType:{kind:"OBJECT",name:"ClaimLinkPaginatedResponse",ofType:null}},deprecated:null},{name:"my_transactions",kind:"query",description:"get one user's successful transactions by query",args:[{name:"query_input",description:null,type:{kind:"NON_NULL",name:null,ofType:{kind:"INPUT_OBJECT",name:"QueryInput",ofType:null}},defaultValue:null}],returnType:{kind:"NON_NULL",name:null,ofType:{kind:"OBJECT",name:"TransactionPaginatedResponse",ofType:null}},deprecated:null},{name:"payment",kind:"query",description:"get one payment by its ID",args:[{name:"id_str",description:null,type:{kind:"NON_NULL",name:null,ofType:{kind:"SCALAR",name:"String",ofType:null}},defaultValue:null}],returnType:{kind:"NON_NULL",name:null,ofType:{kind:"OBJECT",name:"Payment",ofType:null}},deprecated:null},{name:"payments",kind:"query",description:"All payments by business ID as sender or recipient",args:[{name:"business_id_str",description:null,type:{kind:"NON_NULL",name:null,ofType:{kind:"SCALAR",name:"String",ofType:null}},defaultValue:null},{name:"query_input",description:null,type:{kind:"INPUT_OBJECT",name:"QueryInput",ofType:null},defaultValue:"null"}],returnType:{kind:"NON_NULL",name:null,ofType:{kind:"OBJECT",name:"PaymentPaginatedResponse",ofType:null}},deprecated:null},{name:"recipient_payments",kind:"query",description:"Get multiple payments by business ID as recipient",args:[{name:"business_id_str",description:null,type:{kind:"NON_NULL",name:null,ofType:{kind:"SCALAR",name:"String",ofType:null}},defaultValue:null},{name:"query_input",description:null,type:{kind:"INPUT_OBJECT",name:"QueryInput",ofType:null},defaultValue:"null"}],returnType:{kind:"NON_NULL",name:null,ofType:{kind:"OBJECT",name:"PaymentPaginatedResponse",ofType:null}},deprecated:null},{name:"sender_payments",kind:"query",description:"Get multiple payments by business ID as sender",args:[{name:"business_id_str",description:null,type:{kind:"NON_NULL",name:null,ofType:{kind:"SCALAR",name:"String",ofType:null}},defaultValue:null},{name:"query_input",description:null,type:{kind:"INPUT_OBJECT",name:"QueryInput",ofType:null},defaultValue:"null"}],returnType:{kind:"NON_NULL",name:null,ofType:{kind:"OBJECT",name:"PaymentPaginatedResponse",ofType:null}},deprecated:null},{name:"transaction",kind:"query",description:"get one transaction by id_str",args:[{name:"id_str",description:null,type:{kind:"NON_NULL",name:null,ofType:{kind:"SCALAR",name:"String",ofType:null}},defaultValue:null}],returnType:{kind:"NON_NULL",name:null,ofType:{kind:"OBJECT",name:"Transaction",ofType:null}},deprecated:null}];var ce={source:"public-cli-contract",synced_at:"2026-08-03T03:01:54.000Z"};var G=class e extends B{static requiresEscapeHatch=!0;static isLocalOnly=!0;static description="List every operation exposed by the schema (queries and mutations). Disabled by default (exit 10); set ALLSCALE_ALLOW_RAW=1 to enable.";static examples=["$ allscale operations","$ allscale operations --kind mutation","$ allscale operations --grep invoice"];static flags={kind:P.Flags.string({char:"k",description:"Filter by operation kind",options:["query","mutation"]}),grep:P.Flags.string({char:"g",description:"Filter by substring match against name + description (case-insensitive)"}),...B.baseFlags};async runCommand(){let{flags:n}=await this.parse(e),t=n.kind,i=n.grep?.toLowerCase(),a=He.filter(r=>!(t&&r.kind!==t||i&&!`${r.name} ${r.description??""}`.toLowerCase().includes(i))),o={query:0,mutation:0};for(let r of a)o[r.kind]=(o[r.kind]??0)+1;return{total:a.length,by_kind:o,schema_source:ce.source,schema_synced_at:ce.synced_at,operations:a.map(r=>({name:r.name,kind:r.kind,description:r.description,arg_names:r.args.map(s=>s.name),return_type:me(r.returnType)}))}}};function me(e){return e.kind==="NON_NULL"&&e.ofType?`${me(e.ofType)}!`:e.kind==="LIST"&&e.ofType?`[${me(e.ofType)}]`:e.name??"Unknown"}
16
16
  //# sourceMappingURL=operations.js.map