@vcityio/cli 0.7.9 → 0.7.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var qr=/\{[^{}]+\}/g,$r=()=>typeof process==="object"&&Number.parseInt(process?.versions?.node?.substring(0,2))>=18&&process.versions.undici;function Lr(){return Math.random().toString(36).slice(2,11)}function Pe(e){let{baseUrl:t="",Request:r=globalThis.Request,fetch:o=globalThis.fetch,querySerializer:s,bodySerializer:i,headers:n,requestInitExt:a=void 0,...d}={...e};a=$r()?a:void 0,t=Qe(t);let c=[];async function w(f,j){let{baseUrl:S,fetch:J=o,Request:Ve=r,headers:ze,params:H={},parseAs:Se="json",querySerializer:re,bodySerializer:Je=i??Fr,body:He,...Ie}=j||{},Oe=t;if(S)Oe=Qe(S)??t;let xe=typeof s==="function"?s:We(s);if(re)xe=typeof re==="function"?re:We({...typeof s==="object"?s:{},...re});let Ae=He===void 0?void 0:Je(He,Ye(n,ze,H.header)),Dr=Ye(Ae===void 0||Ae instanceof FormData?{}:{"Content-Type":"application/json"},n,ze,H.header),Ur={redirect:"follow",...d,...Ie,body:Ae,headers:Dr},ne,oe,q=new r(Mr(f,{baseUrl:Oe,params:H,querySerializer:xe}),Ur),R;for(let A in Ie)if(!(A in q))q[A]=Ie[A];if(c.length){ne=Lr(),oe=Object.freeze({baseUrl:Oe,fetch:J,parseAs:Se,querySerializer:xe,bodySerializer:Je});for(let A of c)if(A&&typeof A==="object"&&typeof A.onRequest==="function"){let O=await A.onRequest({request:q,schemaPath:f,params:H,options:oe,id:ne});if(O)if(O instanceof r)q=O;else if(O instanceof Response){R=O;break}else throw Error("onRequest: must return new Request() or Response() when modifying the request")}}if(!R){try{R=await J(q,a)}catch(A){let O=A;if(c.length)for(let F=c.length-1;F>=0;F--){let se=c[F];if(se&&typeof se==="object"&&typeof se.onError==="function"){let K=await se.onError({request:q,error:O,schemaPath:f,params:H,options:oe,id:ne});if(K){if(K instanceof Response){O=void 0,R=K;break}if(K instanceof Error){O=K;continue}throw Error("onError: must return new Response() or instance of Error")}}}if(O)throw O}if(c.length)for(let A=c.length-1;A>=0;A--){let O=c[A];if(O&&typeof O==="object"&&typeof O.onResponse==="function"){let F=await O.onResponse({request:q,response:R,schemaPath:f,params:H,options:oe,id:ne});if(F){if(!(F instanceof Response))throw Error("onResponse: must return new Response() when modifying the response");R=F}}}}if(R.status===204||q.method==="HEAD"||R.headers.get("Content-Length")==="0")return R.ok?{data:void 0,response:R}:{error:void 0,response:R};if(R.ok){if(Se==="stream")return{data:R.body,response:R};return{data:await R[Se](),response:R}}let _e=await R.text();try{_e=JSON.parse(_e)}catch{}return{error:_e,response:R}}return{request(f,j,S){return w(j,{...S,method:f.toUpperCase()})},GET(f,j){return w(f,{...j,method:"GET"})},PUT(f,j){return w(f,{...j,method:"PUT"})},POST(f,j){return w(f,{...j,method:"POST"})},DELETE(f,j){return w(f,{...j,method:"DELETE"})},OPTIONS(f,j){return w(f,{...j,method:"OPTIONS"})},HEAD(f,j){return w(f,{...j,method:"HEAD"})},PATCH(f,j){return w(f,{...j,method:"PATCH"})},TRACE(f,j){return w(f,{...j,method:"TRACE"})},use(...f){for(let j of f){if(!j)continue;if(typeof j!=="object"||!(("onRequest"in j)||("onResponse"in j)||("onError"in j)))throw Error("Middleware must be an object with one of `onRequest()`, `onResponse() or `onError()`");c.push(j)}},eject(...f){for(let j of f){let S=c.indexOf(j);if(S!==-1)c.splice(S,1)}}}}function ie(e,t,r){if(t===void 0||t===null)return"";if(typeof t==="object")throw Error("Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.");return`${e}=${r?.allowReserved===!0?t:encodeURIComponent(t)}`}function Xe(e,t,r){if(!t||typeof t!=="object")return"";let o=[],s={simple:",",label:".",matrix:";"}[r.style]||"&";if(r.style!=="deepObject"&&r.explode===!1){for(let a in t)o.push(a,r.allowReserved===!0?t[a]:encodeURIComponent(t[a]));let n=o.join(",");switch(r.style){case"form":return`${e}=${n}`;case"label":return`.${n}`;case"matrix":return`;${e}=${n}`;default:return n}}for(let n in t){let a=r.style==="deepObject"?`${e}[${n}]`:n;o.push(ie(a,t[n],r))}let i=o.join(s);return r.style==="label"||r.style==="matrix"?`${s}${i}`:i}function Ke(e,t,r){if(!Array.isArray(t))return"";if(r.explode===!1){let i={form:",",spaceDelimited:"%20",pipeDelimited:"|"}[r.style]||",",n=(r.allowReserved===!0?t:t.map((a)=>encodeURIComponent(a))).join(i);switch(r.style){case"simple":return n;case"label":return`.${n}`;case"matrix":return`;${e}=${n}`;default:return`${e}=${n}`}}let o={simple:",",label:".",matrix:";"}[r.style]||"&",s=[];for(let i of t)if(r.style==="simple"||r.style==="label")s.push(r.allowReserved===!0?i:encodeURIComponent(i));else s.push(ie(e,i,r));return r.style==="label"||r.style==="matrix"?`${o}${s.join(o)}`:s.join(o)}function We(e){return function(r){let o=[];if(r&&typeof r==="object")for(let s in r){let i=r[s];if(i===void 0||i===null)continue;if(Array.isArray(i)){if(i.length===0)continue;o.push(Ke(s,i,{style:"form",explode:!0,...e?.array,allowReserved:e?.allowReserved||!1}));continue}if(typeof i==="object"){o.push(Xe(s,i,{style:"deepObject",explode:!0,...e?.object,allowReserved:e?.allowReserved||!1}));continue}o.push(ie(s,i,e))}return o.join("&")}}function Br(e,t){let r=e;for(let o of e.match(qr)??[]){let s=o.substring(1,o.length-1),i=!1,n="simple";if(s.endsWith("*"))i=!0,s=s.substring(0,s.length-1);if(s.startsWith("."))n="label",s=s.substring(1);else if(s.startsWith(";"))n="matrix",s=s.substring(1);if(!t||t[s]===void 0||t[s]===null)continue;let a=t[s];if(Array.isArray(a)){r=r.replace(o,Ke(s,a,{style:n,explode:i}));continue}if(typeof a==="object"){r=r.replace(o,Xe(s,a,{style:n,explode:i}));continue}if(n==="matrix"){r=r.replace(o,`;${ie(s,a)}`);continue}r=r.replace(o,n==="label"?`.${encodeURIComponent(a)}`:encodeURIComponent(a))}return r}function Fr(e,t){if(e instanceof FormData)return e;if(t){if((t.get instanceof Function?t.get("Content-Type")??t.get("content-type"):t["Content-Type"]??t["content-type"])==="application/x-www-form-urlencoded")return new URLSearchParams(e).toString()}return JSON.stringify(e)}function Mr(e,t){let r=`${t.baseUrl}${e}`;if(t.params?.path)r=Br(r,t.params.path);let o=t.querySerializer(t.params.query??{});if(o.startsWith("?"))o=o.substring(1);if(o)r+=`?${o}`;return r}function Ye(...e){let t=new Headers;for(let r of e){if(!r||typeof r!=="object")continue;let o=r instanceof Headers?r.entries():Object.entries(r);for(let[s,i]of o)if(i===null)t.delete(s);else if(Array.isArray(i))for(let n of i)t.append(s,n);else if(i!==void 0)t.set(s,i)}return t}function Qe(e){if(e.endsWith("/"))return e.substring(0,e.length-1);return e}class W extends Error{status;body;url;constructor(e,t,r,o){super(e);this.name="ApiClientError",this.status=t,this.body=r,this.url=o.split("?")[0]}}function y(e,t){if(e.error!==void 0&&e.error!==null){let r=e.response?.status??0,o=e.response?.url??"",s=typeof e.error==="object"&&e.error!==null&&"error"in e.error&&typeof e.error.error==="object"&&e.error.error?.message||`${t} failed (${r})`;throw new W(String(s),r,e.error,o)}if(e.data===void 0)throw new W(`${t}: empty response body`,e.response?.status??0,void 0,e.response?.url??"");return e.data}class ae{client;constructor(e){this.client=e}async get(){let e=await this.client.GET("/api/v1/me",{});return y(e,"me.get")}}class de{client;constructor(e){this.client=e}async get(e){let t=await this.client.GET("/api/v1/orgs/{orgId}",{params:{path:{orgId:e}}});return y(t,"orgs.get")}async listMembers(e,t={}){let r=await this.client.GET("/api/v1/orgs/{orgId}/members",{params:{path:{orgId:e},query:t}});return y(r,"orgs.listMembers")}}class ce{client;constructor(e){this.client=e}async list(e,t={}){let r=await this.client.GET("/api/v1/orgs/{orgId}/products",{params:{path:{orgId:e},query:t}});return y(r,"products.list")}async get(e,t){let r=await this.client.GET("/api/v1/orgs/{orgId}/products/{productId}",{params:{path:{orgId:e,productId:t}}});return y(r,"products.get")}async create(e,t){let r=await this.client.POST("/api/v1/orgs/{orgId}/products",{params:{path:{orgId:e}},body:t});return y(r,"products.create")}async update(e,t,r){let o=await this.client.PUT("/api/v1/orgs/{orgId}/products/{productId}",{params:{path:{orgId:e,productId:t}},body:r});return y(o,"products.update")}async delete(e,t){let r=await this.client.DELETE("/api/v1/orgs/{orgId}/products/{productId}",{params:{path:{orgId:e,productId:t}}});return y(r,"products.delete")}}class ue{client;constructor(e){this.client=e}async list(e,t={}){let r=await this.client.GET("/api/v1/orgs/{orgId}/events",{params:{path:{orgId:e},query:t}});return y(r,"events.list")}async get(e,t){let r=await this.client.GET("/api/v1/orgs/{orgId}/events/{eventId}",{params:{path:{orgId:e,eventId:t}}});return y(r,"events.get")}async create(e,t){let r=await this.client.POST("/api/v1/orgs/{orgId}/events",{params:{path:{orgId:e}},body:t});return y(r,"events.create")}async update(e,t,r){let o=await this.client.PUT("/api/v1/orgs/{orgId}/events/{eventId}",{params:{path:{orgId:e,eventId:t}},body:r});return y(o,"events.update")}async delete(e,t){let r=await this.client.DELETE("/api/v1/orgs/{orgId}/events/{eventId}",{params:{path:{orgId:e,eventId:t}}});return y(r,"events.delete")}}class ge{client;constructor(e){this.client=e}async list(e,t={}){let r=await this.client.GET("/api/v1/orgs/{orgId}/rooms",{params:{path:{orgId:e},query:t}});return y(r,"rooms.list")}async get(e,t){let r=await this.client.GET("/api/v1/orgs/{orgId}/rooms/{roomId}",{params:{path:{orgId:e,roomId:t}}});return y(r,"rooms.get")}async create(e,t){let r=await this.client.POST("/api/v1/orgs/{orgId}/rooms",{params:{path:{orgId:e}},body:t});return y(r,"rooms.create")}async update(e,t,r){let o=await this.client.PUT("/api/v1/orgs/{orgId}/rooms/{roomId}",{params:{path:{orgId:e,roomId:t}},body:r});return y(o,"rooms.update")}async delete(e,t){let r=await this.client.DELETE("/api/v1/orgs/{orgId}/rooms/{roomId}",{params:{path:{orgId:e,roomId:t}}});return y(r,"rooms.delete")}}class le{client;constructor(e){this.client=e}async list(e,t={}){let r=await this.client.GET("/api/v1/orgs/{orgId}/bookings",{params:{path:{orgId:e},query:t}});return y(r,"bookings.list")}async get(e,t){let r=await this.client.GET("/api/v1/orgs/{orgId}/bookings/{bookingId}",{params:{path:{orgId:e,bookingId:t}}});return y(r,"bookings.get")}async create(e,t){let r=await this.client.POST("/api/v1/orgs/{orgId}/bookings",{params:{path:{orgId:e}},body:t});return y(r,"bookings.create")}async update(e,t,r){let o=await this.client.PUT("/api/v1/orgs/{orgId}/bookings/{bookingId}",{params:{path:{orgId:e,bookingId:t}},body:r});return y(o,"bookings.update")}async delete(e,t){let r=await this.client.DELETE("/api/v1/orgs/{orgId}/bookings/{bookingId}",{params:{path:{orgId:e,bookingId:t}}});return y(r,"bookings.delete")}}class me{client;constructor(e){this.client=e}async list(e,t={}){let r=await this.client.GET("/api/v1/orgs/{orgId}/projects",{params:{path:{orgId:e},query:t}});return y(r,"projects.list")}async get(e,t){let r=await this.client.GET("/api/v1/orgs/{orgId}/projects/{projectId}",{params:{path:{orgId:e,projectId:t}}});return y(r,"projects.get")}async create(e,t){let r=await this.client.POST("/api/v1/orgs/{orgId}/projects",{params:{path:{orgId:e}},body:t});return y(r,"projects.create")}async update(e,t,r){let o=await this.client.PUT("/api/v1/orgs/{orgId}/projects/{projectId}",{params:{path:{orgId:e,projectId:t}},body:r});return y(o,"projects.update")}async delete(e,t){let r=await this.client.DELETE("/api/v1/orgs/{orgId}/projects/{projectId}",{params:{path:{orgId:e,projectId:t}}});return y(r,"projects.delete")}async listCards(e,t,r={}){let o=await this.client.GET("/api/v1/orgs/{orgId}/projects/{projectId}/cards",{params:{path:{orgId:e,projectId:t},query:r}});return y(o,"projects.listCards")}async getCard(e,t,r){let o=await this.client.GET("/api/v1/orgs/{orgId}/projects/{projectId}/cards/{cardId}",{params:{path:{orgId:e,projectId:t,cardId:r}}});return y(o,"projects.getCard")}async createCard(e,t,r){let o=await this.client.POST("/api/v1/orgs/{orgId}/projects/{projectId}/cards",{params:{path:{orgId:e,projectId:t}},body:r});return y(o,"projects.createCard")}async updateCard(e,t,r,o){let s=await this.client.PUT("/api/v1/orgs/{orgId}/projects/{projectId}/cards/{cardId}",{params:{path:{orgId:e,projectId:t,cardId:r}},body:o});return y(s,"projects.updateCard")}async moveCard(e,t,r,o){let s=await this.client.POST("/api/v1/orgs/{orgId}/projects/{projectId}/cards/{cardId}/move",{params:{path:{orgId:e,projectId:t,cardId:r}},body:o});return y(s,"projects.moveCard")}async deleteCard(e,t,r){let o=await this.client.DELETE("/api/v1/orgs/{orgId}/projects/{projectId}/cards/{cardId}",{params:{path:{orgId:e,projectId:t,cardId:r}}});return y(o,"projects.deleteCard")}async listCardComments(e,t,r,o={}){let s=await this.client.GET("/api/v1/orgs/{orgId}/projects/{projectId}/cards/{cardId}/comments",{params:{path:{orgId:e,projectId:t,cardId:r},query:o}});return y(s,"projects.listCardComments")}async createCardComment(e,t,r,o){let s=await this.client.POST("/api/v1/orgs/{orgId}/projects/{projectId}/cards/{cardId}/comments",{params:{path:{orgId:e,projectId:t,cardId:r}},body:o});return y(s,"projects.createCardComment")}}class pe{client;constructor(e){this.client=e}async list(e,t={}){let r=await this.client.GET("/api/v1/orgs/{orgId}/blogs",{params:{path:{orgId:e},query:t}});return y(r,"blogs.list")}async get(e,t){let r=await this.client.GET("/api/v1/orgs/{orgId}/blogs/{blogId}",{params:{path:{orgId:e,blogId:t}}});return y(r,"blogs.get")}async create(e,t){let r=await this.client.POST("/api/v1/orgs/{orgId}/blogs",{params:{path:{orgId:e}},body:t});return y(r,"blogs.create")}async update(e,t,r){let o=await this.client.PUT("/api/v1/orgs/{orgId}/blogs/{blogId}",{params:{path:{orgId:e,blogId:t}},body:r});return y(o,"blogs.update")}async delete(e,t){let r=await this.client.DELETE("/api/v1/orgs/{orgId}/blogs/{blogId}",{params:{path:{orgId:e,blogId:t}}});return y(r,"blogs.delete")}}class fe{client;constructor(e){this.client=e}async list(e,t={}){let r=await this.client.GET("/api/v1/orgs/{orgId}/booking-types",{params:{path:{orgId:e},query:t}});return y(r,"bookingTypes.list")}async get(e,t){let r=await this.client.GET("/api/v1/orgs/{orgId}/booking-types/{bookingTypeId}",{params:{path:{orgId:e,bookingTypeId:t}}});return y(r,"bookingTypes.get")}async create(e,t){let r=await this.client.POST("/api/v1/orgs/{orgId}/booking-types",{params:{path:{orgId:e}},body:t});return y(r,"bookingTypes.create")}async update(e,t,r){let o=await this.client.PUT("/api/v1/orgs/{orgId}/booking-types/{bookingTypeId}",{params:{path:{orgId:e,bookingTypeId:t}},body:r});return y(o,"bookingTypes.update")}async delete(e,t){let r=await this.client.DELETE("/api/v1/orgs/{orgId}/booking-types/{bookingTypeId}",{params:{path:{orgId:e,bookingTypeId:t}}});return y(r,"bookingTypes.delete")}}class ye{client;constructor(e){this.client=e}async list(e,t={}){let r=await this.client.GET("/api/v1/orgs/{orgId}/orders",{params:{path:{orgId:e},query:t}});return y(r,"orders.list")}async get(e,t){let r=await this.client.GET("/api/v1/orgs/{orgId}/orders/{orderId}",{params:{path:{orgId:e,orderId:t}}});return y(r,"orders.get")}}class he{client;constructor(e){this.client=e}async list(e,t={}){let r=await this.client.GET("/api/v1/orgs/{orgId}/quotes",{params:{path:{orgId:e},query:t}});return y(r,"quotes.list")}async get(e,t){let r=await this.client.GET("/api/v1/orgs/{orgId}/quotes/{quoteId}",{params:{path:{orgId:e,quoteId:t}}});return y(r,"quotes.get")}async create(e,t){let r=await this.client.POST("/api/v1/orgs/{orgId}/quotes",{params:{path:{orgId:e}},body:t});return y(r,"quotes.create")}async update(e,t,r){let o=await this.client.PUT("/api/v1/orgs/{orgId}/quotes/{quoteId}",{params:{path:{orgId:e,quoteId:t}},body:r});return y(o,"quotes.update")}async delete(e,t){let r=await this.client.DELETE("/api/v1/orgs/{orgId}/quotes/{quoteId}",{params:{path:{orgId:e,quoteId:t}}});return y(r,"quotes.delete")}}var Gr="https://vcity.io";function Vr(e){let t;try{t=new URL(e)}catch{throw Error(`@vcityio/api-client: invalid baseUrl (${e.slice(0,200)})`)}if(t.protocol==="https:")return;if(t.protocol==="http:"&&(t.hostname==="localhost"||t.hostname==="127.0.0.1"||t.hostname==="[::1]"))return;throw Error(`@vcityio/api-client: baseUrl must use https:// for non-localhost hosts (got: ${t.protocol}//${t.hostname}).`)}function zr(e,t){let r=t??globalThis.fetch;if(!r)throw Error("@vcityio/api-client: no fetch implementation found. Provide options.fetch or run on Node >=20 / a browser.");return async function(s){if(!e)return r(s);let n=s.headers.get("Authorization")?.match(/^Bearer\s+(.+)$/)?.[1]?.trim();if(n&&n!=="undefined"&&n!=="null")return r(s);let a=new Headers(s.headers);a.set("Authorization",`Bearer ${e}`);let d=new Request(s,{headers:a});return r(d)}}class Ne{raw;me;orgs;products;events;rooms;bookings;bookingTypes;projects;blogs;orders;quotes;constructor(e={}){let t=e.baseUrl??Gr;Vr(t);let r=zr(e.token,e.fetch),o={baseUrl:t,fetch:r,headers:e.headers};this.raw=Pe(o),this.me=new ae(this.raw),this.orgs=new de(this.raw),this.products=new ce(this.raw),this.events=new ue(this.raw),this.rooms=new ge(this.raw),this.bookings=new le(this.raw),this.bookingTypes=new fe(this.raw),this.projects=new me(this.raw),this.blogs=new pe(this.raw),this.orders=new ye(this.raw),this.quotes=new he(this.raw)}}function De(e={}){return new Ne(e)}import U from"node:fs";import Yr from"node:os";import be from"node:path";var Jr=/\x1b(?:\[[0-?]*[ -/]*[@-~]|\][^\x07\x1b]*(?:\x07|\x1b\\)|[P_^X][^\x07\x1b]*(?:\x07|\x1b\\)|[^[\]P_^X])/g,Hr=/[\x00-\x08\x0b-\x1f\x7f-\x9f]/g,Wr=/[\u061c\u200e\u200f\u202a-\u202e\u2066-\u2069]/g;function E(e){return e.replace(Jr,"").replace(Hr,"").replace(Wr,"")}function et(e){let t;try{t=new URL(e)}catch{throw Error(`Refusing to open malformed URL: ${E(e).slice(0,100)}`)}if(t.protocol==="https:")return t;if(t.protocol==="http:"&&(t.hostname==="localhost"||t.hostname==="127.0.0.1"||t.hostname==="[::1]"))return t;throw Error(`Refusing to open URL with unsafe protocol: ${t.protocol}`)}var Ze=512;function v(e,t){let r=e.trim();if(!r)throw Error(`${t} must not be empty.`);if(r.length>Ze)throw Error(`${t} must be at most ${Ze} characters.`);if(/[\x00-\x1f\x7f]/.test(r))throw Error(`${t} must not contain control characters.`);return r}function Y(e){let t;try{t=new URL(e)}catch{throw Error(`Invalid api base URL: ${e.slice(0,200)}`)}if(t.protocol==="https:")return t;if(t.protocol==="http:"&&(t.hostname==="localhost"||t.hostname==="127.0.0.1"||t.hostname==="[::1]"))return t;throw Error(`api base URL must use https:// (got: ${t.protocol}//${t.hostname}).`)}function D(){if(process.env.VCITY_CONFIG_DIR)return be.resolve(process.env.VCITY_CONFIG_DIR);return be.join(Yr.homedir(),".vcity")}function we(){return be.join(D(),"auth.json")}function Ue(){return be.join(D(),"config.json")}function je(){let e=process.env.VCITY_API_BASE_URL||"https://vcity.io";return Y(e),e}import N from"node:fs";function Q(e,t,r=384){if(process.platform==="win32"){N.writeFileSync(e,t,{mode:r});try{N.chmodSync(e,r)}catch{}return}let o=N.constants.O_WRONLY|N.constants.O_CREAT|N.constants.O_TRUNC|N.constants.O_NOFOLLOW,s=N.openSync(e,o,r);try{N.writeSync(s,t),N.fchmodSync(s,r)}finally{N.closeSync(s)}}function Qr(){let e=D();U.mkdirSync(e,{recursive:!0,mode:448});try{U.chmodSync(e,448)}catch{}if(process.platform!=="win32"){let t;try{t=U.statSync(e)}catch{return}if((t.mode&63)!==0)throw Error(`Refusing to write CLI credentials: ${e} is group- or world-accessible (mode ${(t.mode&511).toString(8)}). Tighten its permissions (\`chmod 700 ${e}\`) or set VCITY_CONFIG_DIR to a directory you own.`)}}function Xr(e){if(!e||typeof e!=="object")return!1;let t=e;return typeof t.api_base_url==="string"&&typeof t.access_token==="string"&&typeof t.refresh_token==="string"&&typeof t.access_expires_at==="number"&&typeof t.refresh_expires_at==="number"&&!!t.user&&typeof t.user==="object"}function ve(){let e=we();if(!U.existsSync(e))return;try{let t=JSON.parse(U.readFileSync(e,"utf-8"));if(!Xr(t))return;if(Y(t.api_base_url),new URL(t.api_base_url).origin!==new URL(je()).origin)return;return t}catch{return}}function Kr(e){let t;try{t=U.lstatSync(e)}catch{return}if(t.isSymbolicLink()||t.isFile()&&t.nlink>1)U.rmSync(e,{force:!0})}function ke(e){Qr();let t=we();Kr(t),Q(t,JSON.stringify(e,null,2),384)}function X(){let e=we();if(U.existsSync(e))U.rmSync(e)}function Ee(){let e=ve();if(!e)throw Error("Not logged in. Run `vcity login` first.");return e}var qe={name:"@vcityio/cli",version:"0.7.9",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:"^10.0.0"},keywords:["vcity","cli"],author:"Otherwise SAS",license:"MIT",homepage:"https://vcity.io",bugs:{email:"support@owsas.com"}};var _=qe.version,M=qe.name;var $e=60000,st=`vcity-cli/${_} (${process.platform} ${process.arch})`,tt=2048;class Z extends Error{status;body;constructor(e,t,r){super(r??`HTTP ${e}`);this.status=e;this.body=t;this.name="ApiError"}}function it(e,t,r){if(t.startsWith("//")||/^[a-z][a-z0-9+.-]*:/i.test(t))throw Error(`Refusing to build URL with non-relative path: ${t.slice(0,100)}`);let o=new URL(e),s=new URL(t.startsWith("/")?t:`/${t}`,e);if(s.origin!==o.origin)throw Error(`Refusing to build URL outside base origin: ${s.origin}`);if(r){for(let[i,n]of Object.entries(r))if(n!==void 0&&n!==null&&!Number.isNaN(n))s.searchParams.set(i,String(n))}return s.toString()}var rt=(e,t)=>typeof e==="string"&&e.length>0&&e.length<=t,nt=(e)=>typeof e==="number"&&Number.isFinite(e);async function ot(e){try{let t=await fetch(it(e.api_base_url,"/api/cli/auth/refresh"),{method:"POST",headers:{"content-type":"application/json",authorization:`Bearer ${e.refresh_token}`},body:JSON.stringify({refresh_token:e.refresh_token}),signal:AbortSignal.timeout($e),redirect:"error"});if(!t.ok)return;let r=await t.json();if(!rt(r.access_token,tt)||!rt(r.refresh_token,tt)||!nt(r.access_expires_at)||!nt(r.refresh_expires_at)||r.access_expires_at<=Date.now()||r.refresh_expires_at<=Date.now())return;let o={...e,access_token:r.access_token,refresh_token:r.refresh_token,access_expires_at:r.access_expires_at,refresh_expires_at:r.refresh_expires_at};return ke(o),o}catch{return}}async function ee(e,t={}){let{authed:r=!0,method:o="GET",body:s,query:i,baseUrl:n,headers:a}=t,d=r?Ee():void 0,c=n??d?.api_base_url??"https://vcity.io",w={"content-type":"application/json","user-agent":st};if(d)w.authorization=`Bearer ${d.access_token}`;if(a)for(let[J,Ve]of Object.entries(a))w[J]=Ve;let f=await fetch(it(c,e,i),{method:o,headers:w,body:s===void 0?void 0:JSON.stringify(s),signal:AbortSignal.timeout($e),redirect:"error"}),S=(f.headers.get("content-type")??"").includes("application/json")?await f.json().catch(()=>{return}):await f.text().catch(()=>{return});if(!f.ok){let J=(S&&typeof S==="object"&&"error"in S?String(S.error):void 0)??`Request failed (${f.status})`;throw new Z(f.status,S,J)}return S}function en(e,t){let r=new URL(e).origin;if(r!==t)throw Error(`Refusing to attach Bearer token to cross-origin SDK request: ${r}`)}function tn(){let e=async(t,r,o)=>{en(t.url,o);let s=new Headers(t.headers);s.set("authorization",`Bearer ${r}`),s.set("user-agent",st);let i=new Request(t,{headers:s,signal:AbortSignal.timeout($e),redirect:"error"});return globalThis.fetch(i)};return async function(r){let o=Ee(),s=new URL(o.api_base_url).origin;if(Date.now()>=o.access_expires_at){if(Date.now()>=o.refresh_expires_at)throw X(),new Z(401,void 0,"Session expired. Run `vcity login` again.");let a=await ot(o);if(!a)throw X(),new Z(401,void 0,"Session expired. Run `vcity login` again.");o=a}let i=await e(r,o.access_token,s);if(i.status!==401)return i;let n=await ot(o);if(!n)throw X(),new Z(401,void 0,"Session expired. Run `vcity login` again.");return o=n,e(r,o.access_token,s)}}function m(){let e=Ee();return De({baseUrl:e.api_base_url,fetch:tn()})}import G from"node:fs";import rn from"node:path";var Le=16777216;function nn(e){let t=new Uint8Array(e+1),r=0;while(r<t.length){let o=G.readSync(0,t,r,t.length-r,null);if(o===0)break;r+=o}if(r>e)throw Error(`--data: stdin body exceeds the ${e}-byte cap.`);return Buffer.from(t.buffer,t.byteOffset,r).toString("utf-8")}function k(e){if(e===void 0)return;let t;if(e==="-"){if(process.stdin.isTTY)throw Error("--data: reading from stdin (-) but nothing is piped in");try{t=nn(Le)}catch(r){let o=r instanceof Error?r.message:String(r);if(o.startsWith("--data:"))throw r;throw Error(`--data: could not read stdin: ${o}`)}}else if(e.startsWith("@")){let r=e.slice(1);if(r.length===0)throw Error("--data: missing file path after `@`");if(!/\.json$/i.test(r))throw Error(`--data: @file path must point to a .json file (got: ${r})`);let o;try{o=G.realpathSync(r)}catch(n){let a=n instanceof Error?n.message:String(n);throw Error(`--data: could not read ${r}: ${a}`)}if(!/\.json$/i.test(o))throw Error(`--data: @file path must point to a .json file (got: ${r} → ${o})`);let s;try{s=G.realpathSync(process.cwd())}catch(n){let a=n instanceof Error?n.message:String(n);throw Error(`--data: could not resolve cwd: ${a}`)}if(o!==s&&!o.startsWith(s+rn.sep))throw Error(`--data: @file path must be inside the current working directory (got: ${r}). To send a file from elsewhere, pipe it: cat <file> | vcity ... --data -`);let i;try{i=G.openSync(o,"r")}catch(n){let a=n instanceof Error?n.message:String(n);throw Error(`--data: could not read ${r}: ${a}`)}try{let n;try{n=G.fstatSync(i)}catch(a){let d=a instanceof Error?a.message:String(a);throw Error(`--data: could not read ${r}: ${d}`)}if(n.nlink>1)throw Error(`--data: @file path must not be a hard link (got: ${r})`);if(n.size>Le)throw Error(`--data: ${r} exceeds the ${Le}-byte body cap (got ${n.size} bytes).`);try{t=G.readFileSync(i,"utf-8")}catch(a){let d=a instanceof Error?a.message:String(a);throw Error(`--data: could not read ${r}: ${d}`)}}finally{try{G.closeSync(i)}catch{}}}else t=e;try{return JSON.parse(t)}catch{throw Error("--data: invalid JSON")}}import V from"node:fs";function on(){let e=D();V.mkdirSync(e,{recursive:!0,mode:448});try{V.chmodSync(e,448)}catch{}if(process.platform!=="win32"){let t;try{t=V.statSync(e)}catch{return}if((t.mode&63)!==0)throw Error(`Refusing to write CLI config: ${e} is group- or world-accessible (mode ${(t.mode&511).toString(8)}). Tighten its permissions (\`chmod 700 ${e}\`) or set VCITY_CONFIG_DIR to a directory you own.`)}}function sn(e){if(!e||typeof e!=="object"||Array.isArray(e))return!1;let t=e;if(t.active_org!==void 0&&typeof t.active_org!=="string")return!1;if(t.default_format!==void 0&&t.default_format!=="pretty"&&t.default_format!=="json")return!1;return!0}function z(){let e=Ue();if(!V.existsSync(e))return{};try{let t=JSON.parse(V.readFileSync(e,"utf-8"));return sn(t)?t:{}}catch{return{}}}function an(e){let t;try{t=V.lstatSync(e)}catch{return}if(t.isSymbolicLink()||t.isFile()&&t.nlink>1)V.rmSync(e,{force:!0})}function at(e){on();let r={...z(),...e},o=Ue();return an(o),Q(o,JSON.stringify(r,null,2),384),r}function p(e){if(e)return e;let t=z();if(!t.active_org)throw Error("No active org. Run `vcity org use <slug>` or pass --org <slug>.");return t.active_org}function g(e){if(e)return"json";if(!process.stdout.isTTY)return"json";return"pretty"}function l(e){process.stdout.write(`${JSON.stringify(e,null,2)}
|
|
2
|
+
var qr=/\{[^{}]+\}/g,$r=()=>typeof process==="object"&&Number.parseInt(process?.versions?.node?.substring(0,2))>=18&&process.versions.undici;function Lr(){return Math.random().toString(36).slice(2,11)}function Pe(e){let{baseUrl:t="",Request:r=globalThis.Request,fetch:o=globalThis.fetch,querySerializer:s,bodySerializer:i,headers:n,requestInitExt:a=void 0,...d}={...e};a=$r()?a:void 0,t=Qe(t);let c=[];async function w(f,j){let{baseUrl:S,fetch:J=o,Request:Ve=r,headers:ze,params:H={},parseAs:Se="json",querySerializer:re,bodySerializer:Je=i??Fr,body:He,...Ie}=j||{},Oe=t;if(S)Oe=Qe(S)??t;let xe=typeof s==="function"?s:We(s);if(re)xe=typeof re==="function"?re:We({...typeof s==="object"?s:{},...re});let Ae=He===void 0?void 0:Je(He,Ye(n,ze,H.header)),Dr=Ye(Ae===void 0||Ae instanceof FormData?{}:{"Content-Type":"application/json"},n,ze,H.header),Ur={redirect:"follow",...d,...Ie,body:Ae,headers:Dr},ne,oe,q=new r(Mr(f,{baseUrl:Oe,params:H,querySerializer:xe}),Ur),R;for(let A in Ie)if(!(A in q))q[A]=Ie[A];if(c.length){ne=Lr(),oe=Object.freeze({baseUrl:Oe,fetch:J,parseAs:Se,querySerializer:xe,bodySerializer:Je});for(let A of c)if(A&&typeof A==="object"&&typeof A.onRequest==="function"){let O=await A.onRequest({request:q,schemaPath:f,params:H,options:oe,id:ne});if(O)if(O instanceof r)q=O;else if(O instanceof Response){R=O;break}else throw Error("onRequest: must return new Request() or Response() when modifying the request")}}if(!R){try{R=await J(q,a)}catch(A){let O=A;if(c.length)for(let F=c.length-1;F>=0;F--){let se=c[F];if(se&&typeof se==="object"&&typeof se.onError==="function"){let K=await se.onError({request:q,error:O,schemaPath:f,params:H,options:oe,id:ne});if(K){if(K instanceof Response){O=void 0,R=K;break}if(K instanceof Error){O=K;continue}throw Error("onError: must return new Response() or instance of Error")}}}if(O)throw O}if(c.length)for(let A=c.length-1;A>=0;A--){let O=c[A];if(O&&typeof O==="object"&&typeof O.onResponse==="function"){let F=await O.onResponse({request:q,response:R,schemaPath:f,params:H,options:oe,id:ne});if(F){if(!(F instanceof Response))throw Error("onResponse: must return new Response() when modifying the response");R=F}}}}if(R.status===204||q.method==="HEAD"||R.headers.get("Content-Length")==="0")return R.ok?{data:void 0,response:R}:{error:void 0,response:R};if(R.ok){if(Se==="stream")return{data:R.body,response:R};return{data:await R[Se](),response:R}}let _e=await R.text();try{_e=JSON.parse(_e)}catch{}return{error:_e,response:R}}return{request(f,j,S){return w(j,{...S,method:f.toUpperCase()})},GET(f,j){return w(f,{...j,method:"GET"})},PUT(f,j){return w(f,{...j,method:"PUT"})},POST(f,j){return w(f,{...j,method:"POST"})},DELETE(f,j){return w(f,{...j,method:"DELETE"})},OPTIONS(f,j){return w(f,{...j,method:"OPTIONS"})},HEAD(f,j){return w(f,{...j,method:"HEAD"})},PATCH(f,j){return w(f,{...j,method:"PATCH"})},TRACE(f,j){return w(f,{...j,method:"TRACE"})},use(...f){for(let j of f){if(!j)continue;if(typeof j!=="object"||!(("onRequest"in j)||("onResponse"in j)||("onError"in j)))throw Error("Middleware must be an object with one of `onRequest()`, `onResponse() or `onError()`");c.push(j)}},eject(...f){for(let j of f){let S=c.indexOf(j);if(S!==-1)c.splice(S,1)}}}}function ie(e,t,r){if(t===void 0||t===null)return"";if(typeof t==="object")throw Error("Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.");return`${e}=${r?.allowReserved===!0?t:encodeURIComponent(t)}`}function Xe(e,t,r){if(!t||typeof t!=="object")return"";let o=[],s={simple:",",label:".",matrix:";"}[r.style]||"&";if(r.style!=="deepObject"&&r.explode===!1){for(let a in t)o.push(a,r.allowReserved===!0?t[a]:encodeURIComponent(t[a]));let n=o.join(",");switch(r.style){case"form":return`${e}=${n}`;case"label":return`.${n}`;case"matrix":return`;${e}=${n}`;default:return n}}for(let n in t){let a=r.style==="deepObject"?`${e}[${n}]`:n;o.push(ie(a,t[n],r))}let i=o.join(s);return r.style==="label"||r.style==="matrix"?`${s}${i}`:i}function Ke(e,t,r){if(!Array.isArray(t))return"";if(r.explode===!1){let i={form:",",spaceDelimited:"%20",pipeDelimited:"|"}[r.style]||",",n=(r.allowReserved===!0?t:t.map((a)=>encodeURIComponent(a))).join(i);switch(r.style){case"simple":return n;case"label":return`.${n}`;case"matrix":return`;${e}=${n}`;default:return`${e}=${n}`}}let o={simple:",",label:".",matrix:";"}[r.style]||"&",s=[];for(let i of t)if(r.style==="simple"||r.style==="label")s.push(r.allowReserved===!0?i:encodeURIComponent(i));else s.push(ie(e,i,r));return r.style==="label"||r.style==="matrix"?`${o}${s.join(o)}`:s.join(o)}function We(e){return function(r){let o=[];if(r&&typeof r==="object")for(let s in r){let i=r[s];if(i===void 0||i===null)continue;if(Array.isArray(i)){if(i.length===0)continue;o.push(Ke(s,i,{style:"form",explode:!0,...e?.array,allowReserved:e?.allowReserved||!1}));continue}if(typeof i==="object"){o.push(Xe(s,i,{style:"deepObject",explode:!0,...e?.object,allowReserved:e?.allowReserved||!1}));continue}o.push(ie(s,i,e))}return o.join("&")}}function Br(e,t){let r=e;for(let o of e.match(qr)??[]){let s=o.substring(1,o.length-1),i=!1,n="simple";if(s.endsWith("*"))i=!0,s=s.substring(0,s.length-1);if(s.startsWith("."))n="label",s=s.substring(1);else if(s.startsWith(";"))n="matrix",s=s.substring(1);if(!t||t[s]===void 0||t[s]===null)continue;let a=t[s];if(Array.isArray(a)){r=r.replace(o,Ke(s,a,{style:n,explode:i}));continue}if(typeof a==="object"){r=r.replace(o,Xe(s,a,{style:n,explode:i}));continue}if(n==="matrix"){r=r.replace(o,`;${ie(s,a)}`);continue}r=r.replace(o,n==="label"?`.${encodeURIComponent(a)}`:encodeURIComponent(a))}return r}function Fr(e,t){if(e instanceof FormData)return e;if(t){if((t.get instanceof Function?t.get("Content-Type")??t.get("content-type"):t["Content-Type"]??t["content-type"])==="application/x-www-form-urlencoded")return new URLSearchParams(e).toString()}return JSON.stringify(e)}function Mr(e,t){let r=`${t.baseUrl}${e}`;if(t.params?.path)r=Br(r,t.params.path);let o=t.querySerializer(t.params.query??{});if(o.startsWith("?"))o=o.substring(1);if(o)r+=`?${o}`;return r}function Ye(...e){let t=new Headers;for(let r of e){if(!r||typeof r!=="object")continue;let o=r instanceof Headers?r.entries():Object.entries(r);for(let[s,i]of o)if(i===null)t.delete(s);else if(Array.isArray(i))for(let n of i)t.append(s,n);else if(i!==void 0)t.set(s,i)}return t}function Qe(e){if(e.endsWith("/"))return e.substring(0,e.length-1);return e}class W extends Error{status;body;url;constructor(e,t,r,o){super(e);this.name="ApiClientError",this.status=t,this.body=r,this.url=o.split("?")[0]}}function y(e,t){if(e.error!==void 0&&e.error!==null){let r=e.response?.status??0,o=e.response?.url??"",s=typeof e.error==="object"&&e.error!==null&&"error"in e.error&&typeof e.error.error==="object"&&e.error.error?.message||`${t} failed (${r})`;throw new W(String(s),r,e.error,o)}if(e.data===void 0)throw new W(`${t}: empty response body`,e.response?.status??0,void 0,e.response?.url??"");return e.data}class ae{client;constructor(e){this.client=e}async get(){let e=await this.client.GET("/api/v1/me",{});return y(e,"me.get")}}class de{client;constructor(e){this.client=e}async get(e){let t=await this.client.GET("/api/v1/orgs/{orgId}",{params:{path:{orgId:e}}});return y(t,"orgs.get")}async listMembers(e,t={}){let r=await this.client.GET("/api/v1/orgs/{orgId}/members",{params:{path:{orgId:e},query:t}});return y(r,"orgs.listMembers")}}class ce{client;constructor(e){this.client=e}async list(e,t={}){let r=await this.client.GET("/api/v1/orgs/{orgId}/products",{params:{path:{orgId:e},query:t}});return y(r,"products.list")}async get(e,t){let r=await this.client.GET("/api/v1/orgs/{orgId}/products/{productId}",{params:{path:{orgId:e,productId:t}}});return y(r,"products.get")}async create(e,t){let r=await this.client.POST("/api/v1/orgs/{orgId}/products",{params:{path:{orgId:e}},body:t});return y(r,"products.create")}async update(e,t,r){let o=await this.client.PUT("/api/v1/orgs/{orgId}/products/{productId}",{params:{path:{orgId:e,productId:t}},body:r});return y(o,"products.update")}async delete(e,t){let r=await this.client.DELETE("/api/v1/orgs/{orgId}/products/{productId}",{params:{path:{orgId:e,productId:t}}});return y(r,"products.delete")}}class ue{client;constructor(e){this.client=e}async list(e,t={}){let r=await this.client.GET("/api/v1/orgs/{orgId}/events",{params:{path:{orgId:e},query:t}});return y(r,"events.list")}async get(e,t){let r=await this.client.GET("/api/v1/orgs/{orgId}/events/{eventId}",{params:{path:{orgId:e,eventId:t}}});return y(r,"events.get")}async create(e,t){let r=await this.client.POST("/api/v1/orgs/{orgId}/events",{params:{path:{orgId:e}},body:t});return y(r,"events.create")}async update(e,t,r){let o=await this.client.PUT("/api/v1/orgs/{orgId}/events/{eventId}",{params:{path:{orgId:e,eventId:t}},body:r});return y(o,"events.update")}async delete(e,t){let r=await this.client.DELETE("/api/v1/orgs/{orgId}/events/{eventId}",{params:{path:{orgId:e,eventId:t}}});return y(r,"events.delete")}}class ge{client;constructor(e){this.client=e}async list(e,t={}){let r=await this.client.GET("/api/v1/orgs/{orgId}/rooms",{params:{path:{orgId:e},query:t}});return y(r,"rooms.list")}async get(e,t){let r=await this.client.GET("/api/v1/orgs/{orgId}/rooms/{roomId}",{params:{path:{orgId:e,roomId:t}}});return y(r,"rooms.get")}async create(e,t){let r=await this.client.POST("/api/v1/orgs/{orgId}/rooms",{params:{path:{orgId:e}},body:t});return y(r,"rooms.create")}async update(e,t,r){let o=await this.client.PUT("/api/v1/orgs/{orgId}/rooms/{roomId}",{params:{path:{orgId:e,roomId:t}},body:r});return y(o,"rooms.update")}async delete(e,t){let r=await this.client.DELETE("/api/v1/orgs/{orgId}/rooms/{roomId}",{params:{path:{orgId:e,roomId:t}}});return y(r,"rooms.delete")}}class le{client;constructor(e){this.client=e}async list(e,t={}){let r=await this.client.GET("/api/v1/orgs/{orgId}/bookings",{params:{path:{orgId:e},query:t}});return y(r,"bookings.list")}async get(e,t){let r=await this.client.GET("/api/v1/orgs/{orgId}/bookings/{bookingId}",{params:{path:{orgId:e,bookingId:t}}});return y(r,"bookings.get")}async create(e,t){let r=await this.client.POST("/api/v1/orgs/{orgId}/bookings",{params:{path:{orgId:e}},body:t});return y(r,"bookings.create")}async update(e,t,r){let o=await this.client.PUT("/api/v1/orgs/{orgId}/bookings/{bookingId}",{params:{path:{orgId:e,bookingId:t}},body:r});return y(o,"bookings.update")}async delete(e,t){let r=await this.client.DELETE("/api/v1/orgs/{orgId}/bookings/{bookingId}",{params:{path:{orgId:e,bookingId:t}}});return y(r,"bookings.delete")}}class me{client;constructor(e){this.client=e}async list(e,t={}){let r=await this.client.GET("/api/v1/orgs/{orgId}/projects",{params:{path:{orgId:e},query:t}});return y(r,"projects.list")}async get(e,t){let r=await this.client.GET("/api/v1/orgs/{orgId}/projects/{projectId}",{params:{path:{orgId:e,projectId:t}}});return y(r,"projects.get")}async create(e,t){let r=await this.client.POST("/api/v1/orgs/{orgId}/projects",{params:{path:{orgId:e}},body:t});return y(r,"projects.create")}async update(e,t,r){let o=await this.client.PUT("/api/v1/orgs/{orgId}/projects/{projectId}",{params:{path:{orgId:e,projectId:t}},body:r});return y(o,"projects.update")}async delete(e,t){let r=await this.client.DELETE("/api/v1/orgs/{orgId}/projects/{projectId}",{params:{path:{orgId:e,projectId:t}}});return y(r,"projects.delete")}async listCards(e,t,r={}){let o=await this.client.GET("/api/v1/orgs/{orgId}/projects/{projectId}/cards",{params:{path:{orgId:e,projectId:t},query:r}});return y(o,"projects.listCards")}async getCard(e,t,r){let o=await this.client.GET("/api/v1/orgs/{orgId}/projects/{projectId}/cards/{cardId}",{params:{path:{orgId:e,projectId:t,cardId:r}}});return y(o,"projects.getCard")}async createCard(e,t,r){let o=await this.client.POST("/api/v1/orgs/{orgId}/projects/{projectId}/cards",{params:{path:{orgId:e,projectId:t}},body:r});return y(o,"projects.createCard")}async updateCard(e,t,r,o){let s=await this.client.PUT("/api/v1/orgs/{orgId}/projects/{projectId}/cards/{cardId}",{params:{path:{orgId:e,projectId:t,cardId:r}},body:o});return y(s,"projects.updateCard")}async moveCard(e,t,r,o){let s=await this.client.POST("/api/v1/orgs/{orgId}/projects/{projectId}/cards/{cardId}/move",{params:{path:{orgId:e,projectId:t,cardId:r}},body:o});return y(s,"projects.moveCard")}async deleteCard(e,t,r){let o=await this.client.DELETE("/api/v1/orgs/{orgId}/projects/{projectId}/cards/{cardId}",{params:{path:{orgId:e,projectId:t,cardId:r}}});return y(o,"projects.deleteCard")}async listCardComments(e,t,r,o={}){let s=await this.client.GET("/api/v1/orgs/{orgId}/projects/{projectId}/cards/{cardId}/comments",{params:{path:{orgId:e,projectId:t,cardId:r},query:o}});return y(s,"projects.listCardComments")}async createCardComment(e,t,r,o){let s=await this.client.POST("/api/v1/orgs/{orgId}/projects/{projectId}/cards/{cardId}/comments",{params:{path:{orgId:e,projectId:t,cardId:r}},body:o});return y(s,"projects.createCardComment")}}class pe{client;constructor(e){this.client=e}async list(e,t={}){let r=await this.client.GET("/api/v1/orgs/{orgId}/blogs",{params:{path:{orgId:e},query:t}});return y(r,"blogs.list")}async get(e,t){let r=await this.client.GET("/api/v1/orgs/{orgId}/blogs/{blogId}",{params:{path:{orgId:e,blogId:t}}});return y(r,"blogs.get")}async create(e,t){let r=await this.client.POST("/api/v1/orgs/{orgId}/blogs",{params:{path:{orgId:e}},body:t});return y(r,"blogs.create")}async update(e,t,r){let o=await this.client.PUT("/api/v1/orgs/{orgId}/blogs/{blogId}",{params:{path:{orgId:e,blogId:t}},body:r});return y(o,"blogs.update")}async delete(e,t){let r=await this.client.DELETE("/api/v1/orgs/{orgId}/blogs/{blogId}",{params:{path:{orgId:e,blogId:t}}});return y(r,"blogs.delete")}}class fe{client;constructor(e){this.client=e}async list(e,t={}){let r=await this.client.GET("/api/v1/orgs/{orgId}/booking-types",{params:{path:{orgId:e},query:t}});return y(r,"bookingTypes.list")}async get(e,t){let r=await this.client.GET("/api/v1/orgs/{orgId}/booking-types/{bookingTypeId}",{params:{path:{orgId:e,bookingTypeId:t}}});return y(r,"bookingTypes.get")}async create(e,t){let r=await this.client.POST("/api/v1/orgs/{orgId}/booking-types",{params:{path:{orgId:e}},body:t});return y(r,"bookingTypes.create")}async update(e,t,r){let o=await this.client.PUT("/api/v1/orgs/{orgId}/booking-types/{bookingTypeId}",{params:{path:{orgId:e,bookingTypeId:t}},body:r});return y(o,"bookingTypes.update")}async delete(e,t){let r=await this.client.DELETE("/api/v1/orgs/{orgId}/booking-types/{bookingTypeId}",{params:{path:{orgId:e,bookingTypeId:t}}});return y(r,"bookingTypes.delete")}}class ye{client;constructor(e){this.client=e}async list(e,t={}){let r=await this.client.GET("/api/v1/orgs/{orgId}/orders",{params:{path:{orgId:e},query:t}});return y(r,"orders.list")}async get(e,t){let r=await this.client.GET("/api/v1/orgs/{orgId}/orders/{orderId}",{params:{path:{orgId:e,orderId:t}}});return y(r,"orders.get")}}class he{client;constructor(e){this.client=e}async list(e,t={}){let r=await this.client.GET("/api/v1/orgs/{orgId}/quotes",{params:{path:{orgId:e},query:t}});return y(r,"quotes.list")}async get(e,t){let r=await this.client.GET("/api/v1/orgs/{orgId}/quotes/{quoteId}",{params:{path:{orgId:e,quoteId:t}}});return y(r,"quotes.get")}async create(e,t){let r=await this.client.POST("/api/v1/orgs/{orgId}/quotes",{params:{path:{orgId:e}},body:t});return y(r,"quotes.create")}async update(e,t,r){let o=await this.client.PUT("/api/v1/orgs/{orgId}/quotes/{quoteId}",{params:{path:{orgId:e,quoteId:t}},body:r});return y(o,"quotes.update")}async delete(e,t){let r=await this.client.DELETE("/api/v1/orgs/{orgId}/quotes/{quoteId}",{params:{path:{orgId:e,quoteId:t}}});return y(r,"quotes.delete")}}var Gr="https://vcity.io";function Vr(e){let t;try{t=new URL(e)}catch{throw Error(`@vcityio/api-client: invalid baseUrl (${e.slice(0,200)})`)}if(t.protocol==="https:")return;if(t.protocol==="http:"&&(t.hostname==="localhost"||t.hostname==="127.0.0.1"||t.hostname==="[::1]"))return;throw Error(`@vcityio/api-client: baseUrl must use https:// for non-localhost hosts (got: ${t.protocol}//${t.hostname}).`)}function zr(e,t){let r=t??globalThis.fetch;if(!r)throw Error("@vcityio/api-client: no fetch implementation found. Provide options.fetch or run on Node >=20 / a browser.");return async function(s){if(!e)return r(s);let n=s.headers.get("Authorization")?.match(/^Bearer\s+(.+)$/)?.[1]?.trim();if(n&&n!=="undefined"&&n!=="null")return r(s);let a=new Headers(s.headers);a.set("Authorization",`Bearer ${e}`);let d=new Request(s,{headers:a});return r(d)}}class Ne{raw;me;orgs;products;events;rooms;bookings;bookingTypes;projects;blogs;orders;quotes;constructor(e={}){let t=e.baseUrl??Gr;Vr(t);let r=zr(e.token,e.fetch),o={baseUrl:t,fetch:r,headers:e.headers};this.raw=Pe(o),this.me=new ae(this.raw),this.orgs=new de(this.raw),this.products=new ce(this.raw),this.events=new ue(this.raw),this.rooms=new ge(this.raw),this.bookings=new le(this.raw),this.bookingTypes=new fe(this.raw),this.projects=new me(this.raw),this.blogs=new pe(this.raw),this.orders=new ye(this.raw),this.quotes=new he(this.raw)}}function De(e={}){return new Ne(e)}import U from"node:fs";import Yr from"node:os";import be from"node:path";var Jr=/\x1b(?:\[[0-?]*[ -/]*[@-~]|\][^\x07\x1b]*(?:\x07|\x1b\\)|[P_^X][^\x07\x1b]*(?:\x07|\x1b\\)|[^[\]P_^X])/g,Hr=/[\x00-\x08\x0b-\x1f\x7f-\x9f]/g,Wr=/[\u061c\u200e\u200f\u202a-\u202e\u2066-\u2069]/g;function E(e){return e.replace(Jr,"").replace(Hr,"").replace(Wr,"")}function et(e){let t;try{t=new URL(e)}catch{throw Error(`Refusing to open malformed URL: ${E(e).slice(0,100)}`)}if(t.protocol==="https:")return t;if(t.protocol==="http:"&&(t.hostname==="localhost"||t.hostname==="127.0.0.1"||t.hostname==="[::1]"))return t;throw Error(`Refusing to open URL with unsafe protocol: ${t.protocol}`)}var Ze=512;function v(e,t){let r=e.trim();if(!r)throw Error(`${t} must not be empty.`);if(r.length>Ze)throw Error(`${t} must be at most ${Ze} characters.`);if(/[\x00-\x1f\x7f]/.test(r))throw Error(`${t} must not contain control characters.`);return r}function Y(e){let t;try{t=new URL(e)}catch{throw Error(`Invalid api base URL: ${e.slice(0,200)}`)}if(t.protocol==="https:")return t;if(t.protocol==="http:"&&(t.hostname==="localhost"||t.hostname==="127.0.0.1"||t.hostname==="[::1]"))return t;throw Error(`api base URL must use https:// (got: ${t.protocol}//${t.hostname}).`)}function D(){if(process.env.VCITY_CONFIG_DIR)return be.resolve(process.env.VCITY_CONFIG_DIR);return be.join(Yr.homedir(),".vcity")}function we(){return be.join(D(),"auth.json")}function Ue(){return be.join(D(),"config.json")}function je(){let e=process.env.VCITY_API_BASE_URL||"https://vcity.io";return Y(e),e}import N from"node:fs";function Q(e,t,r=384){if(process.platform==="win32"){N.writeFileSync(e,t,{mode:r});try{N.chmodSync(e,r)}catch{}return}let o=N.constants.O_WRONLY|N.constants.O_CREAT|N.constants.O_TRUNC|N.constants.O_NOFOLLOW,s=N.openSync(e,o,r);try{N.writeSync(s,t),N.fchmodSync(s,r)}finally{N.closeSync(s)}}function Qr(){let e=D();U.mkdirSync(e,{recursive:!0,mode:448});try{U.chmodSync(e,448)}catch{}if(process.platform!=="win32"){let t;try{t=U.statSync(e)}catch{return}if((t.mode&63)!==0)throw Error(`Refusing to write CLI credentials: ${e} is group- or world-accessible (mode ${(t.mode&511).toString(8)}). Tighten its permissions (\`chmod 700 ${e}\`) or set VCITY_CONFIG_DIR to a directory you own.`)}}function Xr(e){if(!e||typeof e!=="object")return!1;let t=e;return typeof t.api_base_url==="string"&&typeof t.access_token==="string"&&typeof t.refresh_token==="string"&&typeof t.access_expires_at==="number"&&typeof t.refresh_expires_at==="number"&&!!t.user&&typeof t.user==="object"}function ve(){let e=we();if(!U.existsSync(e))return;try{let t=JSON.parse(U.readFileSync(e,"utf-8"));if(!Xr(t))return;if(Y(t.api_base_url),new URL(t.api_base_url).origin!==new URL(je()).origin)return;return t}catch{return}}function Kr(e){let t;try{t=U.lstatSync(e)}catch{return}if(t.isSymbolicLink()||t.isFile()&&t.nlink>1)U.rmSync(e,{force:!0})}function ke(e){Qr();let t=we();Kr(t),Q(t,JSON.stringify(e,null,2),384)}function X(){let e=we();if(U.existsSync(e))U.rmSync(e)}function Ee(){let e=ve();if(!e)throw Error("Not logged in. Run `vcity login` first.");return e}var qe={name:"@vcityio/cli",version:"0.7.10",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:"^10.0.0"},keywords:["vcity","cli"],author:"Otherwise SAS",license:"MIT",homepage:"https://vcity.io",bugs:{email:"support@owsas.com"}};var _=qe.version,M=qe.name;var $e=60000,st=`vcity-cli/${_} (${process.platform} ${process.arch})`,tt=2048;class Z extends Error{status;body;constructor(e,t,r){super(r??`HTTP ${e}`);this.status=e;this.body=t;this.name="ApiError"}}function it(e,t,r){if(t.startsWith("//")||/^[a-z][a-z0-9+.-]*:/i.test(t))throw Error(`Refusing to build URL with non-relative path: ${t.slice(0,100)}`);let o=new URL(e),s=new URL(t.startsWith("/")?t:`/${t}`,e);if(s.origin!==o.origin)throw Error(`Refusing to build URL outside base origin: ${s.origin}`);if(r){for(let[i,n]of Object.entries(r))if(n!==void 0&&n!==null&&!Number.isNaN(n))s.searchParams.set(i,String(n))}return s.toString()}var rt=(e,t)=>typeof e==="string"&&e.length>0&&e.length<=t,nt=(e)=>typeof e==="number"&&Number.isFinite(e);async function ot(e){try{let t=await fetch(it(e.api_base_url,"/api/cli/auth/refresh"),{method:"POST",headers:{"content-type":"application/json",authorization:`Bearer ${e.refresh_token}`},body:JSON.stringify({refresh_token:e.refresh_token}),signal:AbortSignal.timeout($e),redirect:"error"});if(!t.ok)return;let r=await t.json();if(!rt(r.access_token,tt)||!rt(r.refresh_token,tt)||!nt(r.access_expires_at)||!nt(r.refresh_expires_at)||r.access_expires_at<=Date.now()||r.refresh_expires_at<=Date.now())return;let o={...e,access_token:r.access_token,refresh_token:r.refresh_token,access_expires_at:r.access_expires_at,refresh_expires_at:r.refresh_expires_at};return ke(o),o}catch{return}}async function ee(e,t={}){let{authed:r=!0,method:o="GET",body:s,query:i,baseUrl:n,headers:a}=t,d=r?Ee():void 0,c=n??d?.api_base_url??"https://vcity.io",w={"content-type":"application/json","user-agent":st};if(d)w.authorization=`Bearer ${d.access_token}`;if(a)for(let[J,Ve]of Object.entries(a))w[J]=Ve;let f=await fetch(it(c,e,i),{method:o,headers:w,body:s===void 0?void 0:JSON.stringify(s),signal:AbortSignal.timeout($e),redirect:"error"}),S=(f.headers.get("content-type")??"").includes("application/json")?await f.json().catch(()=>{return}):await f.text().catch(()=>{return});if(!f.ok){let J=(S&&typeof S==="object"&&"error"in S?String(S.error):void 0)??`Request failed (${f.status})`;throw new Z(f.status,S,J)}return S}function en(e,t){let r=new URL(e).origin;if(r!==t)throw Error(`Refusing to attach Bearer token to cross-origin SDK request: ${r}`)}function tn(){let e=async(t,r,o)=>{en(t.url,o);let s=new Headers(t.headers);s.set("authorization",`Bearer ${r}`),s.set("user-agent",st);let i=new Request(t,{headers:s,signal:AbortSignal.timeout($e),redirect:"error"});return globalThis.fetch(i)};return async function(r){let o=Ee(),s=new URL(o.api_base_url).origin;if(Date.now()>=o.access_expires_at){if(Date.now()>=o.refresh_expires_at)throw X(),new Z(401,void 0,"Session expired. Run `vcity login` again.");let a=await ot(o);if(!a)throw X(),new Z(401,void 0,"Session expired. Run `vcity login` again.");o=a}let i=await e(r,o.access_token,s);if(i.status!==401)return i;let n=await ot(o);if(!n)throw X(),new Z(401,void 0,"Session expired. Run `vcity login` again.");return o=n,e(r,o.access_token,s)}}function m(){let e=Ee();return De({baseUrl:e.api_base_url,fetch:tn()})}import G from"node:fs";import rn from"node:path";var Le=16777216;function nn(e){let t=new Uint8Array(e+1),r=0;while(r<t.length){let o=G.readSync(0,t,r,t.length-r,null);if(o===0)break;r+=o}if(r>e)throw Error(`--data: stdin body exceeds the ${e}-byte cap.`);return Buffer.from(t.buffer,t.byteOffset,r).toString("utf-8")}function k(e){if(e===void 0)return;let t;if(e==="-"){if(process.stdin.isTTY)throw Error("--data: reading from stdin (-) but nothing is piped in");try{t=nn(Le)}catch(r){let o=r instanceof Error?r.message:String(r);if(o.startsWith("--data:"))throw r;throw Error(`--data: could not read stdin: ${o}`)}}else if(e.startsWith("@")){let r=e.slice(1);if(r.length===0)throw Error("--data: missing file path after `@`");if(!/\.json$/i.test(r))throw Error(`--data: @file path must point to a .json file (got: ${r})`);let o;try{o=G.realpathSync(r)}catch(n){let a=n instanceof Error?n.message:String(n);throw Error(`--data: could not read ${r}: ${a}`)}if(!/\.json$/i.test(o))throw Error(`--data: @file path must point to a .json file (got: ${r} → ${o})`);let s;try{s=G.realpathSync(process.cwd())}catch(n){let a=n instanceof Error?n.message:String(n);throw Error(`--data: could not resolve cwd: ${a}`)}if(o!==s&&!o.startsWith(s+rn.sep))throw Error(`--data: @file path must be inside the current working directory (got: ${r}). To send a file from elsewhere, pipe it: cat <file> | vcity ... --data -`);let i;try{i=G.openSync(o,"r")}catch(n){let a=n instanceof Error?n.message:String(n);throw Error(`--data: could not read ${r}: ${a}`)}try{let n;try{n=G.fstatSync(i)}catch(a){let d=a instanceof Error?a.message:String(a);throw Error(`--data: could not read ${r}: ${d}`)}if(n.nlink>1)throw Error(`--data: @file path must not be a hard link (got: ${r})`);if(n.size>Le)throw Error(`--data: ${r} exceeds the ${Le}-byte body cap (got ${n.size} bytes).`);try{t=G.readFileSync(i,"utf-8")}catch(a){let d=a instanceof Error?a.message:String(a);throw Error(`--data: could not read ${r}: ${d}`)}}finally{try{G.closeSync(i)}catch{}}}else t=e;try{return JSON.parse(t)}catch{throw Error("--data: invalid JSON")}}import V from"node:fs";function on(){let e=D();V.mkdirSync(e,{recursive:!0,mode:448});try{V.chmodSync(e,448)}catch{}if(process.platform!=="win32"){let t;try{t=V.statSync(e)}catch{return}if((t.mode&63)!==0)throw Error(`Refusing to write CLI config: ${e} is group- or world-accessible (mode ${(t.mode&511).toString(8)}). Tighten its permissions (\`chmod 700 ${e}\`) or set VCITY_CONFIG_DIR to a directory you own.`)}}function sn(e){if(!e||typeof e!=="object"||Array.isArray(e))return!1;let t=e;if(t.active_org!==void 0&&typeof t.active_org!=="string")return!1;if(t.default_format!==void 0&&t.default_format!=="pretty"&&t.default_format!=="json")return!1;return!0}function z(){let e=Ue();if(!V.existsSync(e))return{};try{let t=JSON.parse(V.readFileSync(e,"utf-8"));return sn(t)?t:{}}catch{return{}}}function an(e){let t;try{t=V.lstatSync(e)}catch{return}if(t.isSymbolicLink()||t.isFile()&&t.nlink>1)V.rmSync(e,{force:!0})}function at(e){on();let r={...z(),...e},o=Ue();return an(o),Q(o,JSON.stringify(r,null,2),384),r}function p(e){if(e)return e;let t=z();if(!t.active_org)throw Error("No active org. Run `vcity org use <slug>` or pass --org <slug>.");return t.active_org}function g(e){if(e)return"json";if(!process.stdout.isTTY)return"json";return"pretty"}function l(e){process.stdout.write(`${JSON.stringify(e,null,2)}
|
|
3
3
|
`)}function dn(e,t){if(e.length===0)return"(no rows)";let r=e.map((a)=>t.map((d)=>E(d.get(a)??""))),o=t.map((a,d)=>Math.max(a.header.length,...r.map((c)=>c[d].length))),s=o.map((a)=>"-".repeat(a)).join(" "),i=t.map((a,d)=>a.header.padEnd(o[d])).join(" "),n=r.map((a)=>a.map((d,c)=>d.padEnd(o[c])).join(" "));return[i,s,...n].join(`
|
|
4
4
|
`)}function C(e,t){process.stdout.write(`${dn(e,t)}
|
|
5
5
|
`)}function b(e){for(let[t,r]of Object.entries(e)){if(r===void 0||r===null)continue;let o=typeof r==="object"?JSON.stringify(r):String(r);process.stdout.write(`${t.padEnd(20)} ${E(o)}
|