@vcityio/cli 0.1.0 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +81 -3
  2. package/dist/index.js +68 -21
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -5,10 +5,38 @@ Official command-line interface for [vcity](https://vcity.io). Modeled after `gh
5
5
  ## Install
6
6
 
7
7
  ```bash
8
+ # Standalone binary — no Node, no bun, nothing else required
9
+ curl -fsSL https://vcity.io/cli/install.sh | sh
10
+
11
+ # OR via npm (Node 20+)
8
12
  npm install -g @vcityio/cli
9
13
  ```
10
14
 
11
- Requires **Node 20+**. Standalone binaries (no Node required) ship in a future release.
15
+ The curl installer detects your platform (`darwin-arm64`, `darwin-x64`, `linux-x64`, `linux-arm64`, `windows-x64`), downloads the matching binary from GitHub Releases, and drops it into `/usr/local/bin/vcity`. Falls back to `npm install -g` if your platform doesn't have a published binary.
16
+
17
+ Pin a specific version or install dir:
18
+
19
+ ```bash
20
+ VCITY_CLI_VERSION=0.1.0 curl -fsSL https://vcity.io/cli/install.sh | sh
21
+ VCITY_CLI_INSTALL_DIR=$HOME/.local/bin curl -fsSL https://vcity.io/cli/install.sh | sh
22
+ VCITY_CLI_FORCE_NPM=1 curl -fsSL https://vcity.io/cli/install.sh | sh
23
+ ```
24
+
25
+ ## Uninstall
26
+
27
+ ```bash
28
+ curl -fsSL https://vcity.io/cli/uninstall.sh | sh
29
+ ```
30
+
31
+ Auto-detects how you installed (binary in `/usr/local/bin` or npm-global) and removes both. Also wipes `~/.vcity` (auth tokens + config) by default — set `VCITY_CLI_KEEP_CONFIG=1` to keep your tokens, or `VCITY_CLI_FORCE=1` to skip the confirmation prompt when run interactively.
32
+
33
+ Manual paths if you prefer:
34
+
35
+ ```bash
36
+ sudo rm /usr/local/bin/vcity # binary install
37
+ npm uninstall -g @vcityio/cli # npm install
38
+ rm -rf ~/.vcity # local config + tokens
39
+ ```
12
40
 
13
41
  ## First run
14
42
 
@@ -41,8 +69,43 @@ Every read command accepts `--json` for scripting. Output auto-falls-back to JSO
41
69
  | `vcity org use <slug>` | Set the active org. |
42
70
  | `vcity products list [--org <slug>] [--limit <n>] [--json]` | List products of the active org. |
43
71
  | `vcity products get <id> [--org <slug>] [--json]` | Print a single product. |
44
-
45
- More commands (events, bookings, quotes, product mutations + bulk import) land in v0.2.
72
+ | `vcity products create [--name --price --currency --sku --data @file] [--json]` | Create a product. `--data` seeds the body; named flags override. |
73
+ | `vcity products update <id> [--name --price --currency --sku --visibility --availability --data]` | Patch product fields. |
74
+ | `vcity products delete <id> [--yes] [--json]` | Soft-delete a product. Asks y/N unless `--yes`. |
75
+ | `vcity events list [--org <slug>] [--limit <n>] [--status active\|disabled] [--json]` | List events. |
76
+ | `vcity events get <id> [--org <slug>] [--json]` | Print a single event. |
77
+ | `vcity events create [--name --starts-at --ends-at --slug --data]` | Create an event. `--starts-at` / `--ends-at` accept ISO or epoch-ms. |
78
+ | `vcity events update <id> [--name --starts-at --ends-at --slug --status --data]` | Patch event fields. |
79
+ | `vcity events delete <id> [--yes]` | Soft-delete an event. |
80
+ | `vcity rooms list [--org <slug>] [--limit <n>] [--json]` | List rooms. |
81
+ | `vcity rooms get <id> [--org <slug>] [--json]` | Print a single room. |
82
+ | `vcity rooms create [--title --description --type --data]` | Create a room. |
83
+ | `vcity rooms update <id> [--title --description --type --disabled --data]` | Patch room fields. |
84
+ | `vcity rooms delete <id> [--yes]` | Soft-delete a room. |
85
+ | `vcity bookings list [--org <slug>] [--limit <n>] [--status <s>] [--json]` | List bookings. |
86
+ | `vcity bookings get <id> [--org <slug>] [--json]` | Print a single booking. |
87
+ | `vcity orders list [--org <slug>] [--limit <n>] [--status <s>] [--json]` | List orders. |
88
+ | `vcity orders get <id> [--org <slug>] [--json]` | Print a single order. |
89
+ | `vcity quotes list [--org <slug>] [--limit <n>] [--status <s>] [--json]` | List quote requests. |
90
+ | `vcity quotes get <id> [--org <slug>] [--json]` | Print a single quote. |
91
+ | `vcity update [--check] [--yes] [--json]` | Self-update the CLI binary. |
92
+
93
+ ### `--data` flag
94
+
95
+ Create / update commands accept `--data <jsonOrPath>`:
96
+
97
+ - Inline: `--data '{"name":"My Product","price":19.99}'`
98
+ - File: `--data @./product.json`
99
+
100
+ Named flags (`--name`, `--price`, …) override values in `--data`. Combine the
101
+ two to start from a template file and override one field per invocation.
102
+
103
+ ### Delete safety
104
+
105
+ Delete commands ask `y/N` before sending the request. Pass `--yes` to skip the
106
+ prompt (required in `--json` / non-TTY mode). All deletes are **soft** — the
107
+ record stays in the database with `deletedAt` set, and read endpoints filter
108
+ it out.
46
109
 
47
110
  ## Environment variables
48
111
 
@@ -51,9 +114,24 @@ More commands (events, bookings, quotes, product mutations + bulk import) land i
51
114
  | `VCITY_API_BASE_URL` | Override the API host (e.g. `https://staging.vcity.io`). |
52
115
  | `VCITY_CONFIG_DIR` | Override the config dir (default `~/.vcity`). Handy for sandboxing dev sessions. |
53
116
  | `VCITY_NO_OPEN_BROWSER` | Never auto-launch a browser during `vcity login`. |
117
+ | `VCITY_NO_UPDATE_CHECK` | Disable the background "new version available" check. |
54
118
 
55
119
  CI tip: `vcity` detects non-interactive stdout and emits JSON without `--json`. Combine with `jq` for pipelines.
56
120
 
121
+ ### Update notifications
122
+
123
+ `vcity` checks the npm registry once every 24h (cached at
124
+ `~/.vcity/update-check.json`) for a newer release. When one exists, a one-line
125
+ banner is printed to stderr after the command finishes:
126
+
127
+ ```
128
+ → vcity 0.3.0 available (you have 0.2.1). Run `vcity update` to upgrade.
129
+ ```
130
+
131
+ The check is silent when piped or non-interactive, in `--json` mode, when
132
+ running `vcity update` itself, or when `VCITY_NO_UPDATE_CHECK=1` is set. The
133
+ fetch has a 1.5s timeout and never blocks command output.
134
+
57
135
  ## Authentication
58
136
 
59
137
  The CLI uses **device-flow** tokens (`vcli_…`) issued through the vcity web app. They inherit your user's org permissions. Refresh tokens rotate single-use — token theft revokes the entire session.
package/dist/index.js CHANGED
@@ -1,27 +1,53 @@
1
1
  #!/usr/bin/env node
2
- import{createRequire as Zo}from"node:module";var bo=Zo(import.meta.url);import{setTimeout as uo}from"node:timers/promises";import E from"node:fs";import ko from"node:os";import co from"node:path";function G(){if(process.env.VCITY_CONFIG_DIR)return process.env.VCITY_CONFIG_DIR;return co.join(ko.homedir(),".vcity")}function M(){return co.join(G(),"auth.json")}function to(){return co.join(G(),"config.json")}function mo(){return process.env.VCITY_API_BASE_URL||process.env.VCITY_PUBLIC_URL||"https://vcity.io"}function vo(){let o=G();if(!E.existsSync(o))E.mkdirSync(o,{recursive:!0,mode:448})}function v(){let o=M();if(!E.existsSync(o))return;try{return JSON.parse(E.readFileSync(o,"utf-8"))}catch{return}}function A(o){vo();let g=M();E.writeFileSync(g,JSON.stringify(o,null,2),{mode:384});try{E.chmodSync(g,384)}catch{}}function B(){let o=M();if(E.existsSync(o))E.rmSync(o)}function Q(){let o=v();if(!o)throw Error(`Not logged in. Run \`vcity login\` first.
3
- Auth file expected at ${M()}.`);return o}var Ao=/\{[^{}]+\}/g,Bo=()=>{return typeof process==="object"&&Number.parseInt(process?.versions?.node?.substring(0,2))>=18&&process.versions.undici};function Qo(){return Math.random().toString(36).slice(2,11)}function fo(o){let{baseUrl:g="",Request:n=globalThis.Request,fetch:t=globalThis.fetch,querySerializer:c,bodySerializer:i,headers:f,requestInitExt:y=void 0,...r}={...o};y=Bo()?y:void 0,g=No(g);let x=[];async function m(_,C){let{baseUrl:w,fetch:_o=t,Request:tn=n,headers:ro,params:Y={},parseAs:l="json",querySerializer:X,bodySerializer:xo=i??Ho,body:jo,...e}=C||{},a=g;if(w)a=No(w)??g;let oo=typeof c==="function"?c:Oo(c);if(X)oo=typeof X==="function"?X:Oo({...typeof c==="object"?c:{},...X});let no=jo===void 0?void 0:xo(jo,$o(f,ro,Y.header)),Ko=$o(no===void 0||no instanceof FormData?{}:{"Content-Type":"application/json"},f,ro,Y.header),Xo={redirect:"follow",...r,...e,body:no,headers:Ko},Z,b,T=new n(Io(_,{baseUrl:a,params:Y,querySerializer:oo}),Xo),j;for(let $ in e)if(!($ in T))T[$]=e[$];if(x.length){Z=Qo(),b=Object.freeze({baseUrl:a,fetch:_o,parseAs:l,querySerializer:oo,bodySerializer:xo});for(let $ of x)if($&&typeof $==="object"&&typeof $.onRequest==="function"){let O=await $.onRequest({request:T,schemaPath:_,params:Y,options:b,id:Z});if(O)if(O instanceof n)T=O;else if(O instanceof Response){j=O;break}else throw Error("onRequest: must return new Request() or Response() when modifying the request")}}if(!j){try{j=await _o(T,y)}catch($){let O=$;if(x.length)for(let J=x.length-1;J>=0;J--){let k=x[J];if(k&&typeof k==="object"&&typeof k.onError==="function"){let s=await k.onError({request:T,error:O,schemaPath:_,params:Y,options:b,id:Z});if(s){if(s instanceof Response){O=void 0,j=s;break}if(s instanceof Error){O=s;continue}throw Error("onError: must return new Response() or instance of Error")}}}if(O)throw O}if(x.length)for(let $=x.length-1;$>=0;$--){let O=x[$];if(O&&typeof O==="object"&&typeof O.onResponse==="function"){let J=await O.onResponse({request:T,response:j,schemaPath:_,params:Y,options:b,id:Z});if(J){if(!(J instanceof Response))throw Error("onResponse: must return new Response() when modifying the response");j=J}}}}if(j.status===204||T.method==="HEAD"||j.headers.get("Content-Length")==="0")return j.ok?{data:void 0,response:j}:{error:void 0,response:j};if(j.ok){if(l==="stream")return{data:j.body,response:j};return{data:await j[l](),response:j}}let go=await j.text();try{go=JSON.parse(go)}catch{}return{error:go,response:j}}return{request(_,C,w){return m(C,{...w,method:_.toUpperCase()})},GET(_,C){return m(_,{...C,method:"GET"})},PUT(_,C){return m(_,{...C,method:"PUT"})},POST(_,C){return m(_,{...C,method:"POST"})},DELETE(_,C){return m(_,{...C,method:"DELETE"})},OPTIONS(_,C){return m(_,{...C,method:"OPTIONS"})},HEAD(_,C){return m(_,{...C,method:"HEAD"})},PATCH(_,C){return m(_,{...C,method:"PATCH"})},TRACE(_,C){return m(_,{...C,method:"TRACE"})},use(..._){for(let C of _){if(!C)continue;if(typeof C!=="object"||!(("onRequest"in C)||("onResponse"in C)||("onError"in C)))throw Error("Middleware must be an object with one of `onRequest()`, `onResponse() or `onError()`");x.push(C)}},eject(..._){for(let C of _){let w=x.indexOf(C);if(w!==-1)x.splice(w,1)}}}}function U(o,g,n){if(g===void 0||g===null)return"";if(typeof g==="object")throw Error("Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.");return`${o}=${n?.allowReserved===!0?g:encodeURIComponent(g)}`}function wo(o,g,n){if(!g||typeof g!=="object")return"";let t=[],c={simple:",",label:".",matrix:";"}[n.style]||"&";if(n.style!=="deepObject"&&n.explode===!1){for(let y in g)t.push(y,n.allowReserved===!0?g[y]:encodeURIComponent(g[y]));let f=t.join(",");switch(n.style){case"form":return`${o}=${f}`;case"label":return`.${f}`;case"matrix":return`;${o}=${f}`;default:return f}}for(let f in g){let y=n.style==="deepObject"?`${o}[${f}]`:f;t.push(U(y,g[f],n))}let i=t.join(c);return n.style==="label"||n.style==="matrix"?`${c}${i}`:i}function To(o,g,n){if(!Array.isArray(g))return"";if(n.explode===!1){let i={form:",",spaceDelimited:"%20",pipeDelimited:"|"}[n.style]||",",f=(n.allowReserved===!0?g:g.map((y)=>encodeURIComponent(y))).join(i);switch(n.style){case"simple":return f;case"label":return`.${f}`;case"matrix":return`;${o}=${f}`;default:return`${o}=${f}`}}let t={simple:",",label:".",matrix:";"}[n.style]||"&",c=[];for(let i of g)if(n.style==="simple"||n.style==="label")c.push(n.allowReserved===!0?i:encodeURIComponent(i));else c.push(U(o,i,n));return n.style==="label"||n.style==="matrix"?`${t}${c.join(t)}`:c.join(t)}function Oo(o){return function(n){let t=[];if(n&&typeof n==="object")for(let c in n){let i=n[c];if(i===void 0||i===null)continue;if(Array.isArray(i)){if(i.length===0)continue;t.push(To(c,i,{style:"form",explode:!0,...o?.array,allowReserved:o?.allowReserved||!1}));continue}if(typeof i==="object"){t.push(wo(c,i,{style:"deepObject",explode:!0,...o?.object,allowReserved:o?.allowReserved||!1}));continue}t.push(U(c,i,o))}return t.join("&")}}function Uo(o,g){let n=o;for(let t of o.match(Ao)??[]){let c=t.substring(1,t.length-1),i=!1,f="simple";if(c.endsWith("*"))i=!0,c=c.substring(0,c.length-1);if(c.startsWith("."))f="label",c=c.substring(1);else if(c.startsWith(";"))f="matrix",c=c.substring(1);if(!g||g[c]===void 0||g[c]===null)continue;let y=g[c];if(Array.isArray(y)){n=n.replace(t,To(c,y,{style:f,explode:i}));continue}if(typeof y==="object"){n=n.replace(t,wo(c,y,{style:f,explode:i}));continue}if(f==="matrix"){n=n.replace(t,`;${U(c,y)}`);continue}n=n.replace(t,f==="label"?`.${encodeURIComponent(y)}`:encodeURIComponent(y))}return n}function Ho(o,g){if(o instanceof FormData)return o;if(g){if((g.get instanceof Function?g.get("Content-Type")??g.get("content-type"):g["Content-Type"]??g["content-type"])==="application/x-www-form-urlencoded")return new URLSearchParams(o).toString()}return JSON.stringify(o)}function Io(o,g){let n=`${g.baseUrl}${o}`;if(g.params?.path)n=Uo(n,g.params.path);let t=g.querySerializer(g.params.query??{});if(t.startsWith("?"))t=t.substring(1);if(t)n+=`?${t}`;return n}function $o(...o){let g=new Headers;for(let n of o){if(!n||typeof n!=="object")continue;let t=n instanceof Headers?n.entries():Object.entries(n);for(let[c,i]of t)if(i===null)g.delete(c);else if(Array.isArray(i))for(let f of i)g.append(c,f);else if(i!==void 0)g.set(c,i)}return g}function No(o){if(o.endsWith("/"))return o.substring(0,o.length-1);return o}class W extends Error{status;body;url;constructor(o,g,n,t){super(o);this.name="ApiClientError",this.status=g,this.body=n,this.url=t}}function N(o,g){if(o.error!==void 0&&o.error!==null){let n=o.response?.status??0,t=o.response?.url??"",c=typeof o.error==="object"&&o.error!==null&&"error"in o.error&&typeof o.error.error==="object"&&o.error.error?.message||`${g} failed (${n})`;throw new W(String(c),n,o.error,t)}if(o.data===void 0)throw new W(`${g}: empty response body`,o.response?.status??0,void 0,o.response?.url??"");return o.data}class d{client;constructor(o){this.client=o}async get(){let o=await this.client.GET("/api/v1/me",{});return N(o,"me.get")}}class H{client;constructor(o){this.client=o}async get(o){let g=await this.client.GET("/api/v1/orgs/{orgId}",{params:{path:{orgId:o}}});return N(g,"orgs.get")}async listMembers(o,g={}){let n=await this.client.GET("/api/v1/orgs/{orgId}/members",{params:{path:{orgId:o},query:g}});return N(n,"orgs.listMembers")}}class I{client;constructor(o){this.client=o}async list(o,g={}){let n=await this.client.GET("/api/v1/orgs/{orgId}/products",{params:{path:{orgId:o},query:g}});return N(n,"products.list")}async get(o,g){let n=await this.client.GET("/api/v1/orgs/{orgId}/products/{productId}",{params:{path:{orgId:o,productId:g}}});return N(n,"products.get")}}class P{client;constructor(o){this.client=o}async list(o,g={}){let n=await this.client.GET("/api/v1/orgs/{orgId}/events",{params:{path:{orgId:o},query:g}});return N(n,"events.list")}async get(o,g){let n=await this.client.GET("/api/v1/orgs/{orgId}/events/{eventId}",{params:{path:{orgId:o,eventId:g}}});return N(n,"events.get")}}class z{client;constructor(o){this.client=o}async list(o,g={}){let n=await this.client.GET("/api/v1/orgs/{orgId}/bookings",{params:{path:{orgId:o},query:g}});return N(n,"bookings.list")}async get(o,g){let n=await this.client.GET("/api/v1/orgs/{orgId}/bookings/{bookingId}",{params:{path:{orgId:o,bookingId:g}}});return N(n,"bookings.get")}}class q{client;constructor(o){this.client=o}async list(o,g={}){let n=await this.client.GET("/api/v1/orgs/{orgId}/orders",{params:{path:{orgId:o},query:g}});return N(n,"orders.list")}async get(o,g){let n=await this.client.GET("/api/v1/orgs/{orgId}/orders/{orderId}",{params:{path:{orgId:o,orderId:g}}});return N(n,"orders.get")}}class p{client;constructor(o){this.client=o}async list(o,g={}){let n=await this.client.GET("/api/v1/orgs/{orgId}/quotes",{params:{path:{orgId:o},query:g}});return N(n,"quotes.list")}async get(o,g){let n=await this.client.GET("/api/v1/orgs/{orgId}/quotes/{quoteId}",{params:{path:{orgId:o,quoteId:g}}});return N(n,"quotes.get")}}var Po="https://vcity.io";function zo(o,g){let n=g??globalThis.fetch;if(!n)throw Error("@vcityio/api-client: no fetch implementation found. Provide options.fetch or run on Node >=20 / a browser.");return async function(c){if(!o)return n(c);if(c.headers.has("Authorization"))return n(c);let i=new Headers(c.headers);i.set("Authorization",`Bearer ${o}`);let f=new Request(c,{headers:i});return n(f)}}class io{raw;me;orgs;products;events;bookings;orders;quotes;constructor(o={}){let g=o.baseUrl??Po,n=zo(o.token,o.fetch),t={baseUrl:g,fetch:n,headers:o.headers};this.raw=fo(t),this.me=new d(this.raw),this.orgs=new H(this.raw),this.products=new I(this.raw),this.events=new P(this.raw),this.bookings=new z(this.raw),this.orders=new q(this.raw),this.quotes=new p(this.raw)}}function yo(o={}){return new io(o)}class Co extends Error{status;body;constructor(o,g,n){super(n??`HTTP ${o}`);this.status=o;this.body=g;this.name="ApiError"}}function Eo(o,g,n){let t=new URL(g.startsWith("/")?g:`/${g}`,o);if(n){for(let[c,i]of Object.entries(n))if(i!==void 0&&i!==null&&!Number.isNaN(i))t.searchParams.set(c,String(i))}return t.toString()}async function qo(o){try{let g=await fetch(Eo(o.api_base_url,"/api/cli/auth/refresh"),{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({refresh_token:o.refresh_token})});if(!g.ok)return;let n=await g.json(),t={...o,access_token:n.access_token,refresh_token:n.refresh_token,access_expires_at:n.access_expires_at,refresh_expires_at:n.refresh_expires_at};return A(t),t}catch{return}}async function L(o,g={}){let{authed:n=!0,method:t="GET",body:c,query:i,baseUrl:f}=g,y=n?Q():void 0,r=f??y?.api_base_url??"https://vcity.io",x={"content-type":"application/json"};if(y)x.authorization=`Bearer ${y.access_token}`;let m=await fetch(Eo(r,o,i),{method:t,headers:x,body:c===void 0?void 0:JSON.stringify(c)}),C=(m.headers.get("content-type")??"").includes("application/json")?await m.json().catch(()=>{return}):await m.text().catch(()=>{return});if(!m.ok){let w=(C&&typeof C==="object"&&"error"in C?String(C.error):void 0)??`Request failed (${m.status})`;throw new Co(m.status,C,w)}return C}function po(){let o=async(g,n)=>{let t=new Headers(g.headers);t.set("authorization",`Bearer ${n}`);let c=new Request(g,{headers:t});return globalThis.fetch(c)};return async function(n){let t=Q(),c=await o(n,t.access_token);if(c.status!==401)return c;let i=await qo(t);if(!i)throw B(),new Co(401,void 0,"Session expired. Run `vcity login` again.");return t=i,o(n,t.access_token)}}var u;function D(){if(u)return u;let o=Q();return u=yo({baseUrl:o.api_base_url,fetch:po()}),u}function ho(o){if(o===!1)return!1;if(process.env.VCITY_NO_OPEN_BROWSER)return!1;if(!process.stdout.isTTY)return!1;return!0}async function lo(o){try{let g=(await import("open")).default;await g(o)}catch{}}async function Jo(o={}){let g=o.apiBaseUrl??mo(),n=await L("/api/cli/auth/device/code",{method:"POST",body:{},authed:!1,baseUrl:g});if(process.stdout.write(`
2
+ import{createRequire as Cc}from"node:module";var Hc=Cc(import.meta.url);var Uc=/\{[^{}]+\}/g,wc=()=>{return typeof process==="object"&&Number.parseInt(process?.versions?.node?.substring(0,2))>=18&&process.versions.undici};function Lc(){return Math.random().toString(36).slice(2,11)}function _n(n){let{baseUrl:c="",Request:k=globalThis.Request,fetch:D=globalThis.fetch,querySerializer:g,bodySerializer:$,headers:j,requestInitExt:x=void 0,...y}={...n};x=wc()?x:void 0,c=Ln(c);let M=[];async function R(T,Y){let{baseUrl:C,fetch:Nn=D,Request:Qk=k,headers:Bn,params:z={},parseAs:En="json",querySerializer:u,bodySerializer:Cn=$??qc,body:Hn,...Jn}=Y||{},fn=c;if(C)fn=Ln(C)??c;let Gn=typeof g==="function"?g:Un(g);if(u)Gn=typeof u==="function"?u:Un({...typeof g==="object"?g:{},...u});let Tn=Hn===void 0?void 0:Cn(Hn,wn(j,Bn,z.header)),Nc=wn(Tn===void 0||Tn instanceof FormData?{}:{"Content-Type":"application/json"},j,Bn,z.header),Bc={redirect:"follow",...y,...Jn,body:Tn,headers:Nc},t,r,w=new k(Ac(T,{baseUrl:fn,params:z,querySerializer:Gn}),Bc),Z;for(let K in Jn)if(!(K in w))w[K]=Jn[K];if(M.length){t=Lc(),r=Object.freeze({baseUrl:fn,fetch:Nn,parseAs:En,querySerializer:Gn,bodySerializer:Cn});for(let K of M)if(K&&typeof K==="object"&&typeof K.onRequest==="function"){let o=await K.onRequest({request:w,schemaPath:T,params:z,options:r,id:t});if(o)if(o instanceof k)w=o;else if(o instanceof Response){Z=o;break}else throw Error("onRequest: must return new Request() or Response() when modifying the request")}}if(!Z){try{Z=await Nn(w,x)}catch(K){let o=K;if(M.length)for(let q=M.length-1;q>=0;q--){let h=M[q];if(h&&typeof h==="object"&&typeof h.onError==="function"){let I=await h.onError({request:w,error:o,schemaPath:T,params:z,options:r,id:t});if(I){if(I instanceof Response){o=void 0,Z=I;break}if(I instanceof Error){o=I;continue}throw Error("onError: must return new Response() or instance of Error")}}}if(o)throw o}if(M.length)for(let K=M.length-1;K>=0;K--){let o=M[K];if(o&&typeof o==="object"&&typeof o.onResponse==="function"){let q=await o.onResponse({request:w,response:Z,schemaPath:T,params:z,options:r,id:t});if(q){if(!(q instanceof Response))throw Error("onResponse: must return new Response() when modifying the response");Z=q}}}}if(Z.status===204||w.method==="HEAD"||Z.headers.get("Content-Length")==="0")return Z.ok?{data:void 0,response:Z}:{error:void 0,response:Z};if(Z.ok){if(En==="stream")return{data:Z.body,response:Z};return{data:await Z[En](),response:Z}}let Wn=await Z.text();try{Wn=JSON.parse(Wn)}catch{}return{error:Wn,response:Z}}return{request(T,Y,C){return R(Y,{...C,method:T.toUpperCase()})},GET(T,Y){return R(T,{...Y,method:"GET"})},PUT(T,Y){return R(T,{...Y,method:"PUT"})},POST(T,Y){return R(T,{...Y,method:"POST"})},DELETE(T,Y){return R(T,{...Y,method:"DELETE"})},OPTIONS(T,Y){return R(T,{...Y,method:"OPTIONS"})},HEAD(T,Y){return R(T,{...Y,method:"HEAD"})},PATCH(T,Y){return R(T,{...Y,method:"PATCH"})},TRACE(T,Y){return R(T,{...Y,method:"TRACE"})},use(...T){for(let Y of T){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()`");M.push(Y)}},eject(...T){for(let Y of T){let C=M.indexOf(Y);if(C!==-1)M.splice(C,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 Sn(n,c,k){if(!c||typeof c!=="object")return"";let D=[],g={simple:",",label:".",matrix:";"}[k.style]||"&";if(k.style!=="deepObject"&&k.explode===!1){for(let x in c)D.push(x,k.allowReserved===!0?c[x]:encodeURIComponent(c[x]));let j=D.join(",");switch(k.style){case"form":return`${n}=${j}`;case"label":return`.${j}`;case"matrix":return`;${n}=${j}`;default:return j}}for(let j in c){let x=k.style==="deepObject"?`${n}[${j}]`:j;D.push(p(x,c[j],k))}let $=D.join(g);return k.style==="label"||k.style==="matrix"?`${g}${$}`:$}function qn(n,c,k){if(!Array.isArray(c))return"";if(k.explode===!1){let $={form:",",spaceDelimited:"%20",pipeDelimited:"|"}[k.style]||",",j=(k.allowReserved===!0?c:c.map((x)=>encodeURIComponent(x))).join($);switch(k.style){case"simple":return j;case"label":return`.${j}`;case"matrix":return`;${n}=${j}`;default:return`${n}=${j}`}}let D={simple:",",label:".",matrix:";"}[k.style]||"&",g=[];for(let $ of c)if(k.style==="simple"||k.style==="label")g.push(k.allowReserved===!0?$:encodeURIComponent($));else g.push(p(n,$,k));return k.style==="label"||k.style==="matrix"?`${D}${g.join(D)}`:g.join(D)}function Un(n){return function(k){let D=[];if(k&&typeof k==="object")for(let g in k){let $=k[g];if($===void 0||$===null)continue;if(Array.isArray($)){if($.length===0)continue;D.push(qn(g,$,{style:"form",explode:!0,...n?.array,allowReserved:n?.allowReserved||!1}));continue}if(typeof $==="object"){D.push(Sn(g,$,{style:"deepObject",explode:!0,...n?.object,allowReserved:n?.allowReserved||!1}));continue}D.push(p(g,$,n))}return D.join("&")}}function Sc(n,c){let k=n;for(let D of n.match(Uc)??[]){let g=D.substring(1,D.length-1),$=!1,j="simple";if(g.endsWith("*"))$=!0,g=g.substring(0,g.length-1);if(g.startsWith("."))j="label",g=g.substring(1);else if(g.startsWith(";"))j="matrix",g=g.substring(1);if(!c||c[g]===void 0||c[g]===null)continue;let x=c[g];if(Array.isArray(x)){k=k.replace(D,qn(g,x,{style:j,explode:$}));continue}if(typeof x==="object"){k=k.replace(D,Sn(g,x,{style:j,explode:$}));continue}if(j==="matrix"){k=k.replace(D,`;${p(g,x)}`);continue}k=k.replace(D,j==="label"?`.${encodeURIComponent(x)}`:encodeURIComponent(x))}return k}function qc(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 Ac(n,c){let k=`${c.baseUrl}${n}`;if(c.params?.path)k=Sc(k,c.params.path);let D=c.querySerializer(c.params.query??{});if(D.startsWith("?"))D=D.substring(1);if(D)k+=`?${D}`;return k}function wn(...n){let c=new Headers;for(let k of n){if(!k||typeof k!=="object")continue;let D=k instanceof Headers?k.entries():Object.entries(k);for(let[g,$]of D)if($===null)c.delete(g);else if(Array.isArray($))for(let j of $)c.append(g,j);else if($!==void 0)c.set(g,$)}return c}function Ln(n){if(n.endsWith("/"))return n.substring(0,n.length-1);return n}class i extends Error{status;body;url;constructor(n,c,k,D){super(n);this.name="ApiClientError",this.status=c,this.body=k,this.url=D}}function _(n,c){if(n.error!==void 0&&n.error!==null){let k=n.response?.status??0,D=n.response?.url??"",g=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 i(String(g),k,n.error,D)}if(n.data===void 0)throw new i(`${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 _(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 _(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 _(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 _(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 _(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 _(k,"products.create")}async update(n,c,k){let D=await this.client.PUT("/api/v1/orgs/{orgId}/products/{productId}",{params:{path:{orgId:n,productId:c}},body:k});return _(D,"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 _(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 _(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 _(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 _(k,"events.create")}async update(n,c,k){let D=await this.client.PUT("/api/v1/orgs/{orgId}/events/{eventId}",{params:{path:{orgId:n,eventId:c}},body:k});return _(D,"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 _(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 _(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 _(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 _(k,"rooms.create")}async update(n,c,k){let D=await this.client.PUT("/api/v1/orgs/{orgId}/rooms/{roomId}",{params:{path:{orgId:n,roomId:c}},body:k});return _(D,"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 _(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 _(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 _(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 _(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 _(k,"orders.get")}}class Dn{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 _(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 _(k,"quotes.get")}}var zc="https://vcity.io";function ic(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(g){if(!n)return k(g);if(g.headers.has("Authorization"))return k(g);let $=new Headers(g.headers);$.set("Authorization",`Bearer ${n}`);let j=new Request(g,{headers:$});return k(j)}}class Xn{raw;me;orgs;products;events;rooms;bookings;orders;quotes;constructor(n={}){let c=n.baseUrl??zc,k=ic(n.token,n.fetch),D={baseUrl:c,fetch:k,headers:n.headers};this.raw=_n(D),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 Dn(this.raw)}}function Zn(n={}){return new Xn(n)}import L from"node:fs";import mc from"node:os";import Qn from"node:path";function H(){if(process.env.VCITY_CONFIG_DIR)return process.env.VCITY_CONFIG_DIR;return Qn.join(mc.homedir(),".vcity")}function gn(){return Qn.join(H(),"auth.json")}function Rn(){return Qn.join(H(),"config.json")}function An(){return process.env.VCITY_API_BASE_URL||process.env.VCITY_PUBLIC_URL||"https://vcity.io"}function Oc(){let n=H();if(!L.existsSync(n))L.mkdirSync(n,{recursive:!0,mode:448})}function $n(){let n=gn();if(!L.existsSync(n))return;try{return JSON.parse(L.readFileSync(n,"utf-8"))}catch{return}}function jn(n){Oc();let c=gn();L.writeFileSync(c,JSON.stringify(n,null,2),{mode:384});try{L.chmodSync(c,384)}catch{}}function m(){let n=gn();if(L.existsSync(n))L.rmSync(n)}function xn(){let n=$n();if(!n)throw Error("Not logged in. Run `vcity login` first.");return n}class v extends Error{status;body;constructor(n,c,k){super(k??`HTTP ${n}`);this.status=n;this.body=c;this.name="ApiError"}}function mn(n,c,k){let D=new URL(c.startsWith("/")?c:`/${c}`,n);if(k){for(let[g,$]of Object.entries(k))if($!==void 0&&$!==null&&!Number.isNaN($))D.searchParams.set(g,String($))}return D.toString()}async function zn(n){try{let c=await fetch(mn(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(),D={...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 jn(D),D}catch{return}}async function d(n,c={}){let{authed:k=!0,method:D="GET",body:g,query:$,baseUrl:j}=c,x=k?xn():void 0,y=j??x?.api_base_url??"https://vcity.io",M={"content-type":"application/json"};if(x)M.authorization=`Bearer ${x.access_token}`;let R=await fetch(mn(y,n,$),{method:D,headers:M,body:g===void 0?void 0:JSON.stringify(g)}),Y=(R.headers.get("content-type")??"").includes("application/json")?await R.json().catch(()=>{return}):await R.text().catch(()=>{return});if(!R.ok){let C=(Y&&typeof Y==="object"&&"error"in Y?String(Y.error):void 0)??`Request failed (${R.status})`;throw new v(R.status,Y,C)}return Y}function Pc(){let n=async(c,k)=>{let D=new Headers(c.headers);D.set("authorization",`Bearer ${k}`);let g=new Request(c,{headers:D});return globalThis.fetch(g)};return async function(k){let D=xn();if(Date.now()>=D.access_expires_at){if(Date.now()>=D.refresh_expires_at)throw m(),new v(401,void 0,"Session expired. Run `vcity login` again.");let j=await zn(D);if(!j)throw m(),new v(401,void 0,"Session expired. Run `vcity login` again.");D=j}let g=await n(k,D.access_token);if(g.status!==401)return g;let $=await zn(D);if(!$)throw m(),new v(401,void 0,"Session expired. Run `vcity login` again.");return D=$,n(k,D.access_token)}}var yn;function f(){if(yn)return yn;let n=xn();return yn=Zn({baseUrl:n.api_base_url,fetch:Pc()}),yn}function S(n){if(n==null)return"";return new Date(n).toISOString().replace("T"," ").slice(0,16)}import O from"node:fs";function Fc(){let n=H();if(!O.existsSync(n))O.mkdirSync(n,{recursive:!0,mode:448})}function A(){let n=Rn();if(!O.existsSync(n))return{};try{return JSON.parse(O.readFileSync(n,"utf-8"))}catch{return{}}}function On(n){Fc();let k={...A(),...n},D=Rn();O.writeFileSync(D,JSON.stringify(k,null,2),{mode:384});try{O.chmodSync(D,384)}catch{}return k}function W(n){if(n)return n;let c=A();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 N(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: ${N(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 E(n){if(n)return"json";if(!process.stdout.isTTY)return"json";return"pretty"}function J(n){process.stdout.write(`${JSON.stringify(n,null,2)}
3
+ `)}function vc(n,c){if(n.length===0)return"(no rows)";let k=n.map((x)=>c.map((y)=>N(y.get(x)??""))),D=c.map((x,y)=>Math.max(x.header.length,...k.map((M)=>M[y].length))),g=D.map((x)=>"-".repeat(x)).join(" "),$=c.map((x,y)=>x.header.padEnd(D[y])).join(" "),j=k.map((x)=>x.map((y,M)=>y.padEnd(D[M])).join(" "));return[$,g,...j].join(`
4
+ `)}function V(n,c){process.stdout.write(`${vc(n,c)}
5
+ `)}function Q(n){for(let[c,k]of Object.entries(n)){if(k===void 0||k===null)continue;let D=typeof k==="object"?JSON.stringify(k):String(k);process.stdout.write(`${c.padEnd(20)} ${N(D)}
6
+ `)}}async function Fn(n={}){let c=E(n.json),k=W(n.org),D={};if(n.limit!==void 0)D.limit=n.limit;if(n.status!==void 0)D.status=n.status;let $=await f().bookings.list(k,D),j=$.data??[];if(c==="json"){J({org:k,bookings:j,total:$.total,skip:$.skip,limit:$.limit,hasMore:$.hasMore});return}V(j,[{header:"ID",get:(x)=>x.id},{header:"NAME",get:(x)=>x.name??""},{header:"EMAIL",get:(x)=>x.email??""},{header:"REQUESTED",get:(x)=>S(x.requestedDate)},{header:"STATUS",get:(x)=>x.status??""}])}async function bn(n,c={}){let k=E(c.json),D=W(c.org),$=await f().bookings.get(D,n);if(k==="json"){J($);return}Q($)}import dc from"node:fs";function U(n){if(n===void 0)return;let c;if(n.startsWith("@")){let k=n.slice(1);if(k.length===0)throw Error("--data: missing file path after `@`");if(!/\.json$/i.test(k))throw Error(`--data: @file path must point to a .json file (got: ${k})`);try{c=dc.readFileSync(k,"utf-8")}catch(D){let g=D instanceof Error?D.message:String(D);throw Error(`--data: could not read ${k}: ${g}`)}}else c=n;try{return JSON.parse(c)}catch(k){let D=k instanceof Error?k.message:String(k);throw Error(`--data: invalid JSON (${D})`)}}import uc from"node:readline";function P(n){let c=uc.createInterface({input:process.stdin,output:process.stdout});return new Promise((k)=>{c.question(`${n} `,(D)=>{c.close();let g=D.trim().toLowerCase();k(g==="y"||g==="yes")})})}async function In(n={}){let c=E(n.json),k=W(n.org),D={};if(n.limit!==void 0)D.limit=n.limit;if(n.status!==void 0)D.status=n.status;let $=await f().events.list(k,D),j=$.data??[];if(c==="json"){J({org:k,events:j,total:$.total,skip:$.skip,limit:$.limit,hasMore:$.hasMore});return}V(j,[{header:"ID",get:(x)=>x.id},{header:"NAME",get:(x)=>x.name??""},{header:"STARTS_AT",get:(x)=>x.startsAt!==void 0?new Date(x.startsAt).toISOString():""},{header:"STATUS",get:(x)=>x.status??""},{header:"CATEGORIES",get:(x)=>(x.categories??[]).join(",")}])}async function vn(n,c={}){let k=E(c.json),D=W(c.org),$=await f().events.get(D,n);if(k==="json"){J($);return}Q($)}function Mn(n,c){if(/^-?\d+$/.test(n)){let D=Number(n);if(Number.isFinite(D))return D}let k=Date.parse(n);if(Number.isFinite(k))return k;throw Error(`${c}: expected ISO 8601 or epoch ms (got: ${n})`)}async function dn(n={}){let c=E(n.json),k=W(n.org),D=U(n.data),g=D&&typeof D==="object"?{...D}:{};if(n.name!==void 0)g.name=n.name;if(n.slug!==void 0)g.slug=n.slug;if(n.startsAt!==void 0)g.startsAt=Mn(n.startsAt,"--starts-at");if(n.endsAt!==void 0)g.endsAt=Mn(n.endsAt,"--ends-at");if(g.name===void 0)throw Error("events create: --name is required (or supply it via --data)");let j=await f().events.create(k,g);if(c==="json"){J(j);return}process.stdout.write(`Created event:
7
+ `),Q(j)}async function un(n,c={}){let k=E(c.json),D=W(c.org),g=U(c.data),$=g&&typeof g==="object"?{...g}:{};if(c.name!==void 0)$.name=c.name;if(c.slug!==void 0)$.slug=c.slug;if(c.status!==void 0)$.status=c.status;if(c.startsAt!==void 0)$.startsAt=Mn(c.startsAt,"--starts-at");if(c.endsAt!==void 0)$.endsAt=Mn(c.endsAt,"--ends-at");if(Object.keys($).length===0)throw Error("events update: nothing to update (pass at least one field or --data)");let x=await f().events.update(D,n,$);if(k==="json"){J(x);return}process.stdout.write(`Updated event:
8
+ `),Q(x)}async function tn(n,c={}){let k=E(c.json),D=W(c.org);if(!c.yes){if(k==="json")throw Error("events delete: --yes is required in JSON / non-interactive mode");if(!await P(`Delete event ${n} in org ${D}? [y/N]`)){process.stdout.write(`Aborted.
9
+ `);return}}let $=await f().events.delete(D,n);if(k==="json"){J($);return}process.stdout.write(`Deleted event ${n}.
10
+ `)}import{setTimeout as tc}from"node:timers/promises";var rn=1;function rc(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 hc(n){try{let c=(await import("open")).default;await c(n)}catch{}}function pc(n){let c;try{c=new URL(n)}catch{throw Error(`Invalid --api-base-url: ${n.slice(0,200)}`)}if(c.protocol==="https:")return c;if(c.protocol==="http:"&&(c.hostname==="localhost"||c.hostname==="127.0.0.1"))return c;throw Error(`--api-base-url must use https:// (got: ${c.protocol}//${c.hostname}).`)}async function hn(n={}){let c=n.apiBaseUrl??An(),k=pc(c),D=await d("/api/cli/auth/device/code",{method:"POST",body:{},authed:!1,baseUrl:k.toString()}),g=new URL("/cli-auth",k),$=new URL(g);if($.searchParams.set("user_code",D.user_code),process.stdout.write(`
4
11
  Open this URL to approve the session:
5
- ${n.verification_uri}
12
+ ${g.toString()}
6
13
  `),process.stdout.write(`Enter this code:
7
- ${n.user_code}
14
+ ${N(D.user_code)}
8
15
 
9
16
  `),process.stdout.write(`Waiting for approval…
10
- `),ho(o.openBrowser))await lo(n.verification_uri_complete);let t=Date.now()+n.expires_in*1000,c=n.interval;while(Date.now()<t){await uo(c*1000);let i=await L("/api/cli/auth/device/token",{method:"POST",body:{device_code:n.device_code},authed:!1,baseUrl:g}).catch((f)=>{if(f&&typeof f==="object"&&"status"in f&&f.status===400)return f.body;throw f});if(!i)continue;if(i.status==="pending"){c=i.interval;continue}if(i.status==="approved"){A({api_base_url:g,access_token:i.access_token,refresh_token:i.refresh_token,access_expires_at:i.access_expires_at,refresh_expires_at:i.refresh_expires_at,user:i.user});let f=i.user.email??i.user.name??i.user.id;process.stdout.write(`
11
- Logged in as ${f}.
12
- `);return}throw Error(`Login ${i.status}. Run \`vcity login\` again.`)}throw Error("Login timed out. Run `vcity login` again.")}async function Do(){if(!v()){process.stdout.write(`Not logged in.
13
- `);return}try{await L("/api/cli/auth/logout",{method:"POST",body:{}})}catch{}B(),process.stdout.write(`Logged out.
14
- `)}import F from"node:fs";function eo(){let o=G();if(!F.existsSync(o))F.mkdirSync(o,{recursive:!0,mode:448})}function R(){let o=to();if(!F.existsSync(o))return{};try{return JSON.parse(F.readFileSync(o,"utf-8"))}catch{return{}}}function Ro(o){eo();let n={...R(),...o};return F.writeFileSync(to(),JSON.stringify(n,null,2),{mode:384}),n}function S(o){if(o)return"json";if(!process.stdout.isTTY)return"json";return"pretty"}function V(o){process.stdout.write(`${JSON.stringify(o,null,2)}
15
- `)}function ao(o,g){if(o.length===0)return"(no rows)";let n=o.map((y)=>g.map((r)=>r.get(y)??"")),t=g.map((y,r)=>Math.max(y.header.length,...n.map((x)=>x[r].length))),c=t.map((y)=>"-".repeat(y)).join(" "),i=g.map((y,r)=>y.header.padEnd(t[r])).join(" "),f=n.map((y)=>y.map((r,x)=>r.padEnd(t[x])).join(" "));return[i,c,...f].join(`
16
- `)}function h(o,g){process.stdout.write(`${ao(o,g)}
17
- `)}async function So(){let g=await D().me.get();if(g&&typeof g==="object"&&"orgs"in g){let n=g.orgs;return Array.isArray(n)?n:[]}return[]}async function Vo(o={}){let g=S(o.json),n=await So(),t=R().active_org;if(g==="json"){V({orgs:n,active_org:t??null});return}h(n,[{header:"*",get:(c)=>c.slug===t?"*":" "},{header:"SLUG",get:(c)=>c.slug},{header:"NAME",get:(c)=>c.name??""},{header:"ID",get:(c)=>c.id}])}async function Yo(o){let n=(await So()).find((t)=>t.slug===o||t.id===o);if(!n)throw Error(`No accessible org matches "${o}". Run \`vcity org list\` to see options.`);Ro({active_org:n.slug}),process.stdout.write(`Active org set to ${n.slug} (${n.name??n.id}).
18
- `)}function Go(o){if(o)return o;let g=R();if(!g.active_org)throw Error("No active org. Run `vcity org use <slug>` or pass --org <slug>.");return g.active_org}async function Wo(o={}){let g=S(o.json),n=Go(o.org),c=await D().products.list(n,o.limit!==void 0?{limit:o.limit}:{}),i=c.data??[];if(g==="json"){V({org:n,products:i,total:c.total,skip:c.skip,limit:c.limit,hasMore:c.hasMore});return}h(i,[{header:"ID",get:(f)=>f.id},{header:"NAME",get:(f)=>f.name??""},{header:"PRICE",get:(f)=>f.price!==void 0?`${f.price.toLocaleString()} ${f.currencyCode??""}`.trim():""},{header:"SKU",get:(f)=>f.sku??""},{header:"VISIBILITY",get:(f)=>f.visibility??""},{header:"STOCK",get:(f)=>f.availability!==void 0?String(f.availability):""}])}async function so(o,g={}){let n=S(g.json),t=Go(g.org),i=await D().products.get(t,o);if(n==="json"){V(i);return}for(let[f,y]of Object.entries(i)){if(y===void 0||y===null)continue;let r=typeof y==="object"?JSON.stringify(y):String(y);process.stdout.write(`${f.padEnd(20)} ${r}
19
- `)}}function on(o){if(o&&typeof o==="object"&&"user"in o){let g=o;return{user:g.user,orgs:g.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 Mo(o={}){let g=S(o.json),t=await D().me.get(),{user:c,orgs:i}=on(t),f=R();if(g==="json"){V({user:c,orgs:i,active_org:f.active_org??null});return}let y=c.email??c.name??c.id;if(process.stdout.write(`User: ${y}
20
- `),process.stdout.write(`User ID: ${c.id}
21
- `),c.admin)process.stdout.write(`Role: platform admin
22
- `);process.stdout.write(`Active org: ${f.active_org??"(none — run `vcity org use <slug>`)"}
23
- `)}var nn=new Set(["json"]);function Lo(o){let g=[],n={};for(let t=0;t<o.length;t++){let c=o[t];if(!c.startsWith("--")){g.push(c);continue}let i=c.indexOf("=");if(i>=0){n[c.slice(2,i)]=c.slice(i+1);continue}let f=c.slice(2),y=o[t+1];if(nn.has(f)||y===void 0||y.startsWith("--"))n[f]=!0;else n[f]=y,t++}return{positional:g,flags:n}}var Fo="0.1.0";function K(o){process.stderr.write(`error: ${o}
24
- `),process.exit(1)}function gn(){process.stdout.write(`vcity ${Fo}
17
+ `),rc(n.openBrowser))await hc(Pn($.toString()).toString());let j=Date.now()+D.expires_in*1000,x=Math.max(D.interval,rn);while(Date.now()<j){await tc(x*1000);let y=await d("/api/cli/auth/device/token",{method:"POST",body:{device_code:D.device_code},authed:!1,baseUrl:k.toString()}).catch((M)=>{if(M&&typeof M==="object"&&"status"in M&&M.status===400)return M.body;throw M});if(!y)continue;if(y.status==="pending"){x=Math.max(y.interval,rn);continue}if(y.status==="approved"){jn({api_base_url:k.toString(),access_token:y.access_token,refresh_token:y.refresh_token,access_expires_at:y.access_expires_at,refresh_expires_at:y.refresh_expires_at,user:y.user});let M=y.user.email??y.user.name??y.user.id;process.stdout.write(`
18
+ Logged in as ${N(M)}.
19
+ `);return}throw Error(`Login ${y.status}. Run \`vcity login\` again.`)}throw Error("Login timed out. Run `vcity login` again.")}async function pn(){let n=$n();if(!n){process.stdout.write(`Not logged in.
20
+ `);return}try{await d("/api/cli/auth/logout",{method:"POST",body:{refresh_token:n.refresh_token}})}catch{}m(),process.stdout.write(`Logged out.
21
+ `)}async function sn(n={}){let c=E(n.json),k=W(n.org),D={};if(n.limit!==void 0)D.limit=n.limit;if(n.status!==void 0)D.status=n.status;let $=await f().orders.list(k,D),j=$.data??[];if(c==="json"){J({org:k,orders:j,total:$.total,skip:$.skip,limit:$.limit,hasMore:$.hasMore});return}V(j,[{header:"ID",get:(x)=>x.id},{header:"STATUS",get:(x)=>x.status??""},{header:"TOTAL",get:(x)=>x.total!==void 0?`${x.total.toLocaleString()} ${x.currencyCode??""}`.trim():""},{header:"CREATED",get:(x)=>S(x.createdAt)}])}async function en(n,c={}){let k=E(c.json),D=W(c.org),$=await f().orders.get(D,n);if(k==="json"){J($);return}Q($)}async function ln(){let c=await f().me.get();if(c&&typeof c==="object"&&"orgs"in c){let k=c.orgs;return Array.isArray(k)?k:[]}return[]}async function an(n={}){let c=E(n.json),k=await ln(),D=A().active_org;if(c==="json"){J({orgs:k,active_org:D??null});return}V(k,[{header:"*",get:(g)=>g.slug===D?"*":" "},{header:"SLUG",get:(g)=>g.slug},{header:"NAME",get:(g)=>g.name??""},{header:"ID",get:(g)=>g.id}])}async function nc(n){let k=(await ln()).find((D)=>D.slug===n||D.id===n);if(!k)throw Error(`No accessible org matches "${n}". Run \`vcity org list\` to see options.`);On({active_org:k.slug}),process.stdout.write(`Active org set to ${k.slug} (${k.name??k.id}).
22
+ `)}async function cc(n={}){let c=E(n.json),k=W(n.org),g=await f().products.list(k,n.limit!==void 0?{limit:n.limit}:{}),$=g.data??[];if(c==="json"){J({org:k,products:$,total:g.total,skip:g.skip,limit:g.limit,hasMore:g.hasMore});return}V($,[{header:"ID",get:(j)=>j.id},{header:"NAME",get:(j)=>j.name??""},{header:"PRICE",get:(j)=>j.price!==void 0?`${j.price.toLocaleString()} ${j.currencyCode??""}`.trim():""},{header:"SKU",get:(j)=>j.sku??""},{header:"VISIBILITY",get:(j)=>j.visibility??""},{header:"STOCK",get:(j)=>j.availability!==void 0?String(j.availability):""}])}async function kc(n,c={}){let k=E(c.json),D=W(c.org),$=await f().products.get(D,n);if(k==="json"){J($);return}Q($)}async function Dc(n={}){let c=E(n.json),k=W(n.org),D=U(n.data),g=D&&typeof D==="object"?{...D}:{};if(n.name!==void 0)g.name=n.name;if(n.price!==void 0)g.price=n.price;if(n.currency!==void 0)g.currencyCode=n.currency;if(n.sku!==void 0)g.sku=n.sku;if(g.name===void 0)throw Error("products create: --name is required (or supply it via --data)");let j=await f().products.create(k,g);if(c==="json"){J(j);return}process.stdout.write(`Created product:
23
+ `),Q(j)}async function gc(n,c={}){let k=E(c.json),D=W(c.org),g=U(c.data),$=g&&typeof g==="object"?{...g}:{};if(c.name!==void 0)$.name=c.name;if(c.price!==void 0)$.price=c.price;if(c.currency!==void 0)$.currencyCode=c.currency;if(c.sku!==void 0)$.sku=c.sku;if(c.visibility!==void 0)$.visibility=c.visibility;if(c.availability!==void 0)$.availability=c.availability;if(Object.keys($).length===0)throw Error("products update: nothing to update (pass at least one field or --data)");let x=await f().products.update(D,n,$);if(k==="json"){J(x);return}process.stdout.write(`Updated product:
24
+ `),Q(x)}async function $c(n,c={}){let k=E(c.json),D=W(c.org);if(!c.yes){if(k==="json")throw Error("products delete: --yes is required in JSON / non-interactive mode");if(!await P(`Delete product ${n} in org ${D}? [y/N]`)){process.stdout.write(`Aborted.
25
+ `);return}}let $=await f().products.delete(D,n);if(k==="json"){J($);return}process.stdout.write(`Deleted product ${n}.
26
+ `)}var jc=new Set(["PENDING","IN_PROGRESS","SUBMITTED","CANCELED","ORDERED"]);async function xc(n={}){let c=E(n.json),k=W(n.org);if(n.status!==void 0&&!jc.has(n.status))throw Error(`Invalid quote status: ${n.status}. Allowed: ${[...jc].join(", ")}`);let D={};if(n.limit!==void 0)D.limit=n.limit;if(n.status!==void 0)D.status=n.status;let $=await f().quotes.list(k,D),j=$.data??[];if(c==="json"){J({org:k,quotes:j,total:$.total,skip:$.skip,limit:$.limit,hasMore:$.hasMore});return}V(j,[{header:"ID",get:(x)=>x.id},{header:"NAME",get:(x)=>x.name??""},{header:"PRODUCT",get:(x)=>x.productId??""},{header:"QTY",get:(x)=>x.quantity!==void 0?String(x.quantity):""},{header:"STATUS",get:(x)=>x.status??""},{header:"CREATED",get:(x)=>S(x.createdAt)}])}async function yc(n,c={}){let k=E(c.json),D=W(c.org),$=await f().quotes.get(D,n);if(k==="json"){J($);return}Q($)}async function Mc(n={}){let c=E(n.json),k=W(n.org),D={};if(n.limit!==void 0)D.limit=n.limit;let $=await f().rooms.list(k,D),j=$.data??[];if(c==="json"){J({org:k,rooms:j,total:$.total,skip:$.skip,limit:$.limit,hasMore:$.hasMore});return}V(j,[{header:"ID",get:(x)=>x.id},{header:"TITLE",get:(x)=>x.title??""},{header:"DISABLED",get:(x)=>x.disabled?"yes":"no"},{header:"TYPE",get:(x)=>x.type??""}])}async function Yc(n,c={}){let k=E(c.json),D=W(c.org),$=await f().rooms.get(D,n);if(k==="json"){J($);return}Q($)}async function Ec(n={}){let c=E(n.json),k=W(n.org),D=U(n.data),g=D&&typeof D==="object"?{...D}:{};if(n.title!==void 0)g.title=n.title;if(n.description!==void 0)g.description=n.description;if(n.type!==void 0)g.type=n.type;if(g.title===void 0)throw Error("rooms create: --title is required (or supply it via --data)");let j=await f().rooms.create(k,g);if(c==="json"){J(j);return}process.stdout.write(`Created room:
27
+ `),Q(j)}async function Jc(n,c={}){let k=E(c.json),D=W(c.org),g=U(c.data),$=g&&typeof g==="object"?{...g}:{};if(c.title!==void 0)$.title=c.title;if(c.description!==void 0)$.description=c.description;if(c.type!==void 0)$.type=c.type;if(c.disabled!==void 0)$.disabled=c.disabled;if(Object.keys($).length===0)throw Error("rooms update: nothing to update (pass at least one field or --data)");let x=await f().rooms.update(D,n,$);if(k==="json"){J(x);return}process.stdout.write(`Updated room:
28
+ `),Q(x)}async function fc(n,c={}){let k=E(c.json),D=W(c.org);if(!c.yes){if(k==="json")throw Error("rooms delete: --yes is required in JSON / non-interactive mode");if(!await P(`Delete room ${n} in org ${D}? [y/N]`)){process.stdout.write(`Aborted.
29
+ `);return}}let $=await f().rooms.delete(D,n);if(k==="json"){J($);return}process.stdout.write(`Deleted room ${n}.
30
+ `)}import{spawn as Wc}from"node:child_process";import{mkdtempSync as ec,rmSync as lc,writeFileSync as ac}from"node:fs";import{tmpdir as nk}from"node:os";import{join as Gc}from"node:path";var on={name:"@vcityio/cli",version:"0.2.4",type:"module",description:"vcity command-line interface for org owners",main:"./dist/index.js",bin:{vcity:"./dist/index.js"},files:["dist","README.md","LICENSE"],engines:{node:">=20"},publishConfig:{access:"public"},optionalDependencies:{open:">=7"},keywords:["vcity","cli"],author:"Otherwise SAS",license:"MIT",homepage:"https://vcity.io",bugs:{email:"support@owsas.com"}};var B=on.version,F=on.name;var Yn="https://vcity.io/cli/install.sh";function ck(){return typeof process.versions.bun==="string"?"binary":"npm"}async function kk(){let n=`https://registry.npmjs.org/${F}/latest`,c;try{c=await fetch(n,{headers:{accept:"application/json"}})}catch(D){throw Error("Could not reach the npm registry. Check your internet connection.",{cause:D})}if(!c.ok)throw Error(`Failed to fetch latest version from npm (HTTP ${c.status})`);let k=await c.json();if(!k.version)throw Error("Latest version response from npm is missing the `version` field");return k.version}function Tc(n){let[c,...k]=n.split("-"),[D,g,$]=c.split(".").map((j)=>parseInt(j,10));return{major:Number.isFinite(D)?D:0,minor:Number.isFinite(g)?g:0,patch:Number.isFinite($)?$:0,prerelease:k.join("-")}}function Kn(n,c){let k=Tc(n),D=Tc(c);if(k.major!==D.major)return k.major-D.major;if(k.minor!==D.minor)return k.minor-D.minor;if(k.patch!==D.patch)return k.patch-D.patch;if(k.prerelease===D.prerelease)return 0;if(k.prerelease==="")return 1;if(D.prerelease==="")return-1;return k.prerelease<D.prerelease?-1:1}function _c(n,c){return new Promise((k,D)=>{let g=Wc(n,c,{stdio:"inherit",shell:!1});g.on("error",D),g.on("exit",($)=>k({exitCode:$??1}))})}function Dk(n,c=["--version"]){return new Promise((k)=>{let D=Wc(n,c,{stdio:"ignore",shell:!1});D.on("error",()=>k(!1)),D.on("exit",(g)=>k(g===0))})}async function gk(){let n;try{n=await fetch(Yn,{headers:{accept:"text/x-shellscript, text/plain"}})}catch(g){throw Error(`Could not download installer from ${Yn}.`,{cause:g})}if(!n.ok)throw Error(`Installer download failed (HTTP ${n.status}).`);let c=await n.text();if(!c.startsWith("#!"))throw Error(`Installer at ${Yn} did not return a shell script (missing shebang). Refusing to execute.`);if(c.length>262144)throw Error(`Installer at ${Yn} is unexpectedly large (${c.length} bytes). Refusing to execute.`);let k=ec(Gc(nk(),"vcity-install-")),D=Gc(k,"install.sh");ac(D,c,{mode:448});try{return await _c("bash",[D])}finally{try{lc(k,{recursive:!0,force:!0})}catch{}}}async function Xc(n={}){let c=E(n.json),k=ck(),D=await kk(),$=Kn(B,D)<0;if(c==="json"){if(J({current:B,latest:D,outdated:$,installMethod:k}),n.check||!$)return}else{if(process.stdout.write(`current: ${B}
31
+ `),process.stdout.write(`latest: ${D}
32
+ `),!$){process.stdout.write(`vcity is up to date.
33
+ `);return}process.stdout.write(`install: ${k==="binary"?"standalone binary":"npm global"}
34
+ `)}if(n.check)return;if(!n.yes&&c!=="json"){if(process.stdout.write(`
35
+ Run with --yes to apply the update, or use the command below:
36
+ `),k==="binary")process.stdout.write(` curl -fsSL https://vcity.io/cli/install.sh | bash
37
+ `);else process.stdout.write(` npm install -g ${F}@latest
38
+ `);return}if(k==="binary"){process.stdout.write(`
39
+ Fetching latest binary…
40
+ `);let{exitCode:j}=await gk();if(j!==0)throw Error(`installer exited with code ${j}`)}else{if(!await Dk("npm"))throw Error("`npm` is not on PATH. Install Node.js 20+ from https://nodejs.org");process.stdout.write(`
41
+ Installing latest from npm…
42
+ `);let{exitCode:j}=await _c("npm",["install","-g",`${F}@latest`]);if(j!==0)throw Error(`npm install exited with code ${j}`)}process.stdout.write(`
43
+ Updated to ${D}. Run \`vcity --version\` to confirm.
44
+ `)}function $k(n){if(n&&typeof n==="object"&&"user"in n){let c=n;return{user:c.user,orgs:c.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 Zc(n={}){let c=E(n.json),D=await f().me.get(),{user:g,orgs:$}=$k(D),j=A();if(c==="json"){J({user:g,orgs:$,active_org:j.active_org??null});return}let x=g.email??g.name??g.id;process.stdout.write(`User: ${x}
45
+ `),process.stdout.write(`User ID: ${g.id}
46
+ `),process.stdout.write(`Active org: ${j.active_org??"(none — run `vcity org use <slug>`)"}
47
+ `)}var jk=new Set(["json","yes","check","no-browser","disabled"]);function Qc(n){let c=[],k={};for(let D=0;D<n.length;D++){let g=n[D];if(!g.startsWith("--")){c.push(g);continue}let $=g.indexOf("=");if($>=0){k[g.slice(2,$)]=g.slice($+1);continue}let j=g.slice(2),x=n[D+1];if(jk.has(j)||x===void 0||x.startsWith("--"))k[j]=!0;else k[j]=x,D++}return{positional:c,flags:k}}import{mkdirSync as xk,readFileSync as yk,writeFileSync as Mk}from"node:fs";import Yk from"node:path";var Ek=86400000,Jk=1500;function Rc(){return Yk.join(H(),"update-check.json")}function fk(){try{let n=yk(Rc(),"utf8"),c=JSON.parse(n);if(typeof c.latest==="string"&&typeof c.checkedAt==="number")return c;return}catch{return}}function Gk(n){try{xk(H(),{recursive:!0}),Mk(Rc(),JSON.stringify(n,null,2),{mode:384})}catch{}}async function Tk(){let n=new AbortController,c=setTimeout(()=>n.abort(),Jk);try{let k=await fetch(`https://registry.npmjs.org/${F}/latest`,{headers:{accept:"application/json"},signal:n.signal});if(!k.ok)return;let D=await k.json();return typeof D.version==="string"?D.version:void 0}catch{return}finally{clearTimeout(c)}}function oc(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 Kc(){let n=fk(),c=Date.now();if(n&&c-n.checkedAt<Ek)return Promise.resolve(n.latest);return Tk().then((k)=>{if(k)Gk({latest:k,checkedAt:c});return k??n?.latest})}function Vc(n){if(!n)return;if(Kn(B,n)>=0)return;process.stderr.write(`
48
+ → vcity ${n} available (you have ${B}). Run \`vcity update\` to upgrade.
49
+ `)}function X(n){process.stderr.write(`error: ${N(n)}
50
+ `),process.exit(1)}function Wk(){process.stdout.write(`vcity ${B}
25
51
 
26
52
  Usage:
27
53
  vcity login [--api-base-url <url>] [--no-browser]
@@ -31,11 +57,32 @@ Usage:
31
57
  vcity org use <slug>
32
58
  vcity products list [--org <slug>] [--limit <n>] [--json]
33
59
  vcity products get <id> [--org <slug>] [--json]
60
+ vcity products create [--org <slug>] [--name <s>] [--price <n>] [--currency <c>] [--sku <s>] [--data <json|@file>] [--json]
61
+ vcity products update <id> [--org <slug>] [--name <s>] [--price <n>] [--currency <c>] [--sku <s>] [--visibility <v>] [--availability <n>] [--data <json|@file>] [--json]
62
+ vcity products delete <id> [--org <slug>] [--yes] [--json]
63
+ vcity events list [--org <slug>] [--limit <n>] [--status active|disabled] [--json]
64
+ vcity events get <id> [--org <slug>] [--json]
65
+ vcity events create [--org <slug>] [--name <s>] [--starts-at <iso|ms>] [--ends-at <iso|ms>] [--slug <s>] [--data <json|@file>] [--json]
66
+ vcity events update <id> [--org <slug>] [--name <s>] [--starts-at <iso|ms>] [--ends-at <iso|ms>] [--slug <s>] [--status <s>] [--data <json|@file>] [--json]
67
+ vcity events delete <id> [--org <slug>] [--yes] [--json]
68
+ vcity rooms list [--org <slug>] [--limit <n>] [--json]
69
+ vcity rooms get <id> [--org <slug>] [--json]
70
+ vcity rooms create [--org <slug>] [--title <s>] [--description <s>] [--type <s>] [--data <json|@file>] [--json]
71
+ vcity rooms update <id> [--org <slug>] [--title <s>] [--description <s>] [--type <s>] [--disabled] [--data <json|@file>] [--json]
72
+ vcity rooms delete <id> [--org <slug>] [--yes] [--json]
73
+ vcity bookings list [--org <slug>] [--limit <n>] [--status <s>] [--json]
74
+ vcity bookings get <id> [--org <slug>] [--json]
75
+ vcity orders list [--org <slug>] [--limit <n>] [--status <s>] [--json]
76
+ vcity orders get <id> [--org <slug>] [--json]
77
+ vcity quotes list [--org <slug>] [--limit <n>] [--status PENDING|IN_PROGRESS|SUBMITTED|CANCELED|ORDERED] [--json]
78
+ vcity quotes get <id> [--org <slug>] [--json]
79
+ vcity update [--check] [--yes] [--json]
34
80
 
35
81
  Environment:
36
82
  VCITY_API_BASE_URL override the API base URL (e.g. https://staging.vcity.io)
37
83
  VCITY_CONFIG_DIR override the config directory (default ~/.vcity)
38
84
  VCITY_NO_OPEN_BROWSER never auto-launch a browser during \`vcity login\`
39
- `)}async function cn(){let o=process.argv.slice(2);if(o.length===0||o[0]==="--help"||o[0]==="-h"||o[0]==="help"){gn();return}if(o[0]==="--version"||o[0]==="-v"){process.stdout.write(`${Fo}
40
- `);return}let[g,n,...t]=o,c=o.slice(1),{positional:i,flags:f}=Lo(c),y=i.slice(n&&!n.startsWith("--")?1:0);switch(g){case"login":return Jo({apiBaseUrl:typeof f["api-base-url"]==="string"?f["api-base-url"]:void 0,openBrowser:f["no-browser"]===!0?!1:void 0});case"logout":return Do();case"whoami":return Mo({json:!!f.json});case"org":{if(n==="list")return Vo({json:!!f.json});if(n==="use"){let r=y[0];if(!r)K("usage: vcity org use <slug>");return Yo(r)}K("usage: vcity org list | vcity org use <slug>")}case"products":{if(n==="list")return Wo({org:typeof f.org==="string"?f.org:void 0,limit:typeof f.limit==="string"?parseInt(f.limit,10):void 0,json:!!f.json});if(n==="get"){let r=y[0];if(!r)K("usage: vcity products get <id>");return so(r,{org:typeof f.org==="string"?f.org:void 0,json:!!f.json})}K("usage: vcity products list | vcity products get <id>")}default:K(`unknown command: ${g}. Run \`vcity --help\`.`)}}cn().catch((o)=>{let g=o instanceof Error?o.message:String(o);process.stderr.write(`error: ${g}
85
+ VCITY_NO_UPDATE_CHECK disable the background "new version available" check
86
+ `)}function _k(n){if(typeof n!=="string")return;let c=parseInt(n,10);if(Number.isNaN(c)||c<0)X(`--limit must be a non-negative integer (got: ${n})`);return c}function Vn(n,c){if(n===void 0)return;if(typeof n!=="string")return;let k=Number(n);if(!Number.isFinite(k))X(`${c} must be a number (got: ${n})`);return k}function G(n,c){return typeof n[c]==="string"?n[c]:void 0}function b(n){return{org:typeof n.org==="string"?n.org:void 0,limit:_k(n.limit),status:typeof n.status==="string"?n.status:void 0,json:!!n.json}}async function Xk(n){if(n.length===0||n[0]==="--help"||n[0]==="-h"||n[0]==="help"){Wk();return}if(n[0]==="--version"||n[0]==="-v"){process.stdout.write(`${B}
87
+ `);return}let[c,k,...D]=n,g=n.slice(1),{positional:$,flags:j}=Qc(g),x=$.slice(k&&!k.startsWith("--")?1:0);switch(c){case"login":return hn({apiBaseUrl:typeof j["api-base-url"]==="string"?j["api-base-url"]:void 0,openBrowser:j["no-browser"]===!0?!1:void 0});case"logout":return pn();case"whoami":return Zc({json:!!j.json});case"org":{if(k==="list")return an({json:!!j.json});if(k==="use"){let y=x[0];if(!y)X("usage: vcity org use <slug>");return nc(y)}X("usage: vcity org list | vcity org use <slug>")}case"products":{let y=b(j);if(k==="list")return cc({org:y.org,limit:y.limit,json:y.json});if(k==="get"){let M=x[0];if(!M)X("usage: vcity products get <id>");return kc(M,{org:y.org,json:y.json})}if(k==="create")return Dc({org:y.org,name:G(j,"name"),price:Vn(j.price,"--price"),currency:G(j,"currency"),sku:G(j,"sku"),data:G(j,"data"),json:y.json});if(k==="update"){let M=x[0];if(!M)X("usage: vcity products update <id>");return gc(M,{org:y.org,name:G(j,"name"),price:Vn(j.price,"--price"),currency:G(j,"currency"),sku:G(j,"sku"),visibility:G(j,"visibility"),availability:Vn(j.availability,"--availability"),data:G(j,"data"),json:y.json})}if(k==="delete"){let M=x[0];if(!M)X("usage: vcity products delete <id>");return $c(M,{org:y.org,yes:j.yes===!0,json:y.json})}X("usage: vcity products list|get|create|update|delete")}case"events":{let y=b(j);if(k==="list"){let M=y.status;if(M!==void 0&&M!=="active"&&M!=="disabled")X(`invalid --status: ${M}. Allowed: active, disabled`);return In({org:y.org,limit:y.limit,status:M,json:y.json})}if(k==="get"){let M=x[0];if(!M)X("usage: vcity events get <id>");return vn(M,{org:y.org,json:y.json})}if(k==="create")return dn({org:y.org,name:G(j,"name"),startsAt:G(j,"starts-at"),endsAt:G(j,"ends-at"),slug:G(j,"slug"),data:G(j,"data"),json:y.json});if(k==="update"){let M=x[0];if(!M)X("usage: vcity events update <id>");return un(M,{org:y.org,name:G(j,"name"),startsAt:G(j,"starts-at"),endsAt:G(j,"ends-at"),slug:G(j,"slug"),status:G(j,"status"),data:G(j,"data"),json:y.json})}if(k==="delete"){let M=x[0];if(!M)X("usage: vcity events delete <id>");return tn(M,{org:y.org,yes:j.yes===!0,json:y.json})}X("usage: vcity events list|get|create|update|delete")}case"rooms":{let y=b(j);if(k==="list")return Mc({org:y.org,limit:y.limit,json:y.json});if(k==="get"){let M=x[0];if(!M)X("usage: vcity rooms get <id>");return Yc(M,{org:y.org,json:y.json})}if(k==="create")return Ec({org:y.org,title:G(j,"title"),description:G(j,"description"),type:G(j,"type"),data:G(j,"data"),json:y.json});if(k==="update"){let M=x[0];if(!M)X("usage: vcity rooms update <id>");return Jc(M,{org:y.org,title:G(j,"title"),description:G(j,"description"),type:G(j,"type"),disabled:j.disabled===!0?!0:void 0,data:G(j,"data"),json:y.json})}if(k==="delete"){let M=x[0];if(!M)X("usage: vcity rooms delete <id>");return fc(M,{org:y.org,yes:j.yes===!0,json:y.json})}X("usage: vcity rooms list|get|create|update|delete")}case"bookings":{let y=b(j);if(k==="list")return Fn(y);if(k==="get"){let M=x[0];if(!M)X("usage: vcity bookings get <id>");return bn(M,{org:y.org,json:y.json})}X("usage: vcity bookings list | vcity bookings get <id>")}case"orders":{let y=b(j);if(k==="list")return sn(y);if(k==="get"){let M=x[0];if(!M)X("usage: vcity orders get <id>");return en(M,{org:y.org,json:y.json})}X("usage: vcity orders list | vcity orders get <id>")}case"quotes":{let y=b(j);if(k==="list")return xc(y);if(k==="get"){let M=x[0];if(!M)X("usage: vcity quotes get <id>");return yc(M,{org:y.org,json:y.json})}X("usage: vcity quotes list | vcity quotes get <id>")}case"update":return Xc({check:j.check===!0,yes:j.yes===!0,json:!!j.json});default:X(`unknown command: ${c}. Run \`vcity --help\`.`)}}async function Zk(){let n=process.argv.slice(2),c=oc(n)?Kc():void 0;try{await Xk(n)}finally{if(c)Vc(await c)}}Zk().catch((n)=>{let c=n instanceof Error?n.message:String(n);process.stderr.write(`error: ${N(c)}
41
88
  `),process.exit(1)});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vcityio/cli",
3
- "version": "0.1.0",
3
+ "version": "0.2.4",
4
4
  "type": "module",
5
5
  "description": "vcity command-line interface for org owners",
6
6
  "main": "./dist/index.js",