@vcityio/cli 0.4.3 → 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.
- package/dist/index.js +47 -47
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,63 +1,63 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{createRequire as bk}from"node:module";var Ik=bk(import.meta.url);var gk=/\{[^{}]+\}/g,mk=()=>{return typeof process==="object"&&Number.parseInt(process?.versions?.node?.substring(0,2))>=18&&process.versions.undici};function vk(){return Math.random().toString(36).slice(2,11)}function Rn(n){let{baseUrl:k="",Request:D=globalThis.Request,fetch:$=globalThis.fetch,querySerializer:c,bodySerializer:Y,headers:W,requestInitExt:Z=void 0,...y}={...n};Z=mk()?Z:void 0,k=An(k);let j=[];async function T(V,Q){let{baseUrl:w,fetch:Ln=$,Request:zD=D,headers:zn,params:I={},parseAs:Qn="json",querySerializer:t,bodySerializer:wn=Y??ik,body:Un,...xn}=Q||{},Mn=k;if(w)Mn=An(w)??k;let Vn=typeof c==="function"?c:fn(c);if(t)Vn=typeof t==="function"?t:fn({...typeof c==="object"?c:{},...t});let En=Un===void 0?void 0:wn(Un,Pn(W,zn,I.header)),Sk=Pn(En===void 0||En instanceof FormData?{}:{"Content-Type":"application/json"},W,zn,I.header),Fk={redirect:"follow",...y,...xn,body:En,headers:Sk},p,r,P=new D(ok(V,{baseUrl:Mn,params:I,querySerializer:Vn}),Fk),H;for(let C in xn)if(!(C in P))P[C]=xn[C];if(j.length){p=vk(),r=Object.freeze({baseUrl:Mn,fetch:Ln,parseAs:Qn,querySerializer:Vn,bodySerializer:wn});for(let C of j)if(C&&typeof C==="object"&&typeof C.onRequest==="function"){let q=await C.onRequest({request:P,schemaPath:V,params:I,options:r,id:p});if(q)if(q instanceof D)P=q;else if(q instanceof Response){H=q;break}else throw Error("onRequest: must return new Request() or Response() when modifying the request")}}if(!H){try{H=await Ln(P,Z)}catch(C){let q=C;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:P,error:q,schemaPath:V,params:I,options:r,id:p});if(i){if(i instanceof Response){q=void 0,H=i;break}if(i instanceof Error){q=i;continue}throw Error("onError: must return new Response() or instance of Error")}}}if(q)throw q}if(j.length)for(let C=j.length-1;C>=0;C--){let q=j[C];if(q&&typeof q==="object"&&typeof q.onResponse==="function"){let S=await q.onResponse({request:P,response:H,schemaPath:V,params:I,options:r,id:p});if(S){if(!(S instanceof Response))throw Error("onResponse: must return new Response() when modifying the response");H=S}}}}if(H.status===204||P.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 Tn=await H.text();try{Tn=JSON.parse(Tn)}catch{}return{error:Tn,response:H}}return{request(V,Q,w){return T(Q,{...w,method:V.toUpperCase()})},GET(V,Q){return T(V,{...Q,method:"GET"})},PUT(V,Q){return T(V,{...Q,method:"PUT"})},POST(V,Q){return T(V,{...Q,method:"POST"})},DELETE(V,Q){return T(V,{...Q,method:"DELETE"})},OPTIONS(V,Q){return T(V,{...Q,method:"OPTIONS"})},HEAD(V,Q){return T(V,{...Q,method:"HEAD"})},PATCH(V,Q){return T(V,{...Q,method:"PATCH"})},TRACE(V,Q){return T(V,{...Q,method:"TRACE"})},use(...V){for(let Q of V){if(!Q)continue;if(typeof Q!=="object"||!(("onRequest"in Q)||("onResponse"in Q)||("onError"in Q)))throw Error("Middleware must be an object with one of `onRequest()`, `onResponse() or `onError()`");j.push(Q)}},eject(...V){for(let Q of V){let w=j.indexOf(Q);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 On(n,k,D){if(!k||typeof k!=="object")return"";let $=[],c={simple:",",label:".",matrix:";"}[D.style]||"&";if(D.style!=="deepObject"&&D.explode===!1){for(let Z in k)$.push(Z,D.allowReserved===!0?k[Z]:encodeURIComponent(k[Z]));let W=$.join(",");switch(D.style){case"form":return`${n}=${W}`;case"label":return`.${W}`;case"matrix":return`;${n}=${W}`;default:return W}}for(let W in k){let Z=D.style==="deepObject"?`${n}[${W}]`:W;$.push(a(Z,k[W],D))}let Y=$.join(c);return D.style==="label"||D.style==="matrix"?`${c}${Y}`:Y}function Sn(n,k,D){if(!Array.isArray(k))return"";if(D.explode===!1){let Y={form:",",spaceDelimited:"%20",pipeDelimited:"|"}[D.style]||",",W=(D.allowReserved===!0?k:k.map((Z)=>encodeURIComponent(Z))).join(Y);switch(D.style){case"simple":return W;case"label":return`.${W}`;case"matrix":return`;${n}=${W}`;default:return`${n}=${W}`}}let $={simple:",",label:".",matrix:";"}[D.style]||"&",c=[];for(let Y of k)if(D.style==="simple"||D.style==="label")c.push(D.allowReserved===!0?Y:encodeURIComponent(Y));else c.push(a(n,Y,D));return D.style==="label"||D.style==="matrix"?`${$}${c.join($)}`:c.join($)}function fn(n){return function(D){let $=[];if(D&&typeof D==="object")for(let c in D){let Y=D[c];if(Y===void 0||Y===null)continue;if(Array.isArray(Y)){if(Y.length===0)continue;$.push(Sn(c,Y,{style:"form",explode:!0,...n?.array,allowReserved:n?.allowReserved||!1}));continue}if(typeof Y==="object"){$.push(On(c,Y,{style:"deepObject",explode:!0,...n?.object,allowReserved:n?.allowReserved||!1}));continue}$.push(a(c,Y,n))}return $.join("&")}}function dk(n,k){let D=n;for(let $ of n.match(gk)??[]){let c=$.substring(1,$.length-1),Y=!1,W="simple";if(c.endsWith("*"))Y=!0,c=c.substring(0,c.length-1);if(c.startsWith("."))W="label",c=c.substring(1);else if(c.startsWith(";"))W="matrix",c=c.substring(1);if(!k||k[c]===void 0||k[c]===null)continue;let Z=k[c];if(Array.isArray(Z)){D=D.replace($,Sn(c,Z,{style:W,explode:Y}));continue}if(typeof Z==="object"){D=D.replace($,On(c,Z,{style:W,explode:Y}));continue}if(W==="matrix"){D=D.replace($,`;${a(c,Z)}`);continue}D=D.replace($,W==="label"?`.${encodeURIComponent(Z)}`:encodeURIComponent(Z))}return D}function ik(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 ok(n,k){let D=`${k.baseUrl}${n}`;if(k.params?.path)D=dk(D,k.params.path);let $=k.querySerializer(k.params.query??{});if($.startsWith("?"))$=$.substring(1);if($)D+=`?${$}`;return D}function Pn(...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[c,Y]of $)if(Y===null)k.delete(c);else if(Array.isArray(Y))for(let W of Y)k.append(c,W);else if(Y!==void 0)k.set(c,Y)}return k}function An(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 E(n,k){if(n.error!==void 0&&n.error!==null){let D=n.response?.status??0,$=n.response?.url??"",c=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(c),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 E(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 E(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 E(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 E(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 E(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 E(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 E($,"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 E(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 E(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 E(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 E(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 E($,"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 E(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 E(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 E(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 E(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 E($,"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 E(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 E(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 E(D,"bookings.get")}}class cn{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 E(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 E(D,"orders.get")}}class Wn{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 E(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 E(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 E(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 E($,"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 E(D,"quotes.delete")}}var hk="https://vcity.io";function uk(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(c){if(!n)return D(c);let W=c.headers.get("Authorization")?.match(/^Bearer\s+(.+)$/)?.[1]?.trim();if(W&&W!=="undefined"&&W!=="null")return D(c);let Z=new Headers(c.headers);Z.set("Authorization",`Bearer ${n}`);let y=new Request(c,{headers:Z});return D(y)}}class Bn{raw;me;orgs;products;events;rooms;bookings;orders;quotes;constructor(n={}){let k=n.baseUrl??hk,D=uk(n.token,n.fetch),$={baseUrl:k,fetch:D,headers:n.headers};this.raw=Rn($),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 cn(this.raw),this.quotes=new Wn(this.raw)}}function Hn(n={}){return new Bn(n)}import f from"node:fs";import tk from"node:os";import Yn from"node:path";function U(){if(process.env.VCITY_CONFIG_DIR)return Yn.resolve(process.env.VCITY_CONFIG_DIR);return Yn.join(tk.homedir(),".vcity")}function Zn(){return Yn.join(U(),"auth.json")}function qn(){return Yn.join(U(),"config.json")}function Fn(){return process.env.VCITY_API_BASE_URL||"https://vcity.io"}var pk=/\x1b(?:\[[0-?]*[ -/]*[@-~]|\][^\x07\x1b]*(?:\x07|\x1b\\)|[P_^X][^\x07\x1b]*(?:\x07|\x1b\\)|[^[\]P_^X])/g,rk=/[\x00-\x08\x0b-\x1f\x7f]/g;function R(n){return n.replace(pk,"").replace(rk,"")}function bn(n){let k;try{k=new URL(n)}catch{throw Error(`Refusing to open malformed URL: ${R(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 N(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 yn(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 lk(){let n=U();f.mkdirSync(n,{recursive:!0,mode:448});try{f.chmodSync(n,448)}catch{}if(process.platform!=="win32"){let k;try{k=f.statSync(n)}catch{return}if((k.mode&63)!==0)throw Error(`Refusing to write CLI credentials: ${n} is group- or world-accessible (mode ${(k.mode&511).toString(8)}). Tighten its permissions (\`chmod 700 ${n}\`) or set VCITY_CONFIG_DIR to a directory you own.`)}}function ak(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=Zn();if(!f.existsSync(n))return;try{let k=JSON.parse(f.readFileSync(n,"utf-8"));if(!ak(k))return;return yn(k.api_base_url),k}catch{return}}function Gn(n){lk();let k=Zn();f.writeFileSync(k,JSON.stringify(n,null,2),{mode:384});try{f.chmodSync(k,384)}catch{}}function m(){let n=Zn();if(f.existsSync(n))f.rmSync(n)}function Jn(){let n=jn();if(!n)throw Error("Not logged in. Run `vcity login` first.");return n}var Nn=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 vn(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),c=new URL(k.startsWith("/")?k:`/${k}`,n);if(c.origin!==$.origin)throw Error(`Refusing to build URL outside base origin: ${c.origin}`);if(D){for(let[Y,W]of Object.entries(D))if(W!==void 0&&W!==null&&!Number.isNaN(W))c.searchParams.set(Y,String(W))}return c.toString()}var In=(n)=>typeof n==="string"&&n!=="",gn=(n)=>typeof n==="number"&&Number.isFinite(n);async function mn(n){try{let k=await fetch(vn(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(Nn)});if(!k.ok)return;let D=await k.json();if(!In(D.access_token)||!In(D.refresh_token)||!gn(D.access_expires_at)||!gn(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 Gn($),$}catch{return}}async function h(n,k={}){let{authed:D=!0,method:$="GET",body:c,query:Y,baseUrl:W}=k,Z=D?Jn():void 0,y=W??Z?.api_base_url??"https://vcity.io",j={"content-type":"application/json"};if(Z)j.authorization=`Bearer ${Z.access_token}`;let T=await fetch(vn(y,n,Y),{method:$,headers:j,body:c===void 0?void 0:JSON.stringify(c),signal:AbortSignal.timeout(Nn)}),Q=(T.headers.get("content-type")??"").includes("application/json")?await T.json().catch(()=>{return}):await T.text().catch(()=>{return});if(!T.ok){let w=(Q&&typeof Q==="object"&&"error"in Q?String(Q.error):void 0)??`Request failed (${T.status})`;throw new o(T.status,Q,w)}return Q}function ek(){let n=async(k,D)=>{let $=new Headers(k.headers);$.set("authorization",`Bearer ${D}`);let c=new Request(k,{headers:$,signal:AbortSignal.timeout(Nn)});return globalThis.fetch(c)};return async function(D){let $=Jn();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 W=await mn($);if(!W)throw m(),new o(401,void 0,"Session expired. Run `vcity login` again.");$=W}let c=await n(D,$.access_token);if(c.status!==401)return c;let Y=await mn($);if(!Y)throw m(),new o(401,void 0,"Session expired. Run `vcity login` again.");return $=Y,n(D,$.access_token)}}function K(){let n=Jn();return Hn({baseUrl:n.api_base_url,fetch:ek()})}function A(n){if(n==null)return"";return new Date(n).toISOString().replace("T"," ").slice(0,16)}import v from"node:fs";function sk(){let n=U();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 dn(n){sk();let D={...F(),...n},$=qn();v.writeFileSync($,JSON.stringify(D,null,2),{mode:384});try{v.chmodSync($,384)}catch{}return D}function x(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 J(n){if(n)return"json";if(!process.stdout.isTTY)return"json";return"pretty"}function X(n){process.stdout.write(`${JSON.stringify(n,null,2)}
|
|
3
|
-
`)}function
|
|
4
|
-
`)}function
|
|
5
|
-
`)}function
|
|
6
|
-
`)}}async function
|
|
7
|
-
`),
|
|
8
|
-
`),
|
|
9
|
-
`);return}}let
|
|
10
|
-
`)}import{setTimeout as
|
|
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
|
-
${
|
|
12
|
+
${Z.toString()}
|
|
13
13
|
`),process.stdout.write(`Enter this code:
|
|
14
|
-
${
|
|
14
|
+
${n(Y.user_code)}
|
|
15
15
|
|
|
16
16
|
`),process.stdout.write(`Waiting for approval…
|
|
17
|
-
`),
|
|
18
|
-
Logged in as ${
|
|
19
|
-
`);return}throw Error(`Login ${
|
|
20
|
-
`);return}try{await
|
|
21
|
-
`)}async function
|
|
22
|
-
`)}async function
|
|
23
|
-
`),
|
|
24
|
-
`),
|
|
25
|
-
`);return}}let
|
|
26
|
-
`)}var
|
|
27
|
-
`),
|
|
28
|
-
`),
|
|
29
|
-
`);return}}let
|
|
30
|
-
`)}async function
|
|
31
|
-
`),
|
|
32
|
-
`),
|
|
33
|
-
`);return}}let
|
|
34
|
-
`)}import{spawn as
|
|
35
|
-
`),process.stdout.write(` curl -fsSL ${
|
|
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 ${
|
|
41
|
-
`)}async function
|
|
42
|
-
`),process.stdout.write(`latest: ${
|
|
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
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(
|
|
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")
|
|
48
|
-
`);return}if(D==="binary"){if(
|
|
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
|
-
`),
|
|
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:
|
|
53
|
-
Updated to ${
|
|
54
|
-
`)}function
|
|
55
|
-
`),process.stdout.write(`User ID: ${
|
|
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
56
|
`),process.stdout.write(`Active org: ${W.active_org??"(none — run `vcity org use <slug>`)"}
|
|
57
|
-
`)}var
|
|
58
|
-
→ vcity ${
|
|
59
|
-
`)}function
|
|
60
|
-
`),process.exit(1)}function
|
|
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
|
|
102
|
-
`);return}let[
|
|
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)});
|