@vcityio/cli 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Otherwise SAS
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,91 @@
1
+ # `@vcityio/cli`
2
+
3
+ Official command-line interface for [vcity](https://vcity.io). Modeled after `gh`, `gcloud`, and `vercel` — terminal-first product management for org owners and staff.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install -g @vcityio/cli
9
+ ```
10
+
11
+ Requires **Node 20+**. Standalone binaries (no Node required) ship in a future release.
12
+
13
+ ## First run
14
+
15
+ ```bash
16
+ vcity login
17
+ ```
18
+
19
+ Opens a browser for the device-flow approval. Stores tokens at `~/.vcity/auth.json` (mode 0600). Subsequent commands use that file — no password to manage.
20
+
21
+ ```bash
22
+ vcity org list # show orgs you have access to
23
+ vcity org use my-shop # set the active org for future commands
24
+ vcity products list # uses the active org
25
+ vcity products list --org acme # one-off override
26
+ vcity products get prod_abc123
27
+ vcity whoami
28
+ vcity logout
29
+ ```
30
+
31
+ Every read command accepts `--json` for scripting. Output auto-falls-back to JSON when stdout isn't a TTY (pipes, redirects, CI runs).
32
+
33
+ ## Available commands
34
+
35
+ | Command | What it does |
36
+ |---------|--------------|
37
+ | `vcity login [--api-base-url <url>] [--no-browser]` | Device-flow login. Writes auth file. |
38
+ | `vcity logout` | Revoke server-side token + delete local auth file. |
39
+ | `vcity whoami [--json]` | Print the logged-in user + active org. |
40
+ | `vcity org list [--json]` | List orgs you can access. |
41
+ | `vcity org use <slug>` | Set the active org. |
42
+ | `vcity products list [--org <slug>] [--limit <n>] [--json]` | List products of the active org. |
43
+ | `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.
46
+
47
+ ## Environment variables
48
+
49
+ | Variable | Purpose |
50
+ |----------|---------|
51
+ | `VCITY_API_BASE_URL` | Override the API host (e.g. `https://staging.vcity.io`). |
52
+ | `VCITY_CONFIG_DIR` | Override the config dir (default `~/.vcity`). Handy for sandboxing dev sessions. |
53
+ | `VCITY_NO_OPEN_BROWSER` | Never auto-launch a browser during `vcity login`. |
54
+
55
+ CI tip: `vcity` detects non-interactive stdout and emits JSON without `--json`. Combine with `jq` for pipelines.
56
+
57
+ ## Authentication
58
+
59
+ 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.
60
+
61
+ For server-to-server integrations, generate an **org API key** (`vapi_…`) from the vcity dashboard and use the [`@vcityio/api-client`](https://www.npmjs.com/package/@vcityio/api-client) SDK directly.
62
+
63
+ ## Scripting
64
+
65
+ ```bash
66
+ # Pipe to jq
67
+ vcity products list --org acme --limit 5 \
68
+ | jq -r '.products[] | "\(.id)\t\(.name)"'
69
+
70
+ # Exit codes
71
+ if ! vcity whoami --json >/dev/null 2>&1; then
72
+ vcity login
73
+ fi
74
+ ```
75
+
76
+ Non-zero exit codes:
77
+ - `1` — generic error (no active org, no auth, request failed)
78
+ - `2` — usage / bad arguments
79
+
80
+ ## Support
81
+
82
+ Email **support@owsas.com** for issues, feature requests, or token problems.
83
+
84
+ ## Related
85
+
86
+ - [`@vcityio/api-client`](https://www.npmjs.com/package/@vcityio/api-client) — the typed SDK this CLI is built on. Use it directly when you need programmatic access from your own services.
87
+ - [API reference](https://vcity.io/docs/api) — OpenAPI 3.1 + Scalar.
88
+
89
+ ## License
90
+
91
+ MIT © Otherwise SAS
package/dist/index.js ADDED
@@ -0,0 +1,41 @@
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(`
4
+ Open this URL to approve the session:
5
+ ${n.verification_uri}
6
+ `),process.stdout.write(`Enter this code:
7
+ ${n.user_code}
8
+
9
+ `),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}
25
+
26
+ Usage:
27
+ vcity login [--api-base-url <url>] [--no-browser]
28
+ vcity logout
29
+ vcity whoami [--json]
30
+ vcity org list [--json]
31
+ vcity org use <slug>
32
+ vcity products list [--org <slug>] [--limit <n>] [--json]
33
+ vcity products get <id> [--org <slug>] [--json]
34
+
35
+ Environment:
36
+ VCITY_API_BASE_URL override the API base URL (e.g. https://staging.vcity.io)
37
+ VCITY_CONFIG_DIR override the config directory (default ~/.vcity)
38
+ 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}
41
+ `),process.exit(1)});
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@vcityio/cli",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "description": "vcity command-line interface for org owners",
6
+ "main": "./dist/index.js",
7
+ "bin": {
8
+ "vcity": "./dist/index.js"
9
+ },
10
+ "files": [
11
+ "dist",
12
+ "README.md",
13
+ "LICENSE"
14
+ ],
15
+ "engines": {
16
+ "node": ">=20"
17
+ },
18
+ "publishConfig": {
19
+ "access": "public"
20
+ },
21
+ "optionalDependencies": {
22
+ "open": ">=7"
23
+ },
24
+ "keywords": [
25
+ "vcity",
26
+ "cli"
27
+ ],
28
+ "author": "Otherwise SAS",
29
+ "license": "MIT",
30
+ "homepage": "https://vcity.io",
31
+ "bugs": {
32
+ "email": "support@owsas.com"
33
+ }
34
+ }