@culvii/cli 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ import n from'fs/promises';import s from'path';import c from'os';import f from'crypto';import m from'proper-lockfile';var l=class{constructor(r=s.join(c.homedir(),".culvii","config"),t=s.join(c.homedir(),".culvii",".lock")){this.configPath=r;this.lockPath=t;}async ensureDir(){let r=s.dirname(this.configPath);return await n.mkdir(r,{recursive:true,mode:448}),r}async read(r={exitOnError:true}){try{let t=await n.readFile(this.configPath,"utf-8"),i=JSON.parse(t);if(!i.active||!i.contexts||!i.contexts[i.active])throw r.exitOnError&&(console.error("Error: Active context key not found in contexts in ~/.culvii/config."),console.error("Please run `culvii login` to authenticate and configure your active context."),process.exit(1)),new Error("Active context key not found");return (!i.anonymousId||!i.version)&&(i.anonymousId=i.anonymousId??f.randomUUID(),i.version=i.version??1,await this.withLock(async()=>{try{let e=await n.readFile(this.configPath,"utf-8"),o=JSON.parse(e);o.anonymousId=i.anonymousId,o.version=i.version,await this.write(o);}catch{await this.write(i);}})),i}catch(t){throw r.exitOnError&&(t.code==="ENOENT"&&(console.error("Error: Config file not found at ~/.culvii/config."),console.error("Please run `culvii login` to authenticate and create your config."),process.exit(1)),console.error(`Error reading config: ${t.message}`),console.error("Please run `culvii login` to fix your configuration."),process.exit(1)),t}}async write(r){let t=await this.ensureDir(),i=`${this.configPath}.tmp`,e=JSON.stringify(r,null,2),o;try{o=await n.open(i,"w",384),await o.writeFile(e,"utf-8"),await o.sync();}finally{o&&await o.close();}if(await n.rename(i,this.configPath),await n.chmod(this.configPath,384),c.platform()!=="win32"){let a;try{a=await n.open(t,"r"),await a.sync();}catch{}finally{a&&await a.close();}}}async withLock(r){await this.ensureDir();let t=this.lockPath;try{await n.writeFile(t,"",{flag:"a",mode:384});}catch{}let i=await m.lock(t,{stale:1e4,retries:{retries:5,minTimeout:100,maxTimeout:1e3}});try{return await r()}finally{await i();}}};export{l as a};
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ import {a as a$1}from'./chunk-57XLDHK6.js';import {b,o,a as a$2,v,l}from'./chunk-YKFGEPLO.js';import {a}from'./chunk-YPLDPHHD.js';import {useState,useEffect}from'react';import {useInput,Box}from'ink';import {jsxs,jsx}from'react/jsx-runtime';function N({label:g,options:e,onSubmit:a$3,isPassword:D,isActive:f=true,defaultValue:u,defaultKey:m}){let[i,s]=useState(""),[k,p]=useState(true);useEffect(()=>{if(!f){p(false);return}let r=setInterval(()=>{p(x=>!x);},500);return ()=>clearInterval(r)},[f]),useInput((r,x)=>{if(f)if(x.return){if(!i){e&&e.length>0&&m!==void 0?a$3&&a$3(m):(!e||e.length===0)&&u!==void 0&&a$3&&a$3(u);return}if(a$3)if(e&&e.length>0){let c=e.find(R=>R.key.toLowerCase()===i.toLowerCase());c?a$3(c.key):s("");}else a$3(i);}else x.backspace||x.delete?s(c=>c.slice(0,-1)):s(c=>c+r);});let v$1=D?"*".repeat(i.length):i,w=a().supportsUnicode?"round":"single",C=e&&e.length>0?Math.max(...e.map(r=>r.key.length)):0;return jsxs(Box,{flexDirection:"column",marginTop:1,children:[e&&e.length>0&&jsxs(Box,{flexDirection:"column",borderStyle:w,borderColor:b,paddingX:1,paddingY:0,children:[jsx(Box,{children:jsx(a$1,{variant:"accent",bold:true,children:g})}),jsx(Box,{flexDirection:"column",children:e.map(r=>jsxs(Box,{flexDirection:"row",gap:1,children:[jsxs(a$1,{variant:"subtle",children:["[",r.key.padStart(C),"]"]}),jsx(a$1,{variant:"default",children:r.label}),r.description&&jsx(a$1,{variant:"subtle",children:r.description})]},r.key))})]}),(f||i)&&jsxs(Box,{flexDirection:"row",marginTop:e&&e.length>0?1:0,gap:1,alignItems:"center",children:[!(e&&e.length>0)&&jsx(a$1,{variant:"accent",bold:true,children:g}),jsxs(Box,{flexDirection:"row",children:[e&&e.length>0&&jsxs(Box,{flexDirection:"row",children:[jsx(a$1,{color:o,children:"~ "}),jsx(a$1,{color:a$2,bold:true,children:v+" "})]}),jsx(a$1,{color:l,children:v$1}),k&&f&&jsx(a$1,{backgroundColor:a$2,children:" "})]})]})]})}export{N as a};
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ import {a}from'./chunk-57XLDHK6.js';import {B,a as a$1,m}from'./chunk-YKFGEPLO.js';import {useState,useEffect}from'react';import {Box}from'ink';import {jsxs,jsx}from'react/jsx-runtime';var i=B;function F({label:e}){let[p,f]=useState(0);return useEffect(()=>{let c=setInterval(()=>{f(s=>(s+1)%i.length);},80);return ()=>clearInterval(c)},[]),jsxs(Box,{flexDirection:"row",gap:1,children:[jsx(a,{color:a$1,children:i[p]}),e&&jsx(a,{color:m,children:e})]})}export{F as a};
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ import {c as c$1,w as w$1,l,m,a,y,e,x,o}from'./chunk-YKFGEPLO.js';import c from'fs/promises';import w from'path';import T from'os';import P from'proper-lockfile';import p from'fs';import {Box,Text}from'ink';import {jsxs,jsx}from'react/jsx-runtime';var A=class{constructor(t=w.join(T.homedir(),".culvii","tokens.json"),e=w.join(T.homedir(),".culvii",".lock")){this.configPath=t;this.lockPath=e;}async ensureDir(){let t=w.dirname(this.configPath);return await c.mkdir(t,{recursive:true,mode:448}),t}async get(){try{let t=await c.readFile(this.configPath,"utf-8");try{let e=JSON.parse(t);return e&&e.version===1&&typeof e.accessToken=="string"&&typeof e.refreshToken=="string"&&typeof e.expiresAt=="number"&&e.tokenType==="Bearer"&&typeof e.issuedAt=="number"&&typeof e.issuer=="string"?e:null}catch{return null}}catch(t){return t.code==="ENOENT",null}}async set(t){let e=await this.ensureDir(),o=this.configPath,a=`${o}.tmp`,s=JSON.stringify({version:1,...t},null,2),f;try{f=await c.open(a,"w",384),await f.writeFile(s,"utf-8"),await f.sync();}finally{f&&await f.close();}if(await c.rename(a,o),T.platform()!=="win32"){let y;try{y=await c.open(e,"r"),await y.sync();}catch{}finally{y&&await y.close();}}}async delete(){try{await c.unlink(this.configPath);}catch(t){if(t.code!=="ENOENT")throw t}}async withLock(t){await this.ensureDir();let e=this.lockPath;try{await c.writeFile(e,"",{flag:"a",mode:384});}catch{}let o=await P.lock(e,{stale:1e4,retries:{retries:5,minTimeout:100,maxTimeout:1e3}});try{return await t()}finally{await o();}}};var B=5*1024*1024,S=class{get isEnabled(){return process.env.CULVII_DEBUG==="1"||process.argv.includes("--debug")}constructor(){this.logDir=w.join(T.homedir(),".culvii","logs"),this.logFile=w.join(this.logDir,"cli.log");}ensureLogDir(){try{p.existsSync(this.logDir)||p.mkdirSync(this.logDir,{recursive:!0});}catch{}}rotateIfNecessary(){try{p.statSync(this.logFile).size>B&&p.renameSync(this.logFile,`${this.logFile}.1`);}catch{}}stripSensitiveData(t){if(t==null||typeof t!="object")return t;if(Array.isArray(t))return t.map(o=>this.stripSensitiveData(o));let e={};for(let[o,a]of Object.entries(t)){let s=o.toLowerCase();s==="accesstoken"||s==="refreshtoken"||s==="idtoken"||s==="code"||s==="code_verifier"||s==="codeverifier"||s==="state"||s.includes("token")||s.includes("secret")?e[o]="[REDACTED]":e[o]=typeof a=="object"?this.stripSensitiveData(a):a;}return e}log(t,e,o){if(this.isEnabled)try{this.ensureLogDir(),this.rotateIfNecessary();let a={ts:new Date().toISOString(),level:t,msg:e,...o&&{data:this.stripSensitiveData(o)}};p.appendFileSync(this.logFile,JSON.stringify(a)+`
3
+ `,"utf8");}catch{}}debug(t,e){this.log("debug",t,e);}info(t,e){this.log("info",t,e);}warn(t,e){this.log("warn",t,e);}error(t,e){this.log("error",t,e);}},J=new S;function z({state:r}){if(r.type==="login_success"){let t=r.roles.length>0?r.roles.join(", "):"no roles";return jsxs(Box,{flexDirection:"column",children:[jsxs(Box,{flexDirection:"row",children:[jsx(Text,{color:c$1,children:w$1+" "}),jsx(Text,{color:l,children:"Authenticated"})]}),jsx(Box,{paddingLeft:2,children:jsx(Text,{color:m,children:r.email})}),jsx(Box,{paddingLeft:2,children:jsxs(Text,{color:m,children:[r.tenant," \xB7 ",t]})})]})}return r.type==="login_warning"?jsxs(Box,{flexDirection:"row",children:[jsx(Text,{color:a,children:y+" "}),jsx(Text,{color:l,children:r.message})]}):r.type==="login_error"?jsxs(Box,{flexDirection:"column",children:[jsxs(Box,{flexDirection:"row",children:[jsx(Text,{color:e,children:x+" "}),jsx(Text,{color:l,children:r.message})]}),r.detail&&jsx(Box,{paddingLeft:2,children:jsx(Text,{color:o,children:r.detail})})]}):r.type==="logout_success"?jsxs(Box,{flexDirection:"row",children:[jsx(Text,{color:c$1,children:w$1+" "}),jsx(Text,{color:l,children:"Logged out"})]}):r.type==="already_logged_out"?jsx(Box,{paddingLeft:2,children:jsx(Text,{color:o,children:"Already logged out"})}):null}export{A as a,J as b,z as c};
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ import {p,o,j,f as f$1,k,a,h,d,i,e,g,c}from'./chunk-YKFGEPLO.js';import {Box,Text}from'ink';import {jsx}from'react/jsx-runtime';var f={allow:{color:c,backgroundColor:g},healthy:{color:c,backgroundColor:g},deny:{color:e,backgroundColor:i},blocked:{color:e,backgroundColor:i},warn:{color:d,backgroundColor:h},throttled:{color:d,backgroundColor:h},accent:{color:a,backgroundColor:k},info:{color:f$1,backgroundColor:j},draft:{color:o,backgroundColor:p}};function T({variant:G,children:N}){let e=f[G];return jsx(Box,{flexDirection:"row",children:jsx(Box,{paddingX:1,backgroundColor:e.backgroundColor,children:jsx(Text,{color:e.color,bold:true,children:N})})})}export{T as a};
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ import {a,u,o}from'./chunk-YKFGEPLO.js';import {Box,Text}from'ink';import {jsx,jsxs}from'react/jsx-runtime';function g({command:c,subcommand:r}){return jsx(Box,{flexDirection:"column",marginBottom:1,children:jsxs(Box,{flexDirection:"row",alignItems:"center",gap:1,children:[jsx(Text,{color:a,bold:true,children:u+" culvii"}),r&&jsx(Text,{color:o,children:r})]})})}export{g as a};
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ import {a as a$1}from'./chunk-YPLDPHHD.js';var e="#FFA500";var E="#8C5E00",A="#10B981",R="#F59E0B",_="#EF4444",T="#3B82F6",S="#065F46",G="#312915",F="#30191E",B="#152238",C="#322714";var r="#252A34";var c="#6B7383",p="#8B94A3",s="#C4CAD4",n="#E4E8EF";var x=n,N=s,O=p,D=c,L=r;var I=e,M=s,U=p,i=x;var o=a$1().supportsUnicode,X=o?"\u2726":"*",H=o?"\u276F":">";var V=o?"\u2713":"v",a=o?"\u2717":"x",m=o?"\u26A0":"!",u=o?"\u2192":"->";var K=o?"\u2500":"-",b=o?["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"]:["|","/","-","\\"];export{K as A,b as B,e as a,E as b,A as c,R as d,_ as e,T as f,S as g,G as h,F as i,B as j,C as k,x as l,N as m,O as n,D as o,L as p,I as q,M as r,U as s,i as t,X as u,H as v,V as w,a as x,m as y,u as z};
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ function l(){let e=process.env,i=process.stdout.isTTY??false,t=e.CI!==void 0&&e.CI!=="false"&&e.CI!=="0",n=e.NO_COLOR!==void 0&&e.NO_COLOR!=="",s=false;n||(e.FORCE_COLOR!==void 0&&e.FORCE_COLOR!=="0"&&e.FORCE_COLOR!=="false"||i&&(e.COLORTERM==="truecolor"||e.COLORTERM==="24bit"||e.TERM&&e.TERM!=="dumb"))&&(s=true);let o=false;return process.platform!=="win32"?o=e.TERM!=="linux":o=e.WT_SESSION!==void 0||e.TERM_PROGRAM==="vscode",!o&&(e.LANG?.toLowerCase().includes("utf-8")||e.LC_ALL?.toLowerCase().includes("utf-8"))&&(o=true),{supportsColor:s,supportsUnicode:o,isCI:t,isTTY:i,noColor:n}}export{l as a};
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export{a as ConfigStore}from'./chunk-HX54IFSD.js';import'./chunk-7UWDMECF.js';