@burdenoff/cli-sdk 2026.504.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/README.md +60 -0
  2. package/dist/chunk-KTKHJORN.js +1 -0
  3. package/dist/chunk-MRONTCXQ.js +879 -0
  4. package/dist/chunk-RNWXATAC.js +32 -0
  5. package/dist/core/index.cjs +32 -0
  6. package/dist/core/index.d.cts +57 -0
  7. package/dist/core/index.d.ts +57 -0
  8. package/dist/core/index.js +1 -0
  9. package/dist/index.cjs +32 -0
  10. package/dist/index.d.cts +4 -0
  11. package/dist/index.d.ts +4 -0
  12. package/dist/index.js +1 -0
  13. package/dist/module-Bv5zhYt2.d.cts +166 -0
  14. package/dist/module-Bv5zhYt2.d.ts +166 -0
  15. package/dist/modules/auth/index.cjs +183 -0
  16. package/dist/modules/auth/index.d.cts +7 -0
  17. package/dist/modules/auth/index.d.ts +7 -0
  18. package/dist/modules/auth/index.js +160 -0
  19. package/dist/modules/billing/index.cjs +105 -0
  20. package/dist/modules/billing/index.d.cts +7 -0
  21. package/dist/modules/billing/index.d.ts +7 -0
  22. package/dist/modules/billing/index.js +105 -0
  23. package/dist/modules/channels/index.cjs +70 -0
  24. package/dist/modules/channels/index.d.cts +7 -0
  25. package/dist/modules/channels/index.d.ts +7 -0
  26. package/dist/modules/channels/index.js +70 -0
  27. package/dist/modules/conversations/index.cjs +37 -0
  28. package/dist/modules/conversations/index.d.cts +7 -0
  29. package/dist/modules/conversations/index.d.ts +7 -0
  30. package/dist/modules/conversations/index.js +37 -0
  31. package/dist/modules/devportal/index.cjs +133 -0
  32. package/dist/modules/devportal/index.d.cts +7 -0
  33. package/dist/modules/devportal/index.d.ts +7 -0
  34. package/dist/modules/devportal/index.js +133 -0
  35. package/dist/modules/export/index.cjs +37 -0
  36. package/dist/modules/export/index.d.cts +7 -0
  37. package/dist/modules/export/index.d.ts +7 -0
  38. package/dist/modules/export/index.js +37 -0
  39. package/dist/modules/files/index.cjs +49 -0
  40. package/dist/modules/files/index.d.cts +7 -0
  41. package/dist/modules/files/index.d.ts +7 -0
  42. package/dist/modules/files/index.js +49 -0
  43. package/dist/modules/groups/index.cjs +67 -0
  44. package/dist/modules/groups/index.d.cts +7 -0
  45. package/dist/modules/groups/index.d.ts +7 -0
  46. package/dist/modules/groups/index.js +67 -0
  47. package/dist/modules/health/index.cjs +1 -0
  48. package/dist/modules/health/index.d.cts +7 -0
  49. package/dist/modules/health/index.d.ts +7 -0
  50. package/dist/modules/health/index.js +1 -0
  51. package/dist/modules/integrations/index.cjs +44 -0
  52. package/dist/modules/integrations/index.d.cts +7 -0
  53. package/dist/modules/integrations/index.d.ts +7 -0
  54. package/dist/modules/integrations/index.js +44 -0
  55. package/dist/modules/notifications/index.cjs +26 -0
  56. package/dist/modules/notifications/index.d.cts +7 -0
  57. package/dist/modules/notifications/index.d.ts +7 -0
  58. package/dist/modules/notifications/index.js +26 -0
  59. package/dist/modules/organizations/index.cjs +53 -0
  60. package/dist/modules/organizations/index.d.cts +7 -0
  61. package/dist/modules/organizations/index.d.ts +7 -0
  62. package/dist/modules/organizations/index.js +53 -0
  63. package/dist/modules/products/index.cjs +102 -0
  64. package/dist/modules/products/index.d.cts +7 -0
  65. package/dist/modules/products/index.d.ts +7 -0
  66. package/dist/modules/products/index.js +102 -0
  67. package/dist/modules/rbac/index.cjs +63 -0
  68. package/dist/modules/rbac/index.d.cts +7 -0
  69. package/dist/modules/rbac/index.d.ts +7 -0
  70. package/dist/modules/rbac/index.js +63 -0
  71. package/dist/modules/sandbox/index.cjs +33 -0
  72. package/dist/modules/sandbox/index.d.cts +7 -0
  73. package/dist/modules/sandbox/index.d.ts +7 -0
  74. package/dist/modules/sandbox/index.js +1 -0
  75. package/dist/modules/scheduler/index.cjs +32 -0
  76. package/dist/modules/scheduler/index.d.cts +7 -0
  77. package/dist/modules/scheduler/index.d.ts +7 -0
  78. package/dist/modules/scheduler/index.js +32 -0
  79. package/dist/modules/security/index.cjs +69 -0
  80. package/dist/modules/security/index.d.cts +7 -0
  81. package/dist/modules/security/index.d.ts +7 -0
  82. package/dist/modules/security/index.js +69 -0
  83. package/dist/modules/store/index.cjs +63 -0
  84. package/dist/modules/store/index.d.cts +7 -0
  85. package/dist/modules/store/index.d.ts +7 -0
  86. package/dist/modules/store/index.js +63 -0
  87. package/dist/modules/support/index.cjs +45 -0
  88. package/dist/modules/support/index.d.cts +7 -0
  89. package/dist/modules/support/index.d.ts +7 -0
  90. package/dist/modules/support/index.js +45 -0
  91. package/dist/modules/tags/index.cjs +54 -0
  92. package/dist/modules/tags/index.d.cts +7 -0
  93. package/dist/modules/tags/index.d.ts +7 -0
  94. package/dist/modules/tags/index.js +54 -0
  95. package/dist/modules/tours/index.cjs +48 -0
  96. package/dist/modules/tours/index.d.cts +7 -0
  97. package/dist/modules/tours/index.d.ts +7 -0
  98. package/dist/modules/tours/index.js +48 -0
  99. package/dist/modules/vibecontrols/index.cjs +844 -0
  100. package/dist/modules/vibecontrols/index.d.cts +7 -0
  101. package/dist/modules/vibecontrols/index.d.ts +7 -0
  102. package/dist/modules/vibecontrols/index.js +2 -0
  103. package/dist/modules/workspaces/index.cjs +90 -0
  104. package/dist/modules/workspaces/index.d.cts +7 -0
  105. package/dist/modules/workspaces/index.d.ts +7 -0
  106. package/dist/modules/workspaces/index.js +77 -0
  107. package/package.json +104 -0
@@ -0,0 +1,32 @@
1
+ import {existsSync,readFileSync,writeFileSync,chmodSync,unlinkSync,mkdirSync}from'fs';import {join}from'path';import {homedir}from'os';import {GraphQLClient}from'graphql-request';import C from'cross-fetch';import {Command}from'commander';var W=300*1e3;function S(e){let n=join(e,"auth.json");function r(){existsSync(e)||mkdirSync(e,{recursive:true,mode:448});}function t(){try{if(!existsSync(n))return null;let a=readFileSync(n,"utf8");return JSON.parse(a)}catch{return null}}function i(a){r(),writeFileSync(n,JSON.stringify(a,null,2),{encoding:"utf8",mode:384});try{chmodSync(n,384);}catch{}}function s(){try{existsSync(n)&&unlinkSync(n);}catch{}}function o(){let a=t();return a?.expiresAt?Date.now()>=a.expiresAt:false}function c(){let a=t();return a?.expiresAt?Date.now()+W>=a.expiresAt:false}function p(){let a=t();return a?.workspaceTokenExpiresAt?Date.now()>=a.workspaceTokenExpiresAt:false}function g(){let a=t();return a?.workspaceTokenExpiresAt?Date.now()+W>=a.workspaceTokenExpiresAt:false}function d(){return t()?.accessToken?!o():false}return {read:t,write:i,clear:s,isTokenExpired:o,isTokenExpiringSoon:c,isWorkspaceTokenExpired:p,isWorkspaceTokenExpiringSoon:g,isAuthenticated:d}}var ae=["workspaceEndpoint","globalEndpoint","oidcIssuer","clientId","defaultFormat","verbose","authServiceEndpoint"];function $(e){let n=join(homedir(),".config",e.configDirName),r=join(n,"config.json"),t={workspaceEndpoint:e.workspaceEndpointDefault,globalEndpoint:e.globalEndpointDefault};function i(){existsSync(n)||mkdirSync(n,{recursive:true,mode:448});}function s(){try{if(!existsSync(r))return {...t};let d=readFileSync(r,"utf8"),a=JSON.parse(d);return {...t,...a}}catch{return {...t}}}function o(d){i(),writeFileSync(r,JSON.stringify(d,null,2),{encoding:"utf8"});try{chmodSync(r,384);}catch{}}function c(d){return s()[d]}function p(d,a){let u=s();u[d]=a,o(u);}function g(){let d=s(),a=d.clientId||e.oidcClientId,u=d.oidcIssuer;if(!u){let l=d.globalEndpoint;l.includes("localhost")||l.includes("127.0.0.1")?u=l.replace(/\/graphql$/,"").replace(/\/global\/graphql$/,"/global"):u=e.oidcIssuerProd??"https://graphql.burdenoff.com/global";}return {oidcIssuer:u,clientId:a}}return {read:s,write:o,get:c,set:p,path:()=>r,dir:()=>n,resolveOIDC:g}}async function ce(e){let n=`${e.oidcIssuer}/oidc/device/code`,r=new URLSearchParams({client_id:e.clientId,scope:"openid profile email offline_access"}),t=await C(n,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:r.toString()});if(!t.ok){let s=await t.text().catch(()=>"Unknown error");throw new Error(`Device code request failed (${t.status}): ${s}`)}let i=await t.json();return {deviceCode:i.device_code,userCode:i.user_code,verificationUri:i.verification_uri,verificationUriComplete:i.verification_uri_complete??null,expiresIn:i.expires_in,interval:i.interval??5}}async function ue(e,n,r){let t=`${r.oidcIssuer}/oauth/device/token`,i=n;for(;;){await new Promise(p=>setTimeout(p,i*1e3));let s=await C(t,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({grant_type:"urn:ietf:params:oauth:grant-type:device_code",device_code:e,client_id:r.clientId}).toString()}),o=await s.json();if(s.ok&&o.access_token)return {accessToken:o.access_token,refreshToken:o.refresh_token??"",expiresIn:o.expires_in??3600};let c=o.error;switch(c){case "authorization_pending":continue;case "slow_down":i+=5;continue;case "expired_token":throw new Error("Device code has expired. Please try again.");case "access_denied":throw new Error("Authorization was denied by the user.");default:throw new Error(`Device code polling failed: ${o.error_description??c??"Unknown error"}`)}}}async function O(e,n,r,t){let s=await C(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:`
2
+ mutation AuthenticateApp($input: AuthenticateAppInput!) {
3
+ authenticateApp(input: $input) {
4
+ accessToken tokenType expiresIn scopes
5
+ }
6
+ }
7
+ `,variables:{input:{clientId:n,clientSecret:r,scopes:t}}})});if(!s.ok){let c=await s.text().catch(()=>"Unknown error");throw new Error(`App authentication failed (${s.status}): ${c}`)}let o=await s.json();if(o.errors?.length)throw new Error(`App authentication failed: ${o.errors[0]?.message??"unknown error"}`);if(!o.data?.authenticateApp?.accessToken)throw new Error("App authentication failed: no access token returned");return o.data.authenticateApp}async function D(e,n,r,t){let s=await C(e,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({query:`
8
+ mutation IssueWorkspaceToken($input: IssueWorkspaceTokenInput!) {
9
+ issueWorkspaceToken(input: $input) {
10
+ success token expiresAt scopes
11
+ error { code message }
12
+ }
13
+ }
14
+ `,variables:{input:{workspaceId:r,organizationId:t}}})});if(!s.ok){let p=await s.text().catch(()=>"Unknown error");throw new Error(`Workspace token request failed (${s.status}): ${p}`)}let o=await s.json();if(o.errors?.length)throw new Error(`Workspace token failed: ${o.errors[0]?.message??"unknown error"}`);let c=o.data?.issueWorkspaceToken;if(!c?.success||!c.token){let p=c?.error?.message??"Unknown error";throw new Error(`Workspace token failed: ${p}`)}return {token:c.token,expiresAt:c.expiresAt??"",scopes:c.scopes??[]}}async function le(e,n){let t=await C(e,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({query:`
15
+ query MyWorkspaces($limit: Int) {
16
+ myWorkspaces(limit: $limit) {
17
+ items { id name slug tenantId organizationId }
18
+ }
19
+ }
20
+ `,variables:{limit:50}})});if(!t.ok){let s=await t.text().catch(()=>"Unknown error");throw new Error(`Failed to fetch workspaces (${t.status}): ${s}`)}let i=await t.json();if(i.errors?.length)throw new Error(`Failed to fetch workspaces: ${i.errors[0]?.message??"unknown error"}`);return i.data?.myWorkspaces?.items??[]}function pe(e){try{let n=new URL(e);return n.protocol==="http:"||n.protocol==="https:"}catch{return false}}async function de(e){try{if(!pe(e))return !1;let{execFile:n}=await import('child_process'),r=process.platform,t,i;return r==="darwin"?(t="open",i=[e]):r==="win32"?(t="cmd",i=["/c","start","",e]):(t="xdg-open",i=[e]),new Promise(s=>{n(t,i,o=>{s(!o);});})}catch{return false}}var ge=3e4,U=3,fe=1e3;function me(e){return new Promise(n=>setTimeout(n,e))}function ke(e){if(e instanceof TypeError)return true;if(e&&typeof e=="object"&&"response"in e){let n=e.response;if(n&&typeof n.status=="number"&&n.status>=500)return true}return false}function H(e){if(e&&typeof e=="object"&&"response"in e){let n=e,r=n.response?.errors?.[0],t=r?.extensions?.originalError?.message;if(t)return t;if(r?.message)return r.message;if(n.message)return n.message}return e instanceof Error?e.message:String(e)}function T(e){let n={};return e?.accessToken&&(n.Authorization=`Bearer ${e.accessToken}`),e?.organizationId&&(n["x-org-id"]=e.organizationId),n}function z(e){let n=T(e);return e?.workspaceToken&&(n["X-Workspace-Authorization"]=`Bearer ${e.workspaceToken}`),e?.organizationId&&(n["x-org-id"]=e.organizationId),n}async function R(e,n,r){let t;for(let i=0;i<U;i++)try{let s=new AbortController,o=setTimeout(()=>s.abort(),ge);try{return await e.request({document:n,variables:r,signal:s.signal})}finally{clearTimeout(o);}}catch(s){if(t=s,s&&typeof s=="object"&&"response"in s){let o=s.response;if(o&&typeof o.status=="number"&&o.status>=400&&o.status<500)break}if(ke(s)&&i<U-1){let o=fe*Math.pow(2,i);await me(o);continue}break}throw new Error(H(t))}function L(e,n){let r=null,t=null;function i(){let a=e.read(),u=n.read();return r=new GraphQLClient(a.workspaceEndpoint),r.setHeaders(z(u)),t=new GraphQLClient(a.globalEndpoint),t.setHeaders(T(u)),{workspace:r,global:t}}async function s(){let a=n.read();if(!a)return;if(a.authMethod==="client_credentials"&&a.clientId&&a.clientSecret){let y=e.read();try{let w=await O(y.globalEndpoint,a.clientId,a.clientSecret);n.write({...a,accessToken:w.accessToken,expiresAt:Date.now()+w.expiresIn*1e3}),r=null,t=null;}catch{}return}if(!a.refreshToken)return;let u=e.read(),l=new GraphQLClient(u.globalEndpoint);l.setHeaders({Authorization:`Bearer ${a.accessToken}`});let I=`
21
+ mutation RefreshToken($token: String!) {
22
+ refreshToken(token: $token) {
23
+ accessToken
24
+ refreshToken
25
+ expiresIn
26
+ }
27
+ }
28
+ `;try{let w=(await l.request(I,{token:a.refreshToken})).refreshToken;n.write({...a,accessToken:w.accessToken,refreshToken:w.refreshToken,expiresAt:Date.now()+w.expiresIn*1e3}),r=null,t=null;}catch{}}async function o(){let a=n.read();if(!a?.accessToken||!a.workspaceId||!a.organizationId)return;let u=e.read();try{let l=await D(u.workspaceEndpoint,a.accessToken,a.workspaceId,a.organizationId);n.write({...a,workspaceToken:l.token,workspaceTokenExpiresAt:new Date(l.expiresAt).getTime()}),r=null;}catch{}}async function c(){n.isTokenExpiringSoon()&&await s(),n.read()?.workspaceToken&&n.isWorkspaceTokenExpiringSoon()&&await o();}return {workspace:{async request(a,u){await c();let{workspace:l}=r?{workspace:r}:i();return l.setHeaders(z(n.read())),R(l,a,u)}},global:{async request(a,u){let{global:l}=t?{global:t}:i();return l.setHeaders(T(n.read())),R(l,a,u)}},workspaceAuthOnly:{async request(a,u){let l=e.read(),I=n.read(),y=new GraphQLClient(l.workspaceEndpoint);return y.setHeaders(T(I)),R(y,a,u)}},reset(){r=null,t=null;}}}function _(){return !!(process.stdout.isTTY&&process.stdin.isTTY)}function B(e){if(e.format){let n=e.format.toLowerCase();if(n==="json"||n==="table"||n==="yaml")return n}return _()?"table":"json"}function P(e){console.log(JSON.stringify(e,null,2));}function V(e,n){if(e.length===0)return;let r=e.map((s,o)=>{let c=s.length;for(let p of n){let g=p[o]??"";g.length>c&&(c=g.length);}return Math.min(c,50)}),t=r.map(s=>"-".repeat(s+2)).join("+"),i=s=>s.map((o,c)=>` ${(o??"").padEnd(r[c]??0)} `).join("|");console.log(i(e)),console.log(t);for(let s of n)console.log(i(s));}function q(e,n){let r=" ".repeat(n),t=[];for(let[i,s]of Object.entries(e))if(s==null)t.push(`${r}${i}: null`);else if(Array.isArray(s)){t.push(`${r}${i}:`);for(let o of s)typeof o=="object"&&o!==null?(t.push(`${r} -`),t.push(q(o,n+2))):t.push(`${r} - ${String(o)}`);}else typeof s=="object"?(t.push(`${r}${i}:`),t.push(q(s,n+1))):t.push(`${r}${i}: ${String(s)}`);return t.join(`
29
+ `)}function J(e){if(typeof e!="object"||e===null){console.log(String(e));return}console.log(q(e,0));}function we(e){console.log(`\u2713 ${e}`);}function Y(e){console.error(`\u2717 ${e}`);}function he(e){console.warn(`! ${e}`);}function ye(e){console.log(`\u2139 ${e}`);}function Ce(e){if(!e)return "-";try{return new Date(e).toLocaleString()}catch{return e}}function xe(e){if(!e)return "-";switch(e.toUpperCase()){case "ACTIVE":case "RUNNING":case "HEALTHY":return `\u2713 ${e}`;case "INACTIVE":case "STOPPED":case "PENDING":return `\u25CB ${e}`;case "ERROR":return `\u2717 ${e}`;case "ARCHIVED":return `\u2192 ${e}`;case "STARTING":return `\u25B6 ${e}`;case "TERMINATED":return `\u25A0 ${e}`;default:return e}}function be(e,n){return e?e.length<=n?e:e.substring(0,n-3)+"...":"-"}function Te(e,n,r){switch(B(e)){case "json":P(n);break;case "yaml":J(n);break;case "table":r?V(r.headers,r.rows):P(n);break}}async function ve(e,n){return n?true:_()?new Promise(r=>{process.stdout.write(`${e} [y/N] `),process.stdin.setEncoding("utf8"),process.stdin.once("data",t=>{let i=t.trim().toLowerCase();r(i==="y"||i==="yes");}),process.stdin.resume();}):(Y(`${e} Use --force to skip confirmation.`),false)}var j={isInteractive:_,getFormat:B,formatAndOutput:Te,printJson:P,printTable:V,printYaml:J,printSuccess:we,printError:Y,printWarning:he,printInfo:ye,formatDate:Ce,formatStatus:xe,truncate:be,confirm:ve};function F(e={}){let{verbose:n=false,quiet:r=false}=e;return {debug(t,...i){n&&console.error(`[debug] ${t}`,...i);},info(t,...i){r||console.error(`[info] ${t}`,...i);},warn(t,...i){console.error(`[warn] ${t}`,...i);},error(t,...i){console.error(`[error] ${t}`,...i);}}}function Ee(e){return e.includes("localhost")||e.includes("127.0.0.1")?"local":e.includes("alpha")||e.includes("staging")?"staging":"prod"}function Ie(e){return !!e&&typeof e.debug=="function"&&typeof e.info=="function"}function Ae(e){let n=$(e.defaults),r=S(n.dir()),t=L(n,r),i=e.output??j,s=Ie(e.logger)?e.logger:F(e.logger),o=e.env??Ee(n.read().workspaceEndpoint);return {productName:e.productName,productVersion:e.productVersion,defaults:e.defaults,config:n,auth:r,gql:t,output:i,logger:s,env:o}}var h=class extends Error{exitCode;hint;constructor(n,r){super(n),this.name="CliUserError",this.exitCode=r?.exitCode??1,this.hint=r?.hint;}},x=class extends h{constructor(n,r){super(n,{exitCode:2,hint:r?.hint??"Run `<product> auth login` to authenticate."}),this.name="CliAuthError";}},k=class extends Error{cause;constructor(n,r){super(n),this.name="CliInternalError",this.cause=r;}};var v=class extends k{constructor(n,r){super(`Module '${n}' declares dependency on '${r}', but '${r}' is not in the module list.`),this.name="MissingDependencyError";}},E=class extends k{constructor(n){super(`Circular dependency detected among modules: ${n.join(" -> ")}`),this.name="CircularDependencyError";}};function N(e){let n=new Map;for(let o of e){if(n.has(o.id))throw new k(`Duplicate module id: '${o.id}'`);n.set(o.id,o);}for(let o of e)for(let c of o.dependsOn??[])if(!n.has(c))throw new v(o.id,c);let r=[],t=new Set,i=new Set;function s(o,c){if(!i.has(o.id)){if(t.has(o.id))throw new E([...c,o.id]);t.add(o.id);for(let p of o.dependsOn??[]){let g=n.get(p);g&&s(g,[...c,o.id]);}t.delete(o.id),i.add(o.id),r.push(o);}}for(let o of e)s(o,[]);return r}function $e(e,n,r){let t=new Command;t.name(r.name).description(r.description??"").version(r.version,"-v, --version").option("-f, --format <format>","Output format (json, table, yaml)").option("--verbose","Enable verbose logging").option("--no-color","Disable colored output");let i=N(n);for(let o of i)o.register(t,e);r.helpExamples?.length&&t.addHelpText("after",`
30
+ Examples:
31
+ `+r.helpExamples.map(o=>" "+o).join(`
32
+ `)),t.on("command:*",()=>{e.output.printError(`Invalid command: ${t.args.join(" ")}`),e.output.printInfo(`Run \`${r.name} --help\` for available commands.`),process.exit(1);});async function s(o=process.argv){try{await t.parseAsync(o),o.length<=2&&t.outputHelp();}catch(c){Oe(e,c);}}return {program:t,run:s}}function Oe(e,n){if(n instanceof x&&(e.output.printError(n.message),n.hint&&e.output.printInfo(n.hint),process.exit(n.exitCode)),n instanceof h&&(e.output.printError(n.message),n.hint&&e.output.printInfo(n.hint),process.exit(n.exitCode)),n instanceof k&&(e.output.printError(`Internal error: ${n.message}`),n.cause&&e.logger.debug("caused by:",n.cause),process.exit(70)),n&&typeof n=="object"&&"code"in n&&"exitCode"in n){let t=n.exitCode;process.exit(typeof t=="number"?t:0);}let r=n instanceof Error?n.message:String(n);e.output.printError(r),process.exit(1);}export{S as a,ae as b,$ as c,ce as d,ue as e,O as f,D as g,le as h,de as i,H as j,L as k,j as l,F as m,Ae as n,h as o,x as p,k as q,v as r,E as s,N as t,$e as u};
@@ -0,0 +1,32 @@
1
+ 'use strict';var fs=require('fs'),path=require('path'),os=require('os'),graphqlRequest=require('graphql-request'),y=require('cross-fetch'),commander=require('commander');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var y__default=/*#__PURE__*/_interopDefault(y);var N=300*1e3;function A(e){let n=path.join(e,"auth.json");function r(){fs.existsSync(e)||fs.mkdirSync(e,{recursive:true,mode:448});}function t(){try{if(!fs.existsSync(n))return null;let a=fs.readFileSync(n,"utf8");return JSON.parse(a)}catch{return null}}function i(a){r(),fs.writeFileSync(n,JSON.stringify(a,null,2),{encoding:"utf8",mode:384});try{fs.chmodSync(n,384);}catch{}}function s(){try{fs.existsSync(n)&&fs.unlinkSync(n);}catch{}}function o(){let a=t();return a?.expiresAt?Date.now()>=a.expiresAt:false}function c(){let a=t();return a?.expiresAt?Date.now()+N>=a.expiresAt:false}function p(){let a=t();return a?.workspaceTokenExpiresAt?Date.now()>=a.workspaceTokenExpiresAt:false}function g(){let a=t();return a?.workspaceTokenExpiresAt?Date.now()+N>=a.workspaceTokenExpiresAt:false}function d(){return t()?.accessToken?!o():false}return {read:t,write:i,clear:s,isTokenExpired:o,isTokenExpiringSoon:c,isWorkspaceTokenExpired:p,isWorkspaceTokenExpiringSoon:g,isAuthenticated:d}}var ie=["workspaceEndpoint","globalEndpoint","oidcIssuer","clientId","defaultFormat","verbose","authServiceEndpoint"];function S(e){let n=path.join(os.homedir(),".config",e.configDirName),r=path.join(n,"config.json"),t={workspaceEndpoint:e.workspaceEndpointDefault,globalEndpoint:e.globalEndpointDefault};function i(){fs.existsSync(n)||fs.mkdirSync(n,{recursive:true,mode:448});}function s(){try{if(!fs.existsSync(r))return {...t};let d=fs.readFileSync(r,"utf8"),a=JSON.parse(d);return {...t,...a}}catch{return {...t}}}function o(d){i(),fs.writeFileSync(r,JSON.stringify(d,null,2),{encoding:"utf8"});try{fs.chmodSync(r,384);}catch{}}function c(d){return s()[d]}function p(d,a){let u=s();u[d]=a,o(u);}function g(){let d=s(),a=d.clientId||e.oidcClientId,u=d.oidcIssuer;if(!u){let l=d.globalEndpoint;l.includes("localhost")||l.includes("127.0.0.1")?u=l.replace(/\/graphql$/,"").replace(/\/global\/graphql$/,"/global"):u=e.oidcIssuerProd??"https://graphql.burdenoff.com/global";}return {oidcIssuer:u,clientId:a}}return {read:s,write:o,get:c,set:p,path:()=>r,dir:()=>n,resolveOIDC:g}}async function ae(e){let n=`${e.oidcIssuer}/oidc/device/code`,r=new URLSearchParams({client_id:e.clientId,scope:"openid profile email offline_access"}),t=await y__default.default(n,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:r.toString()});if(!t.ok){let s=await t.text().catch(()=>"Unknown error");throw new Error(`Device code request failed (${t.status}): ${s}`)}let i=await t.json();return {deviceCode:i.device_code,userCode:i.user_code,verificationUri:i.verification_uri,verificationUriComplete:i.verification_uri_complete??null,expiresIn:i.expires_in,interval:i.interval??5}}async function ce(e,n,r){let t=`${r.oidcIssuer}/oauth/device/token`,i=n;for(;;){await new Promise(p=>setTimeout(p,i*1e3));let s=await y__default.default(t,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({grant_type:"urn:ietf:params:oauth:grant-type:device_code",device_code:e,client_id:r.clientId}).toString()}),o=await s.json();if(s.ok&&o.access_token)return {accessToken:o.access_token,refreshToken:o.refresh_token??"",expiresIn:o.expires_in??3600};let c=o.error;switch(c){case "authorization_pending":continue;case "slow_down":i+=5;continue;case "expired_token":throw new Error("Device code has expired. Please try again.");case "access_denied":throw new Error("Authorization was denied by the user.");default:throw new Error(`Device code polling failed: ${o.error_description??c??"Unknown error"}`)}}}async function $(e,n,r,t){let s=await y__default.default(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:`
2
+ mutation AuthenticateApp($input: AuthenticateAppInput!) {
3
+ authenticateApp(input: $input) {
4
+ accessToken tokenType expiresIn scopes
5
+ }
6
+ }
7
+ `,variables:{input:{clientId:n,clientSecret:r,scopes:t}}})});if(!s.ok){let c=await s.text().catch(()=>"Unknown error");throw new Error(`App authentication failed (${s.status}): ${c}`)}let o=await s.json();if(o.errors?.length)throw new Error(`App authentication failed: ${o.errors[0]?.message??"unknown error"}`);if(!o.data?.authenticateApp?.accessToken)throw new Error("App authentication failed: no access token returned");return o.data.authenticateApp}async function O(e,n,r,t){let s=await y__default.default(e,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({query:`
8
+ mutation IssueWorkspaceToken($input: IssueWorkspaceTokenInput!) {
9
+ issueWorkspaceToken(input: $input) {
10
+ success token expiresAt scopes
11
+ error { code message }
12
+ }
13
+ }
14
+ `,variables:{input:{workspaceId:r,organizationId:t}}})});if(!s.ok){let p=await s.text().catch(()=>"Unknown error");throw new Error(`Workspace token request failed (${s.status}): ${p}`)}let o=await s.json();if(o.errors?.length)throw new Error(`Workspace token failed: ${o.errors[0]?.message??"unknown error"}`);let c=o.data?.issueWorkspaceToken;if(!c?.success||!c.token){let p=c?.error?.message??"Unknown error";throw new Error(`Workspace token failed: ${p}`)}return {token:c.token,expiresAt:c.expiresAt??"",scopes:c.scopes??[]}}async function ue(e,n){let t=await y__default.default(e,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({query:`
15
+ query MyWorkspaces($limit: Int) {
16
+ myWorkspaces(limit: $limit) {
17
+ items { id name slug tenantId organizationId }
18
+ }
19
+ }
20
+ `,variables:{limit:50}})});if(!t.ok){let s=await t.text().catch(()=>"Unknown error");throw new Error(`Failed to fetch workspaces (${t.status}): ${s}`)}let i=await t.json();if(i.errors?.length)throw new Error(`Failed to fetch workspaces: ${i.errors[0]?.message??"unknown error"}`);return i.data?.myWorkspaces?.items??[]}function le(e){try{let n=new URL(e);return n.protocol==="http:"||n.protocol==="https:"}catch{return false}}async function pe(e){try{if(!le(e))return !1;let{execFile:n}=await import('child_process'),r=process.platform,t,i;return r==="darwin"?(t="open",i=[e]):r==="win32"?(t="cmd",i=["/c","start","",e]):(t="xdg-open",i=[e]),new Promise(s=>{n(t,i,o=>{s(!o);});})}catch{return false}}var de=3e4,G=3,ge=1e3;function fe(e){return new Promise(n=>setTimeout(n,e))}function me(e){if(e instanceof TypeError)return true;if(e&&typeof e=="object"&&"response"in e){let n=e.response;if(n&&typeof n.status=="number"&&n.status>=500)return true}return false}function z(e){if(e&&typeof e=="object"&&"response"in e){let n=e,r=n.response?.errors?.[0],t=r?.extensions?.originalError?.message;if(t)return t;if(r?.message)return r.message;if(n.message)return n.message}return e instanceof Error?e.message:String(e)}function b(e){let n={};return e?.accessToken&&(n.Authorization=`Bearer ${e.accessToken}`),e?.organizationId&&(n["x-org-id"]=e.organizationId),n}function U(e){let n=b(e);return e?.workspaceToken&&(n["X-Workspace-Authorization"]=`Bearer ${e.workspaceToken}`),e?.organizationId&&(n["x-org-id"]=e.organizationId),n}async function D(e,n,r){let t;for(let i=0;i<G;i++)try{let s=new AbortController,o=setTimeout(()=>s.abort(),de);try{return await e.request({document:n,variables:r,signal:s.signal})}finally{clearTimeout(o);}}catch(s){if(t=s,s&&typeof s=="object"&&"response"in s){let o=s.response;if(o&&typeof o.status=="number"&&o.status>=400&&o.status<500)break}if(me(s)&&i<G-1){let o=ge*Math.pow(2,i);await fe(o);continue}break}throw new Error(z(t))}function R(e,n){let r=null,t=null;function i(){let a=e.read(),u=n.read();return r=new graphqlRequest.GraphQLClient(a.workspaceEndpoint),r.setHeaders(U(u)),t=new graphqlRequest.GraphQLClient(a.globalEndpoint),t.setHeaders(b(u)),{workspace:r,global:t}}async function s(){let a=n.read();if(!a)return;if(a.authMethod==="client_credentials"&&a.clientId&&a.clientSecret){let h=e.read();try{let k=await $(h.globalEndpoint,a.clientId,a.clientSecret);n.write({...a,accessToken:k.accessToken,expiresAt:Date.now()+k.expiresIn*1e3}),r=null,t=null;}catch{}return}if(!a.refreshToken)return;let u=e.read(),l=new graphqlRequest.GraphQLClient(u.globalEndpoint);l.setHeaders({Authorization:`Bearer ${a.accessToken}`});let E=`
21
+ mutation RefreshToken($token: String!) {
22
+ refreshToken(token: $token) {
23
+ accessToken
24
+ refreshToken
25
+ expiresIn
26
+ }
27
+ }
28
+ `;try{let k=(await l.request(E,{token:a.refreshToken})).refreshToken;n.write({...a,accessToken:k.accessToken,refreshToken:k.refreshToken,expiresAt:Date.now()+k.expiresIn*1e3}),r=null,t=null;}catch{}}async function o(){let a=n.read();if(!a?.accessToken||!a.workspaceId||!a.organizationId)return;let u=e.read();try{let l=await O(u.workspaceEndpoint,a.accessToken,a.workspaceId,a.organizationId);n.write({...a,workspaceToken:l.token,workspaceTokenExpiresAt:new Date(l.expiresAt).getTime()}),r=null;}catch{}}async function c(){n.isTokenExpiringSoon()&&await s(),n.read()?.workspaceToken&&n.isWorkspaceTokenExpiringSoon()&&await o();}return {workspace:{async request(a,u){await c();let{workspace:l}=r?{workspace:r}:i();return l.setHeaders(U(n.read())),D(l,a,u)}},global:{async request(a,u){let{global:l}=t?{global:t}:i();return l.setHeaders(b(n.read())),D(l,a,u)}},workspaceAuthOnly:{async request(a,u){let l=e.read(),E=n.read(),h=new graphqlRequest.GraphQLClient(l.workspaceEndpoint);return h.setHeaders(b(E)),D(h,a,u)}},reset(){r=null,t=null;}}}function q(){return !!(process.stdout.isTTY&&process.stdin.isTTY)}function H(e){if(e.format){let n=e.format.toLowerCase();if(n==="json"||n==="table"||n==="yaml")return n}return q()?"table":"json"}function L(e){console.log(JSON.stringify(e,null,2));}function B(e,n){if(e.length===0)return;let r=e.map((s,o)=>{let c=s.length;for(let p of n){let g=p[o]??"";g.length>c&&(c=g.length);}return Math.min(c,50)}),t=r.map(s=>"-".repeat(s+2)).join("+"),i=s=>s.map((o,c)=>` ${(o??"").padEnd(r[c]??0)} `).join("|");console.log(i(e)),console.log(t);for(let s of n)console.log(i(s));}function P(e,n){let r=" ".repeat(n),t=[];for(let[i,s]of Object.entries(e))if(s==null)t.push(`${r}${i}: null`);else if(Array.isArray(s)){t.push(`${r}${i}:`);for(let o of s)typeof o=="object"&&o!==null?(t.push(`${r} -`),t.push(P(o,n+2))):t.push(`${r} - ${String(o)}`);}else typeof s=="object"?(t.push(`${r}${i}:`),t.push(P(s,n+1))):t.push(`${r}${i}: ${String(s)}`);return t.join(`
29
+ `)}function V(e){if(typeof e!="object"||e===null){console.log(String(e));return}console.log(P(e,0));}function ke(e){console.log(`\u2713 ${e}`);}function J(e){console.error(`\u2717 ${e}`);}function we(e){console.warn(`! ${e}`);}function he(e){console.log(`\u2139 ${e}`);}function ye(e){if(!e)return "-";try{return new Date(e).toLocaleString()}catch{return e}}function Ce(e){if(!e)return "-";switch(e.toUpperCase()){case "ACTIVE":case "RUNNING":case "HEALTHY":return `\u2713 ${e}`;case "INACTIVE":case "STOPPED":case "PENDING":return `\u25CB ${e}`;case "ERROR":return `\u2717 ${e}`;case "ARCHIVED":return `\u2192 ${e}`;case "STARTING":return `\u25B6 ${e}`;case "TERMINATED":return `\u25A0 ${e}`;default:return e}}function xe(e,n){return e?e.length<=n?e:e.substring(0,n-3)+"...":"-"}function be(e,n,r){switch(H(e)){case "json":L(n);break;case "yaml":V(n);break;case "table":r?B(r.headers,r.rows):L(n);break}}async function Te(e,n){return n?true:q()?new Promise(r=>{process.stdout.write(`${e} [y/N] `),process.stdin.setEncoding("utf8"),process.stdin.once("data",t=>{let i=t.trim().toLowerCase();r(i==="y"||i==="yes");}),process.stdin.resume();}):(J(`${e} Use --force to skip confirmation.`),false)}var _={isInteractive:q,getFormat:H,formatAndOutput:be,printJson:L,printTable:B,printYaml:V,printSuccess:ke,printError:J,printWarning:we,printInfo:he,formatDate:ye,formatStatus:Ce,truncate:xe,confirm:Te};function j(e={}){let{verbose:n=false,quiet:r=false}=e;return {debug(t,...i){n&&console.error(`[debug] ${t}`,...i);},info(t,...i){r||console.error(`[info] ${t}`,...i);},warn(t,...i){console.error(`[warn] ${t}`,...i);},error(t,...i){console.error(`[error] ${t}`,...i);}}}function ve(e){return e.includes("localhost")||e.includes("127.0.0.1")?"local":e.includes("alpha")||e.includes("staging")?"staging":"prod"}function Ee(e){return !!e&&typeof e.debug=="function"&&typeof e.info=="function"}function Ie(e){let n=S(e.defaults),r=A(n.dir()),t=R(n,r),i=e.output??_,s=Ee(e.logger)?e.logger:j(e.logger),o=e.env??ve(n.read().workspaceEndpoint);return {productName:e.productName,productVersion:e.productVersion,defaults:e.defaults,config:n,auth:r,gql:t,output:i,logger:s,env:o}}var w=class extends Error{exitCode;hint;constructor(n,r){super(n),this.name="CliUserError",this.exitCode=r?.exitCode??1,this.hint=r?.hint;}},C=class extends w{constructor(n,r){super(n,{exitCode:2,hint:r?.hint??"Run `<product> auth login` to authenticate."}),this.name="CliAuthError";}},m=class extends Error{cause;constructor(n,r){super(n),this.name="CliInternalError",this.cause=r;}};var T=class extends m{constructor(n,r){super(`Module '${n}' declares dependency on '${r}', but '${r}' is not in the module list.`),this.name="MissingDependencyError";}},v=class extends m{constructor(n){super(`Circular dependency detected among modules: ${n.join(" -> ")}`),this.name="CircularDependencyError";}};function F(e){let n=new Map;for(let o of e){if(n.has(o.id))throw new m(`Duplicate module id: '${o.id}'`);n.set(o.id,o);}for(let o of e)for(let c of o.dependsOn??[])if(!n.has(c))throw new T(o.id,c);let r=[],t=new Set,i=new Set;function s(o,c){if(!i.has(o.id)){if(t.has(o.id))throw new v([...c,o.id]);t.add(o.id);for(let p of o.dependsOn??[]){let g=n.get(p);g&&s(g,[...c,o.id]);}t.delete(o.id),i.add(o.id),r.push(o);}}for(let o of e)s(o,[]);return r}function Se(e,n,r){let t=new commander.Command;t.name(r.name).description(r.description??"").version(r.version,"-v, --version").option("-f, --format <format>","Output format (json, table, yaml)").option("--verbose","Enable verbose logging").option("--no-color","Disable colored output");let i=F(n);for(let o of i)o.register(t,e);r.helpExamples?.length&&t.addHelpText("after",`
30
+ Examples:
31
+ `+r.helpExamples.map(o=>" "+o).join(`
32
+ `)),t.on("command:*",()=>{e.output.printError(`Invalid command: ${t.args.join(" ")}`),e.output.printInfo(`Run \`${r.name} --help\` for available commands.`),process.exit(1);});async function s(o=process.argv){try{await t.parseAsync(o),o.length<=2&&t.outputHelp();}catch(c){$e(e,c);}}return {program:t,run:s}}function $e(e,n){if(n instanceof C&&(e.output.printError(n.message),n.hint&&e.output.printInfo(n.hint),process.exit(n.exitCode)),n instanceof w&&(e.output.printError(n.message),n.hint&&e.output.printInfo(n.hint),process.exit(n.exitCode)),n instanceof m&&(e.output.printError(`Internal error: ${n.message}`),n.cause&&e.logger.debug("caused by:",n.cause),process.exit(70)),n&&typeof n=="object"&&"code"in n&&"exitCode"in n){let t=n.exitCode;process.exit(typeof t=="number"?t:0);}let r=n instanceof Error?n.message:String(n);e.output.printError(r),process.exit(1);}exports.CircularDependencyError=v;exports.CliAuthError=C;exports.CliInternalError=m;exports.CliUserError=w;exports.KNOWN_CONFIG_KEYS=ie;exports.MissingDependencyError=T;exports.buildContext=Ie;exports.clientCredentialsFlow=$;exports.createAuthStore=A;exports.createConfigStore=S;exports.createGqlClients=R;exports.createLogger=j;exports.createProgram=Se;exports.defaultOutputAdapter=_;exports.extractGqlErrorMessage=z;exports.fetchWorkspaces=ue;exports.issueWorkspaceToken=O;exports.openBrowser=pe;exports.pollForToken=ce;exports.sortModules=F;exports.startDeviceCodeFlow=ae;
@@ -0,0 +1,57 @@
1
+ import { a as CLIContext, C as CliModule } from '../module-Bv5zhYt2.cjs';
2
+ export { A as AuthStore, B as BuildContextOptions, b as CLIConfig, c as CircularDependencyError, d as CliAuthError, e as CliInternalError, f as CliUserError, g as ConfigStore, E as Environment, G as GqlClient, h as GqlClients, K as KNOWN_CONFIG_KEYS, L as Logger, i as LoggerOptions, M as MissingDependencyError, O as OutputAdapter, j as OutputFormat, P as ProductDefaults, S as StoredAuth, T as TableConfig, k as buildContext, l as createAuthStore, m as createConfigStore, n as createGqlClients, o as createLogger, p as defaultOutputAdapter, q as extractGqlErrorMessage, s as sortModules } from '../module-Bv5zhYt2.cjs';
3
+ import { Command } from 'commander';
4
+ import 'graphql-request';
5
+
6
+ interface CreateProgramOptions {
7
+ name: string;
8
+ description?: string;
9
+ version: string;
10
+ helpExamples?: string[];
11
+ }
12
+ interface ProgramFactoryResult {
13
+ program: Command;
14
+ run(argv?: readonly string[]): Promise<void>;
15
+ }
16
+ declare function createProgram(ctx: CLIContext, modules: readonly CliModule[], opts: CreateProgramOptions): ProgramFactoryResult;
17
+
18
+ interface DeviceCodeResponse {
19
+ deviceCode: string;
20
+ userCode: string;
21
+ verificationUri: string;
22
+ verificationUriComplete: string | null;
23
+ expiresIn: number;
24
+ interval: number;
25
+ }
26
+ interface DeviceCodeTokenResult {
27
+ accessToken: string;
28
+ refreshToken: string;
29
+ expiresIn: number;
30
+ }
31
+ interface OIDCConfig {
32
+ oidcIssuer: string;
33
+ clientId: string;
34
+ }
35
+ declare function startDeviceCodeFlow(config: OIDCConfig): Promise<DeviceCodeResponse>;
36
+ declare function pollForToken(deviceCode: string, interval: number, config: OIDCConfig): Promise<DeviceCodeTokenResult>;
37
+ interface ClientCredentialsResult {
38
+ accessToken: string;
39
+ expiresIn: number;
40
+ scopes: string[];
41
+ }
42
+ declare function clientCredentialsFlow(globalEndpoint: string, clientId: string, clientSecret: string, scopes?: string[]): Promise<ClientCredentialsResult>;
43
+ declare function issueWorkspaceToken(workspaceEndpoint: string, authToken: string, workspaceId: string, organizationId: string): Promise<{
44
+ token: string;
45
+ expiresAt: string;
46
+ scopes: string[];
47
+ }>;
48
+ declare function fetchWorkspaces(globalEndpoint: string, authToken: string): Promise<Array<{
49
+ id: string;
50
+ name: string;
51
+ slug: string;
52
+ tenantId: string;
53
+ organizationId: string;
54
+ }>>;
55
+ declare function openBrowser(url: string): Promise<boolean>;
56
+
57
+ export { CLIContext, CliModule, type ClientCredentialsResult, type CreateProgramOptions, type DeviceCodeResponse, type DeviceCodeTokenResult, type OIDCConfig, type ProgramFactoryResult, clientCredentialsFlow, createProgram, fetchWorkspaces, issueWorkspaceToken, openBrowser, pollForToken, startDeviceCodeFlow };
@@ -0,0 +1,57 @@
1
+ import { a as CLIContext, C as CliModule } from '../module-Bv5zhYt2.js';
2
+ export { A as AuthStore, B as BuildContextOptions, b as CLIConfig, c as CircularDependencyError, d as CliAuthError, e as CliInternalError, f as CliUserError, g as ConfigStore, E as Environment, G as GqlClient, h as GqlClients, K as KNOWN_CONFIG_KEYS, L as Logger, i as LoggerOptions, M as MissingDependencyError, O as OutputAdapter, j as OutputFormat, P as ProductDefaults, S as StoredAuth, T as TableConfig, k as buildContext, l as createAuthStore, m as createConfigStore, n as createGqlClients, o as createLogger, p as defaultOutputAdapter, q as extractGqlErrorMessage, s as sortModules } from '../module-Bv5zhYt2.js';
3
+ import { Command } from 'commander';
4
+ import 'graphql-request';
5
+
6
+ interface CreateProgramOptions {
7
+ name: string;
8
+ description?: string;
9
+ version: string;
10
+ helpExamples?: string[];
11
+ }
12
+ interface ProgramFactoryResult {
13
+ program: Command;
14
+ run(argv?: readonly string[]): Promise<void>;
15
+ }
16
+ declare function createProgram(ctx: CLIContext, modules: readonly CliModule[], opts: CreateProgramOptions): ProgramFactoryResult;
17
+
18
+ interface DeviceCodeResponse {
19
+ deviceCode: string;
20
+ userCode: string;
21
+ verificationUri: string;
22
+ verificationUriComplete: string | null;
23
+ expiresIn: number;
24
+ interval: number;
25
+ }
26
+ interface DeviceCodeTokenResult {
27
+ accessToken: string;
28
+ refreshToken: string;
29
+ expiresIn: number;
30
+ }
31
+ interface OIDCConfig {
32
+ oidcIssuer: string;
33
+ clientId: string;
34
+ }
35
+ declare function startDeviceCodeFlow(config: OIDCConfig): Promise<DeviceCodeResponse>;
36
+ declare function pollForToken(deviceCode: string, interval: number, config: OIDCConfig): Promise<DeviceCodeTokenResult>;
37
+ interface ClientCredentialsResult {
38
+ accessToken: string;
39
+ expiresIn: number;
40
+ scopes: string[];
41
+ }
42
+ declare function clientCredentialsFlow(globalEndpoint: string, clientId: string, clientSecret: string, scopes?: string[]): Promise<ClientCredentialsResult>;
43
+ declare function issueWorkspaceToken(workspaceEndpoint: string, authToken: string, workspaceId: string, organizationId: string): Promise<{
44
+ token: string;
45
+ expiresAt: string;
46
+ scopes: string[];
47
+ }>;
48
+ declare function fetchWorkspaces(globalEndpoint: string, authToken: string): Promise<Array<{
49
+ id: string;
50
+ name: string;
51
+ slug: string;
52
+ tenantId: string;
53
+ organizationId: string;
54
+ }>>;
55
+ declare function openBrowser(url: string): Promise<boolean>;
56
+
57
+ export { CLIContext, CliModule, type ClientCredentialsResult, type CreateProgramOptions, type DeviceCodeResponse, type DeviceCodeTokenResult, type OIDCConfig, type ProgramFactoryResult, clientCredentialsFlow, createProgram, fetchWorkspaces, issueWorkspaceToken, openBrowser, pollForToken, startDeviceCodeFlow };
@@ -0,0 +1 @@
1
+ export{s as CircularDependencyError,p as CliAuthError,q as CliInternalError,o as CliUserError,b as KNOWN_CONFIG_KEYS,r as MissingDependencyError,n as buildContext,f as clientCredentialsFlow,a as createAuthStore,c as createConfigStore,k as createGqlClients,m as createLogger,u as createProgram,l as defaultOutputAdapter,j as extractGqlErrorMessage,h as fetchWorkspaces,g as issueWorkspaceToken,i as openBrowser,e as pollForToken,t as sortModules,d as startDeviceCodeFlow}from'../chunk-RNWXATAC.js';
package/dist/index.cjs ADDED
@@ -0,0 +1,32 @@
1
+ 'use strict';var fs=require('fs'),path=require('path'),os=require('os'),graphqlRequest=require('graphql-request'),y=require('cross-fetch'),commander=require('commander');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var y__default=/*#__PURE__*/_interopDefault(y);var N=300*1e3;function A(e){let n=path.join(e,"auth.json");function r(){fs.existsSync(e)||fs.mkdirSync(e,{recursive:true,mode:448});}function t(){try{if(!fs.existsSync(n))return null;let a=fs.readFileSync(n,"utf8");return JSON.parse(a)}catch{return null}}function i(a){r(),fs.writeFileSync(n,JSON.stringify(a,null,2),{encoding:"utf8",mode:384});try{fs.chmodSync(n,384);}catch{}}function s(){try{fs.existsSync(n)&&fs.unlinkSync(n);}catch{}}function o(){let a=t();return a?.expiresAt?Date.now()>=a.expiresAt:false}function c(){let a=t();return a?.expiresAt?Date.now()+N>=a.expiresAt:false}function p(){let a=t();return a?.workspaceTokenExpiresAt?Date.now()>=a.workspaceTokenExpiresAt:false}function f(){let a=t();return a?.workspaceTokenExpiresAt?Date.now()+N>=a.workspaceTokenExpiresAt:false}function d(){return t()?.accessToken?!o():false}return {read:t,write:i,clear:s,isTokenExpired:o,isTokenExpiringSoon:c,isWorkspaceTokenExpired:p,isWorkspaceTokenExpiringSoon:f,isAuthenticated:d}}var ie=["workspaceEndpoint","globalEndpoint","oidcIssuer","clientId","defaultFormat","verbose","authServiceEndpoint"];function S(e){let n=path.join(os.homedir(),".config",e.configDirName),r=path.join(n,"config.json"),t={workspaceEndpoint:e.workspaceEndpointDefault,globalEndpoint:e.globalEndpointDefault};function i(){fs.existsSync(n)||fs.mkdirSync(n,{recursive:true,mode:448});}function s(){try{if(!fs.existsSync(r))return {...t};let d=fs.readFileSync(r,"utf8"),a=JSON.parse(d);return {...t,...a}}catch{return {...t}}}function o(d){i(),fs.writeFileSync(r,JSON.stringify(d,null,2),{encoding:"utf8"});try{fs.chmodSync(r,384);}catch{}}function c(d){return s()[d]}function p(d,a){let u=s();u[d]=a,o(u);}function f(){let d=s(),a=d.clientId||e.oidcClientId,u=d.oidcIssuer;if(!u){let l=d.globalEndpoint;l.includes("localhost")||l.includes("127.0.0.1")?u=l.replace(/\/graphql$/,"").replace(/\/global\/graphql$/,"/global"):u=e.oidcIssuerProd??"https://graphql.burdenoff.com/global";}return {oidcIssuer:u,clientId:a}}return {read:s,write:o,get:c,set:p,path:()=>r,dir:()=>n,resolveOIDC:f}}async function ae(e){let n=`${e.oidcIssuer}/oidc/device/code`,r=new URLSearchParams({client_id:e.clientId,scope:"openid profile email offline_access"}),t=await y__default.default(n,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:r.toString()});if(!t.ok){let s=await t.text().catch(()=>"Unknown error");throw new Error(`Device code request failed (${t.status}): ${s}`)}let i=await t.json();return {deviceCode:i.device_code,userCode:i.user_code,verificationUri:i.verification_uri,verificationUriComplete:i.verification_uri_complete??null,expiresIn:i.expires_in,interval:i.interval??5}}async function ce(e,n,r){let t=`${r.oidcIssuer}/oauth/device/token`,i=n;for(;;){await new Promise(p=>setTimeout(p,i*1e3));let s=await y__default.default(t,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({grant_type:"urn:ietf:params:oauth:grant-type:device_code",device_code:e,client_id:r.clientId}).toString()}),o=await s.json();if(s.ok&&o.access_token)return {accessToken:o.access_token,refreshToken:o.refresh_token??"",expiresIn:o.expires_in??3600};let c=o.error;switch(c){case "authorization_pending":continue;case "slow_down":i+=5;continue;case "expired_token":throw new Error("Device code has expired. Please try again.");case "access_denied":throw new Error("Authorization was denied by the user.");default:throw new Error(`Device code polling failed: ${o.error_description??c??"Unknown error"}`)}}}async function $(e,n,r,t){let s=await y__default.default(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:`
2
+ mutation AuthenticateApp($input: AuthenticateAppInput!) {
3
+ authenticateApp(input: $input) {
4
+ accessToken tokenType expiresIn scopes
5
+ }
6
+ }
7
+ `,variables:{input:{clientId:n,clientSecret:r,scopes:t}}})});if(!s.ok){let c=await s.text().catch(()=>"Unknown error");throw new Error(`App authentication failed (${s.status}): ${c}`)}let o=await s.json();if(o.errors?.length)throw new Error(`App authentication failed: ${o.errors[0]?.message??"unknown error"}`);if(!o.data?.authenticateApp?.accessToken)throw new Error("App authentication failed: no access token returned");return o.data.authenticateApp}async function O(e,n,r,t){let s=await y__default.default(e,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({query:`
8
+ mutation IssueWorkspaceToken($input: IssueWorkspaceTokenInput!) {
9
+ issueWorkspaceToken(input: $input) {
10
+ success token expiresAt scopes
11
+ error { code message }
12
+ }
13
+ }
14
+ `,variables:{input:{workspaceId:r,organizationId:t}}})});if(!s.ok){let p=await s.text().catch(()=>"Unknown error");throw new Error(`Workspace token request failed (${s.status}): ${p}`)}let o=await s.json();if(o.errors?.length)throw new Error(`Workspace token failed: ${o.errors[0]?.message??"unknown error"}`);let c=o.data?.issueWorkspaceToken;if(!c?.success||!c.token){let p=c?.error?.message??"Unknown error";throw new Error(`Workspace token failed: ${p}`)}return {token:c.token,expiresAt:c.expiresAt??"",scopes:c.scopes??[]}}async function ue(e,n){let t=await y__default.default(e,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({query:`
15
+ query MyWorkspaces($limit: Int) {
16
+ myWorkspaces(limit: $limit) {
17
+ items { id name slug tenantId organizationId }
18
+ }
19
+ }
20
+ `,variables:{limit:50}})});if(!t.ok){let s=await t.text().catch(()=>"Unknown error");throw new Error(`Failed to fetch workspaces (${t.status}): ${s}`)}let i=await t.json();if(i.errors?.length)throw new Error(`Failed to fetch workspaces: ${i.errors[0]?.message??"unknown error"}`);return i.data?.myWorkspaces?.items??[]}function le(e){try{let n=new URL(e);return n.protocol==="http:"||n.protocol==="https:"}catch{return false}}async function pe(e){try{if(!le(e))return !1;let{execFile:n}=await import('child_process'),r=process.platform,t,i;return r==="darwin"?(t="open",i=[e]):r==="win32"?(t="cmd",i=["/c","start","",e]):(t="xdg-open",i=[e]),new Promise(s=>{n(t,i,o=>{s(!o);});})}catch{return false}}var de=3e4,G=3,ge=1e3;function fe(e){return new Promise(n=>setTimeout(n,e))}function me(e){if(e instanceof TypeError)return true;if(e&&typeof e=="object"&&"response"in e){let n=e.response;if(n&&typeof n.status=="number"&&n.status>=500)return true}return false}function z(e){if(e&&typeof e=="object"&&"response"in e){let n=e,r=n.response?.errors?.[0],t=r?.extensions?.originalError?.message;if(t)return t;if(r?.message)return r.message;if(n.message)return n.message}return e instanceof Error?e.message:String(e)}function b(e){let n={};return e?.accessToken&&(n.Authorization=`Bearer ${e.accessToken}`),e?.organizationId&&(n["x-org-id"]=e.organizationId),n}function U(e){let n=b(e);return e?.workspaceToken&&(n["X-Workspace-Authorization"]=`Bearer ${e.workspaceToken}`),e?.organizationId&&(n["x-org-id"]=e.organizationId),n}async function D(e,n,r){let t;for(let i=0;i<G;i++)try{let s=new AbortController,o=setTimeout(()=>s.abort(),de);try{return await e.request({document:n,variables:r,signal:s.signal})}finally{clearTimeout(o);}}catch(s){if(t=s,s&&typeof s=="object"&&"response"in s){let o=s.response;if(o&&typeof o.status=="number"&&o.status>=400&&o.status<500)break}if(me(s)&&i<G-1){let o=ge*Math.pow(2,i);await fe(o);continue}break}throw new Error(z(t))}function R(e,n){let r=null,t=null;function i(){let a=e.read(),u=n.read();return r=new graphqlRequest.GraphQLClient(a.workspaceEndpoint),r.setHeaders(U(u)),t=new graphqlRequest.GraphQLClient(a.globalEndpoint),t.setHeaders(b(u)),{workspace:r,global:t}}async function s(){let a=n.read();if(!a)return;if(a.authMethod==="client_credentials"&&a.clientId&&a.clientSecret){let h=e.read();try{let k=await $(h.globalEndpoint,a.clientId,a.clientSecret);n.write({...a,accessToken:k.accessToken,expiresAt:Date.now()+k.expiresIn*1e3}),r=null,t=null;}catch{}return}if(!a.refreshToken)return;let u=e.read(),l=new graphqlRequest.GraphQLClient(u.globalEndpoint);l.setHeaders({Authorization:`Bearer ${a.accessToken}`});let E=`
21
+ mutation RefreshToken($token: String!) {
22
+ refreshToken(token: $token) {
23
+ accessToken
24
+ refreshToken
25
+ expiresIn
26
+ }
27
+ }
28
+ `;try{let k=(await l.request(E,{token:a.refreshToken})).refreshToken;n.write({...a,accessToken:k.accessToken,refreshToken:k.refreshToken,expiresAt:Date.now()+k.expiresIn*1e3}),r=null,t=null;}catch{}}async function o(){let a=n.read();if(!a?.accessToken||!a.workspaceId||!a.organizationId)return;let u=e.read();try{let l=await O(u.workspaceEndpoint,a.accessToken,a.workspaceId,a.organizationId);n.write({...a,workspaceToken:l.token,workspaceTokenExpiresAt:new Date(l.expiresAt).getTime()}),r=null;}catch{}}async function c(){n.isTokenExpiringSoon()&&await s(),n.read()?.workspaceToken&&n.isWorkspaceTokenExpiringSoon()&&await o();}return {workspace:{async request(a,u){await c();let{workspace:l}=r?{workspace:r}:i();return l.setHeaders(U(n.read())),D(l,a,u)}},global:{async request(a,u){let{global:l}=t?{global:t}:i();return l.setHeaders(b(n.read())),D(l,a,u)}},workspaceAuthOnly:{async request(a,u){let l=e.read(),E=n.read(),h=new graphqlRequest.GraphQLClient(l.workspaceEndpoint);return h.setHeaders(b(E)),D(h,a,u)}},reset(){r=null,t=null;}}}function q(){return !!(process.stdout.isTTY&&process.stdin.isTTY)}function H(e){if(e.format){let n=e.format.toLowerCase();if(n==="json"||n==="table"||n==="yaml")return n}return q()?"table":"json"}function L(e){console.log(JSON.stringify(e,null,2));}function B(e,n){if(e.length===0)return;let r=e.map((s,o)=>{let c=s.length;for(let p of n){let f=p[o]??"";f.length>c&&(c=f.length);}return Math.min(c,50)}),t=r.map(s=>"-".repeat(s+2)).join("+"),i=s=>s.map((o,c)=>` ${(o??"").padEnd(r[c]??0)} `).join("|");console.log(i(e)),console.log(t);for(let s of n)console.log(i(s));}function P(e,n){let r=" ".repeat(n),t=[];for(let[i,s]of Object.entries(e))if(s==null)t.push(`${r}${i}: null`);else if(Array.isArray(s)){t.push(`${r}${i}:`);for(let o of s)typeof o=="object"&&o!==null?(t.push(`${r} -`),t.push(P(o,n+2))):t.push(`${r} - ${String(o)}`);}else typeof s=="object"?(t.push(`${r}${i}:`),t.push(P(s,n+1))):t.push(`${r}${i}: ${String(s)}`);return t.join(`
29
+ `)}function V(e){if(typeof e!="object"||e===null){console.log(String(e));return}console.log(P(e,0));}function ke(e){console.log(`\u2713 ${e}`);}function J(e){console.error(`\u2717 ${e}`);}function we(e){console.warn(`! ${e}`);}function he(e){console.log(`\u2139 ${e}`);}function ye(e){if(!e)return "-";try{return new Date(e).toLocaleString()}catch{return e}}function Ce(e){if(!e)return "-";switch(e.toUpperCase()){case "ACTIVE":case "RUNNING":case "HEALTHY":return `\u2713 ${e}`;case "INACTIVE":case "STOPPED":case "PENDING":return `\u25CB ${e}`;case "ERROR":return `\u2717 ${e}`;case "ARCHIVED":return `\u2192 ${e}`;case "STARTING":return `\u25B6 ${e}`;case "TERMINATED":return `\u25A0 ${e}`;default:return e}}function xe(e,n){return e?e.length<=n?e:e.substring(0,n-3)+"...":"-"}function be(e,n,r){switch(H(e)){case "json":L(n);break;case "yaml":V(n);break;case "table":r?B(r.headers,r.rows):L(n);break}}async function Te(e,n){return n?true:q()?new Promise(r=>{process.stdout.write(`${e} [y/N] `),process.stdin.setEncoding("utf8"),process.stdin.once("data",t=>{let i=t.trim().toLowerCase();r(i==="y"||i==="yes");}),process.stdin.resume();}):(J(`${e} Use --force to skip confirmation.`),false)}var _={isInteractive:q,getFormat:H,formatAndOutput:be,printJson:L,printTable:B,printYaml:V,printSuccess:ke,printError:J,printWarning:we,printInfo:he,formatDate:ye,formatStatus:Ce,truncate:xe,confirm:Te};function j(e={}){let{verbose:n=false,quiet:r=false}=e;return {debug(t,...i){n&&console.error(`[debug] ${t}`,...i);},info(t,...i){r||console.error(`[info] ${t}`,...i);},warn(t,...i){console.error(`[warn] ${t}`,...i);},error(t,...i){console.error(`[error] ${t}`,...i);}}}function ve(e){return e.includes("localhost")||e.includes("127.0.0.1")?"local":e.includes("alpha")||e.includes("staging")?"staging":"prod"}function Ee(e){return !!e&&typeof e.debug=="function"&&typeof e.info=="function"}function Ie(e){let n=S(e.defaults),r=A(n.dir()),t=R(n,r),i=e.output??_,s=Ee(e.logger)?e.logger:j(e.logger),o=e.env??ve(n.read().workspaceEndpoint);return {productName:e.productName,productVersion:e.productVersion,defaults:e.defaults,config:n,auth:r,gql:t,output:i,logger:s,env:o}}var w=class extends Error{exitCode;hint;constructor(n,r){super(n),this.name="CliUserError",this.exitCode=r?.exitCode??1,this.hint=r?.hint;}},C=class extends w{constructor(n,r){super(n,{exitCode:2,hint:r?.hint??"Run `<product> auth login` to authenticate."}),this.name="CliAuthError";}},m=class extends Error{cause;constructor(n,r){super(n),this.name="CliInternalError",this.cause=r;}};var T=class extends m{constructor(n,r){super(`Module '${n}' declares dependency on '${r}', but '${r}' is not in the module list.`),this.name="MissingDependencyError";}},v=class extends m{constructor(n){super(`Circular dependency detected among modules: ${n.join(" -> ")}`),this.name="CircularDependencyError";}};function F(e){let n=new Map;for(let o of e){if(n.has(o.id))throw new m(`Duplicate module id: '${o.id}'`);n.set(o.id,o);}for(let o of e)for(let c of o.dependsOn??[])if(!n.has(c))throw new T(o.id,c);let r=[],t=new Set,i=new Set;function s(o,c){if(!i.has(o.id)){if(t.has(o.id))throw new v([...c,o.id]);t.add(o.id);for(let p of o.dependsOn??[]){let f=n.get(p);f&&s(f,[...c,o.id]);}t.delete(o.id),i.add(o.id),r.push(o);}}for(let o of e)s(o,[]);return r}function Se(e,n,r){let t=new commander.Command;t.name(r.name).description(r.description??"").version(r.version,"-v, --version").option("-f, --format <format>","Output format (json, table, yaml)").option("--verbose","Enable verbose logging").option("--no-color","Disable colored output");let i=F(n);for(let o of i)o.register(t,e);r.helpExamples?.length&&t.addHelpText("after",`
30
+ Examples:
31
+ `+r.helpExamples.map(o=>" "+o).join(`
32
+ `)),t.on("command:*",()=>{e.output.printError(`Invalid command: ${t.args.join(" ")}`),e.output.printInfo(`Run \`${r.name} --help\` for available commands.`),process.exit(1);});async function s(o=process.argv){try{await t.parseAsync(o),o.length<=2&&t.outputHelp();}catch(c){$e(e,c);}}return {program:t,run:s}}function $e(e,n){if(n instanceof C&&(e.output.printError(n.message),n.hint&&e.output.printInfo(n.hint),process.exit(n.exitCode)),n instanceof w&&(e.output.printError(n.message),n.hint&&e.output.printInfo(n.hint),process.exit(n.exitCode)),n instanceof m&&(e.output.printError(`Internal error: ${n.message}`),n.cause&&e.logger.debug("caused by:",n.cause),process.exit(70)),n&&typeof n=="object"&&"code"in n&&"exitCode"in n){let t=n.exitCode;process.exit(typeof t=="number"?t:0);}let r=n instanceof Error?n.message:String(n);e.output.printError(r),process.exit(1);}exports.CircularDependencyError=v;exports.CliAuthError=C;exports.CliInternalError=m;exports.CliUserError=w;exports.KNOWN_CONFIG_KEYS=ie;exports.MissingDependencyError=T;exports.buildContext=Ie;exports.clientCredentialsFlow=$;exports.createAuthStore=A;exports.createConfigStore=S;exports.createGqlClients=R;exports.createLogger=j;exports.createProgram=Se;exports.defaultOutputAdapter=_;exports.extractGqlErrorMessage=z;exports.fetchWorkspaces=ue;exports.issueWorkspaceToken=O;exports.openBrowser=pe;exports.pollForToken=ce;exports.sortModules=F;exports.startDeviceCodeFlow=ae;
@@ -0,0 +1,4 @@
1
+ export { A as AuthStore, B as BuildContextOptions, b as CLIConfig, a as CLIContext, c as CircularDependencyError, d as CliAuthError, e as CliInternalError, C as CliModule, f as CliUserError, g as ConfigStore, E as Environment, G as GqlClient, h as GqlClients, K as KNOWN_CONFIG_KEYS, L as Logger, i as LoggerOptions, M as MissingDependencyError, O as OutputAdapter, j as OutputFormat, P as ProductDefaults, S as StoredAuth, T as TableConfig, k as buildContext, l as createAuthStore, m as createConfigStore, n as createGqlClients, o as createLogger, p as defaultOutputAdapter, q as extractGqlErrorMessage, s as sortModules } from './module-Bv5zhYt2.cjs';
2
+ export { ClientCredentialsResult, CreateProgramOptions, DeviceCodeResponse, DeviceCodeTokenResult, OIDCConfig, ProgramFactoryResult, clientCredentialsFlow, createProgram, fetchWorkspaces, issueWorkspaceToken, openBrowser, pollForToken, startDeviceCodeFlow } from './core/index.cjs';
3
+ import 'commander';
4
+ import 'graphql-request';
@@ -0,0 +1,4 @@
1
+ export { A as AuthStore, B as BuildContextOptions, b as CLIConfig, a as CLIContext, c as CircularDependencyError, d as CliAuthError, e as CliInternalError, C as CliModule, f as CliUserError, g as ConfigStore, E as Environment, G as GqlClient, h as GqlClients, K as KNOWN_CONFIG_KEYS, L as Logger, i as LoggerOptions, M as MissingDependencyError, O as OutputAdapter, j as OutputFormat, P as ProductDefaults, S as StoredAuth, T as TableConfig, k as buildContext, l as createAuthStore, m as createConfigStore, n as createGqlClients, o as createLogger, p as defaultOutputAdapter, q as extractGqlErrorMessage, s as sortModules } from './module-Bv5zhYt2.js';
2
+ export { ClientCredentialsResult, CreateProgramOptions, DeviceCodeResponse, DeviceCodeTokenResult, OIDCConfig, ProgramFactoryResult, clientCredentialsFlow, createProgram, fetchWorkspaces, issueWorkspaceToken, openBrowser, pollForToken, startDeviceCodeFlow } from './core/index.js';
3
+ import 'commander';
4
+ import 'graphql-request';
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export{s as CircularDependencyError,p as CliAuthError,q as CliInternalError,o as CliUserError,b as KNOWN_CONFIG_KEYS,r as MissingDependencyError,n as buildContext,f as clientCredentialsFlow,a as createAuthStore,c as createConfigStore,k as createGqlClients,m as createLogger,u as createProgram,l as defaultOutputAdapter,j as extractGqlErrorMessage,h as fetchWorkspaces,g as issueWorkspaceToken,i as openBrowser,e as pollForToken,t as sortModules,d as startDeviceCodeFlow}from'./chunk-RNWXATAC.js';
@@ -0,0 +1,166 @@
1
+ import { Command } from 'commander';
2
+ import { RequestDocument, Variables } from 'graphql-request';
3
+
4
+ interface StoredAuth {
5
+ accessToken: string;
6
+ refreshToken: string;
7
+ expiresAt?: number;
8
+ workspaceToken?: string;
9
+ workspaceTokenExpiresAt?: number;
10
+ workspaceId?: string;
11
+ organizationId?: string;
12
+ authMethod?: 'device_code' | 'client_credentials';
13
+ clientId?: string;
14
+ clientSecret?: string;
15
+ }
16
+ interface AuthStore {
17
+ read(): StoredAuth | null;
18
+ write(auth: StoredAuth): void;
19
+ clear(): void;
20
+ isTokenExpired(): boolean;
21
+ isTokenExpiringSoon(): boolean;
22
+ isWorkspaceTokenExpired(): boolean;
23
+ isWorkspaceTokenExpiringSoon(): boolean;
24
+ isAuthenticated(): boolean;
25
+ }
26
+ declare function createAuthStore(configDir: string): AuthStore;
27
+
28
+ interface CLIConfig {
29
+ workspaceEndpoint: string;
30
+ globalEndpoint: string;
31
+ oidcIssuer?: string;
32
+ clientId?: string;
33
+ defaultFormat?: string;
34
+ verbose?: boolean;
35
+ authServiceEndpoint?: string;
36
+ }
37
+ interface ProductDefaults {
38
+ configDirName: string;
39
+ oidcClientId: string;
40
+ oidcIssuerProd?: string;
41
+ workspaceEndpointDefault: string;
42
+ globalEndpointDefault: string;
43
+ }
44
+ interface ConfigStore {
45
+ read(): CLIConfig;
46
+ write(config: CLIConfig): void;
47
+ get(key: string): string | undefined;
48
+ set(key: string, value: string): void;
49
+ path(): string;
50
+ dir(): string;
51
+ resolveOIDC(): {
52
+ oidcIssuer: string;
53
+ clientId: string;
54
+ };
55
+ }
56
+ declare const KNOWN_CONFIG_KEYS: readonly ["workspaceEndpoint", "globalEndpoint", "oidcIssuer", "clientId", "defaultFormat", "verbose", "authServiceEndpoint"];
57
+ declare function createConfigStore(defaults: ProductDefaults): ConfigStore;
58
+
59
+ interface GqlClient {
60
+ request<T>(document: RequestDocument, variables?: Variables): Promise<T>;
61
+ }
62
+ interface GqlClients {
63
+ workspace: GqlClient;
64
+ global: GqlClient;
65
+ workspaceAuthOnly: GqlClient;
66
+ reset(): void;
67
+ }
68
+ declare function extractGqlErrorMessage(error: unknown): string;
69
+ declare function createGqlClients(config: ConfigStore, authStore: AuthStore): GqlClients;
70
+
71
+ type OutputFormat = 'json' | 'table' | 'yaml';
72
+ interface TableConfig {
73
+ headers: string[];
74
+ rows: string[][];
75
+ }
76
+ interface OutputAdapter {
77
+ isInteractive(): boolean;
78
+ getFormat(options: {
79
+ format?: string;
80
+ }): OutputFormat;
81
+ formatAndOutput(options: {
82
+ format?: string;
83
+ }, data: unknown, table?: TableConfig): void;
84
+ printJson(data: unknown): void;
85
+ printTable(headers: string[], rows: string[][]): void;
86
+ printYaml(data: unknown): void;
87
+ printSuccess(message: string): void;
88
+ printError(message: string): void;
89
+ printWarning(message: string): void;
90
+ printInfo(message: string): void;
91
+ formatDate(date: string | null | undefined): string;
92
+ formatStatus(status: string | null | undefined): string;
93
+ truncate(str: string | null | undefined, maxLen: number): string;
94
+ confirm(message: string, force?: boolean): Promise<boolean>;
95
+ }
96
+ declare const defaultOutputAdapter: OutputAdapter;
97
+
98
+ interface Logger {
99
+ debug(message: string, ...args: unknown[]): void;
100
+ info(message: string, ...args: unknown[]): void;
101
+ warn(message: string, ...args: unknown[]): void;
102
+ error(message: string, ...args: unknown[]): void;
103
+ }
104
+ interface LoggerOptions {
105
+ verbose?: boolean;
106
+ quiet?: boolean;
107
+ }
108
+ declare function createLogger(opts?: LoggerOptions): Logger;
109
+
110
+ type Environment = 'prod' | 'staging' | 'dev' | 'local';
111
+ interface CLIContext {
112
+ productName: string;
113
+ productVersion: string;
114
+ defaults: ProductDefaults;
115
+ config: ConfigStore;
116
+ auth: AuthStore;
117
+ gql: GqlClients;
118
+ output: OutputAdapter;
119
+ logger: Logger;
120
+ env: Environment;
121
+ }
122
+ interface BuildContextOptions {
123
+ productName: string;
124
+ productVersion: string;
125
+ defaults: ProductDefaults;
126
+ output?: OutputAdapter;
127
+ logger?: LoggerOptions | Logger;
128
+ env?: Environment;
129
+ }
130
+ declare function buildContext(opts: BuildContextOptions): CLIContext;
131
+
132
+ declare class CliUserError extends Error {
133
+ readonly exitCode: number;
134
+ readonly hint: string | undefined;
135
+ constructor(message: string, opts?: {
136
+ exitCode?: number;
137
+ hint?: string;
138
+ });
139
+ }
140
+ declare class CliAuthError extends CliUserError {
141
+ constructor(message: string, opts?: {
142
+ hint?: string;
143
+ });
144
+ }
145
+ declare class CliInternalError extends Error {
146
+ readonly cause: unknown;
147
+ constructor(message: string, cause?: unknown);
148
+ }
149
+
150
+ interface CliModule {
151
+ readonly id: string;
152
+ readonly version: string;
153
+ readonly displayName: string;
154
+ readonly dependsOn?: readonly string[];
155
+ register(program: Command, ctx: CLIContext): void;
156
+ api?: (ctx: CLIContext) => unknown;
157
+ }
158
+ declare class MissingDependencyError extends CliInternalError {
159
+ constructor(moduleId: string, missingDep: string);
160
+ }
161
+ declare class CircularDependencyError extends CliInternalError {
162
+ constructor(cycle: readonly string[]);
163
+ }
164
+ declare function sortModules(modules: readonly CliModule[]): CliModule[];
165
+
166
+ export { type AuthStore as A, type BuildContextOptions as B, type CliModule as C, type Environment as E, type GqlClient as G, KNOWN_CONFIG_KEYS as K, type Logger as L, MissingDependencyError as M, type OutputAdapter as O, type ProductDefaults as P, type StoredAuth as S, type TableConfig as T, type CLIContext as a, type CLIConfig as b, CircularDependencyError as c, CliAuthError as d, CliInternalError as e, CliUserError as f, type ConfigStore as g, type GqlClients as h, type LoggerOptions as i, type OutputFormat as j, buildContext as k, createAuthStore as l, createConfigStore as m, createGqlClients as n, createLogger as o, defaultOutputAdapter as p, extractGqlErrorMessage as q, sortModules as s };