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