@vcityio/cli 0.3.0 → 0.4.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.
Files changed (3) hide show
  1. package/README.md +7 -3
  2. package/dist/index.js +50 -41
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -88,6 +88,9 @@ Every read command accepts `--json` for scripting. Output auto-falls-back to JSO
88
88
  | `vcity orders get <id> [--org <slug>] [--json]` | Print a single order. |
89
89
  | `vcity quotes list [--org <slug>] [--limit <n>] [--status <s>] [--json]` | List quote requests. |
90
90
  | `vcity quotes get <id> [--org <slug>] [--json]` | Print a single quote. |
91
+ | `vcity quotes create [--name --email --product --quantity --phone --variation --company --note --data]` | Create a quote request. |
92
+ | `vcity quotes update <id> [--status --assignee --name --email --product --quantity --phone --variation --company --note --data]` | Patch quote fields. |
93
+ | `vcity quotes delete <id> [--yes] [--json]` | Delete a quote. Asks y/N unless `--yes`. |
91
94
  | `vcity update [--check] [--yes] [--json]` | Self-update the CLI binary. |
92
95
 
93
96
  ### `--data` flag
@@ -103,9 +106,10 @@ two to start from a template file and override one field per invocation.
103
106
  ### Delete safety
104
107
 
105
108
  Delete commands ask `y/N` before sending the request. Pass `--yes` to skip the
106
- prompt (required in `--json` / non-TTY mode). All deletes are **soft** — the
107
- record stays in the database with `deletedAt` set, and read endpoints filter
108
- it out.
109
+ prompt (required in `--json` / non-TTY mode). `products` / `events` / `rooms`
110
+ deletes are **soft** — the record stays in the database with `deletedAt` set,
111
+ and read endpoints filter it out. `quotes delete` is **permanent** — the
112
+ record is removed outright.
109
113
 
110
114
  ## Environment variables
111
115
 
package/dist/index.js CHANGED
@@ -1,53 +1,57 @@
1
1
  #!/usr/bin/env node
2
- import{createRequire as Bc}from"node:module";var Cc=Bc(import.meta.url);var Hc=/\{[^{}]+\}/g,wc=()=>{return typeof process==="object"&&Number.parseInt(process?.versions?.node?.substring(0,2))>=18&&process.versions.undici};function Uc(){return Math.random().toString(36).slice(2,11)}function Rn(n){let{baseUrl:c="",Request:k=globalThis.Request,fetch:o=globalThis.fetch,querySerializer:D,bodySerializer:g,headers:f,requestInitExt:y=void 0,...$}={...n};y=wc()?y:void 0,c=mn(c);let x=[];async function X(J,j){let{baseUrl:B,fetch:Nn=o,Request:_k=k,headers:Bn,params:q={},parseAs:Mn="json",querySerializer:d,bodySerializer:Cn=g??Lc,body:Hn,...En}=j||{},Yn=c;if(B)Yn=mn(B)??c;let Jn=typeof D==="function"?D:wn(D);if(d)Jn=typeof d==="function"?d:wn({...typeof D==="object"?D:{},...d});let Gn=Hn===void 0?void 0:Cn(Hn,Un(f,Bn,q.header)),Vc=Un(Gn===void 0||Gn instanceof FormData?{}:{"Content-Type":"application/json"},f,Bn,q.header),Nc={redirect:"follow",...$,...En,body:Gn,headers:Vc},u,r,w=new k(Sc(J,{baseUrl:Yn,params:q,querySerializer:Jn}),Nc),W;for(let Q in En)if(!(Q in w))w[Q]=En[Q];if(x.length){u=Uc(),r=Object.freeze({baseUrl:Yn,fetch:Nn,parseAs:Mn,querySerializer:Jn,bodySerializer:Cn});for(let Q of x)if(Q&&typeof Q==="object"&&typeof Q.onRequest==="function"){let Z=await Q.onRequest({request:w,schemaPath:J,params:q,options:r,id:u});if(Z)if(Z instanceof k)w=Z;else if(Z instanceof Response){W=Z;break}else throw Error("onRequest: must return new Request() or Response() when modifying the request")}}if(!W){try{W=await Nn(w,y)}catch(Q){let Z=Q;if(x.length)for(let L=x.length-1;L>=0;L--){let h=x[L];if(h&&typeof h==="object"&&typeof h.onError==="function"){let I=await h.onError({request:w,error:Z,schemaPath:J,params:q,options:r,id:u});if(I){if(I instanceof Response){Z=void 0,W=I;break}if(I instanceof Error){Z=I;continue}throw Error("onError: must return new Response() or instance of Error")}}}if(Z)throw Z}if(x.length)for(let Q=x.length-1;Q>=0;Q--){let Z=x[Q];if(Z&&typeof Z==="object"&&typeof Z.onResponse==="function"){let L=await Z.onResponse({request:w,response:W,schemaPath:J,params:q,options:r,id:u});if(L){if(!(L instanceof Response))throw Error("onResponse: must return new Response() when modifying the response");W=L}}}}if(W.status===204||w.method==="HEAD"||W.headers.get("Content-Length")==="0")return W.ok?{data:void 0,response:W}:{error:void 0,response:W};if(W.ok){if(Mn==="stream")return{data:W.body,response:W};return{data:await W[Mn](),response:W}}let Tn=await W.text();try{Tn=JSON.parse(Tn)}catch{}return{error:Tn,response:W}}return{request(J,j,B){return X(j,{...B,method:J.toUpperCase()})},GET(J,j){return X(J,{...j,method:"GET"})},PUT(J,j){return X(J,{...j,method:"PUT"})},POST(J,j){return X(J,{...j,method:"POST"})},DELETE(J,j){return X(J,{...j,method:"DELETE"})},OPTIONS(J,j){return X(J,{...j,method:"OPTIONS"})},HEAD(J,j){return X(J,{...j,method:"HEAD"})},PATCH(J,j){return X(J,{...j,method:"PATCH"})},TRACE(J,j){return X(J,{...j,method:"TRACE"})},use(...J){for(let j of J){if(!j)continue;if(typeof j!=="object"||!(("onRequest"in j)||("onResponse"in j)||("onError"in j)))throw Error("Middleware must be an object with one of `onRequest()`, `onResponse() or `onError()`");x.push(j)}},eject(...J){for(let j of J){let B=x.indexOf(j);if(B!==-1)x.splice(B,1)}}}}function p(n,c,k){if(c===void 0||c===null)return"";if(typeof c==="object")throw Error("Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.");return`${n}=${k?.allowReserved===!0?c:encodeURIComponent(c)}`}function Ln(n,c,k){if(!c||typeof c!=="object")return"";let o=[],D={simple:",",label:".",matrix:";"}[k.style]||"&";if(k.style!=="deepObject"&&k.explode===!1){for(let y in c)o.push(y,k.allowReserved===!0?c[y]:encodeURIComponent(c[y]));let f=o.join(",");switch(k.style){case"form":return`${n}=${f}`;case"label":return`.${f}`;case"matrix":return`;${n}=${f}`;default:return f}}for(let f in c){let y=k.style==="deepObject"?`${n}[${f}]`:f;o.push(p(y,c[f],k))}let g=o.join(D);return k.style==="label"||k.style==="matrix"?`${D}${g}`:g}function Sn(n,c,k){if(!Array.isArray(c))return"";if(k.explode===!1){let g={form:",",spaceDelimited:"%20",pipeDelimited:"|"}[k.style]||",",f=(k.allowReserved===!0?c:c.map((y)=>encodeURIComponent(y))).join(g);switch(k.style){case"simple":return f;case"label":return`.${f}`;case"matrix":return`;${n}=${f}`;default:return`${n}=${f}`}}let o={simple:",",label:".",matrix:";"}[k.style]||"&",D=[];for(let g of c)if(k.style==="simple"||k.style==="label")D.push(k.allowReserved===!0?g:encodeURIComponent(g));else D.push(p(n,g,k));return k.style==="label"||k.style==="matrix"?`${o}${D.join(o)}`:D.join(o)}function wn(n){return function(k){let o=[];if(k&&typeof k==="object")for(let D in k){let g=k[D];if(g===void 0||g===null)continue;if(Array.isArray(g)){if(g.length===0)continue;o.push(Sn(D,g,{style:"form",explode:!0,...n?.array,allowReserved:n?.allowReserved||!1}));continue}if(typeof g==="object"){o.push(Ln(D,g,{style:"deepObject",explode:!0,...n?.object,allowReserved:n?.allowReserved||!1}));continue}o.push(p(D,g,n))}return o.join("&")}}function mc(n,c){let k=n;for(let o of n.match(Hc)??[]){let D=o.substring(1,o.length-1),g=!1,f="simple";if(D.endsWith("*"))g=!0,D=D.substring(0,D.length-1);if(D.startsWith("."))f="label",D=D.substring(1);else if(D.startsWith(";"))f="matrix",D=D.substring(1);if(!c||c[D]===void 0||c[D]===null)continue;let y=c[D];if(Array.isArray(y)){k=k.replace(o,Sn(D,y,{style:f,explode:g}));continue}if(typeof y==="object"){k=k.replace(o,Ln(D,y,{style:f,explode:g}));continue}if(f==="matrix"){k=k.replace(o,`;${p(D,y)}`);continue}k=k.replace(o,f==="label"?`.${encodeURIComponent(y)}`:encodeURIComponent(y))}return k}function Lc(n,c){if(n instanceof FormData)return n;if(c){if((c.get instanceof Function?c.get("Content-Type")??c.get("content-type"):c["Content-Type"]??c["content-type"])==="application/x-www-form-urlencoded")return new URLSearchParams(n).toString()}return JSON.stringify(n)}function Sc(n,c){let k=`${c.baseUrl}${n}`;if(c.params?.path)k=mc(k,c.params.path);let o=c.querySerializer(c.params.query??{});if(o.startsWith("?"))o=o.substring(1);if(o)k+=`?${o}`;return k}function Un(...n){let c=new Headers;for(let k of n){if(!k||typeof k!=="object")continue;let o=k instanceof Headers?k.entries():Object.entries(k);for(let[D,g]of o)if(g===null)c.delete(D);else if(Array.isArray(g))for(let f of g)c.append(D,f);else if(g!==void 0)c.set(D,g)}return c}function mn(n){if(n.endsWith("/"))return n.substring(0,n.length-1);return n}class A extends Error{status;body;url;constructor(n,c,k,o){super(n);this.name="ApiClientError",this.status=c,this.body=k,this.url=o}}function T(n,c){if(n.error!==void 0&&n.error!==null){let k=n.response?.status??0,o=n.response?.url??"",D=typeof n.error==="object"&&n.error!==null&&"error"in n.error&&typeof n.error.error==="object"&&n.error.error?.message||`${c} failed (${k})`;throw new A(String(D),k,n.error,o)}if(n.data===void 0)throw new A(`${c}: empty response body`,n.response?.status??0,void 0,n.response?.url??"");return n.data}class s{client;constructor(n){this.client=n}async get(){let n=await this.client.GET("/api/v1/me",{});return T(n,"me.get")}}class e{client;constructor(n){this.client=n}async get(n){let c=await this.client.GET("/api/v1/orgs/{orgId}",{params:{path:{orgId:n}}});return T(c,"orgs.get")}async listMembers(n,c={}){let k=await this.client.GET("/api/v1/orgs/{orgId}/members",{params:{path:{orgId:n},query:c}});return T(k,"orgs.listMembers")}}class l{client;constructor(n){this.client=n}async list(n,c={}){let k=await this.client.GET("/api/v1/orgs/{orgId}/products",{params:{path:{orgId:n},query:c}});return T(k,"products.list")}async get(n,c){let k=await this.client.GET("/api/v1/orgs/{orgId}/products/{productId}",{params:{path:{orgId:n,productId:c}}});return T(k,"products.get")}async create(n,c){let k=await this.client.POST("/api/v1/orgs/{orgId}/products",{params:{path:{orgId:n}},body:c});return T(k,"products.create")}async update(n,c,k){let o=await this.client.PUT("/api/v1/orgs/{orgId}/products/{productId}",{params:{path:{orgId:n,productId:c}},body:k});return T(o,"products.update")}async delete(n,c){let k=await this.client.DELETE("/api/v1/orgs/{orgId}/products/{productId}",{params:{path:{orgId:n,productId:c}}});return T(k,"products.delete")}}class a{client;constructor(n){this.client=n}async list(n,c={}){let k=await this.client.GET("/api/v1/orgs/{orgId}/events",{params:{path:{orgId:n},query:c}});return T(k,"events.list")}async get(n,c){let k=await this.client.GET("/api/v1/orgs/{orgId}/events/{eventId}",{params:{path:{orgId:n,eventId:c}}});return T(k,"events.get")}async create(n,c){let k=await this.client.POST("/api/v1/orgs/{orgId}/events",{params:{path:{orgId:n}},body:c});return T(k,"events.create")}async update(n,c,k){let o=await this.client.PUT("/api/v1/orgs/{orgId}/events/{eventId}",{params:{path:{orgId:n,eventId:c}},body:k});return T(o,"events.update")}async delete(n,c){let k=await this.client.DELETE("/api/v1/orgs/{orgId}/events/{eventId}",{params:{path:{orgId:n,eventId:c}}});return T(k,"events.delete")}}class nn{client;constructor(n){this.client=n}async list(n,c={}){let k=await this.client.GET("/api/v1/orgs/{orgId}/rooms",{params:{path:{orgId:n},query:c}});return T(k,"rooms.list")}async get(n,c){let k=await this.client.GET("/api/v1/orgs/{orgId}/rooms/{roomId}",{params:{path:{orgId:n,roomId:c}}});return T(k,"rooms.get")}async create(n,c){let k=await this.client.POST("/api/v1/orgs/{orgId}/rooms",{params:{path:{orgId:n}},body:c});return T(k,"rooms.create")}async update(n,c,k){let o=await this.client.PUT("/api/v1/orgs/{orgId}/rooms/{roomId}",{params:{path:{orgId:n,roomId:c}},body:k});return T(o,"rooms.update")}async delete(n,c){let k=await this.client.DELETE("/api/v1/orgs/{orgId}/rooms/{roomId}",{params:{path:{orgId:n,roomId:c}}});return T(k,"rooms.delete")}}class cn{client;constructor(n){this.client=n}async list(n,c={}){let k=await this.client.GET("/api/v1/orgs/{orgId}/bookings",{params:{path:{orgId:n},query:c}});return T(k,"bookings.list")}async get(n,c){let k=await this.client.GET("/api/v1/orgs/{orgId}/bookings/{bookingId}",{params:{path:{orgId:n,bookingId:c}}});return T(k,"bookings.get")}}class kn{client;constructor(n){this.client=n}async list(n,c={}){let k=await this.client.GET("/api/v1/orgs/{orgId}/orders",{params:{path:{orgId:n},query:c}});return T(k,"orders.list")}async get(n,c){let k=await this.client.GET("/api/v1/orgs/{orgId}/orders/{orderId}",{params:{path:{orgId:n,orderId:c}}});return T(k,"orders.get")}}class on{client;constructor(n){this.client=n}async list(n,c={}){let k=await this.client.GET("/api/v1/orgs/{orgId}/quotes",{params:{path:{orgId:n},query:c}});return T(k,"quotes.list")}async get(n,c){let k=await this.client.GET("/api/v1/orgs/{orgId}/quotes/{quoteId}",{params:{path:{orgId:n,quoteId:c}}});return T(k,"quotes.get")}}var qc="https://vcity.io";function Ac(n,c){let k=c??globalThis.fetch;if(!k)throw Error("@vcityio/api-client: no fetch implementation found. Provide options.fetch or run on Node >=20 / a browser.");return async function(D){if(!n)return k(D);if(D.headers.has("Authorization"))return k(D);let g=new Headers(D.headers);g.set("Authorization",`Bearer ${n}`);let f=new Request(D,{headers:g});return k(f)}}class Wn{raw;me;orgs;products;events;rooms;bookings;orders;quotes;constructor(n={}){let c=n.baseUrl??qc,k=Ac(n.token,n.fetch),o={baseUrl:c,fetch:k,headers:n.headers};this.raw=Rn(o),this.me=new s(this.raw),this.orgs=new e(this.raw),this.products=new l(this.raw),this.events=new a(this.raw),this.rooms=new nn(this.raw),this.bookings=new cn(this.raw),this.orders=new kn(this.raw),this.quotes=new on(this.raw)}}function _n(n={}){return new Wn(n)}import U from"node:fs";import zc from"node:os";import Xn from"node:path";function C(){if(process.env.VCITY_CONFIG_DIR)return process.env.VCITY_CONFIG_DIR;return Xn.join(zc.homedir(),".vcity")}function Dn(){return Xn.join(C(),"auth.json")}function Zn(){return Xn.join(C(),"config.json")}function qn(){return process.env.VCITY_API_BASE_URL||process.env.VCITY_PUBLIC_URL||"https://vcity.io"}function Oc(){let n=C();if(!U.existsSync(n))U.mkdirSync(n,{recursive:!0,mode:448})}function gn(){let n=Dn();if(!U.existsSync(n))return;try{return JSON.parse(U.readFileSync(n,"utf-8"))}catch{return}}function fn(n){Oc();let c=Dn();U.writeFileSync(c,JSON.stringify(n,null,2),{mode:384});try{U.chmodSync(c,384)}catch{}}function z(){let n=Dn();if(U.existsSync(n))U.rmSync(n)}function yn(){let n=gn();if(!n)throw Error("Not logged in. Run `vcity login` first.");return n}class t extends Error{status;body;constructor(n,c,k){super(k??`HTTP ${n}`);this.status=n;this.body=c;this.name="ApiError"}}function zn(n,c,k){let o=new URL(c.startsWith("/")?c:`/${c}`,n);if(k){for(let[D,g]of Object.entries(k))if(g!==void 0&&g!==null&&!Number.isNaN(g))o.searchParams.set(D,String(g))}return o.toString()}async function An(n){try{let c=await fetch(zn(n.api_base_url,"/api/cli/auth/refresh"),{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({refresh_token:n.refresh_token})});if(!c.ok)return;let k=await c.json(),o={...n,access_token:k.access_token,refresh_token:k.refresh_token,access_expires_at:k.access_expires_at,refresh_expires_at:k.refresh_expires_at};return fn(o),o}catch{return}}async function v(n,c={}){let{authed:k=!0,method:o="GET",body:D,query:g,baseUrl:f}=c,y=k?yn():void 0,$=f??y?.api_base_url??"https://vcity.io",x={"content-type":"application/json"};if(y)x.authorization=`Bearer ${y.access_token}`;let X=await fetch(zn($,n,g),{method:o,headers:x,body:D===void 0?void 0:JSON.stringify(D)}),j=(X.headers.get("content-type")??"").includes("application/json")?await X.json().catch(()=>{return}):await X.text().catch(()=>{return});if(!X.ok){let B=(j&&typeof j==="object"&&"error"in j?String(j.error):void 0)??`Request failed (${X.status})`;throw new t(X.status,j,B)}return j}function Pc(){let n=async(c,k)=>{let o=new Headers(c.headers);o.set("authorization",`Bearer ${k}`);let D=new Request(c,{headers:o});return globalThis.fetch(D)};return async function(k){let o=yn();if(Date.now()>=o.access_expires_at){if(Date.now()>=o.refresh_expires_at)throw z(),new t(401,void 0,"Session expired. Run `vcity login` again.");let f=await An(o);if(!f)throw z(),new t(401,void 0,"Session expired. Run `vcity login` again.");o=f}let D=await n(k,o.access_token);if(D.status!==401)return D;let g=await An(o);if(!g)throw z(),new t(401,void 0,"Session expired. Run `vcity login` again.");return o=g,n(k,o.access_token)}}var $n;function E(){if($n)return $n;let n=yn();return $n=_n({baseUrl:n.api_base_url,fetch:Pc()}),$n}function m(n){if(n==null)return"";return new Date(n).toISOString().replace("T"," ").slice(0,16)}import O from"node:fs";function Fc(){let n=C();if(!O.existsSync(n))O.mkdirSync(n,{recursive:!0,mode:448})}function S(){let n=Zn();if(!O.existsSync(n))return{};try{return JSON.parse(O.readFileSync(n,"utf-8"))}catch{return{}}}function On(n){Fc();let k={...S(),...n},o=Zn();O.writeFileSync(o,JSON.stringify(k,null,2),{mode:384});try{O.chmodSync(o,384)}catch{}return k}function G(n){if(n)return n;let c=S();if(!c.active_org)throw Error("No active org. Run `vcity org use <slug>` or pass --org <slug>.");return c.active_org}var bc=/\x1b(?:\[[0-?]*[ -/]*[@-~]|\][^\x07\x1b]*(?:\x07|\x1b\\)|[P_^X][^\x07\x1b]*(?:\x07|\x1b\\)|[^[\]P_^X])/g,Ic=/[\x00-\x08\x0b-\x1f\x7f]/g;function K(n){return n.replace(bc,"").replace(Ic,"")}function Pn(n){let c;try{c=new URL(n)}catch{throw Error(`Refusing to open malformed URL: ${K(n).slice(0,100)}`)}if(c.protocol==="https:")return c;if(c.protocol==="http:"&&(c.hostname==="localhost"||c.hostname==="127.0.0.1"))return c;throw Error(`Refusing to open URL with unsafe protocol: ${c.protocol}`)}function i(n){if(n)return"json";if(!process.stdout.isTTY)return"json";return"pretty"}function M(n){process.stdout.write(`${JSON.stringify(n,null,2)}
3
- `)}function tc(n,c){if(n.length===0)return"(no rows)";let k=n.map((y)=>c.map(($)=>K($.get(y)??""))),o=c.map((y,$)=>Math.max(y.header.length,...k.map((x)=>x[$].length))),D=o.map((y)=>"-".repeat(y)).join(" "),g=c.map((y,$)=>y.header.padEnd(o[$])).join(" "),f=k.map((y)=>y.map(($,x)=>$.padEnd(o[x])).join(" "));return[g,D,...f].join(`
4
- `)}function V(n,c){process.stdout.write(`${tc(n,c)}
5
- `)}function _(n){for(let[c,k]of Object.entries(n)){if(k===void 0||k===null)continue;let o=typeof k==="object"?JSON.stringify(k):String(k);process.stdout.write(`${c.padEnd(20)} ${K(o)}
6
- `)}}async function Fn(n={}){let c=i(n.json),k=G(n.org),o={};if(n.limit!==void 0)o.limit=n.limit;if(n.status!==void 0)o.status=n.status;let g=await E().bookings.list(k,o),f=g.data??[];if(c==="json"){M({org:k,bookings:f,total:g.total,skip:g.skip,limit:g.limit,hasMore:g.hasMore});return}V(f,[{header:"ID",get:(y)=>y.id},{header:"NAME",get:(y)=>y.name??""},{header:"EMAIL",get:(y)=>y.email??""},{header:"REQUESTED",get:(y)=>m(y.requestedDate)},{header:"STATUS",get:(y)=>y.status??""}])}async function bn(n,c={}){let k=i(c.json),o=G(c.org),g=await E().bookings.get(o,n);if(k==="json"){M(g);return}_(g)}import vc from"node:fs";function H(n){if(n===void 0)return;let c;if(n.startsWith("@")){let k=n.slice(1);if(k.length===0)throw Error("--data: missing file path after `@`");if(!/\.json$/i.test(k))throw Error(`--data: @file path must point to a .json file (got: ${k})`);try{c=vc.readFileSync(k,"utf-8")}catch(o){let D=o instanceof Error?o.message:String(o);throw Error(`--data: could not read ${k}: ${D}`)}}else c=n;try{return JSON.parse(c)}catch(k){let o=k instanceof Error?k.message:String(k);throw Error(`--data: invalid JSON (${o})`)}}import dc from"node:readline";function P(n){let c=dc.createInterface({input:process.stdin,output:process.stdout});return new Promise((k)=>{c.question(`${n} `,(o)=>{c.close();let D=o.trim().toLowerCase();k(D==="y"||D==="yes")})})}async function In(n={}){let c=i(n.json),k=G(n.org),o={};if(n.limit!==void 0)o.limit=n.limit;if(n.status!==void 0)o.status=n.status;let g=await E().events.list(k,o),f=g.data??[];if(c==="json"){M({org:k,events:f,total:g.total,skip:g.skip,limit:g.limit,hasMore:g.hasMore});return}V(f,[{header:"ID",get:(y)=>y.id},{header:"NAME",get:(y)=>y.name??""},{header:"STARTS_AT",get:(y)=>y.startsAt!==void 0?new Date(y.startsAt).toISOString():""},{header:"STATUS",get:(y)=>y.status??""},{header:"CATEGORIES",get:(y)=>(y.categories??[]).join(",")}])}async function tn(n,c={}){let k=i(c.json),o=G(c.org),g=await E().events.get(o,n);if(k==="json"){M(g);return}_(g)}function xn(n,c){if(/^-?\d+$/.test(n)){let o=Number(n);if(Number.isFinite(o))return o}let k=Date.parse(n);if(Number.isFinite(k))return k;throw Error(`${c}: expected ISO 8601 or epoch ms (got: ${n})`)}async function vn(n={}){let c=i(n.json),k=G(n.org),o=H(n.data),D=o&&typeof o==="object"?{...o}:{};if(n.name!==void 0)D.name=n.name;if(n.slug!==void 0)D.slug=n.slug;if(n.startsAt!==void 0)D.startsAt=xn(n.startsAt,"--starts-at");if(n.endsAt!==void 0)D.endsAt=xn(n.endsAt,"--ends-at");if(D.name===void 0)throw Error("events create: --name is required (or supply it via --data)");let f=await E().events.create(k,D);if(c==="json"){M(f);return}process.stdout.write(`Created event:
7
- `),_(f)}async function dn(n,c={}){let k=i(c.json),o=G(c.org),D=H(c.data),g=D&&typeof D==="object"?{...D}:{};if(c.name!==void 0)g.name=c.name;if(c.slug!==void 0)g.slug=c.slug;if(c.status!==void 0)g.status=c.status;if(c.startsAt!==void 0)g.startsAt=xn(c.startsAt,"--starts-at");if(c.endsAt!==void 0)g.endsAt=xn(c.endsAt,"--ends-at");if(Object.keys(g).length===0)throw Error("events update: nothing to update (pass at least one field or --data)");let y=await E().events.update(o,n,g);if(k==="json"){M(y);return}process.stdout.write(`Updated event:
8
- `),_(y)}async function un(n,c={}){let k=i(c.json),o=G(c.org);if(!c.yes){if(k==="json")throw Error("events delete: --yes is required in JSON / non-interactive mode");if(!await P(`Delete event ${n} in org ${o}? [y/N]`)){process.stdout.write(`Aborted.
9
- `);return}}let g=await E().events.delete(o,n);if(k==="json"){M(g);return}process.stdout.write(`Deleted event ${n}.
10
- `)}import{setTimeout as uc}from"node:timers/promises";var rn=1;function rc(n){if(n===!1)return!1;if(process.env.VCITY_NO_OPEN_BROWSER)return!1;if(!process.stdout.isTTY)return!1;return!0}async function hc(n){try{let c=(await import("open")).default;await c(n)}catch{}}function pc(n){let c;try{c=new URL(n)}catch{throw Error(`Invalid --api-base-url: ${n.slice(0,200)}`)}if(c.protocol==="https:")return c;if(c.protocol==="http:"&&(c.hostname==="localhost"||c.hostname==="127.0.0.1"))return c;throw Error(`--api-base-url must use https:// (got: ${c.protocol}//${c.hostname}).`)}async function hn(n={}){let c=n.apiBaseUrl??qn(),k=pc(c),o=await v("/api/cli/auth/device/code",{method:"POST",body:{},authed:!1,baseUrl:k.toString()}),D=new URL("/cli-auth",k),g=new URL(D);if(g.searchParams.set("user_code",o.user_code),process.stdout.write(`
2
+ import{createRequire as dc}from"node:module";var Lc=dc(import.meta.url);var Ac=/\{[^{}]+\}/g,zc=()=>{return typeof process==="object"&&Number.parseInt(process?.versions?.node?.substring(0,2))>=18&&process.versions.undici};function Pc(){return Math.random().toString(36).slice(2,11)}function tn(n){let{baseUrl:c="",Request:o=globalThis.Request,fetch:i=globalThis.fetch,querySerializer:k,bodySerializer:y,headers:f,requestInitExt:D=void 0,...j}={...n};D=zc()?D:void 0,c=Cn(c);let $=[];async function Z(T,E){let{baseUrl:q,fetch:Vn=i,Request:qo=o,headers:qn,params:z={},parseAs:Gn="json",querySerializer:I,bodySerializer:Nn=y??bc,body:Bn,...Tn}=E||{},Yn=c;if(q)Yn=Cn(q)??c;let Wn=typeof k==="function"?k:Hn(k);if(I)Wn=typeof I==="function"?I:Hn({...typeof k==="object"?k:{},...I});let Xn=Bn===void 0?void 0:Nn(Bn,Un(f,qn,z.header)),Uc=Un(Xn===void 0||Xn instanceof FormData?{}:{"Content-Type":"application/json"},f,qn,z.header),Cc={redirect:"follow",...j,...Tn,body:Xn,headers:Uc},h,e,B=new o(Oc(T,{baseUrl:Yn,params:z,querySerializer:Wn}),Cc),X;for(let R in Tn)if(!(R in B))B[R]=Tn[R];if($.length){h=Pc(),e=Object.freeze({baseUrl:Yn,fetch:Vn,parseAs:Gn,querySerializer:Wn,bodySerializer:Nn});for(let R of $)if(R&&typeof R==="object"&&typeof R.onRequest==="function"){let t=await R.onRequest({request:B,schemaPath:T,params:z,options:e,id:h});if(t)if(t instanceof o)B=t;else if(t instanceof Response){X=t;break}else throw Error("onRequest: must return new Request() or Response() when modifying the request")}}if(!X){try{X=await Vn(B,D)}catch(R){let t=R;if($.length)for(let d=$.length-1;d>=0;d--){let p=$[d];if(p&&typeof p==="object"&&typeof p.onError==="function"){let u=await p.onError({request:B,error:t,schemaPath:T,params:z,options:e,id:h});if(u){if(u instanceof Response){t=void 0,X=u;break}if(u instanceof Error){t=u;continue}throw Error("onError: must return new Response() or instance of Error")}}}if(t)throw t}if($.length)for(let R=$.length-1;R>=0;R--){let t=$[R];if(t&&typeof t==="object"&&typeof t.onResponse==="function"){let d=await t.onResponse({request:B,response:X,schemaPath:T,params:z,options:e,id:h});if(d){if(!(d instanceof Response))throw Error("onResponse: must return new Response() when modifying the response");X=d}}}}if(X.status===204||B.method==="HEAD"||X.headers.get("Content-Length")==="0")return X.ok?{data:void 0,response:X}:{error:void 0,response:X};if(X.ok){if(Gn==="stream")return{data:X.body,response:X};return{data:await X[Gn](),response:X}}let Zn=await X.text();try{Zn=JSON.parse(Zn)}catch{}return{error:Zn,response:X}}return{request(T,E,q){return Z(E,{...q,method:T.toUpperCase()})},GET(T,E){return Z(T,{...E,method:"GET"})},PUT(T,E){return Z(T,{...E,method:"PUT"})},POST(T,E){return Z(T,{...E,method:"POST"})},DELETE(T,E){return Z(T,{...E,method:"DELETE"})},OPTIONS(T,E){return Z(T,{...E,method:"OPTIONS"})},HEAD(T,E){return Z(T,{...E,method:"HEAD"})},PATCH(T,E){return Z(T,{...E,method:"PATCH"})},TRACE(T,E){return Z(T,{...E,method:"TRACE"})},use(...T){for(let E of T){if(!E)continue;if(typeof E!=="object"||!(("onRequest"in E)||("onResponse"in E)||("onError"in E)))throw Error("Middleware must be an object with one of `onRequest()`, `onResponse() or `onError()`");$.push(E)}},eject(...T){for(let E of T){let q=$.indexOf(E);if(q!==-1)$.splice(q,1)}}}}function s(n,c,o){if(c===void 0||c===null)return"";if(typeof c==="object")throw Error("Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.");return`${n}=${o?.allowReserved===!0?c:encodeURIComponent(c)}`}function dn(n,c,o){if(!c||typeof c!=="object")return"";let i=[],k={simple:",",label:".",matrix:";"}[o.style]||"&";if(o.style!=="deepObject"&&o.explode===!1){for(let D in c)i.push(D,o.allowReserved===!0?c[D]:encodeURIComponent(c[D]));let f=i.join(",");switch(o.style){case"form":return`${n}=${f}`;case"label":return`.${f}`;case"matrix":return`;${n}=${f}`;default:return f}}for(let f in c){let D=o.style==="deepObject"?`${n}[${f}]`:f;i.push(s(D,c[f],o))}let y=i.join(k);return o.style==="label"||o.style==="matrix"?`${k}${y}`:y}function Ln(n,c,o){if(!Array.isArray(c))return"";if(o.explode===!1){let y={form:",",spaceDelimited:"%20",pipeDelimited:"|"}[o.style]||",",f=(o.allowReserved===!0?c:c.map((D)=>encodeURIComponent(D))).join(y);switch(o.style){case"simple":return f;case"label":return`.${f}`;case"matrix":return`;${n}=${f}`;default:return`${n}=${f}`}}let i={simple:",",label:".",matrix:";"}[o.style]||"&",k=[];for(let y of c)if(o.style==="simple"||o.style==="label")k.push(o.allowReserved===!0?y:encodeURIComponent(y));else k.push(s(n,y,o));return o.style==="label"||o.style==="matrix"?`${i}${k.join(i)}`:k.join(i)}function Hn(n){return function(o){let i=[];if(o&&typeof o==="object")for(let k in o){let y=o[k];if(y===void 0||y===null)continue;if(Array.isArray(y)){if(y.length===0)continue;i.push(Ln(k,y,{style:"form",explode:!0,...n?.array,allowReserved:n?.allowReserved||!1}));continue}if(typeof y==="object"){i.push(dn(k,y,{style:"deepObject",explode:!0,...n?.object,allowReserved:n?.allowReserved||!1}));continue}i.push(s(k,y,n))}return i.join("&")}}function Sc(n,c){let o=n;for(let i of n.match(Ac)??[]){let k=i.substring(1,i.length-1),y=!1,f="simple";if(k.endsWith("*"))y=!0,k=k.substring(0,k.length-1);if(k.startsWith("."))f="label",k=k.substring(1);else if(k.startsWith(";"))f="matrix",k=k.substring(1);if(!c||c[k]===void 0||c[k]===null)continue;let D=c[k];if(Array.isArray(D)){o=o.replace(i,Ln(k,D,{style:f,explode:y}));continue}if(typeof D==="object"){o=o.replace(i,dn(k,D,{style:f,explode:y}));continue}if(f==="matrix"){o=o.replace(i,`;${s(k,D)}`);continue}o=o.replace(i,f==="label"?`.${encodeURIComponent(D)}`:encodeURIComponent(D))}return o}function bc(n,c){if(n instanceof FormData)return n;if(c){if((c.get instanceof Function?c.get("Content-Type")??c.get("content-type"):c["Content-Type"]??c["content-type"])==="application/x-www-form-urlencoded")return new URLSearchParams(n).toString()}return JSON.stringify(n)}function Oc(n,c){let o=`${c.baseUrl}${n}`;if(c.params?.path)o=Sc(o,c.params.path);let i=c.querySerializer(c.params.query??{});if(i.startsWith("?"))i=i.substring(1);if(i)o+=`?${i}`;return o}function Un(...n){let c=new Headers;for(let o of n){if(!o||typeof o!=="object")continue;let i=o instanceof Headers?o.entries():Object.entries(o);for(let[k,y]of i)if(y===null)c.delete(k);else if(Array.isArray(y))for(let f of y)c.append(k,f);else if(y!==void 0)c.set(k,y)}return c}function Cn(n){if(n.endsWith("/"))return n.substring(0,n.length-1);return n}class P extends Error{status;body;url;constructor(n,c,o,i){super(n);this.name="ApiClientError",this.status=c,this.body=o,this.url=i.split("?")[0]}}function Y(n,c){if(n.error!==void 0&&n.error!==null){let o=n.response?.status??0,i=n.response?.url??"",k=typeof n.error==="object"&&n.error!==null&&"error"in n.error&&typeof n.error.error==="object"&&n.error.error?.message||`${c} failed (${o})`;throw new P(String(k),o,n.error,i)}if(n.data===void 0)throw new P(`${c}: empty response body`,n.response?.status??0,void 0,n.response?.url??"");return n.data}class a{client;constructor(n){this.client=n}async get(){let n=await this.client.GET("/api/v1/me",{});return Y(n,"me.get")}}class l{client;constructor(n){this.client=n}async get(n){let c=await this.client.GET("/api/v1/orgs/{orgId}",{params:{path:{orgId:n}}});return Y(c,"orgs.get")}async listMembers(n,c={}){let o=await this.client.GET("/api/v1/orgs/{orgId}/members",{params:{path:{orgId:n},query:c}});return Y(o,"orgs.listMembers")}}class nn{client;constructor(n){this.client=n}async list(n,c={}){let o=await this.client.GET("/api/v1/orgs/{orgId}/products",{params:{path:{orgId:n},query:c}});return Y(o,"products.list")}async get(n,c){let o=await this.client.GET("/api/v1/orgs/{orgId}/products/{productId}",{params:{path:{orgId:n,productId:c}}});return Y(o,"products.get")}async create(n,c){let o=await this.client.POST("/api/v1/orgs/{orgId}/products",{params:{path:{orgId:n}},body:c});return Y(o,"products.create")}async update(n,c,o){let i=await this.client.PUT("/api/v1/orgs/{orgId}/products/{productId}",{params:{path:{orgId:n,productId:c}},body:o});return Y(i,"products.update")}async delete(n,c){let o=await this.client.DELETE("/api/v1/orgs/{orgId}/products/{productId}",{params:{path:{orgId:n,productId:c}}});return Y(o,"products.delete")}}class cn{client;constructor(n){this.client=n}async list(n,c={}){let o=await this.client.GET("/api/v1/orgs/{orgId}/events",{params:{path:{orgId:n},query:c}});return Y(o,"events.list")}async get(n,c){let o=await this.client.GET("/api/v1/orgs/{orgId}/events/{eventId}",{params:{path:{orgId:n,eventId:c}}});return Y(o,"events.get")}async create(n,c){let o=await this.client.POST("/api/v1/orgs/{orgId}/events",{params:{path:{orgId:n}},body:c});return Y(o,"events.create")}async update(n,c,o){let i=await this.client.PUT("/api/v1/orgs/{orgId}/events/{eventId}",{params:{path:{orgId:n,eventId:c}},body:o});return Y(i,"events.update")}async delete(n,c){let o=await this.client.DELETE("/api/v1/orgs/{orgId}/events/{eventId}",{params:{path:{orgId:n,eventId:c}}});return Y(o,"events.delete")}}class on{client;constructor(n){this.client=n}async list(n,c={}){let o=await this.client.GET("/api/v1/orgs/{orgId}/rooms",{params:{path:{orgId:n},query:c}});return Y(o,"rooms.list")}async get(n,c){let o=await this.client.GET("/api/v1/orgs/{orgId}/rooms/{roomId}",{params:{path:{orgId:n,roomId:c}}});return Y(o,"rooms.get")}async create(n,c){let o=await this.client.POST("/api/v1/orgs/{orgId}/rooms",{params:{path:{orgId:n}},body:c});return Y(o,"rooms.create")}async update(n,c,o){let i=await this.client.PUT("/api/v1/orgs/{orgId}/rooms/{roomId}",{params:{path:{orgId:n,roomId:c}},body:o});return Y(i,"rooms.update")}async delete(n,c){let o=await this.client.DELETE("/api/v1/orgs/{orgId}/rooms/{roomId}",{params:{path:{orgId:n,roomId:c}}});return Y(o,"rooms.delete")}}class kn{client;constructor(n){this.client=n}async list(n,c={}){let o=await this.client.GET("/api/v1/orgs/{orgId}/bookings",{params:{path:{orgId:n},query:c}});return Y(o,"bookings.list")}async get(n,c){let o=await this.client.GET("/api/v1/orgs/{orgId}/bookings/{bookingId}",{params:{path:{orgId:n,bookingId:c}}});return Y(o,"bookings.get")}}class fn{client;constructor(n){this.client=n}async list(n,c={}){let o=await this.client.GET("/api/v1/orgs/{orgId}/orders",{params:{path:{orgId:n},query:c}});return Y(o,"orders.list")}async get(n,c){let o=await this.client.GET("/api/v1/orgs/{orgId}/orders/{orderId}",{params:{path:{orgId:n,orderId:c}}});return Y(o,"orders.get")}}class yn{client;constructor(n){this.client=n}async list(n,c={}){let o=await this.client.GET("/api/v1/orgs/{orgId}/quotes",{params:{path:{orgId:n},query:c}});return Y(o,"quotes.list")}async get(n,c){let o=await this.client.GET("/api/v1/orgs/{orgId}/quotes/{quoteId}",{params:{path:{orgId:n,quoteId:c}}});return Y(o,"quotes.get")}async create(n,c){let o=await this.client.POST("/api/v1/orgs/{orgId}/quotes",{params:{path:{orgId:n}},body:c});return Y(o,"quotes.create")}async update(n,c,o){let i=await this.client.PUT("/api/v1/orgs/{orgId}/quotes/{quoteId}",{params:{path:{orgId:n,quoteId:c}},body:o});return Y(i,"quotes.update")}async delete(n,c){let o=await this.client.DELETE("/api/v1/orgs/{orgId}/quotes/{quoteId}",{params:{path:{orgId:n,quoteId:c}}});return Y(o,"quotes.delete")}}var uc="https://vcity.io";function Fc(n,c){let o=c??globalThis.fetch;if(!o)throw Error("@vcityio/api-client: no fetch implementation found. Provide options.fetch or run on Node >=20 / a browser.");return async function(k){if(!n)return o(k);if(k.headers.has("Authorization"))return o(k);let y=new Headers(k.headers);y.set("Authorization",`Bearer ${n}`);let f=new Request(k,{headers:y});return o(f)}}class wn{raw;me;orgs;products;events;rooms;bookings;orders;quotes;constructor(n={}){let c=n.baseUrl??uc,o=Fc(n.token,n.fetch),i={baseUrl:c,fetch:o,headers:n.headers};this.raw=tn(i),this.me=new a(this.raw),this.orgs=new l(this.raw),this.products=new nn(this.raw),this.events=new cn(this.raw),this.rooms=new on(this.raw),this.bookings=new kn(this.raw),this.orders=new fn(this.raw),this.quotes=new yn(this.raw)}}function Qn(n={}){return new wn(n)}import H from"node:fs";import rc from"node:os";import Dn from"node:path";function N(){if(process.env.VCITY_CONFIG_DIR)return Dn.resolve(process.env.VCITY_CONFIG_DIR);return Dn.join(rc.homedir(),".vcity")}function jn(){return Dn.join(N(),"auth.json")}function Rn(){return Dn.join(N(),"config.json")}function An(){return process.env.VCITY_API_BASE_URL||process.env.VCITY_PUBLIC_URL||"https://vcity.io"}function vc(){let n=N();if(!H.existsSync(n))H.mkdirSync(n,{recursive:!0,mode:448})}function $n(){let n=jn();if(!H.existsSync(n))return;try{return JSON.parse(H.readFileSync(n,"utf-8"))}catch{return}}function mn(n){vc();let c=jn();H.writeFileSync(c,JSON.stringify(n,null,2),{mode:384});try{H.chmodSync(c,384)}catch{}}function S(){let n=jn();if(H.existsSync(n))H.rmSync(n)}function Mn(){let n=$n();if(!n)throw Error("Not logged in. Run `vcity login` first.");return n}class F extends Error{status;body;constructor(n,c,o){super(o??`HTTP ${n}`);this.status=n;this.body=c;this.name="ApiError"}}function bn(n,c,o){let i=new URL(c.startsWith("/")?c:`/${c}`,n);if(o){for(let[k,y]of Object.entries(o))if(y!==void 0&&y!==null&&!Number.isNaN(y))i.searchParams.set(k,String(y))}return i.toString()}var zn=(n)=>typeof n==="string"&&n!=="",Pn=(n)=>typeof n==="number"&&Number.isFinite(n);async function Sn(n){try{let c=await fetch(bn(n.api_base_url,"/api/cli/auth/refresh"),{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({refresh_token:n.refresh_token})});if(!c.ok)return;let o=await c.json();if(!zn(o.access_token)||!zn(o.refresh_token)||!Pn(o.access_expires_at)||!Pn(o.refresh_expires_at)||o.access_expires_at<=Date.now()||o.refresh_expires_at<=Date.now())return;let i={...n,access_token:o.access_token,refresh_token:o.refresh_token,access_expires_at:o.access_expires_at,refresh_expires_at:o.refresh_expires_at};return mn(i),i}catch{return}}async function r(n,c={}){let{authed:o=!0,method:i="GET",body:k,query:y,baseUrl:f}=c,D=o?Mn():void 0,j=f??D?.api_base_url??"https://vcity.io",$={"content-type":"application/json"};if(D)$.authorization=`Bearer ${D.access_token}`;let Z=await fetch(bn(j,n,y),{method:i,headers:$,body:k===void 0?void 0:JSON.stringify(k)}),E=(Z.headers.get("content-type")??"").includes("application/json")?await Z.json().catch(()=>{return}):await Z.text().catch(()=>{return});if(!Z.ok){let q=(E&&typeof E==="object"&&"error"in E?String(E.error):void 0)??`Request failed (${Z.status})`;throw new F(Z.status,E,q)}return E}function Ic(){let n=async(c,o)=>{let i=new Headers(c.headers);i.set("authorization",`Bearer ${o}`);let k=new Request(c,{headers:i});return globalThis.fetch(k)};return async function(o){let i=Mn();if(Date.now()>=i.access_expires_at){if(Date.now()>=i.refresh_expires_at)throw S(),new F(401,void 0,"Session expired. Run `vcity login` again.");let f=await Sn(i);if(!f)throw S(),new F(401,void 0,"Session expired. Run `vcity login` again.");i=f}let k=await n(o,i.access_token);if(k.status!==401)return k;let y=await Sn(i);if(!y)throw S(),new F(401,void 0,"Session expired. Run `vcity login` again.");return i=y,n(o,i.access_token)}}var gn;function x(){if(gn)return gn;let n=Mn();return gn=Qn({baseUrl:n.api_base_url,fetch:Ic()}),gn}function U(n){if(n==null)return"";return new Date(n).toISOString().replace("T"," ").slice(0,16)}import b from"node:fs";function hc(){let n=N();if(!b.existsSync(n))b.mkdirSync(n,{recursive:!0,mode:448})}function L(){let n=Rn();if(!b.existsSync(n))return{};try{return JSON.parse(b.readFileSync(n,"utf-8"))}catch{return{}}}function On(n){hc();let o={...L(),...n},i=Rn();b.writeFileSync(i,JSON.stringify(o,null,2),{mode:384});try{b.chmodSync(i,384)}catch{}return o}function J(n){if(n)return n;let c=L();if(!c.active_org)throw Error("No active org. Run `vcity org use <slug>` or pass --org <slug>.");return c.active_org}var ec=/\x1b(?:\[[0-?]*[ -/]*[@-~]|\][^\x07\x1b]*(?:\x07|\x1b\\)|[P_^X][^\x07\x1b]*(?:\x07|\x1b\\)|[^[\]P_^X])/g,pc=/[\x00-\x08\x0b-\x1f\x7f]/g;function K(n){return n.replace(ec,"").replace(pc,"")}function un(n){let c;try{c=new URL(n)}catch{throw Error(`Refusing to open malformed URL: ${K(n).slice(0,100)}`)}if(c.protocol==="https:")return c;if(c.protocol==="http:"&&(c.hostname==="localhost"||c.hostname==="127.0.0.1"))return c;throw Error(`Refusing to open URL with unsafe protocol: ${c.protocol}`)}function w(n,c){let o=n.trim();if(!o)throw Error(`${c} must not be empty.`);if(/[\x00-\x1f\x7f]/.test(o))throw Error(`${c} must not contain control characters.`);return o}function M(n){if(n)return"json";if(!process.stdout.isTTY)return"json";return"pretty"}function g(n){process.stdout.write(`${JSON.stringify(n,null,2)}
3
+ `)}function sc(n,c){if(n.length===0)return"(no rows)";let o=n.map((D)=>c.map((j)=>K(j.get(D)??""))),i=c.map((D,j)=>Math.max(D.header.length,...o.map(($)=>$[j].length))),k=i.map((D)=>"-".repeat(D)).join(" "),y=c.map((D,j)=>D.header.padEnd(i[j])).join(" "),f=o.map((D)=>D.map((j,$)=>j.padEnd(i[$])).join(" "));return[y,k,...f].join(`
4
+ `)}function Q(n,c){process.stdout.write(`${sc(n,c)}
5
+ `)}function W(n){for(let[c,o]of Object.entries(n)){if(o===void 0||o===null)continue;let i=typeof o==="object"?JSON.stringify(o):String(o);process.stdout.write(`${c.padEnd(20)} ${K(i)}
6
+ `)}}async function Fn(n={}){let c=M(n.json),o=J(n.org),i={};if(n.limit!==void 0)i.limit=n.limit;if(n.status!==void 0)i.status=n.status;let y=await x().bookings.list(o,i),f=y.data??[];if(c==="json"){g({org:o,bookings:f,total:y.total,skip:y.skip,limit:y.limit,hasMore:y.hasMore});return}Q(f,[{header:"ID",get:(D)=>D.id},{header:"NAME",get:(D)=>D.name??""},{header:"EMAIL",get:(D)=>D.email??""},{header:"REQUESTED",get:(D)=>U(D.requestedDate)},{header:"STATUS",get:(D)=>D.status??""}])}async function rn(n,c={}){let o=M(c.json),i=J(c.org),y=await x().bookings.get(i,n);if(o==="json"){g(y);return}W(y)}import ac from"node:fs";function _(n){if(n===void 0)return;let c;if(n.startsWith("@")){let o=n.slice(1);if(o.length===0)throw Error("--data: missing file path after `@`");if(!/\.json$/i.test(o))throw Error(`--data: @file path must point to a .json file (got: ${o})`);try{c=ac.readFileSync(o,"utf-8")}catch(i){let k=i instanceof Error?i.message:String(i);throw Error(`--data: could not read ${o}: ${k}`)}}else c=n;try{return JSON.parse(c)}catch(o){let i=o instanceof Error?o.message:String(o);throw Error(`--data: invalid JSON (${i})`)}}import lc from"node:readline";function C(n){let c=lc.createInterface({input:process.stdin,output:process.stdout});return new Promise((o)=>{c.question(`${n} `,(i)=>{c.close();let k=i.trim().toLowerCase();o(k==="y"||k==="yes")})})}async function vn(n={}){let c=M(n.json),o=J(n.org),i={};if(n.limit!==void 0)i.limit=n.limit;if(n.status!==void 0)i.status=n.status;let y=await x().events.list(o,i),f=y.data??[];if(c==="json"){g({org:o,events:f,total:y.total,skip:y.skip,limit:y.limit,hasMore:y.hasMore});return}Q(f,[{header:"ID",get:(D)=>D.id},{header:"NAME",get:(D)=>D.name??""},{header:"STARTS_AT",get:(D)=>D.startsAt!==void 0?new Date(D.startsAt).toISOString():""},{header:"STATUS",get:(D)=>D.status??""},{header:"CATEGORIES",get:(D)=>(D.categories??[]).join(",")}])}async function In(n,c={}){let o=M(c.json),i=J(c.org),y=await x().events.get(i,n);if(o==="json"){g(y);return}W(y)}function xn(n,c){if(/^-?\d+$/.test(n)){let i=Number(n);if(Number.isFinite(i))return i}let o=Date.parse(n);if(Number.isFinite(o))return o;throw Error(`${c}: expected ISO 8601 or epoch ms (got: ${n})`)}async function hn(n={}){let c=M(n.json),o=J(n.org),i=_(n.data),k=i&&typeof i==="object"?{...i}:{};if(n.name!==void 0)k.name=n.name;if(n.slug!==void 0)k.slug=n.slug;if(n.startsAt!==void 0)k.startsAt=xn(n.startsAt,"--starts-at");if(n.endsAt!==void 0)k.endsAt=xn(n.endsAt,"--ends-at");if(k.name===void 0)throw Error("events create: --name is required (or supply it via --data)");let f=await x().events.create(o,k);if(c==="json"){g(f);return}process.stdout.write(`Created event:
7
+ `),W(f)}async function en(n,c={}){let o=M(c.json),i=J(c.org),k=_(c.data),y=k&&typeof k==="object"?{...k}:{};if(c.name!==void 0)y.name=c.name;if(c.slug!==void 0)y.slug=c.slug;if(c.status!==void 0)y.status=c.status;if(c.startsAt!==void 0)y.startsAt=xn(c.startsAt,"--starts-at");if(c.endsAt!==void 0)y.endsAt=xn(c.endsAt,"--ends-at");if(Object.keys(y).length===0)throw Error("events update: nothing to update (pass at least one field or --data)");let D=await x().events.update(i,n,y);if(o==="json"){g(D);return}process.stdout.write(`Updated event:
8
+ `),W(D)}async function pn(n,c={}){let o=M(c.json),i=J(c.org);if(!c.yes){if(o==="json")throw Error("events delete: --yes is required in JSON / non-interactive mode");if(!await C(`Delete event ${n} in org ${i}? [y/N]`)){process.stdout.write(`Aborted.
9
+ `);return}}let y=await x().events.delete(i,n);if(o==="json"){g(y);return}process.stdout.write(`Deleted event ${n}.
10
+ `)}import{setTimeout as no}from"node:timers/promises";var sn=1;function co(n){if(n===!1)return!1;if(process.env.VCITY_NO_OPEN_BROWSER)return!1;if(!process.stdout.isTTY)return!1;return!0}async function oo(n){try{let c=(await import("open")).default;await c(n)}catch{}}function io(n){let c;try{c=new URL(n)}catch{throw Error(`Invalid --api-base-url: ${n.slice(0,200)}`)}if(c.protocol==="https:")return c;if(c.protocol==="http:"&&(c.hostname==="localhost"||c.hostname==="127.0.0.1"))return c;throw Error(`--api-base-url must use https:// (got: ${c.protocol}//${c.hostname}).`)}async function an(n={}){let c=n.apiBaseUrl??An(),o=io(c),i=await r("/api/cli/auth/device/code",{method:"POST",body:{},authed:!1,baseUrl:o.toString()}),k=new URL("/cli-auth",o),y=new URL(k);if(y.searchParams.set("user_code",i.user_code),process.stdout.write(`
11
11
  Open this URL to approve the session:
12
- ${D.toString()}
12
+ ${k.toString()}
13
13
  `),process.stdout.write(`Enter this code:
14
- ${K(o.user_code)}
14
+ ${K(i.user_code)}
15
15
 
16
16
  `),process.stdout.write(`Waiting for approval…
17
- `),rc(n.openBrowser))await hc(Pn(g.toString()).toString());let f=Date.now()+o.expires_in*1000,y=Math.max(o.interval,rn);while(Date.now()<f){await uc(y*1000);let $=await v("/api/cli/auth/device/token",{method:"POST",body:{device_code:o.device_code},authed:!1,baseUrl:k.toString()}).catch((x)=>{if(x&&typeof x==="object"&&"status"in x&&x.status===400)return x.body;throw x});if(!$)continue;if($.status==="pending"){y=Math.max($.interval,rn);continue}if($.status==="approved"){fn({api_base_url:k.toString(),access_token:$.access_token,refresh_token:$.refresh_token,access_expires_at:$.access_expires_at,refresh_expires_at:$.refresh_expires_at,user:$.user});let x=$.user.email??$.user.name??$.user.id;process.stdout.write(`
18
- Logged in as ${K(x)}.
19
- `);return}throw Error(`Login ${$.status}. Run \`vcity login\` again.`)}throw Error("Login timed out. Run `vcity login` again.")}async function pn(){let n=gn();if(!n){process.stdout.write(`Not logged in.
20
- `);return}try{await v("/api/cli/auth/logout",{method:"POST",body:{refresh_token:n.refresh_token}})}catch{}z(),process.stdout.write(`Logged out.
21
- `)}async function sn(n={}){let c=i(n.json),k=G(n.org),o={};if(n.limit!==void 0)o.limit=n.limit;if(n.status!==void 0)o.status=n.status;let g=await E().orders.list(k,o),f=g.data??[];if(c==="json"){M({org:k,orders:f,total:g.total,skip:g.skip,limit:g.limit,hasMore:g.hasMore});return}V(f,[{header:"ID",get:(y)=>y.id},{header:"STATUS",get:(y)=>y.status??""},{header:"TOTAL",get:(y)=>y.total!==void 0?`${y.total.toLocaleString()} ${y.currencyCode??""}`.trim():""},{header:"CREATED",get:(y)=>m(y.createdAt)}])}async function en(n,c={}){let k=i(c.json),o=G(c.org),g=await E().orders.get(o,n);if(k==="json"){M(g);return}_(g)}async function ln(){let c=await E().me.get();if(c&&typeof c==="object"&&"orgs"in c){let k=c.orgs;return Array.isArray(k)?k:[]}return[]}async function an(n={}){let c=i(n.json),k=await ln(),o=S().active_org;if(c==="json"){M({orgs:k,active_org:o??null});return}V(k,[{header:"*",get:(D)=>D.slug===o?"*":" "},{header:"SLUG",get:(D)=>D.slug},{header:"NAME",get:(D)=>D.name??""},{header:"ID",get:(D)=>D.id}])}async function nc(n){let k=(await ln()).find((o)=>o.slug===n||o.id===n);if(!k)throw Error(`No accessible org matches "${n}". Run \`vcity org list\` to see options.`);On({active_org:k.slug}),process.stdout.write(`Active org set to ${k.slug} (${k.name??k.id}).
22
- `)}async function cc(n={}){let c=i(n.json),k=G(n.org),D=await E().products.list(k,n.limit!==void 0?{limit:n.limit}:{}),g=D.data??[];if(c==="json"){M({org:k,products:g,total:D.total,skip:D.skip,limit:D.limit,hasMore:D.hasMore});return}V(g,[{header:"ID",get:(f)=>f.id},{header:"NAME",get:(f)=>f.name??""},{header:"PRICE",get:(f)=>f.price!==void 0?`${f.price.toLocaleString()} ${f.currencyCode??""}`.trim():""},{header:"SKU",get:(f)=>f.sku??""},{header:"VISIBILITY",get:(f)=>f.visibility??""},{header:"STOCK",get:(f)=>f.availability!==void 0?String(f.availability):""}])}async function kc(n,c={}){let k=i(c.json),o=G(c.org),g=await E().products.get(o,n);if(k==="json"){M(g);return}_(g)}async function oc(n={}){let c=i(n.json),k=G(n.org),o=H(n.data),D=o&&typeof o==="object"?{...o}:{};if(n.name!==void 0)D.name=n.name;if(n.price!==void 0)D.price=n.price;if(n.currency!==void 0)D.currencyCode=n.currency;if(n.sku!==void 0)D.sku=n.sku;if(D.name===void 0)throw Error("products create: --name is required (or supply it via --data)");let f=await E().products.create(k,D);if(c==="json"){M(f);return}process.stdout.write(`Created product:
23
- `),_(f)}async function Dc(n,c={}){let k=i(c.json),o=G(c.org),D=H(c.data),g=D&&typeof D==="object"?{...D}:{};if(c.name!==void 0)g.name=c.name;if(c.price!==void 0)g.price=c.price;if(c.currency!==void 0)g.currencyCode=c.currency;if(c.sku!==void 0)g.sku=c.sku;if(c.visibility!==void 0)g.visibility=c.visibility;if(c.availability!==void 0)g.availability=c.availability;if(Object.keys(g).length===0)throw Error("products update: nothing to update (pass at least one field or --data)");let y=await E().products.update(o,n,g);if(k==="json"){M(y);return}process.stdout.write(`Updated product:
24
- `),_(y)}async function gc(n,c={}){let k=i(c.json),o=G(c.org);if(!c.yes){if(k==="json")throw Error("products delete: --yes is required in JSON / non-interactive mode");if(!await P(`Delete product ${n} in org ${o}? [y/N]`)){process.stdout.write(`Aborted.
25
- `);return}}let g=await E().products.delete(o,n);if(k==="json"){M(g);return}process.stdout.write(`Deleted product ${n}.
26
- `)}var fc=new Set(["PENDING","IN_PROGRESS","SUBMITTED","CANCELED","ORDERED"]);async function yc(n={}){let c=i(n.json),k=G(n.org);if(n.status!==void 0&&!fc.has(n.status))throw Error(`Invalid quote status: ${n.status}. Allowed: ${[...fc].join(", ")}`);let o={};if(n.limit!==void 0)o.limit=n.limit;if(n.status!==void 0)o.status=n.status;let g=await E().quotes.list(k,o),f=g.data??[];if(c==="json"){M({org:k,quotes:f,total:g.total,skip:g.skip,limit:g.limit,hasMore:g.hasMore});return}V(f,[{header:"ID",get:(y)=>y.id},{header:"NAME",get:(y)=>y.name??""},{header:"PRODUCT",get:(y)=>y.productId??""},{header:"QTY",get:(y)=>y.quantity!==void 0?String(y.quantity):""},{header:"STATUS",get:(y)=>y.status??""},{header:"CREATED",get:(y)=>m(y.createdAt)}])}async function $c(n,c={}){let k=i(c.json),o=G(c.org),g=await E().quotes.get(o,n);if(k==="json"){M(g);return}_(g)}async function xc(n={}){let c=i(n.json),k=G(n.org),o={};if(n.limit!==void 0)o.limit=n.limit;let g=await E().rooms.list(k,o),f=g.data??[];if(c==="json"){M({org:k,rooms:f,total:g.total,skip:g.skip,limit:g.limit,hasMore:g.hasMore});return}V(f,[{header:"ID",get:(y)=>y.id},{header:"TITLE",get:(y)=>y.title??""},{header:"DISABLED",get:(y)=>y.disabled?"yes":"no"},{header:"TYPE",get:(y)=>y.type??""}])}async function jc(n,c={}){let k=i(c.json),o=G(c.org),g=await E().rooms.get(o,n);if(k==="json"){M(g);return}_(g)}async function ic(n={}){let c=i(n.json),k=G(n.org),o=H(n.data),D=o&&typeof o==="object"?{...o}:{};if(n.title!==void 0)D.title=n.title;if(n.description!==void 0)D.description=n.description;if(n.type!==void 0)D.type=n.type;if(D.title===void 0)throw Error("rooms create: --title is required (or supply it via --data)");let f=await E().rooms.create(k,D);if(c==="json"){M(f);return}process.stdout.write(`Created room:
27
- `),_(f)}async function Mc(n,c={}){let k=i(c.json),o=G(c.org),D=H(c.data),g=D&&typeof D==="object"?{...D}:{};if(c.title!==void 0)g.title=c.title;if(c.description!==void 0)g.description=c.description;if(c.type!==void 0)g.type=c.type;if(c.disabled!==void 0)g.disabled=c.disabled;if(Object.keys(g).length===0)throw Error("rooms update: nothing to update (pass at least one field or --data)");let y=await E().rooms.update(o,n,g);if(k==="json"){M(y);return}process.stdout.write(`Updated room:
28
- `),_(y)}async function Ec(n,c={}){let k=i(c.json),o=G(c.org);if(!c.yes){if(k==="json")throw Error("rooms delete: --yes is required in JSON / non-interactive mode");if(!await P(`Delete room ${n} in org ${o}? [y/N]`)){process.stdout.write(`Aborted.
29
- `);return}}let g=await E().rooms.delete(o,n);if(k==="json"){M(g);return}process.stdout.write(`Deleted room ${n}.
30
- `)}import{spawn as Gc}from"node:child_process";import{mkdtempSync as ec,rmSync as lc,writeFileSync as ac}from"node:fs";import{tmpdir as nk}from"node:os";import{join as Yc}from"node:path";var Qn={name:"@vcityio/cli",version:"0.3.0",type:"module",description:"vcity command-line interface for org owners",main:"./dist/index.js",bin:{vcity:"./dist/index.js"},files:["dist","README.md","LICENSE"],engines:{node:">=20"},publishConfig:{access:"public"},optionalDependencies:{open:">=7"},keywords:["vcity","cli"],author:"Otherwise SAS",license:"MIT",homepage:"https://vcity.io",bugs:{email:"support@owsas.com"}};var N=Qn.version,F=Qn.name;var jn="https://vcity.io/cli/install.sh";function ck(){return typeof process.versions.bun==="string"?"binary":"npm"}async function kk(){let n=`https://registry.npmjs.org/${F}/latest`,c;try{c=await fetch(n,{headers:{accept:"application/json"}})}catch(o){throw Error("Could not reach the npm registry. Check your internet connection.",{cause:o})}if(!c.ok)throw Error(`Failed to fetch latest version from npm (HTTP ${c.status})`);let k=await c.json();if(!k.version)throw Error("Latest version response from npm is missing the `version` field");return k.version}function Jc(n){let[c,...k]=n.split("-"),[o,D,g]=c.split(".").map((f)=>parseInt(f,10));return{major:Number.isFinite(o)?o:0,minor:Number.isFinite(D)?D:0,patch:Number.isFinite(g)?g:0,prerelease:k.join("-")}}function Kn(n,c){let k=Jc(n),o=Jc(c);if(k.major!==o.major)return k.major-o.major;if(k.minor!==o.minor)return k.minor-o.minor;if(k.patch!==o.patch)return k.patch-o.patch;if(k.prerelease===o.prerelease)return 0;if(k.prerelease==="")return 1;if(o.prerelease==="")return-1;return k.prerelease<o.prerelease?-1:1}function Tc(n,c){return new Promise((k,o)=>{let D=Gc(n,c,{stdio:"inherit",shell:!1});D.on("error",o),D.on("exit",(g)=>k({exitCode:g??1}))})}function ok(n,c=["--version"]){return new Promise((k)=>{let o=Gc(n,c,{stdio:"ignore",shell:!1});o.on("error",()=>k(!1)),o.on("exit",(D)=>k(D===0))})}async function Dk(){let n;try{n=await fetch(jn,{headers:{accept:"text/x-shellscript, text/plain"}})}catch(D){throw Error(`Could not download installer from ${jn}.`,{cause:D})}if(!n.ok)throw Error(`Installer download failed (HTTP ${n.status}).`);let c=await n.text();if(!c.startsWith("#!"))throw Error(`Installer at ${jn} did not return a shell script (missing shebang). Refusing to execute.`);if(c.length>262144)throw Error(`Installer at ${jn} is unexpectedly large (${c.length} bytes). Refusing to execute.`);let k=ec(Yc(nk(),"vcity-install-")),o=Yc(k,"install.sh");ac(o,c,{mode:448});try{return await Tc("bash",[o])}finally{try{lc(k,{recursive:!0,force:!0})}catch{}}}async function Rc(n={}){let c=i(n.json),k=ck(),o=await kk(),D=K(o),f=Kn(N,o)<0;if(c==="json"){if(M({current:N,latest:D,outdated:f,installMethod:k}),n.check||!f)return}else{if(process.stdout.write(`current: ${N}
31
- `),process.stdout.write(`latest: ${D}
17
+ `),co(n.openBrowser))await oo(un(y.toString()).toString());let f=Date.now()+i.expires_in*1000,D=Math.max(i.interval,sn);while(Date.now()<f){await no(D*1000);let j=await r("/api/cli/auth/device/token",{method:"POST",body:{device_code:i.device_code},authed:!1,baseUrl:o.toString()}).catch(($)=>{if($&&typeof $==="object"&&"status"in $&&$.status===400)return $.body;throw $});if(!j)continue;if(j.status==="pending"){D=Math.max(j.interval,sn);continue}if(j.status==="approved"){mn({api_base_url:o.toString(),access_token:j.access_token,refresh_token:j.refresh_token,access_expires_at:j.access_expires_at,refresh_expires_at:j.refresh_expires_at,user:j.user});let $=j.user.email??j.user.name??j.user.id;process.stdout.write(`
18
+ Logged in as ${K($)}.
19
+ `);return}throw Error(`Login ${j.status}. Run \`vcity login\` again.`)}throw Error("Login timed out. Run `vcity login` again.")}async function ln(){let n=$n();if(!n){process.stdout.write(`Not logged in.
20
+ `);return}try{await r("/api/cli/auth/logout",{method:"POST",body:{refresh_token:n.refresh_token}})}catch{}S(),process.stdout.write(`Logged out.
21
+ `)}async function nc(n={}){let c=M(n.json),o=J(n.org),i={};if(n.limit!==void 0)i.limit=n.limit;if(n.status!==void 0)i.status=n.status;let y=await x().orders.list(o,i),f=y.data??[];if(c==="json"){g({org:o,orders:f,total:y.total,skip:y.skip,limit:y.limit,hasMore:y.hasMore});return}Q(f,[{header:"ID",get:(D)=>D.id},{header:"STATUS",get:(D)=>D.status??""},{header:"TOTAL",get:(D)=>D.total!==void 0?`${D.total.toLocaleString()} ${D.currencyCode??""}`.trim():""},{header:"CREATED",get:(D)=>U(D.createdAt)}])}async function cc(n,c={}){let o=M(c.json),i=J(c.org),y=await x().orders.get(i,n);if(o==="json"){g(y);return}W(y)}async function oc(){let c=await x().me.get();if(c&&typeof c==="object"&&"orgs"in c){let o=c.orgs;return Array.isArray(o)?o:[]}return[]}function ko(n){if(!n)return"";let c=[];if(n.admin)c.push("admin");if(n.admins?.create||n.admins?.update||n.admins?.delete)c.push("admins");if(n.products?.create||n.products?.update||n.products?.delete)c.push("products");if(n.orders?.retrieve||n.orders?.update)c.push("orders");if(n.quotes?.retrieve||n.quotes?.update)c.push("quotes");if(n.surveys?.create||n.surveys?.update||n.surveys?.delete||n.surveys?.retrieve)c.push("surveys");return c.join(",")}async function ic(n={}){let c=M(n.json),o=await oc(),i=L().active_org;if(c==="json"){g({orgs:o,active_org:i??null});return}Q(o,[{header:"*",get:(k)=>k.slug===i?"*":" "},{header:"SLUG",get:(k)=>k.slug},{header:"NAME",get:(k)=>k.name??""},{header:"ID",get:(k)=>k.id}])}async function kc(n){let o=(await oc()).find((i)=>i.slug===n||i.id===n);if(!o)throw Error(`No accessible org matches "${n}". Run \`vcity org list\` to see options.`);On({active_org:o.slug}),process.stdout.write(`Active org set to ${o.slug} (${o.name??o.id}).
22
+ `)}async function fc(n={}){let c=M(n.json),o=J(n.org),i={};if(n.limit!==void 0)i.limit=n.limit;let y=await x().orgs.listMembers(o,i),f=y.data??[];if(c==="json"){g({org:o,members:f,total:y.total,skip:y.skip,limit:y.limit,hasMore:y.hasMore});return}Q(f,[{header:"ID",get:(D)=>D.id},{header:"PROFILE_ID",get:(D)=>D.profileId??""},{header:"ACTIVE",get:(D)=>D.active?"yes":"no"},{header:"PERMISSIONS",get:(D)=>ko(D.permissions)}])}async function yc(n,c={}){let o=M(c.json),k=await x().orgs.get(n);if(o==="json"){g(k);return}W(k)}async function Dc(n={}){let c=M(n.json),o=J(n.org),k=await x().products.list(o,n.limit!==void 0?{limit:n.limit}:{}),y=k.data??[];if(c==="json"){g({org:o,products:y,total:k.total,skip:k.skip,limit:k.limit,hasMore:k.hasMore});return}Q(y,[{header:"ID",get:(f)=>f.id},{header:"NAME",get:(f)=>f.name??""},{header:"PRICE",get:(f)=>f.price!==void 0?`${f.price.toLocaleString()} ${f.currencyCode??""}`.trim():""},{header:"SKU",get:(f)=>f.sku??""},{header:"VISIBILITY",get:(f)=>f.visibility??""},{header:"STOCK",get:(f)=>f.availability!==void 0?String(f.availability):""}])}async function jc(n,c={}){let o=M(c.json),i=J(c.org),y=await x().products.get(i,n);if(o==="json"){g(y);return}W(y)}async function $c(n={}){let c=M(n.json),o=J(n.org),i=_(n.data),k=i&&typeof i==="object"?{...i}:{};if(n.name!==void 0)k.name=n.name;if(n.price!==void 0)k.price=n.price;if(n.currency!==void 0)k.currencyCode=n.currency;if(n.sku!==void 0)k.sku=n.sku;if(k.name===void 0)throw Error("products create: --name is required (or supply it via --data)");let f=await x().products.create(o,k);if(c==="json"){g(f);return}process.stdout.write(`Created product:
23
+ `),W(f)}async function mc(n,c={}){let o=M(c.json),i=J(c.org),k=_(c.data),y=k&&typeof k==="object"?{...k}:{};if(c.name!==void 0)y.name=c.name;if(c.price!==void 0)y.price=c.price;if(c.currency!==void 0)y.currencyCode=c.currency;if(c.sku!==void 0)y.sku=c.sku;if(c.visibility!==void 0)y.visibility=c.visibility;if(c.availability!==void 0)y.availability=c.availability;if(Object.keys(y).length===0)throw Error("products update: nothing to update (pass at least one field or --data)");let D=await x().products.update(i,n,y);if(o==="json"){g(D);return}process.stdout.write(`Updated product:
24
+ `),W(D)}async function Mc(n,c={}){let o=M(c.json),i=J(c.org);if(!c.yes){if(o==="json")throw Error("products delete: --yes is required in JSON / non-interactive mode");if(!await C(`Delete product ${n} in org ${i}? [y/N]`)){process.stdout.write(`Aborted.
25
+ `);return}}let y=await x().products.delete(i,n);if(o==="json"){g(y);return}process.stdout.write(`Deleted product ${n}.
26
+ `)}var En=new Set(["PENDING","IN_PROGRESS","SUBMITTED","CANCELED","ORDERED"]);async function gc(n={}){let c=M(n.json),o=J(n.org);if(n.status!==void 0&&!En.has(n.status))throw Error(`Invalid quote status: ${n.status}. Allowed: ${[...En].join(", ")}`);let i={};if(n.limit!==void 0)i.limit=n.limit;if(n.status!==void 0)i.status=n.status;let y=await x().quotes.list(o,i),f=y.data??[];if(c==="json"){g({org:o,quotes:f,total:y.total,skip:y.skip,limit:y.limit,hasMore:y.hasMore});return}Q(f,[{header:"ID",get:(D)=>D.id},{header:"NAME",get:(D)=>D.name??""},{header:"PRODUCT",get:(D)=>D.productId??""},{header:"QTY",get:(D)=>D.quantity!==void 0?String(D.quantity):""},{header:"STATUS",get:(D)=>D.status??""},{header:"CREATED",get:(D)=>U(D.createdAt)}])}async function xc(n,c={}){let o=M(c.json),i=J(c.org),y=await x().quotes.get(i,n);if(o==="json"){g(y);return}W(y)}async function Ec(n={}){let c=M(n.json),o=J(n.org),i=_(n.data),k=i&&typeof i==="object"?{...i}:{};if(n.name!==void 0)k.name=n.name;if(n.email!==void 0)k.email=n.email;if(n.product!==void 0)k.productId=n.product;if(n.quantity!==void 0)k.quantity=n.quantity;if(n.phone!==void 0)k.telephone=n.phone;if(n.variation!==void 0)k.selectedVariation=n.variation;if(n.company!==void 0)k.company=n.company;if(n.note!==void 0)k.note=n.note;if(k.name===void 0||k.email===void 0||k.productId===void 0)throw Error("quotes create: --name, --email and --product are required (or supply them via --data)");let f=await x().quotes.create(o,k);if(c==="json"){g(f);return}process.stdout.write(`Created quote:
27
+ `),W(f)}async function Jc(n,c={}){let o=M(c.json),i=J(c.org);if(c.status!==void 0&&!En.has(c.status))throw Error(`Invalid quote status: ${c.status}. Allowed: ${[...En].join(", ")}`);let k=_(c.data),y=k&&typeof k==="object"?{...k}:{};if(c.name!==void 0)y.name=c.name;if(c.email!==void 0)y.email=c.email;if(c.product!==void 0)y.productId=c.product;if(c.quantity!==void 0)y.quantity=c.quantity;if(c.phone!==void 0)y.telephone=c.phone;if(c.variation!==void 0)y.selectedVariation=c.variation;if(c.status!==void 0)y.status=c.status;if(c.company!==void 0)y.company=c.company;if(c.note!==void 0)y.note=c.note;if(c.assignee!==void 0)y.assigneeUid=c.assignee;if(Object.keys(y).length===0)throw Error("quotes update: nothing to update (pass at least one field or --data)");let D=await x().quotes.update(i,n,y);if(o==="json"){g(D);return}process.stdout.write(`Updated quote:
28
+ `),W(D)}async function Gc(n,c={}){let o=M(c.json),i=J(c.org);if(!c.yes){if(o==="json")throw Error("quotes delete: --yes is required in JSON / non-interactive mode");if(!await C(`Delete quote ${n} in org ${i}? [y/N]`)){process.stdout.write(`Aborted.
29
+ `);return}}let y=await x().quotes.delete(i,n);if(o==="json"){g(y);return}process.stdout.write(`Deleted quote ${n}.
30
+ `)}async function Tc(n={}){let c=M(n.json),o=J(n.org),i={};if(n.limit!==void 0)i.limit=n.limit;let y=await x().rooms.list(o,i),f=y.data??[];if(c==="json"){g({org:o,rooms:f,total:y.total,skip:y.skip,limit:y.limit,hasMore:y.hasMore});return}Q(f,[{header:"ID",get:(D)=>D.id},{header:"TITLE",get:(D)=>D.title??""},{header:"DISABLED",get:(D)=>D.disabled?"yes":"no"},{header:"TYPE",get:(D)=>D.type??""}])}async function Yc(n,c={}){let o=M(c.json),i=J(c.org),y=await x().rooms.get(i,n);if(o==="json"){g(y);return}W(y)}async function Wc(n={}){let c=M(n.json),o=J(n.org),i=_(n.data),k=i&&typeof i==="object"?{...i}:{};if(n.title!==void 0)k.title=n.title;if(n.description!==void 0)k.description=n.description;if(n.type!==void 0)k.type=n.type;if(k.title===void 0)throw Error("rooms create: --title is required (or supply it via --data)");let f=await x().rooms.create(o,k);if(c==="json"){g(f);return}process.stdout.write(`Created room:
31
+ `),W(f)}async function Xc(n,c={}){let o=M(c.json),i=J(c.org),k=_(c.data),y=k&&typeof k==="object"?{...k}:{};if(c.title!==void 0)y.title=c.title;if(c.description!==void 0)y.description=c.description;if(c.type!==void 0)y.type=c.type;if(c.disabled!==void 0)y.disabled=c.disabled;if(Object.keys(y).length===0)throw Error("rooms update: nothing to update (pass at least one field or --data)");let D=await x().rooms.update(i,n,y);if(o==="json"){g(D);return}process.stdout.write(`Updated room:
32
+ `),W(D)}async function Zc(n,c={}){let o=M(c.json),i=J(c.org);if(!c.yes){if(o==="json")throw Error("rooms delete: --yes is required in JSON / non-interactive mode");if(!await C(`Delete room ${n} in org ${i}? [y/N]`)){process.stdout.write(`Aborted.
33
+ `);return}}let y=await x().rooms.delete(i,n);if(o==="json"){g(y);return}process.stdout.write(`Deleted room ${n}.
34
+ `)}import{spawn as Qc}from"node:child_process";import{mkdtempSync as yo,rmSync as Do,writeFileSync as jo}from"node:fs";import{tmpdir as $o}from"node:os";import{join as tc}from"node:path";var Kn={name:"@vcityio/cli",version:"0.4.0",type:"module",description:"vcity command-line interface for org owners",main:"./dist/index.js",bin:{vcity:"./dist/index.js"},files:["dist","README.md","LICENSE"],engines:{node:">=20"},publishConfig:{access:"public"},optionalDependencies:{open:">=7"},keywords:["vcity","cli"],author:"Otherwise SAS",license:"MIT",homepage:"https://vcity.io",bugs:{email:"support@owsas.com"}};var V=Kn.version,O=Kn.name;var Jn="https://vcity.io/cli/install.sh";function mo(){return typeof process.versions.bun==="string"?"binary":"npm"}async function Mo(){let n=`https://registry.npmjs.org/${O}/latest`,c;try{c=await fetch(n,{headers:{accept:"application/json"}})}catch(i){throw Error("Could not reach the npm registry. Check your internet connection.",{cause:i})}if(!c.ok)throw Error(`Failed to fetch latest version from npm (HTTP ${c.status})`);let o=await c.json();if(!o.version)throw Error("Latest version response from npm is missing the `version` field");return o.version}function wc(n){let[c,...o]=n.split("-"),[i,k,y]=c.split(".").map((f)=>parseInt(f,10));return{major:Number.isFinite(i)?i:0,minor:Number.isFinite(k)?k:0,patch:Number.isFinite(y)?y:0,prerelease:o.join("-")}}function _n(n,c){let o=wc(n),i=wc(c);if(o.major!==i.major)return o.major-i.major;if(o.minor!==i.minor)return o.minor-i.minor;if(o.patch!==i.patch)return o.patch-i.patch;if(o.prerelease===i.prerelease)return 0;if(o.prerelease==="")return 1;if(i.prerelease==="")return-1;return o.prerelease<i.prerelease?-1:1}function Rc(n,c){return new Promise((o,i)=>{let k=Qc(n,c,{stdio:"inherit",shell:!1});k.on("error",i),k.on("exit",(y)=>o({exitCode:y??1}))})}function go(n,c=["--version"]){return new Promise((o)=>{let i=Qc(n,c,{stdio:"ignore",shell:!1});i.on("error",()=>o(!1)),i.on("exit",(k)=>o(k===0))})}async function xo(){let n;try{n=await fetch(Jn,{headers:{accept:"text/x-shellscript, text/plain"}})}catch(k){throw Error(`Could not download installer from ${Jn}.`,{cause:k})}if(!n.ok)throw Error(`Installer download failed (HTTP ${n.status}).`);let c=await n.text();if(!c.startsWith("#!"))throw Error(`Installer at ${Jn} did not return a shell script (missing shebang). Refusing to execute.`);if(c.length>262144)throw Error(`Installer at ${Jn} is unexpectedly large (${c.length} bytes). Refusing to execute.`);let o=yo(tc($o(),"vcity-install-")),i=tc(o,"install.sh");jo(i,c,{mode:448});try{return await Rc("bash",[i])}finally{try{Do(o,{recursive:!0,force:!0})}catch{}}}async function Kc(n={}){let c=M(n.json),o=mo(),i=await Mo(),k=K(i),f=_n(V,k)<0;if(c==="json"){if(g({current:V,latest:k,outdated:f,installMethod:o}),n.check||!f)return}else{if(process.stdout.write(`current: ${V}
35
+ `),process.stdout.write(`latest: ${k}
32
36
  `),!f){process.stdout.write(`vcity is up to date.
33
- `);return}process.stdout.write(`install: ${k==="binary"?"standalone binary":"npm global"}
37
+ `);return}process.stdout.write(`install: ${o==="binary"?"standalone binary":"npm global"}
34
38
  `)}if(n.check)return;if(!n.yes&&c!=="json"){if(process.stdout.write(`
35
39
  Run with --yes to apply the update, or use the command below:
36
- `),k==="binary")process.stdout.write(` curl -fsSL https://vcity.io/cli/install.sh | bash
37
- `);else process.stdout.write(` npm install -g ${F}@latest
38
- `);return}if(k==="binary"){process.stdout.write(`
40
+ `),o==="binary")process.stdout.write(` curl -fsSL https://vcity.io/cli/install.sh | bash
41
+ `);else process.stdout.write(` npm install -g ${O}@latest
42
+ `);return}if(o==="binary"){process.stdout.write(`
39
43
  Fetching latest binary…
40
- `);let{exitCode:y}=await Dk();if(y!==0)throw Error(`installer exited with code ${y}`)}else{if(!await ok("npm"))throw Error("`npm` is not on PATH. Install Node.js 20+ from https://nodejs.org");process.stdout.write(`
44
+ `);let{exitCode:D}=await xo();if(D!==0)throw Error(`installer exited with code ${D}`)}else{if(!await go("npm"))throw Error("`npm` is not on PATH. Install Node.js 20+ from https://nodejs.org");process.stdout.write(`
41
45
  Installing latest from npm…
42
- `);let{exitCode:y}=await Tc("npm",["install","-g",`${F}@latest`]);if(y!==0)throw Error(`npm install exited with code ${y}`)}process.stdout.write(`
43
- Updated to ${D}. Run \`vcity --version\` to confirm.
44
- `)}function gk(n){if(n&&typeof n==="object"&&"user"in n){let c=n;return{user:c.user,orgs:c.orgs??[]}}throw Error("Logged-in token is an API key, not a CLI user token. `vcity whoami` is only valid for CLI sessions.")}async function Wc(n={}){let c=i(n.json),o=await E().me.get(),{user:D,orgs:g}=gk(o),f=S();if(c==="json"){M({user:D,orgs:g,active_org:f.active_org??null});return}let y=D.email??D.name??D.id;process.stdout.write(`User: ${y}
45
- `),process.stdout.write(`User ID: ${D.id}
46
+ `);let{exitCode:D}=await Rc("npm",["install","-g",`${O}@latest`]);if(D!==0)throw Error(`npm install exited with code ${D}`)}process.stdout.write(`
47
+ Updated to ${k}. Run \`vcity --version\` to confirm.
48
+ `)}function Eo(n){if(n&&typeof n==="object"&&"user"in n){let c=n;return{user:c.user,orgs:c.orgs??[]}}throw Error("Logged-in token is an API key, not a CLI user token. `vcity whoami` is only valid for CLI sessions.")}async function _c(n={}){let c=M(n.json),i=await x().me.get(),{user:k,orgs:y}=Eo(i),f=L();if(c==="json"){g({user:k,orgs:y,active_org:f.active_org??null});return}let D=k.email??k.name??k.id;process.stdout.write(`User: ${D}
49
+ `),process.stdout.write(`User ID: ${k.id}
46
50
  `),process.stdout.write(`Active org: ${f.active_org??"(none — run `vcity org use <slug>`)"}
47
- `)}var fk=new Set(["json","yes","check","no-browser","disabled"]);function _c(n){let c=[],k={};for(let o=0;o<n.length;o++){let D=n[o];if(!D.startsWith("--")){c.push(D);continue}let g=D.indexOf("=");if(g>=0){k[D.slice(2,g)]=D.slice(g+1);continue}let f=D.slice(2),y=n[o+1];if(fk.has(f)||y===void 0||y.startsWith("--"))k[f]=!0;else k[f]=y,o++}return{positional:c,flags:k}}import{mkdirSync as yk,readFileSync as $k,writeFileSync as xk}from"node:fs";import jk from"node:path";var ik=86400000,Mk=1500;function Xc(){return jk.join(C(),"update-check.json")}function Ek(){try{let n=$k(Xc(),"utf8"),c=JSON.parse(n);if(typeof c.latest==="string"&&typeof c.checkedAt==="number")return c;return}catch{return}}function Yk(n){try{yk(C(),{recursive:!0}),xk(Xc(),JSON.stringify(n,null,2),{mode:384})}catch{}}async function Jk(){let n=new AbortController,c=setTimeout(()=>n.abort(),Mk);try{let k=await fetch(`https://registry.npmjs.org/${F}/latest`,{headers:{accept:"application/json"},signal:n.signal});if(!k.ok)return;let o=await k.json();return typeof o.version==="string"?o.version:void 0}catch{return}finally{clearTimeout(c)}}function Zc(n){if(process.env.VCITY_NO_UPDATE_CHECK==="1")return!1;if(!process.stderr.isTTY)return!1;if(n.includes("--json"))return!1;if(n[0]==="update")return!1;return!0}function Qc(){let n=Ek(),c=Date.now();if(n&&c-n.checkedAt<ik)return Promise.resolve(n.latest);return Jk().then((k)=>{if(k)Yk({latest:k,checkedAt:c});return k??n?.latest})}function Kc(n){if(!n)return;if(Kn(N,n)>=0)return;process.stderr.write(`
48
- → vcity ${K(n)} available (you have ${N}). Run \`vcity update\` to upgrade.
49
- `)}function R(n){process.stderr.write(`error: ${K(n)}
50
- `),process.exit(1)}function Gk(){process.stdout.write(`vcity ${N}
51
+ `)}var Jo=new Set(["json","yes","check","no-browser","disabled"]);function Vc(n){let c=[],o={};for(let i=0;i<n.length;i++){let k=n[i];if(!k.startsWith("--")){c.push(k);continue}let y=k.indexOf("=");if(y>=0){o[k.slice(2,y)]=k.slice(y+1);continue}let f=k.slice(2),D=n[i+1];if(Jo.has(f)||D===void 0||D.startsWith("--"))o[f]=!0;else o[f]=D,i++}return{positional:c,flags:o}}import{mkdirSync as Go,readFileSync as To,writeFileSync as Yo}from"node:fs";import Wo from"node:path";var Xo=86400000,Zo=1500;function qc(){return Wo.join(N(),"update-check.json")}function to(){try{let n=To(qc(),"utf8"),c=JSON.parse(n);if(typeof c.latest==="string"&&typeof c.checkedAt==="number")return c;return}catch{return}}function wo(n){try{Go(N(),{recursive:!0}),Yo(qc(),JSON.stringify(n,null,2),{mode:384})}catch{}}async function Qo(){let n=new AbortController,c=setTimeout(()=>n.abort(),Zo);try{let o=await fetch(`https://registry.npmjs.org/${O}/latest`,{headers:{accept:"application/json"},signal:n.signal});if(!o.ok)return;let i=await o.json();return typeof i.version==="string"?i.version:void 0}catch{return}finally{clearTimeout(c)}}function Nc(n){if(process.env.VCITY_NO_UPDATE_CHECK==="1")return!1;if(!process.stderr.isTTY)return!1;if(n.includes("--json"))return!1;if(n[0]==="update")return!1;return!0}function Bc(){let n=to(),c=Date.now();if(n&&c-n.checkedAt<Xo)return Promise.resolve(n.latest);return Qo().then((o)=>{if(o)wo({latest:o,checkedAt:c});return o??n?.latest})}function Hc(n){if(!n)return;if(_n(V,n)>=0)return;process.stderr.write(`
52
+ → vcity ${K(n)} available (you have ${V}). Run \`vcity update\` to upgrade.
53
+ `)}function G(n){process.stderr.write(`error: ${K(n)}
54
+ `),process.exit(1)}function Ro(){process.stdout.write(`vcity ${V}
51
55
 
52
56
  Usage:
53
57
  vcity login [--api-base-url <url>] [--no-browser]
@@ -55,6 +59,8 @@ Usage:
55
59
  vcity whoami [--json]
56
60
  vcity org list [--json]
57
61
  vcity org use <slug>
62
+ vcity org get <id> [--json]
63
+ vcity org members list [--org <slug>] [--limit <n>] [--json]
58
64
  vcity products list [--org <slug>] [--limit <n>] [--json]
59
65
  vcity products get <id> [--org <slug>] [--json]
60
66
  vcity products create [--org <slug>] [--name <s>] [--price <n>] [--currency <c>] [--sku <s>] [--data <json|@file>] [--json]
@@ -76,6 +82,9 @@ Usage:
76
82
  vcity orders get <id> [--org <slug>] [--json]
77
83
  vcity quotes list [--org <slug>] [--limit <n>] [--status PENDING|IN_PROGRESS|SUBMITTED|CANCELED|ORDERED] [--json]
78
84
  vcity quotes get <id> [--org <slug>] [--json]
85
+ vcity quotes create [--org <slug>] [--name <s>] [--email <s>] [--product <id>] [--quantity <n>] [--phone <s>] [--variation <s>] [--company <s>] [--note <s>] [--data <json|@file>] [--json]
86
+ vcity quotes update <id> [--org <slug>] [--status <s>] [--assignee <uid>] [--name <s>] [--email <s>] [--product <id>] [--quantity <n>] [--phone <s>] [--variation <s>] [--company <s>] [--note <s>] [--data <json|@file>] [--json]
87
+ vcity quotes delete <id> [--org <slug>] [--yes] [--json]
79
88
  vcity update [--check] [--yes] [--json]
80
89
 
81
90
  Environment:
@@ -83,6 +92,6 @@ Environment:
83
92
  VCITY_CONFIG_DIR override the config directory (default ~/.vcity)
84
93
  VCITY_NO_OPEN_BROWSER never auto-launch a browser during \`vcity login\`
85
94
  VCITY_NO_UPDATE_CHECK disable the background "new version available" check
86
- `)}function Tk(n){if(typeof n!=="string")return;let c=parseInt(n,10);if(Number.isNaN(c)||c<0)R(`--limit must be a non-negative integer (got: ${n})`);return c}function Vn(n,c){if(n===void 0)return;if(typeof n!=="string")return;let k=Number(n);if(!Number.isFinite(k))R(`${c} must be a number (got: ${n})`);return k}function Y(n,c){return typeof n[c]==="string"?n[c]:void 0}function b(n){return{org:typeof n.org==="string"?n.org:void 0,limit:Tk(n.limit),status:typeof n.status==="string"?n.status:void 0,json:!!n.json}}async function Rk(n){if(n.length===0||n[0]==="--help"||n[0]==="-h"||n[0]==="help"){Gk();return}if(n[0]==="--version"||n[0]==="-v"){process.stdout.write(`${N}
87
- `);return}let[c,k,...o]=n,D=n.slice(1),{positional:g,flags:f}=_c(D),y=g.slice(k&&!k.startsWith("--")?1:0);switch(c){case"login":return hn({apiBaseUrl:typeof f["api-base-url"]==="string"?f["api-base-url"]:void 0,openBrowser:f["no-browser"]===!0?!1:void 0});case"logout":return pn();case"whoami":return Wc({json:!!f.json});case"org":{if(k==="list")return an({json:!!f.json});if(k==="use"){let $=y[0];if(!$)R("usage: vcity org use <slug>");return nc($)}R("usage: vcity org list | vcity org use <slug>")}case"products":{let $=b(f);if(k==="list")return cc({org:$.org,limit:$.limit,json:$.json});if(k==="get"){let x=y[0];if(!x)R("usage: vcity products get <id>");return kc(x,{org:$.org,json:$.json})}if(k==="create")return oc({org:$.org,name:Y(f,"name"),price:Vn(f.price,"--price"),currency:Y(f,"currency"),sku:Y(f,"sku"),data:Y(f,"data"),json:$.json});if(k==="update"){let x=y[0];if(!x)R("usage: vcity products update <id>");return Dc(x,{org:$.org,name:Y(f,"name"),price:Vn(f.price,"--price"),currency:Y(f,"currency"),sku:Y(f,"sku"),visibility:Y(f,"visibility"),availability:Vn(f.availability,"--availability"),data:Y(f,"data"),json:$.json})}if(k==="delete"){let x=y[0];if(!x)R("usage: vcity products delete <id>");return gc(x,{org:$.org,yes:f.yes===!0,json:$.json})}R("usage: vcity products list|get|create|update|delete")}case"events":{let $=b(f);if(k==="list"){let x=$.status;if(x!==void 0&&x!=="active"&&x!=="disabled")R(`invalid --status: ${x}. Allowed: active, disabled`);return In({org:$.org,limit:$.limit,status:x,json:$.json})}if(k==="get"){let x=y[0];if(!x)R("usage: vcity events get <id>");return tn(x,{org:$.org,json:$.json})}if(k==="create")return vn({org:$.org,name:Y(f,"name"),startsAt:Y(f,"starts-at"),endsAt:Y(f,"ends-at"),slug:Y(f,"slug"),data:Y(f,"data"),json:$.json});if(k==="update"){let x=y[0];if(!x)R("usage: vcity events update <id>");return dn(x,{org:$.org,name:Y(f,"name"),startsAt:Y(f,"starts-at"),endsAt:Y(f,"ends-at"),slug:Y(f,"slug"),status:Y(f,"status"),data:Y(f,"data"),json:$.json})}if(k==="delete"){let x=y[0];if(!x)R("usage: vcity events delete <id>");return un(x,{org:$.org,yes:f.yes===!0,json:$.json})}R("usage: vcity events list|get|create|update|delete")}case"rooms":{let $=b(f);if(k==="list")return xc({org:$.org,limit:$.limit,json:$.json});if(k==="get"){let x=y[0];if(!x)R("usage: vcity rooms get <id>");return jc(x,{org:$.org,json:$.json})}if(k==="create")return ic({org:$.org,title:Y(f,"title"),description:Y(f,"description"),type:Y(f,"type"),data:Y(f,"data"),json:$.json});if(k==="update"){let x=y[0];if(!x)R("usage: vcity rooms update <id>");return Mc(x,{org:$.org,title:Y(f,"title"),description:Y(f,"description"),type:Y(f,"type"),disabled:f.disabled===!0?!0:void 0,data:Y(f,"data"),json:$.json})}if(k==="delete"){let x=y[0];if(!x)R("usage: vcity rooms delete <id>");return Ec(x,{org:$.org,yes:f.yes===!0,json:$.json})}R("usage: vcity rooms list|get|create|update|delete")}case"bookings":{let $=b(f);if(k==="list")return Fn($);if(k==="get"){let x=y[0];if(!x)R("usage: vcity bookings get <id>");return bn(x,{org:$.org,json:$.json})}R("usage: vcity bookings list | vcity bookings get <id>")}case"orders":{let $=b(f);if(k==="list")return sn($);if(k==="get"){let x=y[0];if(!x)R("usage: vcity orders get <id>");return en(x,{org:$.org,json:$.json})}R("usage: vcity orders list | vcity orders get <id>")}case"quotes":{let $=b(f);if(k==="list")return yc($);if(k==="get"){let x=y[0];if(!x)R("usage: vcity quotes get <id>");return $c(x,{org:$.org,json:$.json})}R("usage: vcity quotes list | vcity quotes get <id>")}case"update":return Rc({check:f.check===!0,yes:f.yes===!0,json:!!f.json});default:R(`unknown command: ${c}. Run \`vcity --help\`.`)}}async function Wk(){let n=process.argv.slice(2),c=Zc(n)?Qc():void 0;try{await Rk(n)}finally{if(c)Kc(await c)}}Wk().catch((n)=>{let c=n instanceof Error?n.message:String(n);process.stderr.write(`error: ${K(c)}
95
+ `)}function Ko(n){if(typeof n!=="string")return;let c=parseInt(n,10);if(Number.isNaN(c)||c<0)G(`--limit must be a non-negative integer (got: ${n})`);return c}function v(n,c){if(n===void 0)return;if(typeof n!=="string")return;let o=Number(n);if(!Number.isFinite(o))G(`${c} must be a number (got: ${n})`);return o}function m(n,c){return typeof n[c]==="string"?n[c]:void 0}function A(n){return{org:typeof n.org==="string"?n.org:void 0,limit:Ko(n.limit),status:typeof n.status==="string"?n.status:void 0,json:!!n.json}}async function _o(n){if(n.length===0||n[0]==="--help"||n[0]==="-h"||n[0]==="help"){Ro();return}if(n[0]==="--version"||n[0]==="-v"){process.stdout.write(`${V}
96
+ `);return}let[c,o,...i]=n,k=n.slice(1),{positional:y,flags:f}=Vc(k),D=y.slice(o&&!o.startsWith("--")?1:0);switch(c){case"login":return an({apiBaseUrl:typeof f["api-base-url"]==="string"?f["api-base-url"]:void 0,openBrowser:f["no-browser"]===!0?!1:void 0});case"logout":return ln();case"whoami":return _c({json:!!f.json});case"org":{if(o==="list")return ic({json:!!f.json});if(o==="use"){let j=D[0];if(!j)G("usage: vcity org use <slug>");return kc(j)}if(o==="get"){let j=D[0];if(!j)G("usage: vcity org get <id>");return yc(w(j,"org id"))}if(o==="members"){let j=A(f);if(D[0]==="list")return fc({org:j.org,limit:j.limit,json:j.json});G("usage: vcity org members list")}G("usage: vcity org list | vcity org use <slug> | vcity org get <id> | vcity org members list")}case"products":{let j=A(f);if(o==="list")return Dc({org:j.org,limit:j.limit,json:j.json});if(o==="get"){let $=D[0];if(!$)G("usage: vcity products get <id>");return jc(w($,"product id"),{org:j.org,json:j.json})}if(o==="create")return $c({org:j.org,name:m(f,"name"),price:v(f.price,"--price"),currency:m(f,"currency"),sku:m(f,"sku"),data:m(f,"data"),json:j.json});if(o==="update"){let $=D[0];if(!$)G("usage: vcity products update <id>");return mc(w($,"product id"),{org:j.org,name:m(f,"name"),price:v(f.price,"--price"),currency:m(f,"currency"),sku:m(f,"sku"),visibility:m(f,"visibility"),availability:v(f.availability,"--availability"),data:m(f,"data"),json:j.json})}if(o==="delete"){let $=D[0];if(!$)G("usage: vcity products delete <id>");return Mc(w($,"product id"),{org:j.org,yes:f.yes===!0,json:j.json})}G("usage: vcity products list|get|create|update|delete")}case"events":{let j=A(f);if(o==="list"){let $=j.status;if($!==void 0&&$!=="active"&&$!=="disabled")G(`invalid --status: ${$}. Allowed: active, disabled`);return vn({org:j.org,limit:j.limit,status:$,json:j.json})}if(o==="get"){let $=D[0];if(!$)G("usage: vcity events get <id>");return In(w($,"event id"),{org:j.org,json:j.json})}if(o==="create")return hn({org:j.org,name:m(f,"name"),startsAt:m(f,"starts-at"),endsAt:m(f,"ends-at"),slug:m(f,"slug"),data:m(f,"data"),json:j.json});if(o==="update"){let $=D[0];if(!$)G("usage: vcity events update <id>");return en(w($,"event id"),{org:j.org,name:m(f,"name"),startsAt:m(f,"starts-at"),endsAt:m(f,"ends-at"),slug:m(f,"slug"),status:m(f,"status"),data:m(f,"data"),json:j.json})}if(o==="delete"){let $=D[0];if(!$)G("usage: vcity events delete <id>");return pn(w($,"event id"),{org:j.org,yes:f.yes===!0,json:j.json})}G("usage: vcity events list|get|create|update|delete")}case"rooms":{let j=A(f);if(o==="list")return Tc({org:j.org,limit:j.limit,json:j.json});if(o==="get"){let $=D[0];if(!$)G("usage: vcity rooms get <id>");return Yc(w($,"room id"),{org:j.org,json:j.json})}if(o==="create")return Wc({org:j.org,title:m(f,"title"),description:m(f,"description"),type:m(f,"type"),data:m(f,"data"),json:j.json});if(o==="update"){let $=D[0];if(!$)G("usage: vcity rooms update <id>");return Xc(w($,"room id"),{org:j.org,title:m(f,"title"),description:m(f,"description"),type:m(f,"type"),disabled:f.disabled===!0?!0:void 0,data:m(f,"data"),json:j.json})}if(o==="delete"){let $=D[0];if(!$)G("usage: vcity rooms delete <id>");return Zc(w($,"room id"),{org:j.org,yes:f.yes===!0,json:j.json})}G("usage: vcity rooms list|get|create|update|delete")}case"bookings":{let j=A(f);if(o==="list")return Fn(j);if(o==="get"){let $=D[0];if(!$)G("usage: vcity bookings get <id>");return rn(w($,"booking id"),{org:j.org,json:j.json})}G("usage: vcity bookings list | vcity bookings get <id>")}case"orders":{let j=A(f);if(o==="list")return nc(j);if(o==="get"){let $=D[0];if(!$)G("usage: vcity orders get <id>");return cc(w($,"order id"),{org:j.org,json:j.json})}G("usage: vcity orders list | vcity orders get <id>")}case"quotes":{let j=A(f);if(o==="list")return gc(j);if(o==="get"){let $=D[0];if(!$)G("usage: vcity quotes get <id>");return xc(w($,"quote id"),{org:j.org,json:j.json})}if(o==="create")return Ec({org:j.org,name:m(f,"name"),email:m(f,"email"),product:m(f,"product"),quantity:v(f.quantity,"--quantity"),phone:m(f,"phone"),variation:m(f,"variation"),company:m(f,"company"),note:m(f,"note"),data:m(f,"data"),json:j.json});if(o==="update"){let $=D[0];if(!$)G("usage: vcity quotes update <id>");return Jc(w($,"quote id"),{org:j.org,status:m(f,"status"),assignee:m(f,"assignee"),name:m(f,"name"),email:m(f,"email"),product:m(f,"product"),quantity:v(f.quantity,"--quantity"),phone:m(f,"phone"),variation:m(f,"variation"),company:m(f,"company"),note:m(f,"note"),data:m(f,"data"),json:j.json})}if(o==="delete"){let $=D[0];if(!$)G("usage: vcity quotes delete <id>");return Gc(w($,"quote id"),{org:j.org,yes:f.yes===!0,json:j.json})}G("usage: vcity quotes list|get|create|update|delete")}case"update":return Kc({check:f.check===!0,yes:f.yes===!0,json:!!f.json});default:G(`unknown command: ${c}. Run \`vcity --help\`.`)}}async function Vo(){let n=process.argv.slice(2),c=Nc(n)?Bc():void 0;try{await _o(n)}finally{if(c)Hc(await c)}}Vo().catch((n)=>{let c=n instanceof Error?n.message:String(n);process.stderr.write(`error: ${K(c)}
88
97
  `),process.exit(1)});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vcityio/cli",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "type": "module",
5
5
  "description": "vcity command-line interface for org owners",
6
6
  "main": "./dist/index.js",