@vcityio/cli 0.4.2 → 0.4.4

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 (2) hide show
  1. package/dist/index.js +49 -49
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,63 +1,63 @@
1
1
  #!/usr/bin/env node
2
- import{createRequire as Fk}from"node:module";var bk=Fk(import.meta.url);var Ik=/\{[^{}]+\}/g,gk=()=>{return typeof process==="object"&&Number.parseInt(process?.versions?.node?.substring(0,2))>=18&&process.versions.undici};function mk(){return Math.random().toString(36).slice(2,11)}function Hn(n){let{baseUrl:k="",Request:D=globalThis.Request,fetch:$=globalThis.fetch,querySerializer:X,bodySerializer:Z,headers:Y,requestInitExt:G=void 0,...W}={...n};G=gk()?G:void 0,k=On(k);let J=[];async function N(E,M){let{baseUrl:w,fetch:zn=$,Request:CD=D,headers:wn,params:I={},parseAs:Qn="json",querySerializer:t,bodySerializer:fn=Z??dk,body:Un,...xn}=M||{},En=k;if(w)En=On(w)??k;let Vn=typeof X==="function"?X:Pn(X);if(t)Vn=typeof t==="function"?t:Pn({...typeof X==="object"?X:{},...t});let Tn=Un===void 0?void 0:fn(Un,An(Y,wn,I.header)),Ok=An(Tn===void 0||Tn instanceof FormData?{}:{"Content-Type":"application/json"},Y,wn,I.header),Sk={redirect:"follow",...W,...xn,body:Tn,headers:Ok},r,p,U=new D(ik(E,{baseUrl:En,params:I,querySerializer:Vn}),Sk),H;for(let L in xn)if(!(L in U))U[L]=xn[L];if(J.length){r=mk(),p=Object.freeze({baseUrl:En,fetch:zn,parseAs:Qn,querySerializer:Vn,bodySerializer:fn});for(let L of J)if(L&&typeof L==="object"&&typeof L.onRequest==="function"){let B=await L.onRequest({request:U,schemaPath:E,params:I,options:p,id:r});if(B)if(B instanceof D)U=B;else if(B instanceof Response){H=B;break}else throw Error("onRequest: must return new Request() or Response() when modifying the request")}}if(!H){try{H=await zn(U,G)}catch(L){let B=L;if(J.length)for(let S=J.length-1;S>=0;S--){let l=J[S];if(l&&typeof l==="object"&&typeof l.onError==="function"){let i=await l.onError({request:U,error:B,schemaPath:E,params:I,options:p,id:r});if(i){if(i instanceof Response){B=void 0,H=i;break}if(i instanceof Error){B=i;continue}throw Error("onError: must return new Response() or instance of Error")}}}if(B)throw B}if(J.length)for(let L=J.length-1;L>=0;L--){let B=J[L];if(B&&typeof B==="object"&&typeof B.onResponse==="function"){let S=await B.onResponse({request:U,response:H,schemaPath:E,params:I,options:p,id:r});if(S){if(!(S instanceof Response))throw Error("onResponse: must return new Response() when modifying the response");H=S}}}}if(H.status===204||U.method==="HEAD"||H.headers.get("Content-Length")==="0")return H.ok?{data:void 0,response:H}:{error:void 0,response:H};if(H.ok){if(Qn==="stream")return{data:H.body,response:H};return{data:await H[Qn](),response:H}}let Rn=await H.text();try{Rn=JSON.parse(Rn)}catch{}return{error:Rn,response:H}}return{request(E,M,w){return N(M,{...w,method:E.toUpperCase()})},GET(E,M){return N(E,{...M,method:"GET"})},PUT(E,M){return N(E,{...M,method:"PUT"})},POST(E,M){return N(E,{...M,method:"POST"})},DELETE(E,M){return N(E,{...M,method:"DELETE"})},OPTIONS(E,M){return N(E,{...M,method:"OPTIONS"})},HEAD(E,M){return N(E,{...M,method:"HEAD"})},PATCH(E,M){return N(E,{...M,method:"PATCH"})},TRACE(E,M){return N(E,{...M,method:"TRACE"})},use(...E){for(let M of E){if(!M)continue;if(typeof M!=="object"||!(("onRequest"in M)||("onResponse"in M)||("onError"in M)))throw Error("Middleware must be an object with one of `onRequest()`, `onResponse() or `onError()`");J.push(M)}},eject(...E){for(let M of E){let w=J.indexOf(M);if(w!==-1)J.splice(w,1)}}}}function a(n,k,D){if(k===void 0||k===null)return"";if(typeof k==="object")throw Error("Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.");return`${n}=${D?.allowReserved===!0?k:encodeURIComponent(k)}`}function Sn(n,k,D){if(!k||typeof k!=="object")return"";let $=[],X={simple:",",label:".",matrix:";"}[D.style]||"&";if(D.style!=="deepObject"&&D.explode===!1){for(let G in k)$.push(G,D.allowReserved===!0?k[G]:encodeURIComponent(k[G]));let Y=$.join(",");switch(D.style){case"form":return`${n}=${Y}`;case"label":return`.${Y}`;case"matrix":return`;${n}=${Y}`;default:return Y}}for(let Y in k){let G=D.style==="deepObject"?`${n}[${Y}]`:Y;$.push(a(G,k[Y],D))}let Z=$.join(X);return D.style==="label"||D.style==="matrix"?`${X}${Z}`:Z}function Fn(n,k,D){if(!Array.isArray(k))return"";if(D.explode===!1){let Z={form:",",spaceDelimited:"%20",pipeDelimited:"|"}[D.style]||",",Y=(D.allowReserved===!0?k:k.map((G)=>encodeURIComponent(G))).join(Z);switch(D.style){case"simple":return Y;case"label":return`.${Y}`;case"matrix":return`;${n}=${Y}`;default:return`${n}=${Y}`}}let $={simple:",",label:".",matrix:";"}[D.style]||"&",X=[];for(let Z of k)if(D.style==="simple"||D.style==="label")X.push(D.allowReserved===!0?Z:encodeURIComponent(Z));else X.push(a(n,Z,D));return D.style==="label"||D.style==="matrix"?`${$}${X.join($)}`:X.join($)}function Pn(n){return function(D){let $=[];if(D&&typeof D==="object")for(let X in D){let Z=D[X];if(Z===void 0||Z===null)continue;if(Array.isArray(Z)){if(Z.length===0)continue;$.push(Fn(X,Z,{style:"form",explode:!0,...n?.array,allowReserved:n?.allowReserved||!1}));continue}if(typeof Z==="object"){$.push(Sn(X,Z,{style:"deepObject",explode:!0,...n?.object,allowReserved:n?.allowReserved||!1}));continue}$.push(a(X,Z,n))}return $.join("&")}}function vk(n,k){let D=n;for(let $ of n.match(Ik)??[]){let X=$.substring(1,$.length-1),Z=!1,Y="simple";if(X.endsWith("*"))Z=!0,X=X.substring(0,X.length-1);if(X.startsWith("."))Y="label",X=X.substring(1);else if(X.startsWith(";"))Y="matrix",X=X.substring(1);if(!k||k[X]===void 0||k[X]===null)continue;let G=k[X];if(Array.isArray(G)){D=D.replace($,Fn(X,G,{style:Y,explode:Z}));continue}if(typeof G==="object"){D=D.replace($,Sn(X,G,{style:Y,explode:Z}));continue}if(Y==="matrix"){D=D.replace($,`;${a(X,G)}`);continue}D=D.replace($,Y==="label"?`.${encodeURIComponent(G)}`:encodeURIComponent(G))}return D}function dk(n,k){if(n instanceof FormData)return n;if(k){if((k.get instanceof Function?k.get("Content-Type")??k.get("content-type"):k["Content-Type"]??k["content-type"])==="application/x-www-form-urlencoded")return new URLSearchParams(n).toString()}return JSON.stringify(n)}function ik(n,k){let D=`${k.baseUrl}${n}`;if(k.params?.path)D=vk(D,k.params.path);let $=k.querySerializer(k.params.query??{});if($.startsWith("?"))$=$.substring(1);if($)D+=`?${$}`;return D}function An(...n){let k=new Headers;for(let D of n){if(!D||typeof D!=="object")continue;let $=D instanceof Headers?D.entries():Object.entries(D);for(let[X,Z]of $)if(Z===null)k.delete(X);else if(Array.isArray(Z))for(let Y of Z)k.append(X,Y);else if(Z!==void 0)k.set(X,Z)}return k}function On(n){if(n.endsWith("/"))return n.substring(0,n.length-1);return n}class g extends Error{status;body;url;constructor(n,k,D,$){super(n);this.name="ApiClientError",this.status=k,this.body=D,this.url=$.split("?")[0]}}function V(n,k){if(n.error!==void 0&&n.error!==null){let D=n.response?.status??0,$=n.response?.url??"",X=typeof n.error==="object"&&n.error!==null&&"error"in n.error&&typeof n.error.error==="object"&&n.error.error?.message||`${k} failed (${D})`;throw new g(String(X),D,n.error,$)}if(n.data===void 0)throw new g(`${k}: empty response body`,n.response?.status??0,void 0,n.response?.url??"");return n.data}class e{client;constructor(n){this.client=n}async get(){let n=await this.client.GET("/api/v1/me",{});return V(n,"me.get")}}class s{client;constructor(n){this.client=n}async get(n){let k=await this.client.GET("/api/v1/orgs/{orgId}",{params:{path:{orgId:n}}});return V(k,"orgs.get")}async listMembers(n,k={}){let D=await this.client.GET("/api/v1/orgs/{orgId}/members",{params:{path:{orgId:n},query:k}});return V(D,"orgs.listMembers")}}class nn{client;constructor(n){this.client=n}async list(n,k={}){let D=await this.client.GET("/api/v1/orgs/{orgId}/products",{params:{path:{orgId:n},query:k}});return V(D,"products.list")}async get(n,k){let D=await this.client.GET("/api/v1/orgs/{orgId}/products/{productId}",{params:{path:{orgId:n,productId:k}}});return V(D,"products.get")}async create(n,k){let D=await this.client.POST("/api/v1/orgs/{orgId}/products",{params:{path:{orgId:n}},body:k});return V(D,"products.create")}async update(n,k,D){let $=await this.client.PUT("/api/v1/orgs/{orgId}/products/{productId}",{params:{path:{orgId:n,productId:k}},body:D});return V($,"products.update")}async delete(n,k){let D=await this.client.DELETE("/api/v1/orgs/{orgId}/products/{productId}",{params:{path:{orgId:n,productId:k}}});return V(D,"products.delete")}}class kn{client;constructor(n){this.client=n}async list(n,k={}){let D=await this.client.GET("/api/v1/orgs/{orgId}/events",{params:{path:{orgId:n},query:k}});return V(D,"events.list")}async get(n,k){let D=await this.client.GET("/api/v1/orgs/{orgId}/events/{eventId}",{params:{path:{orgId:n,eventId:k}}});return V(D,"events.get")}async create(n,k){let D=await this.client.POST("/api/v1/orgs/{orgId}/events",{params:{path:{orgId:n}},body:k});return V(D,"events.create")}async update(n,k,D){let $=await this.client.PUT("/api/v1/orgs/{orgId}/events/{eventId}",{params:{path:{orgId:n,eventId:k}},body:D});return V($,"events.update")}async delete(n,k){let D=await this.client.DELETE("/api/v1/orgs/{orgId}/events/{eventId}",{params:{path:{orgId:n,eventId:k}}});return V(D,"events.delete")}}class Dn{client;constructor(n){this.client=n}async list(n,k={}){let D=await this.client.GET("/api/v1/orgs/{orgId}/rooms",{params:{path:{orgId:n},query:k}});return V(D,"rooms.list")}async get(n,k){let D=await this.client.GET("/api/v1/orgs/{orgId}/rooms/{roomId}",{params:{path:{orgId:n,roomId:k}}});return V(D,"rooms.get")}async create(n,k){let D=await this.client.POST("/api/v1/orgs/{orgId}/rooms",{params:{path:{orgId:n}},body:k});return V(D,"rooms.create")}async update(n,k,D){let $=await this.client.PUT("/api/v1/orgs/{orgId}/rooms/{roomId}",{params:{path:{orgId:n,roomId:k}},body:D});return V($,"rooms.update")}async delete(n,k){let D=await this.client.DELETE("/api/v1/orgs/{orgId}/rooms/{roomId}",{params:{path:{orgId:n,roomId:k}}});return V(D,"rooms.delete")}}class $n{client;constructor(n){this.client=n}async list(n,k={}){let D=await this.client.GET("/api/v1/orgs/{orgId}/bookings",{params:{path:{orgId:n},query:k}});return V(D,"bookings.list")}async get(n,k){let D=await this.client.GET("/api/v1/orgs/{orgId}/bookings/{bookingId}",{params:{path:{orgId:n,bookingId:k}}});return V(D,"bookings.get")}}class Xn{client;constructor(n){this.client=n}async list(n,k={}){let D=await this.client.GET("/api/v1/orgs/{orgId}/orders",{params:{path:{orgId:n},query:k}});return V(D,"orders.list")}async get(n,k){let D=await this.client.GET("/api/v1/orgs/{orgId}/orders/{orderId}",{params:{path:{orgId:n,orderId:k}}});return V(D,"orders.get")}}class Yn{client;constructor(n){this.client=n}async list(n,k={}){let D=await this.client.GET("/api/v1/orgs/{orgId}/quotes",{params:{path:{orgId:n},query:k}});return V(D,"quotes.list")}async get(n,k){let D=await this.client.GET("/api/v1/orgs/{orgId}/quotes/{quoteId}",{params:{path:{orgId:n,quoteId:k}}});return V(D,"quotes.get")}async create(n,k){let D=await this.client.POST("/api/v1/orgs/{orgId}/quotes",{params:{path:{orgId:n}},body:k});return V(D,"quotes.create")}async update(n,k,D){let $=await this.client.PUT("/api/v1/orgs/{orgId}/quotes/{quoteId}",{params:{path:{orgId:n,quoteId:k}},body:D});return V($,"quotes.update")}async delete(n,k){let D=await this.client.DELETE("/api/v1/orgs/{orgId}/quotes/{quoteId}",{params:{path:{orgId:n,quoteId:k}}});return V(D,"quotes.delete")}}var ok="https://vcity.io";function hk(n,k){let D=k??globalThis.fetch;if(!D)throw Error("@vcityio/api-client: no fetch implementation found. Provide options.fetch or run on Node >=20 / a browser.");return async function(X){if(!n)return D(X);if(X.headers.has("Authorization"))return D(X);let Z=new Headers(X.headers);Z.set("Authorization",`Bearer ${n}`);let Y=new Request(X,{headers:Z});return D(Y)}}class Nn{raw;me;orgs;products;events;rooms;bookings;orders;quotes;constructor(n={}){let k=n.baseUrl??ok,D=hk(n.token,n.fetch),$={baseUrl:k,fetch:D,headers:n.headers};this.raw=Hn($),this.me=new e(this.raw),this.orgs=new s(this.raw),this.products=new nn(this.raw),this.events=new kn(this.raw),this.rooms=new Dn(this.raw),this.bookings=new $n(this.raw),this.orders=new Xn(this.raw),this.quotes=new Yn(this.raw)}}function Bn(n={}){return new Nn(n)}import P from"node:fs";import uk from"node:os";import Zn from"node:path";function f(){if(process.env.VCITY_CONFIG_DIR)return Zn.resolve(process.env.VCITY_CONFIG_DIR);return Zn.join(uk.homedir(),".vcity")}function Gn(){return Zn.join(f(),"auth.json")}function qn(){return Zn.join(f(),"config.json")}function bn(){return process.env.VCITY_API_BASE_URL||process.env.VCITY_PUBLIC_URL||"https://vcity.io"}var tk=/\x1b(?:\[[0-?]*[ -/]*[@-~]|\][^\x07\x1b]*(?:\x07|\x1b\\)|[P_^X][^\x07\x1b]*(?:\x07|\x1b\\)|[^[\]P_^X])/g,rk=/[\x00-\x08\x0b-\x1f\x7f]/g;function T(n){return n.replace(tk,"").replace(rk,"")}function In(n){let k;try{k=new URL(n)}catch{throw Error(`Refusing to open malformed URL: ${T(n).slice(0,100)}`)}if(k.protocol==="https:")return k;if(k.protocol==="http:"&&(k.hostname==="localhost"||k.hostname==="127.0.0.1"))return k;throw Error(`Refusing to open URL with unsafe protocol: ${k.protocol}`)}function q(n,k){let D=n.trim();if(!D)throw Error(`${k} must not be empty.`);if(/[\x00-\x1f\x7f]/.test(D))throw Error(`${k} must not contain control characters.`);return D}function Wn(n){let k;try{k=new URL(n)}catch{throw Error(`Invalid api base URL: ${n.slice(0,200)}`)}if(k.protocol==="https:")return k;if(k.protocol==="http:"&&(k.hostname==="localhost"||k.hostname==="127.0.0.1"))return k;throw Error(`api base URL must use https:// (got: ${k.protocol}//${k.hostname}).`)}function pk(){let n=f();P.mkdirSync(n,{recursive:!0,mode:448});try{P.chmodSync(n,448)}catch{}}function lk(n){if(!n||typeof n!=="object")return!1;let k=n;return typeof k.api_base_url==="string"&&typeof k.access_token==="string"&&typeof k.refresh_token==="string"&&typeof k.access_expires_at==="number"&&typeof k.refresh_expires_at==="number"&&!!k.user&&typeof k.user==="object"}function Jn(){let n=Gn();if(!P.existsSync(n))return;try{let k=JSON.parse(P.readFileSync(n,"utf-8"));if(!lk(k))return;return Wn(k.api_base_url),k}catch{return}}function jn(n){pk();let k=Gn();P.writeFileSync(k,JSON.stringify(n,null,2),{mode:384});try{P.chmodSync(k,384)}catch{}}function m(){let n=Gn();if(P.existsSync(n))P.rmSync(n)}function yn(){let n=Jn();if(!n)throw Error("Not logged in. Run `vcity login` first.");return n}var _n=60000;class o extends Error{status;body;constructor(n,k,D){super(D??`HTTP ${n}`);this.status=n;this.body=k;this.name="ApiError"}}function dn(n,k,D){if(k.startsWith("//")||/^[a-z][a-z0-9+.-]*:/i.test(k))throw Error(`Refusing to build URL with non-relative path: ${k.slice(0,100)}`);let $=new URL(n),X=new URL(k.startsWith("/")?k:`/${k}`,n);if(X.origin!==$.origin)throw Error(`Refusing to build URL outside base origin: ${X.origin}`);if(D){for(let[Z,Y]of Object.entries(D))if(Y!==void 0&&Y!==null&&!Number.isNaN(Y))X.searchParams.set(Z,String(Y))}return X.toString()}var gn=(n)=>typeof n==="string"&&n!=="",mn=(n)=>typeof n==="number"&&Number.isFinite(n);async function vn(n){try{let k=await fetch(dn(n.api_base_url,"/api/cli/auth/refresh"),{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({refresh_token:n.refresh_token}),signal:AbortSignal.timeout(_n)});if(!k.ok)return;let D=await k.json();if(!gn(D.access_token)||!gn(D.refresh_token)||!mn(D.access_expires_at)||!mn(D.refresh_expires_at)||D.access_expires_at<=Date.now()||D.refresh_expires_at<=Date.now())return;let $={...n,access_token:D.access_token,refresh_token:D.refresh_token,access_expires_at:D.access_expires_at,refresh_expires_at:D.refresh_expires_at};return jn($),$}catch{return}}async function h(n,k={}){let{authed:D=!0,method:$="GET",body:X,query:Z,baseUrl:Y}=k,G=D?yn():void 0,W=Y??G?.api_base_url??"https://vcity.io",J={"content-type":"application/json"};if(G)J.authorization=`Bearer ${G.access_token}`;let N=await fetch(dn(W,n,Z),{method:$,headers:J,body:X===void 0?void 0:JSON.stringify(X),signal:AbortSignal.timeout(_n)}),M=(N.headers.get("content-type")??"").includes("application/json")?await N.json().catch(()=>{return}):await N.text().catch(()=>{return});if(!N.ok){let w=(M&&typeof M==="object"&&"error"in M?String(M.error):void 0)??`Request failed (${N.status})`;throw new o(N.status,M,w)}return M}function ak(){let n=async(k,D)=>{let $=new Headers(k.headers);$.set("authorization",`Bearer ${D}`);let X=new Request(k,{headers:$,signal:AbortSignal.timeout(_n)});return globalThis.fetch(X)};return async function(D){let $=yn();if(Date.now()>=$.access_expires_at){if(Date.now()>=$.refresh_expires_at)throw m(),new o(401,void 0,"Session expired. Run `vcity login` again.");let Y=await vn($);if(!Y)throw m(),new o(401,void 0,"Session expired. Run `vcity login` again.");$=Y}let X=await n(D,$.access_token);if(X.status!==401)return X;let Z=await vn($);if(!Z)throw m(),new o(401,void 0,"Session expired. Run `vcity login` again.");return $=Z,n(D,$.access_token)}}var cn;function K(){if(cn)return cn;let n=yn();return cn=Bn({baseUrl:n.api_base_url,fetch:ak()}),cn}function A(n){if(n==null)return"";return new Date(n).toISOString().replace("T"," ").slice(0,16)}import v from"node:fs";function ek(){let n=f();v.mkdirSync(n,{recursive:!0,mode:448});try{v.chmodSync(n,448)}catch{}}function F(){let n=qn();if(!v.existsSync(n))return{};try{return JSON.parse(v.readFileSync(n,"utf-8"))}catch{return{}}}function on(n){ek();let D={...F(),...n},$=qn();v.writeFileSync($,JSON.stringify(D,null,2),{mode:384});try{v.chmodSync($,384)}catch{}return D}function Q(n){if(n)return n;let k=F();if(!k.active_org)throw Error("No active org. Run `vcity org use <slug>` or pass --org <slug>.");return k.active_org}function y(n){if(n)return"json";if(!process.stdout.isTTY)return"json";return"pretty"}function c(n){process.stdout.write(`${JSON.stringify(n,null,2)}
3
- `)}function sk(n,k){if(n.length===0)return"(no rows)";let D=n.map((G)=>k.map((W)=>T(W.get(G)??""))),$=k.map((G,W)=>Math.max(G.header.length,...D.map((J)=>J[W].length))),X=$.map((G)=>"-".repeat(G)).join(" "),Z=k.map((G,W)=>G.header.padEnd($[W])).join(" "),Y=D.map((G)=>G.map((W,J)=>W.padEnd($[J])).join(" "));return[Z,X,...Y].join(`
4
- `)}function _(n,k){process.stdout.write(`${sk(n,k)}
5
- `)}function R(n){for(let[k,D]of Object.entries(n)){if(D===void 0||D===null)continue;let $=typeof D==="object"?JSON.stringify(D):String(D);process.stdout.write(`${k.padEnd(20)} ${T($)}
6
- `)}}async function hn(n={}){let k=y(n.json),D=Q(n.org),$={};if(n.limit!==void 0)$.limit=n.limit;if(n.status!==void 0)$.status=n.status;let Z=await K().bookings.list(D,$),Y=Z.data??[];if(k==="json"){c({org:D,bookings:Y,total:Z.total,skip:Z.skip,limit:Z.limit,hasMore:Z.hasMore});return}_(Y,[{header:"ID",get:(G)=>G.id},{header:"NAME",get:(G)=>G.name??""},{header:"EMAIL",get:(G)=>G.email??""},{header:"REQUESTED",get:(G)=>A(G.requestedDate)},{header:"STATUS",get:(G)=>G.status??""}])}async function un(n,k={}){let D=y(k.json),$=Q(k.org),Z=await K().bookings.get($,n);if(D==="json"){c(Z);return}R(Z)}import nD from"node:fs";function C(n){if(n===void 0)return;let k;if(n.startsWith("@")){let D=n.slice(1);if(D.length===0)throw Error("--data: missing file path after `@`");if(!/\.json$/i.test(D))throw Error(`--data: @file path must point to a .json file (got: ${D})`);try{k=nD.readFileSync(D,"utf-8")}catch($){let X=$ instanceof Error?$.message:String($);throw Error(`--data: could not read ${D}: ${X}`)}}else k=n;try{return JSON.parse(k)}catch(D){let $=D instanceof Error?D.message:String(D);throw Error(`--data: invalid JSON (${$})`)}}import kD from"node:readline";function O(n){let k=kD.createInterface({input:process.stdin,output:process.stdout});return new Promise((D)=>{k.question(`${T(n)} `,($)=>{k.close();let X=$.trim().toLowerCase();D(X==="y"||X==="yes")})})}async function tn(n={}){let k=y(n.json),D=Q(n.org),$={};if(n.limit!==void 0)$.limit=n.limit;if(n.status!==void 0)$.status=n.status;let Z=await K().events.list(D,$),Y=Z.data??[];if(k==="json"){c({org:D,events:Y,total:Z.total,skip:Z.skip,limit:Z.limit,hasMore:Z.hasMore});return}_(Y,[{header:"ID",get:(G)=>G.id},{header:"NAME",get:(G)=>G.name??""},{header:"STARTS_AT",get:(G)=>G.startsAt!==void 0?new Date(G.startsAt).toISOString():""},{header:"STATUS",get:(G)=>G.status??""},{header:"CATEGORIES",get:(G)=>(G.categories??[]).join(",")}])}async function rn(n,k={}){let D=y(k.json),$=Q(k.org),Z=await K().events.get($,n);if(D==="json"){c(Z);return}R(Z)}function Kn(n,k){if(/^-?\d+$/.test(n)){let $=Number(n);if(Number.isFinite($))return $}let D=Date.parse(n);if(Number.isFinite(D))return D;throw Error(`${k}: expected ISO 8601 or epoch ms (got: ${n})`)}async function pn(n={}){let k=y(n.json),D=Q(n.org),$=C(n.data),X=$&&typeof $==="object"?{...$}:{};if(n.name!==void 0)X.name=n.name;if(n.slug!==void 0)X.slug=n.slug;if(n.startsAt!==void 0)X.startsAt=Kn(n.startsAt,"--starts-at");if(n.endsAt!==void 0)X.endsAt=Kn(n.endsAt,"--ends-at");if(X.name===void 0)throw Error("events create: --name is required (or supply it via --data)");let Y=await K().events.create(D,X);if(k==="json"){c(Y);return}process.stdout.write(`Created event:
7
- `),R(Y)}async function ln(n,k={}){let D=y(k.json),$=Q(k.org),X=C(k.data),Z=X&&typeof X==="object"?{...X}:{};if(k.name!==void 0)Z.name=k.name;if(k.slug!==void 0)Z.slug=k.slug;if(k.status!==void 0)Z.status=k.status;if(k.startsAt!==void 0)Z.startsAt=Kn(k.startsAt,"--starts-at");if(k.endsAt!==void 0)Z.endsAt=Kn(k.endsAt,"--ends-at");if(Object.keys(Z).length===0)throw Error("events update: nothing to update (pass at least one field or --data)");let G=await K().events.update($,n,Z);if(D==="json"){c(G);return}process.stdout.write(`Updated event:
8
- `),R(G)}async function an(n,k={}){let D=y(k.json),$=Q(k.org);if(!k.yes){if(D==="json")throw Error("events delete: --yes is required in JSON / non-interactive mode");if(!await O(`Delete event ${n} in org ${$}? [y/N]`)){process.stdout.write(`Aborted.
9
- `);return}}let Z=await K().events.delete($,n);if(D==="json"){c(Z);return}process.stdout.write(`Deleted event ${n}.
10
- `)}import{setTimeout as DD}from"node:timers/promises";var en=1;function $D(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 XD(n){try{let k=(await import("open")).default;await k(n)}catch{}}async function sn(n={}){let k=n.apiBaseUrl??bn(),D=Wn(k),$=await h("/api/cli/auth/device/code",{method:"POST",body:{},authed:!1,baseUrl:D.toString()}),X=new URL("/cli-auth",D),Z=new URL(X);if(Z.searchParams.set("user_code",$.user_code),process.stdout.write(`
2
+ import{createRequire as I$}from"node:module";var v$=I$(import.meta.url);var g$=/\{[^{}]+\}/g,m$=()=>{return typeof process==="object"&&Number.parseInt(process?.versions?.node?.substring(0,2))>=18&&process.versions.undici};function h$(){return Math.random().toString(36).slice(2,11)}function nk(k){let{baseUrl:$="",Request:D=globalThis.Request,fetch:Y=globalThis.fetch,querySerializer:Z,bodySerializer:K,headers:W,requestInitExt:G=void 0,...X}={...k};G=m$()?G:void 0,$=fk($);let Q=[];async function B(x,y){let{baseUrl:U,fetch:Ck=Y,Request:fD=D,headers:Lk,params:v={},parseAs:jk="json",querySerializer:t,bodySerializer:Uk=K??u$,body:wk,...yk}=y||{},Bk=$;if(U)Bk=fk(U)??$;let Hk=typeof Z==="function"?Z:Pk(Z);if(t)Hk=typeof t==="function"?t:Pk({...typeof Z==="object"?Z:{},...t});let Rk=wk===void 0?void 0:Uk(wk,Ak(W,Lk,v.header)),S$=Ak(Rk===void 0||Rk instanceof FormData?{}:{"Content-Type":"application/json"},W,Lk,v.header),b$={redirect:"follow",...X,...yk,body:Rk,headers:S$},l,r,A=new D(i$(x,{baseUrl:Bk,params:v,querySerializer:Hk}),b$),c;for(let _ in yk)if(!(_ in A))A[_]=yk[_];if(Q.length){l=h$(),r=Object.freeze({baseUrl:Bk,fetch:Ck,parseAs:jk,querySerializer:Hk,bodySerializer:Uk});for(let _ of Q)if(_&&typeof _==="object"&&typeof _.onRequest==="function"){let E=await _.onRequest({request:A,schemaPath:x,params:v,options:r,id:l});if(E)if(E instanceof D)A=E;else if(E instanceof Response){c=E;break}else throw Error("onRequest: must return new Request() or Response() when modifying the request")}}if(!c){try{c=await Ck(A,G)}catch(_){let E=_;if(Q.length)for(let O=Q.length-1;O>=0;O--){let a=Q[O];if(a&&typeof a==="object"&&typeof a.onError==="function"){let u=await a.onError({request:A,error:E,schemaPath:x,params:v,options:r,id:l});if(u){if(u instanceof Response){E=void 0,c=u;break}if(u instanceof Error){E=u;continue}throw Error("onError: must return new Response() or instance of Error")}}}if(E)throw E}if(Q.length)for(let _=Q.length-1;_>=0;_--){let E=Q[_];if(E&&typeof E==="object"&&typeof E.onResponse==="function"){let O=await E.onResponse({request:A,response:c,schemaPath:x,params:v,options:r,id:l});if(O){if(!(O instanceof Response))throw Error("onResponse: must return new Response() when modifying the response");c=O}}}}if(c.status===204||A.method==="HEAD"||c.headers.get("Content-Length")==="0")return c.ok?{data:void 0,response:c}:{error:void 0,response:c};if(c.ok){if(jk==="stream")return{data:c.body,response:c};return{data:await c[jk](),response:c}}let Nk=await c.text();try{Nk=JSON.parse(Nk)}catch{}return{error:Nk,response:c}}return{request(x,y,U){return B(y,{...U,method:x.toUpperCase()})},GET(x,y){return B(x,{...y,method:"GET"})},PUT(x,y){return B(x,{...y,method:"PUT"})},POST(x,y){return B(x,{...y,method:"POST"})},DELETE(x,y){return B(x,{...y,method:"DELETE"})},OPTIONS(x,y){return B(x,{...y,method:"OPTIONS"})},HEAD(x,y){return B(x,{...y,method:"HEAD"})},PATCH(x,y){return B(x,{...y,method:"PATCH"})},TRACE(x,y){return B(x,{...y,method:"TRACE"})},use(...x){for(let y of x){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()`");Q.push(y)}},eject(...x){for(let y of x){let U=Q.indexOf(y);if(U!==-1)Q.splice(U,1)}}}}function e(k,$,D){if($===void 0||$===null)return"";if(typeof $==="object")throw Error("Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.");return`${k}=${D?.allowReserved===!0?$:encodeURIComponent($)}`}function Fk(k,$,D){if(!$||typeof $!=="object")return"";let Y=[],Z={simple:",",label:".",matrix:";"}[D.style]||"&";if(D.style!=="deepObject"&&D.explode===!1){for(let G in $)Y.push(G,D.allowReserved===!0?$[G]:encodeURIComponent($[G]));let W=Y.join(",");switch(D.style){case"form":return`${k}=${W}`;case"label":return`.${W}`;case"matrix":return`;${k}=${W}`;default:return W}}for(let W in $){let G=D.style==="deepObject"?`${k}[${W}]`:W;Y.push(e(G,$[W],D))}let K=Y.join(Z);return D.style==="label"||D.style==="matrix"?`${Z}${K}`:K}function Ok(k,$,D){if(!Array.isArray($))return"";if(D.explode===!1){let K={form:",",spaceDelimited:"%20",pipeDelimited:"|"}[D.style]||",",W=(D.allowReserved===!0?$:$.map((G)=>encodeURIComponent(G))).join(K);switch(D.style){case"simple":return W;case"label":return`.${W}`;case"matrix":return`;${k}=${W}`;default:return`${k}=${W}`}}let Y={simple:",",label:".",matrix:";"}[D.style]||"&",Z=[];for(let K of $)if(D.style==="simple"||D.style==="label")Z.push(D.allowReserved===!0?K:encodeURIComponent(K));else Z.push(e(k,K,D));return D.style==="label"||D.style==="matrix"?`${Y}${Z.join(Y)}`:Z.join(Y)}function Pk(k){return function(D){let Y=[];if(D&&typeof D==="object")for(let Z in D){let K=D[Z];if(K===void 0||K===null)continue;if(Array.isArray(K)){if(K.length===0)continue;Y.push(Ok(Z,K,{style:"form",explode:!0,...k?.array,allowReserved:k?.allowReserved||!1}));continue}if(typeof K==="object"){Y.push(Fk(Z,K,{style:"deepObject",explode:!0,...k?.object,allowReserved:k?.allowReserved||!1}));continue}Y.push(e(Z,K,k))}return Y.join("&")}}function d$(k,$){let D=k;for(let Y of k.match(g$)??[]){let Z=Y.substring(1,Y.length-1),K=!1,W="simple";if(Z.endsWith("*"))K=!0,Z=Z.substring(0,Z.length-1);if(Z.startsWith("."))W="label",Z=Z.substring(1);else if(Z.startsWith(";"))W="matrix",Z=Z.substring(1);if(!$||$[Z]===void 0||$[Z]===null)continue;let G=$[Z];if(Array.isArray(G)){D=D.replace(Y,Ok(Z,G,{style:W,explode:K}));continue}if(typeof G==="object"){D=D.replace(Y,Fk(Z,G,{style:W,explode:K}));continue}if(W==="matrix"){D=D.replace(Y,`;${e(Z,G)}`);continue}D=D.replace(Y,W==="label"?`.${encodeURIComponent(G)}`:encodeURIComponent(G))}return D}function u$(k,$){if(k instanceof FormData)return k;if($){if(($.get instanceof Function?$.get("Content-Type")??$.get("content-type"):$["Content-Type"]??$["content-type"])==="application/x-www-form-urlencoded")return new URLSearchParams(k).toString()}return JSON.stringify(k)}function i$(k,$){let D=`${$.baseUrl}${k}`;if($.params?.path)D=d$(D,$.params.path);let Y=$.querySerializer($.params.query??{});if(Y.startsWith("?"))Y=Y.substring(1);if(Y)D+=`?${Y}`;return D}function Ak(...k){let $=new Headers;for(let D of k){if(!D||typeof D!=="object")continue;let Y=D instanceof Headers?D.entries():Object.entries(D);for(let[Z,K]of Y)if(K===null)$.delete(Z);else if(Array.isArray(K))for(let W of K)$.append(Z,W);else if(K!==void 0)$.set(Z,K)}return $}function fk(k){if(k.endsWith("/"))return k.substring(0,k.length-1);return k}class g extends Error{status;body;url;constructor(k,$,D,Y){super(k);this.name="ApiClientError",this.status=$,this.body=D,this.url=Y.split("?")[0]}}function N(k,$){if(k.error!==void 0&&k.error!==null){let D=k.response?.status??0,Y=k.response?.url??"",Z=typeof k.error==="object"&&k.error!==null&&"error"in k.error&&typeof k.error.error==="object"&&k.error.error?.message||`${$} failed (${D})`;throw new g(String(Z),D,k.error,Y)}if(k.data===void 0)throw new g(`${$}: empty response body`,k.response?.status??0,void 0,k.response?.url??"");return k.data}class s{client;constructor(k){this.client=k}async get(){let k=await this.client.GET("/api/v1/me",{});return N(k,"me.get")}}class kk{client;constructor(k){this.client=k}async get(k){let $=await this.client.GET("/api/v1/orgs/{orgId}",{params:{path:{orgId:k}}});return N($,"orgs.get")}async listMembers(k,$={}){let D=await this.client.GET("/api/v1/orgs/{orgId}/members",{params:{path:{orgId:k},query:$}});return N(D,"orgs.listMembers")}}class $k{client;constructor(k){this.client=k}async list(k,$={}){let D=await this.client.GET("/api/v1/orgs/{orgId}/products",{params:{path:{orgId:k},query:$}});return N(D,"products.list")}async get(k,$){let D=await this.client.GET("/api/v1/orgs/{orgId}/products/{productId}",{params:{path:{orgId:k,productId:$}}});return N(D,"products.get")}async create(k,$){let D=await this.client.POST("/api/v1/orgs/{orgId}/products",{params:{path:{orgId:k}},body:$});return N(D,"products.create")}async update(k,$,D){let Y=await this.client.PUT("/api/v1/orgs/{orgId}/products/{productId}",{params:{path:{orgId:k,productId:$}},body:D});return N(Y,"products.update")}async delete(k,$){let D=await this.client.DELETE("/api/v1/orgs/{orgId}/products/{productId}",{params:{path:{orgId:k,productId:$}}});return N(D,"products.delete")}}class Dk{client;constructor(k){this.client=k}async list(k,$={}){let D=await this.client.GET("/api/v1/orgs/{orgId}/events",{params:{path:{orgId:k},query:$}});return N(D,"events.list")}async get(k,$){let D=await this.client.GET("/api/v1/orgs/{orgId}/events/{eventId}",{params:{path:{orgId:k,eventId:$}}});return N(D,"events.get")}async create(k,$){let D=await this.client.POST("/api/v1/orgs/{orgId}/events",{params:{path:{orgId:k}},body:$});return N(D,"events.create")}async update(k,$,D){let Y=await this.client.PUT("/api/v1/orgs/{orgId}/events/{eventId}",{params:{path:{orgId:k,eventId:$}},body:D});return N(Y,"events.update")}async delete(k,$){let D=await this.client.DELETE("/api/v1/orgs/{orgId}/events/{eventId}",{params:{path:{orgId:k,eventId:$}}});return N(D,"events.delete")}}class Yk{client;constructor(k){this.client=k}async list(k,$={}){let D=await this.client.GET("/api/v1/orgs/{orgId}/rooms",{params:{path:{orgId:k},query:$}});return N(D,"rooms.list")}async get(k,$){let D=await this.client.GET("/api/v1/orgs/{orgId}/rooms/{roomId}",{params:{path:{orgId:k,roomId:$}}});return N(D,"rooms.get")}async create(k,$){let D=await this.client.POST("/api/v1/orgs/{orgId}/rooms",{params:{path:{orgId:k}},body:$});return N(D,"rooms.create")}async update(k,$,D){let Y=await this.client.PUT("/api/v1/orgs/{orgId}/rooms/{roomId}",{params:{path:{orgId:k,roomId:$}},body:D});return N(Y,"rooms.update")}async delete(k,$){let D=await this.client.DELETE("/api/v1/orgs/{orgId}/rooms/{roomId}",{params:{path:{orgId:k,roomId:$}}});return N(D,"rooms.delete")}}class Zk{client;constructor(k){this.client=k}async list(k,$={}){let D=await this.client.GET("/api/v1/orgs/{orgId}/bookings",{params:{path:{orgId:k},query:$}});return N(D,"bookings.list")}async get(k,$){let D=await this.client.GET("/api/v1/orgs/{orgId}/bookings/{bookingId}",{params:{path:{orgId:k,bookingId:$}}});return N(D,"bookings.get")}}class Wk{client;constructor(k){this.client=k}async list(k,$={}){let D=await this.client.GET("/api/v1/orgs/{orgId}/orders",{params:{path:{orgId:k},query:$}});return N(D,"orders.list")}async get(k,$){let D=await this.client.GET("/api/v1/orgs/{orgId}/orders/{orderId}",{params:{path:{orgId:k,orderId:$}}});return N(D,"orders.get")}}class Kk{client;constructor(k){this.client=k}async list(k,$={}){let D=await this.client.GET("/api/v1/orgs/{orgId}/quotes",{params:{path:{orgId:k},query:$}});return N(D,"quotes.list")}async get(k,$){let D=await this.client.GET("/api/v1/orgs/{orgId}/quotes/{quoteId}",{params:{path:{orgId:k,quoteId:$}}});return N(D,"quotes.get")}async create(k,$){let D=await this.client.POST("/api/v1/orgs/{orgId}/quotes",{params:{path:{orgId:k}},body:$});return N(D,"quotes.create")}async update(k,$,D){let Y=await this.client.PUT("/api/v1/orgs/{orgId}/quotes/{quoteId}",{params:{path:{orgId:k,quoteId:$}},body:D});return N(Y,"quotes.update")}async delete(k,$){let D=await this.client.DELETE("/api/v1/orgs/{orgId}/quotes/{quoteId}",{params:{path:{orgId:k,quoteId:$}}});return N(D,"quotes.delete")}}var o$="https://vcity.io";function p$(k,$){let D=$??globalThis.fetch;if(!D)throw Error("@vcityio/api-client: no fetch implementation found. Provide options.fetch or run on Node >=20 / a browser.");return async function(Z){if(!k)return D(Z);let W=Z.headers.get("Authorization")?.match(/^Bearer\s+(.+)$/)?.[1]?.trim();if(W&&W!=="undefined"&&W!=="null")return D(Z);let G=new Headers(Z.headers);G.set("Authorization",`Bearer ${k}`);let X=new Request(Z,{headers:G});return D(X)}}class qk{raw;me;orgs;products;events;rooms;bookings;orders;quotes;constructor(k={}){let $=k.baseUrl??o$,D=p$(k.token,k.fetch),Y={baseUrl:$,fetch:D,headers:k.headers};this.raw=nk(Y),this.me=new s(this.raw),this.orgs=new kk(this.raw),this.products=new $k(this.raw),this.events=new Dk(this.raw),this.rooms=new Yk(this.raw),this.bookings=new Zk(this.raw),this.orders=new Wk(this.raw),this.quotes=new Kk(this.raw)}}function ck(k={}){return new qk(k)}import P from"node:fs";import r$ from"node:os";import Gk from"node:path";var t$=/\x1b(?:\[[0-?]*[ -/]*[@-~]|\][^\x07\x1b]*(?:\x07|\x1b\\)|[P_^X][^\x07\x1b]*(?:\x07|\x1b\\)|[^[\]P_^X])/g,l$=/[\x00-\x08\x0b-\x1f\x7f]/g;function n(k){return k.replace(t$,"").replace(l$,"")}function Sk(k){let $;try{$=new URL(k)}catch{throw Error(`Refusing to open malformed URL: ${n(k).slice(0,100)}`)}if($.protocol==="https:")return $;if($.protocol==="http:"&&($.hostname==="localhost"||$.hostname==="127.0.0.1"||$.hostname==="[::1]"))return $;throw Error(`Refusing to open URL with unsafe protocol: ${$.protocol}`)}function z(k,$){let D=k.trim();if(!D)throw Error(`${$} must not be empty.`);if(/[\x00-\x1f\x7f]/.test(D))throw Error(`${$} must not contain control characters.`);return D}function m(k){let $;try{$=new URL(k)}catch{throw Error(`Invalid api base URL: ${k.slice(0,200)}`)}if($.protocol==="https:")return $;if($.protocol==="http:"&&($.hostname==="localhost"||$.hostname==="127.0.0.1"||$.hostname==="[::1]"))return $;throw Error(`api base URL must use https:// (got: ${$.protocol}//${$.hostname}).`)}function w(){if(process.env.VCITY_CONFIG_DIR)return Gk.resolve(process.env.VCITY_CONFIG_DIR);return Gk.join(r$.homedir(),".vcity")}function Xk(){return Gk.join(w(),"auth.json")}function Ek(){return Gk.join(w(),"config.json")}function bk(){let k=process.env.VCITY_API_BASE_URL||"https://vcity.io";return m(k),k}function a$(){let k=w();P.mkdirSync(k,{recursive:!0,mode:448});try{P.chmodSync(k,448)}catch{}if(process.platform!=="win32"){let $;try{$=P.statSync(k)}catch{return}if(($.mode&63)!==0)throw Error(`Refusing to write CLI credentials: ${k} is group- or world-accessible (mode ${($.mode&511).toString(8)}). Tighten its permissions (\`chmod 700 ${k}\`) or set VCITY_CONFIG_DIR to a directory you own.`)}}function e$(k){if(!k||typeof k!=="object")return!1;let $=k;return typeof $.api_base_url==="string"&&typeof $.access_token==="string"&&typeof $.refresh_token==="string"&&typeof $.access_expires_at==="number"&&typeof $.refresh_expires_at==="number"&&!!$.user&&typeof $.user==="object"}function Qk(){let k=Xk();if(!P.existsSync(k))return;try{let $=JSON.parse(P.readFileSync(k,"utf-8"));if(!e$($))return;return m($.api_base_url),$}catch{return}}function Jk(k){a$();let $=Xk();P.writeFileSync($,JSON.stringify(k,null,2),{mode:384});try{P.chmodSync($,384)}catch{}}function h(){let k=Xk();if(P.existsSync(k))P.rmSync(k)}function xk(){let k=Qk();if(!k)throw Error("Not logged in. Run `vcity login` first.");return k}var zk=60000;class i extends Error{status;body;constructor(k,$,D){super(D??`HTTP ${k}`);this.status=k;this.body=$;this.name="ApiError"}}function mk(k,$,D){if($.startsWith("//")||/^[a-z][a-z0-9+.-]*:/i.test($))throw Error(`Refusing to build URL with non-relative path: ${$.slice(0,100)}`);let Y=new URL(k),Z=new URL($.startsWith("/")?$:`/${$}`,k);if(Z.origin!==Y.origin)throw Error(`Refusing to build URL outside base origin: ${Z.origin}`);if(D){for(let[K,W]of Object.entries(D))if(W!==void 0&&W!==null&&!Number.isNaN(W))Z.searchParams.set(K,String(W))}return Z.toString()}var Ik=(k)=>typeof k==="string"&&k!=="",vk=(k)=>typeof k==="number"&&Number.isFinite(k);async function gk(k){try{let $=await fetch(mk(k.api_base_url,"/api/cli/auth/refresh"),{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({refresh_token:k.refresh_token}),signal:AbortSignal.timeout(zk)});if(!$.ok)return;let D=await $.json();if(!Ik(D.access_token)||!Ik(D.refresh_token)||!vk(D.access_expires_at)||!vk(D.refresh_expires_at)||D.access_expires_at<=Date.now()||D.refresh_expires_at<=Date.now())return;let Y={...k,access_token:D.access_token,refresh_token:D.refresh_token,access_expires_at:D.access_expires_at,refresh_expires_at:D.refresh_expires_at};return Jk(Y),Y}catch{return}}async function o(k,$={}){let{authed:D=!0,method:Y="GET",body:Z,query:K,baseUrl:W}=$,G=D?xk():void 0,X=W??G?.api_base_url??"https://vcity.io",Q={"content-type":"application/json"};if(G)Q.authorization=`Bearer ${G.access_token}`;let B=await fetch(mk(X,k,K),{method:Y,headers:Q,body:Z===void 0?void 0:JSON.stringify(Z),signal:AbortSignal.timeout(zk)}),y=(B.headers.get("content-type")??"").includes("application/json")?await B.json().catch(()=>{return}):await B.text().catch(()=>{return});if(!B.ok){let U=(y&&typeof y==="object"&&"error"in y?String(y.error):void 0)??`Request failed (${B.status})`;throw new i(B.status,y,U)}return y}function s$(){let k=async($,D)=>{let Y=new Headers($.headers);Y.set("authorization",`Bearer ${D}`);let Z=new Request($,{headers:Y,signal:AbortSignal.timeout(zk)});return globalThis.fetch(Z)};return async function(D){let Y=xk();if(Date.now()>=Y.access_expires_at){if(Date.now()>=Y.refresh_expires_at)throw h(),new i(401,void 0,"Session expired. Run `vcity login` again.");let W=await gk(Y);if(!W)throw h(),new i(401,void 0,"Session expired. Run `vcity login` again.");Y=W}let Z=await k(D,Y.access_token);if(Z.status!==401)return Z;let K=await gk(Y);if(!K)throw h(),new i(401,void 0,"Session expired. Run `vcity login` again.");return Y=K,k(D,Y.access_token)}}function j(){let k=xk();return ck({baseUrl:k.api_base_url,fetch:s$()})}function f(k){if(k==null)return"";return new Date(k).toISOString().replace("T"," ").slice(0,16)}import S from"node:fs";function kD(){let k=w();S.mkdirSync(k,{recursive:!0,mode:448});try{S.chmodSync(k,448)}catch{}if(process.platform!=="win32"){let $;try{$=S.statSync(k)}catch{return}if(($.mode&63)!==0)throw Error(`Refusing to write CLI config: ${k} is group- or world-accessible (mode ${($.mode&511).toString(8)}). Tighten its permissions (\`chmod 700 ${k}\`) or set VCITY_CONFIG_DIR to a directory you own.`)}}function b(){let k=Ek();if(!S.existsSync(k))return{};try{return JSON.parse(S.readFileSync(k,"utf-8"))}catch{return{}}}function hk(k){kD();let D={...b(),...k},Y=Ek();S.writeFileSync(Y,JSON.stringify(D,null,2),{mode:384});try{S.chmodSync(Y,384)}catch{}return D}function H(k){if(k)return k;let $=b();if(!$.active_org)throw Error("No active org. Run `vcity org use <slug>` or pass --org <slug>.");return $.active_org}function V(k){if(k)return"json";if(!process.stdout.isTTY)return"json";return"pretty"}function M(k){process.stdout.write(`${JSON.stringify(k,null,2)}
3
+ `)}function $D(k,$){if(k.length===0)return"(no rows)";let D=k.map((G)=>$.map((X)=>n(X.get(G)??""))),Y=$.map((G,X)=>Math.max(G.header.length,...D.map((Q)=>Q[X].length))),Z=Y.map((G)=>"-".repeat(G)).join(" "),K=$.map((G,X)=>G.header.padEnd(Y[X])).join(" "),W=D.map((G)=>G.map((X,Q)=>X.padEnd(Y[Q])).join(" "));return[K,Z,...W].join(`
4
+ `)}function T(k,$){process.stdout.write(`${$D(k,$)}
5
+ `)}function q(k){for(let[$,D]of Object.entries(k)){if(D===void 0||D===null)continue;let Y=typeof D==="object"?JSON.stringify(D):String(D);process.stdout.write(`${$.padEnd(20)} ${n(Y)}
6
+ `)}}var dk=new Set(["PENDING","APPROVED","REJECTED","CANCELED","COMPLETED","NO_SHOW"]);async function uk(k={}){let $=V(k.json),D=H(k.org);if(k.status!==void 0&&!dk.has(k.status))throw Error(`Invalid booking status: ${k.status}. Allowed: ${[...dk].join(", ")}`);let Y={};if(k.limit!==void 0)Y.limit=k.limit;if(k.status!==void 0)Y.status=k.status;let K=await j().bookings.list(D,Y),W=K.data??[];if($==="json"){M({org:D,bookings:W,total:K.total,skip:K.skip,limit:K.limit,hasMore:K.hasMore});return}T(W,[{header:"ID",get:(G)=>G.id},{header:"NAME",get:(G)=>G.name??""},{header:"EMAIL",get:(G)=>G.email??""},{header:"REQUESTED",get:(G)=>f(G.requestedDate)},{header:"STATUS",get:(G)=>G.status??""}])}async function ik(k,$={}){let D=V($.json),Y=H($.org),K=await j().bookings.get(Y,k);if(D==="json"){M(K);return}q(K)}import ok from"node:fs";function C(k){if(k===void 0)return;let $;if(k.startsWith("@")){let D=k.slice(1);if(D.length===0)throw Error("--data: missing file path after `@`");if(!/\.json$/i.test(D))throw Error(`--data: @file path must point to a .json file (got: ${D})`);let Y;try{Y=ok.realpathSync(D)}catch(Z){let K=Z instanceof Error?Z.message:String(Z);throw Error(`--data: could not read ${D}: ${K}`)}if(!/\.json$/i.test(Y))throw Error(`--data: @file path must point to a .json file (got: ${D} → ${Y})`);try{$=ok.readFileSync(Y,"utf-8")}catch(Z){let K=Z instanceof Error?Z.message:String(Z);throw Error(`--data: could not read ${D}: ${K}`)}}else $=k;try{return JSON.parse($)}catch(D){let Y=D instanceof Error?D.message:String(D);throw Error(`--data: invalid JSON (${Y})`)}}import DD from"node:readline";function F(k){let $=DD.createInterface({input:process.stdin,output:process.stdout});return new Promise((D)=>{$.question(`${n(k)} `,(Y)=>{$.close();let Z=Y.trim().toLowerCase();D(Z==="y"||Z==="yes")})})}async function pk(k={}){let $=V(k.json),D=H(k.org),Y={};if(k.limit!==void 0)Y.limit=k.limit;if(k.status!==void 0)Y.status=k.status;let K=await j().events.list(D,Y),W=K.data??[];if($==="json"){M({org:D,events:W,total:K.total,skip:K.skip,limit:K.limit,hasMore:K.hasMore});return}T(W,[{header:"ID",get:(G)=>G.id},{header:"NAME",get:(G)=>G.name??""},{header:"STARTS_AT",get:(G)=>G.startsAt!==void 0?new Date(G.startsAt).toISOString():""},{header:"STATUS",get:(G)=>G.status??""},{header:"CATEGORIES",get:(G)=>(G.categories??[]).join(",")}])}async function tk(k,$={}){let D=V($.json),Y=H($.org),K=await j().events.get(Y,k);if(D==="json"){M(K);return}q(K)}function Vk(k,$){if(/^-?\d+$/.test(k)){let Y=Number(k);if(Number.isFinite(Y))return Y}let D=Date.parse(k);if(Number.isFinite(D))return D;throw Error(`${$}: expected ISO 8601 or epoch ms (got: ${k})`)}async function lk(k={}){let $=V(k.json),D=H(k.org),Y=C(k.data),Z=Y&&typeof Y==="object"?{...Y}:{};if(k.name!==void 0)Z.name=k.name;if(k.slug!==void 0)Z.slug=k.slug;if(k.startsAt!==void 0)Z.startsAt=Vk(k.startsAt,"--starts-at");if(k.endsAt!==void 0)Z.endsAt=Vk(k.endsAt,"--ends-at");if(Z.name===void 0)throw Error("events create: --name is required (or supply it via --data)");let W=await j().events.create(D,Z);if($==="json"){M(W);return}process.stdout.write(`Created event:
7
+ `),q(W)}async function rk(k,$={}){let D=V($.json),Y=H($.org),Z=C($.data),K=Z&&typeof Z==="object"?{...Z}:{};if($.name!==void 0)K.name=$.name;if($.slug!==void 0)K.slug=$.slug;if($.status!==void 0)K.status=$.status;if($.startsAt!==void 0)K.startsAt=Vk($.startsAt,"--starts-at");if($.endsAt!==void 0)K.endsAt=Vk($.endsAt,"--ends-at");if(Object.keys(K).length===0)throw Error("events update: nothing to update (pass at least one field or --data)");let G=await j().events.update(Y,k,K);if(D==="json"){M(G);return}process.stdout.write(`Updated event:
8
+ `),q(G)}async function ak(k,$={}){let D=V($.json),Y=H($.org);if(!$.yes){if(D==="json")throw Error("events delete: --yes is required in JSON / non-interactive mode");if(!await F(`Delete event ${k} in org ${Y}? [y/N]`)){process.stdout.write(`Aborted.
9
+ `);return}}let K=await j().events.delete(Y,k);if(D==="json"){M(K);return}process.stdout.write(`Deleted event ${k}.
10
+ `)}import{setTimeout as YD}from"node:timers/promises";var ZD=1,WD=30,KD=64,GD=512;function XD(k){if(k===!1)return!1;if(process.env.VCITY_NO_OPEN_BROWSER)return!1;if(!process.stdout.isTTY)return!1;return!0}async function QD(k){try{let $=(await import("open")).default;await $(k)}catch{}}async function ek(k={}){let $=k.apiBaseUrl??bk(),D=m($),Y=await o("/api/cli/auth/device/code",{method:"POST",body:{},authed:!1,baseUrl:D.toString()});if(typeof Y.user_code!=="string"||Y.user_code.length===0||Y.user_code.length>KD)throw Error("Invalid device flow response: user_code is missing or too long.");if(typeof Y.device_code!=="string"||Y.device_code.length===0||Y.device_code.length>GD)throw Error("Invalid device flow response: device_code is missing or too long.");let Z=new URL("/cli-auth",D),K=new URL(Z);if(K.searchParams.set("user_code",Y.user_code),process.stdout.write(`
11
11
  Open this URL to approve the session:
12
- ${X.toString()}
12
+ ${Z.toString()}
13
13
  `),process.stdout.write(`Enter this code:
14
- ${T($.user_code)}
14
+ ${n(Y.user_code)}
15
15
 
16
16
  `),process.stdout.write(`Waiting for approval…
17
- `),$D(n.openBrowser))await XD(In(Z.toString()).toString());let Y=Date.now()+$.expires_in*1000,G=Math.max($.interval,en);while(Date.now()<Y){await DD(G*1000);let W=await h("/api/cli/auth/device/token",{method:"POST",body:{device_code:$.device_code},authed:!1,baseUrl:D.toString()}).catch((J)=>{if(J&&typeof J==="object"&&"status"in J&&J.status===400)return J.body;throw J});if(!W)continue;if(W.status==="pending"){G=Math.max(W.interval,en);continue}if(W.status==="approved"){jn({api_base_url:D.toString(),access_token:W.access_token,refresh_token:W.refresh_token,access_expires_at:W.access_expires_at,refresh_expires_at:W.refresh_expires_at,user:W.user});let J=W.user.email??W.user.name??W.user.id;process.stdout.write(`
18
- Logged in as ${T(J)}.
19
- `);return}throw Error(`Login ${W.status}. Run \`vcity login\` again.`)}throw Error("Login timed out. Run `vcity login` again.")}async function nk(){let n=Jn();if(!n){process.stdout.write(`Not logged in.
20
- `);return}try{await h("/api/cli/auth/logout",{method:"POST",body:{refresh_token:n.refresh_token}})}catch{}m(),process.stdout.write(`Logged out.
21
- `)}async function kk(n={}){let k=y(n.json),D=Q(n.org),$={};if(n.limit!==void 0)$.limit=n.limit;if(n.status!==void 0)$.status=n.status;let Z=await K().orders.list(D,$),Y=Z.data??[];if(k==="json"){c({org:D,orders:Y,total:Z.total,skip:Z.skip,limit:Z.limit,hasMore:Z.hasMore});return}_(Y,[{header:"ID",get:(G)=>G.id},{header:"STATUS",get:(G)=>G.status??""},{header:"TOTAL",get:(G)=>G.total!==void 0?`${G.total.toLocaleString()} ${G.currencyCode??""}`.trim():""},{header:"CREATED",get:(G)=>A(G.createdAt)}])}async function Dk(n,k={}){let D=y(k.json),$=Q(k.org),Z=await K().orders.get($,n);if(D==="json"){c(Z);return}R(Z)}async function $k(){let k=await K().me.get();if(k&&typeof k==="object"&&"orgs"in k){let D=k.orgs;return Array.isArray(D)?D:[]}return[]}function YD(n){if(!n)return"";let k=[];if(n.admin)k.push("admin");if(n.admins?.create||n.admins?.update||n.admins?.delete)k.push("admins");if(n.products?.create||n.products?.update||n.products?.delete)k.push("products");if(n.orders?.retrieve||n.orders?.update)k.push("orders");if(n.quotes?.retrieve||n.quotes?.update)k.push("quotes");if(n.surveys?.create||n.surveys?.update||n.surveys?.delete||n.surveys?.retrieve)k.push("surveys");return k.join(",")}async function Xk(n={}){let k=y(n.json),D=await $k(),$=F().active_org;if(k==="json"){c({orgs:D,active_org:$??null});return}_(D,[{header:"*",get:(X)=>X.slug===$?"*":" "},{header:"SLUG",get:(X)=>X.slug},{header:"NAME",get:(X)=>X.name??""},{header:"ID",get:(X)=>X.id}])}async function Yk(n){let D=(await $k()).find(($)=>$.slug===n||$.id===n);if(!D)throw Error(`No accessible org matches "${n}". Run \`vcity org list\` to see options.`);on({active_org:D.slug}),process.stdout.write(`Active org set to ${T(D.slug)} (${T(D.name??D.id)}).
22
- `)}async function Zk(n={}){let k=y(n.json),D=Q(n.org),$={};if(n.limit!==void 0)$.limit=n.limit;let Z=await K().orgs.listMembers(D,$),Y=Z.data??[];if(k==="json"){c({org:D,members:Y,total:Z.total,skip:Z.skip,limit:Z.limit,hasMore:Z.hasMore});return}_(Y,[{header:"ID",get:(G)=>G.id},{header:"PROFILE_ID",get:(G)=>G.profileId??""},{header:"ACTIVE",get:(G)=>G.active?"yes":"no"},{header:"PERMISSIONS",get:(G)=>YD(G.permissions)}])}async function Gk(n,k={}){let D=y(k.json),X=await K().orgs.get(n);if(D==="json"){c(X);return}R(X)}async function Wk(n={}){let k=y(n.json),D=Q(n.org),X=await K().products.list(D,n.limit!==void 0?{limit:n.limit}:{}),Z=X.data??[];if(k==="json"){c({org:D,products:Z,total:X.total,skip:X.skip,limit:X.limit,hasMore:X.hasMore});return}_(Z,[{header:"ID",get:(Y)=>Y.id},{header:"NAME",get:(Y)=>Y.name??""},{header:"PRICE",get:(Y)=>Y.price!==void 0?`${Y.price.toLocaleString()} ${Y.currencyCode??""}`.trim():""},{header:"SKU",get:(Y)=>Y.sku??""},{header:"VISIBILITY",get:(Y)=>Y.visibility??""},{header:"STOCK",get:(Y)=>Y.availability!==void 0?String(Y.availability):""}])}async function Jk(n,k={}){let D=y(k.json),$=Q(k.org),Z=await K().products.get($,n);if(D==="json"){c(Z);return}R(Z)}async function jk(n={}){let k=y(n.json),D=Q(n.org),$=C(n.data),X=$&&typeof $==="object"?{...$}:{};if(n.name!==void 0)X.name=n.name;if(n.price!==void 0)X.price=n.price;if(n.currency!==void 0)X.currencyCode=n.currency;if(n.sku!==void 0)X.sku=n.sku;if(X.name===void 0)throw Error("products create: --name is required (or supply it via --data)");let Y=await K().products.create(D,X);if(k==="json"){c(Y);return}process.stdout.write(`Created product:
23
- `),R(Y)}async function yk(n,k={}){let D=y(k.json),$=Q(k.org),X=C(k.data),Z=X&&typeof X==="object"?{...X}:{};if(k.name!==void 0)Z.name=k.name;if(k.price!==void 0)Z.price=k.price;if(k.currency!==void 0)Z.currencyCode=k.currency;if(k.sku!==void 0)Z.sku=k.sku;if(k.visibility!==void 0)Z.visibility=k.visibility;if(k.availability!==void 0)Z.availability=k.availability;if(Object.keys(Z).length===0)throw Error("products update: nothing to update (pass at least one field or --data)");let G=await K().products.update($,n,Z);if(D==="json"){c(G);return}process.stdout.write(`Updated product:
24
- `),R(G)}async function ck(n,k={}){let D=y(k.json),$=Q(k.org);if(!k.yes){if(D==="json")throw Error("products delete: --yes is required in JSON / non-interactive mode");if(!await O(`Delete product ${n} in org ${$}? [y/N]`)){process.stdout.write(`Aborted.
25
- `);return}}let Z=await K().products.delete($,n);if(D==="json"){c(Z);return}process.stdout.write(`Deleted product ${n}.
26
- `)}var Mn=new Set(["PENDING","IN_PROGRESS","SUBMITTED","CANCELED","ORDERED"]);async function Kk(n={}){let k=y(n.json),D=Q(n.org);if(n.status!==void 0&&!Mn.has(n.status))throw Error(`Invalid quote status: ${n.status}. Allowed: ${[...Mn].join(", ")}`);let $={};if(n.limit!==void 0)$.limit=n.limit;if(n.status!==void 0)$.status=n.status;let Z=await K().quotes.list(D,$),Y=Z.data??[];if(k==="json"){c({org:D,quotes:Y,total:Z.total,skip:Z.skip,limit:Z.limit,hasMore:Z.hasMore});return}_(Y,[{header:"ID",get:(G)=>G.id},{header:"NAME",get:(G)=>G.name??""},{header:"PRODUCT",get:(G)=>G.productId??""},{header:"QTY",get:(G)=>G.quantity!==void 0?String(G.quantity):""},{header:"STATUS",get:(G)=>G.status??""},{header:"CREATED",get:(G)=>A(G.createdAt)}])}async function Mk(n,k={}){let D=y(k.json),$=Q(k.org),Z=await K().quotes.get($,n);if(D==="json"){c(Z);return}R(Z)}async function Qk(n={}){let k=y(n.json),D=Q(n.org),$=C(n.data),X=$&&typeof $==="object"?{...$}:{};if(n.name!==void 0)X.name=n.name;if(n.email!==void 0)X.email=n.email;if(n.product!==void 0)X.productId=n.product;if(n.quantity!==void 0)X.quantity=n.quantity;if(n.phone!==void 0)X.telephone=n.phone;if(n.variation!==void 0)X.selectedVariation=n.variation;if(n.company!==void 0)X.company=n.company;if(n.note!==void 0)X.note=n.note;if(X.name===void 0||X.email===void 0||X.productId===void 0)throw Error("quotes create: --name, --email and --product are required (or supply them via --data)");let Y=await K().quotes.create(D,X);if(k==="json"){c(Y);return}process.stdout.write(`Created quote:
27
- `),R(Y)}async function xk(n,k={}){let D=y(k.json),$=Q(k.org);if(k.status!==void 0&&!Mn.has(k.status))throw Error(`Invalid quote status: ${k.status}. Allowed: ${[...Mn].join(", ")}`);let X=C(k.data),Z=X&&typeof X==="object"?{...X}:{};if(k.name!==void 0)Z.name=k.name;if(k.email!==void 0)Z.email=k.email;if(k.product!==void 0)Z.productId=k.product;if(k.quantity!==void 0)Z.quantity=k.quantity;if(k.phone!==void 0)Z.telephone=k.phone;if(k.variation!==void 0)Z.selectedVariation=k.variation;if(k.status!==void 0)Z.status=k.status;if(k.company!==void 0)Z.company=k.company;if(k.note!==void 0)Z.note=k.note;if(k.assignee!==void 0)Z.assigneeUid=k.assignee;if(Object.keys(Z).length===0)throw Error("quotes update: nothing to update (pass at least one field or --data)");let G=await K().quotes.update($,n,Z);if(D==="json"){c(G);return}process.stdout.write(`Updated quote:
28
- `),R(G)}async function Ek(n,k={}){let D=y(k.json),$=Q(k.org);if(!k.yes){if(D==="json")throw Error("quotes delete: --yes is required in JSON / non-interactive mode");if(!await O(`Delete quote ${n} in org ${$}? [y/N]`)){process.stdout.write(`Aborted.
29
- `);return}}let Z=await K().quotes.delete($,n);if(D==="json"){c(Z);return}process.stdout.write(`Deleted quote ${n}.
30
- `)}async function Vk(n={}){let k=y(n.json),D=Q(n.org),$={};if(n.limit!==void 0)$.limit=n.limit;let Z=await K().rooms.list(D,$),Y=Z.data??[];if(k==="json"){c({org:D,rooms:Y,total:Z.total,skip:Z.skip,limit:Z.limit,hasMore:Z.hasMore});return}_(Y,[{header:"ID",get:(G)=>G.id},{header:"TITLE",get:(G)=>G.title??""},{header:"DISABLED",get:(G)=>G.disabled?"yes":"no"},{header:"TYPE",get:(G)=>G.type??""}])}async function Tk(n,k={}){let D=y(k.json),$=Q(k.org),Z=await K().rooms.get($,n);if(D==="json"){c(Z);return}R(Z)}async function Rk(n={}){let k=y(n.json),D=Q(n.org),$=C(n.data),X=$&&typeof $==="object"?{...$}:{};if(n.title!==void 0)X.title=n.title;if(n.description!==void 0)X.description=n.description;if(n.type!==void 0)X.type=n.type;if(X.title===void 0)throw Error("rooms create: --title is required (or supply it via --data)");let Y=await K().rooms.create(D,X);if(k==="json"){c(Y);return}process.stdout.write(`Created room:
31
- `),R(Y)}async function Hk(n,k={}){let D=y(k.json),$=Q(k.org),X=C(k.data),Z=X&&typeof X==="object"?{...X}:{};if(k.title!==void 0)Z.title=k.title;if(k.description!==void 0)Z.description=k.description;if(k.type!==void 0)Z.type=k.type;if(k.disabled!==void 0)Z.disabled=k.disabled;if(Object.keys(Z).length===0)throw Error("rooms update: nothing to update (pass at least one field or --data)");let G=await K().rooms.update($,n,Z);if(D==="json"){c(G);return}process.stdout.write(`Updated room:
32
- `),R(G)}async function Nk(n,k={}){let D=y(k.json),$=Q(k.org);if(!k.yes){if(D==="json")throw Error("rooms delete: --yes is required in JSON / non-interactive mode");if(!await O(`Delete room ${n} in org ${$}? [y/N]`)){process.stdout.write(`Aborted.
33
- `);return}}let Z=await K().rooms.delete($,n);if(D==="json"){c(Z);return}process.stdout.write(`Deleted room ${n}.
34
- `)}import{spawn as Lk}from"node:child_process";var Ln={name:"@vcityio/cli",version:"0.4.2",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 z=Ln.version,d=Ln.name;var Bk="https://vcity.io/cli/install.sh";function GD(){return typeof process.versions.bun==="string"?"binary":"npm"}async function WD(){let n=`https://registry.npmjs.org/${d}/latest`,k;try{k=await fetch(n,{headers:{accept:"application/json"}})}catch($){throw Error("Could not reach the npm registry. Check your internet connection.",{cause:$})}if(!k.ok)throw Error(`Failed to fetch latest version from npm (HTTP ${k.status})`);let D=await k.json();if(!D.version)throw Error("Latest version response from npm is missing the `version` field");return D.version}function qk(n){let[k,...D]=n.split("-"),[$,X,Z]=k.split(".").map((Y)=>parseInt(Y,10));return{major:Number.isFinite($)?$:0,minor:Number.isFinite(X)?X:0,patch:Number.isFinite(Z)?Z:0,prerelease:D.join("-")}}function Cn(n,k){let D=qk(n),$=qk(k);if(D.major!==$.major)return D.major-$.major;if(D.minor!==$.minor)return D.minor-$.minor;if(D.patch!==$.patch)return D.patch-$.patch;if(D.prerelease===$.prerelease)return 0;if(D.prerelease==="")return 1;if($.prerelease==="")return-1;return D.prerelease<$.prerelease?-1:1}function JD(n,k){return new Promise((D,$)=>{let X=Lk(n,k,{stdio:"inherit",shell:!1});X.on("error",$),X.on("exit",(Z)=>D({exitCode:Z??1}))})}function jD(n,k=["--version"]){return new Promise((D)=>{let $=Lk(n,k,{stdio:"ignore",shell:!1});$.on("error",()=>D(!1)),$.on("exit",(X)=>D(X===0))})}function _k(){process.stdout.write(`Download, inspect, then run (recommended):
35
- `),process.stdout.write(` curl -fsSL ${Bk} -o /tmp/vcity-install.sh
17
+ `),XD(k.openBrowser))await QD(Sk(K.toString()).toString());let W=(B)=>{let x=typeof B==="number"&&Number.isFinite(B)?B:0;return Math.max(x,ZD)},G=Math.max(typeof Y.expires_in==="number"&&Number.isFinite(Y.expires_in)?Y.expires_in:0,WD),X=Date.now()+G*1000,Q=W(Y.interval);while(Date.now()<X){await YD(Q*1000);let B=await o("/api/cli/auth/device/token",{method:"POST",body:{device_code:Y.device_code},authed:!1,baseUrl:D.toString()}).catch((x)=>{if(x&&typeof x==="object"&&"status"in x&&x.status===400)return x.body;throw x});if(!B)continue;if(B.status==="pending"){Q=W(B.interval);continue}if(B.status==="approved"){Jk({api_base_url:D.toString(),access_token:B.access_token,refresh_token:B.refresh_token,access_expires_at:B.access_expires_at,refresh_expires_at:B.refresh_expires_at,user:B.user});let x=B.user.email??B.user.name??B.user.id;process.stdout.write(`
18
+ Logged in as ${n(x)}.
19
+ `);return}throw Error(`Login ${B.status}. Run \`vcity login\` again.`)}throw Error("Login timed out. Run `vcity login` again.")}async function sk(){let k=Qk();if(!k){process.stdout.write(`Not logged in.
20
+ `);return}try{await o("/api/cli/auth/logout",{method:"POST",body:{refresh_token:k.refresh_token}})}catch{}h(),process.stdout.write(`Logged out.
21
+ `)}var k$=new Set(["ACCEPTED","REJECTED","PENDING","FAILED","REVERSED","RETAINED","STARTED","EXPIRED","ABANDONED","CANCELED","ANTIFRAUD"]);async function $$(k={}){let $=V(k.json),D=H(k.org);if(k.status!==void 0&&!k$.has(k.status))throw Error(`Invalid order status: ${k.status}. Allowed: ${[...k$].join(", ")}`);let Y={};if(k.limit!==void 0)Y.limit=k.limit;if(k.status!==void 0)Y.status=k.status;let K=await j().orders.list(D,Y),W=K.data??[];if($==="json"){M({org:D,orders:W,total:K.total,skip:K.skip,limit:K.limit,hasMore:K.hasMore});return}T(W,[{header:"ID",get:(G)=>G.id},{header:"STATUS",get:(G)=>G.status??""},{header:"TOTAL",get:(G)=>G.total!==void 0?`${G.total.toLocaleString()} ${G.currencyCode??""}`.trim():""},{header:"CREATED",get:(G)=>f(G.createdAt)}])}async function D$(k,$={}){let D=V($.json),Y=H($.org),K=await j().orders.get(Y,k);if(D==="json"){M(K);return}q(K)}async function Y$(){let $=await j().me.get();if($&&typeof $==="object"&&"orgs"in $){let D=$.orgs;return Array.isArray(D)?D:[]}return[]}function JD(k){if(!k)return"";let $=[];if(k.admin)$.push("admin");if(k.admins?.create||k.admins?.update||k.admins?.delete)$.push("admins");if(k.products?.create||k.products?.update||k.products?.delete)$.push("products");if(k.orders?.retrieve||k.orders?.update)$.push("orders");if(k.quotes?.retrieve||k.quotes?.update)$.push("quotes");if(k.surveys?.create||k.surveys?.update||k.surveys?.delete||k.surveys?.retrieve)$.push("surveys");return $.join(",")}async function Z$(k={}){let $=V(k.json),D=await Y$(),Y=b().active_org;if($==="json"){M({orgs:D,active_org:Y??null});return}T(D,[{header:"*",get:(Z)=>Z.slug===Y?"*":" "},{header:"SLUG",get:(Z)=>Z.slug},{header:"NAME",get:(Z)=>Z.name??""},{header:"ID",get:(Z)=>Z.id}])}async function W$(k){let D=(await Y$()).find((Y)=>Y.slug===k||Y.id===k);if(!D)throw Error(`No accessible org matches "${k}". Run \`vcity org list\` to see options.`);hk({active_org:D.slug}),process.stdout.write(`Active org set to ${n(D.slug)} (${n(D.name??D.id)}).
22
+ `)}async function K$(k={}){let $=V(k.json),D=H(k.org),Y={};if(k.limit!==void 0)Y.limit=k.limit;let K=await j().orgs.listMembers(D,Y),W=K.data??[];if($==="json"){M({org:D,members:W,total:K.total,skip:K.skip,limit:K.limit,hasMore:K.hasMore});return}T(W,[{header:"ID",get:(G)=>G.id},{header:"PROFILE_ID",get:(G)=>G.profileId??""},{header:"ACTIVE",get:(G)=>G.active?"yes":"no"},{header:"PERMISSIONS",get:(G)=>JD(G.permissions)}])}async function G$(k,$={}){let D=V($.json),Z=await j().orgs.get(k);if(D==="json"){M(Z);return}q(Z)}async function X$(k={}){let $=V(k.json),D=H(k.org),Z=await j().products.list(D,k.limit!==void 0?{limit:k.limit}:{}),K=Z.data??[];if($==="json"){M({org:D,products:K,total:Z.total,skip:Z.skip,limit:Z.limit,hasMore:Z.hasMore});return}T(K,[{header:"ID",get:(W)=>W.id},{header:"NAME",get:(W)=>W.name??""},{header:"PRICE",get:(W)=>W.price!==void 0?`${W.price.toLocaleString()} ${W.currencyCode??""}`.trim():""},{header:"SKU",get:(W)=>W.sku??""},{header:"VISIBILITY",get:(W)=>W.visibility??""},{header:"STOCK",get:(W)=>W.availability!==void 0?String(W.availability):""}])}async function Q$(k,$={}){let D=V($.json),Y=H($.org),K=await j().products.get(Y,k);if(D==="json"){M(K);return}q(K)}async function J$(k={}){let $=V(k.json),D=H(k.org),Y=C(k.data),Z=Y&&typeof Y==="object"?{...Y}:{};if(k.name!==void 0)Z.name=k.name;if(k.price!==void 0)Z.price=k.price;if(k.currency!==void 0)Z.currencyCode=k.currency;if(k.sku!==void 0)Z.sku=k.sku;if(Z.name===void 0)throw Error("products create: --name is required (or supply it via --data)");let W=await j().products.create(D,Z);if($==="json"){M(W);return}process.stdout.write(`Created product:
23
+ `),q(W)}async function x$(k,$={}){let D=V($.json),Y=H($.org),Z=C($.data),K=Z&&typeof Z==="object"?{...Z}:{};if($.name!==void 0)K.name=$.name;if($.price!==void 0)K.price=$.price;if($.currency!==void 0)K.currencyCode=$.currency;if($.sku!==void 0)K.sku=$.sku;if($.visibility!==void 0)K.visibility=$.visibility;if($.availability!==void 0)K.availability=$.availability;if(Object.keys(K).length===0)throw Error("products update: nothing to update (pass at least one field or --data)");let G=await j().products.update(Y,k,K);if(D==="json"){M(G);return}process.stdout.write(`Updated product:
24
+ `),q(G)}async function V$(k,$={}){let D=V($.json),Y=H($.org);if(!$.yes){if(D==="json")throw Error("products delete: --yes is required in JSON / non-interactive mode");if(!await F(`Delete product ${k} in org ${Y}? [y/N]`)){process.stdout.write(`Aborted.
25
+ `);return}}let K=await j().products.delete(Y,k);if(D==="json"){M(K);return}process.stdout.write(`Deleted product ${k}.
26
+ `)}var Mk=new Set(["PENDING","IN_PROGRESS","SUBMITTED","CANCELED","ORDERED"]);async function M$(k={}){let $=V(k.json),D=H(k.org);if(k.status!==void 0&&!Mk.has(k.status))throw Error(`Invalid quote status: ${k.status}. Allowed: ${[...Mk].join(", ")}`);let Y={};if(k.limit!==void 0)Y.limit=k.limit;if(k.status!==void 0)Y.status=k.status;let K=await j().quotes.list(D,Y),W=K.data??[];if($==="json"){M({org:D,quotes:W,total:K.total,skip:K.skip,limit:K.limit,hasMore:K.hasMore});return}T(W,[{header:"ID",get:(G)=>G.id},{header:"NAME",get:(G)=>G.name??""},{header:"PRODUCT",get:(G)=>G.productId??""},{header:"QTY",get:(G)=>G.quantity!==void 0?String(G.quantity):""},{header:"STATUS",get:(G)=>G.status??""},{header:"CREATED",get:(G)=>f(G.createdAt)}])}async function j$(k,$={}){let D=V($.json),Y=H($.org),K=await j().quotes.get(Y,k);if(D==="json"){M(K);return}q(K)}async function y$(k={}){let $=V(k.json),D=H(k.org),Y=C(k.data),Z=Y&&typeof Y==="object"?{...Y}:{};if(k.name!==void 0)Z.name=k.name;if(k.email!==void 0)Z.email=k.email;if(k.product!==void 0)Z.productId=k.product;if(k.quantity!==void 0)Z.quantity=k.quantity;if(k.phone!==void 0)Z.telephone=k.phone;if(k.variation!==void 0)Z.selectedVariation=k.variation;if(k.company!==void 0)Z.company=k.company;if(k.note!==void 0)Z.note=k.note;if(Z.name===void 0||Z.email===void 0||Z.productId===void 0)throw Error("quotes create: --name, --email and --product are required (or supply them via --data)");let W=await j().quotes.create(D,Z);if($==="json"){M(W);return}process.stdout.write(`Created quote:
27
+ `),q(W)}async function B$(k,$={}){let D=V($.json),Y=H($.org);if($.status!==void 0&&!Mk.has($.status))throw Error(`Invalid quote status: ${$.status}. Allowed: ${[...Mk].join(", ")}`);let Z=C($.data),K=Z&&typeof Z==="object"?{...Z}:{};if($.name!==void 0)K.name=$.name;if($.email!==void 0)K.email=$.email;if($.product!==void 0)K.productId=$.product;if($.quantity!==void 0)K.quantity=$.quantity;if($.phone!==void 0)K.telephone=$.phone;if($.variation!==void 0)K.selectedVariation=$.variation;if($.status!==void 0)K.status=$.status;if($.company!==void 0)K.company=$.company;if($.note!==void 0)K.note=$.note;if($.assignee!==void 0)K.assigneeUid=$.assignee;if(Object.keys(K).length===0)throw Error("quotes update: nothing to update (pass at least one field or --data)");let G=await j().quotes.update(Y,k,K);if(D==="json"){M(G);return}process.stdout.write(`Updated quote:
28
+ `),q(G)}async function H$(k,$={}){let D=V($.json),Y=H($.org);if(!$.yes){if(D==="json")throw Error("quotes delete: --yes is required in JSON / non-interactive mode");if(!await F(`Delete quote ${k} in org ${Y}? [y/N]`)){process.stdout.write(`Aborted.
29
+ `);return}}let K=await j().quotes.delete(Y,k);if(D==="json"){M(K);return}process.stdout.write(`Deleted quote ${k}.
30
+ `)}async function R$(k={}){let $=V(k.json),D=H(k.org),Y={};if(k.limit!==void 0)Y.limit=k.limit;let K=await j().rooms.list(D,Y),W=K.data??[];if($==="json"){M({org:D,rooms:W,total:K.total,skip:K.skip,limit:K.limit,hasMore:K.hasMore});return}T(W,[{header:"ID",get:(G)=>G.id},{header:"TITLE",get:(G)=>G.title??""},{header:"DISABLED",get:(G)=>G.disabled?"yes":"no"},{header:"TYPE",get:(G)=>G.type??""}])}async function N$(k,$={}){let D=V($.json),Y=H($.org),K=await j().rooms.get(Y,k);if(D==="json"){M(K);return}q(K)}async function n$(k={}){let $=V(k.json),D=H(k.org),Y=C(k.data),Z=Y&&typeof Y==="object"?{...Y}:{};if(k.title!==void 0)Z.title=k.title;if(k.description!==void 0)Z.description=k.description;if(k.type!==void 0)Z.type=k.type;if(Z.title===void 0)throw Error("rooms create: --title is required (or supply it via --data)");let W=await j().rooms.create(D,Z);if($==="json"){M(W);return}process.stdout.write(`Created room:
31
+ `),q(W)}async function q$(k,$={}){let D=V($.json),Y=H($.org),Z=C($.data),K=Z&&typeof Z==="object"?{...Z}:{};if($.title!==void 0)K.title=$.title;if($.description!==void 0)K.description=$.description;if($.type!==void 0)K.type=$.type;if($.disabled!==void 0)K.disabled=$.disabled;if(Object.keys(K).length===0)throw Error("rooms update: nothing to update (pass at least one field or --data)");let G=await j().rooms.update(Y,k,K);if(D==="json"){M(G);return}process.stdout.write(`Updated room:
32
+ `),q(G)}async function c$(k,$={}){let D=V($.json),Y=H($.org);if(!$.yes){if(D==="json")throw Error("rooms delete: --yes is required in JSON / non-interactive mode");if(!await F(`Delete room ${k} in org ${Y}? [y/N]`)){process.stdout.write(`Aborted.
33
+ `);return}}let K=await j().rooms.delete(Y,k);if(D==="json"){M(K);return}process.stdout.write(`Deleted room ${k}.
34
+ `)}import{spawn as C$}from"node:child_process";var Tk={name:"@vcityio/cli",version:"0.4.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 L=Tk.version,d=Tk.name;var E$="https://vcity.io/cli/install.sh",z$=1e4,VD=64;function MD(){return typeof process.versions.bun==="string"?"binary":"npm"}async function jD(){let k=`https://registry.npmjs.org/${d}/latest`,$;try{$=await fetch(k,{headers:{accept:"application/json"},signal:AbortSignal.timeout(z$)})}catch(Y){if(Y instanceof Error&&Y.name==="TimeoutError")throw Error(`npm registry did not respond within ${z$/1000}s. Try again later.`,{cause:Y});throw Error("Could not reach the npm registry. Check your internet connection.",{cause:Y})}if(!$.ok)throw Error(`Failed to fetch latest version from npm (HTTP ${$.status})`);let D=await $.json();if(!D.version||typeof D.version!=="string"||D.version.length>VD)throw Error("Latest version response from npm is missing or invalid `version` field");return D.version}function T$(k){let[$,...D]=k.split("-"),[Y,Z,K]=$.split(".").map((W)=>parseInt(W,10));return{major:Number.isFinite(Y)?Y:0,minor:Number.isFinite(Z)?Z:0,patch:Number.isFinite(K)?K:0,prerelease:D.join("-")}}function _k(k,$){let D=T$(k),Y=T$($);if(D.major!==Y.major)return D.major-Y.major;if(D.minor!==Y.minor)return D.minor-Y.minor;if(D.patch!==Y.patch)return D.patch-Y.patch;if(D.prerelease===Y.prerelease)return 0;if(D.prerelease==="")return 1;if(Y.prerelease==="")return-1;return D.prerelease<Y.prerelease?-1:1}function yD(k,$){return new Promise((D,Y)=>{let Z=C$(k,$,{stdio:"inherit",shell:!1});Z.on("error",Y),Z.on("exit",(K)=>D({exitCode:K??1}))})}function BD(k,$=["--version"]){return new Promise((D)=>{let Y=C$(k,$,{stdio:"ignore",shell:!1});Y.on("error",()=>D(!1)),Y.on("exit",(Z)=>D(Z===0))})}function _$(){process.stdout.write(`Download, inspect, then run (recommended):
35
+ `),process.stdout.write(` curl -fsSL ${E$} -o /tmp/vcity-install.sh
36
36
  `),process.stdout.write(` less /tmp/vcity-install.sh
37
37
  `),process.stdout.write(` bash /tmp/vcity-install.sh
38
38
  `),process.stdout.write(`
39
39
  Or, if you trust the origin (no signature verification is performed):
40
- `),process.stdout.write(` curl -fsSL ${Bk} | bash
41
- `)}async function Ck(n={}){let k=y(n.json),D=GD(),$=await WD(),X=T($),Y=Cn(z,X)<0;if(k==="json"){if(c({current:z,latest:X,outdated:Y,installMethod:D}),n.check||!Y)return}else{if(process.stdout.write(`current: ${z}
42
- `),process.stdout.write(`latest: ${X}
43
- `),!Y){process.stdout.write(`vcity is up to date.
40
+ `),process.stdout.write(` curl -fsSL ${E$} | bash
41
+ `)}async function L$(k={}){let $=V(k.json),D=MD(),Y=await jD(),Z=n(Y),W=_k(L,Z)<0;if($==="json"){if(M({current:L,latest:Z,outdated:W,installMethod:D}),k.check||!W)return}else{if(process.stdout.write(`current: ${L}
42
+ `),process.stdout.write(`latest: ${Z}
43
+ `),!W){process.stdout.write(`vcity is up to date.
44
44
  `);return}process.stdout.write(`install: ${D==="binary"?"standalone binary":"npm global"}
45
- `)}if(n.check)return;if(!n.yes&&k!=="json"){if(process.stdout.write(`
45
+ `)}if(k.check)return;if(!k.yes&&$!=="json"){if(process.stdout.write(`
46
46
  Run with --yes to apply the update, or use the command below:
47
- `),D==="binary")_k();else process.stdout.write(` npm install -g ${d}@latest
48
- `);return}if(D==="binary"){if(k!=="json")process.stdout.write(`
47
+ `),D==="binary")_$();else process.stdout.write(` npm install -g ${d}@latest
48
+ `);return}if(D==="binary"){if($!=="json")process.stdout.write(`
49
49
  This CLI was installed from a standalone binary.
50
- `),_k();return}if(!await jD("npm"))throw Error("`npm` is not on PATH. Install Node.js 20+ from https://nodejs.org");process.stdout.write(`
50
+ `),_$();return}if(!await BD("npm"))throw Error("`npm` is not on PATH. Install Node.js 20+ from https://nodejs.org");process.stdout.write(`
51
51
  Installing latest from npm…
52
- `);let{exitCode:G}=await JD("npm",["install","-g",`${d}@latest`]);if(G!==0)throw Error(`npm install exited with code ${G}`);process.stdout.write(`
53
- Updated to ${X}. Run \`vcity --version\` to confirm.
54
- `)}function yD(n){if(n&&typeof n==="object"&&"user"in n){let k=n;return{user:k.user,orgs:k.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 zk(n={}){let k=y(n.json),$=await K().me.get(),{user:X,orgs:Z}=yD($),Y=F();if(k==="json"){c({user:X,orgs:Z,active_org:Y.active_org??null});return}let G=T(X.email??X.name??X.id);process.stdout.write(`User: ${G}
55
- `),process.stdout.write(`User ID: ${T(X.id)}
56
- `),process.stdout.write(`Active org: ${Y.active_org??"(none — run `vcity org use <slug>`)"}
57
- `)}var cD=new Set(["json","yes","check","no-browser","disabled"]);function wk(n){let k=[],D={};for(let $=0;$<n.length;$++){let X=n[$];if(!X.startsWith("--")){k.push(X);continue}let Z=X.indexOf("=");if(Z>=0){D[X.slice(2,Z)]=X.slice(Z+1);continue}let Y=X.slice(2),G=n[$+1];if(cD.has(Y)||G===void 0||G.startsWith("--"))D[Y]=!0;else D[Y]=G,$++}return{positional:k,flags:D}}import{chmodSync as KD,mkdirSync as MD,readFileSync as QD,writeFileSync as xD}from"node:fs";import ED from"node:path";var VD=86400000,TD=1500;function fk(){return ED.join(f(),"update-check.json")}function RD(){try{let n=QD(fk(),"utf8"),k=JSON.parse(n);if(typeof k.latest==="string"&&typeof k.checkedAt==="number")return k;return}catch{return}}function HD(n){try{let k=f();MD(k,{recursive:!0,mode:448});try{KD(k,448)}catch{}xD(fk(),JSON.stringify(n,null,2),{mode:384})}catch{}}async function ND(){let n=new AbortController,k=setTimeout(()=>n.abort(),TD);try{let D=await fetch(`https://registry.npmjs.org/${d}/latest`,{headers:{accept:"application/json"},signal:n.signal});if(!D.ok)return;let $=await D.json();return typeof $.version==="string"?$.version:void 0}catch{return}finally{clearTimeout(k)}}function Uk(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 Pk(){let n=RD(),k=Date.now();if(n&&k-n.checkedAt<VD)return Promise.resolve(n.latest);return ND().then((D)=>{if(D)HD({latest:D,checkedAt:k});return D??n?.latest})}function Ak(n){if(!n)return;if(Cn(z,n)>=0)return;process.stderr.write(`
58
- → vcity ${T(n)} available (you have ${z}). Run \`vcity update\` to upgrade.
59
- `)}function x(n){process.stderr.write(`error: ${T(n)}
60
- `),process.exit(1)}function BD(){process.stdout.write(`vcity ${z}
52
+ `);let{exitCode:G}=await yD("npm",["install","-g",`${d}@latest`]);if(G!==0)throw Error(`npm install exited with code ${G}`);process.stdout.write(`
53
+ Updated to ${Z}. Run \`vcity --version\` to confirm.
54
+ `)}function HD(k){if(k&&typeof k==="object"&&"user"in k){let $=k;return{user:$.user,orgs:$.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 U$(k={}){let $=V(k.json),Y=await j().me.get(),{user:Z,orgs:K}=HD(Y),W=b();if($==="json"){M({user:Z,orgs:K,active_org:W.active_org??null});return}let G=n(Z.email??Z.name??Z.id);process.stdout.write(`User: ${G}
55
+ `),process.stdout.write(`User ID: ${n(Z.id)}
56
+ `),process.stdout.write(`Active org: ${W.active_org??"(none — run `vcity org use <slug>`)"}
57
+ `)}var RD=new Set(["json","yes","check","no-browser","disabled"]);function w$(k){let $=[],D={};for(let Y=0;Y<k.length;Y++){let Z=k[Y];if(!Z.startsWith("--")){$.push(Z);continue}let K=Z.indexOf("=");if(K>=0){D[Z.slice(2,K)]=Z.slice(K+1);continue}let W=Z.slice(2),G=k[Y+1];if(RD.has(W)||G===void 0||G.startsWith("--"))D[W]=!0;else D[W]=G,Y++}return{positional:$,flags:D}}import{chmodSync as ND,mkdirSync as nD,readFileSync as qD,writeFileSync as cD}from"node:fs";import ED from"node:path";var zD=86400000,TD=1500,P$=64;function A$(){return ED.join(w(),"update-check.json")}function _D(){try{let k=qD(A$(),"utf8"),$=JSON.parse(k);if(typeof $.latest==="string"&&$.latest.length>0&&$.latest.length<=P$&&typeof $.checkedAt==="number")return $;return}catch{return}}function CD(k){try{let $=w();nD($,{recursive:!0,mode:448});try{ND($,448)}catch{}cD(A$(),JSON.stringify(k,null,2),{mode:384})}catch{}}async function LD(){let k=new AbortController,$=setTimeout(()=>k.abort(),TD);try{let D=await fetch(`https://registry.npmjs.org/${d}/latest`,{headers:{accept:"application/json"},signal:k.signal});if(!D.ok)return;let Z=(await D.json()).version;return typeof Z==="string"&&Z.length>0&&Z.length<=P$?Z:void 0}catch{return}finally{clearTimeout($)}}function f$(k){if(process.env.VCITY_NO_UPDATE_CHECK==="1")return!1;if(!process.stderr.isTTY)return!1;if(k.includes("--json"))return!1;if(k[0]==="update")return!1;return!0}function F$(){let k=_D(),$=Date.now();if(k&&$-k.checkedAt<zD)return Promise.resolve(k.latest);return LD().then((D)=>{if(D)CD({latest:D,checkedAt:$});return D??k?.latest})}function O$(k){if(!k)return;if(_k(L,k)>=0)return;process.stderr.write(`
58
+ → vcity ${n(k)} available (you have ${L}). Run \`vcity update\` to upgrade.
59
+ `)}function R(k){process.stderr.write(`error: ${n(k)}
60
+ `),process.exit(1)}function UD(){process.stdout.write(`vcity ${L}
61
61
 
62
62
  Usage:
63
63
  vcity login [--api-base-url <url>] [--no-browser]
@@ -98,6 +98,6 @@ Environment:
98
98
  VCITY_CONFIG_DIR override the config directory (default ~/.vcity)
99
99
  VCITY_NO_OPEN_BROWSER never auto-launch a browser during \`vcity login\`
100
100
  VCITY_NO_UPDATE_CHECK disable the background "new version available" check
101
- `)}function qD(n){if(typeof n!=="string")return;let k=parseInt(n,10);if(Number.isNaN(k)||k<0)x(`--limit must be a non-negative integer (got: ${n})`);return k}function u(n,k){if(n===void 0)return;if(typeof n!=="string")return;let D=Number(n);if(!Number.isFinite(D))x(`${k} must be a number (got: ${n})`);return D}function j(n,k){return typeof n[k]==="string"?n[k]:void 0}function b(n){return{org:typeof n.org==="string"?n.org:void 0,limit:qD(n.limit),status:typeof n.status==="string"?n.status:void 0,json:!!n.json}}async function _D(n){if(n.length===0||n[0]==="--help"||n[0]==="-h"||n[0]==="help"){BD();return}if(n[0]==="--version"||n[0]==="-v"){process.stdout.write(`${z}
102
- `);return}let[k,D,...$]=n,X=n.slice(1),{positional:Z,flags:Y}=wk(X),G=Z.slice(D&&!D.startsWith("--")?1:0);switch(k){case"login":return sn({apiBaseUrl:typeof Y["api-base-url"]==="string"?Y["api-base-url"]:void 0,openBrowser:Y["no-browser"]===!0?!1:void 0});case"logout":return nk();case"whoami":return zk({json:!!Y.json});case"org":{if(D==="list")return Xk({json:!!Y.json});if(D==="use"){let W=G[0];if(!W)x("usage: vcity org use <slug>");return Yk(W)}if(D==="get"){let W=G[0];if(!W)x("usage: vcity org get <id>");return Gk(q(W,"org id"))}if(D==="members"){let W=b(Y);if(G[0]==="list")return Zk({org:W.org,limit:W.limit,json:W.json});x("usage: vcity org members list")}x("usage: vcity org list | vcity org use <slug> | vcity org get <id> | vcity org members list")}case"products":{let W=b(Y);if(D==="list")return Wk({org:W.org,limit:W.limit,json:W.json});if(D==="get"){let J=G[0];if(!J)x("usage: vcity products get <id>");return Jk(q(J,"product id"),{org:W.org,json:W.json})}if(D==="create")return jk({org:W.org,name:j(Y,"name"),price:u(Y.price,"--price"),currency:j(Y,"currency"),sku:j(Y,"sku"),data:j(Y,"data"),json:W.json});if(D==="update"){let J=G[0];if(!J)x("usage: vcity products update <id>");return yk(q(J,"product id"),{org:W.org,name:j(Y,"name"),price:u(Y.price,"--price"),currency:j(Y,"currency"),sku:j(Y,"sku"),visibility:j(Y,"visibility"),availability:u(Y.availability,"--availability"),data:j(Y,"data"),json:W.json})}if(D==="delete"){let J=G[0];if(!J)x("usage: vcity products delete <id>");return ck(q(J,"product id"),{org:W.org,yes:Y.yes===!0,json:W.json})}x("usage: vcity products list|get|create|update|delete")}case"events":{let W=b(Y);if(D==="list"){let J=W.status;if(J!==void 0&&J!=="active"&&J!=="disabled")x(`invalid --status: ${J}. Allowed: active, disabled`);return tn({org:W.org,limit:W.limit,status:J,json:W.json})}if(D==="get"){let J=G[0];if(!J)x("usage: vcity events get <id>");return rn(q(J,"event id"),{org:W.org,json:W.json})}if(D==="create")return pn({org:W.org,name:j(Y,"name"),startsAt:j(Y,"starts-at"),endsAt:j(Y,"ends-at"),slug:j(Y,"slug"),data:j(Y,"data"),json:W.json});if(D==="update"){let J=G[0];if(!J)x("usage: vcity events update <id>");return ln(q(J,"event id"),{org:W.org,name:j(Y,"name"),startsAt:j(Y,"starts-at"),endsAt:j(Y,"ends-at"),slug:j(Y,"slug"),status:j(Y,"status"),data:j(Y,"data"),json:W.json})}if(D==="delete"){let J=G[0];if(!J)x("usage: vcity events delete <id>");return an(q(J,"event id"),{org:W.org,yes:Y.yes===!0,json:W.json})}x("usage: vcity events list|get|create|update|delete")}case"rooms":{let W=b(Y);if(D==="list")return Vk({org:W.org,limit:W.limit,json:W.json});if(D==="get"){let J=G[0];if(!J)x("usage: vcity rooms get <id>");return Tk(q(J,"room id"),{org:W.org,json:W.json})}if(D==="create")return Rk({org:W.org,title:j(Y,"title"),description:j(Y,"description"),type:j(Y,"type"),data:j(Y,"data"),json:W.json});if(D==="update"){let J=G[0];if(!J)x("usage: vcity rooms update <id>");return Hk(q(J,"room id"),{org:W.org,title:j(Y,"title"),description:j(Y,"description"),type:j(Y,"type"),disabled:Y.disabled===!0?!0:void 0,data:j(Y,"data"),json:W.json})}if(D==="delete"){let J=G[0];if(!J)x("usage: vcity rooms delete <id>");return Nk(q(J,"room id"),{org:W.org,yes:Y.yes===!0,json:W.json})}x("usage: vcity rooms list|get|create|update|delete")}case"bookings":{let W=b(Y);if(D==="list")return hn(W);if(D==="get"){let J=G[0];if(!J)x("usage: vcity bookings get <id>");return un(q(J,"booking id"),{org:W.org,json:W.json})}x("usage: vcity bookings list | vcity bookings get <id>")}case"orders":{let W=b(Y);if(D==="list")return kk(W);if(D==="get"){let J=G[0];if(!J)x("usage: vcity orders get <id>");return Dk(q(J,"order id"),{org:W.org,json:W.json})}x("usage: vcity orders list | vcity orders get <id>")}case"quotes":{let W=b(Y);if(D==="list")return Kk(W);if(D==="get"){let J=G[0];if(!J)x("usage: vcity quotes get <id>");return Mk(q(J,"quote id"),{org:W.org,json:W.json})}if(D==="create")return Qk({org:W.org,name:j(Y,"name"),email:j(Y,"email"),product:j(Y,"product"),quantity:u(Y.quantity,"--quantity"),phone:j(Y,"phone"),variation:j(Y,"variation"),company:j(Y,"company"),note:j(Y,"note"),data:j(Y,"data"),json:W.json});if(D==="update"){let J=G[0];if(!J)x("usage: vcity quotes update <id>");return xk(q(J,"quote id"),{org:W.org,status:j(Y,"status"),assignee:j(Y,"assignee"),name:j(Y,"name"),email:j(Y,"email"),product:j(Y,"product"),quantity:u(Y.quantity,"--quantity"),phone:j(Y,"phone"),variation:j(Y,"variation"),company:j(Y,"company"),note:j(Y,"note"),data:j(Y,"data"),json:W.json})}if(D==="delete"){let J=G[0];if(!J)x("usage: vcity quotes delete <id>");return Ek(q(J,"quote id"),{org:W.org,yes:Y.yes===!0,json:W.json})}x("usage: vcity quotes list|get|create|update|delete")}case"update":return Ck({check:Y.check===!0,yes:Y.yes===!0,json:!!Y.json});default:x(`unknown command: ${k}. Run \`vcity --help\`.`)}}async function LD(){let n=process.argv.slice(2),k=Uk(n)?Pk():void 0;try{await _D(n)}finally{if(k)Ak(await k)}}LD().catch((n)=>{let k=n instanceof Error?n.message:String(n);process.stderr.write(`error: ${T(k)}
101
+ `)}function wD(k){if(typeof k!=="string")return;let $=parseInt(k,10);if(Number.isNaN($)||$<0)R(`--limit must be a non-negative integer (got: ${k})`);return $}function p(k,$){if(k===void 0)return;if(typeof k!=="string")return;let D=Number(k);if(!Number.isFinite(D))R(`${$} must be a number (got: ${k})`);return D}function J(k,$){return typeof k[$]==="string"?k[$]:void 0}function I(k){return{org:typeof k.org==="string"?k.org:void 0,limit:wD(k.limit),status:typeof k.status==="string"?k.status:void 0,json:!!k.json}}async function PD(k){if(k.length===0||k[0]==="--help"||k[0]==="-h"||k[0]==="help"){UD();return}if(k[0]==="--version"||k[0]==="-v"){process.stdout.write(`${L}
102
+ `);return}let[$,D,...Y]=k,Z=k.slice(1),{positional:K,flags:W}=w$(Z),G=K.slice(D&&!D.startsWith("--")?1:0);switch($){case"login":return ek({apiBaseUrl:typeof W["api-base-url"]==="string"?W["api-base-url"]:void 0,openBrowser:W["no-browser"]===!0?!1:void 0});case"logout":return sk();case"whoami":return U$({json:!!W.json});case"org":{if(D==="list")return Z$({json:!!W.json});if(D==="use"){let X=G[0];if(!X)R("usage: vcity org use <slug>");return W$(X)}if(D==="get"){let X=G[0];if(!X)R("usage: vcity org get <id>");return G$(z(X,"org id"))}if(D==="members"){let X=I(W);if(G[0]==="list")return K$({org:X.org,limit:X.limit,json:X.json});R("usage: vcity org members list")}R("usage: vcity org list | vcity org use <slug> | vcity org get <id> | vcity org members list")}case"products":{let X=I(W);if(D==="list")return X$({org:X.org,limit:X.limit,json:X.json});if(D==="get"){let Q=G[0];if(!Q)R("usage: vcity products get <id>");return Q$(z(Q,"product id"),{org:X.org,json:X.json})}if(D==="create")return J$({org:X.org,name:J(W,"name"),price:p(W.price,"--price"),currency:J(W,"currency"),sku:J(W,"sku"),data:J(W,"data"),json:X.json});if(D==="update"){let Q=G[0];if(!Q)R("usage: vcity products update <id>");return x$(z(Q,"product id"),{org:X.org,name:J(W,"name"),price:p(W.price,"--price"),currency:J(W,"currency"),sku:J(W,"sku"),visibility:J(W,"visibility"),availability:p(W.availability,"--availability"),data:J(W,"data"),json:X.json})}if(D==="delete"){let Q=G[0];if(!Q)R("usage: vcity products delete <id>");return V$(z(Q,"product id"),{org:X.org,yes:W.yes===!0,json:X.json})}R("usage: vcity products list|get|create|update|delete")}case"events":{let X=I(W);if(D==="list"){let Q=X.status;if(Q!==void 0&&Q!=="active"&&Q!=="disabled")R(`invalid --status: ${Q}. Allowed: active, disabled`);return pk({org:X.org,limit:X.limit,status:Q,json:X.json})}if(D==="get"){let Q=G[0];if(!Q)R("usage: vcity events get <id>");return tk(z(Q,"event id"),{org:X.org,json:X.json})}if(D==="create")return lk({org:X.org,name:J(W,"name"),startsAt:J(W,"starts-at"),endsAt:J(W,"ends-at"),slug:J(W,"slug"),data:J(W,"data"),json:X.json});if(D==="update"){let Q=G[0];if(!Q)R("usage: vcity events update <id>");return rk(z(Q,"event id"),{org:X.org,name:J(W,"name"),startsAt:J(W,"starts-at"),endsAt:J(W,"ends-at"),slug:J(W,"slug"),status:J(W,"status"),data:J(W,"data"),json:X.json})}if(D==="delete"){let Q=G[0];if(!Q)R("usage: vcity events delete <id>");return ak(z(Q,"event id"),{org:X.org,yes:W.yes===!0,json:X.json})}R("usage: vcity events list|get|create|update|delete")}case"rooms":{let X=I(W);if(D==="list")return R$({org:X.org,limit:X.limit,json:X.json});if(D==="get"){let Q=G[0];if(!Q)R("usage: vcity rooms get <id>");return N$(z(Q,"room id"),{org:X.org,json:X.json})}if(D==="create")return n$({org:X.org,title:J(W,"title"),description:J(W,"description"),type:J(W,"type"),data:J(W,"data"),json:X.json});if(D==="update"){let Q=G[0];if(!Q)R("usage: vcity rooms update <id>");return q$(z(Q,"room id"),{org:X.org,title:J(W,"title"),description:J(W,"description"),type:J(W,"type"),disabled:W.disabled===!0?!0:void 0,data:J(W,"data"),json:X.json})}if(D==="delete"){let Q=G[0];if(!Q)R("usage: vcity rooms delete <id>");return c$(z(Q,"room id"),{org:X.org,yes:W.yes===!0,json:X.json})}R("usage: vcity rooms list|get|create|update|delete")}case"bookings":{let X=I(W);if(D==="list")return uk(X);if(D==="get"){let Q=G[0];if(!Q)R("usage: vcity bookings get <id>");return ik(z(Q,"booking id"),{org:X.org,json:X.json})}R("usage: vcity bookings list | vcity bookings get <id>")}case"orders":{let X=I(W);if(D==="list")return $$(X);if(D==="get"){let Q=G[0];if(!Q)R("usage: vcity orders get <id>");return D$(z(Q,"order id"),{org:X.org,json:X.json})}R("usage: vcity orders list | vcity orders get <id>")}case"quotes":{let X=I(W);if(D==="list")return M$(X);if(D==="get"){let Q=G[0];if(!Q)R("usage: vcity quotes get <id>");return j$(z(Q,"quote id"),{org:X.org,json:X.json})}if(D==="create")return y$({org:X.org,name:J(W,"name"),email:J(W,"email"),product:J(W,"product"),quantity:p(W.quantity,"--quantity"),phone:J(W,"phone"),variation:J(W,"variation"),company:J(W,"company"),note:J(W,"note"),data:J(W,"data"),json:X.json});if(D==="update"){let Q=G[0];if(!Q)R("usage: vcity quotes update <id>");return B$(z(Q,"quote id"),{org:X.org,status:J(W,"status"),assignee:J(W,"assignee"),name:J(W,"name"),email:J(W,"email"),product:J(W,"product"),quantity:p(W.quantity,"--quantity"),phone:J(W,"phone"),variation:J(W,"variation"),company:J(W,"company"),note:J(W,"note"),data:J(W,"data"),json:X.json})}if(D==="delete"){let Q=G[0];if(!Q)R("usage: vcity quotes delete <id>");return H$(z(Q,"quote id"),{org:X.org,yes:W.yes===!0,json:X.json})}R("usage: vcity quotes list|get|create|update|delete")}case"update":return L$({check:W.check===!0,yes:W.yes===!0,json:!!W.json});default:R(`unknown command: ${$}. Run \`vcity --help\`.`)}}async function AD(){let k=process.argv.slice(2),$=f$(k)?F$():void 0;try{await PD(k)}finally{if($)O$(await $)}}AD().catch((k)=>{let $=k instanceof Error?k.message:String(k);process.stderr.write(`error: ${n($)}
103
103
  `),process.exit(1)});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vcityio/cli",
3
- "version": "0.4.2",
3
+ "version": "0.4.4",
4
4
  "type": "module",
5
5
  "description": "vcity command-line interface for org owners",
6
6
  "main": "./dist/index.js",