@hyperscale0/cli 1.0.0-beta.15 → 1.0.0-beta.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/hyperscale.js +2 -2
- package/package.json +2 -2
package/hyperscale.js
CHANGED
|
@@ -87,7 +87,7 @@ Examples:
|
|
|
87
87
|
hyperscale call account.list --input-file input.json
|
|
88
88
|
printf '{"limit":5}' | hyperscale call account.list
|
|
89
89
|
hyperscale call account.retrieve --input '{"accountId":"acct_sandbox_..."}'
|
|
90
|
-
`,Ie={start:{usage:"start [--blueprint <slug>] [--name <name>] [--json]",summary:"Choose a catalog company, create its Product, and run its first published runnable journey step.",options:["--blueprint <slug> Skip the prompt and choose this catalog Blueprint.","--name <name> Product name. Defaults to the selected Blueprint name.","--json Print one machine document, including the one-time API key under shown_once."],notes:["The command requires an active founder login.","Without --blueprint, start requires an interactive terminal and asks which company to build.","Scripts and agents must pass --blueprint <slug>.","Machine output returns the Product API key only under shown_once.","A Blueprint without a published runnable journey stops after composition and names the next command."],example:"hyperscale start --blueprint vehicle-escrow-marketplace --json"},"auth login":{usage:"auth login [--no-browser] [--token <pat>]",summary:"Sign in through the portal callback or save a founder PAT.",options:["--no-browser Skip the portal callback. Print where to mint a PAT when no token is set.","--token <pat> Founder PAT. Defaults to HYPERSCALE_TOKEN.","--json Print the saved session summary as one JSON document."],notes:["Without a PAT, the CLI opens portal sign-in and accepts one localhost callback.","Headless environments should pass --no-browser and set HYPERSCALE_TOKEN or --token to a portal-minted founder PAT.","Set HYPERSCALE_CREDENTIAL_STORE=file to use the 0600 profile file instead of macOS Keychain."],example:"hyperscale auth login --no-browser"},"auth status":{usage:"auth status [--json]",summary:"Verify and show the active founder PAT and selected Product.",options:["--json Print machine-readable JSON."],example:"hyperscale auth status --json"},"auth logout":{usage:"auth logout [--revoke] [--json]",summary:"Forget the local founder PAT. Optionally revoke it first.",options:["--revoke Revoke the PAT before deleting local state.","--json Print machine-readable JSON."],example:"hyperscale auth logout --revoke"},"blueprint list":{usage:"blueprint list [--json]",summary:"List public Blueprints without authentication.",options:["--json Print the complete collection as JSON."],example:"hyperscale blueprint list"},"blueprint show":{usage:"blueprint show <id> [--json]",summary:"Show one public Blueprint.",options:["--json Print the complete Blueprint as JSON."],example:"hyperscale blueprint show luxury-goods-consignment-escrow"},"product create":{usage:"product create --blueprint <id> --name <name> [--json]",summary:"Create and select a Product. The command refuses a duplicate name.",options:["--blueprint <id> Required Blueprint id.","--name <name> Required Product name.","--json Print the creation summary as JSON."],example:'hyperscale product create --blueprint luxury-goods-consignment-escrow --name "Luxury Consignment"'},"product list":{usage:"product list [--json]",summary:"List Products in the signed-in company.",options:["--json Print the complete collection as JSON."],example:"hyperscale product list"},"product show":{usage:"product show [id] [--json]",summary:"Show a Product summary, or the complete Product document as JSON.",options:["--json Print the complete Product document."],example:"hyperscale product show prd_sandbox_..."},"product select":{usage:"product select <id> [--json]",summary:"Verify a Product and save it as the default for later commands.",options:["--token <pat> Founder PAT. Defaults to HYPERSCALE_TOKEN or the stored login.","--base-url <url> API origin. Defaults to the active founder profile.","--environment <name> sandbox or live. Defaults to the active founder profile.","--json Print the selected Product id as JSON."],notes:["The CLI stores the selection in the active founder profile.","Product show, compose plan/apply, and key commands use it when --product is absent.","Product create and start select the Product they create."],example:"hyperscale product select prd_sandbox_..."},"product actions":{usage:"product actions [operation-id] [--product <id>] [--json]",summary:"List frozen public actions or show one action's full schemas.",options:["--product <id> Product to inspect. Defaults to the selected Product.","--api-key <key> Product API key. Defaults to HYPERSCALE_API_KEY.","--json Print machine-readable JSON."],notes:["Setup operation details include the public input schema used by hyperscale call.","When that schema has no required fields, omit --input or pass {}."],example:"hyperscale product actions escrow_order.placeBuyerHold --json"},"product run":{usage:"product run <operation-id> [--input <json> | --input-file <path>] [--idempotency-key <key>] [--json]",summary:"Run one frozen public action with a Product API key.",options:["--input <json> JSON input object. Stdin is used when piped.","--input-file <path> Read the JSON input object from a file.","--product <id> Product to call. Defaults to the selected Product.","--api-key <key> Product API key. Defaults to HYPERSCALE_API_KEY.","--idempotency-key <key> Send this exact Idempotency-Key header. The default is a generated UUID.","--json Print the key, receipt ids, and output as JSON."],notes:["Reuse an Idempotency-Key only with the same operation and input.",'If a bounded validation value appears as "[Truncated]", run "hyperscale product actions <operation-id>" for the full input schema.'],example:`hyperscale product run escrow_order.placeBuyerHold --input '{"escrowOrderId":"eord_sandbox_..."}' --idempotency-key hold-001`},"compose check":{usage:"compose check <file.hsx> [--catalog-revision <id>] [--json]",summary:"Ask the server to compile and check an HSX program.",options:["--catalog-revision <id> Compile against this immutable tenant catalog revision.","--json Print diagnostics and the verdict as JSON."],example:"hyperscale compose check product.hsx"},"compose plan":{usage:"compose plan <file.hsx> [--product <id>] [--catalog-revision <id>] [--json]",summary:"Diff an HSX program against a Product.",options:["--product <id> Product to compare. Defaults to the selected Product.","--catalog-revision <id> Compile against this immutable tenant catalog revision.","--json Print the plan as JSON."],example:"hyperscale compose plan product.hsx --json"},"compose apply":{usage:"compose apply <file.hsx> (--confirm | --yes) (--pricing-identity <id> | --plan-file <path>) [--product <id>] [--catalog-revision <id>] [--json]",summary:"Recompose a Product from checked HSX.",options:["--confirm Confirm the mutation for a person.","--yes Confirm the mutation without a prompt for an agent.","--pricing-identity <id> Candidate pricing identity from compose plan.","--plan-file <path> Saved JSON plan file from compose plan --json.","--product <id> Product to recompose. Defaults to the selected Product.","--catalog-revision <id> Compile and persist against this immutable tenant catalog revision.","--json Print the result as JSON."],example:"hyperscale compose apply product.hsx --yes --pricing-identity <id>"},"key create":{usage:"key create [--name <name>] [--product <id>] [--json]",summary:"Create a sandbox Product API key.",options:["--name <name> Key name. Defaults to Founder CLI.","--product <id> Product for the key. Defaults to the selected Product.","--json Print the one-time secret and key metadata as JSON."],example:'hyperscale key create --name "Founder laptop"'},"key list":{usage:"key list [--product <id>] [--json]",summary:"List keys for one Product.",options:["--product <id> Product to inspect. Defaults to the selected Product.","--json Print the collection as JSON."],example:"hyperscale key list --json"},"key revoke":{usage:"key revoke <id> [--product <id>] [--json]",summary:"Revoke one Product API key.",options:["--product <id> Product that owns the key. Defaults to the selected Product.","--json Print the result as JSON."],example:"hyperscale key revoke key_sandbox_..."},"activity list":{usage:"activity list [--json]",summary:"List company activity with timestamps and resource targets.",options:["--json Print the complete collection as JSON."],example:"hyperscale activity list"},whoami:{usage:"whoami [--json]",summary:"Show the user and company the founder PAT resolves to.",options:["--json Print machine-readable JSON."],example:"hyperscale whoami --json"},"ops list":{usage:"ops list [filter] [--product <id>] [--json]",summary:"List callable operations from the Product machine document.",options:["--product <id> Product to inspect. The Product API key must belong to it.","--api-key <key> Product API key. Defaults to HYPERSCALE_API_KEY.","--json Print matching operations as JSON."],example:"hyperscale ops list account"},call:{usage:"call <operation> [--input <json> | --input-file <path>] [--idempotency-key <key>] [--product <id>]",summary:"Call one operation from the Product machine document.",options:["--input <json> JSON input object. Stdin is used when piped.","--input-file <path> Read the JSON input object from a file.","--product <id> Product to call. The Product API key must belong to it.","--api-key <key> Product API key. Defaults to HYPERSCALE_API_KEY.","--idempotency-key <key> Send this exact Idempotency-Key header for a mutation. The default is a generated UUID."],notes:["Reuse an Idempotency-Key only with the same operation and input."],example:`hyperscale call account.create --input '{"currency":"SAR"}'`}};function pt(e){let n=Object.keys(Ie).sort((r,i)=>i.split(" ").length-r.split(" ").length).find(r=>r.split(" ").every((a,c)=>e[c]===a));if(!n)throw new u(`No help for ${e.join(" ")}. Run "hyperscale --help" to list commands.`);let o=Ie[n];return[`Usage: hyperscale ${o.usage}`,"",o.summary,"","Options:",...o.options.map(r=>` ${r}`),...o.notes?["","Notes:",...o.notes.map(r=>` ${r}`)]:[],"","Example:",` ${o.example}`,""].join(`
|
|
90
|
+
`,Ie={start:{usage:"start [--blueprint <slug>] [--name <name>] [--json]",summary:"Choose a catalog company, create its Product, and run its first published runnable journey step.",options:["--blueprint <slug> Skip the prompt and choose this catalog Blueprint.","--name <name> Product name. Defaults to the selected Blueprint name.","--json Print one machine document, including the one-time API key under shown_once."],notes:["The command requires an active founder login.","Without --blueprint, start requires an interactive terminal and asks which company to build.","Scripts and agents must pass --blueprint <slug>.","Machine output returns the Product API key only under shown_once.","A Blueprint without a published runnable journey stops after composition and names the next command."],example:"hyperscale start --blueprint vehicle-escrow-marketplace --json"},"auth login":{usage:"auth login [--no-browser] [--token <pat>]",summary:"Sign in through the portal callback or save a founder PAT.",options:["--no-browser Skip the portal callback. Print where to mint a PAT when no token is set.","--token <pat> Founder PAT. Defaults to HYPERSCALE_TOKEN.","--json Print the saved session summary as one JSON document."],notes:["Without a PAT, the CLI opens portal sign-in and accepts one localhost callback.","Headless environments should pass --no-browser and set HYPERSCALE_TOKEN or --token to a portal-minted founder PAT.","Set HYPERSCALE_CREDENTIAL_STORE=file to use the 0600 profile file instead of macOS Keychain."],example:"hyperscale auth login --no-browser"},"auth status":{usage:"auth status [--json]",summary:"Verify and show the active founder PAT and selected Product.",options:["--json Print machine-readable JSON."],example:"hyperscale auth status --json"},"auth logout":{usage:"auth logout [--revoke] [--json]",summary:"Forget the local founder PAT. Optionally revoke it first.",options:["--revoke Revoke the PAT before deleting local state.","--json Print machine-readable JSON."],example:"hyperscale auth logout --revoke"},"blueprint list":{usage:"blueprint list [--json]",summary:"List public Blueprints without authentication.",options:["--json Print the complete collection as JSON."],example:"hyperscale blueprint list"},"blueprint show":{usage:"blueprint show <id> [--json]",summary:"Show one public Blueprint.",options:["--json Print the complete Blueprint as JSON."],example:"hyperscale blueprint show luxury-goods-consignment-escrow"},"product create":{usage:"product create --blueprint <id> --name <name> [--json]",summary:"Create and select a Product. The command refuses a duplicate name.",options:["--blueprint <id> Required Blueprint id.","--name <name> Required Product name.","--json Print the creation summary as JSON."],example:'hyperscale product create --blueprint luxury-goods-consignment-escrow --name "Luxury Consignment"'},"product list":{usage:"product list [--json]",summary:"List Products in the signed-in company.",options:["--json Print the complete collection as JSON."],example:"hyperscale product list"},"product show":{usage:"product show [id] [--json]",summary:"Show a Product summary, or the complete Product document as JSON.",options:["--json Print the complete Product document."],example:"hyperscale product show prd_sandbox_..."},"product select":{usage:"product select <id> [--json]",summary:"Verify a Product and save it as the default for later commands.",options:["--token <pat> Founder PAT. Defaults to HYPERSCALE_TOKEN or the stored login.","--base-url <url> API origin. Defaults to the active founder profile.","--environment <name> sandbox or live. Defaults to the active founder profile.","--json Print the selected Product id as JSON."],notes:["The CLI stores the selection in the active founder profile.","Product show, compose plan/apply, and key commands use it when --product is absent.","Product create and start select the Product they create."],example:"hyperscale product select prd_sandbox_..."},"product actions":{usage:"product actions [operation-id] [--product <id>] [--json]",summary:"List frozen public actions or show one action's full schemas.",options:["--product <id> Product to inspect. Defaults to the selected Product.","--api-key <key> Product API key. Defaults to HYPERSCALE_API_KEY.","--json Print machine-readable JSON."],notes:["Setup operation details include the public input schema used by hyperscale call.","When that schema has no required fields, omit --input or pass {}."],example:"hyperscale product actions escrow_order.placeBuyerHold --json"},"product run":{usage:"product run <operation-id> [--input <json> | --input-file <path>] [--idempotency-key <key>] [--json]",summary:"Run one frozen public action with a Product API key.",options:["--input <json> JSON input object. Stdin is used when piped.","--input-file <path> Read the JSON input object from a file.","--product <id> Product to call. Defaults to the selected Product.","--api-key <key> Product API key. Defaults to HYPERSCALE_API_KEY.","--idempotency-key <key> Send this exact Idempotency-Key header. The default is a generated UUID.","--json Print the key, receipt ids, and output as JSON."],notes:["Reuse an Idempotency-Key only with the same operation and input.",'If a bounded validation value appears as "[Truncated]", run "hyperscale product actions <operation-id>" for the full input schema.'],example:`hyperscale product run escrow_order.placeBuyerHold --input '{"escrowOrderId":"eord_sandbox_..."}' --idempotency-key hold-001`},"compose check":{usage:"compose check <file.hsx> [--catalog-revision <id>] [--json]",summary:"Ask the server to compile and check an HSX program.",options:["--catalog-revision <id> Compile against this immutable tenant catalog revision.","--json Print diagnostics and the verdict as JSON."],example:"hyperscale compose check product.hsx"},"compose plan":{usage:"compose plan <file.hsx> [--product <id>] [--catalog-revision <id>] [--json]",summary:"Diff an HSX program against a Product.",options:["--product <id> Product to compare. Defaults to the selected Product.","--catalog-revision <id> Compile against this immutable tenant catalog revision.","--json Print the plan as JSON."],example:"hyperscale compose plan product.hsx --json"},"compose apply":{usage:"compose apply <file.hsx> (--confirm (--pricing-identity <id> | --plan-file <path>) | --yes) [--product <id>] [--catalog-revision <id>] [--json]",summary:"Recompose a Product from checked HSX.",options:["--confirm Confirm the mutation for a person, who must also name the candidate price they reviewed.","--yes Confirm the mutation without a prompt for an agent; accepts the candidate price current at apply time.","--pricing-identity <id> Candidate pricing identity from compose plan.","--plan-file <path> Saved JSON plan file from compose plan --json.","--product <id> Product to recompose. Defaults to the selected Product.","--catalog-revision <id> Compile and persist against this immutable tenant catalog revision.","--json Print the result as JSON."],example:"hyperscale compose apply product.hsx --yes --pricing-identity <id>"},"key create":{usage:"key create [--name <name>] [--product <id>] [--json]",summary:"Create a sandbox Product API key.",options:["--name <name> Key name. Defaults to Founder CLI.","--product <id> Product for the key. Defaults to the selected Product.","--json Print the one-time secret and key metadata as JSON."],example:'hyperscale key create --name "Founder laptop"'},"key list":{usage:"key list [--product <id>] [--json]",summary:"List keys for one Product.",options:["--product <id> Product to inspect. Defaults to the selected Product.","--json Print the collection as JSON."],example:"hyperscale key list --json"},"key revoke":{usage:"key revoke <id> [--product <id>] [--json]",summary:"Revoke one Product API key.",options:["--product <id> Product that owns the key. Defaults to the selected Product.","--json Print the result as JSON."],example:"hyperscale key revoke key_sandbox_..."},"activity list":{usage:"activity list [--json]",summary:"List company activity with timestamps and resource targets.",options:["--json Print the complete collection as JSON."],example:"hyperscale activity list"},whoami:{usage:"whoami [--json]",summary:"Show the user and company the founder PAT resolves to.",options:["--json Print machine-readable JSON."],example:"hyperscale whoami --json"},"ops list":{usage:"ops list [filter] [--product <id>] [--json]",summary:"List callable operations from the Product machine document.",options:["--product <id> Product to inspect. The Product API key must belong to it.","--api-key <key> Product API key. Defaults to HYPERSCALE_API_KEY.","--json Print matching operations as JSON."],example:"hyperscale ops list account"},call:{usage:"call <operation> [--input <json> | --input-file <path>] [--idempotency-key <key>] [--product <id>]",summary:"Call one operation from the Product machine document.",options:["--input <json> JSON input object. Stdin is used when piped.","--input-file <path> Read the JSON input object from a file.","--product <id> Product to call. The Product API key must belong to it.","--api-key <key> Product API key. Defaults to HYPERSCALE_API_KEY.","--idempotency-key <key> Send this exact Idempotency-Key header for a mutation. The default is a generated UUID."],notes:["Reuse an Idempotency-Key only with the same operation and input."],example:`hyperscale call account.create --input '{"currency":"SAR"}'`}};function pt(e){let n=Object.keys(Ie).sort((r,i)=>i.split(" ").length-r.split(" ").length).find(r=>r.split(" ").every((a,c)=>e[c]===a));if(!n)throw new u(`No help for ${e.join(" ")}. Run "hyperscale --help" to list commands.`);let o=Ie[n];return[`Usage: hyperscale ${o.usage}`,"",o.summary,"","Options:",...o.options.map(r=>` ${r}`),...o.notes?["","Notes:",...o.notes.map(r=>` ${r}`)]:[],"","Example:",` ${o.example}`,""].join(`
|
|
91
91
|
`)}var u=class extends Error{constructor(t,n={}){super(t),typeof n.code=="string"&&(this.code=n.code),n.details!==void 0&&(this.details=n.details),Number.isInteger(n.exitCode)&&(this.exitCode=n.exitCode),typeof n.fix=="string"&&(this.fix=n.fix)}},E=class extends u{constructor(t,{requestId:n,status:o,code:r,details:i,operationId:a,receiptId:c,traceId:d,structuredError:l}={}){super(t,{code:r,details:i}),this.requestId=n,this.status=o,this.operationId=a??null,this.receiptId=c??null,this.traceId=d??null,this.structuredError=l}};function ee(){return new u(at,{fix:st})}function Te(e){let t=e??"<id>";return new u(`This command needs a Product API key. Create one with "hyperscale key create --name 'Founder CLI' --product ${t}", then set HYPERSCALE_API_KEY or pass --api-key.`)}var B=class extends u{constructor(t,n){super(t),this.code="check_failed",this.details=n,this.exitCode=2}},ve=new Set(["--api-key","--base-url","--blueprint","--catalog-revision","--environment","--idempotency-key","--input","--input-file","--name","--plan-file","--pricing-identity","--product","--token"]);function mt(e){let t=[],n={};for(let o=0;o<e.length;o+=1){let r=e[o];if(!r.startsWith("--")){t.push(r);continue}if(ve.has(r)){let i=e[o+1];if(i===void 0)throw new u(`${r} needs a value`);n[r]=i,o+=1;continue}if(r==="--help"||r==="--version"||r==="--json"||r==="--confirm"||r==="--yes"||r==="--no-browser"||r==="--passkey"||r==="--revoke"){n[r]=!0;continue}throw new u(`Unknown option: ${r}`)}return{flags:n,positional:t}}function $e(e,t){let n=e["--api-key"]??t.HYPERSCALE_API_KEY;if(!n)throw Te();let o=e["--environment"]??t.HYPERSCALE_ENVIRONMENT??le;if(o!=="sandbox"&&o!=="live")throw new u(`Unknown environment: ${o}. Use sandbox or live.`);let r=(e["--base-url"]??t.HYPERSCALE_BASE_URL??de).replace(/\/+$/,"");return{apiKey:n,baseUrl:r,environment:o}}function j(e,t,n={}){let o=e["--environment"]??t.HYPERSCALE_ENVIRONMENT??n.environment??le;if(o!=="sandbox"&&o!=="live")throw new u(`Unknown environment: ${o}. Use sandbox or live.`);let r=(e["--base-url"]??t.HYPERSCALE_BASE_URL??n.baseUrl??de).replace(/\/+$/,""),i;try{i=new URL(r)}catch{i=null}let a=i?.origin??null;if(!a||a!==r)throw new u(`Invalid API origin: ${r}. Use an origin such as https://hyperscale0.ai.`);let c=["localhost","127.0.0.1","[::1]","::1"].includes(i.hostname);if(i.protocol!=="https:"&&!(i.protocol==="http:"&&c))throw new u(`Refusing cleartext API origin ${r}. Use HTTPS unless the API runs on loopback.`);return{baseUrl:r,environment:o}}function Ee(e){return e.HYPERSCALE_CONFIG_DIR??z(nt(),".config","hyperscale")}function Ce(e){return z(Ee(e),it)}function S(e,t){return z(Ee(t),`session-${D(e)}.json`)}function V(e){let t=e.HYPERSCALE_CREDENTIAL_STORE??"auto";if(t==="auto"||t==="file")return t;throw new u(`Unknown HYPERSCALE_CREDENTIAL_STORE value: ${t}. Use auto or file.`)}async function me(e,t){let n=S(e,t),o=`${ot(n)}.`,r;try{r=await Qe(oe(n),{withFileTypes:!0})}catch(i){if(i&&i.code==="ENOENT")return;throw i}for(let i of r){if(!i.isFile()||!i.name.startsWith(o))continue;let a=i.name.slice(o.length);/^\d+\.[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\.tmp$/.test(a)&&await L(z(oe(n),i.name))}}async function ft(e){try{return JSON.parse(await U(e,"utf8"))}catch(t){if(t&&t.code==="ENOENT")return null;throw t instanceof SyntaxError?new u(`${e} is not valid JSON`):t}}async function R(e,t){let n=ht(e);await Xe(n,{mode:448,recursive:!0}),await Z(n,448);let o=`${e}.${process.pid}.${globalThis.crypto.randomUUID()}.tmp`;await tt(o,t,{flag:"wx",mode:384}),await Z(o,384);try{await Ze(o,e),await Z(e,384)}catch(r){throw await L(o),r}}function ht(e){return oe(e)}async function L(e){try{await et(e)}catch(t){if(!t||t.code!=="ENOENT")throw t}}function yt(e,t){if(!e||typeof e!="object"||Array.isArray(e))throw new u(`${t} does not contain a CLI profile`);let{baseUrl:n,email:o,environment:r,selectedProduct:i}=e;if(typeof n!="string"||typeof o!="string"||r!=="sandbox"&&r!=="live"||!(i===null||typeof i=="string"))throw new u(`${t} does not contain a valid CLI profile`);return{baseUrl:n,email:o,environment:r,selectedProduct:i}}async function W(e){let t=Ce(e),n=await ft(t);return n===null?null:yt(n,t)}async function G(e,t){let n={email:t.email,baseUrl:t.baseUrl,environment:t.environment,selectedProduct:t.selectedProduct??null};await R(Ce(e),`${JSON.stringify(n,null,2)}
|
|
92
92
|
`)}function D(e){return Ve("sha256").update(`${e.baseUrl}\0${e.environment}\0${e.email}`).digest("hex")}async function X(e,t){return re===null?{error:null,status:null,stdout:"",unavailable:!0}:await new Promise(n=>{let o={...process.env};delete o.HYPERSCALE_API_KEY,delete o.HYPERSCALE_TOKEN;let r=xe(re,e,{env:o,stdio:["pipe","pipe","pipe"]}),i=[],a=!1,c=l=>{a||(a=!0,clearTimeout(d),n(l))},d=setTimeout(()=>{r.kill("SIGKILL"),c({error:null,status:null,stdout:"",unavailable:!0})},ct);r.stdout.on("data",l=>i.push(l)),r.stderr.on("data",()=>{}),r.stdin.on("error",()=>{}),r.once("error",l=>c({error:l,status:null,stdout:"",unavailable:!0})),r.once("close",l=>c({error:null,status:l,stdout:Buffer.concat(i).toString("utf8"),unavailable:!1})),t===void 0?r.stdin.end():r.stdin.end(`${t}
|
|
93
93
|
`)})}async function fe(){return(await X(["show-keychain-info"])).status===0}function Oe(e){try{let t=typeof e=="string"?JSON.parse(e):e;if(t&&typeof t=="object"&&!Array.isArray(t)&&typeof t.token=="string"&&typeof t.tenantId=="string"&&(t.personalAccessTokenId===void 0||typeof t.personalAccessTokenId=="string")&&(t.tokenName===void 0||typeof t.tokenName=="string"))return{token:t.token,tenantId:t.tenantId,...t.personalAccessTokenId?{personalAccessTokenId:t.personalAccessTokenId}:{},...t.tokenName?{tokenName:t.tokenName}:{}}}catch{}return null}async function wt(e,t,n){await me(e,n);let o=D(e);if(V(n)==="auto"&&await fe()){let r=JSON.stringify(t),i=["add-generic-password","-a",o,"-s",pe,"-U","-X",Buffer.from(r,"utf8").toString("hex")].join(" ");if((await X(["-i"],i)).status===0)return await L(S(e,n)),"keychain"}return await R(S(e,n),`${JSON.stringify({account:o,activeStore:"file",credential:t})}
|
|
@@ -116,7 +116,7 @@ ${be(JSON.stringify(r.hsxStructured.document,null,2)," ")}`)),s("Terms:");for
|
|
|
116
116
|
`);for(let[m,f]of o.entries()){let $=f.summary.replace(/\s+/g," ").trim();process.stderr.write(` ${m+1}. ${f.name} (${f.id})${$?`: ${$}`:""}
|
|
117
117
|
`)}let i=Ge({input:process.stdin,output:process.stderr,terminal:!0}),a=new AbortController,c=()=>a.abort();process.stdin.once("end",c),process.stdin.readableEnded&&a.abort();let d;try{try{d=(await i.question("Choose a number or Blueprint slug: ",{signal:a.signal})).trim()}catch(m){throw m?.name!=="AbortError"&&m?.code!=="ABORT_ERR"?m:new u("Start cancelled before a Blueprint was chosen.",{code:"start_cancelled"})}}finally{process.stdin.off("end",c),i.close()}let l=Number(d),p=Number.isInteger(l)?o[l-1]:o.find(({id:m})=>m===d);if(p)return p;throw new u(`No Blueprint matches ${JSON.stringify(d)}.`,{fix:"Run hyperscale start again and choose a listed number or slug."})}async function Se(e,t){Ut(e);let n={};try{await Ht(e,t,n)}catch(o){throw typeof n.apiKey!="string"?o:Lt(o,n.apiKey)}}async function Ht(e,t,n){let o=await k(e,t),r=await T(o,o.token),i=await Jt(e,o),a=e["--name"]??i.name;e["--json"]||s(`Authenticated: ${r.email}`);let c=await Q(o,"/v1/products/blueprint-compose",A({blueprintId:i.id,name:a,tenantId:o.tenantId}),o.token),d=we(c.response,c.text,[o.token]);if(typeof d?.productId!="string"||!dt.test(d.productId)||typeof d?.productBuildId!="string"||d?.blueprintId!==i.id)throw new u("product.blueprint.compose returned an invalid start Product");let l=d?.shown_once;if(typeof l!="string"||l.length===0)throw new u("The composed Product did not return its one-time API key. Choose a new Product name and run hyperscale start again.",{code:"start_api_key_unavailable"});n.apiKey=l;let p=ye(c.response);await G(t,{...o,selectedProduct:d.productId}),e["--json"]||(s(`Product: ${d.productId}`),s(`Blueprint: ${d.blueprintId}`),jt("Compose",p));let m=[`hyperscale compose plan product.hsx --product ${d.productId}`],f="Composition completed. Run SDK journeys against your Product.",$={blueprintId:d.blueprintId,composeOnly:!0,nextCommands:m,notice:f,productBuildId:d.productBuildId,productId:d.productId,receipts:[{stage:"product.blueprint.compose",...p}],...typeof d.startKeyId=="string"?{startKeyId:d.startKeyId}:{},shown_once:l};if(e["--json"]){w($);return}s(f),s(`Shown once Product API key: ${l}`),s("Next:");for(let g of m)s(` ${g}`);s(" Run journeys with the Hyperscale SDK using the Product API key above.")}async function Kt(e,t){let n=e["--blueprint"],o=e["--name"];if(!n)throw new u("product create needs --blueprint <id>");if(!o)throw new u("product create needs --name <name>");let r=await k(e,t),i;try{i=await C(r,"/v1/products",{tenantId:r.tenantId},"product.list",r.token,[r.token])}catch(m){if(!(m instanceof E)||m.status!==403)throw m}let a=o.trim().toLocaleLowerCase("en-US"),c=(i?v(i,"product.list"):[]).find(m=>{let f=m?.displayName??m?.name;return typeof f=="string"&&f.trim().toLocaleLowerCase("en-US")===a});if(c){let m=c.productId??c.id??"<id>";throw new u(`A Product named ${JSON.stringify(o.trim())} already exists as ${m}.`,{code:"duplicate_product_name",fix:`Use "hyperscale product select ${m}" or choose another --name.`})}let d=await b(r,"/v1/products/blueprint-compose",A({blueprintId:n,name:o,tenantId:r.tenantId}),r.token,[r.token]);if(typeof d?.productId!="string"||typeof d?.blueprintId!="string"||typeof d?.productBuildId!="string")throw new u("product.blueprint.compose returned an invalid Product");await G(t,{...r,selectedProduct:d.productId});let l=typeof d?.shown_once=="string"&&d.shown_once.length>0?d.shown_once:void 0,p={blueprintId:d.blueprintId,nextSteps:[`hyperscale product show ${d.productId}`,...l?[]:['hyperscale key create --name "Founder CLI"']],productBuildId:d.productBuildId,productId:d.productId,selectedProduct:d.productId,...typeof d.startKeyId=="string"?{startKeyId:d.startKeyId}:{},...l?{shown_once:l}:{}};if(e["--json"]){w(p);return}s(`Product: ${p.productId}`),s(`Blueprint: ${p.blueprintId}`),s(`Build: ${p.productBuildId}`),s(`Selected: ${p.selectedProduct}`),p.shown_once&&s(`Shown once Product API key: ${p.shown_once}`),s("Next:");for(let m of p.nextSteps)s(` ${m}`)}function De(e){return new URLSearchParams({tenantId:e}).toString()}async function Bt(e,t){let n=await k(e,t),o=await C(n,"/v1/products",{tenantId:n.tenantId},"product.list",n.token,[n.token]),r=v(o,"product.list");if(e["--json"]){w(o);return}if(r.length===0){s('No Products yet. Run "hyperscale blueprint list", then "hyperscale product create --blueprint <id> --name <name>".');return}s("ID Name Status");for(let i of r){let a=i.productId??i.id??"unknown",c=i.displayName??i.name??"unnamed";s(`${a} ${c}${i.status?` ${i.status}`:""}`)}}async function Yt(e,t,n){let o=await k(e,t),r=n??o.selectedProduct;if(!r)throw new u("product show needs an id because no Product is selected. Create a Product first.");let i=await b(o,`/v1/products/${encodeURIComponent(r)}?${De(o.tenantId)}`,{},o.token,[o.token]);if(e["--json"]){w(i);return}qt(i,r)}function qt(e,t){let n=e?.displayName??e?.name??"unnamed",o=e?.status??"unknown",r=e?.blueprint,i=r?.id?`${r.name??r.id}${r.name?` (${r.id})`:""}`:"custom composition",a=e?.cost?.currency??"SAR",c=e?.pricing?.current?.monthlySar??e?.cost?.platformMonthlySar,d=e?.pricing?.current?.setupSar??e?.cost?.platformSetupSar,l=[...Array.isArray(e?.readiness?.outstandingLiveRequirements)?e.readiness.outstandingLiveRequirements:[],...Array.isArray(e?.readiness?.liveUnavailableCapabilities)?e.readiness.liveUnavailableCapabilities.map(p=>`unavailable:${p}`):[],...Array.isArray(e?.cost?.blockers)?e.cost.blockers.map(p=>p?.code??"pricing"):[]];s(`Name: ${n}`),s(`Product: ${e?.productId??t}`),s(`Status: ${o}`),s(`Blueprint: ${i}`),e?.pricing?.scheduled?(s(`Current billing price: ${a} ${e.pricing.current.monthlySar}/mo`),s(`Accepted price from ${e.pricing.scheduled.effectiveAt}: ${a} ${e.pricing.scheduled.monthlySar}/mo`)):s(`Monthly: ${c==null?"not returned":`${a} ${c}`}`),s(`Setup: ${d==null?"not returned":`${a} ${d}`}`),s(`Live: ${e?.readiness?.live===!0?"active":"not active"}`),s(`Live blockers: ${l.length>0?l.join(", "):"none"}`);for(let[p,m]of[["openapi","OpenAPI"],["mcp","MCP"],["sdk","SDK"],["graphql","GraphQL"]]){let f=e?.surfaces?.[p];f?.url&&s(`${m}: ${f.url}`)}s("Next:"),s(` hyperscale key create --name "Founder CLI" --product ${e?.productId??t}`)}async function Ft(e,t,n){if(!n)throw new u("product select needs a Product id");let o=await k(e,t),r=await b(o,`/v1/products/${encodeURIComponent(n)}?${De(o.tenantId)}`,{},o.token,[o.token]);if(r?.productId!==n)throw new u("product.retrieve returned the wrong Product");await G(t,{...o,selectedProduct:n});let i={productId:n,selected:!0};e["--json"]?w(i):s(`Selected Product: ${r.displayName??n} (${n})`)}function Mt(e){return e.map(t=>`${t.path}: error [composer] ${t.code}: ${t.message}`)}async function zt(e){if(!e)throw new u("compose needs a .hsx file");if(!e.endsWith(".hsx"))throw new u(`compose reads a .hsx file, got ${e}`);let t;try{t=await U(e,"utf8")}catch(n){throw new u(`Could not read ${e}: ${n.message}`)}return{file:e,source:t}}function Vt(e){if(!e||typeof e!="object"||typeof e.ok!="boolean"||!Array.isArray(e.issues))throw new u("composer.check returned an invalid result");return{issues:e.issues.map(n=>{if(!n||typeof n!="object"||typeof n.code!="string"||typeof n.message!="string"||typeof n.path!="string")throw new u("composer.check returned an invalid issue");return{code:n.code,message:n.message,path:n.path}}),ok:e.ok}}async function ge(e,t,n,o="none"){let r=await zt(n),i=await k(e,t),a=o==="required"?K(i,e):o==="optional"?He(i,e):void 0,c=await Q(i,"/v1/composer/check",A({tenantId:i.tenantId,document:r.source,...e["--catalog-revision"]?{catalogRevisionId:e["--catalog-revision"]}:{}}),i.token),d=ye(c.response,[i.token]),l=Vt(we(c.response,c.text,[i.token]));if(!l.ok)throw new B(["composer.check refused the program.",...Mt(l.issues)].join(`
|
|
118
118
|
`),{file:n,issues:l.issues,...d});return{check:l,receipt:d,context:i,productId:a,program:r,catalogRevisionId:e["--catalog-revision"]}}async function Wt(e,t,n){let o=await ge(e,t,n,"none");if(e["--json"]){w({command:"composer.check",file:n,issues:o.check.issues,ok:!0,...o.receipt});return}s(`Check passed: ${n}`)}async function Je(e,t){let n=await Q(e.context,"/v1/composer/plan",A({document:e.program.source,tenantId:e.context.tenantId,...e.productId?{productId:e.productId}:{},...e.catalogRevisionId?{catalogRevisionId:e.catalogRevisionId}:{}}),e.context.token),o=we(n.response,n.text,[e.context.token]),r=ye(n.response,[e.context.token]);if(!o||typeof o!="object"||typeof o.summary!="string"||!Array.isArray(o.actions)||!o.pricing||typeof o.pricing!="object")throw new u("composer.plan returned an invalid result");let i=o.actions.filter(a=>!a||typeof a!="object"||a.kind!=="configure_product");if(i.length>0)throw new B([o.summary,...i.map(a=>a&&typeof a=="object"?`${a.kind??"unknown"} ${a.target??"unknown"} ${a.detail??"Composer refused this action."}`:"unknown unknown Composer returned an invalid refusal action.")].join(`
|
|
119
|
-
`),{actions:i,file:t,...r,...e.productId?{productId:e.productId}:{}});return{...o,...r}}async function Gt(e,t,n){let o=await ge(e,t,n,"optional"),r=await Je(o,n);if(e["--json"]){w({command:"composer.plan",file:n,check:{...o.check,...o.receipt},plan:r,...o.productId?{productId:o.productId}:{}});return}s(r.summary);for(let i of r.actions)s(`${i.kind} ${i.target} ${i.detail}`);r.pricing?.scheduled?(s(`Current billing price: SAR ${r.pricing.current.monthlySar}/mo`),s(`Candidate price from ${r.pricing.scheduled.effectiveAt}: SAR ${r.pricing.scheduled.monthlySar}/mo`),s(`Pricing identity: ${r.pricing.scheduled.pricingIdentity}`)):(s(`Monthly: SAR ${r.pricing.monthlySar}`),s(`Activation: SAR ${r.pricing.activationSar}`))}async function Xt(e,t,n){if(!e["--confirm"]&&!e["--yes"])throw new u("compose apply changes the selected Product. Pass --confirm, or --yes for an agent.");let o=e["--pricing-identity"];if(!o&&e["--plan-file"]){let c=e["--plan-file"];try{let d=await U(c,"utf8"),l=JSON.parse(d);o=l.plan?.pricing?.scheduled?.pricingIdentity??l.pricing?.scheduled?.pricingIdentity??l.pricingIdentity}catch(d){throw new u(`Failed to read saved plan file ${c}: ${d.message}`)}}let r=await ge(e,t,n,"required");if((await Je(r,n)).pricing?.scheduled&&!o)throw new u(`compose apply requires --pricing-identity (or --plan-file). Run "hyperscale compose plan ${n}" to review candidate pricing and copy the pricing identity.`);let a=await b(r.context,"/v1/products/recompose",A({program:{source:r.program.source},...r.catalogRevisionId?{catalogRevisionId:r.catalogRevisionId}:{},...o?{pricingIdentity:o}:{},tenantId:r.context.tenantId,productId:r.productId},e["--idempotency-key"]),r.context.token,[r.context.token]);if(!a||typeof a.productBuildId!="string")throw new u("product.recompose returned no new build identity");if(e["--json"]){w({command:"product.recompose",file:n,output:a});return}s(`Product: ${a.productId??r.productId}`),s(`Build: ${a.productBuildId}`),a.buildDigest&&s(`Digest: ${a.buildDigest}`),a.pricing?.scheduled&&(s(`Current billing price: SAR ${a.pricing.current.monthlySar}/mo`),s(`Accepted price from ${a.pricing.scheduled.effectiveAt}: SAR ${a.pricing.scheduled.monthlySar}/mo`))}function He(e,t){let n=t["--product"]??e.selectedProduct;return typeof n=="string"&&n.length>0?n:void 0}function K(e,t){let n=He(e,t);if(!n)throw new u("No Product selected. Pass --product <id> or create a Product first.");return n}async function F(e,t,n){let o=await W(t),r=K(o??{},e),i=j(e,t,o??{});if(o&&(i.baseUrl!==o.baseUrl||i.environment!==o.environment))throw new u(`The selected Product belongs to ${o.baseUrl} (${o.environment}). Select a Product at the configured API origin first.`);let a=e["--api-key"]??t.HYPERSCALE_API_KEY;if(!a)throw Te(r);let c={...i,apiKey:a,productId:r};return await Qt(c,r,n),c}async function Qt(e,t,n){let o=`/v1/products/${encodeURIComponent(t)}/operation-set`,{response:r,text:i}=await J(e,o,{},n);if(r.ok)return;let a;try{a=JSON.parse(i)?.error?.message}catch{a=void 0}throw typeof a=="string"&&a.includes("does not match API key Product")?new u(`${a} Or set HYPERSCALE_API_KEY to a key for ${t}, or pass that key with --api-key.`):H(r,i,[e.apiKey])}async function Ke(e,t){let n=`/v1/products/${encodeURIComponent(e.productId)}/operation-set`,{response:o,text:r}=await J(e,n,{},t);if(!o.ok)throw Ye(o,r,[e.apiKey]);return tn(r,o.status)}async function Zt(e,t,n){let o=await F(e,t),r=await Ke(o);if(n){en(r,n,e);return}if(e["--json"]){w(r);return}if(r.status==="legacy"){s("This Product uses a legacy surface. It has no frozen public actions yet."),s(`Build: ${r.productBuildId}`);return}if(r.publicActions.length===0)s("No public actions");else{s("Operation ID Input Kind");for(let i of r.publicActions){let a=i.idempotencyPolicy?.mode==="not_required"?"read-only":"mutation";s(`${i.instrument}.${i.name} ${rn(i.inputSchema)} ${a}`)}}if(r.setupOperations.length>0){s("Setup operations (run with hyperscale call)");for(let i of r.setupOperations)s(i.operationName)}if(r.readOperationIds.length>0){s("Reads (run with hyperscale call)");for(let i of r.readOperationIds)s(on(i))}s(`Digest: ${r.tenantOperationSetDigest}`),s(`Setup digest: ${r.tenantSetupOperationSetDigest}`),s(`Read digest: ${r.tenantReadOperationSetDigest}`),s(`Build: ${r.productBuildId}`),s(`Surface version: ${r.tenantSurfaceVersion}`)}function en(e,t,n){if(e.status==="legacy")throw new u(`This Product uses a legacy surface and has no frozen public action named ${t}. Run "hyperscale product actions" after rebuilding the Product.`);let o=e.publicActions.find(c=>c&&`${c.instrument}.${c.name}`===t),r=nn(t),i=e.setupOperations.find(c=>c&&(c.operationId===t||c.operationId===r||c.operationName===t));if(i){let{inputSchema:c,operationId:d,operationName:l}=i,p={status:e.status,productBuildId:e.productBuildId,tenantSurfaceVersion:e.tenantSurfaceVersion,tenantSetupOperationSetDigest:e.tenantSetupOperationSetDigest,setupOperationId:d,operationName:l,command:`hyperscale call ${l}`,inputSchema:c};if(n["--json"]){w(p);return}s(`Operation ID: ${d}`),s(`Operation name: ${l}`),s(`Run: hyperscale call ${l}`),s(`Input schema: ${JSON.stringify(c,null,2)}`),(!Array.isArray(c.required)||c.required.length===0)&&s("Input: omit --input or pass {}."),s(`Setup digest: ${e.tenantSetupOperationSetDigest}`),s(`Build: ${e.productBuildId}`),s(`Surface version: ${e.tenantSurfaceVersion}`);return}if(!o)throw new u(`Unknown frozen public action: ${t}. Run "hyperscale product actions" to list exact names.`);let a={status:e.status,productBuildId:e.productBuildId,tenantSurfaceVersion:e.tenantSurfaceVersion,tenantOperationSetDigest:e.tenantOperationSetDigest,publicAction:o};if(n["--json"]){w(a);return}s(`Operation ID: ${o.instrument}.${o.name}`),s(`Instrument: ${o.instrument}`),s(`Input schema: ${JSON.stringify(o.inputSchema,null,2)}`),s(`Output schema: ${JSON.stringify(o.outputSchema,null,2)}`),s(`Actor policy: ${JSON.stringify(o.actorPolicy,null,2)}`),s(`Port policy: ${JSON.stringify(o.portPolicy,null,2)}`),s(`Idempotency policy: ${JSON.stringify(o.idempotencyPolicy,null,2)}`),s(`Receipt policy: ${JSON.stringify(o.receiptPolicy,null,2)}`),s(`Receipt evidence: ${JSON.stringify(o.receiptEvidence,null,2)}`),s(`Digest: ${e.tenantOperationSetDigest}`),s(`Build: ${e.productBuildId}`),s(`Surface version: ${e.tenantSurfaceVersion}`)}function tn(e,t){let n;try{n=JSON.parse(e)}catch{throw new u(`HTTP ${t} returned invalid JSON`)}if(!n||typeof n!="object"||n.status!=="legacy"&&n.status!=="frozen"||typeof n.productBuildId!="string")throw new u("The Product operation set is not in the expected format. Upgrade the CLI.");if(n.status==="legacy")return n;if(typeof n.tenantSurfaceVersion!="number"||typeof n.tenantOperationSetDigest!="string"||typeof n.tenantReadOperationSetDigest!="string"||typeof n.tenantSetupOperationSetDigest!="string"||!Array.isArray(n.publicActions)||!Array.isArray(n.readOperationIds)||!Array.isArray(n.setupOperationIds)||!Array.isArray(n.setupOperations))throw new u("The Product operation set is not in the expected format. Upgrade the CLI.");return n}function nn(e){return e.replaceAll(".","_")}function on(e){for(let t of["create","list","retrieve"]){let n=`_${t}`;if(e.endsWith(n))return`${e.slice(0,-n.length)}.${t}`}return e}function rn(e){if(!e||typeof e!="object")return"input schema unavailable";let t=e.properties&&typeof e.properties=="object"&&!Array.isArray(e.properties)?e.properties:{},n=new Set(Array.isArray(e.required)?e.required.filter(r=>typeof r=="string"):[]),o=Object.entries(t).map(([r,i])=>`${r}${n.has(r)?"":"?"}: ${Be(i)}`);return o.length===0?"no input":o.join(", ")}function Be(e){return!e||typeof e!="object"?"value":Array.isArray(e.enum)&&e.enum.length>0?e.enum.map(t=>String(t)).join(" | "):e.type==="array"?`${Be(e.items)}[]`:typeof e.type=="string"?typeof e.format=="string"?`${e.type} (${e.format})`:e.type:"value"}async function an(e,t,n){if(!n)throw new u("product run needs a public action");let o=await F(e,t,n),r=await Ke(o,n);sn(r,n);let i=await qe(e),a=e["--idempotency-key"]??globalThis.crypto.randomUUID(),{response:c,text:d}=await J(o,`/v1/operations/${encodeURIComponent(n)}`,{body:JSON.stringify(i),headers:{"content-type":"application/json","idempotency-key":a},method:"POST"},n);if(!c.ok)throw Ye(c,d,[o.apiKey],{action:n});let l=c.headers.get("hyperscale-operation-id"),p=c.headers.get("hyperscale-receipt-id"),m=c.headers.get("x-request-id"),f=l?y(l,[o.apiKey]):null,$=p?y(p,[o.apiKey]):null,g=m?y(m,[o.apiKey]):null;if(e["--json"]){w({idempotencyKey:a,...g?{requestId:g}:{},operationId:f,receiptId:$,output:cn(d)});return}f&&s(`Operation: ${f}`),$&&s(`Receipt: ${$}`),s(`Idempotency key: ${a}`);let h=Fe(d);h&&s(h)}function sn(e,t){if(e.status==="legacy")throw new u(`This Product uses a legacy surface and has no frozen public action named ${t}. Run "hyperscale product actions" after rebuilding the Product.`);let n=e.publicActions.find(r=>r&&`${r.instrument}.${r.name}`===t);if(n)return n;let o=e.publicActions.map(r=>`${r.instrument}.${r.name}`).map(r=>({candidate:r,distance:ue(t,r)})).sort((r,i)=>r.distance-i.distance||r.candidate.localeCompare(i.candidate)).slice(0,3).map(({candidate:r})=>r);throw new u(`Unknown frozen public action: ${t}. Closest valid names: ${o.join(", ")}. Run "hyperscale product actions" to list exact names.`)}function cn(e){if(e.trim()==="")return null;try{return JSON.parse(e)}catch{return e}}function Ye(e,t,n=[],o={}){let r=y(t.trim(),n),i;try{i=JSON.parse(t)}catch{return new u(`HTTP ${e.status}${r?` \xB7 ${r}`:""}`)}if(!i?.error||typeof i.error.message!="string")return new u(`HTTP ${e.status}`);let a=typeof i.error.code=="string"?i.error.code:"user_error",c=a==="user_error"?"":`${a}: `,d=y(`HTTP ${e.status} \xB7 ${c}${i.error.message}`,n),l=un(i.error.details,n),p;a==="idempotency_conflict"?p="Reuse the same key only with the same operation and input. Use a new unique key for a different request.":[i.error.message,...l].some(x=>typeof x=="string"&&x.includes("[Truncated]"))&&o.action&&(p=`Run "hyperscale product actions ${o.action}" to read the full input schema and allowed values.`);let m=e.headers.get("x-request-id")??(i&&typeof i=="object"&&typeof i.requestId=="string"?i.requestId:void 0),f=e.headers.get("hyperscale-operation-id")??void 0,$=e.headers.get("hyperscale-receipt-id")??void 0,g=m?y(m,n):void 0,h=f?y(f,n):void 0,I=$?y($,n):void 0,P=new u([d,...l].join(`
|
|
119
|
+
`),{actions:i,file:t,...r,...e.productId?{productId:e.productId}:{}});return{...o,...r}}async function Gt(e,t,n){let o=await ge(e,t,n,"optional"),r=await Je(o,n);if(e["--json"]){w({command:"composer.plan",file:n,check:{...o.check,...o.receipt},plan:r,...o.productId?{productId:o.productId}:{}});return}s(r.summary);for(let i of r.actions)s(`${i.kind} ${i.target} ${i.detail}`);r.pricing?.scheduled?(s(`Current billing price: SAR ${r.pricing.current.monthlySar}/mo`),s(`Candidate price from ${r.pricing.scheduled.effectiveAt}: SAR ${r.pricing.scheduled.monthlySar}/mo`),s(`Pricing identity: ${r.pricing.scheduled.pricingIdentity}`)):(s(`Monthly: SAR ${r.pricing.monthlySar}`),s(`Activation: SAR ${r.pricing.activationSar}`))}async function Xt(e,t,n){if(!e["--confirm"]&&!e["--yes"])throw new u("compose apply changes the selected Product. Pass --confirm, or --yes for an agent.");let o=e["--pricing-identity"];if(!o&&e["--plan-file"]){let c=e["--plan-file"];try{let d=await U(c,"utf8"),l=JSON.parse(d);o=l.plan?.pricing?.scheduled?.pricingIdentity??l.pricing?.scheduled?.pricingIdentity??l.pricingIdentity}catch(d){throw new u(`Failed to read saved plan file ${c}: ${d.message}`)}}let r=await ge(e,t,n,"required"),i=await Je(r,n);if(i.pricing?.scheduled&&!o){if(!e["--yes"])throw new u(`compose apply --confirm requires --pricing-identity (or --plan-file). Run "hyperscale compose plan ${n}" to review candidate pricing and copy the pricing identity, or pass --yes to accept the current candidate.`);o=i.pricing.scheduled.pricingIdentity}let a=await b(r.context,"/v1/products/recompose",A({program:{source:r.program.source},...r.catalogRevisionId?{catalogRevisionId:r.catalogRevisionId}:{},...o?{pricingIdentity:o}:{},tenantId:r.context.tenantId,productId:r.productId},e["--idempotency-key"]),r.context.token,[r.context.token]);if(!a||typeof a.productBuildId!="string")throw new u("product.recompose returned no new build identity");if(e["--json"]){w({command:"product.recompose",file:n,output:a});return}s(`Product: ${a.productId??r.productId}`),s(`Build: ${a.productBuildId}`),a.buildDigest&&s(`Digest: ${a.buildDigest}`),a.pricing?.scheduled&&(s(`Current billing price: SAR ${a.pricing.current.monthlySar}/mo`),s(`Accepted price from ${a.pricing.scheduled.effectiveAt}: SAR ${a.pricing.scheduled.monthlySar}/mo`))}function He(e,t){let n=t["--product"]??e.selectedProduct;return typeof n=="string"&&n.length>0?n:void 0}function K(e,t){let n=He(e,t);if(!n)throw new u("No Product selected. Pass --product <id> or create a Product first.");return n}async function F(e,t,n){let o=await W(t),r=K(o??{},e),i=j(e,t,o??{});if(o&&(i.baseUrl!==o.baseUrl||i.environment!==o.environment))throw new u(`The selected Product belongs to ${o.baseUrl} (${o.environment}). Select a Product at the configured API origin first.`);let a=e["--api-key"]??t.HYPERSCALE_API_KEY;if(!a)throw Te(r);let c={...i,apiKey:a,productId:r};return await Qt(c,r,n),c}async function Qt(e,t,n){let o=`/v1/products/${encodeURIComponent(t)}/operation-set`,{response:r,text:i}=await J(e,o,{},n);if(r.ok)return;let a;try{a=JSON.parse(i)?.error?.message}catch{a=void 0}throw typeof a=="string"&&a.includes("does not match API key Product")?new u(`${a} Or set HYPERSCALE_API_KEY to a key for ${t}, or pass that key with --api-key.`):H(r,i,[e.apiKey])}async function Ke(e,t){let n=`/v1/products/${encodeURIComponent(e.productId)}/operation-set`,{response:o,text:r}=await J(e,n,{},t);if(!o.ok)throw Ye(o,r,[e.apiKey]);return tn(r,o.status)}async function Zt(e,t,n){let o=await F(e,t),r=await Ke(o);if(n){en(r,n,e);return}if(e["--json"]){w(r);return}if(r.status==="legacy"){s("This Product uses a legacy surface. It has no frozen public actions yet."),s(`Build: ${r.productBuildId}`);return}if(r.publicActions.length===0)s("No public actions");else{s("Operation ID Input Kind");for(let i of r.publicActions){let a=i.idempotencyPolicy?.mode==="not_required"?"read-only":"mutation";s(`${i.instrument}.${i.name} ${rn(i.inputSchema)} ${a}`)}}if(r.setupOperations.length>0){s("Setup operations (run with hyperscale call)");for(let i of r.setupOperations)s(i.operationName)}if(r.readOperationIds.length>0){s("Reads (run with hyperscale call)");for(let i of r.readOperationIds)s(on(i))}s(`Digest: ${r.tenantOperationSetDigest}`),s(`Setup digest: ${r.tenantSetupOperationSetDigest}`),s(`Read digest: ${r.tenantReadOperationSetDigest}`),s(`Build: ${r.productBuildId}`),s(`Surface version: ${r.tenantSurfaceVersion}`)}function en(e,t,n){if(e.status==="legacy")throw new u(`This Product uses a legacy surface and has no frozen public action named ${t}. Run "hyperscale product actions" after rebuilding the Product.`);let o=e.publicActions.find(c=>c&&`${c.instrument}.${c.name}`===t),r=nn(t),i=e.setupOperations.find(c=>c&&(c.operationId===t||c.operationId===r||c.operationName===t));if(i){let{inputSchema:c,operationId:d,operationName:l}=i,p={status:e.status,productBuildId:e.productBuildId,tenantSurfaceVersion:e.tenantSurfaceVersion,tenantSetupOperationSetDigest:e.tenantSetupOperationSetDigest,setupOperationId:d,operationName:l,command:`hyperscale call ${l}`,inputSchema:c};if(n["--json"]){w(p);return}s(`Operation ID: ${d}`),s(`Operation name: ${l}`),s(`Run: hyperscale call ${l}`),s(`Input schema: ${JSON.stringify(c,null,2)}`),(!Array.isArray(c.required)||c.required.length===0)&&s("Input: omit --input or pass {}."),s(`Setup digest: ${e.tenantSetupOperationSetDigest}`),s(`Build: ${e.productBuildId}`),s(`Surface version: ${e.tenantSurfaceVersion}`);return}if(!o)throw new u(`Unknown frozen public action: ${t}. Run "hyperscale product actions" to list exact names.`);let a={status:e.status,productBuildId:e.productBuildId,tenantSurfaceVersion:e.tenantSurfaceVersion,tenantOperationSetDigest:e.tenantOperationSetDigest,publicAction:o};if(n["--json"]){w(a);return}s(`Operation ID: ${o.instrument}.${o.name}`),s(`Instrument: ${o.instrument}`),s(`Input schema: ${JSON.stringify(o.inputSchema,null,2)}`),s(`Output schema: ${JSON.stringify(o.outputSchema,null,2)}`),s(`Actor policy: ${JSON.stringify(o.actorPolicy,null,2)}`),s(`Port policy: ${JSON.stringify(o.portPolicy,null,2)}`),s(`Idempotency policy: ${JSON.stringify(o.idempotencyPolicy,null,2)}`),s(`Receipt policy: ${JSON.stringify(o.receiptPolicy,null,2)}`),s(`Receipt evidence: ${JSON.stringify(o.receiptEvidence,null,2)}`),s(`Digest: ${e.tenantOperationSetDigest}`),s(`Build: ${e.productBuildId}`),s(`Surface version: ${e.tenantSurfaceVersion}`)}function tn(e,t){let n;try{n=JSON.parse(e)}catch{throw new u(`HTTP ${t} returned invalid JSON`)}if(!n||typeof n!="object"||n.status!=="legacy"&&n.status!=="frozen"||typeof n.productBuildId!="string")throw new u("The Product operation set is not in the expected format. Upgrade the CLI.");if(n.status==="legacy")return n;if(typeof n.tenantSurfaceVersion!="number"||typeof n.tenantOperationSetDigest!="string"||typeof n.tenantReadOperationSetDigest!="string"||typeof n.tenantSetupOperationSetDigest!="string"||!Array.isArray(n.publicActions)||!Array.isArray(n.readOperationIds)||!Array.isArray(n.setupOperationIds)||!Array.isArray(n.setupOperations))throw new u("The Product operation set is not in the expected format. Upgrade the CLI.");return n}function nn(e){return e.replaceAll(".","_")}function on(e){for(let t of["create","list","retrieve"]){let n=`_${t}`;if(e.endsWith(n))return`${e.slice(0,-n.length)}.${t}`}return e}function rn(e){if(!e||typeof e!="object")return"input schema unavailable";let t=e.properties&&typeof e.properties=="object"&&!Array.isArray(e.properties)?e.properties:{},n=new Set(Array.isArray(e.required)?e.required.filter(r=>typeof r=="string"):[]),o=Object.entries(t).map(([r,i])=>`${r}${n.has(r)?"":"?"}: ${Be(i)}`);return o.length===0?"no input":o.join(", ")}function Be(e){return!e||typeof e!="object"?"value":Array.isArray(e.enum)&&e.enum.length>0?e.enum.map(t=>String(t)).join(" | "):e.type==="array"?`${Be(e.items)}[]`:typeof e.type=="string"?typeof e.format=="string"?`${e.type} (${e.format})`:e.type:"value"}async function an(e,t,n){if(!n)throw new u("product run needs a public action");let o=await F(e,t,n),r=await Ke(o,n);sn(r,n);let i=await qe(e),a=e["--idempotency-key"]??globalThis.crypto.randomUUID(),{response:c,text:d}=await J(o,`/v1/operations/${encodeURIComponent(n)}`,{body:JSON.stringify(i),headers:{"content-type":"application/json","idempotency-key":a},method:"POST"},n);if(!c.ok)throw Ye(c,d,[o.apiKey],{action:n});let l=c.headers.get("hyperscale-operation-id"),p=c.headers.get("hyperscale-receipt-id"),m=c.headers.get("x-request-id"),f=l?y(l,[o.apiKey]):null,$=p?y(p,[o.apiKey]):null,g=m?y(m,[o.apiKey]):null;if(e["--json"]){w({idempotencyKey:a,...g?{requestId:g}:{},operationId:f,receiptId:$,output:cn(d)});return}f&&s(`Operation: ${f}`),$&&s(`Receipt: ${$}`),s(`Idempotency key: ${a}`);let h=Fe(d);h&&s(h)}function sn(e,t){if(e.status==="legacy")throw new u(`This Product uses a legacy surface and has no frozen public action named ${t}. Run "hyperscale product actions" after rebuilding the Product.`);let n=e.publicActions.find(r=>r&&`${r.instrument}.${r.name}`===t);if(n)return n;let o=e.publicActions.map(r=>`${r.instrument}.${r.name}`).map(r=>({candidate:r,distance:ue(t,r)})).sort((r,i)=>r.distance-i.distance||r.candidate.localeCompare(i.candidate)).slice(0,3).map(({candidate:r})=>r);throw new u(`Unknown frozen public action: ${t}. Closest valid names: ${o.join(", ")}. Run "hyperscale product actions" to list exact names.`)}function cn(e){if(e.trim()==="")return null;try{return JSON.parse(e)}catch{return e}}function Ye(e,t,n=[],o={}){let r=y(t.trim(),n),i;try{i=JSON.parse(t)}catch{return new u(`HTTP ${e.status}${r?` \xB7 ${r}`:""}`)}if(!i?.error||typeof i.error.message!="string")return new u(`HTTP ${e.status}`);let a=typeof i.error.code=="string"?i.error.code:"user_error",c=a==="user_error"?"":`${a}: `,d=y(`HTTP ${e.status} \xB7 ${c}${i.error.message}`,n),l=un(i.error.details,n),p;a==="idempotency_conflict"?p="Reuse the same key only with the same operation and input. Use a new unique key for a different request.":[i.error.message,...l].some(x=>typeof x=="string"&&x.includes("[Truncated]"))&&o.action&&(p=`Run "hyperscale product actions ${o.action}" to read the full input schema and allowed values.`);let m=e.headers.get("x-request-id")??(i&&typeof i=="object"&&typeof i.requestId=="string"?i.requestId:void 0),f=e.headers.get("hyperscale-operation-id")??void 0,$=e.headers.get("hyperscale-receipt-id")??void 0,g=m?y(m,n):void 0,h=f?y(f,n):void 0,I=$?y($,n):void 0,P=new u([d,...l].join(`
|
|
120
120
|
`),{code:a,...i.error.details?{details:M(i.error.details,n)}:{},...p?{fix:p}:{}});return g&&(P.requestId=g),h&&(P.operationId=h),I&&(P.receiptId=I),P}function M(e,t){return typeof e=="string"?y(e,t):Array.isArray(e)?e.map(n=>M(n,t)):e&&typeof e=="object"?Object.fromEntries(Object.entries(e).map(([n,o])=>[y(n,t),M(o,t)])):e}function un(e,t){if(!e||typeof e!="object")return[];if(Array.isArray(e.issues))return e.issues.flatMap(o=>{if(!o||typeof o!="object")return[];let i=(Array.isArray(o.path)?o.path.join("."):"input")||"input";return typeof o.message=="string"?[`${i}: ${y(o.message,t)}`]:[]});let n=[];return ce(e,"",n,t),n}function ce(e,t,n,o){if(Array.isArray(e)){if(e.every(r=>r===null||typeof r!="object")){n.push(`${Ae(t)}: ${y(e.join(", "),o)}`);return}e.forEach((r,i)=>ce(r,`${t}[${i}]`,n,o));return}if(e&&typeof e=="object"){for(let[r,i]of Object.entries(e))ce(i,t?`${t}.${r}`:r,n,o);return}t&&n.push(`${Ae(t)}: ${y(String(e),o)}`)}function Ae(e){let t=e.replace(/([a-z0-9])([A-Z])/g,"$1 $2").replaceAll("."," ");return t.charAt(0).toUpperCase()+t.slice(1)}async function dn(e,t){let n=await k(e,t),o=K(n,e),r=await b(n,"/v1/sandbox-api-keys",A({name:e["--name"]??"Founder CLI",tenantId:n.tenantId,productId:o}),n.token,[n.token]);if(e["--json"]){w(r);return}s(`Key: ${r.apiKeyId??"unknown"}`),s(`Product: ${r.productId??o}`),s(`Status: ${r.status??"unknown"}`),r.secret?(s(`Secret: ${r.secret}`),s("Store it now. Hyperscale will not return it again."),s("Next:"),s(` export HYPERSCALE_API_KEY=${ln(r.secret)}`),s(` hyperscale product actions --product ${o}`)):s("The key already existed, so the one-time secret is unavailable.")}function ln(e){return`'${String(e).replaceAll("'",`'"'"'`)}'`}async function pn(e,t){let n=await k(e,t),o=K(n,e),r=await C(n,"/v1/api-keys",{tenantId:n.tenantId},"api_key.list",n.token,[n.token]),i=v(r,"api_key.list").filter(c=>c.productId===o),a={...r,items:i};if(e["--json"]){w(a);return}for(let c of i)s(`${c.apiKeyId} ${c.name??"unnamed"} ${c.status??"unknown"}`)}async function mn(e,t,n){if(!n)throw new u("key revoke needs an API key id");let o=await k(e,t),r=K(o,e),i=await b(o,`/v1/api-keys/${encodeURIComponent(n)}/revoke`,A({tenantId:o.tenantId,productId:r}),o.token,[o.token]);e["--json"]?w(i):s(`Key ${i.apiKeyId??n}: ${i.status??"revoked"}`)}async function fn(e,t){let n=await k(e,t),o=n.identity??await T(n,n.token),r=he(n,o);if(e["--json"]){w(r);return}s(`User: ${o.email}`),s(`Tenant: ${o.tenantId}`),s(`Role: ${o.role}`),s(`Token: ${o.name}`),s(`Expires: ${o.expiresAt}`)}async function hn(e,t,n){let o=await Le(e),r=n?n.toLowerCase():null,i=r?o.operations.filter(c=>c.name.toLowerCase().includes(r)||c.path.toLowerCase().includes(r)):o.operations;if(t["--json"]){s(JSON.stringify(i,null,2));return}if(i.length===0){s(n?`No operation matches ${n}`:"No operations");return}let a=Math.max(...i.map(c=>c.name.length));for(let c of i)s(`${c.name.padEnd(a)} ${c.method.padEnd(6)}${c.path}`)}async function yn(e,t){let n=await k(e,t),o=await C(n,"/v1/activity",{tenantId:n.tenantId},"activity.list",n.token,[n.token]),r=v(o,"activity.list");if(e["--json"]){w(o);return}s("Time Activity Target Status");for(let i of r){let a=i.operation??i.auditEvent??"activity",c=i.resourceKind&&i.resourceId?`${i.resourceKind}:${i.resourceId}`:i.resourceKind??i.resourceId??"-";s(`${i.occurredAt??"unknown"} ${a} ${c} ${i.status??"recorded"}`)}}function wn(e,t){let n={...t},o=[],r=e.path.replace(/\{([^}]+)\}/g,(i,a)=>{let c=n[a];return c==null?(o.push(a),""):(delete n[a],encodeURIComponent(String(c)))});if(o.length>0)throw new u(`${e.name} needs ${o.join(", ")} in --input`);return{path:r,remaining:n}}function gn(e){let t=new URLSearchParams;for(let[o,r]of Object.entries(e))r!=null&&t.set(o,typeof r=="string"?r:JSON.stringify(r));let n=t.toString();return n?`?${n}`:""}function ue(e,t){let n=Array.from({length:t.length+1},(o,r)=>r);for(let o=1;o<=e.length;o+=1){let r=[o];for(let i=1;i<=t.length;i+=1)r[i]=Math.min(r[i-1]+1,n[i]+1,n[i-1]+(e[o-1]===t[i-1]?0:1));n.splice(0,n.length,...r)}return n[t.length]}function In(e,t){let n=e.find(i=>i.name===t);if(n)return n;let o=e.filter(i=>i.operationId===t);if(o.length===1)return o[0];if(o.length>1)throw new u(`${t} matches more than one operation. Use one of: ${o.map(i=>i.name).join(", ")}.`);let r=e.map(i=>({candidate:i,distance:Math.min(ue(t,i.name),ue(t,i.operationId))})).sort((i,a)=>i.distance-a.distance||i.candidate.name.localeCompare(a.candidate.name)).slice(0,3).flatMap(({candidate:i})=>[i.name,i.operationId]);throw new u(`${t} is not an operation in the selected Product's machine document. Closest valid names: ${r.join(", ")}.`)}async function $n(e,t,n){if(!n)throw new u("call needs an operation name");let o=await Le(e),r=In(o.operations,n),i=await qe(t),{path:a,remaining:c}=wn(r,i),d={method:r.method},l=a;r.method==="GET"?l+=gn(c):(d.body=JSON.stringify(c),d.headers={"content-type":"application/json",...r.idempotency==="not_required"?{}:{"idempotency-key":t["--idempotency-key"]??globalThis.crypto.randomUUID()}});let{response:p,text:m}=await J(e,l,d);if(p.ok){if(t["--json"]){let f=kt(m),$=p.headers.get("x-request-id")??(f&&typeof f=="object"&&typeof f.requestId=="string"?f.requestId:null),g=p.headers.get("hyperscale-operation-id")??null,h=p.headers.get("hyperscale-receipt-id")??null,I=Ue(p.headers),P=$?y($,[e.apiKey]):null,x=g?y(g,[e.apiKey]):null,Me=h?y(h,[e.apiKey]):null,ze=I?y(I,[e.apiKey]):null;w({status:p.status,data:f,requestId:P,operationId:x,receiptId:Me,traceId:ze});return}s(Fe(m));return}throw H(p,m,[e.apiKey])}async function qe(e){if(e["--input"]!==void 0&&e["--input-file"]!==void 0)throw new u("Use only one of --input and --input-file");if(e["--input"]!==void 0)return ne(e["--input"],"--input");if(e["--input-file"]!==void 0){let t;try{t=await U(e["--input-file"],"utf8")}catch(n){throw new u(`Could not read ${e["--input-file"]}: ${n.message}`)}return ne(t,"--input-file")}if(!process.stdin.isTTY){let t=await It();if(t.trim()!=="")return ne(t,"stdin")}return{}}function ne(e,t="--input"){if(e===void 0)return{};let n;try{n=JSON.parse(e)}catch(o){throw new u(`${t} is not valid JSON: ${o.message}`)}if(n===null||typeof n!="object"||Array.isArray(n))throw new u(`${t} must be a JSON object`);return n}function Fe(e){if(e.trim()==="")return"";try{return JSON.stringify(JSON.parse(e),null,2)}catch{return e}}function s(e){process.stdout.write(`${e}
|
|
121
121
|
`)}function w(e){s(JSON.stringify(e,null,2))}function kn(e){for(let t=0;t<e.length;t+=1){let n=e[t];if(!n.startsWith("--"))return n;ve.has(n)&&(t+=1)}}function Pn(e,t){let n=kn(t)==="call",o=t.includes("--json");if(n&&o&&e instanceof E){w({status:e.status,error:e.structuredError??{code:e.code??"http_error",message:e.message},requestId:e.requestId??null,operationId:e.operationId??null,receiptId:e.receiptId??null,traceId:e.traceId??null});let c=typeof e.message=="string"?e.message:e.stack??String(e);process.stderr.write(`${c}
|
|
122
122
|
`);return}let r=e instanceof u&&typeof e.shownOnce=="string"?e.shownOnce:void 0;if(!o){let c=e instanceof u?e.message:e.stack??String(e),d=e instanceof u&&typeof e.fix=="string"?`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hyperscale0/cli",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.16",
|
|
4
4
|
"description": "Hyperscale CLI: compose Products, manage keys, and call Product operations.",
|
|
5
5
|
"license": "LicenseRef-Hyperscale-Proprietary",
|
|
6
6
|
"author": "Hyperscale LLC",
|
|
@@ -20,5 +20,5 @@
|
|
|
20
20
|
"publishConfig": {
|
|
21
21
|
"access": "public"
|
|
22
22
|
},
|
|
23
|
-
"gitHead": "
|
|
23
|
+
"gitHead": "67dc24fafb99eaacc2622151f451cbe670ae75e0"
|
|
24
24
|
}
|