@vcityio/cli 0.2.4 → 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 +52 -43
  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 Cc}from"node:module";var Hc=Cc(import.meta.url);var Uc=/\{[^{}]+\}/g,wc=()=>{return typeof process==="object"&&Number.parseInt(process?.versions?.node?.substring(0,2))>=18&&process.versions.undici};function Lc(){return Math.random().toString(36).slice(2,11)}function _n(n){let{baseUrl:c="",Request:k=globalThis.Request,fetch:D=globalThis.fetch,querySerializer:g,bodySerializer:$,headers:j,requestInitExt:x=void 0,...y}={...n};x=wc()?x:void 0,c=Ln(c);let M=[];async function R(T,Y){let{baseUrl:C,fetch:Nn=D,Request:Qk=k,headers:Bn,params:z={},parseAs:En="json",querySerializer:u,bodySerializer:Cn=$??qc,body:Hn,...Jn}=Y||{},fn=c;if(C)fn=Ln(C)??c;let Gn=typeof g==="function"?g:Un(g);if(u)Gn=typeof u==="function"?u:Un({...typeof g==="object"?g:{},...u});let Tn=Hn===void 0?void 0:Cn(Hn,wn(j,Bn,z.header)),Nc=wn(Tn===void 0||Tn instanceof FormData?{}:{"Content-Type":"application/json"},j,Bn,z.header),Bc={redirect:"follow",...y,...Jn,body:Tn,headers:Nc},t,r,w=new k(Ac(T,{baseUrl:fn,params:z,querySerializer:Gn}),Bc),Z;for(let K in Jn)if(!(K in w))w[K]=Jn[K];if(M.length){t=Lc(),r=Object.freeze({baseUrl:fn,fetch:Nn,parseAs:En,querySerializer:Gn,bodySerializer:Cn});for(let K of M)if(K&&typeof K==="object"&&typeof K.onRequest==="function"){let o=await K.onRequest({request:w,schemaPath:T,params:z,options:r,id:t});if(o)if(o instanceof k)w=o;else if(o instanceof Response){Z=o;break}else throw Error("onRequest: must return new Request() or Response() when modifying the request")}}if(!Z){try{Z=await Nn(w,x)}catch(K){let o=K;if(M.length)for(let q=M.length-1;q>=0;q--){let h=M[q];if(h&&typeof h==="object"&&typeof h.onError==="function"){let I=await h.onError({request:w,error:o,schemaPath:T,params:z,options:r,id:t});if(I){if(I instanceof Response){o=void 0,Z=I;break}if(I instanceof Error){o=I;continue}throw Error("onError: must return new Response() or instance of Error")}}}if(o)throw o}if(M.length)for(let K=M.length-1;K>=0;K--){let o=M[K];if(o&&typeof o==="object"&&typeof o.onResponse==="function"){let q=await o.onResponse({request:w,response:Z,schemaPath:T,params:z,options:r,id:t});if(q){if(!(q instanceof Response))throw Error("onResponse: must return new Response() when modifying the response");Z=q}}}}if(Z.status===204||w.method==="HEAD"||Z.headers.get("Content-Length")==="0")return Z.ok?{data:void 0,response:Z}:{error:void 0,response:Z};if(Z.ok){if(En==="stream")return{data:Z.body,response:Z};return{data:await Z[En](),response:Z}}let Wn=await Z.text();try{Wn=JSON.parse(Wn)}catch{}return{error:Wn,response:Z}}return{request(T,Y,C){return R(Y,{...C,method:T.toUpperCase()})},GET(T,Y){return R(T,{...Y,method:"GET"})},PUT(T,Y){return R(T,{...Y,method:"PUT"})},POST(T,Y){return R(T,{...Y,method:"POST"})},DELETE(T,Y){return R(T,{...Y,method:"DELETE"})},OPTIONS(T,Y){return R(T,{...Y,method:"OPTIONS"})},HEAD(T,Y){return R(T,{...Y,method:"HEAD"})},PATCH(T,Y){return R(T,{...Y,method:"PATCH"})},TRACE(T,Y){return R(T,{...Y,method:"TRACE"})},use(...T){for(let Y of T){if(!Y)continue;if(typeof Y!=="object"||!(("onRequest"in Y)||("onResponse"in Y)||("onError"in Y)))throw Error("Middleware must be an object with one of `onRequest()`, `onResponse() or `onError()`");M.push(Y)}},eject(...T){for(let Y of T){let C=M.indexOf(Y);if(C!==-1)M.splice(C,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 Sn(n,c,k){if(!c||typeof c!=="object")return"";let D=[],g={simple:",",label:".",matrix:";"}[k.style]||"&";if(k.style!=="deepObject"&&k.explode===!1){for(let x in c)D.push(x,k.allowReserved===!0?c[x]:encodeURIComponent(c[x]));let j=D.join(",");switch(k.style){case"form":return`${n}=${j}`;case"label":return`.${j}`;case"matrix":return`;${n}=${j}`;default:return j}}for(let j in c){let x=k.style==="deepObject"?`${n}[${j}]`:j;D.push(p(x,c[j],k))}let $=D.join(g);return k.style==="label"||k.style==="matrix"?`${g}${$}`:$}function qn(n,c,k){if(!Array.isArray(c))return"";if(k.explode===!1){let $={form:",",spaceDelimited:"%20",pipeDelimited:"|"}[k.style]||",",j=(k.allowReserved===!0?c:c.map((x)=>encodeURIComponent(x))).join($);switch(k.style){case"simple":return j;case"label":return`.${j}`;case"matrix":return`;${n}=${j}`;default:return`${n}=${j}`}}let D={simple:",",label:".",matrix:";"}[k.style]||"&",g=[];for(let $ of c)if(k.style==="simple"||k.style==="label")g.push(k.allowReserved===!0?$:encodeURIComponent($));else g.push(p(n,$,k));return k.style==="label"||k.style==="matrix"?`${D}${g.join(D)}`:g.join(D)}function Un(n){return function(k){let D=[];if(k&&typeof k==="object")for(let g in k){let $=k[g];if($===void 0||$===null)continue;if(Array.isArray($)){if($.length===0)continue;D.push(qn(g,$,{style:"form",explode:!0,...n?.array,allowReserved:n?.allowReserved||!1}));continue}if(typeof $==="object"){D.push(Sn(g,$,{style:"deepObject",explode:!0,...n?.object,allowReserved:n?.allowReserved||!1}));continue}D.push(p(g,$,n))}return D.join("&")}}function Sc(n,c){let k=n;for(let D of n.match(Uc)??[]){let g=D.substring(1,D.length-1),$=!1,j="simple";if(g.endsWith("*"))$=!0,g=g.substring(0,g.length-1);if(g.startsWith("."))j="label",g=g.substring(1);else if(g.startsWith(";"))j="matrix",g=g.substring(1);if(!c||c[g]===void 0||c[g]===null)continue;let x=c[g];if(Array.isArray(x)){k=k.replace(D,qn(g,x,{style:j,explode:$}));continue}if(typeof x==="object"){k=k.replace(D,Sn(g,x,{style:j,explode:$}));continue}if(j==="matrix"){k=k.replace(D,`;${p(g,x)}`);continue}k=k.replace(D,j==="label"?`.${encodeURIComponent(x)}`:encodeURIComponent(x))}return k}function qc(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 Ac(n,c){let k=`${c.baseUrl}${n}`;if(c.params?.path)k=Sc(k,c.params.path);let D=c.querySerializer(c.params.query??{});if(D.startsWith("?"))D=D.substring(1);if(D)k+=`?${D}`;return k}function wn(...n){let c=new Headers;for(let k of n){if(!k||typeof k!=="object")continue;let D=k instanceof Headers?k.entries():Object.entries(k);for(let[g,$]of D)if($===null)c.delete(g);else if(Array.isArray($))for(let j of $)c.append(g,j);else if($!==void 0)c.set(g,$)}return c}function Ln(n){if(n.endsWith("/"))return n.substring(0,n.length-1);return n}class i extends Error{status;body;url;constructor(n,c,k,D){super(n);this.name="ApiClientError",this.status=c,this.body=k,this.url=D}}function _(n,c){if(n.error!==void 0&&n.error!==null){let k=n.response?.status??0,D=n.response?.url??"",g=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 i(String(g),k,n.error,D)}if(n.data===void 0)throw new i(`${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 _(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 _(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 _(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 _(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 _(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 _(k,"products.create")}async update(n,c,k){let D=await this.client.PUT("/api/v1/orgs/{orgId}/products/{productId}",{params:{path:{orgId:n,productId:c}},body:k});return _(D,"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 _(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 _(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 _(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 _(k,"events.create")}async update(n,c,k){let D=await this.client.PUT("/api/v1/orgs/{orgId}/events/{eventId}",{params:{path:{orgId:n,eventId:c}},body:k});return _(D,"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 _(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 _(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 _(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 _(k,"rooms.create")}async update(n,c,k){let D=await this.client.PUT("/api/v1/orgs/{orgId}/rooms/{roomId}",{params:{path:{orgId:n,roomId:c}},body:k});return _(D,"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 _(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 _(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 _(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 _(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 _(k,"orders.get")}}class Dn{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 _(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 _(k,"quotes.get")}}var zc="https://vcity.io";function ic(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(g){if(!n)return k(g);if(g.headers.has("Authorization"))return k(g);let $=new Headers(g.headers);$.set("Authorization",`Bearer ${n}`);let j=new Request(g,{headers:$});return k(j)}}class Xn{raw;me;orgs;products;events;rooms;bookings;orders;quotes;constructor(n={}){let c=n.baseUrl??zc,k=ic(n.token,n.fetch),D={baseUrl:c,fetch:k,headers:n.headers};this.raw=_n(D),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 Dn(this.raw)}}function Zn(n={}){return new Xn(n)}import L from"node:fs";import mc from"node:os";import Qn from"node:path";function H(){if(process.env.VCITY_CONFIG_DIR)return process.env.VCITY_CONFIG_DIR;return Qn.join(mc.homedir(),".vcity")}function gn(){return Qn.join(H(),"auth.json")}function Rn(){return Qn.join(H(),"config.json")}function An(){return process.env.VCITY_API_BASE_URL||process.env.VCITY_PUBLIC_URL||"https://vcity.io"}function Oc(){let n=H();if(!L.existsSync(n))L.mkdirSync(n,{recursive:!0,mode:448})}function $n(){let n=gn();if(!L.existsSync(n))return;try{return JSON.parse(L.readFileSync(n,"utf-8"))}catch{return}}function jn(n){Oc();let c=gn();L.writeFileSync(c,JSON.stringify(n,null,2),{mode:384});try{L.chmodSync(c,384)}catch{}}function m(){let n=gn();if(L.existsSync(n))L.rmSync(n)}function xn(){let n=$n();if(!n)throw Error("Not logged in. Run `vcity login` first.");return n}class v extends Error{status;body;constructor(n,c,k){super(k??`HTTP ${n}`);this.status=n;this.body=c;this.name="ApiError"}}function mn(n,c,k){let D=new URL(c.startsWith("/")?c:`/${c}`,n);if(k){for(let[g,$]of Object.entries(k))if($!==void 0&&$!==null&&!Number.isNaN($))D.searchParams.set(g,String($))}return D.toString()}async function zn(n){try{let c=await fetch(mn(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(),D={...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 jn(D),D}catch{return}}async function d(n,c={}){let{authed:k=!0,method:D="GET",body:g,query:$,baseUrl:j}=c,x=k?xn():void 0,y=j??x?.api_base_url??"https://vcity.io",M={"content-type":"application/json"};if(x)M.authorization=`Bearer ${x.access_token}`;let R=await fetch(mn(y,n,$),{method:D,headers:M,body:g===void 0?void 0:JSON.stringify(g)}),Y=(R.headers.get("content-type")??"").includes("application/json")?await R.json().catch(()=>{return}):await R.text().catch(()=>{return});if(!R.ok){let C=(Y&&typeof Y==="object"&&"error"in Y?String(Y.error):void 0)??`Request failed (${R.status})`;throw new v(R.status,Y,C)}return Y}function Pc(){let n=async(c,k)=>{let D=new Headers(c.headers);D.set("authorization",`Bearer ${k}`);let g=new Request(c,{headers:D});return globalThis.fetch(g)};return async function(k){let D=xn();if(Date.now()>=D.access_expires_at){if(Date.now()>=D.refresh_expires_at)throw m(),new v(401,void 0,"Session expired. Run `vcity login` again.");let j=await zn(D);if(!j)throw m(),new v(401,void 0,"Session expired. Run `vcity login` again.");D=j}let g=await n(k,D.access_token);if(g.status!==401)return g;let $=await zn(D);if(!$)throw m(),new v(401,void 0,"Session expired. Run `vcity login` again.");return D=$,n(k,D.access_token)}}var yn;function f(){if(yn)return yn;let n=xn();return yn=Zn({baseUrl:n.api_base_url,fetch:Pc()}),yn}function S(n){if(n==null)return"";return new Date(n).toISOString().replace("T"," ").slice(0,16)}import O from"node:fs";function Fc(){let n=H();if(!O.existsSync(n))O.mkdirSync(n,{recursive:!0,mode:448})}function A(){let n=Rn();if(!O.existsSync(n))return{};try{return JSON.parse(O.readFileSync(n,"utf-8"))}catch{return{}}}function On(n){Fc();let k={...A(),...n},D=Rn();O.writeFileSync(D,JSON.stringify(k,null,2),{mode:384});try{O.chmodSync(D,384)}catch{}return k}function W(n){if(n)return n;let c=A();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 N(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: ${N(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 E(n){if(n)return"json";if(!process.stdout.isTTY)return"json";return"pretty"}function J(n){process.stdout.write(`${JSON.stringify(n,null,2)}
3
- `)}function vc(n,c){if(n.length===0)return"(no rows)";let k=n.map((x)=>c.map((y)=>N(y.get(x)??""))),D=c.map((x,y)=>Math.max(x.header.length,...k.map((M)=>M[y].length))),g=D.map((x)=>"-".repeat(x)).join(" "),$=c.map((x,y)=>x.header.padEnd(D[y])).join(" "),j=k.map((x)=>x.map((y,M)=>y.padEnd(D[M])).join(" "));return[$,g,...j].join(`
4
- `)}function V(n,c){process.stdout.write(`${vc(n,c)}
5
- `)}function Q(n){for(let[c,k]of Object.entries(n)){if(k===void 0||k===null)continue;let D=typeof k==="object"?JSON.stringify(k):String(k);process.stdout.write(`${c.padEnd(20)} ${N(D)}
6
- `)}}async function Fn(n={}){let c=E(n.json),k=W(n.org),D={};if(n.limit!==void 0)D.limit=n.limit;if(n.status!==void 0)D.status=n.status;let $=await f().bookings.list(k,D),j=$.data??[];if(c==="json"){J({org:k,bookings:j,total:$.total,skip:$.skip,limit:$.limit,hasMore:$.hasMore});return}V(j,[{header:"ID",get:(x)=>x.id},{header:"NAME",get:(x)=>x.name??""},{header:"EMAIL",get:(x)=>x.email??""},{header:"REQUESTED",get:(x)=>S(x.requestedDate)},{header:"STATUS",get:(x)=>x.status??""}])}async function bn(n,c={}){let k=E(c.json),D=W(c.org),$=await f().bookings.get(D,n);if(k==="json"){J($);return}Q($)}import dc from"node:fs";function U(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=dc.readFileSync(k,"utf-8")}catch(D){let g=D instanceof Error?D.message:String(D);throw Error(`--data: could not read ${k}: ${g}`)}}else c=n;try{return JSON.parse(c)}catch(k){let D=k instanceof Error?k.message:String(k);throw Error(`--data: invalid JSON (${D})`)}}import uc from"node:readline";function P(n){let c=uc.createInterface({input:process.stdin,output:process.stdout});return new Promise((k)=>{c.question(`${n} `,(D)=>{c.close();let g=D.trim().toLowerCase();k(g==="y"||g==="yes")})})}async function In(n={}){let c=E(n.json),k=W(n.org),D={};if(n.limit!==void 0)D.limit=n.limit;if(n.status!==void 0)D.status=n.status;let $=await f().events.list(k,D),j=$.data??[];if(c==="json"){J({org:k,events:j,total:$.total,skip:$.skip,limit:$.limit,hasMore:$.hasMore});return}V(j,[{header:"ID",get:(x)=>x.id},{header:"NAME",get:(x)=>x.name??""},{header:"STARTS_AT",get:(x)=>x.startsAt!==void 0?new Date(x.startsAt).toISOString():""},{header:"STATUS",get:(x)=>x.status??""},{header:"CATEGORIES",get:(x)=>(x.categories??[]).join(",")}])}async function vn(n,c={}){let k=E(c.json),D=W(c.org),$=await f().events.get(D,n);if(k==="json"){J($);return}Q($)}function Mn(n,c){if(/^-?\d+$/.test(n)){let D=Number(n);if(Number.isFinite(D))return D}let k=Date.parse(n);if(Number.isFinite(k))return k;throw Error(`${c}: expected ISO 8601 or epoch ms (got: ${n})`)}async function dn(n={}){let c=E(n.json),k=W(n.org),D=U(n.data),g=D&&typeof D==="object"?{...D}:{};if(n.name!==void 0)g.name=n.name;if(n.slug!==void 0)g.slug=n.slug;if(n.startsAt!==void 0)g.startsAt=Mn(n.startsAt,"--starts-at");if(n.endsAt!==void 0)g.endsAt=Mn(n.endsAt,"--ends-at");if(g.name===void 0)throw Error("events create: --name is required (or supply it via --data)");let j=await f().events.create(k,g);if(c==="json"){J(j);return}process.stdout.write(`Created event:
7
- `),Q(j)}async function un(n,c={}){let k=E(c.json),D=W(c.org),g=U(c.data),$=g&&typeof g==="object"?{...g}:{};if(c.name!==void 0)$.name=c.name;if(c.slug!==void 0)$.slug=c.slug;if(c.status!==void 0)$.status=c.status;if(c.startsAt!==void 0)$.startsAt=Mn(c.startsAt,"--starts-at");if(c.endsAt!==void 0)$.endsAt=Mn(c.endsAt,"--ends-at");if(Object.keys($).length===0)throw Error("events update: nothing to update (pass at least one field or --data)");let x=await f().events.update(D,n,$);if(k==="json"){J(x);return}process.stdout.write(`Updated event:
8
- `),Q(x)}async function tn(n,c={}){let k=E(c.json),D=W(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 ${D}? [y/N]`)){process.stdout.write(`Aborted.
9
- `);return}}let $=await f().events.delete(D,n);if(k==="json"){J($);return}process.stdout.write(`Deleted event ${n}.
10
- `)}import{setTimeout as tc}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??An(),k=pc(c),D=await d("/api/cli/auth/device/code",{method:"POST",body:{},authed:!1,baseUrl:k.toString()}),g=new URL("/cli-auth",k),$=new URL(g);if($.searchParams.set("user_code",D.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
- ${g.toString()}
12
+ ${k.toString()}
13
13
  `),process.stdout.write(`Enter this code:
14
- ${N(D.user_code)}
14
+ ${K(i.user_code)}
15
15
 
16
16
  `),process.stdout.write(`Waiting for approval…
17
- `),rc(n.openBrowser))await hc(Pn($.toString()).toString());let j=Date.now()+D.expires_in*1000,x=Math.max(D.interval,rn);while(Date.now()<j){await tc(x*1000);let y=await d("/api/cli/auth/device/token",{method:"POST",body:{device_code:D.device_code},authed:!1,baseUrl:k.toString()}).catch((M)=>{if(M&&typeof M==="object"&&"status"in M&&M.status===400)return M.body;throw M});if(!y)continue;if(y.status==="pending"){x=Math.max(y.interval,rn);continue}if(y.status==="approved"){jn({api_base_url:k.toString(),access_token:y.access_token,refresh_token:y.refresh_token,access_expires_at:y.access_expires_at,refresh_expires_at:y.refresh_expires_at,user:y.user});let M=y.user.email??y.user.name??y.user.id;process.stdout.write(`
18
- Logged in as ${N(M)}.
19
- `);return}throw Error(`Login ${y.status}. Run \`vcity login\` again.`)}throw Error("Login timed out. Run `vcity login` again.")}async function pn(){let n=$n();if(!n){process.stdout.write(`Not logged in.
20
- `);return}try{await d("/api/cli/auth/logout",{method:"POST",body:{refresh_token:n.refresh_token}})}catch{}m(),process.stdout.write(`Logged out.
21
- `)}async function sn(n={}){let c=E(n.json),k=W(n.org),D={};if(n.limit!==void 0)D.limit=n.limit;if(n.status!==void 0)D.status=n.status;let $=await f().orders.list(k,D),j=$.data??[];if(c==="json"){J({org:k,orders:j,total:$.total,skip:$.skip,limit:$.limit,hasMore:$.hasMore});return}V(j,[{header:"ID",get:(x)=>x.id},{header:"STATUS",get:(x)=>x.status??""},{header:"TOTAL",get:(x)=>x.total!==void 0?`${x.total.toLocaleString()} ${x.currencyCode??""}`.trim():""},{header:"CREATED",get:(x)=>S(x.createdAt)}])}async function en(n,c={}){let k=E(c.json),D=W(c.org),$=await f().orders.get(D,n);if(k==="json"){J($);return}Q($)}async function ln(){let c=await f().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=E(n.json),k=await ln(),D=A().active_org;if(c==="json"){J({orgs:k,active_org:D??null});return}V(k,[{header:"*",get:(g)=>g.slug===D?"*":" "},{header:"SLUG",get:(g)=>g.slug},{header:"NAME",get:(g)=>g.name??""},{header:"ID",get:(g)=>g.id}])}async function nc(n){let k=(await ln()).find((D)=>D.slug===n||D.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=E(n.json),k=W(n.org),g=await f().products.list(k,n.limit!==void 0?{limit:n.limit}:{}),$=g.data??[];if(c==="json"){J({org:k,products:$,total:g.total,skip:g.skip,limit:g.limit,hasMore:g.hasMore});return}V($,[{header:"ID",get:(j)=>j.id},{header:"NAME",get:(j)=>j.name??""},{header:"PRICE",get:(j)=>j.price!==void 0?`${j.price.toLocaleString()} ${j.currencyCode??""}`.trim():""},{header:"SKU",get:(j)=>j.sku??""},{header:"VISIBILITY",get:(j)=>j.visibility??""},{header:"STOCK",get:(j)=>j.availability!==void 0?String(j.availability):""}])}async function kc(n,c={}){let k=E(c.json),D=W(c.org),$=await f().products.get(D,n);if(k==="json"){J($);return}Q($)}async function Dc(n={}){let c=E(n.json),k=W(n.org),D=U(n.data),g=D&&typeof D==="object"?{...D}:{};if(n.name!==void 0)g.name=n.name;if(n.price!==void 0)g.price=n.price;if(n.currency!==void 0)g.currencyCode=n.currency;if(n.sku!==void 0)g.sku=n.sku;if(g.name===void 0)throw Error("products create: --name is required (or supply it via --data)");let j=await f().products.create(k,g);if(c==="json"){J(j);return}process.stdout.write(`Created product:
23
- `),Q(j)}async function gc(n,c={}){let k=E(c.json),D=W(c.org),g=U(c.data),$=g&&typeof g==="object"?{...g}:{};if(c.name!==void 0)$.name=c.name;if(c.price!==void 0)$.price=c.price;if(c.currency!==void 0)$.currencyCode=c.currency;if(c.sku!==void 0)$.sku=c.sku;if(c.visibility!==void 0)$.visibility=c.visibility;if(c.availability!==void 0)$.availability=c.availability;if(Object.keys($).length===0)throw Error("products update: nothing to update (pass at least one field or --data)");let x=await f().products.update(D,n,$);if(k==="json"){J(x);return}process.stdout.write(`Updated product:
24
- `),Q(x)}async function $c(n,c={}){let k=E(c.json),D=W(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 ${D}? [y/N]`)){process.stdout.write(`Aborted.
25
- `);return}}let $=await f().products.delete(D,n);if(k==="json"){J($);return}process.stdout.write(`Deleted product ${n}.
26
- `)}var jc=new Set(["PENDING","IN_PROGRESS","SUBMITTED","CANCELED","ORDERED"]);async function xc(n={}){let c=E(n.json),k=W(n.org);if(n.status!==void 0&&!jc.has(n.status))throw Error(`Invalid quote status: ${n.status}. Allowed: ${[...jc].join(", ")}`);let D={};if(n.limit!==void 0)D.limit=n.limit;if(n.status!==void 0)D.status=n.status;let $=await f().quotes.list(k,D),j=$.data??[];if(c==="json"){J({org:k,quotes:j,total:$.total,skip:$.skip,limit:$.limit,hasMore:$.hasMore});return}V(j,[{header:"ID",get:(x)=>x.id},{header:"NAME",get:(x)=>x.name??""},{header:"PRODUCT",get:(x)=>x.productId??""},{header:"QTY",get:(x)=>x.quantity!==void 0?String(x.quantity):""},{header:"STATUS",get:(x)=>x.status??""},{header:"CREATED",get:(x)=>S(x.createdAt)}])}async function yc(n,c={}){let k=E(c.json),D=W(c.org),$=await f().quotes.get(D,n);if(k==="json"){J($);return}Q($)}async function Mc(n={}){let c=E(n.json),k=W(n.org),D={};if(n.limit!==void 0)D.limit=n.limit;let $=await f().rooms.list(k,D),j=$.data??[];if(c==="json"){J({org:k,rooms:j,total:$.total,skip:$.skip,limit:$.limit,hasMore:$.hasMore});return}V(j,[{header:"ID",get:(x)=>x.id},{header:"TITLE",get:(x)=>x.title??""},{header:"DISABLED",get:(x)=>x.disabled?"yes":"no"},{header:"TYPE",get:(x)=>x.type??""}])}async function Yc(n,c={}){let k=E(c.json),D=W(c.org),$=await f().rooms.get(D,n);if(k==="json"){J($);return}Q($)}async function Ec(n={}){let c=E(n.json),k=W(n.org),D=U(n.data),g=D&&typeof D==="object"?{...D}:{};if(n.title!==void 0)g.title=n.title;if(n.description!==void 0)g.description=n.description;if(n.type!==void 0)g.type=n.type;if(g.title===void 0)throw Error("rooms create: --title is required (or supply it via --data)");let j=await f().rooms.create(k,g);if(c==="json"){J(j);return}process.stdout.write(`Created room:
27
- `),Q(j)}async function Jc(n,c={}){let k=E(c.json),D=W(c.org),g=U(c.data),$=g&&typeof g==="object"?{...g}:{};if(c.title!==void 0)$.title=c.title;if(c.description!==void 0)$.description=c.description;if(c.type!==void 0)$.type=c.type;if(c.disabled!==void 0)$.disabled=c.disabled;if(Object.keys($).length===0)throw Error("rooms update: nothing to update (pass at least one field or --data)");let x=await f().rooms.update(D,n,$);if(k==="json"){J(x);return}process.stdout.write(`Updated room:
28
- `),Q(x)}async function fc(n,c={}){let k=E(c.json),D=W(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 ${D}? [y/N]`)){process.stdout.write(`Aborted.
29
- `);return}}let $=await f().rooms.delete(D,n);if(k==="json"){J($);return}process.stdout.write(`Deleted room ${n}.
30
- `)}import{spawn as Wc}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 Gc}from"node:path";var on={name:"@vcityio/cli",version:"0.2.4",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 B=on.version,F=on.name;var Yn="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(D){throw Error("Could not reach the npm registry. Check your internet connection.",{cause:D})}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 Tc(n){let[c,...k]=n.split("-"),[D,g,$]=c.split(".").map((j)=>parseInt(j,10));return{major:Number.isFinite(D)?D:0,minor:Number.isFinite(g)?g:0,patch:Number.isFinite($)?$:0,prerelease:k.join("-")}}function Kn(n,c){let k=Tc(n),D=Tc(c);if(k.major!==D.major)return k.major-D.major;if(k.minor!==D.minor)return k.minor-D.minor;if(k.patch!==D.patch)return k.patch-D.patch;if(k.prerelease===D.prerelease)return 0;if(k.prerelease==="")return 1;if(D.prerelease==="")return-1;return k.prerelease<D.prerelease?-1:1}function _c(n,c){return new Promise((k,D)=>{let g=Wc(n,c,{stdio:"inherit",shell:!1});g.on("error",D),g.on("exit",($)=>k({exitCode:$??1}))})}function Dk(n,c=["--version"]){return new Promise((k)=>{let D=Wc(n,c,{stdio:"ignore",shell:!1});D.on("error",()=>k(!1)),D.on("exit",(g)=>k(g===0))})}async function gk(){let n;try{n=await fetch(Yn,{headers:{accept:"text/x-shellscript, text/plain"}})}catch(g){throw Error(`Could not download installer from ${Yn}.`,{cause:g})}if(!n.ok)throw Error(`Installer download failed (HTTP ${n.status}).`);let c=await n.text();if(!c.startsWith("#!"))throw Error(`Installer at ${Yn} did not return a shell script (missing shebang). Refusing to execute.`);if(c.length>262144)throw Error(`Installer at ${Yn} is unexpectedly large (${c.length} bytes). Refusing to execute.`);let k=ec(Gc(nk(),"vcity-install-")),D=Gc(k,"install.sh");ac(D,c,{mode:448});try{return await _c("bash",[D])}finally{try{lc(k,{recursive:!0,force:!0})}catch{}}}async function Xc(n={}){let c=E(n.json),k=ck(),D=await kk(),$=Kn(B,D)<0;if(c==="json"){if(J({current:B,latest:D,outdated:$,installMethod:k}),n.check||!$)return}else{if(process.stdout.write(`current: ${B}
31
- `),process.stdout.write(`latest: ${D}
32
- `),!$){process.stdout.write(`vcity is up to date.
33
- `);return}process.stdout.write(`install: ${k==="binary"?"standalone binary":"npm global"}
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}
36
+ `),!f){process.stdout.write(`vcity is up to date.
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:j}=await gk();if(j!==0)throw Error(`installer exited with code ${j}`)}else{if(!await Dk("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:j}=await _c("npm",["install","-g",`${F}@latest`]);if(j!==0)throw Error(`npm install exited with code ${j}`)}process.stdout.write(`
43
- Updated to ${D}. Run \`vcity --version\` to confirm.
44
- `)}function $k(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 Zc(n={}){let c=E(n.json),D=await f().me.get(),{user:g,orgs:$}=$k(D),j=A();if(c==="json"){J({user:g,orgs:$,active_org:j.active_org??null});return}let x=g.email??g.name??g.id;process.stdout.write(`User: ${x}
45
- `),process.stdout.write(`User ID: ${g.id}
46
- `),process.stdout.write(`Active org: ${j.active_org??"(none — run `vcity org use <slug>`)"}
47
- `)}var jk=new Set(["json","yes","check","no-browser","disabled"]);function Qc(n){let c=[],k={};for(let D=0;D<n.length;D++){let g=n[D];if(!g.startsWith("--")){c.push(g);continue}let $=g.indexOf("=");if($>=0){k[g.slice(2,$)]=g.slice($+1);continue}let j=g.slice(2),x=n[D+1];if(jk.has(j)||x===void 0||x.startsWith("--"))k[j]=!0;else k[j]=x,D++}return{positional:c,flags:k}}import{mkdirSync as xk,readFileSync as yk,writeFileSync as Mk}from"node:fs";import Yk from"node:path";var Ek=86400000,Jk=1500;function Rc(){return Yk.join(H(),"update-check.json")}function fk(){try{let n=yk(Rc(),"utf8"),c=JSON.parse(n);if(typeof c.latest==="string"&&typeof c.checkedAt==="number")return c;return}catch{return}}function Gk(n){try{xk(H(),{recursive:!0}),Mk(Rc(),JSON.stringify(n,null,2),{mode:384})}catch{}}async function Tk(){let n=new AbortController,c=setTimeout(()=>n.abort(),Jk);try{let k=await fetch(`https://registry.npmjs.org/${F}/latest`,{headers:{accept:"application/json"},signal:n.signal});if(!k.ok)return;let D=await k.json();return typeof D.version==="string"?D.version:void 0}catch{return}finally{clearTimeout(c)}}function oc(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 Kc(){let n=fk(),c=Date.now();if(n&&c-n.checkedAt<Ek)return Promise.resolve(n.latest);return Tk().then((k)=>{if(k)Gk({latest:k,checkedAt:c});return k??n?.latest})}function Vc(n){if(!n)return;if(Kn(B,n)>=0)return;process.stderr.write(`
48
- → vcity ${n} available (you have ${B}). Run \`vcity update\` to upgrade.
49
- `)}function X(n){process.stderr.write(`error: ${N(n)}
50
- `),process.exit(1)}function Wk(){process.stdout.write(`vcity ${B}
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}
50
+ `),process.stdout.write(`Active org: ${f.active_org??"(none — run `vcity org use <slug>`)"}
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 _k(n){if(typeof n!=="string")return;let c=parseInt(n,10);if(Number.isNaN(c)||c<0)X(`--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))X(`${c} must be a number (got: ${n})`);return k}function G(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:_k(n.limit),status:typeof n.status==="string"?n.status:void 0,json:!!n.json}}async function Xk(n){if(n.length===0||n[0]==="--help"||n[0]==="-h"||n[0]==="help"){Wk();return}if(n[0]==="--version"||n[0]==="-v"){process.stdout.write(`${B}
87
- `);return}let[c,k,...D]=n,g=n.slice(1),{positional:$,flags:j}=Qc(g),x=$.slice(k&&!k.startsWith("--")?1:0);switch(c){case"login":return hn({apiBaseUrl:typeof j["api-base-url"]==="string"?j["api-base-url"]:void 0,openBrowser:j["no-browser"]===!0?!1:void 0});case"logout":return pn();case"whoami":return Zc({json:!!j.json});case"org":{if(k==="list")return an({json:!!j.json});if(k==="use"){let y=x[0];if(!y)X("usage: vcity org use <slug>");return nc(y)}X("usage: vcity org list | vcity org use <slug>")}case"products":{let y=b(j);if(k==="list")return cc({org:y.org,limit:y.limit,json:y.json});if(k==="get"){let M=x[0];if(!M)X("usage: vcity products get <id>");return kc(M,{org:y.org,json:y.json})}if(k==="create")return Dc({org:y.org,name:G(j,"name"),price:Vn(j.price,"--price"),currency:G(j,"currency"),sku:G(j,"sku"),data:G(j,"data"),json:y.json});if(k==="update"){let M=x[0];if(!M)X("usage: vcity products update <id>");return gc(M,{org:y.org,name:G(j,"name"),price:Vn(j.price,"--price"),currency:G(j,"currency"),sku:G(j,"sku"),visibility:G(j,"visibility"),availability:Vn(j.availability,"--availability"),data:G(j,"data"),json:y.json})}if(k==="delete"){let M=x[0];if(!M)X("usage: vcity products delete <id>");return $c(M,{org:y.org,yes:j.yes===!0,json:y.json})}X("usage: vcity products list|get|create|update|delete")}case"events":{let y=b(j);if(k==="list"){let M=y.status;if(M!==void 0&&M!=="active"&&M!=="disabled")X(`invalid --status: ${M}. Allowed: active, disabled`);return In({org:y.org,limit:y.limit,status:M,json:y.json})}if(k==="get"){let M=x[0];if(!M)X("usage: vcity events get <id>");return vn(M,{org:y.org,json:y.json})}if(k==="create")return dn({org:y.org,name:G(j,"name"),startsAt:G(j,"starts-at"),endsAt:G(j,"ends-at"),slug:G(j,"slug"),data:G(j,"data"),json:y.json});if(k==="update"){let M=x[0];if(!M)X("usage: vcity events update <id>");return un(M,{org:y.org,name:G(j,"name"),startsAt:G(j,"starts-at"),endsAt:G(j,"ends-at"),slug:G(j,"slug"),status:G(j,"status"),data:G(j,"data"),json:y.json})}if(k==="delete"){let M=x[0];if(!M)X("usage: vcity events delete <id>");return tn(M,{org:y.org,yes:j.yes===!0,json:y.json})}X("usage: vcity events list|get|create|update|delete")}case"rooms":{let y=b(j);if(k==="list")return Mc({org:y.org,limit:y.limit,json:y.json});if(k==="get"){let M=x[0];if(!M)X("usage: vcity rooms get <id>");return Yc(M,{org:y.org,json:y.json})}if(k==="create")return Ec({org:y.org,title:G(j,"title"),description:G(j,"description"),type:G(j,"type"),data:G(j,"data"),json:y.json});if(k==="update"){let M=x[0];if(!M)X("usage: vcity rooms update <id>");return Jc(M,{org:y.org,title:G(j,"title"),description:G(j,"description"),type:G(j,"type"),disabled:j.disabled===!0?!0:void 0,data:G(j,"data"),json:y.json})}if(k==="delete"){let M=x[0];if(!M)X("usage: vcity rooms delete <id>");return fc(M,{org:y.org,yes:j.yes===!0,json:y.json})}X("usage: vcity rooms list|get|create|update|delete")}case"bookings":{let y=b(j);if(k==="list")return Fn(y);if(k==="get"){let M=x[0];if(!M)X("usage: vcity bookings get <id>");return bn(M,{org:y.org,json:y.json})}X("usage: vcity bookings list | vcity bookings get <id>")}case"orders":{let y=b(j);if(k==="list")return sn(y);if(k==="get"){let M=x[0];if(!M)X("usage: vcity orders get <id>");return en(M,{org:y.org,json:y.json})}X("usage: vcity orders list | vcity orders get <id>")}case"quotes":{let y=b(j);if(k==="list")return xc(y);if(k==="get"){let M=x[0];if(!M)X("usage: vcity quotes get <id>");return yc(M,{org:y.org,json:y.json})}X("usage: vcity quotes list | vcity quotes get <id>")}case"update":return Xc({check:j.check===!0,yes:j.yes===!0,json:!!j.json});default:X(`unknown command: ${c}. Run \`vcity --help\`.`)}}async function Zk(){let n=process.argv.slice(2),c=oc(n)?Kc():void 0;try{await Xk(n)}finally{if(c)Vc(await c)}}Zk().catch((n)=>{let c=n instanceof Error?n.message:String(n);process.stderr.write(`error: ${N(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.2.4",
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",