@vcityio/cli 0.3.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/README.md +7 -3
- package/dist/index.js +60 -45
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -88,6 +88,9 @@ Every read command accepts `--json` for scripting. Output auto-falls-back to JSO
|
|
|
88
88
|
| `vcity orders get <id> [--org <slug>] [--json]` | Print a single order. |
|
|
89
89
|
| `vcity quotes list [--org <slug>] [--limit <n>] [--status <s>] [--json]` | List quote requests. |
|
|
90
90
|
| `vcity quotes get <id> [--org <slug>] [--json]` | Print a single quote. |
|
|
91
|
+
| `vcity quotes create [--name --email --product --quantity --phone --variation --company --note --data]` | Create a quote request. |
|
|
92
|
+
| `vcity quotes update <id> [--status --assignee --name --email --product --quantity --phone --variation --company --note --data]` | Patch quote fields. |
|
|
93
|
+
| `vcity quotes delete <id> [--yes] [--json]` | Delete a quote. Asks y/N unless `--yes`. |
|
|
91
94
|
| `vcity update [--check] [--yes] [--json]` | Self-update the CLI binary. |
|
|
92
95
|
|
|
93
96
|
### `--data` flag
|
|
@@ -103,9 +106,10 @@ two to start from a template file and override one field per invocation.
|
|
|
103
106
|
### Delete safety
|
|
104
107
|
|
|
105
108
|
Delete commands ask `y/N` before sending the request. Pass `--yes` to skip the
|
|
106
|
-
prompt (required in `--json` / non-TTY mode).
|
|
107
|
-
record stays in the database with `deletedAt` set,
|
|
108
|
-
it out.
|
|
109
|
+
prompt (required in `--json` / non-TTY mode). `products` / `events` / `rooms`
|
|
110
|
+
deletes are **soft** — the record stays in the database with `deletedAt` set,
|
|
111
|
+
and read endpoints filter it out. `quotes delete` is **permanent** — the
|
|
112
|
+
record is removed outright.
|
|
109
113
|
|
|
110
114
|
## Environment variables
|
|
111
115
|
|
package/dist/index.js
CHANGED
|
@@ -1,53 +1,63 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{createRequire as Bc}from"node:module";var Cc=Bc(import.meta.url);var Hc=/\{[^{}]+\}/g,wc=()=>{return typeof process==="object"&&Number.parseInt(process?.versions?.node?.substring(0,2))>=18&&process.versions.undici};function Uc(){return Math.random().toString(36).slice(2,11)}function Rn(n){let{baseUrl:c="",Request:k=globalThis.Request,fetch:o=globalThis.fetch,querySerializer:D,bodySerializer:g,headers:f,requestInitExt:y=void 0,...$}={...n};y=wc()?y:void 0,c=mn(c);let x=[];async function X(J,j){let{baseUrl:B,fetch:Nn=o,Request:_k=k,headers:Bn,params:q={},parseAs:Mn="json",querySerializer:d,bodySerializer:Cn=g??Lc,body:Hn,...En}=j||{},Yn=c;if(B)Yn=mn(B)??c;let Jn=typeof D==="function"?D:wn(D);if(d)Jn=typeof d==="function"?d:wn({...typeof D==="object"?D:{},...d});let Gn=Hn===void 0?void 0:Cn(Hn,Un(f,Bn,q.header)),Vc=Un(Gn===void 0||Gn instanceof FormData?{}:{"Content-Type":"application/json"},f,Bn,q.header),Nc={redirect:"follow",...$,...En,body:Gn,headers:Vc},u,r,w=new k(Sc(J,{baseUrl:Yn,params:q,querySerializer:Jn}),Nc),W;for(let Q in En)if(!(Q in w))w[Q]=En[Q];if(x.length){u=Uc(),r=Object.freeze({baseUrl:Yn,fetch:Nn,parseAs:Mn,querySerializer:Jn,bodySerializer:Cn});for(let Q of x)if(Q&&typeof Q==="object"&&typeof Q.onRequest==="function"){let Z=await Q.onRequest({request:w,schemaPath:J,params:q,options:r,id:u});if(Z)if(Z instanceof k)w=Z;else if(Z instanceof Response){W=Z;break}else throw Error("onRequest: must return new Request() or Response() when modifying the request")}}if(!W){try{W=await Nn(w,y)}catch(Q){let Z=Q;if(x.length)for(let L=x.length-1;L>=0;L--){let h=x[L];if(h&&typeof h==="object"&&typeof h.onError==="function"){let I=await h.onError({request:w,error:Z,schemaPath:J,params:q,options:r,id:u});if(I){if(I instanceof Response){Z=void 0,W=I;break}if(I instanceof Error){Z=I;continue}throw Error("onError: must return new Response() or instance of Error")}}}if(Z)throw Z}if(x.length)for(let Q=x.length-1;Q>=0;Q--){let Z=x[Q];if(Z&&typeof Z==="object"&&typeof Z.onResponse==="function"){let L=await Z.onResponse({request:w,response:W,schemaPath:J,params:q,options:r,id:u});if(L){if(!(L instanceof Response))throw Error("onResponse: must return new Response() when modifying the response");W=L}}}}if(W.status===204||w.method==="HEAD"||W.headers.get("Content-Length")==="0")return W.ok?{data:void 0,response:W}:{error:void 0,response:W};if(W.ok){if(Mn==="stream")return{data:W.body,response:W};return{data:await W[Mn](),response:W}}let Tn=await W.text();try{Tn=JSON.parse(Tn)}catch{}return{error:Tn,response:W}}return{request(J,j,B){return X(j,{...B,method:J.toUpperCase()})},GET(J,j){return X(J,{...j,method:"GET"})},PUT(J,j){return X(J,{...j,method:"PUT"})},POST(J,j){return X(J,{...j,method:"POST"})},DELETE(J,j){return X(J,{...j,method:"DELETE"})},OPTIONS(J,j){return X(J,{...j,method:"OPTIONS"})},HEAD(J,j){return X(J,{...j,method:"HEAD"})},PATCH(J,j){return X(J,{...j,method:"PATCH"})},TRACE(J,j){return X(J,{...j,method:"TRACE"})},use(...J){for(let j of J){if(!j)continue;if(typeof j!=="object"||!(("onRequest"in j)||("onResponse"in j)||("onError"in j)))throw Error("Middleware must be an object with one of `onRequest()`, `onResponse() or `onError()`");x.push(j)}},eject(...J){for(let j of J){let B=x.indexOf(j);if(B!==-1)x.splice(B,1)}}}}function p(n,c,k){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}=${k?.allowReserved===!0?c:encodeURIComponent(c)}`}function Ln(n,c,k){if(!c||typeof c!=="object")return"";let o=[],D={simple:",",label:".",matrix:";"}[k.style]||"&";if(k.style!=="deepObject"&&k.explode===!1){for(let y in c)o.push(y,k.allowReserved===!0?c[y]:encodeURIComponent(c[y]));let f=o.join(",");switch(k.style){case"form":return`${n}=${f}`;case"label":return`.${f}`;case"matrix":return`;${n}=${f}`;default:return f}}for(let f in c){let y=k.style==="deepObject"?`${n}[${f}]`:f;o.push(p(y,c[f],k))}let g=o.join(D);return k.style==="label"||k.style==="matrix"?`${D}${g}`:g}function Sn(n,c,k){if(!Array.isArray(c))return"";if(k.explode===!1){let g={form:",",spaceDelimited:"%20",pipeDelimited:"|"}[k.style]||",",f=(k.allowReserved===!0?c:c.map((y)=>encodeURIComponent(y))).join(g);switch(k.style){case"simple":return f;case"label":return`.${f}`;case"matrix":return`;${n}=${f}`;default:return`${n}=${f}`}}let o={simple:",",label:".",matrix:";"}[k.style]||"&",D=[];for(let g of c)if(k.style==="simple"||k.style==="label")D.push(k.allowReserved===!0?g:encodeURIComponent(g));else D.push(p(n,g,k));return k.style==="label"||k.style==="matrix"?`${o}${D.join(o)}`:D.join(o)}function wn(n){return function(k){let o=[];if(k&&typeof k==="object")for(let D in k){let g=k[D];if(g===void 0||g===null)continue;if(Array.isArray(g)){if(g.length===0)continue;o.push(Sn(D,g,{style:"form",explode:!0,...n?.array,allowReserved:n?.allowReserved||!1}));continue}if(typeof g==="object"){o.push(Ln(D,g,{style:"deepObject",explode:!0,...n?.object,allowReserved:n?.allowReserved||!1}));continue}o.push(p(D,g,n))}return o.join("&")}}function mc(n,c){let k=n;for(let o of n.match(Hc)??[]){let D=o.substring(1,o.length-1),g=!1,f="simple";if(D.endsWith("*"))g=!0,D=D.substring(0,D.length-1);if(D.startsWith("."))f="label",D=D.substring(1);else if(D.startsWith(";"))f="matrix",D=D.substring(1);if(!c||c[D]===void 0||c[D]===null)continue;let y=c[D];if(Array.isArray(y)){k=k.replace(o,Sn(D,y,{style:f,explode:g}));continue}if(typeof y==="object"){k=k.replace(o,Ln(D,y,{style:f,explode:g}));continue}if(f==="matrix"){k=k.replace(o,`;${p(D,y)}`);continue}k=k.replace(o,f==="label"?`.${encodeURIComponent(y)}`:encodeURIComponent(y))}return k}function Lc(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 Sc(n,c){let k=`${c.baseUrl}${n}`;if(c.params?.path)k=mc(k,c.params.path);let o=c.querySerializer(c.params.query??{});if(o.startsWith("?"))o=o.substring(1);if(o)k+=`?${o}`;return k}function Un(...n){let c=new Headers;for(let k of n){if(!k||typeof k!=="object")continue;let o=k instanceof Headers?k.entries():Object.entries(k);for(let[D,g]of o)if(g===null)c.delete(D);else if(Array.isArray(g))for(let f of g)c.append(D,f);else if(g!==void 0)c.set(D,g)}return c}function mn(n){if(n.endsWith("/"))return n.substring(0,n.length-1);return n}class A extends Error{status;body;url;constructor(n,c,k,o){super(n);this.name="ApiClientError",this.status=c,this.body=k,this.url=o}}function T(n,c){if(n.error!==void 0&&n.error!==null){let k=n.response?.status??0,o=n.response?.url??"",D=typeof n.error==="object"&&n.error!==null&&"error"in n.error&&typeof n.error.error==="object"&&n.error.error?.message||`${c} failed (${k})`;throw new A(String(D),k,n.error,o)}if(n.data===void 0)throw new A(`${c}: empty response body`,n.response?.status??0,void 0,n.response?.url??"");return n.data}class s{client;constructor(n){this.client=n}async get(){let n=await this.client.GET("/api/v1/me",{});return T(n,"me.get")}}class e{client;constructor(n){this.client=n}async get(n){let c=await this.client.GET("/api/v1/orgs/{orgId}",{params:{path:{orgId:n}}});return T(c,"orgs.get")}async listMembers(n,c={}){let k=await this.client.GET("/api/v1/orgs/{orgId}/members",{params:{path:{orgId:n},query:c}});return T(k,"orgs.listMembers")}}class l{client;constructor(n){this.client=n}async list(n,c={}){let k=await this.client.GET("/api/v1/orgs/{orgId}/products",{params:{path:{orgId:n},query:c}});return T(k,"products.list")}async get(n,c){let k=await this.client.GET("/api/v1/orgs/{orgId}/products/{productId}",{params:{path:{orgId:n,productId:c}}});return T(k,"products.get")}async create(n,c){let k=await this.client.POST("/api/v1/orgs/{orgId}/products",{params:{path:{orgId:n}},body:c});return T(k,"products.create")}async update(n,c,k){let o=await this.client.PUT("/api/v1/orgs/{orgId}/products/{productId}",{params:{path:{orgId:n,productId:c}},body:k});return T(o,"products.update")}async delete(n,c){let k=await this.client.DELETE("/api/v1/orgs/{orgId}/products/{productId}",{params:{path:{orgId:n,productId:c}}});return T(k,"products.delete")}}class a{client;constructor(n){this.client=n}async list(n,c={}){let k=await this.client.GET("/api/v1/orgs/{orgId}/events",{params:{path:{orgId:n},query:c}});return T(k,"events.list")}async get(n,c){let k=await this.client.GET("/api/v1/orgs/{orgId}/events/{eventId}",{params:{path:{orgId:n,eventId:c}}});return T(k,"events.get")}async create(n,c){let k=await this.client.POST("/api/v1/orgs/{orgId}/events",{params:{path:{orgId:n}},body:c});return T(k,"events.create")}async update(n,c,k){let o=await this.client.PUT("/api/v1/orgs/{orgId}/events/{eventId}",{params:{path:{orgId:n,eventId:c}},body:k});return T(o,"events.update")}async delete(n,c){let k=await this.client.DELETE("/api/v1/orgs/{orgId}/events/{eventId}",{params:{path:{orgId:n,eventId:c}}});return T(k,"events.delete")}}class nn{client;constructor(n){this.client=n}async list(n,c={}){let k=await this.client.GET("/api/v1/orgs/{orgId}/rooms",{params:{path:{orgId:n},query:c}});return T(k,"rooms.list")}async get(n,c){let k=await this.client.GET("/api/v1/orgs/{orgId}/rooms/{roomId}",{params:{path:{orgId:n,roomId:c}}});return T(k,"rooms.get")}async create(n,c){let k=await this.client.POST("/api/v1/orgs/{orgId}/rooms",{params:{path:{orgId:n}},body:c});return T(k,"rooms.create")}async update(n,c,k){let o=await this.client.PUT("/api/v1/orgs/{orgId}/rooms/{roomId}",{params:{path:{orgId:n,roomId:c}},body:k});return T(o,"rooms.update")}async delete(n,c){let k=await this.client.DELETE("/api/v1/orgs/{orgId}/rooms/{roomId}",{params:{path:{orgId:n,roomId:c}}});return T(k,"rooms.delete")}}class cn{client;constructor(n){this.client=n}async list(n,c={}){let k=await this.client.GET("/api/v1/orgs/{orgId}/bookings",{params:{path:{orgId:n},query:c}});return T(k,"bookings.list")}async get(n,c){let k=await this.client.GET("/api/v1/orgs/{orgId}/bookings/{bookingId}",{params:{path:{orgId:n,bookingId:c}}});return T(k,"bookings.get")}}class kn{client;constructor(n){this.client=n}async list(n,c={}){let k=await this.client.GET("/api/v1/orgs/{orgId}/orders",{params:{path:{orgId:n},query:c}});return T(k,"orders.list")}async get(n,c){let k=await this.client.GET("/api/v1/orgs/{orgId}/orders/{orderId}",{params:{path:{orgId:n,orderId:c}}});return T(k,"orders.get")}}class on{client;constructor(n){this.client=n}async list(n,c={}){let k=await this.client.GET("/api/v1/orgs/{orgId}/quotes",{params:{path:{orgId:n},query:c}});return T(k,"quotes.list")}async get(n,c){let k=await this.client.GET("/api/v1/orgs/{orgId}/quotes/{quoteId}",{params:{path:{orgId:n,quoteId:c}}});return T(k,"quotes.get")}}var qc="https://vcity.io";function Ac(n,c){let k=c??globalThis.fetch;if(!k)throw Error("@vcityio/api-client: no fetch implementation found. Provide options.fetch or run on Node >=20 / a browser.");return async function(D){if(!n)return k(D);if(D.headers.has("Authorization"))return k(D);let g=new Headers(D.headers);g.set("Authorization",`Bearer ${n}`);let f=new Request(D,{headers:g});return k(f)}}class Wn{raw;me;orgs;products;events;rooms;bookings;orders;quotes;constructor(n={}){let c=n.baseUrl??qc,k=Ac(n.token,n.fetch),o={baseUrl:c,fetch:k,headers:n.headers};this.raw=Rn(o),this.me=new s(this.raw),this.orgs=new e(this.raw),this.products=new l(this.raw),this.events=new a(this.raw),this.rooms=new nn(this.raw),this.bookings=new cn(this.raw),this.orders=new kn(this.raw),this.quotes=new on(this.raw)}}function _n(n={}){return new Wn(n)}import U from"node:fs";import zc from"node:os";import Xn from"node:path";function C(){if(process.env.VCITY_CONFIG_DIR)return process.env.VCITY_CONFIG_DIR;return Xn.join(zc.homedir(),".vcity")}function Dn(){return Xn.join(C(),"auth.json")}function Zn(){return Xn.join(C(),"config.json")}function qn(){return process.env.VCITY_API_BASE_URL||process.env.VCITY_PUBLIC_URL||"https://vcity.io"}function Oc(){let n=C();if(!U.existsSync(n))U.mkdirSync(n,{recursive:!0,mode:448})}function gn(){let n=Dn();if(!U.existsSync(n))return;try{return JSON.parse(U.readFileSync(n,"utf-8"))}catch{return}}function fn(n){Oc();let c=Dn();U.writeFileSync(c,JSON.stringify(n,null,2),{mode:384});try{U.chmodSync(c,384)}catch{}}function z(){let n=Dn();if(U.existsSync(n))U.rmSync(n)}function yn(){let n=gn();if(!n)throw Error("Not logged in. Run `vcity login` first.");return n}class t extends Error{status;body;constructor(n,c,k){super(k??`HTTP ${n}`);this.status=n;this.body=c;this.name="ApiError"}}function zn(n,c,k){let o=new URL(c.startsWith("/")?c:`/${c}`,n);if(k){for(let[D,g]of Object.entries(k))if(g!==void 0&&g!==null&&!Number.isNaN(g))o.searchParams.set(D,String(g))}return o.toString()}async function An(n){try{let c=await fetch(zn(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 k=await c.json(),o={...n,access_token:k.access_token,refresh_token:k.refresh_token,access_expires_at:k.access_expires_at,refresh_expires_at:k.refresh_expires_at};return fn(o),o}catch{return}}async function v(n,c={}){let{authed:k=!0,method:o="GET",body:D,query:g,baseUrl:f}=c,y=k?yn():void 0,$=f??y?.api_base_url??"https://vcity.io",x={"content-type":"application/json"};if(y)x.authorization=`Bearer ${y.access_token}`;let X=await fetch(zn($,n,g),{method:o,headers:x,body:D===void 0?void 0:JSON.stringify(D)}),j=(X.headers.get("content-type")??"").includes("application/json")?await X.json().catch(()=>{return}):await X.text().catch(()=>{return});if(!X.ok){let B=(j&&typeof j==="object"&&"error"in j?String(j.error):void 0)??`Request failed (${X.status})`;throw new t(X.status,j,B)}return j}function Pc(){let n=async(c,k)=>{let o=new Headers(c.headers);o.set("authorization",`Bearer ${k}`);let D=new Request(c,{headers:o});return globalThis.fetch(D)};return async function(k){let o=yn();if(Date.now()>=o.access_expires_at){if(Date.now()>=o.refresh_expires_at)throw z(),new t(401,void 0,"Session expired. Run `vcity login` again.");let f=await An(o);if(!f)throw z(),new t(401,void 0,"Session expired. Run `vcity login` again.");o=f}let D=await n(k,o.access_token);if(D.status!==401)return D;let g=await An(o);if(!g)throw z(),new t(401,void 0,"Session expired. Run `vcity login` again.");return o=g,n(k,o.access_token)}}var $n;function E(){if($n)return $n;let n=yn();return $n=_n({baseUrl:n.api_base_url,fetch:Pc()}),$n}function m(n){if(n==null)return"";return new Date(n).toISOString().replace("T"," ").slice(0,16)}import O from"node:fs";function Fc(){let n=C();if(!O.existsSync(n))O.mkdirSync(n,{recursive:!0,mode:448})}function S(){let n=Zn();if(!O.existsSync(n))return{};try{return JSON.parse(O.readFileSync(n,"utf-8"))}catch{return{}}}function On(n){Fc();let k={...S(),...n},o=Zn();O.writeFileSync(o,JSON.stringify(k,null,2),{mode:384});try{O.chmodSync(o,384)}catch{}return k}function G(n){if(n)return n;let c=S();if(!c.active_org)throw Error("No active org. Run `vcity org use <slug>` or pass --org <slug>.");return c.active_org}var bc=/\x1b(?:\[[0-?]*[ -/]*[@-~]|\][^\x07\x1b]*(?:\x07|\x1b\\)|[P_^X][^\x07\x1b]*(?:\x07|\x1b\\)|[^[\]P_^X])/g,Ic=/[\x00-\x08\x0b-\x1f\x7f]/g;function K(n){return n.replace(bc,"").replace(Ic,"")}function Pn(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 i(n){if(n)return"json";if(!process.stdout.isTTY)return"json";return"pretty"}function M(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
|
-
`)}
|
|
31
|
-
`),process.stdout.write(`
|
|
32
|
-
`)
|
|
33
|
-
`);return}process.stdout.write(`
|
|
34
|
-
`)}
|
|
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(`
|
|
35
46
|
Run with --yes to apply the update, or use the command below:
|
|
36
|
-
`),
|
|
37
|
-
`);
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
`);let{exitCode:y}=await Dk();if(y!==0)throw Error(`installer exited with code ${y}`)}else{if(!await ok("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(`
|
|
41
51
|
Installing latest from npm…
|
|
42
|
-
`);let{exitCode:
|
|
43
|
-
Updated to ${
|
|
44
|
-
`)}function
|
|
45
|
-
`),process.stdout.write(`User ID: ${
|
|
46
|
-
`),process.stdout.write(`Active org: ${
|
|
47
|
-
`)}var
|
|
48
|
-
→ vcity ${
|
|
49
|
-
`)}function
|
|
50
|
-
`),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}
|
|
51
61
|
|
|
52
62
|
Usage:
|
|
53
63
|
vcity login [--api-base-url <url>] [--no-browser]
|
|
@@ -55,6 +65,8 @@ Usage:
|
|
|
55
65
|
vcity whoami [--json]
|
|
56
66
|
vcity org list [--json]
|
|
57
67
|
vcity org use <slug>
|
|
68
|
+
vcity org get <id> [--json]
|
|
69
|
+
vcity org members list [--org <slug>] [--limit <n>] [--json]
|
|
58
70
|
vcity products list [--org <slug>] [--limit <n>] [--json]
|
|
59
71
|
vcity products get <id> [--org <slug>] [--json]
|
|
60
72
|
vcity products create [--org <slug>] [--name <s>] [--price <n>] [--currency <c>] [--sku <s>] [--data <json|@file>] [--json]
|
|
@@ -76,6 +88,9 @@ Usage:
|
|
|
76
88
|
vcity orders get <id> [--org <slug>] [--json]
|
|
77
89
|
vcity quotes list [--org <slug>] [--limit <n>] [--status PENDING|IN_PROGRESS|SUBMITTED|CANCELED|ORDERED] [--json]
|
|
78
90
|
vcity quotes get <id> [--org <slug>] [--json]
|
|
91
|
+
vcity quotes create [--org <slug>] [--name <s>] [--email <s>] [--product <id>] [--quantity <n>] [--phone <s>] [--variation <s>] [--company <s>] [--note <s>] [--data <json|@file>] [--json]
|
|
92
|
+
vcity quotes update <id> [--org <slug>] [--status <s>] [--assignee <uid>] [--name <s>] [--email <s>] [--product <id>] [--quantity <n>] [--phone <s>] [--variation <s>] [--company <s>] [--note <s>] [--data <json|@file>] [--json]
|
|
93
|
+
vcity quotes delete <id> [--org <slug>] [--yes] [--json]
|
|
79
94
|
vcity update [--check] [--yes] [--json]
|
|
80
95
|
|
|
81
96
|
Environment:
|
|
@@ -83,6 +98,6 @@ Environment:
|
|
|
83
98
|
VCITY_CONFIG_DIR override the config directory (default ~/.vcity)
|
|
84
99
|
VCITY_NO_OPEN_BROWSER never auto-launch a browser during \`vcity login\`
|
|
85
100
|
VCITY_NO_UPDATE_CHECK disable the background "new version available" check
|
|
86
|
-
`)}function
|
|
87
|
-
`);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)}
|
|
88
103
|
`),process.exit(1)});
|