@zibby/cli 0.1.63 → 0.1.66
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/commands/workflows/logs.js +25 -19
- package/dist/package.json +1 -1
- package/package.json +1 -1
|
@@ -1,36 +1,42 @@
|
|
|
1
|
-
import o from"chalk";import{readFileSync as
|
|
1
|
+
import o from"chalk";import{readFileSync as T,existsSync as I}from"fs";import{homedir as E}from"os";import{join as j}from"path";var $="https://logs.workflows.zibby.app";function R(n){let r=j(E(),".zibby","config.json");I(r)||(console.log(o.red(`
|
|
2
2
|
Not authenticated`)),console.log(o.gray(` Run: zibby login
|
|
3
|
-
`)),process.exit(1));let t;try{t=JSON.parse(
|
|
3
|
+
`)),process.exit(1));let t;try{t=JSON.parse(T(r,"utf-8"))}catch{console.log(o.red(`
|
|
4
4
|
Config file corrupt`)),console.log(o.gray(` Run: zibby login
|
|
5
5
|
`)),process.exit(1)}let l=t.sessionToken;l||(console.log(o.red(`
|
|
6
6
|
Not authenticated`)),console.log(o.gray(` Run: zibby login
|
|
7
|
-
`)),process.exit(1));let c=n.project;return{token:l,projectId:c}}function
|
|
7
|
+
`)),process.exit(1));let c=n.project;return{token:l,projectId:c}}function x(n){return new Date(n).toISOString().replace("T"," ").replace("Z","")}function C(n){return n==="running"?o.yellow(n):n==="completed"?o.green(n):o.red(n||"unknown")}function h(n){return n?.length>16?n.slice(0,16):n}async function S(n,r){let t=await fetch(n,{headers:{Authorization:`Bearer ${r}`}});if(!t.ok){let l=await t.text();throw new Error(`API ${t.status}: ${l}`)}return t.json()}async function P(n,r,t,l){if(n)return n;l||(console.log(o.red(`
|
|
8
8
|
Job ID or --project is required`)),console.log(o.gray(" Usage: zibby logs <uuid>")),console.log(o.gray(` zibby logs --workflow ticket-triage --project <id>
|
|
9
9
|
`)),process.exit(1));let c=r.workflow;c||(console.log(o.red(`
|
|
10
10
|
Job ID or --workflow is required`)),console.log(o.gray(" Usage: zibby logs <uuid>")),console.log(o.gray(" zibby logs --workflow ticket-triage --project <id>")),console.log(o.gray(` zibby logs --workflow ticket-triage --all --project <id>
|
|
11
|
-
`)),process.exit(1));let u=new URLSearchParams({workflow:c,limit:"10"}),{jobs:
|
|
11
|
+
`)),process.exit(1));let u=new URLSearchParams({workflow:c,limit:"10"}),{jobs:a}=await S(`${$}/jobs/${l}?${u}`,t);(!a||a.length===0)&&(console.log(o.yellow(`
|
|
12
12
|
No jobs found for workflow "${c}".`)),process.exit(0)),console.log(o.gray(`
|
|
13
13
|
Recent runs for ${o.cyan(c)}:
|
|
14
|
-
`));for(let m of
|
|
15
|
-
Tailing latest: ${o.cyan(
|
|
16
|
-
`)),
|
|
17
|
-
`));let u=new Set,
|
|
14
|
+
`));for(let m of a.slice(0,5))console.log(o.gray(` ${h(m.jobId)} ${C(m.status)} ${m.createdAt||""}`));let i=a[0];return console.log(o.gray(`
|
|
15
|
+
Tailing latest: ${o.cyan(h(i.jobId))}
|
|
16
|
+
`)),i.jobId}async function z({token:n,projectId:r,workflowUuid:t,follow:l,limit:c}){console.log(o.gray(` Tailing all executions for workflow ${o.cyan(t)}...`)),console.log(o.gray(" Showing live logs from all runs (interleaved by timestamp).")),console.log(o.gray(` Press Ctrl+C to stop.
|
|
17
|
+
`));let u=new Set,a=new Set,i=null,m=!1,d=0,b=5,w=()=>{m=!0,console.log(o.gray(`
|
|
18
18
|
Stopped tailing.
|
|
19
|
-
`)),process.exit(0)};for(process.on("SIGINT",
|
|
20
|
-
\u26A1 New execution: ${
|
|
21
|
-
`)),
|
|
19
|
+
`)),process.exit(0)};for(process.on("SIGINT",w),process.on("SIGTERM",w);!m;)try{let y=r?`${$}/logs/${r}/${t}`:`${$}/job/${t}`,p=new URLSearchParams({limit:String(c)}),s=await S(`${y}?${p}`,n);if(d=0,s.executions)for(let e of s.executions)a.has(e.jobId)||(a.size>0&&console.log(o.yellow(`
|
|
20
|
+
\u26A1 New execution: ${h(e.jobId)}
|
|
21
|
+
`)),a.add(e.jobId));let g=[];for(let e of s.lines||[]){let f=`${e.jobId}:${e.timestamp}:${e.message}`;u.has(f)||(u.add(f),g.push(e))}g.sort((e,f)=>e.timestamp-f.timestamp);for(let e of g){let f=e.jobId||e.executionId;f!==i&&(i!==null&&console.log(""),console.log(o.dim(` \u2500\u2500 Execution: ${h(f)} \u2500\u2500`)),i=f);let k=o.gray(x(e.timestamp));console.log(`${k} ${e.message.replace(/\n$/,"")}`)}if(!l)break;await new Promise(e=>setTimeout(e,2e3))}catch(y){if(y.name==="AbortError")break;d++,console.error(o.red(` Error: ${y.message}`)),d>=b&&(console.error(o.red(`
|
|
22
|
+
Too many consecutive errors (${b}). Stopping.
|
|
23
|
+
`)),process.exit(1)),l||process.exit(1),await new Promise(p=>setTimeout(p,3e3))}}async function A({token:n,projectId:r,jobId:t,follow:l,limit:c}){let u=r?`${$}/logs/${r}/${t}`:`${$}/job/${t}`,a=null,i=0,m=new Set,d=!1,b=0,w=5,y=()=>{d=!0,console.log(o.gray(`
|
|
22
24
|
Stopped tailing.
|
|
23
|
-
`)),process.exit(0)};for(process.on("SIGINT",
|
|
24
|
-
`):"");!
|
|
25
|
+
`)),process.exit(0)};for(process.on("SIGINT",y),process.on("SIGTERM",y),console.log(o.gray(` Tailing logs for job ${o.cyan(t)}...`)),console.log(l?o.gray(` Press Ctrl+C to stop.
|
|
26
|
+
`):"");!d;)try{let p=new URLSearchParams({limit:String(c)});a&&p.set("nextToken",a);let s=await S(`${u}?${p}`,n);b=0,s.message&&s.lines?.length===0&&i===0&&console.log(o.gray(` ${s.message}`)),s.status==="starting"&&s.lines?.length===0&&i===0&&console.log(o.gray(" Container starting..."));for(let e of s.lines||[]){let f=`${e.timestamp}:${e.message}`;if(m.has(f))continue;m.add(f);let k=o.gray(x(e.timestamp));console.log(`${k} ${e.message.replace(/\n$/,"")}`)}if(i=s.lines?.length>0?0:i+1,a=s.nextForwardToken||null,s.status==="completed"||s.status==="failed"){let e=s.status==="completed"?o.green:o.red;console.log(e(`
|
|
25
27
|
Job ${s.status}.`)),process.exit(s.status==="completed"?0:1)}if(!l){s.status&&console.log(o.gray(`
|
|
26
|
-
Status: ${s.status}`));break}await new Promise(e=>setTimeout(e,
|
|
28
|
+
Status: ${s.status}`));break}await new Promise(e=>setTimeout(e,i>5?5e3:2e3))}catch(p){if(p.name==="AbortError")break;b++,console.error(o.red(` Error: ${p.message}`)),b>=w&&(console.error(o.red(`
|
|
29
|
+
Too many consecutive errors (${w}). Stopping.
|
|
30
|
+
`)),process.exit(1)),l||process.exit(1),await new Promise(s=>setTimeout(s,3e3))}}async function U({token:n,projectId:r,workflow:t,follow:l,limit:c}){let u=`${$}/all/${r}`,a=null,i=0,m=new Set,d=null,b=!1,w=0,y=5,p=()=>{b=!0,console.log(o.gray(`
|
|
27
31
|
Stopped tailing.
|
|
28
32
|
`)),process.exit(0)};for(process.on("SIGINT",p),process.on("SIGTERM",p),console.log(o.gray(`
|
|
29
33
|
Tailing all runs for ${o.cyan(t)}...`)),console.log(l?o.gray(` Press Ctrl+C to stop.
|
|
30
|
-
`):"");!
|
|
31
|
-
... more logs available. Run again or use --follow to stream.`)),g.jobCount&&console.log(o.gray(` ${g.jobCount} job(s) found.`));break}if(!g.hasRunning&&!i
|
|
32
|
-
No running jobs. All caught up.`));break}await new Promise(e=>setTimeout(e,
|
|
34
|
+
`):"");!b;)try{let s=new URLSearchParams({workflow:t,limit:String(c)});a&&s.set("nextToken",a);let g=await S(`${u}?${s}`,n);w=0,g.message&&g.lines?.length===0&&i===0&&console.log(o.gray(` ${g.message}`));for(let e of g.lines||[]){let f=`${e.timestamp}:${e.jobId}:${e.message}`;if(m.has(f))continue;m.add(f),e.jobId!==d&&(d!==null&&console.log(""),console.log(o.dim(` \u2500\u2500 ${h(e.jobId)} \u2500\u2500`)),d=e.jobId);let k=o.gray(x(e.timestamp));console.log(`${k} ${e.message.replace(/\n$/,"")}`)}if(i=g.lines?.length>0?0:i+1,a=g.nextToken||null,!l){a&&console.log(o.gray(`
|
|
35
|
+
... more logs available. Run again or use --follow to stream.`)),g.jobCount&&console.log(o.gray(` ${g.jobCount} job(s) found.`));break}if(!g.hasRunning&&!a&&i>2){console.log(o.gray(`
|
|
36
|
+
No running jobs. All caught up.`));break}await new Promise(e=>setTimeout(e,i>5?5e3:2e3))}catch(s){if(s.name==="AbortError")break;w++,console.error(o.red(` Error: ${s.message}`)),w>=y&&(console.error(o.red(`
|
|
37
|
+
Too many consecutive errors (${y}). Stopping.
|
|
38
|
+
`)),process.exit(1)),l||process.exit(1),await new Promise(g=>setTimeout(g,3e3))}}async function O(n,r){let{token:t,projectId:l}=R(r),c=r.follow!==!1,u=r.lines?parseInt(r.lines,10):500;if(r.all){let i=r.workflow;return i||(console.log(o.red(`
|
|
33
39
|
--workflow is required with --all`)),console.log(o.gray(` Example: zibby logs --workflow ticket-triage --all --project <id>
|
|
34
|
-
`)),process.exit(1)),
|
|
40
|
+
`)),process.exit(1)),U({token:t,projectId:l,workflow:i,follow:c,limit:u})}if(r.tailLatest)return n||(console.log(o.red(`
|
|
35
41
|
Workflow UUID is required with --tail-latest`)),console.log(o.gray(` Example: zibby logs <workflowUuid> -t
|
|
36
|
-
`)),process.exit(1)),z({token:t,projectId:l,workflowUuid:n,follow:c,limit:u});let
|
|
42
|
+
`)),process.exit(1)),z({token:t,projectId:l,workflowUuid:n,follow:c,limit:u});let a=await P(n,r,t,l);return A({token:t,projectId:l,jobId:a,follow:c,limit:u})}export{O as logsCommand};
|
package/dist/package.json
CHANGED