@zibby/cli 0.6.0 → 0.7.0

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,28 @@
1
+ import e from"chalk";import{readFileSync as y,existsSync as I}from"fs";import{homedir as B}from"os";import{join as v}from"path";var w={local:{name:"Local Development",apiUrl:"http://localhost:3001",accountApiUrl:"http://localhost:3001",frontendUrl:"http://localhost:3000",description:"Local backend running on port 3001"},prod:{name:"Production",apiUrl:process.env.ZIBBY_PROD_API_URL||"https://api-prod.zibby.app",accountApiUrl:process.env.ZIBBY_PROD_ACCOUNT_API_URL||"https://api-prod.zibby.app",frontendUrl:process.env.ZIBBY_PROD_FRONTEND_URL||"https://studio.zibby.dev",description:"Production environment"}};function b(){let o;if(process.env.ZIBBY_API_URL)o=process.env.ZIBBY_API_URL;else{let r=process.env.ZIBBY_ENV||"prod";w[r]?o=w[r].apiUrl:o=w.prod.apiUrl}try{let r=new URL(o);return r.protocol!=="http:"&&r.protocol!=="https:"?(console.error(`\u26A0\uFE0F Invalid API URL protocol: ${r.protocol} (only http/https allowed)`),w.prod.apiUrl):o}catch{return console.error(`\u26A0\uFE0F Invalid API URL: ${o}`),w.prod.apiUrl}}var $=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function h(o){return o?$.test(o)?{ok:!0}:{ok:!1,error:`'${o}' is not a UUID. Cloud workflows are identified by UUID only. Run \`zibby workflow list\` to find yours, or run \`zibby workflow trigger\` with no argument for interactive selection.`}:{ok:!0}}function m(o){if(o)return o;let r=v(B(),".zibby","config.json");if(I(r))try{let i=JSON.parse(y(r,"utf-8"));if(i.sessionToken)return i.sessionToken}catch{}if(process.env.ZIBBY_API_KEY)return process.env.ZIBBY_API_KEY;console.error(e.red(`
2
+ Not authenticated`)),console.error(e.gray(" Run: zibby login")),console.error(e.gray(` OR set ZIBBY_API_KEY env var
3
+ `)),process.exit(1)}async function k(o,r,i,s){let t=await fetch(r,{method:o,headers:{"Content-Type":"application/json",Authorization:`Bearer ${i}`},...s!==void 0?{body:JSON.stringify(s)}:{}}),a=await t.text(),n=null;try{n=a?JSON.parse(a):null}catch{}if(!t.ok){let p=n?.error||n?.message||a||`HTTP ${t.status}`;throw new Error(`API ${o} ${t.status}: ${p}`)}return n}async function _(o,r){let i=b(),s=await fetch(`${i}/projects`,{method:"GET",headers:{"Content-Type":"application/json",Authorization:`Bearer ${r}`}});if(!s.ok)throw new Error(`Failed to list projects (HTTP ${s.status})`);let t=await s.json(),a=t.projects||t||[];for(let n of a){let p=n.projectId||n.id;if(!p)continue;let l=await fetch(`${i}/projects/${p}/workflows`,{method:"GET",headers:{"Content-Type":"application/json",Authorization:`Bearer ${r}`}});if(!l.ok)continue;let c=await l.json(),u=(Array.isArray(c)?c:c.workflows||[]).find(g=>g.uuid===o);if(u)return{projectId:p,workflowType:u.workflowType||u.name}}throw new Error(`Workflow with UUID "${o}" not found. Check: zibby workflow list`)}function A(o,r){return`${String(b()).replace(/\/+$/,"")}/projects/${encodeURIComponent(o)}/workflows/${encodeURIComponent(r)}`}function R(o){return`${String(b()).replace(/\/+$/,"")}/workflows/${encodeURIComponent(o)}`}async function f(o,r,i,{tokenJustGenerated:s=!1}={}){let t=await k("PATCH",o,r,{triggers:i});if(U(t),s){let a=t?.webhookToken;a?(console.log(""),console.log(e.yellow.bold(" \u26A0 Copy this token now \u2014 it will NOT be shown again:")),console.log(` ${e.cyan(a)}`)):console.log(e.gray(`
4
+ (backend did not return a plaintext token)`))}return console.log(""),t}function T(o){if(!o)return null;let r=String(b()),i="";return/-dev\b|\bdev\b|localhost|127\.0\.0\.1/.test(r)?i="-dev":/-staging\b|\bstaging\b/.test(r)&&(i="-staging"),`https://${o}.workflows${i}.zibby.app/trigger`}function U(o){if(!o)return;let r=o?.triggers?.api===!0,i=o?.triggers?.webhook||{},s=i.basic||{},t=i.ip||{},a=i.token||{},n=l=>l?e.green("on"):e.gray("off");console.log(""),console.log(` ${e.bold("Webhook:")} ${n(r)}`);let p=T(o?.subdomain);p&&console.log(` ${e.bold("URL:")} ${e.cyan(p)}`),console.log(` ${e.bold("Basic:")} ${n(s.enabled)}${s.username?e.gray(` (user: ${s.username})`):""}`),console.log(` ${e.bold("IP allow:")} ${n(t.enabled)}${Array.isArray(t.allowList)&&t.allowList.length?e.gray(` [${t.allowList.join(", ")}]`):""}`),console.log(` ${e.bold("Token:")} ${n(a.enabled)}${a.tokenMasked?e.gray(` (${a.tokenMasked})`):""}`)}function P(o){return o?String(o).split(",").map(r=>r.trim()).filter(Boolean):[]}async function Z(o,r,i,s={}){let t=(o||"").toLowerCase(),a=null,n=r;t==="auth"&&(a=(r||"").toLowerCase(),n=i);let p=h(n);p.ok||(console.error(e.red(`
5
+ Error: ${p.error}
6
+ `)),process.exit(1)),n||(console.error(e.red(`
7
+ Workflow UUID required.`)),console.error(e.gray(` Usage: zibby workflow webhook <enable|disable|auth|show> <uuid>
8
+ `)),process.exit(1));let l=m(s.apiKey);try{let c=R(n);if(t==="enable"||t==="disable"){let d=t==="enable";console.log(e.green(`
9
+ \u2714 Webhook ${d?"enabled":"disabled"} for ${n}`)),await f(c,l,{api:d});return}if(t==="show"||t==="get"){let{projectId:d,workflowType:u}=await _(n,l),g=await k("GET",A(d,u),l);console.log(e.bold(`
10
+ Webhook config for ${n}:`)),U(g),console.log("");return}if(t==="auth"){if(a==="basic"){if(s.disable){console.log(e.green(`
11
+ \u2714 Basic auth disabled for ${n}`)),await f(c,l,{webhook:{basic:{enabled:!1}}});return}s.username||(console.error(e.red(`
12
+ --username is required (or pass --disable)
13
+ `)),process.exit(1));let d={enabled:!0,username:s.username};s.password&&(d.password=s.password),console.log(e.green(`
14
+ \u2714 Basic auth enabled for ${n}`)),await f(c,l,{webhook:{basic:d}});return}if(a==="ip"){if(s.disable){console.log(e.green(`
15
+ \u2714 IP allowlist disabled for ${n}`)),await f(c,l,{webhook:{ip:{enabled:!1}}});return}let d=P(s.allow);d.length||(console.error(e.red(`
16
+ --allow <cidr,...> is required (or pass --disable)
17
+ `)),process.exit(1)),console.log(e.green(`
18
+ \u2714 IP allowlist set for ${n}`)),await f(c,l,{webhook:{ip:{enabled:!0,allowList:d}}});return}if(a==="token"){if(s.disable){console.log(e.green(`
19
+ \u2714 Token auth disabled for ${n}`)),await f(c,l,{webhook:{token:{enabled:!1}}});return}s.generate||(console.error(e.red(`
20
+ Pass --generate to mint a token (or --disable to turn it off)
21
+ `)),process.exit(1)),console.log(e.green(`
22
+ \u2714 Token generated for ${n}`)),await f(c,l,{webhook:{token:{enabled:!0,generate:!0}}},{tokenJustGenerated:!0});return}console.error(e.red(`
23
+ Unknown auth method: "${r}"`)),console.error(e.gray(` Valid methods: basic | ip | token
24
+ `)),process.exit(1)}console.error(e.red(`
25
+ Unknown action: "${o}"`)),console.error(e.gray(` Valid actions: enable | disable | auth <basic|ip|token> | show
26
+ `)),process.exit(1)}catch(c){console.error(e.red(`
27
+ \u2717 ${c.message}
28
+ `)),process.exit(1)}}export{Z as webhookCommand};
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zibby/cli",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "Zibby CLI - Test automation generator and runner",
5
5
  "type": "module",
6
6
  "bin": {
@@ -40,6 +40,7 @@
40
40
  "@zibby/ui-memory": "^1.0.0",
41
41
  "@zibby/workflow-templates": "^0.3.0",
42
42
  "adm-zip": "^0.5.17",
43
+ "better-sqlite3": "^12.6.2",
43
44
  "chalk": "^5.3.0",
44
45
  "cli-highlight": "^2.1.11",
45
46
  "commander": "^12.0.0",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zibby/cli",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "Zibby CLI - Test automation generator and runner",
5
5
  "type": "module",
6
6
  "bin": {
@@ -40,6 +40,7 @@
40
40
  "@zibby/ui-memory": "^1.0.0",
41
41
  "@zibby/workflow-templates": "^0.3.0",
42
42
  "adm-zip": "^0.5.17",
43
+ "better-sqlite3": "^12.6.2",
43
44
  "chalk": "^5.3.0",
44
45
  "cli-highlight": "^2.1.11",
45
46
  "commander": "^12.0.0",