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