@vcityio/cli 0.9.0 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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 Rn=/\{[^{}]+\}/g,Tn=()=>typeof process==="object"&&Number.parseInt(process?.versions?.node?.substring(0,2))>=18&&process.versions.undici;function Sn(){return Math.random().toString(36).slice(2,11)}function Fe(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=Tn()?a:void 0,t=at(t);let c=[];async function w(h,k){let{baseUrl:S,fetch:z=o,Request:tt=r,headers:rt,params:J={},parseAs:Ne="json",querySerializer:oe,bodySerializer:nt=i??On,body:ot,...$e}=k||{},Ue=t;if(S)Ue=at(S)??t;let qe=typeof s==="function"?s:st(s);if(oe)qe=typeof oe==="function"?oe:st({...typeof s==="object"?s:{},...oe});let Le=ot===void 0?void 0:nt(ot,it(n,rt,J.header)),Cn=it(Le===void 0||Le instanceof FormData?{}:{"Content-Type":"application/json"},n,rt,J.header),En={redirect:"follow",...d,...$e,body:Le,headers:Cn},se,ie,q=new r(An(h,{baseUrl:Ue,params:J,querySerializer:qe}),En),T;for(let x in $e)if(!(x in q))q[x]=$e[x];if(c.length){se=Sn(),ie=Object.freeze({baseUrl:Ue,fetch:z,parseAs:Ne,querySerializer:qe,bodySerializer:nt});for(let x of c)if(x&&typeof x==="object"&&typeof x.onRequest==="function"){let A=await x.onRequest({request:q,schemaPath:h,params:J,options:ie,id:se});if(A)if(A instanceof r)q=A;else if(A instanceof Response){T=A;break}else throw Error("onRequest: must return new Request() or Response() when modifying the request")}}if(!T){try{T=await z(q,a)}catch(x){let A=x;if(c.length)for(let F=c.length-1;F>=0;F--){let ae=c[F];if(ae&&typeof ae==="object"&&typeof ae.onError==="function"){let K=await ae.onError({request:q,error:A,schemaPath:h,params:J,options:ie,id:se});if(K){if(K instanceof Response){A=void 0,T=K;break}if(K instanceof Error){A=K;continue}throw Error("onError: must return new Response() or instance of Error")}}}if(A)throw A}if(c.length)for(let x=c.length-1;x>=0;x--){let A=c[x];if(A&&typeof A==="object"&&typeof A.onResponse==="function"){let F=await A.onResponse({request:q,response:T,schemaPath:h,params:J,options:ie,id:se});if(F){if(!(F instanceof Response))throw Error("onResponse: must return new Response() when modifying the response");T=F}}}}if(T.status===204||q.method==="HEAD"||T.headers.get("Content-Length")==="0")return T.ok?{data:void 0,response:T}:{error:void 0,response:T};if(T.ok){if(Ne==="stream")return{data:T.body,response:T};return{data:await T[Ne](),response:T}}let Be=await T.text();try{Be=JSON.parse(Be)}catch{}return{error:Be,response:T}}return{request(h,k,S){return w(k,{...S,method:h.toUpperCase()})},GET(h,k){return w(h,{...k,method:"GET"})},PUT(h,k){return w(h,{...k,method:"PUT"})},POST(h,k){return w(h,{...k,method:"POST"})},DELETE(h,k){return w(h,{...k,method:"DELETE"})},OPTIONS(h,k){return w(h,{...k,method:"OPTIONS"})},HEAD(h,k){return w(h,{...k,method:"HEAD"})},PATCH(h,k){return w(h,{...k,method:"PATCH"})},TRACE(h,k){return w(h,{...k,method:"TRACE"})},use(...h){for(let k of h){if(!k)continue;if(typeof k!=="object"||!(("onRequest"in k)||("onResponse"in k)||("onError"in k)))throw Error("Middleware must be an object with one of `onRequest()`, `onResponse() or `onError()`");c.push(k)}},eject(...h){for(let k of h){let S=c.indexOf(k);if(S!==-1)c.splice(S,1)}}}}function de(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 dt(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(de(a,t[n],r))}let i=o.join(s);return r.style==="label"||r.style==="matrix"?`${s}${i}`:i}function ct(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(de(e,i,r));return r.style==="label"||r.style==="matrix"?`${o}${s.join(o)}`:s.join(o)}function st(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(ct(s,i,{style:"form",explode:!0,...e?.array,allowReserved:e?.allowReserved||!1}));continue}if(typeof i==="object"){o.push(dt(s,i,{style:"deepObject",explode:!0,...e?.object,allowReserved:e?.allowReserved||!1}));continue}o.push(de(s,i,e))}return o.join("&")}}function In(e,t){let r=e;for(let o of e.match(Rn)??[]){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,ct(s,a,{style:n,explode:i}));continue}if(typeof a==="object"){r=r.replace(o,dt(s,a,{style:n,explode:i}));continue}if(n==="matrix"){r=r.replace(o,`;${de(s,a)}`);continue}r=r.replace(o,n==="label"?`.${encodeURIComponent(a)}`:encodeURIComponent(a))}return r}function On(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 An(e,t){let r=`${t.baseUrl}${e}`;if(t.params?.path)r=In(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 it(...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 at(e){if(e.endsWith("/"))return e.substring(0,e.length-1);return e}class H 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 f(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 H(String(s),r,e.error,o)}if(e.data===void 0)throw new H(`${t}: empty response body`,e.response?.status??0,void 0,e.response?.url??"");return e.data}class ce{client;constructor(e){this.client=e}async get(){let e=await this.client.GET("/api/v1/me",{});return f(e,"me.get")}}class ue{client;constructor(e){this.client=e}async get(e){let t=await this.client.GET("/api/v1/orgs/{orgId}",{params:{path:{orgId:e}}});return f(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 f(r,"orgs.listMembers")}}class ge{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 f(r,"products.list")}async get(e,t,r={}){let o=await this.client.GET("/api/v1/orgs/{orgId}/products/{productId}",{params:{path:{orgId:e,productId:t},query:r}});return f(o,"products.get")}async create(e,t){let r=await this.client.POST("/api/v1/orgs/{orgId}/products",{params:{path:{orgId:e}},body:t});return f(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 f(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 f(r,"products.delete")}}class le{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 f(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 f(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 f(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 f(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 f(r,"events.delete")}}class me{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 f(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 f(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 f(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 f(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 f(r,"rooms.delete")}}class pe{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 f(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 f(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 f(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 f(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 f(r,"bookings.delete")}}class fe{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 f(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 f(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 f(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 f(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 f(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 f(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 f(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 f(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 f(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 f(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 f(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 f(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 f(s,"projects.createCardComment")}}class ye{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 f(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 f(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 f(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 f(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 f(r,"blogs.delete")}}class he{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 f(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 f(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 f(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 f(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 f(r,"bookingTypes.delete")}}class be{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 f(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 f(r,"orders.get")}}class we{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 f(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 f(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 f(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 f(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 f(r,"quotes.delete")}}class ve{client;constructor(e){this.client=e}async summary(e,t={}){let r=await this.client.GET("/api/v1/orgs/{orgId}/analytics/summary",{params:{path:{orgId:e},query:t}});return f(r,"analytics.summary")}async visits(e,t={}){let r=await this.client.GET("/api/v1/orgs/{orgId}/analytics/visits",{params:{path:{orgId:e},query:t}});return f(r,"analytics.visits")}async topProducts(e,t={}){let r=await this.client.GET("/api/v1/orgs/{orgId}/analytics/products/top",{params:{path:{orgId:e},query:t}});return f(r,"analytics.topProducts")}}class je{client;constructor(e){this.client=e}async list(e){let t=await this.client.GET("/api/v1/orgs/{orgId}/collections",{params:{path:{orgId:e}}});return f(t,"collections.list")}async get(e,t){let r=await this.client.GET("/api/v1/orgs/{orgId}/collections/{collectionId}",{params:{path:{orgId:e,collectionId:t}}});return f(r,"collections.get")}async create(e,t){let r=await this.client.POST("/api/v1/orgs/{orgId}/collections",{params:{path:{orgId:e}},body:t});return f(r,"collections.create")}async update(e,t,r){let o=await this.client.PUT("/api/v1/orgs/{orgId}/collections/{collectionId}",{params:{path:{orgId:e,collectionId:t}},body:r});return f(o,"collections.update")}async delete(e,t){let r=await this.client.DELETE("/api/v1/orgs/{orgId}/collections/{collectionId}",{params:{path:{orgId:e,collectionId:t}}});return f(r,"collections.delete")}}class ke{client;constructor(e){this.client=e}async list(e,t={}){let r=await this.client.GET("/api/v1/orgs/{orgId}/agents",{params:{path:{orgId:e},query:t}});return f(r,"agents.list")}async get(e,t){let r=await this.client.GET("/api/v1/orgs/{orgId}/agents/{agentId}",{params:{path:{orgId:e,agentId:t}}});return f(r,"agents.get")}}class Ce{client;constructor(e){this.client=e}async list(e,t={}){let r=await this.client.GET("/api/v1/orgs/{orgId}/conversations",{params:{path:{orgId:e},query:t}});return f(r,"conversations.list")}async get(e,t,r={}){let o=await this.client.GET("/api/v1/orgs/{orgId}/conversations/{conversationId}",{params:{path:{orgId:e,conversationId:t},query:r}});return f(o,"conversations.get")}}class Ee{client;constructor(e){this.client=e}async get(e){let t=await this.client.GET("/api/v1/orgs/{orgId}/customer-agent",{params:{path:{orgId:e}}});return f(t,"customerAgent.get")}async listKnowledge(e){let t=await this.client.GET("/api/v1/orgs/{orgId}/customer-agent/knowledge",{params:{path:{orgId:e}}});return f(t,"customerAgent.listKnowledge")}}class Re{client;constructor(e){this.client=e}async list(e,t={}){let r=await this.client.GET("/api/v1/orgs/{orgId}/posts",{params:{path:{orgId:e},query:t}});return f(r,"posts.list")}async get(e,t){let r=await this.client.GET("/api/v1/orgs/{orgId}/posts/{postId}",{params:{path:{orgId:e,postId:t}}});return f(r,"posts.get")}async createDraft(e,t){let r=await this.client.POST("/api/v1/orgs/{orgId}/posts",{params:{path:{orgId:e}},body:t});return f(r,"posts.createDraft")}async requestVideoUpload(e,t,r){let o=await this.client.POST("/api/v1/orgs/{orgId}/posts/{postId}/video",{params:{path:{orgId:e,postId:t}},body:{bytes:r}});return f(o,"posts.requestVideoUpload")}async finalizeVideo(e,t){let r=await this.client.POST("/api/v1/orgs/{orgId}/posts/{postId}/video/finalize",{params:{path:{orgId:e,postId:t}}});return f(r,"posts.finalizeVideo")}async videoPreview(e,t){let r=await this.client.GET("/api/v1/orgs/{orgId}/posts/{postId}/video/preview",{params:{path:{orgId:e,postId:t}}});return f(r,"posts.videoPreview")}async publish(e,t){let r=await this.client.POST("/api/v1/orgs/{orgId}/posts/{postId}/publish",{params:{path:{orgId:e,postId:t}}});return f(r,"posts.publish")}}var Pn="https://vcity.io";function xn(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 _n(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 Me{raw;me;orgs;products;events;rooms;agents;conversations;customerAgent;posts;collections;bookings;bookingTypes;projects;blogs;orders;analytics;quotes;constructor(e={}){let t=e.baseUrl??Pn;xn(t);let r=_n(e.token,e.fetch),o={baseUrl:t,fetch:r,headers:e.headers};this.raw=Fe(o),this.me=new ce(this.raw),this.orgs=new ue(this.raw),this.products=new ge(this.raw),this.events=new le(this.raw),this.rooms=new me(this.raw),this.agents=new ke(this.raw),this.conversations=new Ce(this.raw),this.customerAgent=new Ee(this.raw),this.posts=new Re(this.raw),this.collections=new je(this.raw),this.bookings=new pe(this.raw),this.bookingTypes=new he(this.raw),this.projects=new fe(this.raw),this.blogs=new ye(this.raw),this.orders=new be(this.raw),this.analytics=new ve(this.raw),this.quotes=new we(this.raw)}}function Ge(e={}){return new Me(e)}import U from"node:fs";import Un from"node:os";import Te from"node:path";var Dn=/\x1b(?:\[[0-?]*[ -/]*[@-~]|\][^\x07\x1b]*(?:\x07|\x1b\\)|[P_^X][^\x07\x1b]*(?:\x07|\x1b\\)|[^[\]P_^X])/g,Nn=/[\x00-\x08\x0b-\x1f\x7f-\x9f]/g,$n=/[\u061c\u200e\u200f\u202a-\u202e\u2066-\u2069]/g;function E(e){return e.replace(Dn,"").replace(Nn,"").replace($n,"")}function gt(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 ut=512;function v(e,t){let r=e.trim();if(!r)throw Error(`${t} must not be empty.`);if(r.length>ut)throw Error(`${t} must be at most ${ut} characters.`);if(/[\x00-\x1f\x7f]/.test(r))throw Error(`${t} must not contain control characters.`);return r}function W(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 N(){if(process.env.VCITY_CONFIG_DIR)return Te.resolve(process.env.VCITY_CONFIG_DIR);return Te.join(Un.homedir(),".vcity")}function Se(){return Te.join(N(),"auth.json")}function Ve(){return Te.join(N(),"config.json")}function Ie(){let e=process.env.VCITY_API_BASE_URL||"https://vcity.io";return W(e),e}import D from"node:fs";function Q(e,t,r=384){if(process.platform==="win32"){D.writeFileSync(e,t,{mode:r});try{D.chmodSync(e,r)}catch{}return}let o=D.constants.O_WRONLY|D.constants.O_CREAT|D.constants.O_TRUNC|D.constants.O_NOFOLLOW,s=D.openSync(e,o,r);try{D.writeSync(s,t),D.fchmodSync(s,r)}finally{D.closeSync(s)}}function qn(){let e=N();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 Ln(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 X(){let e=Se();if(!U.existsSync(e))return;try{let t=JSON.parse(U.readFileSync(e,"utf-8"));if(!Ln(t))return;if(W(t.api_base_url),new URL(t.api_base_url).origin!==new URL(Ie()).origin)return;return t}catch{return}}function Bn(e){let t;try{t=U.lstatSync(e)}catch{return}if(t.isSymbolicLink()||t.isFile()&&t.nlink>1)U.rmSync(e,{force:!0})}function Oe(e){qn();let t=Se();Bn(t),Q(t,JSON.stringify(e,null,2),384)}function Z(){let e=Se();if(U.existsSync(e))U.rmSync(e)}function Ae(){let e=X();if(!e)throw Error("Not logged in. Run `vcity login` first.");return e}var Ye={name:"@vcityio/cli",version:"0.9.0",type:"module",description:"vcity command-line interface for org owners",main:"./dist/index.js",bin:{vcity:"./dist/index.js"},files:["dist","README.md","LICENSE"],engines:{node:">=20"},publishConfig:{access:"public"},optionalDependencies:{open:"^10.0.0"},keywords:["vcity","cli"],author:"Otherwise SAS",license:"MIT",homepage:"https://vcity.io",bugs:{email:"support@owsas.com"}};var _=Ye.version,M=Ye.name;var ze=60000,yt=`vcity-cli/${_} (${process.platform} ${process.arch})`,lt=2048;class ee extends Error{status;body;constructor(e,t,r){super(r??`HTTP ${e}`);this.status=e;this.body=t;this.name="ApiError"}}function ht(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 mt=(e,t)=>typeof e==="string"&&e.length>0&&e.length<=t,Pe=Symbol("transient"),pt=(e)=>typeof e==="number"&&Number.isFinite(e);async function Mn(e){try{let t=await fetch(ht(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(ze),redirect:"error"});if(t.status===429||t.status>=500)return Pe;if(!t.ok)return;let r=await t.json();if(!mt(r.access_token,lt)||!mt(r.refresh_token,lt)||!pt(r.access_expires_at)||!pt(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 Oe(o),o}catch{return Pe}}async function ft(e){let t=()=>new ee(401,void 0,"Session expired. Run `vcity login` again."),r=X();if(r&&r.refresh_token!==e.refresh_token)return r;let o=await Mn(e);if(o&&o!==Pe)return o;let s=X();if(s&&s.refresh_token!==e.refresh_token)return s;if(o===Pe)throw new ee(503,void 0,"Could not refresh the session. Check your connection and try again.");throw Z(),t()}async function te(e,t={}){let{authed:r=!0,method:o="GET",body:s,query:i,baseUrl:n,headers:a}=t,d=r?Ae():void 0,c=n??d?.api_base_url??"https://vcity.io",w={"content-type":"application/json","user-agent":yt};if(d)w.authorization=`Bearer ${d.access_token}`;if(a)for(let[z,tt]of Object.entries(a))w[z]=tt;let h=await fetch(ht(c,e,i),{method:o,headers:w,body:s===void 0?void 0:JSON.stringify(s),signal:AbortSignal.timeout(ze),redirect:"error"}),S=(h.headers.get("content-type")??"").includes("application/json")?await h.json().catch(()=>{return}):await h.text().catch(()=>{return});if(!h.ok){let z=(S&&typeof S==="object"&&"error"in S?String(S.error):void 0)??`Request failed (${h.status})`;throw new ee(h.status,S,z)}return S}function Gn(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 Vn(){let e=async(t,r,o)=>{Gn(t.url,o);let s=new Headers(t.headers);s.set("authorization",`Bearer ${r}`),s.set("user-agent",yt);let i=new Request(t,{headers:s,signal:AbortSignal.timeout(ze),redirect:"error"});return globalThis.fetch(i)};return async function(r){let o=Ae(),s=new URL(o.api_base_url).origin;if(Date.now()>=o.access_expires_at){if(Date.now()>=o.refresh_expires_at)throw Z(),new ee(401,void 0,"Session expired. Run `vcity login` again.");o=await ft(o)}let i=await e(r,o.access_token,s);if(i.status!==401)return i;return o=await ft(o),e(r,o.access_token,s)}}function m(){let e=Ae();return Ge({baseUrl:e.api_base_url,fetch:Vn()})}import G from"node:fs";import Yn from"node:path";var Je=16777216;function zn(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 C(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=zn(Je)}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+Yn.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>Je)throw Error(`--data: ${r} exceeds the ${Je}-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 Jn(){let e=N();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 Hn(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 Y(){let e=Ve();if(!V.existsSync(e))return{};try{let t=JSON.parse(V.readFileSync(e,"utf-8"));return Hn(t)?t:{}}catch{return{}}}function Wn(e){let t;try{t=V.lstatSync(e)}catch{return}if(t.isSymbolicLink()||t.isFile()&&t.nlink>1)V.rmSync(e,{force:!0})}function bt(e){Jn();let r={...Y(),...e},o=Ve();return Wn(o),Q(o,JSON.stringify(r,null,2),384),r}function p(e){if(e)return e;let t=Y();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 Rn=/\{[^{}]+\}/g,Tn=()=>typeof process==="object"&&Number.parseInt(process?.versions?.node?.substring(0,2))>=18&&process.versions.undici;function Sn(){return Math.random().toString(36).slice(2,11)}function Fe(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=Tn()?a:void 0,t=at(t);let c=[];async function w(h,k){let{baseUrl:S,fetch:z=o,Request:tt=r,headers:rt,params:J={},parseAs:Ne="json",querySerializer:oe,bodySerializer:nt=i??On,body:ot,...$e}=k||{},Ue=t;if(S)Ue=at(S)??t;let qe=typeof s==="function"?s:st(s);if(oe)qe=typeof oe==="function"?oe:st({...typeof s==="object"?s:{},...oe});let Le=ot===void 0?void 0:nt(ot,it(n,rt,J.header)),Cn=it(Le===void 0||Le instanceof FormData?{}:{"Content-Type":"application/json"},n,rt,J.header),En={redirect:"follow",...d,...$e,body:Le,headers:Cn},se,ie,q=new r(An(h,{baseUrl:Ue,params:J,querySerializer:qe}),En),T;for(let x in $e)if(!(x in q))q[x]=$e[x];if(c.length){se=Sn(),ie=Object.freeze({baseUrl:Ue,fetch:z,parseAs:Ne,querySerializer:qe,bodySerializer:nt});for(let x of c)if(x&&typeof x==="object"&&typeof x.onRequest==="function"){let A=await x.onRequest({request:q,schemaPath:h,params:J,options:ie,id:se});if(A)if(A instanceof r)q=A;else if(A instanceof Response){T=A;break}else throw Error("onRequest: must return new Request() or Response() when modifying the request")}}if(!T){try{T=await z(q,a)}catch(x){let A=x;if(c.length)for(let F=c.length-1;F>=0;F--){let ae=c[F];if(ae&&typeof ae==="object"&&typeof ae.onError==="function"){let K=await ae.onError({request:q,error:A,schemaPath:h,params:J,options:ie,id:se});if(K){if(K instanceof Response){A=void 0,T=K;break}if(K instanceof Error){A=K;continue}throw Error("onError: must return new Response() or instance of Error")}}}if(A)throw A}if(c.length)for(let x=c.length-1;x>=0;x--){let A=c[x];if(A&&typeof A==="object"&&typeof A.onResponse==="function"){let F=await A.onResponse({request:q,response:T,schemaPath:h,params:J,options:ie,id:se});if(F){if(!(F instanceof Response))throw Error("onResponse: must return new Response() when modifying the response");T=F}}}}if(T.status===204||q.method==="HEAD"||T.headers.get("Content-Length")==="0")return T.ok?{data:void 0,response:T}:{error:void 0,response:T};if(T.ok){if(Ne==="stream")return{data:T.body,response:T};return{data:await T[Ne](),response:T}}let Be=await T.text();try{Be=JSON.parse(Be)}catch{}return{error:Be,response:T}}return{request(h,k,S){return w(k,{...S,method:h.toUpperCase()})},GET(h,k){return w(h,{...k,method:"GET"})},PUT(h,k){return w(h,{...k,method:"PUT"})},POST(h,k){return w(h,{...k,method:"POST"})},DELETE(h,k){return w(h,{...k,method:"DELETE"})},OPTIONS(h,k){return w(h,{...k,method:"OPTIONS"})},HEAD(h,k){return w(h,{...k,method:"HEAD"})},PATCH(h,k){return w(h,{...k,method:"PATCH"})},TRACE(h,k){return w(h,{...k,method:"TRACE"})},use(...h){for(let k of h){if(!k)continue;if(typeof k!=="object"||!(("onRequest"in k)||("onResponse"in k)||("onError"in k)))throw Error("Middleware must be an object with one of `onRequest()`, `onResponse() or `onError()`");c.push(k)}},eject(...h){for(let k of h){let S=c.indexOf(k);if(S!==-1)c.splice(S,1)}}}}function de(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 dt(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(de(a,t[n],r))}let i=o.join(s);return r.style==="label"||r.style==="matrix"?`${s}${i}`:i}function ct(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(de(e,i,r));return r.style==="label"||r.style==="matrix"?`${o}${s.join(o)}`:s.join(o)}function st(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(ct(s,i,{style:"form",explode:!0,...e?.array,allowReserved:e?.allowReserved||!1}));continue}if(typeof i==="object"){o.push(dt(s,i,{style:"deepObject",explode:!0,...e?.object,allowReserved:e?.allowReserved||!1}));continue}o.push(de(s,i,e))}return o.join("&")}}function In(e,t){let r=e;for(let o of e.match(Rn)??[]){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,ct(s,a,{style:n,explode:i}));continue}if(typeof a==="object"){r=r.replace(o,dt(s,a,{style:n,explode:i}));continue}if(n==="matrix"){r=r.replace(o,`;${de(s,a)}`);continue}r=r.replace(o,n==="label"?`.${encodeURIComponent(a)}`:encodeURIComponent(a))}return r}function On(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 An(e,t){let r=`${t.baseUrl}${e}`;if(t.params?.path)r=In(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 it(...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 at(e){if(e.endsWith("/"))return e.substring(0,e.length-1);return e}class H 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 f(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 H(String(s),r,e.error,o)}if(e.data===void 0)throw new H(`${t}: empty response body`,e.response?.status??0,void 0,e.response?.url??"");return e.data}class ce{client;constructor(e){this.client=e}async get(){let e=await this.client.GET("/api/v1/me",{});return f(e,"me.get")}}class ue{client;constructor(e){this.client=e}async get(e){let t=await this.client.GET("/api/v1/orgs/{orgId}",{params:{path:{orgId:e}}});return f(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 f(r,"orgs.listMembers")}}class ge{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 f(r,"products.list")}async get(e,t,r={}){let o=await this.client.GET("/api/v1/orgs/{orgId}/products/{productId}",{params:{path:{orgId:e,productId:t},query:r}});return f(o,"products.get")}async create(e,t){let r=await this.client.POST("/api/v1/orgs/{orgId}/products",{params:{path:{orgId:e}},body:t});return f(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 f(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 f(r,"products.delete")}}class le{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 f(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 f(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 f(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 f(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 f(r,"events.delete")}}class me{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 f(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 f(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 f(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 f(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 f(r,"rooms.delete")}}class pe{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 f(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 f(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 f(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 f(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 f(r,"bookings.delete")}}class fe{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 f(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 f(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 f(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 f(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 f(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 f(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 f(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 f(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 f(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 f(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 f(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 f(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 f(s,"projects.createCardComment")}}class ye{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 f(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 f(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 f(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 f(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 f(r,"blogs.delete")}}class he{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 f(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 f(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 f(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 f(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 f(r,"bookingTypes.delete")}}class be{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 f(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 f(r,"orders.get")}}class we{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 f(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 f(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 f(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 f(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 f(r,"quotes.delete")}}class ve{client;constructor(e){this.client=e}async summary(e,t={}){let r=await this.client.GET("/api/v1/orgs/{orgId}/analytics/summary",{params:{path:{orgId:e},query:t}});return f(r,"analytics.summary")}async visits(e,t={}){let r=await this.client.GET("/api/v1/orgs/{orgId}/analytics/visits",{params:{path:{orgId:e},query:t}});return f(r,"analytics.visits")}async topProducts(e,t={}){let r=await this.client.GET("/api/v1/orgs/{orgId}/analytics/products/top",{params:{path:{orgId:e},query:t}});return f(r,"analytics.topProducts")}}class je{client;constructor(e){this.client=e}async list(e){let t=await this.client.GET("/api/v1/orgs/{orgId}/collections",{params:{path:{orgId:e}}});return f(t,"collections.list")}async get(e,t){let r=await this.client.GET("/api/v1/orgs/{orgId}/collections/{collectionId}",{params:{path:{orgId:e,collectionId:t}}});return f(r,"collections.get")}async create(e,t){let r=await this.client.POST("/api/v1/orgs/{orgId}/collections",{params:{path:{orgId:e}},body:t});return f(r,"collections.create")}async update(e,t,r){let o=await this.client.PUT("/api/v1/orgs/{orgId}/collections/{collectionId}",{params:{path:{orgId:e,collectionId:t}},body:r});return f(o,"collections.update")}async delete(e,t){let r=await this.client.DELETE("/api/v1/orgs/{orgId}/collections/{collectionId}",{params:{path:{orgId:e,collectionId:t}}});return f(r,"collections.delete")}}class ke{client;constructor(e){this.client=e}async list(e,t={}){let r=await this.client.GET("/api/v1/orgs/{orgId}/agents",{params:{path:{orgId:e},query:t}});return f(r,"agents.list")}async get(e,t){let r=await this.client.GET("/api/v1/orgs/{orgId}/agents/{agentId}",{params:{path:{orgId:e,agentId:t}}});return f(r,"agents.get")}}class Ce{client;constructor(e){this.client=e}async list(e,t={}){let r=await this.client.GET("/api/v1/orgs/{orgId}/conversations",{params:{path:{orgId:e},query:t}});return f(r,"conversations.list")}async get(e,t,r={}){let o=await this.client.GET("/api/v1/orgs/{orgId}/conversations/{conversationId}",{params:{path:{orgId:e,conversationId:t},query:r}});return f(o,"conversations.get")}}class Ee{client;constructor(e){this.client=e}async get(e){let t=await this.client.GET("/api/v1/orgs/{orgId}/customer-agent",{params:{path:{orgId:e}}});return f(t,"customerAgent.get")}async listKnowledge(e){let t=await this.client.GET("/api/v1/orgs/{orgId}/customer-agent/knowledge",{params:{path:{orgId:e}}});return f(t,"customerAgent.listKnowledge")}}class Re{client;constructor(e){this.client=e}async list(e,t={}){let r=await this.client.GET("/api/v1/orgs/{orgId}/posts",{params:{path:{orgId:e},query:t}});return f(r,"posts.list")}async get(e,t){let r=await this.client.GET("/api/v1/orgs/{orgId}/posts/{postId}",{params:{path:{orgId:e,postId:t}}});return f(r,"posts.get")}async createDraft(e,t){let r=await this.client.POST("/api/v1/orgs/{orgId}/posts",{params:{path:{orgId:e}},body:t});return f(r,"posts.createDraft")}async requestVideoUpload(e,t,r){let o=await this.client.POST("/api/v1/orgs/{orgId}/posts/{postId}/video",{params:{path:{orgId:e,postId:t}},body:{bytes:r}});return f(o,"posts.requestVideoUpload")}async finalizeVideo(e,t){let r=await this.client.POST("/api/v1/orgs/{orgId}/posts/{postId}/video/finalize",{params:{path:{orgId:e,postId:t}}});return f(r,"posts.finalizeVideo")}async videoPreview(e,t){let r=await this.client.GET("/api/v1/orgs/{orgId}/posts/{postId}/video/preview",{params:{path:{orgId:e,postId:t}}});return f(r,"posts.videoPreview")}async publish(e,t){let r=await this.client.POST("/api/v1/orgs/{orgId}/posts/{postId}/publish",{params:{path:{orgId:e,postId:t}}});return f(r,"posts.publish")}}var Pn="https://vcity.io";function xn(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 _n(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 Me{raw;me;orgs;products;events;rooms;agents;conversations;customerAgent;posts;collections;bookings;bookingTypes;projects;blogs;orders;analytics;quotes;constructor(e={}){let t=e.baseUrl??Pn;xn(t);let r=_n(e.token,e.fetch),o={baseUrl:t,fetch:r,headers:e.headers};this.raw=Fe(o),this.me=new ce(this.raw),this.orgs=new ue(this.raw),this.products=new ge(this.raw),this.events=new le(this.raw),this.rooms=new me(this.raw),this.agents=new ke(this.raw),this.conversations=new Ce(this.raw),this.customerAgent=new Ee(this.raw),this.posts=new Re(this.raw),this.collections=new je(this.raw),this.bookings=new pe(this.raw),this.bookingTypes=new he(this.raw),this.projects=new fe(this.raw),this.blogs=new ye(this.raw),this.orders=new be(this.raw),this.analytics=new ve(this.raw),this.quotes=new we(this.raw)}}function Ge(e={}){return new Me(e)}import U from"node:fs";import Un from"node:os";import Te from"node:path";var Dn=/\x1b(?:\[[0-?]*[ -/]*[@-~]|\][^\x07\x1b]*(?:\x07|\x1b\\)|[P_^X][^\x07\x1b]*(?:\x07|\x1b\\)|[^[\]P_^X])/g,Nn=/[\x00-\x08\x0b-\x1f\x7f-\x9f]/g,$n=/[\u061c\u200e\u200f\u202a-\u202e\u2066-\u2069]/g;function E(e){return e.replace(Dn,"").replace(Nn,"").replace($n,"")}function gt(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 ut=512;function v(e,t){let r=e.trim();if(!r)throw Error(`${t} must not be empty.`);if(r.length>ut)throw Error(`${t} must be at most ${ut} characters.`);if(/[\x00-\x1f\x7f]/.test(r))throw Error(`${t} must not contain control characters.`);return r}function W(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 N(){if(process.env.VCITY_CONFIG_DIR)return Te.resolve(process.env.VCITY_CONFIG_DIR);return Te.join(Un.homedir(),".vcity")}function Se(){return Te.join(N(),"auth.json")}function Ve(){return Te.join(N(),"config.json")}function Ie(){let e=process.env.VCITY_API_BASE_URL||"https://vcity.io";return W(e),e}import D from"node:fs";function Q(e,t,r=384){if(process.platform==="win32"){D.writeFileSync(e,t,{mode:r});try{D.chmodSync(e,r)}catch{}return}let o=D.constants.O_WRONLY|D.constants.O_CREAT|D.constants.O_TRUNC|D.constants.O_NOFOLLOW,s=D.openSync(e,o,r);try{D.writeSync(s,t),D.fchmodSync(s,r)}finally{D.closeSync(s)}}function qn(){let e=N();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 Ln(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 X(){let e=Se();if(!U.existsSync(e))return;try{let t=JSON.parse(U.readFileSync(e,"utf-8"));if(!Ln(t))return;if(W(t.api_base_url),new URL(t.api_base_url).origin!==new URL(Ie()).origin)return;return t}catch{return}}function Bn(e){let t;try{t=U.lstatSync(e)}catch{return}if(t.isSymbolicLink()||t.isFile()&&t.nlink>1)U.rmSync(e,{force:!0})}function Oe(e){qn();let t=Se();Bn(t),Q(t,JSON.stringify(e,null,2),384)}function Z(){let e=Se();if(U.existsSync(e))U.rmSync(e)}function Ae(){let e=X();if(!e)throw Error("Not logged in. Run `vcity login` first.");return e}var Ye={name:"@vcityio/cli",version:"0.9.1",type:"module",description:"vcity command-line interface for org owners",main:"./dist/index.js",bin:{vcity:"./dist/index.js"},files:["dist","README.md","LICENSE"],engines:{node:">=20"},publishConfig:{access:"public"},optionalDependencies:{open:"^10.0.0"},keywords:["vcity","cli"],author:"Otherwise SAS",license:"MIT",homepage:"https://vcity.io",bugs:{email:"support@owsas.com"}};var _=Ye.version,M=Ye.name;var ze=60000,yt=`vcity-cli/${_} (${process.platform} ${process.arch})`,lt=2048;class ee extends Error{status;body;constructor(e,t,r){super(r??`HTTP ${e}`);this.status=e;this.body=t;this.name="ApiError"}}function ht(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 mt=(e,t)=>typeof e==="string"&&e.length>0&&e.length<=t,Pe=Symbol("transient"),pt=(e)=>typeof e==="number"&&Number.isFinite(e);async function Mn(e){try{let t=await fetch(ht(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(ze),redirect:"error"});if(t.status===429||t.status>=500)return Pe;if(!t.ok)return;let r=await t.json();if(!mt(r.access_token,lt)||!mt(r.refresh_token,lt)||!pt(r.access_expires_at)||!pt(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 Oe(o),o}catch{return Pe}}async function ft(e){let t=()=>new ee(401,void 0,"Session expired. Run `vcity login` again."),r=X();if(r&&r.refresh_token!==e.refresh_token)return r;let o=await Mn(e);if(o&&o!==Pe)return o;let s=X();if(s&&s.refresh_token!==e.refresh_token)return s;if(o===Pe)throw new ee(503,void 0,"Could not refresh the session. Check your connection and try again.");throw Z(),t()}async function te(e,t={}){let{authed:r=!0,method:o="GET",body:s,query:i,baseUrl:n,headers:a}=t,d=r?Ae():void 0,c=n??d?.api_base_url??"https://vcity.io",w={"content-type":"application/json","user-agent":yt};if(d)w.authorization=`Bearer ${d.access_token}`;if(a)for(let[z,tt]of Object.entries(a))w[z]=tt;let h=await fetch(ht(c,e,i),{method:o,headers:w,body:s===void 0?void 0:JSON.stringify(s),signal:AbortSignal.timeout(ze),redirect:"error"}),S=(h.headers.get("content-type")??"").includes("application/json")?await h.json().catch(()=>{return}):await h.text().catch(()=>{return});if(!h.ok){let z=(S&&typeof S==="object"&&"error"in S?String(S.error):void 0)??`Request failed (${h.status})`;throw new ee(h.status,S,z)}return S}function Gn(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 Vn(){let e=async(t,r,o)=>{Gn(t.url,o);let s=new Headers(t.headers);s.set("authorization",`Bearer ${r}`),s.set("user-agent",yt);let i=new Request(t,{headers:s,signal:AbortSignal.timeout(ze),redirect:"error"});return globalThis.fetch(i)};return async function(r){let o=Ae(),s=new URL(o.api_base_url).origin;if(Date.now()>=o.access_expires_at){if(Date.now()>=o.refresh_expires_at)throw Z(),new ee(401,void 0,"Session expired. Run `vcity login` again.");o=await ft(o)}let i=await e(r,o.access_token,s);if(i.status!==401)return i;return o=await ft(o),e(r,o.access_token,s)}}function m(){let e=Ae();return Ge({baseUrl:e.api_base_url,fetch:Vn()})}import G from"node:fs";import Yn from"node:path";var Je=16777216;function zn(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 C(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=zn(Je)}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+Yn.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>Je)throw Error(`--data: ${r} exceeds the ${Je}-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 Jn(){let e=N();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 Hn(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 Y(){let e=Ve();if(!V.existsSync(e))return{};try{let t=JSON.parse(V.readFileSync(e,"utf-8"));return Hn(t)?t:{}}catch{return{}}}function Wn(e){let t;try{t=V.lstatSync(e)}catch{return}if(t.isSymbolicLink()||t.isFile()&&t.nlink>1)V.rmSync(e,{force:!0})}function bt(e){Jn();let r={...Y(),...e},o=Ve();return Wn(o),Q(o,JSON.stringify(r,null,2),384),r}function p(e){if(e)return e;let t=Y();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 Qn(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 j(e,t){process.stdout.write(`${Qn(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(`${E(t).padEnd(20)} ${E(o)}
|