@stackone/cli 1.13.1 → 1.13.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.cjs CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- const e=require(`./cliCore-D1Qdo7ts.cjs`);new e.t().run();
2
+ const e=require(`./cliCore-E8z0v8KP.cjs`);new e.t().run();
package/dist/cli.mjs CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import{t as e}from"./cliCore-C7KMeP98.mjs";new e().run();export{};
2
+ import{t as e}from"./cliCore-D2QQhlz-.mjs";new e().run();export{};
@@ -51,7 +51,7 @@ To create a profile, run "stackone init".`),process.exit(1)),c&&p&&(b.error(`Ple
51
51
  To create a profile, run "stackone init".`),process.exit(1)),h=await this.#o(e,m?.apiUrl??Dp,m?.apiKey)):h=this.#e(e):N(a)&&(h=await this.#s(a,m?.apiUrl??Dp,m?.apiKey));let g=N(n)?this.#r(n,e):h;P(g)&&(b.error(`A valid connector is required to run an action.`),process.exit(1));let ee=N(g?.actions)?Object.keys(g?.actions).length:0,te=N(g?.actions)?Object.keys(g.actions)[ee-1]:void 0,ne=N(te)?g?.actions?.[te]?.id:void 0,re=(N(r)&&!r?.startsWith(`${g.key}_`)?`${g.key}_${r}`:r)??ne;P(re)&&(b.error(`A valid action ID is required to run an action.`),process.exit(1));let ie=N(a)?await this.#c(a,m?.apiUrl??Dp,m?.apiKey):{},ae=N(i)?this.#i(i,g.key??`unknown`,g.version??`unknown`):void 0,_=N(s)?this.#l(s):{},oe={...ie,...ae,credentials:{...ie.credentials??{},..._}};P(oe)&&(b.error(`A valid account data is required to run an action.`),process.exit(1));let se=N(o)?this.#u(o):{path:{},queryParams:{},header:{},body:{}},ce=g.actions?.[re];P(ce)&&(b.error(`Action with ID '${re}' not found in the connector ${g.key}@${g.version}.`),process.exit(1));let v=await this.#d({connector:g,actionId:re,account:oe,queryParams:{...se.queryParams,...u?{debug:`true`}:{}},pathParams:se.path,body:se.body,headers:se.header});if(N(l))try{f.writeFileSync(l,JSON.stringify(v.output,null,2),`utf-8`),b.info(`Output written to file: ${l}`)}catch(e){b.error(`Failed to write output to file ${l}: ${e.message}`),process.exit(1)}else kp(v.output);console.info(t.green(`\nAction '${re}' from connector '${g?.key}@${g?.version}' executed successfully!`)),process.exit(0)}#e=e=>{let t=e;try{t=pe(e)}catch{}return t?this.#n(t):void 0};#t=e=>{try{return pe(e)}catch(t){b.error(`Failed to load connector file from ${e}: ${t.message}`),process.exit(1)}};#n=e=>{let n=he(e),r=n?.errors??[];if(n.success)return n.connector||(b.error(`Failed to load connector.`),process.exit(1)),n.connector;r.length>0?(b.error(`Connector is not valid. Please fix the following errors:
52
52
  `),r.forEach(e=>{console.info(t.red(`- L${e.line}: ${e.message}`))}),process.exit(1)):(b.error(`Connector is not valid. Please check the file for errors.`),process.exit(1))};#r=(e,t)=>{let n=e;try{n=f.readFileSync(e,`utf-8`)}catch{}P(t)&&(b.error(`A valid connector is required to load an action.`),process.exit(1));let r=`${this.#t(t)} - ${n.split(`
53
53
  `).map((e,t)=>t===0?e:` ${e}`).join(`
54
- `)}`;return this.#n(r)};#i=(e,t,n)=>{let r=e;try{r=f.readFileSync(e,`utf-8`)}catch{}try{let e=wp.parse(JSON.parse(r));return{providerKey:t,providerVersion:n,authConfigKey:e.auth_config_key,environment:e.environment,organizationId:e.organization_id,secureId:e.account_id,projectSecureId:e.project_id}}catch(e){b.error(`Failed to parse account information: ${e.message}`),process.exit(1)}};#a=e=>e.includes(`@`)&&e.split(`@`).length===2&&!e.includes(`/`)&&!e.includes(`\\`)&&!e.endsWith(`.yaml`)&&!e.endsWith(`.yml`);#o=async(e,n,r)=>{(P(e)||P(n)||P(r))&&(b.error(`Connector identifier, API URL, and API key are required to fetch connector from registry.`),process.exit(1));try{console.info(t.blue(`Fetching connector ${e} from registry...`));let i=Buffer.from(r).toString(`base64`),a=await fetch(`${n}/registry/connectors/${e}`,{method:`GET`,headers:{Authorization:`Basic ${i}`}});if(!a.ok){let e=await a.text();b.error(`Failed to fetch connector from registry: ${a.status} - ${a.statusText}`),e&&b.error(e),process.exit(1)}let o=await a.text(),s=this.#n(o);return b.success(`Fetched connector ${s.key}@${s.version} from registry\n`),s}catch(e){b.error(`Failed to fetch connector from registry: ${e.message}`),process.exit(1)}};#s=async(e,n,r)=>{(P(e)||P(n)||P(r))&&(b.error(`Account ID, API URL, and API key are required to fetch connector information.`),process.exit(1));try{console.info(t.blue(`Fetching connector for account ${e} from API...`));let i=Buffer.from(r).toString(`base64`),a=await fetch(`${n}/accounts/${e}/connector`,{method:`GET`,headers:{Authorization:`Basic ${i}`}});if(!a.ok){let e=await a.text();b.error(`Failed to fetch connector information: ${a.status} - ${a.statusText}`),e&&b.error(e),process.exit(1)}let o=await a.text(),s=this.#n(o);return b.success(`Fetched connector ${s.key}@${s.version} for account "${e}"\n`),s}catch(e){b.error(`Failed to fetch connector information: ${e.message}`),process.exit(1)}};#c=async(e,n,r)=>{(P(e)||P(n)||P(r))&&(b.error(`Account ID, API URL, and API key are required to fetch account information.`),process.exit(1));try{console.info(t.blue(`Fetching account ${e} information from API...`));let i=Buffer.from(r).toString(`base64`),a=await fetch(`${n}/accounts/${e}/credentials`,{method:`GET`,headers:{Authorization:`Basic ${i}`}});if(!a.ok){let e=await a.text();b.error(`Failed to fetch account information: ${a.status} - ${a.statusText}`),e&&b.error(e),process.exit(1)}let o=await a.json();return b.success(`Fetched information account id "${e}" from project "${o.project_id}"\n`),{providerKey:o.provider_key,providerVersion:o.provider_version,authConfigKey:o.auth_config_key,environment:o.environment,organizationId:o.organization_id,secureId:o.account_id,projectSecureId:o.project_id,credentials:o.credentials}}catch(e){b.error(`Failed to fetch account information: ${e.message}`),process.exit(1)}};#l=e=>{let t=e;try{t=f.readFileSync(e,`utf-8`)}catch{}try{return Tp.parse(JSON.parse(t))}catch(e){b.error(`Failed to parse credentials: ${e.message}`),process.exit(1)}};#u=e=>{let t=e;try{t=f.readFileSync(e,`utf-8`)}catch{}try{return Ep.parse(JSON.parse(t))}catch(e){b.error(`Failed to parse action parameters: ${e.message}`),process.exit(1)}};async#d({connector:e,actionId:t,account:n,pathParams:r={},queryParams:i={},body:a={},headers:o={}}){try{let s=await me({mode:`action_id`,actionId:t,account:n,connector:e,pathParams:r,queryParams:i,body:a,headers:o,getHttpClient:async()=>new ge});if(s.response?.successful){let e={...this.#f(i,s.steps),...yn(s.outputs)?s.outputs:{data:s.outputs}};return{statusCode:s.response?.statusCode,output:e}}else{let n=s.response?.message??`An error occurred while processing the request`;b.error(`Action with id ${t} from connector ${e.key}@${e.version} failed with status ${s.response?.statusCode}: ${n}`);let r={...this.#f(i,s.steps)};Object.keys(r).length>0&&(b.info(`Execution details:`),kp(r)),process.exit(1)}}catch(e){this.#p(e)}}#f(e,t){return e?.debug===`true`?{debug:{steps:t}}:{}}#p(e){let t=e;switch(P(t.errorType)&&(b.error(`An unknown error occurred: ${e instanceof Error?e.message:String(e)}`),process.exit(1)),t.errorType){case`MISSING_ACTION_ERROR`:b.error(`The specified action was not found: ${t.message}`);break;case`INVALID_ACTION_INPUTS_ERROR`:b.error(`Invalid action inputs: ${t.message}`);break;case`INVALID_CURSOR_ERROR`:b.error(`Invalid cursor: ${t.message}`);break;default:b.error(`An error occurred: ${t.message}`)}process.exit(1)}};function kp(e){console.info(fe({data:e},{indent:2,colors:{Whitespace:y.gray,Brace:y.gray,Bracket:y.gray,Colon:y.gray,Comma:y.gray,StringKey:y.red,StringLiteral:y.yellow,NumberLiteral:y.green,BooleanLiteral:y.cyan,NullLiteral:y.white}}))}const Ap=()=>{try{let e=_(ae(ve(import.meta.url)),`..`,`package.json`);return JSON.parse(h(e,`utf8`)).version}catch{return`unknown`}};var jp=class{constructor(){this.packageName=`@stackone/cli`,this.currentVersion=Ap()}async execute(e={}){try{b.info(`Checking for updates...`);let n=this.getLatestVersion();n||(b.error(`Failed to check for updates`),process.exit(1)),this.isNewerVersion(n,this.currentVersion)?(b.info(`New version available: ${t.yellow(this.currentVersion)} → ${t.green(n)}`),this.performUpdate()):e.force?(b.info(`No updates available, but forcing reinstall...`),this.performUpdate()):b.success(`You are already on the latest version (${this.currentVersion})`),process.exit(0)}catch(e){b.error(`Failed to update CLI`),e instanceof Error&&b.error(e.message),process.exit(1)}}getLatestVersion(){try{return a(`npm view ${this.packageName} version`,{encoding:`utf-8`,stdio:[`pipe`,`pipe`,`pipe`]}).trim()}catch{return null}}isNewerVersion(e,t){return _e.gt(e,t)}performUpdate(){try{b.info(`Updating CLI...`),a(`npm install -g ${this.packageName}@latest`,{encoding:`utf-8`,stdio:`inherit`}),b.success(`StackOne CLI updated successfully!`)}catch{throw Error(`Failed to install update. Please try manually: npm install -g @stackone/cli@latest`)}}},Mp=class{async execute(e){let{watchMode:n,fileOrDir:r}=e,i=d(`Watching for changes...`),a=()=>{console.clear(),console.info(t.yellow(`Watch mode enabled. Press "q" to quit.
54
+ `)}`;return this.#n(r)};#i=(e,t,n)=>{let r=e;try{r=f.readFileSync(e,`utf-8`)}catch{}try{let e=wp.parse(JSON.parse(r));return{providerKey:t,providerVersion:n,authConfigKey:e.auth_config_key,environment:e.environment,organizationId:e.organization_id,secureId:e.account_id,projectSecureId:e.project_id}}catch(e){b.error(`Failed to parse account information: ${e.message}`),process.exit(1)}};#a=e=>e.includes(`@`)&&e.split(`@`).length===2&&!e.includes(`/`)&&!e.includes(`\\`)&&!e.endsWith(`.yaml`)&&!e.endsWith(`.yml`);#o=async(e,n,r)=>{(P(e)||P(n)||P(r))&&(b.error(`Connector identifier, API URL, and API key are required to fetch connector from registry.`),process.exit(1));try{console.info(t.blue(`Fetching connector ${e} from registry...`));let i=Buffer.from(r).toString(`base64`),a=await fetch(`${n}/registry/connectors/${e}`,{method:`GET`,headers:{Authorization:`Basic ${i}`}});if(!a.ok){let e=await a.text();b.error(`Failed to fetch connector from registry: ${a.status} - ${a.statusText}`),e&&b.error(e),process.exit(1)}let o=await a.text(),s=this.#n(o);return b.success(`Fetched connector ${s.key}@${s.version} from registry\n`),s}catch(e){b.error(`Failed to fetch connector from registry: ${e.message}`),process.exit(1)}};#s=async(e,n,r)=>{(P(e)||P(n)||P(r))&&(b.error(`Account ID, API URL, and API key are required to fetch connector information.`),process.exit(1));try{console.info(t.blue(`Fetching connector for account ${e} from API...`));let i=Buffer.from(r).toString(`base64`),a=await fetch(`${n}/accounts/${e}/connector`,{method:`GET`,headers:{Authorization:`Basic ${i}`}});if(!a.ok){let e=await a.text();b.error(`Failed to fetch connector information: ${a.status} - ${a.statusText}`),e&&b.error(e),process.exit(1)}let o=await a.text(),s=this.#n(o);return b.success(`Fetched connector ${s.key}@${s.version} for account "${e}"\n`),s}catch(e){b.error(`Failed to fetch connector information: ${e.message}`),process.exit(1)}};#c=async(e,n,r)=>{(P(e)||P(n)||P(r))&&(b.error(`Account ID, API URL, and API key are required to fetch account information.`),process.exit(1));try{console.info(t.blue(`Fetching account ${e} information from API...`));let i=Buffer.from(r).toString(`base64`),a=await fetch(`${n}/accounts/${e}/credentials`,{method:`GET`,headers:{Authorization:`Basic ${i}`}});if(!a.ok){let e=await a.text();b.error(`Failed to fetch account information: ${a.status} - ${a.statusText}`),e&&b.error(e),process.exit(1)}let o=await a.json();return b.success(`Fetched information account id "${e}" from project "${o.project_id}"\n`),{providerKey:o.provider_key,providerVersion:o.provider_version,authConfigKey:o.auth_config_key,environment:o.environment,organizationId:o.organization_id,secureId:o.account_id,projectSecureId:o.project_id,credentials:o.credentials}}catch(e){b.error(`Failed to fetch account information: ${e.message}`),process.exit(1)}};#l=e=>{let t=e;try{t=f.readFileSync(e,`utf-8`)}catch{}try{return Tp.parse(JSON.parse(t))}catch(e){b.error(`Failed to parse credentials: ${e.message}`),process.exit(1)}};#u=e=>{let t=e;try{t=f.readFileSync(e,`utf-8`)}catch{}try{return Ep.parse(JSON.parse(t))}catch(e){b.error(`Failed to parse action parameters: ${e.message}`),process.exit(1)}};async#d({connector:e,actionId:t,account:n,pathParams:r={},queryParams:i={},body:a={},headers:o={}}){try{let s=await me({mode:`action_id`,actionId:t,account:n,connector:e,pathParams:r,queryParams:i,body:a,headers:o,getHttpClient:async()=>new ge});if(s.response?.successful){let e={...this.#f(i,s.steps),...yn(s.outputs)?s.outputs:{data:s.outputs}};return{statusCode:s.response?.statusCode,output:e}}else{let n=s.response?.message??`An error occurred while processing the request`;b.error(`Action with id ${t} from connector ${e.key}@${e.version} failed with status ${s.response?.statusCode}: ${n}`);let r={...this.#f(i,s.steps)};Object.keys(r).length>0&&(b.info(`Execution details:`),kp(r)),process.exit(1)}}catch(e){this.#p(e)}}#f(e,t){return e?.debug===`true`?{debug:{steps:t}}:{}}#p(e){let t=e;switch(P(t.errorType)&&(b.error(`An unknown error occurred: ${e instanceof Error?e.message:String(e)}`),process.exit(1)),t.errorType){case`MISSING_ACTION_ERROR`:b.error(`The specified action was not found: ${t.message}`);break;case`INVALID_ACTION_INPUTS_ERROR`:b.error(`Invalid action inputs: ${t.message}`);break;case`INVALID_CURSOR_ERROR`:b.error(`Invalid cursor: ${t.message}`);break;default:b.error(`An error occurred: ${t.message}`)}process.exit(1)}};function kp(e){console.info(fe({data:e},{indent:2,colors:{Whitespace:y.gray,Brace:y.gray,Bracket:y.gray,Colon:y.gray,Comma:y.gray,StringKey:y.red,StringLiteral:y.yellow,NumberLiteral:y.green,BooleanLiteral:y.cyan,NullLiteral:y.white}}))}const Ap=()=>{try{let e=_(ae(ve(import.meta.url)),`..`,`package.json`);return JSON.parse(h(e,`utf8`)).version}catch{return`unknown`}};var jp=class{constructor(){this.packageName=`@stackone/cli`,this.currentVersion=Ap()}async execute(e={}){try{b.info(`Checking for updates...`);let n=this.getLatestVersion();n||(b.error(`Failed to check for updates`),process.exit(1)),this.isNewerVersion(n,this.currentVersion)?(b.info(`New version available: ${t.yellow(this.currentVersion)} → ${t.green(n)}`),this.performUpdate()):e.force?(b.info(`No updates available, but forcing reinstall...`),this.performUpdate()):b.success(`You are already on the latest version (${this.currentVersion})`),process.exit(0)}catch(e){b.error(`Failed to update CLI`),e instanceof Error&&b.error(e.message),process.exit(1)}}getLatestVersion(){try{return a(`npm view ${this.packageName} version`,{encoding:`utf-8`,stdio:[`pipe`,`pipe`,`pipe`]}).trim()}catch{return null}}isNewerVersion(e,t){return _e.gt(e,t)}isUsingVolta(){return typeof process.env.VOLTA_HOME==`string`&&process.env.VOLTA_HOME.length>0}performUpdate(){let e=this.isUsingVolta();try{b.info(`Updating CLI...`),a(e?`volta install ${this.packageName}@latest`:`npm install -g ${this.packageName}@latest`,{encoding:`utf-8`,stdio:`inherit`}),b.success(`StackOne CLI updated successfully!`)}catch{let t=e?`volta install ${this.packageName}@latest`:`npm install -g ${this.packageName}@latest`;throw Error(`Failed to install update. Please try manually: ${t}`)}}},Mp=class{async execute(e){let{watchMode:n,fileOrDir:r}=e,i=d(`Watching for changes...`),a=()=>{console.clear(),console.info(t.yellow(`Watch mode enabled. Press "q" to quit.
55
55
  `))};if(r){try{te(r)}catch{b.error(`File or directory not found: ${r}`),process.exit(1)}if(n){let{watch:e}=await import(`chokidar`),n=(await import(`readline`)).createInterface({input:process.stdin,output:process.stdout});process.stdin.setRawMode(!0),process.stdin.resume(),process.stdin.setEncoding(`utf8`);let o=()=>{console.info(t.grey(`
56
56
 
57
57
  Exiting watch mode...`)),s.close(),i.stop(),n.close(),process.exit(0)};a(),console.info(t.blue(`Running connector(s) validations...`)),await Np(r),i.start();let s=e(r||`.`,{ignored:/(^|[/\\])\../,persistent:!0});s.on(`change`,async e=>{a(),i.stop(),console.info(t.blue(`File change detected. Running connector(s) validations...`)),await Np(r),i.start()}),process.stdin.on(`data`,e=>{e.toString()===`q`&&o()}),process.on(`SIGINT`,()=>{o()})}else await Np(r),process.exit(0)}}};const Np=async e=>{let t=te(e);if(t.isDirectory()){let t=g(e).filter(e=>e.endsWith(`.s1.yaml`));if(t.length===0){b.error(`No StackOne connectors found in directory: ${e}. Connector files need to have the extension .s1.yaml.\n`);return}let n=0,r=0;for(let i of t){let t=`${e}/${i}`;te(t).isFile()&&(await Pp(t)?n++:r++)}b.info(`Validation completed: ${n} valid, ${r} invalid connectors.\n`)}else t.isFile()&&e.endsWith(`s1.yaml`)?await Pp(e):b.error(`No StackOne connector found: ${e}. Connector files need to have the extension .s1.yaml.\n`)},Pp=async e=>{let n=he(pe(e)),r=n?.errors??[];if(n.success){let t=e.split(`/`).pop()||e;return b.success(`Connector ${t} is valid!\n`),!0}else if(r.length>0)return b.error(`Connector ${e} is not valid. Please fix the following errors:\n`),r.forEach(e=>{console.info(t.red(`- L${e.line}: ${e.message}`))}),console.info(`
@@ -51,7 +51,7 @@ To create a profile, run "stackone init".`),process.exit(1)),s&&f&&(x.error(`Ple
51
51
  To create a profile, run "stackone init".`),process.exit(1)),m=await this.#o(e,p?.apiUrl??Mg,p?.apiKey)):m=this.#e(e):M(i)&&(m=await this.#s(i,p?.apiUrl??Mg,p?.apiKey));let h=M(t)?this.#r(t,e):m;N(h)&&(x.error(`A valid connector is required to run an action.`),process.exit(1));let ee=M(h?.actions)?Object.keys(h?.actions).length:0,_=M(h?.actions)?Object.keys(h.actions)[ee-1]:void 0,te=M(_)?h?.actions?.[_]?.id:void 0,ne=(M(n)&&!n?.startsWith(`${h.key}_`)?`${h.key}_${n}`:n)??te;N(ne)&&(x.error(`A valid action ID is required to run an action.`),process.exit(1));let v=M(i)?await this.#c(i,p?.apiUrl??Mg,p?.apiKey):{},re=M(r)?this.#i(r,h.key??`unknown`,h.version??`unknown`):void 0,ie=M(o)?this.#l(o):{},y={...v,...re,credentials:{...v.credentials??{},...ie}};N(y)&&(x.error(`A valid account data is required to run an action.`),process.exit(1));let b=M(a)?this.#u(a):{path:{},queryParams:{},header:{},body:{}},ae=h.actions?.[ne];N(ae)&&(x.error(`Action with ID '${ne}' not found in the connector ${h.key}@${h.version}.`),process.exit(1));let oe=await this.#d({connector:h,actionId:ne,account:y,queryParams:{...b.queryParams,...u?{debug:`true`}:{}},pathParams:b.path,body:b.body,headers:b.header});if(M(c))try{g.default.writeFileSync(c,JSON.stringify(oe.output,null,2),`utf-8`),x.info(`Output written to file: ${c}`)}catch(e){x.error(`Failed to write output to file ${c}: ${e.message}`),process.exit(1)}else Pg(oe.output);console.info(l.default.green(`\nAction '${ne}' from connector '${h?.key}@${h?.version}' executed successfully!`)),process.exit(0)}#e=e=>{let t=e;try{t=(0,b.loadConnector)(e)}catch{}return t?this.#n(t):void 0};#t=e=>{try{return(0,b.loadConnector)(e)}catch(t){x.error(`Failed to load connector file from ${e}: ${t.message}`),process.exit(1)}};#n=e=>{let t=(0,b.validateYamlConnector)(e),n=t?.errors??[];if(t.success)return t.connector||(x.error(`Failed to load connector.`),process.exit(1)),t.connector;n.length>0?(x.error(`Connector is not valid. Please fix the following errors:
52
52
  `),n.forEach(e=>{console.info(l.default.red(`- L${e.line}: ${e.message}`))}),process.exit(1)):(x.error(`Connector is not valid. Please check the file for errors.`),process.exit(1))};#r=(e,t)=>{let n=e;try{n=g.default.readFileSync(e,`utf-8`)}catch{}N(t)&&(x.error(`A valid connector is required to load an action.`),process.exit(1));let r=`${this.#t(t)} - ${n.split(`
53
53
  `).map((e,t)=>t===0?e:` ${e}`).join(`
54
- `)}`;return this.#n(r)};#i=(e,t,n)=>{let r=e;try{r=g.default.readFileSync(e,`utf-8`)}catch{}try{let e=kg.parse(JSON.parse(r));return{providerKey:t,providerVersion:n,authConfigKey:e.auth_config_key,environment:e.environment,organizationId:e.organization_id,secureId:e.account_id,projectSecureId:e.project_id}}catch(e){x.error(`Failed to parse account information: ${e.message}`),process.exit(1)}};#a=e=>e.includes(`@`)&&e.split(`@`).length===2&&!e.includes(`/`)&&!e.includes(`\\`)&&!e.endsWith(`.yaml`)&&!e.endsWith(`.yml`);#o=async(e,t,n)=>{(N(e)||N(t)||N(n))&&(x.error(`Connector identifier, API URL, and API key are required to fetch connector from registry.`),process.exit(1));try{console.info(l.default.blue(`Fetching connector ${e} from registry...`));let r=Buffer.from(n).toString(`base64`),i=await fetch(`${t}/registry/connectors/${e}`,{method:`GET`,headers:{Authorization:`Basic ${r}`}});if(!i.ok){let e=await i.text();x.error(`Failed to fetch connector from registry: ${i.status} - ${i.statusText}`),e&&x.error(e),process.exit(1)}let a=await i.text(),o=this.#n(a);return x.success(`Fetched connector ${o.key}@${o.version} from registry\n`),o}catch(e){x.error(`Failed to fetch connector from registry: ${e.message}`),process.exit(1)}};#s=async(e,t,n)=>{(N(e)||N(t)||N(n))&&(x.error(`Account ID, API URL, and API key are required to fetch connector information.`),process.exit(1));try{console.info(l.default.blue(`Fetching connector for account ${e} from API...`));let r=Buffer.from(n).toString(`base64`),i=await fetch(`${t}/accounts/${e}/connector`,{method:`GET`,headers:{Authorization:`Basic ${r}`}});if(!i.ok){let e=await i.text();x.error(`Failed to fetch connector information: ${i.status} - ${i.statusText}`),e&&x.error(e),process.exit(1)}let a=await i.text(),o=this.#n(a);return x.success(`Fetched connector ${o.key}@${o.version} for account "${e}"\n`),o}catch(e){x.error(`Failed to fetch connector information: ${e.message}`),process.exit(1)}};#c=async(e,t,n)=>{(N(e)||N(t)||N(n))&&(x.error(`Account ID, API URL, and API key are required to fetch account information.`),process.exit(1));try{console.info(l.default.blue(`Fetching account ${e} information from API...`));let r=Buffer.from(n).toString(`base64`),i=await fetch(`${t}/accounts/${e}/credentials`,{method:`GET`,headers:{Authorization:`Basic ${r}`}});if(!i.ok){let e=await i.text();x.error(`Failed to fetch account information: ${i.status} - ${i.statusText}`),e&&x.error(e),process.exit(1)}let a=await i.json();return x.success(`Fetched information account id "${e}" from project "${a.project_id}"\n`),{providerKey:a.provider_key,providerVersion:a.provider_version,authConfigKey:a.auth_config_key,environment:a.environment,organizationId:a.organization_id,secureId:a.account_id,projectSecureId:a.project_id,credentials:a.credentials}}catch(e){x.error(`Failed to fetch account information: ${e.message}`),process.exit(1)}};#l=e=>{let t=e;try{t=g.default.readFileSync(e,`utf-8`)}catch{}try{return Ag.parse(JSON.parse(t))}catch(e){x.error(`Failed to parse credentials: ${e.message}`),process.exit(1)}};#u=e=>{let t=e;try{t=g.default.readFileSync(e,`utf-8`)}catch{}try{return jg.parse(JSON.parse(t))}catch(e){x.error(`Failed to parse action parameters: ${e.message}`),process.exit(1)}};async#d({connector:e,actionId:t,account:n,pathParams:r={},queryParams:i={},body:a={},headers:o={}}){try{let s=await(0,b.runAction)({mode:`action_id`,actionId:t,account:n,connector:e,pathParams:r,queryParams:i,body:a,headers:o,getHttpClient:async()=>new ae.HttpClient});if(s.response?.successful){let e={...this.#f(i,s.steps),...Wi(s.outputs)?s.outputs:{data:s.outputs}};return{statusCode:s.response?.statusCode,output:e}}else{let n=s.response?.message??`An error occurred while processing the request`;x.error(`Action with id ${t} from connector ${e.key}@${e.version} failed with status ${s.response?.statusCode}: ${n}`);let r={...this.#f(i,s.steps)};Object.keys(r).length>0&&(x.info(`Execution details:`),Pg(r)),process.exit(1)}}catch(e){this.#p(e)}}#f(e,t){return e?.debug===`true`?{debug:{steps:t}}:{}}#p(e){let t=e;switch(N(t.errorType)&&(x.error(`An unknown error occurred: ${e instanceof Error?e.message:String(e)}`),process.exit(1)),t.errorType){case`MISSING_ACTION_ERROR`:x.error(`The specified action was not found: ${t.message}`);break;case`INVALID_ACTION_INPUTS_ERROR`:x.error(`Invalid action inputs: ${t.message}`);break;case`INVALID_CURSOR_ERROR`:x.error(`Invalid cursor: ${t.message}`);break;default:x.error(`An error occurred: ${t.message}`)}process.exit(1)}};function Pg(e){console.info((0,y.colorize)({data:e},{indent:2,colors:{Whitespace:y.color.gray,Brace:y.color.gray,Bracket:y.color.gray,Colon:y.color.gray,Comma:y.color.gray,StringKey:y.color.red,StringLiteral:y.color.yellow,NumberLiteral:y.color.green,BooleanLiteral:y.color.cyan,NullLiteral:y.color.white}}))}const Fg=()=>{try{let e=(0,_.join)((0,_.dirname)((0,se.fileURLToPath)(require(`url`).pathToFileURL(__filename).href)),`..`,`package.json`);return JSON.parse((0,g.readFileSync)(e,`utf8`)).version}catch{return`unknown`}};var Ig=class{constructor(){this.packageName=`@stackone/cli`,this.currentVersion=Fg()}async execute(e={}){try{x.info(`Checking for updates...`);let t=this.getLatestVersion();t||(x.error(`Failed to check for updates`),process.exit(1)),this.isNewerVersion(t,this.currentVersion)?(x.info(`New version available: ${l.default.yellow(this.currentVersion)} → ${l.default.green(t)}`),this.performUpdate()):e.force?(x.info(`No updates available, but forcing reinstall...`),this.performUpdate()):x.success(`You are already on the latest version (${this.currentVersion})`),process.exit(0)}catch(e){x.error(`Failed to update CLI`),e instanceof Error&&x.error(e.message),process.exit(1)}}getLatestVersion(){try{return(0,d.execSync)(`npm view ${this.packageName} version`,{encoding:`utf-8`,stdio:[`pipe`,`pipe`,`pipe`]}).trim()}catch{return null}}isNewerVersion(e,t){return oe.default.gt(e,t)}performUpdate(){try{x.info(`Updating CLI...`),(0,d.execSync)(`npm install -g ${this.packageName}@latest`,{encoding:`utf-8`,stdio:`inherit`}),x.success(`StackOne CLI updated successfully!`)}catch{throw Error(`Failed to install update. Please try manually: npm install -g @stackone/cli@latest`)}}},Lg=class{async execute(e){let{watchMode:t,fileOrDir:n}=e,r=(0,h.default)(`Watching for changes...`),i=()=>{console.clear(),console.info(l.default.yellow(`Watch mode enabled. Press "q" to quit.
54
+ `)}`;return this.#n(r)};#i=(e,t,n)=>{let r=e;try{r=g.default.readFileSync(e,`utf-8`)}catch{}try{let e=kg.parse(JSON.parse(r));return{providerKey:t,providerVersion:n,authConfigKey:e.auth_config_key,environment:e.environment,organizationId:e.organization_id,secureId:e.account_id,projectSecureId:e.project_id}}catch(e){x.error(`Failed to parse account information: ${e.message}`),process.exit(1)}};#a=e=>e.includes(`@`)&&e.split(`@`).length===2&&!e.includes(`/`)&&!e.includes(`\\`)&&!e.endsWith(`.yaml`)&&!e.endsWith(`.yml`);#o=async(e,t,n)=>{(N(e)||N(t)||N(n))&&(x.error(`Connector identifier, API URL, and API key are required to fetch connector from registry.`),process.exit(1));try{console.info(l.default.blue(`Fetching connector ${e} from registry...`));let r=Buffer.from(n).toString(`base64`),i=await fetch(`${t}/registry/connectors/${e}`,{method:`GET`,headers:{Authorization:`Basic ${r}`}});if(!i.ok){let e=await i.text();x.error(`Failed to fetch connector from registry: ${i.status} - ${i.statusText}`),e&&x.error(e),process.exit(1)}let a=await i.text(),o=this.#n(a);return x.success(`Fetched connector ${o.key}@${o.version} from registry\n`),o}catch(e){x.error(`Failed to fetch connector from registry: ${e.message}`),process.exit(1)}};#s=async(e,t,n)=>{(N(e)||N(t)||N(n))&&(x.error(`Account ID, API URL, and API key are required to fetch connector information.`),process.exit(1));try{console.info(l.default.blue(`Fetching connector for account ${e} from API...`));let r=Buffer.from(n).toString(`base64`),i=await fetch(`${t}/accounts/${e}/connector`,{method:`GET`,headers:{Authorization:`Basic ${r}`}});if(!i.ok){let e=await i.text();x.error(`Failed to fetch connector information: ${i.status} - ${i.statusText}`),e&&x.error(e),process.exit(1)}let a=await i.text(),o=this.#n(a);return x.success(`Fetched connector ${o.key}@${o.version} for account "${e}"\n`),o}catch(e){x.error(`Failed to fetch connector information: ${e.message}`),process.exit(1)}};#c=async(e,t,n)=>{(N(e)||N(t)||N(n))&&(x.error(`Account ID, API URL, and API key are required to fetch account information.`),process.exit(1));try{console.info(l.default.blue(`Fetching account ${e} information from API...`));let r=Buffer.from(n).toString(`base64`),i=await fetch(`${t}/accounts/${e}/credentials`,{method:`GET`,headers:{Authorization:`Basic ${r}`}});if(!i.ok){let e=await i.text();x.error(`Failed to fetch account information: ${i.status} - ${i.statusText}`),e&&x.error(e),process.exit(1)}let a=await i.json();return x.success(`Fetched information account id "${e}" from project "${a.project_id}"\n`),{providerKey:a.provider_key,providerVersion:a.provider_version,authConfigKey:a.auth_config_key,environment:a.environment,organizationId:a.organization_id,secureId:a.account_id,projectSecureId:a.project_id,credentials:a.credentials}}catch(e){x.error(`Failed to fetch account information: ${e.message}`),process.exit(1)}};#l=e=>{let t=e;try{t=g.default.readFileSync(e,`utf-8`)}catch{}try{return Ag.parse(JSON.parse(t))}catch(e){x.error(`Failed to parse credentials: ${e.message}`),process.exit(1)}};#u=e=>{let t=e;try{t=g.default.readFileSync(e,`utf-8`)}catch{}try{return jg.parse(JSON.parse(t))}catch(e){x.error(`Failed to parse action parameters: ${e.message}`),process.exit(1)}};async#d({connector:e,actionId:t,account:n,pathParams:r={},queryParams:i={},body:a={},headers:o={}}){try{let s=await(0,b.runAction)({mode:`action_id`,actionId:t,account:n,connector:e,pathParams:r,queryParams:i,body:a,headers:o,getHttpClient:async()=>new ae.HttpClient});if(s.response?.successful){let e={...this.#f(i,s.steps),...Wi(s.outputs)?s.outputs:{data:s.outputs}};return{statusCode:s.response?.statusCode,output:e}}else{let n=s.response?.message??`An error occurred while processing the request`;x.error(`Action with id ${t} from connector ${e.key}@${e.version} failed with status ${s.response?.statusCode}: ${n}`);let r={...this.#f(i,s.steps)};Object.keys(r).length>0&&(x.info(`Execution details:`),Pg(r)),process.exit(1)}}catch(e){this.#p(e)}}#f(e,t){return e?.debug===`true`?{debug:{steps:t}}:{}}#p(e){let t=e;switch(N(t.errorType)&&(x.error(`An unknown error occurred: ${e instanceof Error?e.message:String(e)}`),process.exit(1)),t.errorType){case`MISSING_ACTION_ERROR`:x.error(`The specified action was not found: ${t.message}`);break;case`INVALID_ACTION_INPUTS_ERROR`:x.error(`Invalid action inputs: ${t.message}`);break;case`INVALID_CURSOR_ERROR`:x.error(`Invalid cursor: ${t.message}`);break;default:x.error(`An error occurred: ${t.message}`)}process.exit(1)}};function Pg(e){console.info((0,y.colorize)({data:e},{indent:2,colors:{Whitespace:y.color.gray,Brace:y.color.gray,Bracket:y.color.gray,Colon:y.color.gray,Comma:y.color.gray,StringKey:y.color.red,StringLiteral:y.color.yellow,NumberLiteral:y.color.green,BooleanLiteral:y.color.cyan,NullLiteral:y.color.white}}))}const Fg=()=>{try{let e=(0,_.join)((0,_.dirname)((0,se.fileURLToPath)(require(`url`).pathToFileURL(__filename).href)),`..`,`package.json`);return JSON.parse((0,g.readFileSync)(e,`utf8`)).version}catch{return`unknown`}};var Ig=class{constructor(){this.packageName=`@stackone/cli`,this.currentVersion=Fg()}async execute(e={}){try{x.info(`Checking for updates...`);let t=this.getLatestVersion();t||(x.error(`Failed to check for updates`),process.exit(1)),this.isNewerVersion(t,this.currentVersion)?(x.info(`New version available: ${l.default.yellow(this.currentVersion)} → ${l.default.green(t)}`),this.performUpdate()):e.force?(x.info(`No updates available, but forcing reinstall...`),this.performUpdate()):x.success(`You are already on the latest version (${this.currentVersion})`),process.exit(0)}catch(e){x.error(`Failed to update CLI`),e instanceof Error&&x.error(e.message),process.exit(1)}}getLatestVersion(){try{return(0,d.execSync)(`npm view ${this.packageName} version`,{encoding:`utf-8`,stdio:[`pipe`,`pipe`,`pipe`]}).trim()}catch{return null}}isNewerVersion(e,t){return oe.default.gt(e,t)}isUsingVolta(){return typeof process.env.VOLTA_HOME==`string`&&process.env.VOLTA_HOME.length>0}performUpdate(){let e=this.isUsingVolta();try{x.info(`Updating CLI...`),(0,d.execSync)(e?`volta install ${this.packageName}@latest`:`npm install -g ${this.packageName}@latest`,{encoding:`utf-8`,stdio:`inherit`}),x.success(`StackOne CLI updated successfully!`)}catch{let t=e?`volta install ${this.packageName}@latest`:`npm install -g ${this.packageName}@latest`;throw Error(`Failed to install update. Please try manually: ${t}`)}}},Lg=class{async execute(e){let{watchMode:t,fileOrDir:n}=e,r=(0,h.default)(`Watching for changes...`),i=()=>{console.clear(),console.info(l.default.yellow(`Watch mode enabled. Press "q" to quit.
55
55
  `))};if(n){try{(0,g.statSync)(n)}catch{x.error(`File or directory not found: ${n}`),process.exit(1)}if(t){let{watch:e}=await import(`chokidar`),t=(await import(`readline`)).createInterface({input:process.stdin,output:process.stdout});process.stdin.setRawMode(!0),process.stdin.resume(),process.stdin.setEncoding(`utf8`);let a=()=>{console.info(l.default.grey(`
56
56
 
57
57
  Exiting watch mode...`)),o.close(),r.stop(),t.close(),process.exit(0)};i(),console.info(l.default.blue(`Running connector(s) validations...`)),await Rg(n),r.start();let o=e(n||`.`,{ignored:/(^|[/\\])\../,persistent:!0});o.on(`change`,async e=>{i(),r.stop(),console.info(l.default.blue(`File change detected. Running connector(s) validations...`)),await Rg(n),r.start()}),process.stdin.on(`data`,e=>{e.toString()===`q`&&a()}),process.on(`SIGINT`,()=>{a()})}else await Rg(n),process.exit(0)}}};const Rg=async e=>{let t=(0,g.statSync)(e);if(t.isDirectory()){let t=(0,g.readdirSync)(e).filter(e=>e.endsWith(`.s1.yaml`));if(t.length===0){x.error(`No StackOne connectors found in directory: ${e}. Connector files need to have the extension .s1.yaml.\n`);return}let n=0,r=0;for(let i of t){let t=`${e}/${i}`;(0,g.statSync)(t).isFile()&&(await zg(t)?n++:r++)}x.info(`Validation completed: ${n} valid, ${r} invalid connectors.\n`)}else t.isFile()&&e.endsWith(`s1.yaml`)?await zg(e):x.error(`No StackOne connector found: ${e}. Connector files need to have the extension .s1.yaml.\n`)},zg=async e=>{let t=(0,b.validateYamlConnector)((0,b.loadConnector)(e)),n=t?.errors??[];if(t.success){let t=e.split(`/`).pop()||e;return x.success(`Connector ${t} is valid!\n`),!0}else if(n.length>0)return x.error(`Connector ${e} is not valid. Please fix the following errors:\n`),n.forEach(e=>{console.info(l.default.red(`- L${e.line}: ${e.message}`))}),console.info(`
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- const e=require(`./cliCore-D1Qdo7ts.cjs`);exports.CLI=e.t;
1
+ const e=require(`./cliCore-E8z0v8KP.cjs`);exports.CLI=e.t;
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{t as e}from"./cliCore-C7KMeP98.mjs";export{e as CLI};
1
+ import{t as e}from"./cliCore-D2QQhlz-.mjs";export{e as CLI};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stackone/cli",
3
- "version": "1.13.1",
3
+ "version": "1.13.2",
4
4
  "description": "StackOne Connect CLI tool",
5
5
  "type": "module",
6
6
  "main": "dist/index.mjs",