@vcityio/cli 0.4.1 → 0.4.2
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 +46 -46
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,63 +1,63 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{createRequire as Sk}from"node:module";var Fk=Sk(import.meta.url);var bk=/\{[^{}]+\}/g,Ik=()=>{return typeof process==="object"&&Number.parseInt(process?.versions?.node?.substring(0,2))>=18&&process.versions.undici};function gk(){return Math.random().toString(36).slice(2,11)}function Hn(n){let{baseUrl:k="",Request:D=globalThis.Request,fetch:$=globalThis.fetch,querySerializer:E,bodySerializer:X,headers:M,requestInitExt:Y=void 0,...Z}={...n};Y=Ik()?Y:void 0,k=An(k);let G=[];async function N(T,Q){let{baseUrl:z,fetch:Un=$,Request:qD=D,headers:Cn,params:I={},parseAs:jn="json",querySerializer:t,bodySerializer:zn=X??vk,body:wn,...Kn}=Q||{},Tn=k;if(z)Tn=An(z)??k;let xn=typeof E==="function"?E:fn(E);if(t)xn=typeof t==="function"?t:fn({...typeof E==="object"?E:{},...t});let Vn=wn===void 0?void 0:zn(wn,Pn(M,Cn,I.header)),Ak=Pn(Vn===void 0||Vn instanceof FormData?{}:{"Content-Type":"application/json"},M,Cn,I.header),Ok={redirect:"follow",...Z,...Kn,body:Vn,headers:Ak},r,p,f=new D(dk(T,{baseUrl:Tn,params:I,querySerializer:xn}),Ok),H;for(let L in Kn)if(!(L in f))f[L]=Kn[L];if(G.length){r=gk(),p=Object.freeze({baseUrl:Tn,fetch:Un,parseAs:jn,querySerializer:xn,bodySerializer:zn});for(let L of G)if(L&&typeof L==="object"&&typeof L.onRequest==="function"){let _=await L.onRequest({request:f,schemaPath:T,params:I,options:p,id:r});if(_)if(_ instanceof D)f=_;else if(_ instanceof Response){H=_;break}else throw Error("onRequest: must return new Request() or Response() when modifying the request")}}if(!H){try{H=await Un(f,Y)}catch(L){let _=L;if(G.length)for(let S=G.length-1;S>=0;S--){let l=G[S];if(l&&typeof l==="object"&&typeof l.onError==="function"){let i=await l.onError({request:f,error:_,schemaPath:T,params:I,options:p,id:r});if(i){if(i instanceof Response){_=void 0,H=i;break}if(i instanceof Error){_=i;continue}throw Error("onError: must return new Response() or instance of Error")}}}if(_)throw _}if(G.length)for(let L=G.length-1;L>=0;L--){let _=G[L];if(_&&typeof _==="object"&&typeof _.onResponse==="function"){let S=await _.onResponse({request:f,response:H,schemaPath:T,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||f.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(jn==="stream")return{data:H.body,response:H};return{data:await H[jn](),response:H}}let Rn=await H.text();try{Rn=JSON.parse(Rn)}catch{}return{error:Rn,response:H}}return{request(T,Q,z){return N(Q,{...z,method:T.toUpperCase()})},GET(T,Q){return N(T,{...Q,method:"GET"})},PUT(T,Q){return N(T,{...Q,method:"PUT"})},POST(T,Q){return N(T,{...Q,method:"POST"})},DELETE(T,Q){return N(T,{...Q,method:"DELETE"})},OPTIONS(T,Q){return N(T,{...Q,method:"OPTIONS"})},HEAD(T,Q){return N(T,{...Q,method:"HEAD"})},PATCH(T,Q){return N(T,{...Q,method:"PATCH"})},TRACE(T,Q){return N(T,{...Q,method:"TRACE"})},use(...T){for(let Q of T){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()`");G.push(Q)}},eject(...T){for(let Q of T){let z=G.indexOf(Q);if(z!==-1)G.splice(z,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 $=[],E={simple:",",label:".",matrix:";"}[D.style]||"&";if(D.style!=="deepObject"&&D.explode===!1){for(let Y in k)$.push(Y,D.allowReserved===!0?k[Y]:encodeURIComponent(k[Y]));let M=$.join(",");switch(D.style){case"form":return`${n}=${M}`;case"label":return`.${M}`;case"matrix":return`;${n}=${M}`;default:return M}}for(let M in k){let Y=D.style==="deepObject"?`${n}[${M}]`:M;$.push(a(Y,k[M],D))}let X=$.join(E);return D.style==="label"||D.style==="matrix"?`${E}${X}`:X}function Sn(n,k,D){if(!Array.isArray(k))return"";if(D.explode===!1){let X={form:",",spaceDelimited:"%20",pipeDelimited:"|"}[D.style]||",",M=(D.allowReserved===!0?k:k.map((Y)=>encodeURIComponent(Y))).join(X);switch(D.style){case"simple":return M;case"label":return`.${M}`;case"matrix":return`;${n}=${M}`;default:return`${n}=${M}`}}let $={simple:",",label:".",matrix:";"}[D.style]||"&",E=[];for(let X of k)if(D.style==="simple"||D.style==="label")E.push(D.allowReserved===!0?X:encodeURIComponent(X));else E.push(a(n,X,D));return D.style==="label"||D.style==="matrix"?`${$}${E.join($)}`:E.join($)}function fn(n){return function(D){let $=[];if(D&&typeof D==="object")for(let E in D){let X=D[E];if(X===void 0||X===null)continue;if(Array.isArray(X)){if(X.length===0)continue;$.push(Sn(E,X,{style:"form",explode:!0,...n?.array,allowReserved:n?.allowReserved||!1}));continue}if(typeof X==="object"){$.push(On(E,X,{style:"deepObject",explode:!0,...n?.object,allowReserved:n?.allowReserved||!1}));continue}$.push(a(E,X,n))}return $.join("&")}}function mk(n,k){let D=n;for(let $ of n.match(bk)??[]){let E=$.substring(1,$.length-1),X=!1,M="simple";if(E.endsWith("*"))X=!0,E=E.substring(0,E.length-1);if(E.startsWith("."))M="label",E=E.substring(1);else if(E.startsWith(";"))M="matrix",E=E.substring(1);if(!k||k[E]===void 0||k[E]===null)continue;let Y=k[E];if(Array.isArray(Y)){D=D.replace($,Sn(E,Y,{style:M,explode:X}));continue}if(typeof Y==="object"){D=D.replace($,On(E,Y,{style:M,explode:X}));continue}if(M==="matrix"){D=D.replace($,`;${a(E,Y)}`);continue}D=D.replace($,M==="label"?`.${encodeURIComponent(Y)}`:encodeURIComponent(Y))}return D}function vk(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 dk(n,k){let D=`${k.baseUrl}${n}`;if(k.params?.path)D=mk(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[E,X]of $)if(X===null)k.delete(E);else if(Array.isArray(X))for(let M of X)k.append(E,M);else if(X!==void 0)k.set(E,X)}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 x(n,k){if(n.error!==void 0&&n.error!==null){let D=n.response?.status??0,$=n.response?.url??"",E=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(E),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 x(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 x(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 x(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 x(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 x(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 x(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 x($,"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 x(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 x(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 x(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 x(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 x($,"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 x(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 x(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 x(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 x(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 x($,"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 x(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 x(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 x(D,"bookings.get")}}class En{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 x(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 x(D,"orders.get")}}class Mn{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 x(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 x(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 x(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 x($,"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 x(D,"quotes.delete")}}var ik="https://vcity.io";function ok(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(E){if(!n)return D(E);if(E.headers.has("Authorization"))return D(E);let X=new Headers(E.headers);X.set("Authorization",`Bearer ${n}`);let M=new Request(E,{headers:X});return D(M)}}class Nn{raw;me;orgs;products;events;rooms;bookings;orders;quotes;constructor(n={}){let k=n.baseUrl??ik,D=ok(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 En(this.raw),this.quotes=new Mn(this.raw)}}function _n(n={}){return new Nn(n)}import P from"node:fs";import hk from"node:os";import Xn from"node:path";function w(){if(process.env.VCITY_CONFIG_DIR)return Xn.resolve(process.env.VCITY_CONFIG_DIR);return Xn.join(hk.homedir(),".vcity")}function Yn(){return Xn.join(w(),"auth.json")}function Bn(){return Xn.join(w(),"config.json")}function Fn(){return process.env.VCITY_API_BASE_URL||process.env.VCITY_PUBLIC_URL||"https://vcity.io"}var uk=/\x1b(?:\[[0-?]*[ -/]*[@-~]|\][^\x07\x1b]*(?:\x07|\x1b\\)|[P_^X][^\x07\x1b]*(?:\x07|\x1b\\)|[^[\]P_^X])/g,tk=/[\x00-\x08\x0b-\x1f\x7f]/g;function V(n){return n.replace(uk,"").replace(tk,"")}function bn(n){let k;try{k=new URL(n)}catch{throw Error(`Refusing to open malformed URL: ${V(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 B(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 Zn(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 rk(){let n=w();P.mkdirSync(n,{recursive:!0,mode:448});try{P.chmodSync(n,448)}catch{}}function pk(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 Gn(){let n=Yn();if(!P.existsSync(n))return;try{let k=JSON.parse(P.readFileSync(n,"utf-8"));if(!pk(k))return;return Zn(k.api_base_url),k}catch{return}}function Wn(n){rk();let k=Yn();P.writeFileSync(k,JSON.stringify(n,null,2),{mode:384});try{P.chmodSync(k,384)}catch{}}function m(){let n=Yn();if(P.existsSync(n))P.rmSync(n)}function cn(){let n=Gn();if(!n)throw Error("Not logged in. Run `vcity login` first.");return n}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){let $=new URL(k.startsWith("/")?k:`/${k}`,n);if(D){for(let[E,X]of Object.entries(D))if(X!==void 0&&X!==null&&!Number.isNaN(X))$.searchParams.set(E,String(X))}return $.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})});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 Wn($),$}catch{return}}async function h(n,k={}){let{authed:D=!0,method:$="GET",body:E,query:X,baseUrl:M}=k,Y=D?cn():void 0,Z=M??Y?.api_base_url??"https://vcity.io",G={"content-type":"application/json"};if(Y)G.authorization=`Bearer ${Y.access_token}`;let N=await fetch(vn(Z,n,X),{method:$,headers:G,body:E===void 0?void 0:JSON.stringify(E)}),Q=(N.headers.get("content-type")??"").includes("application/json")?await N.json().catch(()=>{return}):await N.text().catch(()=>{return});if(!N.ok){let z=(Q&&typeof Q==="object"&&"error"in Q?String(Q.error):void 0)??`Request failed (${N.status})`;throw new o(N.status,Q,z)}return Q}function lk(){let n=async(k,D)=>{let $=new Headers(k.headers);$.set("authorization",`Bearer ${D}`);let E=new Request(k,{headers:$});return globalThis.fetch(E)};return async function(D){let $=cn();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 M=await mn($);if(!M)throw m(),new o(401,void 0,"Session expired. Run `vcity login` again.");$=M}let E=await n(D,$.access_token);if(E.status!==401)return E;let X=await mn($);if(!X)throw m(),new o(401,void 0,"Session expired. Run `vcity login` again.");return $=X,n(D,$.access_token)}}var yn;function J(){if(yn)return yn;let n=cn();return yn=_n({baseUrl:n.api_base_url,fetch:lk()}),yn}function A(n){if(n==null)return"";return new Date(n).toISOString().replace("T"," ").slice(0,16)}import v from"node:fs";function ak(){let n=w();v.mkdirSync(n,{recursive:!0,mode:448});try{v.chmodSync(n,448)}catch{}}function F(){let n=Bn();if(!v.existsSync(n))return{};try{return JSON.parse(v.readFileSync(n,"utf-8"))}catch{return{}}}function dn(n){ak();let D={...F(),...n},$=Bn();v.writeFileSync($,JSON.stringify(D,null,2),{mode:384});try{v.chmodSync($,384)}catch{}return D}function j(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 c(n){if(n)return"json";if(!process.stdout.isTTY)return"json";return"pretty"}function y(n){process.stdout.write(`${JSON.stringify(n,null,2)}
|
|
3
|
-
`)}function
|
|
4
|
-
`)}function
|
|
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)} ${
|
|
6
|
-
`)}}async function
|
|
7
|
-
`),R(
|
|
8
|
-
`),R(
|
|
9
|
-
`);return}}let
|
|
10
|
-
`)}import{setTimeout as
|
|
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(`
|
|
11
11
|
Open this URL to approve the session:
|
|
12
|
-
${
|
|
12
|
+
${X.toString()}
|
|
13
13
|
`),process.stdout.write(`Enter this code:
|
|
14
|
-
${
|
|
14
|
+
${T($.user_code)}
|
|
15
15
|
|
|
16
16
|
`),process.stdout.write(`Waiting for approval…
|
|
17
|
-
`)
|
|
18
|
-
Logged in as ${
|
|
19
|
-
`);return}throw Error(`Login ${
|
|
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
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
|
|
22
|
-
`)}async function
|
|
23
|
-
`),R(
|
|
24
|
-
`),R(
|
|
25
|
-
`);return}}let
|
|
26
|
-
`)}var
|
|
27
|
-
`),R(
|
|
28
|
-
`),R(
|
|
29
|
-
`);return}}let
|
|
30
|
-
`)}async function
|
|
31
|
-
`),R(
|
|
32
|
-
`),R(
|
|
33
|
-
`);return}}let
|
|
34
|
-
`)}import{spawn as
|
|
35
|
-
`),process.stdout.write(` curl -fsSL ${
|
|
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
|
|
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: ${
|
|
43
|
-
`),!
|
|
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.
|
|
44
44
|
`);return}process.stdout.write(`install: ${D==="binary"?"standalone binary":"npm global"}
|
|
45
45
|
`)}if(n.check)return;if(!n.yes&&k!=="json"){if(process.stdout.write(`
|
|
46
46
|
Run with --yes to apply the update, or use the command below:
|
|
47
|
-
`),D==="binary")
|
|
47
|
+
`),D==="binary")_k();else process.stdout.write(` npm install -g ${d}@latest
|
|
48
48
|
`);return}if(D==="binary"){if(k!=="json")process.stdout.write(`
|
|
49
49
|
This CLI was installed from a standalone binary.
|
|
50
|
-
`),
|
|
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(`
|
|
51
51
|
Installing latest from npm…
|
|
52
|
-
`);let{exitCode:
|
|
53
|
-
Updated to ${
|
|
54
|
-
`)}function
|
|
55
|
-
`),process.stdout.write(`User ID: ${
|
|
56
|
-
`),process.stdout.write(`Active org: ${
|
|
57
|
-
`)}var cD=new Set(["json","yes","check","no-browser","disabled"]);function
|
|
58
|
-
→ vcity ${
|
|
59
|
-
`)}function
|
|
60
|
-
`),process.exit(1)}function
|
|
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}
|
|
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[k,D,...$]=n,
|
|
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)}
|
|
103
103
|
`),process.exit(1)});
|