@vcityio/cli 0.9.1 → 0.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +89 -1
- package/dist/index.js +329 -88
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,100 +1,230 @@
|
|
|
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.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
|
-
|
|
4
|
-
`)
|
|
5
|
-
`)
|
|
6
|
-
`)
|
|
7
|
-
|
|
8
|
-
`),b(w)}async function St(e,t={}){let r=g(t.json),o=p(t.org);if(!t.yes){if(r==="json")throw Error("blogs delete: --yes is required in JSON / non-interactive mode");if(!await R(`Delete blog ${e} in org ${o}? [y/N]`)){process.stdout.write(`Aborted.
|
|
9
|
-
`);
|
|
10
|
-
`)}
|
|
11
|
-
`)
|
|
12
|
-
`),
|
|
13
|
-
`)
|
|
14
|
-
`)
|
|
15
|
-
`)
|
|
16
|
-
`)
|
|
17
|
-
`)
|
|
18
|
-
`)
|
|
19
|
-
`)
|
|
20
|
-
`),
|
|
21
|
-
`),
|
|
22
|
-
`)
|
|
23
|
-
`)}
|
|
24
|
-
`),
|
|
25
|
-
`),
|
|
26
|
-
`),
|
|
27
|
-
|
|
28
|
-
`)
|
|
2
|
+
var ai=/\{[^{}]+\}/g,ci=()=>typeof process==="object"&&Number.parseInt(process?.versions?.node?.substring(0,2))>=18&&process.versions.undici;function di(){return Math.random().toString(36).slice(2,11)}function ir(t){let{baseUrl:e="",Request:r=globalThis.Request,fetch:n=globalThis.fetch,querySerializer:i,bodySerializer:a,headers:s,requestInitExt:o=void 0,...c}={...t};o=ci()?o:void 0,e=xr(e);let u=[];async function l(w,v){let{baseUrl:R,fetch:T=n,Request:N=r,headers:F,params:D={},parseAs:X="json",querySerializer:L,bodySerializer:rt=a??gi,body:kt,...It}=v||{},rr=e;if(R)rr=xr(R)??e;let sr=typeof i==="function"?i:Sr(i);if(L)sr=typeof L==="function"?L:Sr({...typeof i==="object"?i:{},...L});let nr=kt===void 0?void 0:rt(kt,Or(s,F,D.header)),oi=Or(nr===void 0||nr instanceof FormData?{}:{"Content-Type":"application/json"},s,F,D.header),ii={redirect:"follow",...c,...It,body:nr,headers:oi},Jt,Ht,ft=new r(li(w,{baseUrl:rr,params:D,querySerializer:sr}),ii),W;for(let et in It)if(!(et in ft))ft[et]=It[et];if(u.length){Jt=di(),Ht=Object.freeze({baseUrl:rr,fetch:T,parseAs:X,querySerializer:sr,bodySerializer:rt});for(let et of u)if(et&&typeof et==="object"&&typeof et.onRequest==="function"){let K=await et.onRequest({request:ft,schemaPath:w,params:D,options:Ht,id:Jt});if(K)if(K instanceof r)ft=K;else if(K instanceof Response){W=K;break}else throw Error("onRequest: must return new Request() or Response() when modifying the request")}}if(!W){try{W=await T(ft,o)}catch(et){let K=et;if(u.length)for(let jt=u.length-1;jt>=0;jt--){let Yt=u[jt];if(Yt&&typeof Yt==="object"&&typeof Yt.onError==="function"){let Pt=await Yt.onError({request:ft,error:K,schemaPath:w,params:D,options:Ht,id:Jt});if(Pt){if(Pt instanceof Response){K=void 0,W=Pt;break}if(Pt instanceof Error){K=Pt;continue}throw Error("onError: must return new Response() or instance of Error")}}}if(K)throw K}if(u.length)for(let et=u.length-1;et>=0;et--){let K=u[et];if(K&&typeof K==="object"&&typeof K.onResponse==="function"){let jt=await K.onResponse({request:ft,response:W,schemaPath:w,params:D,options:Ht,id:Jt});if(jt){if(!(jt instanceof Response))throw Error("onResponse: must return new Response() when modifying the response");W=jt}}}}if(W.status===204||ft.method==="HEAD"||W.headers.get("Content-Length")==="0")return W.ok?{data:void 0,response:W}:{error:void 0,response:W};if(W.ok){if(X==="stream")return{data:W.body,response:W};return{data:await W[X](),response:W}}let or=await W.text();try{or=JSON.parse(or)}catch{}return{error:or,response:W}}return{request(w,v,R){return l(v,{...R,method:w.toUpperCase()})},GET(w,v){return l(w,{...v,method:"GET"})},PUT(w,v){return l(w,{...v,method:"PUT"})},POST(w,v){return l(w,{...v,method:"POST"})},DELETE(w,v){return l(w,{...v,method:"DELETE"})},OPTIONS(w,v){return l(w,{...v,method:"OPTIONS"})},HEAD(w,v){return l(w,{...v,method:"HEAD"})},PATCH(w,v){return l(w,{...v,method:"PATCH"})},TRACE(w,v){return l(w,{...v,method:"TRACE"})},use(...w){for(let v of w){if(!v)continue;if(typeof v!=="object"||!(("onRequest"in v)||("onResponse"in v)||("onError"in v)))throw Error("Middleware must be an object with one of `onRequest()`, `onResponse() or `onError()`");u.push(v)}},eject(...w){for(let v of w){let R=u.indexOf(v);if(R!==-1)u.splice(R,1)}}}}function Qt(t,e,r){if(e===void 0||e===null)return"";if(typeof e==="object")throw Error("Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.");return`${t}=${r?.allowReserved===!0?e:encodeURIComponent(e)}`}function Ar(t,e,r){if(!e||typeof e!=="object")return"";let n=[],i={simple:",",label:".",matrix:";"}[r.style]||"&";if(r.style!=="deepObject"&&r.explode===!1){for(let o in e)n.push(o,r.allowReserved===!0?e[o]:encodeURIComponent(e[o]));let s=n.join(",");switch(r.style){case"form":return`${t}=${s}`;case"label":return`.${s}`;case"matrix":return`;${t}=${s}`;default:return s}}for(let s in e){let o=r.style==="deepObject"?`${t}[${s}]`:s;n.push(Qt(o,e[s],r))}let a=n.join(i);return r.style==="label"||r.style==="matrix"?`${i}${a}`:a}function Pr(t,e,r){if(!Array.isArray(e))return"";if(r.explode===!1){let a={form:",",spaceDelimited:"%20",pipeDelimited:"|"}[r.style]||",",s=(r.allowReserved===!0?e:e.map((o)=>encodeURIComponent(o))).join(a);switch(r.style){case"simple":return s;case"label":return`.${s}`;case"matrix":return`;${t}=${s}`;default:return`${t}=${s}`}}let n={simple:",",label:".",matrix:";"}[r.style]||"&",i=[];for(let a of e)if(r.style==="simple"||r.style==="label")i.push(r.allowReserved===!0?a:encodeURIComponent(a));else i.push(Qt(t,a,r));return r.style==="label"||r.style==="matrix"?`${n}${i.join(n)}`:i.join(n)}function Sr(t){return function(r){let n=[];if(r&&typeof r==="object")for(let i in r){let a=r[i];if(a===void 0||a===null)continue;if(Array.isArray(a)){if(a.length===0)continue;n.push(Pr(i,a,{style:"form",explode:!0,...t?.array,allowReserved:t?.allowReserved||!1}));continue}if(typeof a==="object"){n.push(Ar(i,a,{style:"deepObject",explode:!0,...t?.object,allowReserved:t?.allowReserved||!1}));continue}n.push(Qt(i,a,t))}return n.join("&")}}function ui(t,e){let r=t;for(let n of t.match(ai)??[]){let i=n.substring(1,n.length-1),a=!1,s="simple";if(i.endsWith("*"))a=!0,i=i.substring(0,i.length-1);if(i.startsWith("."))s="label",i=i.substring(1);else if(i.startsWith(";"))s="matrix",i=i.substring(1);if(!e||e[i]===void 0||e[i]===null)continue;let o=e[i];if(Array.isArray(o)){r=r.replace(n,Pr(i,o,{style:s,explode:a}));continue}if(typeof o==="object"){r=r.replace(n,Ar(i,o,{style:s,explode:a}));continue}if(s==="matrix"){r=r.replace(n,`;${Qt(i,o)}`);continue}r=r.replace(n,s==="label"?`.${encodeURIComponent(o)}`:encodeURIComponent(o))}return r}function gi(t,e){if(t instanceof FormData)return t;if(e){if((e.get instanceof Function?e.get("Content-Type")??e.get("content-type"):e["Content-Type"]??e["content-type"])==="application/x-www-form-urlencoded")return new URLSearchParams(t).toString()}return JSON.stringify(t)}function li(t,e){let r=`${e.baseUrl}${t}`;if(e.params?.path)r=ui(r,e.params.path);let n=e.querySerializer(e.params.query??{});if(n.startsWith("?"))n=n.substring(1);if(n)r+=`?${n}`;return r}function Or(...t){let e=new Headers;for(let r of t){if(!r||typeof r!=="object")continue;let n=r instanceof Headers?r.entries():Object.entries(r);for(let[i,a]of n)if(a===null)e.delete(i);else if(Array.isArray(a))for(let s of a)e.append(i,s);else if(a!==void 0)e.set(i,a)}return e}function xr(t){if(t.endsWith("/"))return t.substring(0,t.length-1);return t}class ct extends Error{status;body;url;constructor(t,e,r,n){super(t);this.name="ApiClientError",this.status=e,this.body=r,this.url=n.split("?")[0]}}function d(t,e){if(t.error!==void 0&&t.error!==null){let r=t.response?.status??0,n=t.response?.url??"",i=typeof t.error==="object"&&t.error!==null&&"error"in t.error&&typeof t.error.error==="object"&&t.error.error?.message||`${e} failed (${r})`;throw new ct(String(i),r,t.error,n)}if(t.data===void 0)throw new ct(`${e}: empty response body`,t.response?.status??0,void 0,t.response?.url??"");return t.data}class Wt{client;constructor(t){this.client=t}async startUpload(t,e){let r=await this.client.POST("/api/v1/orgs/{orgId}/uploads",{params:{path:{orgId:t}},body:e});return d(r,"media.startUpload")}async completeUpload(t,e){let r=await this.client.POST("/api/v1/orgs/{orgId}/uploads/{fileId}",{params:{path:{orgId:t,fileId:e}}});return d(r,"media.completeUpload")}async upload(t,e,r=fetch){let n=await this.startUpload(t,{name:e.name,contentType:e.contentType,size:e.data.byteLength}),i=await r(n.uploadUrl,{method:n.method,headers:n.headers,body:e.data});if(!i.ok)throw new ct(`media.upload: storage refused the bytes (${i.status})`,i.status,void 0,n.uploadUrl);return this.completeUpload(t,n.fileId)}}class zt{client;constructor(t){this.client=t}async createProductDraft(t){return d(await this.client.POST("/api/v1/orgs/{orgId}/products/drafts",{params:{path:{orgId:t}}}),"drafts.createProductDraft")}async createEventDraft(t){return d(await this.client.POST("/api/v1/orgs/{orgId}/events/drafts",{params:{path:{orgId:t}}}),"drafts.createEventDraft")}async createBlogDraft(t){return d(await this.client.POST("/api/v1/orgs/{orgId}/blogs/drafts",{params:{path:{orgId:t}}}),"drafts.createBlogDraft")}async getProductForEdit(t,e){return d(await this.client.GET("/api/v1/orgs/{orgId}/products/{productId}/edit",{params:{path:{orgId:t,productId:e}}}),"drafts.getProductForEdit")}async getEventForEdit(t,e){return d(await this.client.GET("/api/v1/orgs/{orgId}/events/{eventId}/edit",{params:{path:{orgId:t,eventId:e}}}),"drafts.getEventForEdit")}async getBlogForEdit(t,e){return d(await this.client.GET("/api/v1/orgs/{orgId}/blogs/{blogId}/edit",{params:{path:{orgId:t,blogId:e}}}),"drafts.getBlogForEdit")}async eventSlugAvailable(t,e,r){return d(await this.client.GET("/api/v1/orgs/{orgId}/events/slug-available",{params:{path:{orgId:t},query:{slug:e,eventId:r}}}),"drafts.eventSlugAvailable")}async getProductDraft(t,e){let r=await this.client.GET("/api/v1/orgs/{orgId}/products/{productId}/draft",{params:{path:{orgId:t,productId:e}}});return d(r,"drafts.getProductDraft")}async stageProductDraft(t,e,r){let n=await this.client.PUT("/api/v1/orgs/{orgId}/products/{productId}/draft",{params:{path:{orgId:t,productId:e}},body:r});return d(n,"drafts.stageProductDraft")}async publishProduct(t,e){let r=await this.client.POST("/api/v1/orgs/{orgId}/products/{productId}/publish",{params:{path:{orgId:t,productId:e}}});return d(r,"drafts.publishProduct")}async discardProductDraft(t,e){let r=await this.client.POST("/api/v1/orgs/{orgId}/products/{productId}/discard-draft",{params:{path:{orgId:t,productId:e}}});return d(r,"drafts.discardProductDraft")}async setProductVisibility(t,e,r){let n=await this.client.PUT("/api/v1/orgs/{orgId}/products/{productId}/visibility",{params:{path:{orgId:t,productId:e}},body:{visibility:r}});return d(n,"drafts.setProductVisibility")}async getEventDraft(t,e){let r=await this.client.GET("/api/v1/orgs/{orgId}/events/{eventId}/draft",{params:{path:{orgId:t,eventId:e}}});return d(r,"drafts.getEventDraft")}async stageEventDraft(t,e,r){let n=await this.client.PUT("/api/v1/orgs/{orgId}/events/{eventId}/draft",{params:{path:{orgId:t,eventId:e}},body:r});return d(n,"drafts.stageEventDraft")}async publishEvent(t,e){let r=await this.client.POST("/api/v1/orgs/{orgId}/events/{eventId}/publish",{params:{path:{orgId:t,eventId:e}}});return d(r,"drafts.publishEvent")}async discardEventDraft(t,e){let r=await this.client.POST("/api/v1/orgs/{orgId}/events/{eventId}/discard-draft",{params:{path:{orgId:t,eventId:e}}});return d(r,"drafts.discardEventDraft")}async setEventVisibility(t,e,r){let n=await this.client.PUT("/api/v1/orgs/{orgId}/events/{eventId}/visibility",{params:{path:{orgId:t,eventId:e}},body:{visibility:r}});return d(n,"drafts.setEventVisibility")}async getBlogDraft(t,e){let r=await this.client.GET("/api/v1/orgs/{orgId}/blogs/{blogId}/draft",{params:{path:{orgId:t,blogId:e}}});return d(r,"drafts.getBlogDraft")}async stageBlogDraft(t,e,r){let n=await this.client.PUT("/api/v1/orgs/{orgId}/blogs/{blogId}/draft",{params:{path:{orgId:t,blogId:e}},body:r});return d(n,"drafts.stageBlogDraft")}async publishBlog(t,e){let r=await this.client.POST("/api/v1/orgs/{orgId}/blogs/{blogId}/publish",{params:{path:{orgId:t,blogId:e}}});return d(r,"drafts.publishBlog")}async discardBlogDraft(t,e){let r=await this.client.POST("/api/v1/orgs/{orgId}/blogs/{blogId}/discard-draft",{params:{path:{orgId:t,blogId:e}}});return d(r,"drafts.discardBlogDraft")}}class Kt{client;constructor(t){this.client=t}async list(t,e={}){let r=await this.client.GET("/api/v1/orgs/{orgId}/coupons",{params:{path:{orgId:t},query:e}});return d(r,"coupons.list")}async create(t,e){let r=await this.client.POST("/api/v1/orgs/{orgId}/coupons",{params:{path:{orgId:t}},body:e});return d(r,"coupons.create")}async get(t,e){let r=await this.client.GET("/api/v1/orgs/{orgId}/coupons/{couponId}",{params:{path:{orgId:t,couponId:e}}});return d(r,"coupons.get")}async update(t,e,r){let n=await this.client.PATCH("/api/v1/orgs/{orgId}/coupons/{couponId}",{params:{path:{orgId:t,couponId:e}},body:r});return d(n,"coupons.update")}async activate(t,e){let r=await this.client.POST("/api/v1/orgs/{orgId}/coupons/{couponId}/activate",{params:{path:{orgId:t,couponId:e}}});return d(r,"coupons.activate")}async deactivate(t,e){let r=await this.client.POST("/api/v1/orgs/{orgId}/coupons/{couponId}/deactivate",{params:{path:{orgId:t,couponId:e}}});return d(r,"coupons.deactivate")}async validate(t,e){let r=await this.client.POST("/api/v1/orgs/{orgId}/coupons/validate",{params:{path:{orgId:t}},body:e});return d(r,"coupons.validate")}}class Xt{client;constructor(t){this.client=t}async get(){let t=await this.client.GET("/api/v1/me",{});return d(t,"me.get")}async update(t){return d(await this.client.PATCH("/api/v1/me",{body:t}),"me.update")}async unread(){return d(await this.client.GET("/api/v1/me/unread",{}),"me.unread")}async teamChat(){return d(await this.client.GET("/api/v1/me/team-chat",{}),"me.teamChat")}}class Zt{client;constructor(t){this.client=t}async get(t){let e=await this.client.GET("/api/v1/orgs/{orgId}",{params:{path:{orgId:t}}});return d(e,"orgs.get")}async getSettings(t){let e=await this.client.GET("/api/v1/orgs/{orgId}/settings",{params:{path:{orgId:t}}});return d(e,"orgs.getSettings")}async update(t,e){let r=await this.client.PATCH("/api/v1/orgs/{orgId}",{params:{path:{orgId:t}},body:e});return d(r,"orgs.update")}async listMembers(t,e={}){let r=await this.client.GET("/api/v1/orgs/{orgId}/members",{params:{path:{orgId:t},query:e}});return d(r,"orgs.listMembers")}async overview(t,e={}){return d(await this.client.GET("/api/v1/orgs/{orgId}/overview",{params:{path:{orgId:t},query:e}}),"orgs.overview")}async summary(t,e={}){return d(await this.client.GET("/api/v1/orgs/{orgId}/summary",{params:{path:{orgId:t},query:e}}),"orgs.summary")}async attention(t){return d(await this.client.GET("/api/v1/orgs/{orgId}/attention",{params:{path:{orgId:t}}}),"orgs.attention")}async addMember(t,e){let r=await this.client.POST("/api/v1/orgs/{orgId}/members",{params:{path:{orgId:t}},body:e});return d(r,"orgs.addMember")}async setMemberRole(t,e,r){let n=await this.client.PATCH("/api/v1/orgs/{orgId}/members/{uid}",{params:{path:{orgId:t,uid:e}},body:{role:r}});return d(n,"orgs.setMemberRole")}async removeMember(t,e){let r=await this.client.DELETE("/api/v1/orgs/{orgId}/members/{uid}",{params:{path:{orgId:t,uid:e}}});return d(r,"orgs.removeMember")}async listInvitations(t){let e=await this.client.GET("/api/v1/orgs/{orgId}/invitations",{params:{path:{orgId:t}}});return d(e,"orgs.listInvitations")}async revokeInvitation(t,e){let r=await this.client.DELETE("/api/v1/orgs/{orgId}/invitations/{invitationId}",{params:{path:{orgId:t,invitationId:e}}});return d(r,"orgs.revokeInvitation")}async resendInvitation(t,e){let r=await this.client.POST("/api/v1/orgs/{orgId}/invitations/{invitationId}/resend",{params:{path:{orgId:t,invitationId:e}}});return d(r,"orgs.resendInvitation")}}class te{client;constructor(t){this.client=t}async list(t,e={}){let r=await this.client.GET("/api/v1/orgs/{orgId}/products",{params:{path:{orgId:t},query:e}});return d(r,"products.list")}async get(t,e,r={}){let n=await this.client.GET("/api/v1/orgs/{orgId}/products/{productId}",{params:{path:{orgId:t,productId:e},query:r}});return d(n,"products.get")}async create(t,e){let r=await this.client.POST("/api/v1/orgs/{orgId}/products",{params:{path:{orgId:t}},body:e});return d(r,"products.create")}async update(t,e,r){let n=await this.client.PUT("/api/v1/orgs/{orgId}/products/{productId}",{params:{path:{orgId:t,productId:e}},body:r});return d(n,"products.update")}async delete(t,e){let r=await this.client.DELETE("/api/v1/orgs/{orgId}/products/{productId}",{params:{path:{orgId:t,productId:e}}});return d(r,"products.delete")}}class ee{client;constructor(t){this.client=t}async list(t,e={}){let r=await this.client.GET("/api/v1/orgs/{orgId}/events",{params:{path:{orgId:t},query:e}});return d(r,"events.list")}async get(t,e){let r=await this.client.GET("/api/v1/orgs/{orgId}/events/{eventId}",{params:{path:{orgId:t,eventId:e}}});return d(r,"events.get")}async create(t,e){let r=await this.client.POST("/api/v1/orgs/{orgId}/events",{params:{path:{orgId:t}},body:e});return d(r,"events.create")}async update(t,e,r){let n=await this.client.PUT("/api/v1/orgs/{orgId}/events/{eventId}",{params:{path:{orgId:t,eventId:e}},body:r});return d(n,"events.update")}async delete(t,e){let r=await this.client.DELETE("/api/v1/orgs/{orgId}/events/{eventId}",{params:{path:{orgId:t,eventId:e}}});return d(r,"events.delete")}}class re{client;constructor(t){this.client=t}async list(t,e={}){let r=await this.client.GET("/api/v1/orgs/{orgId}/rooms",{params:{path:{orgId:t},query:e}});return d(r,"rooms.list")}async get(t,e){let r=await this.client.GET("/api/v1/orgs/{orgId}/rooms/{roomId}",{params:{path:{orgId:t,roomId:e}}});return d(r,"rooms.get")}async create(t,e){let r=await this.client.POST("/api/v1/orgs/{orgId}/rooms",{params:{path:{orgId:t}},body:e});return d(r,"rooms.create")}async update(t,e,r){let n=await this.client.PUT("/api/v1/orgs/{orgId}/rooms/{roomId}",{params:{path:{orgId:t,roomId:e}},body:r});return d(n,"rooms.update")}async delete(t,e){let r=await this.client.DELETE("/api/v1/orgs/{orgId}/rooms/{roomId}",{params:{path:{orgId:t,roomId:e}}});return d(r,"rooms.delete")}}class se{client;constructor(t){this.client=t}async list(t,e={}){let r=await this.client.GET("/api/v1/orgs/{orgId}/bookings",{params:{path:{orgId:t},query:e}});return d(r,"bookings.list")}async get(t,e){let r=await this.client.GET("/api/v1/orgs/{orgId}/bookings/{bookingId}",{params:{path:{orgId:t,bookingId:e}}});return d(r,"bookings.get")}async create(t,e){let r=await this.client.POST("/api/v1/orgs/{orgId}/bookings",{params:{path:{orgId:t}},body:e});return d(r,"bookings.create")}async update(t,e,r){let n=await this.client.PUT("/api/v1/orgs/{orgId}/bookings/{bookingId}",{params:{path:{orgId:t,bookingId:e}},body:r});return d(n,"bookings.update")}async delete(t,e){let r=await this.client.DELETE("/api/v1/orgs/{orgId}/bookings/{bookingId}",{params:{path:{orgId:t,bookingId:e}}});return d(r,"bookings.delete")}async slots(t,e){let r=await this.client.GET("/api/v1/orgs/{orgId}/bookings/slots",{params:{path:{orgId:t},query:e}});return d(r,"bookings.slots")}async listUnavailability(t,e={}){let r=await this.client.GET("/api/v1/orgs/{orgId}/bookings/unavailability",{params:{path:{orgId:t},query:e}});return d(r,"bookings.listUnavailability")}async addUnavailability(t,e){let r=await this.client.POST("/api/v1/orgs/{orgId}/bookings/unavailability",{params:{path:{orgId:t}},body:e});return d(r,"bookings.addUnavailability")}async removeUnavailability(t,e){let r=await this.client.DELETE("/api/v1/orgs/{orgId}/bookings/unavailability/{unavailabilityId}",{params:{path:{orgId:t,unavailabilityId:e}}});return d(r,"bookings.removeUnavailability")}async getMemberHours(t,e){let r=await this.client.GET("/api/v1/orgs/{orgId}/bookings/member-hours/{uid}",{params:{path:{orgId:t,uid:e}}});return d(r,"bookings.getMemberHours")}async setMemberHours(t,e,r){let n=await this.client.PUT("/api/v1/orgs/{orgId}/bookings/member-hours/{uid}",{params:{path:{orgId:t,uid:e}},body:r});return d(n,"bookings.setMemberHours")}}class ne{client;constructor(t){this.client=t}async list(t,e={}){let r=await this.client.GET("/api/v1/orgs/{orgId}/projects",{params:{path:{orgId:t},query:e}});return d(r,"projects.list")}async get(t,e){let r=await this.client.GET("/api/v1/orgs/{orgId}/projects/{projectId}",{params:{path:{orgId:t,projectId:e}}});return d(r,"projects.get")}async create(t,e){let r=await this.client.POST("/api/v1/orgs/{orgId}/projects",{params:{path:{orgId:t}},body:e});return d(r,"projects.create")}async update(t,e,r){let n=await this.client.PUT("/api/v1/orgs/{orgId}/projects/{projectId}",{params:{path:{orgId:t,projectId:e}},body:r});return d(n,"projects.update")}async delete(t,e){let r=await this.client.DELETE("/api/v1/orgs/{orgId}/projects/{projectId}",{params:{path:{orgId:t,projectId:e}}});return d(r,"projects.delete")}async listCards(t,e,r={}){let n=await this.client.GET("/api/v1/orgs/{orgId}/projects/{projectId}/cards",{params:{path:{orgId:t,projectId:e},query:r}});return d(n,"projects.listCards")}async getCard(t,e,r){let n=await this.client.GET("/api/v1/orgs/{orgId}/projects/{projectId}/cards/{cardId}",{params:{path:{orgId:t,projectId:e,cardId:r}}});return d(n,"projects.getCard")}async createCard(t,e,r){let n=await this.client.POST("/api/v1/orgs/{orgId}/projects/{projectId}/cards",{params:{path:{orgId:t,projectId:e}},body:r});return d(n,"projects.createCard")}async updateCard(t,e,r,n){let i=await this.client.PUT("/api/v1/orgs/{orgId}/projects/{projectId}/cards/{cardId}",{params:{path:{orgId:t,projectId:e,cardId:r}},body:n});return d(i,"projects.updateCard")}async moveCard(t,e,r,n){let i=await this.client.POST("/api/v1/orgs/{orgId}/projects/{projectId}/cards/{cardId}/move",{params:{path:{orgId:t,projectId:e,cardId:r}},body:n});return d(i,"projects.moveCard")}async deleteCard(t,e,r){let n=await this.client.DELETE("/api/v1/orgs/{orgId}/projects/{projectId}/cards/{cardId}",{params:{path:{orgId:t,projectId:e,cardId:r}}});return d(n,"projects.deleteCard")}async listCardComments(t,e,r,n={}){let i=await this.client.GET("/api/v1/orgs/{orgId}/projects/{projectId}/cards/{cardId}/comments",{params:{path:{orgId:t,projectId:e,cardId:r},query:n}});return d(i,"projects.listCardComments")}async createCardComment(t,e,r,n){let i=await this.client.POST("/api/v1/orgs/{orgId}/projects/{projectId}/cards/{cardId}/comments",{params:{path:{orgId:t,projectId:e,cardId:r}},body:n});return d(i,"projects.createCardComment")}async updateCardComment(t,e,r,n,i){let a=await this.client.PATCH("/api/v1/orgs/{orgId}/projects/{projectId}/cards/{cardId}/comments/{commentId}",{params:{path:{orgId:t,projectId:e,cardId:r,commentId:n}},body:i});return d(a,"projects.updateCardComment")}async deleteCardComment(t,e,r,n){let i=await this.client.DELETE("/api/v1/orgs/{orgId}/projects/{projectId}/cards/{cardId}/comments/{commentId}",{params:{path:{orgId:t,projectId:e,cardId:r,commentId:n}}});return d(i,"projects.deleteCardComment")}async listCardLinks(t,e,r,n={}){let i=await this.client.GET("/api/v1/orgs/{orgId}/projects/{projectId}/cards/{cardId}/links",{params:{path:{orgId:t,projectId:e,cardId:r},query:n}});return d(i,"projects.listCardLinks")}async getCardWatch(t,e,r){let n=await this.client.GET("/api/v1/orgs/{orgId}/projects/{projectId}/cards/{cardId}/watch",{params:{path:{orgId:t,projectId:e,cardId:r}}});return d(n,"projects.getCardWatch")}async watchCard(t,e,r){let n=await this.client.PUT("/api/v1/orgs/{orgId}/projects/{projectId}/cards/{cardId}/watch",{params:{path:{orgId:t,projectId:e,cardId:r}}});return d(n,"projects.watchCard")}async unwatchCard(t,e,r){let n=await this.client.DELETE("/api/v1/orgs/{orgId}/projects/{projectId}/cards/{cardId}/watch",{params:{path:{orgId:t,projectId:e,cardId:r}}});return d(n,"projects.unwatchCard")}}class oe{client;constructor(t){this.client=t}async list(t,e={}){let r=await this.client.GET("/api/v1/orgs/{orgId}/blogs",{params:{path:{orgId:t},query:e}});return d(r,"blogs.list")}async get(t,e){let r=await this.client.GET("/api/v1/orgs/{orgId}/blogs/{blogId}",{params:{path:{orgId:t,blogId:e}}});return d(r,"blogs.get")}async create(t,e){let r=await this.client.POST("/api/v1/orgs/{orgId}/blogs",{params:{path:{orgId:t}},body:e});return d(r,"blogs.create")}async update(t,e,r){let n=await this.client.PUT("/api/v1/orgs/{orgId}/blogs/{blogId}",{params:{path:{orgId:t,blogId:e}},body:r});return d(n,"blogs.update")}async delete(t,e){let r=await this.client.DELETE("/api/v1/orgs/{orgId}/blogs/{blogId}",{params:{path:{orgId:t,blogId:e}}});return d(r,"blogs.delete")}}class ie{client;constructor(t){this.client=t}async list(t,e={}){let r=await this.client.GET("/api/v1/orgs/{orgId}/booking-types",{params:{path:{orgId:t},query:e}});return d(r,"bookingTypes.list")}async get(t,e){let r=await this.client.GET("/api/v1/orgs/{orgId}/booking-types/{bookingTypeId}",{params:{path:{orgId:t,bookingTypeId:e}}});return d(r,"bookingTypes.get")}async create(t,e){let r=await this.client.POST("/api/v1/orgs/{orgId}/booking-types",{params:{path:{orgId:t}},body:e});return d(r,"bookingTypes.create")}async update(t,e,r){let n=await this.client.PUT("/api/v1/orgs/{orgId}/booking-types/{bookingTypeId}",{params:{path:{orgId:t,bookingTypeId:e}},body:r});return d(n,"bookingTypes.update")}async delete(t,e){let r=await this.client.DELETE("/api/v1/orgs/{orgId}/booking-types/{bookingTypeId}",{params:{path:{orgId:t,bookingTypeId:e}}});return d(r,"bookingTypes.delete")}}class ae{client;constructor(t){this.client=t}async list(t,e={}){let r=await this.client.GET("/api/v1/orgs/{orgId}/orders",{params:{path:{orgId:t},query:e}});return d(r,"orders.list")}async listLineItems(t,e={}){let r=await this.client.GET("/api/v1/orgs/{orgId}/line-items",{params:{path:{orgId:t},query:e}});return d(r,"orders.listLineItems")}async get(t,e){let r=await this.client.GET("/api/v1/orgs/{orgId}/orders/{orderId}",{params:{path:{orgId:t,orderId:e}}});return d(r,"orders.get")}async updateLineItemShipping(t,e,r,n){let i=await this.client.PATCH("/api/v1/orgs/{orgId}/orders/{orderId}/line-items/{lineItemId}",{params:{path:{orgId:t,orderId:e,lineItemId:r}},body:n});return d(i,"orders.updateLineItemShipping")}async listLineItemComments(t,e,r){let n=await this.client.GET("/api/v1/orgs/{orgId}/orders/{orderId}/line-items/{lineItemId}/comments",{params:{path:{orgId:t,orderId:e,lineItemId:r}}});return d(n,"orders.listLineItemComments")}async commentLineItem(t,e,r,n){let i=await this.client.POST("/api/v1/orgs/{orgId}/orders/{orderId}/line-items/{lineItemId}/comments",{params:{path:{orgId:t,orderId:e,lineItemId:r}},body:n});return d(i,"orders.commentLineItem")}async breakdown(t,e){let r=await this.client.POST("/api/v1/orgs/{orgId}/orders/breakdown",{params:{path:{orgId:t}},body:e});return d(r,"orders.breakdown")}}class ce{client;constructor(t){this.client=t}async list(t,e={}){let r=await this.client.GET("/api/v1/orgs/{orgId}/quotes",{params:{path:{orgId:t},query:e}});return d(r,"quotes.list")}async get(t,e){let r=await this.client.GET("/api/v1/orgs/{orgId}/quotes/{quoteId}",{params:{path:{orgId:t,quoteId:e}}});return d(r,"quotes.get")}async create(t,e){let r=await this.client.POST("/api/v1/orgs/{orgId}/quotes",{params:{path:{orgId:t}},body:e});return d(r,"quotes.create")}async update(t,e,r){let n=await this.client.PUT("/api/v1/orgs/{orgId}/quotes/{quoteId}",{params:{path:{orgId:t,quoteId:e}},body:r});return d(n,"quotes.update")}async delete(t,e){let r=await this.client.DELETE("/api/v1/orgs/{orgId}/quotes/{quoteId}",{params:{path:{orgId:t,quoteId:e}}});return d(r,"quotes.delete")}}class de{client;constructor(t){this.client=t}async summary(t,e={}){let r=await this.client.GET("/api/v1/orgs/{orgId}/analytics/summary",{params:{path:{orgId:t},query:e}});return d(r,"analytics.summary")}async overview(t,e={}){let r=await this.client.GET("/api/v1/orgs/{orgId}/analytics/overview",{params:{path:{orgId:t},query:e}});return d(r,"analytics.overview")}async visits(t,e={}){let r=await this.client.GET("/api/v1/orgs/{orgId}/analytics/visits",{params:{path:{orgId:t},query:e}});return d(r,"analytics.visits")}async topProducts(t,e={}){let r=await this.client.GET("/api/v1/orgs/{orgId}/analytics/products/top",{params:{path:{orgId:t},query:e}});return d(r,"analytics.topProducts")}}class ue{client;constructor(t){this.client=t}async list(t){let e=await this.client.GET("/api/v1/orgs/{orgId}/collections",{params:{path:{orgId:t}}});return d(e,"collections.list")}async get(t,e){let r=await this.client.GET("/api/v1/orgs/{orgId}/collections/{collectionId}",{params:{path:{orgId:t,collectionId:e}}});return d(r,"collections.get")}async create(t,e){let r=await this.client.POST("/api/v1/orgs/{orgId}/collections",{params:{path:{orgId:t}},body:e});return d(r,"collections.create")}async update(t,e,r){let n=await this.client.PUT("/api/v1/orgs/{orgId}/collections/{collectionId}",{params:{path:{orgId:t,collectionId:e}},body:r});return d(n,"collections.update")}async delete(t,e){let r=await this.client.DELETE("/api/v1/orgs/{orgId}/collections/{collectionId}",{params:{path:{orgId:t,collectionId:e}}});return d(r,"collections.delete")}}class ge{client;constructor(t){this.client=t}async list(t,e={}){let r=await this.client.GET("/api/v1/orgs/{orgId}/agents",{params:{path:{orgId:t},query:e}});return d(r,"agents.list")}async get(t,e){let r=await this.client.GET("/api/v1/orgs/{orgId}/agents/{agentId}",{params:{path:{orgId:t,agentId:e}}});return d(r,"agents.get")}async update(t,e,r){let n=await this.client.PATCH("/api/v1/orgs/{orgId}/agents/{agentId}",{params:{path:{orgId:t,agentId:e}},body:r});return d(n,"agents.update")}async run(t,e){let r=await this.client.POST("/api/v1/orgs/{orgId}/agents/{agentId}/run",{params:{path:{orgId:t,agentId:e}}});return d(r,"agents.run")}async listRuns(t,e={}){let r=await this.client.GET("/api/v1/orgs/{orgId}/agents/runs",{params:{path:{orgId:t},query:e}});return d(r,"agents.listRuns")}async getRun(t,e){let r=await this.client.GET("/api/v1/orgs/{orgId}/agents/runs/{runId}",{params:{path:{orgId:t,runId:e}}});return d(r,"agents.getRun")}async cancelRun(t,e){let r=await this.client.POST("/api/v1/orgs/{orgId}/agents/runs/{runId}/cancel",{params:{path:{orgId:t,runId:e}}});return d(r,"agents.cancelRun")}async listProposals(t,e={}){let r=await this.client.GET("/api/v1/orgs/{orgId}/agents/proposals",{params:{path:{orgId:t},query:e}});return d(r,"agents.listProposals")}async approveProposal(t,e,r={}){let n=await this.client.POST("/api/v1/orgs/{orgId}/agents/proposals/{proposalId}/approve",{params:{path:{orgId:t,proposalId:e}},body:r});return d(n,"agents.approveProposal")}async rejectProposal(t,e){let r=await this.client.POST("/api/v1/orgs/{orgId}/agents/proposals/{proposalId}/reject",{params:{path:{orgId:t,proposalId:e}}});return d(r,"agents.rejectProposal")}}class le{client;constructor(t){this.client=t}async list(t,e={}){let r=await this.client.GET("/api/v1/orgs/{orgId}/conversations",{params:{path:{orgId:t},query:e}});return d(r,"conversations.list")}async get(t,e,r={}){let n=await this.client.GET("/api/v1/orgs/{orgId}/conversations/{conversationId}",{params:{path:{orgId:t,conversationId:e},query:r}});return d(n,"conversations.get")}}class pe{client;constructor(t){this.client=t}async get(t){let e=await this.client.GET("/api/v1/orgs/{orgId}/customer-agent",{params:{path:{orgId:t}}});return d(e,"customerAgent.get")}async listKnowledge(t){let e=await this.client.GET("/api/v1/orgs/{orgId}/customer-agent/knowledge",{params:{path:{orgId:t}}});return d(e,"customerAgent.listKnowledge")}}class me{client;constructor(t){this.client=t}async list(t,e={}){let r=await this.client.GET("/api/v1/orgs/{orgId}/posts",{params:{path:{orgId:t},query:e}});return d(r,"posts.list")}async get(t,e){let r=await this.client.GET("/api/v1/orgs/{orgId}/posts/{postId}",{params:{path:{orgId:t,postId:e}}});return d(r,"posts.get")}async createDraft(t,e){let r=await this.client.POST("/api/v1/orgs/{orgId}/posts",{params:{path:{orgId:t}},body:e});return d(r,"posts.createDraft")}async requestVideoUpload(t,e,r){let n=await this.client.POST("/api/v1/orgs/{orgId}/posts/{postId}/video",{params:{path:{orgId:t,postId:e}},body:{bytes:r}});return d(n,"posts.requestVideoUpload")}async finalizeVideo(t,e){let r=await this.client.POST("/api/v1/orgs/{orgId}/posts/{postId}/video/finalize",{params:{path:{orgId:t,postId:e}}});return d(r,"posts.finalizeVideo")}async videoPreview(t,e){let r=await this.client.GET("/api/v1/orgs/{orgId}/posts/{postId}/video/preview",{params:{path:{orgId:t,postId:e}}});return d(r,"posts.videoPreview")}async publish(t,e){let r=await this.client.POST("/api/v1/orgs/{orgId}/posts/{postId}/publish",{params:{path:{orgId:t,postId:e}}});return d(r,"posts.publish")}}class fe{client;constructor(t){this.client=t}async list(t={}){return d(await this.client.GET("/api/v1/notifications",{params:{query:t}}),"notifications.list")}async markRead(t){return d(await this.client.POST("/api/v1/notifications/read",{body:t}),"notifications.markRead")}}class ye{client;constructor(t){this.client=t}async latest(){return d(await this.client.GET("/api/v1/desk/latest",{}),"desk.latest")}async downloadUrl(t){let{response:e}=await this.client.GET("/api/v1/desk/download",{params:{query:{os:t}},parseAs:"stream",redirect:"manual"}),r=e.headers.get("Location");if(r)return new URL(r,e.url||"https://vcity.io").toString();if(e.ok&&e.url)return e.url;throw new ct(`desk.downloadUrl failed (${e.status})`,e.status,void 0,e.url)}}class he{client;constructor(t){this.client=t}async listTickets(t,e={}){return d(await this.client.GET("/api/v1/orgs/{orgId}/support/tickets",{params:{path:{orgId:t},query:e}}),"support.listTickets")}async getTicket(t,e){return d(await this.client.GET("/api/v1/orgs/{orgId}/support/tickets/{ticketId}",{params:{path:{orgId:t,ticketId:e}}}),"support.getTicket")}async updateTicket(t,e,r){return d(await this.client.PATCH("/api/v1/orgs/{orgId}/support/tickets/{ticketId}",{params:{path:{orgId:t,ticketId:e}},body:r}),"support.updateTicket")}async stats(t){return d(await this.client.GET("/api/v1/orgs/{orgId}/support/stats",{params:{path:{orgId:t}}}),"support.stats")}}class we{client;constructor(t){this.client=t}async list(t,e={}){return d(await this.client.GET("/api/v1/orgs/{orgId}/api-keys",{params:{path:{orgId:t},query:e}}),"apiKeys.list")}async create(t,e){return d(await this.client.POST("/api/v1/orgs/{orgId}/api-keys",{params:{path:{orgId:t}},body:e}),"apiKeys.create")}async revoke(t,e){return d(await this.client.DELETE("/api/v1/orgs/{orgId}/api-keys/{keyId}",{params:{path:{orgId:t,keyId:e}}}),"apiKeys.revoke")}async rotate(t,e){return d(await this.client.POST("/api/v1/orgs/{orgId}/api-keys/{keyId}/rotate",{params:{path:{orgId:t,keyId:e}}}),"apiKeys.rotate")}}class ve{client;constructor(t){this.client=t}async list(t,e={}){let r=await this.client.GET("/api/v1/orgs/{orgId}/campaigns",{params:{path:{orgId:t},query:e}});return d(r,"campaigns.list")}async create(t,e){let r=await this.client.POST("/api/v1/orgs/{orgId}/campaigns",{params:{path:{orgId:t}},body:e});return d(r,"campaigns.create")}async get(t,e){let r=await this.client.GET("/api/v1/orgs/{orgId}/campaigns/{campaignId}",{params:{path:{orgId:t,campaignId:e}}});return d(r,"campaigns.get")}async update(t,e,r){let n=await this.client.PATCH("/api/v1/orgs/{orgId}/campaigns/{campaignId}",{params:{path:{orgId:t,campaignId:e}},body:r});return d(n,"campaigns.update")}async delete(t,e){let r=await this.client.DELETE("/api/v1/orgs/{orgId}/campaigns/{campaignId}",{params:{path:{orgId:t,campaignId:e}}});return d(r,"campaigns.delete")}async activate(t,e){let r=await this.client.POST("/api/v1/orgs/{orgId}/campaigns/{campaignId}/activate",{params:{path:{orgId:t,campaignId:e}}});return d(r,"campaigns.activate")}async pause(t,e){let r=await this.client.POST("/api/v1/orgs/{orgId}/campaigns/{campaignId}/pause",{params:{path:{orgId:t,campaignId:e}}});return d(r,"campaigns.pause")}async stats(t,e){let r=await this.client.GET("/api/v1/orgs/{orgId}/campaigns/{campaignId}/stats",{params:{path:{orgId:t,campaignId:e}}});return d(r,"campaigns.stats")}async listContacts(t,e,r={}){let n=await this.client.GET("/api/v1/orgs/{orgId}/campaigns/{campaignId}/contacts",{params:{path:{orgId:t,campaignId:e},query:r}});return d(n,"campaigns.listContacts")}async addContacts(t,e,r){let n=await this.client.POST("/api/v1/orgs/{orgId}/campaigns/{campaignId}/contacts",{params:{path:{orgId:t,campaignId:e}},body:r});return d(n,"campaigns.addContacts")}async removeContact(t,e,r){let n=await this.client.DELETE("/api/v1/orgs/{orgId}/campaigns/{campaignId}/contacts/{contactId}",{params:{path:{orgId:t,campaignId:e,contactId:r}}});return d(n,"campaigns.removeContact")}}class be{client;constructor(t){this.client=t}async list(t){return d(await this.client.GET("/api/v1/comments",{params:{query:t}}),"comments.list")}async create(t){return d(await this.client.POST("/api/v1/comments",{body:t}),"comments.create")}async edit(t,e){return d(await this.client.PATCH("/api/v1/comments/{commentId}",{params:{path:{commentId:t}},body:{content:e}}),"comments.edit")}async delete(t){return d(await this.client.DELETE("/api/v1/comments/{commentId}",{params:{path:{commentId:t}}}),"comments.delete")}async pin(t){return d(await this.client.PUT("/api/v1/comments/{commentId}/pin",{params:{path:{commentId:t}}}),"comments.pin")}async unpin(t){return d(await this.client.DELETE("/api/v1/comments/{commentId}/pin",{params:{path:{commentId:t}}}),"comments.unpin")}async reactions(t){return d(await this.client.GET("/api/v1/reactions",{params:{query:{target:t}}}),"comments.reactions")}async react(t){return d(await this.client.PUT("/api/v1/reactions",{body:t}),"comments.react")}}class ke{client;constructor(t){this.client=t}async getConfig(t){return d(await this.client.GET("/api/v1/orgs/{orgId}/newsletter",{params:{path:{orgId:t}}}),"newsletter.getConfig")}async saveSettings(t,e){return d(await this.client.PUT("/api/v1/orgs/{orgId}/newsletter",{params:{path:{orgId:t}},body:e}),"newsletter.saveSettings")}async publicConfig(t){return d(await this.client.GET("/api/v1/orgs/{orgId}/newsletter/public-config",{params:{path:{orgId:t}}}),"newsletter.publicConfig")}async subscribers(t,e={}){return d(await this.client.GET("/api/v1/orgs/{orgId}/newsletter/subscribers",{params:{path:{orgId:t},query:e}}),"newsletter.subscribers")}async stats(t,e={}){return d(await this.client.GET("/api/v1/orgs/{orgId}/newsletter/stats",{params:{path:{orgId:t},query:e}}),"newsletter.stats")}}class Ie{client;constructor(t){this.client=t}async list(t,e={}){return d(await this.client.GET("/api/v1/orgs/{orgId}/surveys",{params:{path:{orgId:t},query:e}}),"surveys.list")}async get(t,e){return d(await this.client.GET("/api/v1/orgs/{orgId}/surveys/{surveyId}",{params:{path:{orgId:t,surveyId:e}}}),"surveys.get")}async create(t,e){return d(await this.client.POST("/api/v1/orgs/{orgId}/surveys",{params:{path:{orgId:t}},body:e}),"surveys.create")}async update(t,e,r){return d(await this.client.PATCH("/api/v1/orgs/{orgId}/surveys/{surveyId}",{params:{path:{orgId:t,surveyId:e}},body:r}),"surveys.update")}async delete(t,e){return d(await this.client.DELETE("/api/v1/orgs/{orgId}/surveys/{surveyId}",{params:{path:{orgId:t,surveyId:e}}}),"surveys.delete")}async publish(t,e){return d(await this.client.POST("/api/v1/orgs/{orgId}/surveys/{surveyId}/publish",{params:{path:{orgId:t,surveyId:e}}}),"surveys.publish")}async close(t,e){return d(await this.client.POST("/api/v1/orgs/{orgId}/surveys/{surveyId}/close",{params:{path:{orgId:t,surveyId:e}}}),"surveys.close")}async responses(t,e,r={}){return d(await this.client.GET("/api/v1/orgs/{orgId}/surveys/{surveyId}/responses",{params:{path:{orgId:t,surveyId:e},query:r}}),"surveys.responses")}}class je{client;constructor(t){this.client=t}async get(t){return d(await this.client.GET("/api/v1/orgs/{orgId}/storefront",{params:{path:{orgId:t}}}),"storefront.get")}async update(t,e){return d(await this.client.PATCH("/api/v1/orgs/{orgId}/storefront",{params:{path:{orgId:t}},body:e}),"storefront.update")}async setDomain(t,e){return d(await this.client.PUT("/api/v1/orgs/{orgId}/storefront/domain",{params:{path:{orgId:t}},body:{domain:e}}),"storefront.setDomain")}async removeDomain(t){return d(await this.client.DELETE("/api/v1/orgs/{orgId}/storefront/domain",{params:{path:{orgId:t}}}),"storefront.removeDomain")}async verifyDomain(t){return d(await this.client.POST("/api/v1/orgs/{orgId}/storefront/domain/verify",{params:{path:{orgId:t}}}),"storefront.verifyDomain")}async redirects(t){return d(await this.client.GET("/api/v1/orgs/{orgId}/storefront/redirects",{params:{path:{orgId:t}}}),"storefront.redirects")}async setRedirects(t,e){return d(await this.client.PUT("/api/v1/orgs/{orgId}/storefront/redirects",{params:{path:{orgId:t}},body:{redirects:e}}),"storefront.setRedirects")}async previewShopifyRedirects(t,e){return d(await this.client.POST("/api/v1/orgs/{orgId}/storefront/redirects/shopify-preview",{params:{path:{orgId:t}},body:{csv:e}}),"storefront.previewShopifyRedirects")}}class Te{client;constructor(t){this.client=t}async summary(t){return d(await this.client.GET("/api/v1/orgs/{orgId}/billing",{params:{path:{orgId:t}}}),"billing.summary")}async invoices(t,e={}){return d(await this.client.GET("/api/v1/orgs/{orgId}/billing/invoices",{params:{path:{orgId:t},query:e}}),"billing.invoices")}async usage(t){return d(await this.client.GET("/api/v1/orgs/{orgId}/billing/usage",{params:{path:{orgId:t}}}),"billing.usage")}async credits(t,e={}){return d(await this.client.GET("/api/v1/orgs/{orgId}/billing/credits",{params:{path:{orgId:t},query:e}}),"billing.credits")}}class Ee{client;constructor(t){this.client=t}async store(t){return d(await this.client.GET("/api/v1/public/stores/{storeId}",{params:{path:{storeId:t}}}),"public.store")}async rooms(t){return d(await this.client.GET("/api/v1/public/stores/{storeId}/rooms",{params:{path:{storeId:t}}}),"public.rooms")}async blogs(t,e={}){return d(await this.client.GET("/api/v1/public/stores/{storeId}/blogs",{params:{path:{storeId:t},query:e}}),"public.blogs")}async newsletter(t){return d(await this.client.GET("/api/v1/public/stores/{storeId}/newsletter",{params:{path:{storeId:t}}}),"public.newsletter")}async radioStations(){return d(await this.client.GET("/api/v1/public/radio-stations",{}),"public.radioStations")}async storeRadioStations(t){return d(await this.client.GET("/api/v1/orgs/{orgId}/radio-stations",{params:{path:{orgId:t}}}),"public.storeRadioStations")}}class Re{client;constructor(t){this.client=t}async get(t){return d(await this.client.GET("/api/v1/me/chat/rooms/{roomId}",{params:{path:{roomId:t}}}),"chatRooms.get")}async messages(t,e={}){return d(await this.client.GET("/api/v1/me/chat/rooms/{roomId}/messages",{params:{path:{roomId:t},query:e}}),"chatRooms.messages")}async send(t,e){return d(await this.client.POST("/api/v1/me/chat/rooms/{roomId}/messages",{params:{path:{roomId:t}},body:e}),"chatRooms.send")}async edit(t,e,r){return d(await this.client.PATCH("/api/v1/me/chat/rooms/{roomId}/messages/{messageId}",{params:{path:{roomId:t,messageId:e}},body:{content:r}}),"chatRooms.edit")}async delete(t,e){return d(await this.client.DELETE("/api/v1/me/chat/rooms/{roomId}/messages/{messageId}",{params:{path:{roomId:t,messageId:e}}}),"chatRooms.delete")}async reactions(t,e){return d(await this.client.GET("/api/v1/me/chat/rooms/{roomId}/messages/{messageId}/reactions",{params:{path:{roomId:t,messageId:e}}}),"chatRooms.reactions")}async react(t,e,r,n="add"){return d(await this.client.PUT("/api/v1/me/chat/rooms/{roomId}/messages/{messageId}/reactions",{params:{path:{roomId:t,messageId:e}},body:{emoji:r,action:n}}),"chatRooms.react")}async markRead(t){return d(await this.client.POST("/api/v1/me/chat/rooms/{roomId}/read",{params:{path:{roomId:t}}}),"chatRooms.markRead")}async search(t,e){return d(await this.client.GET("/api/v1/me/chat/rooms/{roomId}/search",{params:{path:{roomId:t},query:{q:e}}}),"chatRooms.search")}async list(t){let e=t?.length?{kind:t.join(",")}:{};return d(await this.client.GET("/api/v1/me/chat/rooms",{params:{query:e}}),"chatRooms.list")}async polls(t,e){return d(await this.client.GET("/api/v1/me/chat/rooms/{roomId}/polls",{params:{path:{roomId:t},query:{messageIds:e.join(",")}}}),"chatRooms.polls")}async createPoll(t,e){return d(await this.client.POST("/api/v1/me/chat/rooms/{roomId}/polls",{params:{path:{roomId:t}},body:e}),"chatRooms.createPoll")}async vote(t,e,r){return d(await this.client.POST("/api/v1/me/chat/rooms/{roomId}/polls/{messageId}",{params:{path:{roomId:t,messageId:e}},body:{optionId:r}}),"chatRooms.vote")}async linkPreview(t){return d(await this.client.GET("/api/v1/link-preview",{params:{query:{url:t}}}),"chatRooms.linkPreview")}}class Ce{client;constructor(t){this.client=t}async list(t){return d(await this.client.GET("/api/v1/orgs/{orgId}/configurators",{params:{path:{orgId:t}}}),"configurators.list")}async seeds(t){return d(await this.client.GET("/api/v1/orgs/{orgId}/configurators/seeds",{params:{path:{orgId:t}}}),"configurators.seeds")}async create(t,e){return d(await this.client.POST("/api/v1/orgs/{orgId}/configurators",{params:{path:{orgId:t}},body:e}),"configurators.create")}async get(t,e){return d(await this.client.GET("/api/v1/orgs/{orgId}/configurators/{configuratorId}",{params:{path:{orgId:t,configuratorId:e}}}),"configurators.get")}async update(t,e,r){return d(await this.client.PATCH("/api/v1/orgs/{orgId}/configurators/{configuratorId}",{params:{path:{orgId:t,configuratorId:e}},body:r}),"configurators.update")}async delete(t,e){return d(await this.client.DELETE("/api/v1/orgs/{orgId}/configurators/{configuratorId}",{params:{path:{orgId:t,configuratorId:e}}}),"configurators.delete")}}class Se{client;constructor(t){this.client=t}async activeSession(t){return d(await this.client.GET("/api/v1/orgs/{orgId}/pos/session",{params:{path:{orgId:t}}}),"pos.activeSession")}async openSession(t,e){return d(await this.client.POST("/api/v1/orgs/{orgId}/pos/sessions",{params:{path:{orgId:t}},body:e}),"pos.openSession")}async closeSession(t,e,r){return d(await this.client.POST("/api/v1/orgs/{orgId}/pos/sessions/{sessionId}/close",{params:{path:{orgId:t,sessionId:e}},body:r}),"pos.closeSession")}async sessionSummary(t,e){return d(await this.client.GET("/api/v1/orgs/{orgId}/pos/sessions/{sessionId}/summary",{params:{path:{orgId:t,sessionId:e}}}),"pos.sessionSummary")}async sales(t,e={}){return d(await this.client.GET("/api/v1/orgs/{orgId}/pos/sales",{params:{path:{orgId:t},query:e}}),"pos.sales")}async createSale(t,e,r){return d(await this.client.POST("/api/v1/orgs/{orgId}/pos/sales",{params:{path:{orgId:t}},body:e,...r?{headers:{"Idempotency-Key":r}}:{}}),"pos.createSale")}async sale(t,e){return d(await this.client.GET("/api/v1/orgs/{orgId}/pos/sales/{saleId}",{params:{path:{orgId:t,saleId:e}}}),"pos.sale")}async favorites(t){return d(await this.client.GET("/api/v1/orgs/{orgId}/pos/favorites",{params:{path:{orgId:t}}}),"pos.favorites")}async setFavorites(t,e){return d(await this.client.PUT("/api/v1/orgs/{orgId}/pos/favorites",{params:{path:{orgId:t}},body:{productIds:e}}),"pos.setFavorites")}}class Oe{client;constructor(t){this.client=t}async connections(t){return d(await this.client.GET("/api/v1/orgs/{orgId}/dropshipping/connections",{params:{path:{orgId:t}}}),"dropshipping.connections")}async products(t,e={}){return d(await this.client.GET("/api/v1/orgs/{orgId}/dropshipping/products",{params:{path:{orgId:t},query:e}}),"dropshipping.products")}async import(t,e){return d(await this.client.POST("/api/v1/orgs/{orgId}/dropshipping/imports",{params:{path:{orgId:t}},body:e}),"dropshipping.import")}async fulfillments(t,e){return d(await this.client.GET("/api/v1/orgs/{orgId}/dropshipping/fulfillments",{params:{path:{orgId:t},query:{orderId:e}}}),"dropshipping.fulfillments")}async retryFulfillment(t,e){return d(await this.client.POST("/api/v1/orgs/{orgId}/dropshipping/fulfillments/{fulfillmentId}/retry",{params:{path:{orgId:t,fulfillmentId:e}}}),"dropshipping.retryFulfillment")}}class xe{client;constructor(t){this.client=t}async openConversation(t,e={}){return d(await this.client.POST("/api/v1/orgs/{orgId}/assistant/conversations",{params:{path:{orgId:t}},body:e}),"assistant.openConversation")}async*turn(t,e,r){let n=await this.client.POST("/api/v1/orgs/{orgId}/assistant/conversations/{conversationId}/turns",{params:{path:{orgId:t,conversationId:e}},body:r,parseAs:"stream"}),i=d(n,"assistant.turn");if(!i)return;let a=i.getReader(),s=new TextDecoder,o="";for(;;){let{value:c,done:u}=await a.read();if(u)break;o+=s.decode(c,{stream:!0});let l=o.indexOf(`
|
|
3
|
+
|
|
4
|
+
`);while(l>=0){let w=o.slice(0,l).split(`
|
|
5
|
+
`).filter((v)=>v.startsWith("data:")).map((v)=>v.slice(5).trimStart()).join(`
|
|
6
|
+
`);if(o=o.slice(l+2),w)yield JSON.parse(w);l=o.indexOf(`
|
|
7
|
+
|
|
8
|
+
`)}}}async listProposals(t,e){return d(await this.client.GET("/api/v1/orgs/{orgId}/assistant/proposals",{params:{path:{orgId:t},query:e}}),"assistant.listProposals")}async approve(t,e,r={}){return d(await this.client.POST("/api/v1/orgs/{orgId}/assistant/proposals/{proposalId}/approve",{params:{path:{orgId:t,proposalId:e}},body:r}),"assistant.approve")}async reject(t,e){return d(await this.client.POST("/api/v1/orgs/{orgId}/assistant/proposals/{proposalId}/reject",{params:{path:{orgId:t,proposalId:e}}}),"assistant.reject")}}class Ae{client;constructor(t){this.client=t}async list(t,e={}){return d(await this.client.GET("/api/v1/orgs/{orgId}/calendar",{params:{path:{orgId:t},query:e}}),"calendar.list")}async ics(t,e){let{data:r,error:n,response:i}=await this.client.GET("/api/v1/orgs/{orgId}/calendar.ics",{params:{path:{orgId:t},query:{token:e}},parseAs:"text"});if(n!==void 0||typeof r!=="string")throw new ct(`calendar.ics failed (${i.status})`,i.status,n,i.url);return r}async createEntry(t,e){return d(await this.client.POST("/api/v1/orgs/{orgId}/calendar/entries",{params:{path:{orgId:t}},body:e}),"calendar.createEntry")}async getEntry(t,e){return d(await this.client.GET("/api/v1/orgs/{orgId}/calendar/entries/{entryId}",{params:{path:{orgId:t,entryId:e}}}),"calendar.getEntry")}async updateEntry(t,e,r){return d(await this.client.PATCH("/api/v1/orgs/{orgId}/calendar/entries/{entryId}",{params:{path:{orgId:t,entryId:e}},body:r}),"calendar.updateEntry")}async cancelEntry(t,e,r={}){return d(await this.client.DELETE("/api/v1/orgs/{orgId}/calendar/entries/{entryId}",{params:{path:{orgId:t,entryId:e},query:r}}),"calendar.cancelEntry")}async settings(t){return d(await this.client.GET("/api/v1/orgs/{orgId}/calendar/settings",{params:{path:{orgId:t}}}),"calendar.settings")}async updateSettings(t,e){return d(await this.client.PATCH("/api/v1/orgs/{orgId}/calendar/settings",{params:{path:{orgId:t}},body:e}),"calendar.updateSettings")}async staff(t){return d(await this.client.GET("/api/v1/orgs/{orgId}/calendar/staff",{params:{path:{orgId:t}}}),"calendar.staff")}async holidays(t,e={}){return d(await this.client.GET("/api/v1/orgs/{orgId}/calendar/holidays",{params:{path:{orgId:t},query:e}}),"calendar.holidays")}async listFeeds(t){return d(await this.client.GET("/api/v1/orgs/{orgId}/calendar/feeds",{params:{path:{orgId:t}}}),"calendar.listFeeds")}async createFeed(t,e){return d(await this.client.POST("/api/v1/orgs/{orgId}/calendar/feeds",{params:{path:{orgId:t}},body:e}),"calendar.createFeed")}async updateFeed(t,e,r){return d(await this.client.PATCH("/api/v1/orgs/{orgId}/calendar/feeds/{feedId}",{params:{path:{orgId:t,feedId:e}},body:r}),"calendar.updateFeed")}async revokeFeed(t,e){return d(await this.client.DELETE("/api/v1/orgs/{orgId}/calendar/feeds/{feedId}",{params:{path:{orgId:t,feedId:e}}}),"calendar.revokeFeed")}async listExternal(t){return d(await this.client.GET("/api/v1/orgs/{orgId}/calendar/external",{params:{path:{orgId:t}}}),"calendar.listExternal")}async addExternal(t,e){return d(await this.client.POST("/api/v1/orgs/{orgId}/calendar/external",{params:{path:{orgId:t}},body:e}),"calendar.addExternal")}async updateExternal(t,e,r){return d(await this.client.PATCH("/api/v1/orgs/{orgId}/calendar/external/{calendarId}",{params:{path:{orgId:t,calendarId:e}},body:r}),"calendar.updateExternal")}async removeExternal(t,e){return d(await this.client.DELETE("/api/v1/orgs/{orgId}/calendar/external/{calendarId}",{params:{path:{orgId:t,calendarId:e}}}),"calendar.removeExternal")}}class Pe{client;constructor(t){this.client=t}async listContacts(t,e={}){return d(await this.client.GET("/api/v1/orgs/{orgId}/crm/contacts",{params:{path:{orgId:t},query:e}}),"crm.listContacts")}async createContact(t,e){return d(await this.client.POST("/api/v1/orgs/{orgId}/crm/contacts",{params:{path:{orgId:t}},body:e}),"crm.createContact")}async getContact(t,e){return d(await this.client.GET("/api/v1/orgs/{orgId}/crm/contacts/{contactId}",{params:{path:{orgId:t,contactId:e}}}),"crm.getContact")}async updateContact(t,e,r){return d(await this.client.PATCH("/api/v1/orgs/{orgId}/crm/contacts/{contactId}",{params:{path:{orgId:t,contactId:e}},body:r}),"crm.updateContact")}async archiveContact(t,e){return d(await this.client.DELETE("/api/v1/orgs/{orgId}/crm/contacts/{contactId}",{params:{path:{orgId:t,contactId:e}}}),"crm.archiveContact")}async restoreContact(t,e){return d(await this.client.POST("/api/v1/orgs/{orgId}/crm/contacts/{contactId}/restore",{params:{path:{orgId:t,contactId:e}}}),"crm.restoreContact")}async setContactTags(t,e,r){return d(await this.client.PUT("/api/v1/orgs/{orgId}/crm/contacts/{contactId}/tags",{params:{path:{orgId:t,contactId:e}},body:r}),"crm.setContactTags")}async contactTimeline(t,e){return d(await this.client.GET("/api/v1/orgs/{orgId}/crm/contacts/{contactId}/timeline",{params:{path:{orgId:t,contactId:e}}}),"crm.contactTimeline")}async contactAudiences(t,e){return d(await this.client.GET("/api/v1/orgs/{orgId}/crm/contacts/{contactId}/audiences",{params:{path:{orgId:t,contactId:e}}}),"crm.contactAudiences")}async addDeal(t,e,r){return d(await this.client.POST("/api/v1/orgs/{orgId}/crm/contacts/{contactId}/deals",{params:{path:{orgId:t,contactId:e}},body:r}),"crm.addDeal")}async listTags(t){return d(await this.client.GET("/api/v1/orgs/{orgId}/crm/tags",{params:{path:{orgId:t}}}),"crm.listTags")}async createTag(t,e){return d(await this.client.POST("/api/v1/orgs/{orgId}/crm/tags",{params:{path:{orgId:t}},body:e}),"crm.createTag")}async listFollowUps(t,e={}){return d(await this.client.GET("/api/v1/orgs/{orgId}/crm/follow-ups",{params:{path:{orgId:t},query:e}}),"crm.listFollowUps")}async listAudiences(t){return d(await this.client.GET("/api/v1/orgs/{orgId}/crm/audiences",{params:{path:{orgId:t}}}),"crm.listAudiences")}async listAudienceContacts(t,e,r={}){return d(await this.client.GET("/api/v1/orgs/{orgId}/crm/audiences/{audienceId}/contacts",{params:{path:{orgId:t,audienceId:e},query:r}}),"crm.listAudienceContacts")}}class $e{client;constructor(t){this.client=t}async list(t,e={}){return d(await this.client.GET("/api/v1/orgs/{orgId}/inbox",{params:{path:{orgId:t},query:e}}),"inbox.list")}async unreadCount(t){return d(await this.client.GET("/api/v1/orgs/{orgId}/inbox/unread-count",{params:{path:{orgId:t}}}),"inbox.unreadCount")}async get(t,e){return d(await this.client.GET("/api/v1/orgs/{orgId}/inbox/{conversationId}",{params:{path:{orgId:t,conversationId:e}}}),"inbox.get")}async update(t,e,r){return d(await this.client.PATCH("/api/v1/orgs/{orgId}/inbox/{conversationId}",{params:{path:{orgId:t,conversationId:e}},body:r}),"inbox.update")}async customer(t,e){return d(await this.client.GET("/api/v1/orgs/{orgId}/inbox/{conversationId}/customer",{params:{path:{orgId:t,conversationId:e}}}),"inbox.customer")}async listMessages(t,e,r={}){return d(await this.client.GET("/api/v1/orgs/{orgId}/inbox/{conversationId}/messages",{params:{path:{orgId:t,conversationId:e},query:r}}),"inbox.listMessages")}async reply(t,e,r){return d(await this.client.POST("/api/v1/orgs/{orgId}/inbox/{conversationId}/messages",{params:{path:{orgId:t,conversationId:e}},body:r}),"inbox.reply")}async editMessage(t,e,r,n){return d(await this.client.PATCH("/api/v1/orgs/{orgId}/inbox/{conversationId}/messages/{messageId}",{params:{path:{orgId:t,conversationId:e,messageId:r}},body:n}),"inbox.editMessage")}async deleteMessage(t,e,r){return d(await this.client.DELETE("/api/v1/orgs/{orgId}/inbox/{conversationId}/messages/{messageId}",{params:{path:{orgId:t,conversationId:e,messageId:r}}}),"inbox.deleteMessage")}async markRead(t,e){let r={orgId:t,conversationId:e};return d(await this.client.POST("/api/v1/orgs/{orgId}/inbox/{conversationId}/read",{params:{path:r}}),"inbox.markRead")}async search(t,e,r){let n={orgId:t,conversationId:e};return d(await this.client.GET("/api/v1/orgs/{orgId}/inbox/{conversationId}/search",{params:{path:n,query:{q:r}}}),"inbox.search")}async startCall(t,e){let r={orgId:t,conversationId:e};return d(await this.client.POST("/api/v1/orgs/{orgId}/inbox/{conversationId}/calls",{params:{path:r}}),"inbox.startCall")}async createPoll(t,e,r){return d(await this.client.POST("/api/v1/orgs/{orgId}/inbox/{conversationId}/polls",{params:{path:{orgId:t,conversationId:e}},body:r}),"inbox.createPoll")}async votePoll(t,e,r,n){return d(await this.client.POST("/api/v1/orgs/{orgId}/inbox/{conversationId}/polls/{messageId}",{params:{path:{orgId:t,conversationId:e,messageId:r}},body:n}),"inbox.votePoll")}async share(t,e,r){return d(await this.client.POST("/api/v1/orgs/{orgId}/inbox/{conversationId}/shares",{params:{path:{orgId:t,conversationId:e}},body:r}),"inbox.share")}async startUpload(t,e,r){return d(await this.client.POST("/api/v1/orgs/{orgId}/inbox/{conversationId}/uploads",{params:{path:{orgId:t,conversationId:e}},body:r}),"inbox.startUpload")}async completeUpload(t,e,r){return d(await this.client.POST("/api/v1/orgs/{orgId}/inbox/{conversationId}/uploads/{fileId}",{params:{path:{orgId:t,conversationId:e,fileId:r}}}),"inbox.completeUpload")}async shareables(t,e){return d(await this.client.GET("/api/v1/orgs/{orgId}/chat/shareables",{params:{path:{orgId:t},query:e}}),"inbox.shareables")}}class De{client;constructor(t){this.client=t}async list(t){return d(await this.client.GET("/api/v1/orgs/{orgId}/quick-replies",{params:{path:{orgId:t}}}),"quickReplies.list")}async create(t,e){return d(await this.client.POST("/api/v1/orgs/{orgId}/quick-replies",{params:{path:{orgId:t}},body:e}),"quickReplies.create")}async update(t,e,r){return d(await this.client.PATCH("/api/v1/orgs/{orgId}/quick-replies/{quickReplyId}",{params:{path:{orgId:t,quickReplyId:e}},body:r}),"quickReplies.update")}async delete(t,e){return d(await this.client.DELETE("/api/v1/orgs/{orgId}/quick-replies/{quickReplyId}",{params:{path:{orgId:t,quickReplyId:e}}}),"quickReplies.delete")}}class Ne{client;constructor(t){this.client=t}async listRooms(t){return d(await this.client.GET("/api/v1/orgs/{orgId}/team-chat",{params:{path:{orgId:t}}}),"teamChat.listRooms")}async createChannel(t,e){return d(await this.client.POST("/api/v1/orgs/{orgId}/team-chat/channels",{params:{path:{orgId:t}},body:e}),"teamChat.createChannel")}async updateChannel(t,e,r){return d(await this.client.PATCH("/api/v1/orgs/{orgId}/team-chat/channels/{channelId}",{params:{path:{orgId:t,channelId:e}},body:r}),"teamChat.updateChannel")}async deleteChannel(t,e){return d(await this.client.DELETE("/api/v1/orgs/{orgId}/team-chat/channels/{channelId}",{params:{path:{orgId:t,channelId:e}}}),"teamChat.deleteChannel")}async openDm(t,e){return d(await this.client.POST("/api/v1/orgs/{orgId}/team-chat/dms",{params:{path:{orgId:t}},body:e}),"teamChat.openDm")}async members(t){return d(await this.client.GET("/api/v1/orgs/{orgId}/team-chat/members",{params:{path:{orgId:t}}}),"teamChat.members")}async search(t,e){return d(await this.client.GET("/api/v1/orgs/{orgId}/team-chat/search",{params:{path:{orgId:t},query:e}}),"teamChat.search")}async listMessages(t,e,r={}){return d(await this.client.GET("/api/v1/orgs/{orgId}/team-chat/rooms/{roomId}/messages",{params:{path:{orgId:t,roomId:e},query:r}}),"teamChat.listMessages")}async send(t,e,r){return d(await this.client.POST("/api/v1/orgs/{orgId}/team-chat/rooms/{roomId}/messages",{params:{path:{orgId:t,roomId:e}},body:r}),"teamChat.send")}async editMessage(t,e,r,n){let i={orgId:t,roomId:e,messageId:r};return d(await this.client.PATCH("/api/v1/orgs/{orgId}/team-chat/rooms/{roomId}/messages/{messageId}",{params:{path:i},body:n}),"teamChat.editMessage")}async deleteMessage(t,e,r){let n={orgId:t,roomId:e,messageId:r};return d(await this.client.DELETE("/api/v1/orgs/{orgId}/team-chat/rooms/{roomId}/messages/{messageId}",{params:{path:n}}),"teamChat.deleteMessage")}async react(t,e,r,n){let i={orgId:t,roomId:e,messageId:r};return d(await this.client.PUT("/api/v1/orgs/{orgId}/team-chat/rooms/{roomId}/messages/{messageId}/reactions",{params:{path:i},body:{emoji:n}}),"teamChat.react")}async unreact(t,e,r,n){let i={orgId:t,roomId:e,messageId:r};return d(await this.client.DELETE("/api/v1/orgs/{orgId}/team-chat/rooms/{roomId}/messages/{messageId}/reactions",{params:{path:i,query:{emoji:n}}}),"teamChat.unreact")}async thread(t,e,r){let n={orgId:t,roomId:e,messageId:r};return d(await this.client.GET("/api/v1/orgs/{orgId}/team-chat/rooms/{roomId}/messages/{messageId}/thread",{params:{path:n}}),"teamChat.thread")}async createPoll(t,e,r){return d(await this.client.POST("/api/v1/orgs/{orgId}/team-chat/rooms/{roomId}/polls",{params:{path:{orgId:t,roomId:e}},body:r}),"teamChat.createPoll")}async votePoll(t,e,r,n){let i={orgId:t,roomId:e,messageId:r};return d(await this.client.POST("/api/v1/orgs/{orgId}/team-chat/rooms/{roomId}/polls/{messageId}",{params:{path:i},body:n}),"teamChat.votePoll")}async markRead(t,e){let r={orgId:t,roomId:e};return d(await this.client.POST("/api/v1/orgs/{orgId}/team-chat/rooms/{roomId}/read",{params:{path:r}}),"teamChat.markRead")}async typing(t,e){let r={orgId:t,roomId:e};return d(await this.client.POST("/api/v1/orgs/{orgId}/team-chat/rooms/{roomId}/typing",{params:{path:r}}),"teamChat.typing")}async startCall(t,e){let r={orgId:t,roomId:e};return d(await this.client.POST("/api/v1/orgs/{orgId}/team-chat/rooms/{roomId}/calls",{params:{path:r}}),"teamChat.startCall")}async share(t,e,r){return d(await this.client.POST("/api/v1/orgs/{orgId}/team-chat/rooms/{roomId}/shares",{params:{path:{orgId:t,roomId:e}},body:r}),"teamChat.share")}async startUpload(t,e,r){return d(await this.client.POST("/api/v1/orgs/{orgId}/team-chat/rooms/{roomId}/uploads",{params:{path:{orgId:t,roomId:e}},body:r}),"teamChat.startUpload")}async completeUpload(t,e,r){return d(await this.client.POST("/api/v1/orgs/{orgId}/team-chat/rooms/{roomId}/uploads/{fileId}",{params:{path:{orgId:t,roomId:e,fileId:r}}}),"teamChat.completeUpload")}async realtimeToken(t){return d(await this.client.POST("/api/v1/chat/realtime-token",{body:t}),"teamChat.realtimeToken")}}class Fe{client;constructor(t){this.client=t}async listNotes(t){return d(await this.client.GET("/api/v1/orgs/{orgId}/vault/notes",{params:{path:{orgId:t}}}),"vault.listNotes")}async createNote(t,e){return d(await this.client.POST("/api/v1/orgs/{orgId}/vault/notes",{params:{path:{orgId:t}},body:e}),"vault.createNote")}async getNote(t,e){return d(await this.client.GET("/api/v1/orgs/{orgId}/vault/notes/{noteId}",{params:{path:{orgId:t,noteId:e}}}),"vault.getNote")}async saveNote(t,e,r){return d(await this.client.PATCH("/api/v1/orgs/{orgId}/vault/notes/{noteId}",{params:{path:{orgId:t,noteId:e}},body:r}),"vault.saveNote")}async deleteNote(t,e){return d(await this.client.DELETE("/api/v1/orgs/{orgId}/vault/notes/{noteId}",{params:{path:{orgId:t,noteId:e}}}),"vault.deleteNote")}async moveNote(t,e,r){return d(await this.client.POST("/api/v1/orgs/{orgId}/vault/notes/{noteId}/move",{params:{path:{orgId:t,noteId:e}},body:r}),"vault.moveNote")}async search(t,e){return d(await this.client.GET("/api/v1/orgs/{orgId}/vault/search",{params:{path:{orgId:t},query:e}}),"vault.search")}async graph(t){return d(await this.client.GET("/api/v1/orgs/{orgId}/vault/graph",{params:{path:{orgId:t}}}),"vault.graph")}async changes(t,e){return d(await this.client.GET("/api/v1/me/vault-changes",{params:{query:{org:t,since:e}}}),"vault.changes")}}class Ue{client;constructor(t){this.client=t}async list(t,e={}){return d(await this.client.GET("/api/v1/orgs/{orgId}/webhooks",{params:{path:{orgId:t},query:e}}),"webhooks.list")}async create(t,e){return d(await this.client.POST("/api/v1/orgs/{orgId}/webhooks",{params:{path:{orgId:t}},body:e}),"webhooks.create")}async get(t,e){return d(await this.client.GET("/api/v1/orgs/{orgId}/webhooks/{webhookId}",{params:{path:{orgId:t,webhookId:e}}}),"webhooks.get")}async update(t,e,r){return d(await this.client.PUT("/api/v1/orgs/{orgId}/webhooks/{webhookId}",{params:{path:{orgId:t,webhookId:e}},body:r}),"webhooks.update")}async delete(t,e){return d(await this.client.DELETE("/api/v1/orgs/{orgId}/webhooks/{webhookId}",{params:{path:{orgId:t,webhookId:e}}}),"webhooks.delete")}async deliveries(t,e,r={}){return d(await this.client.GET("/api/v1/orgs/{orgId}/webhooks/{webhookId}/deliveries",{params:{path:{orgId:t,webhookId:e},query:r}}),"webhooks.deliveries")}async rotateSecret(t,e){return d(await this.client.POST("/api/v1/orgs/{orgId}/webhooks/{webhookId}/rotate",{params:{path:{orgId:t,webhookId:e}}}),"webhooks.rotateSecret")}async test(t,e){return d(await this.client.POST("/api/v1/orgs/{orgId}/webhooks/{webhookId}/test",{params:{path:{orgId:t,webhookId:e}}}),"webhooks.test")}}var pi="https://vcity.io";function mi(t){let e;try{e=new URL(t)}catch{throw Error(`@vcityio/api-client: invalid baseUrl (${t.slice(0,200)})`)}if(e.protocol==="https:")return;if(e.protocol==="http:"&&(e.hostname==="localhost"||e.hostname==="127.0.0.1"||e.hostname==="[::1]"))return;throw Error(`@vcityio/api-client: baseUrl must use https:// for non-localhost hosts (got: ${e.protocol}//${e.hostname}).`)}function fi(t,e){let r=e??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(i){if(!t)return r(i);let s=i.headers.get("Authorization")?.match(/^Bearer\s+(.+)$/)?.[1]?.trim();if(s&&s!=="undefined"&&s!=="null")return r(i);let o=new Headers(i.headers);o.set("Authorization",`Bearer ${t}`);let c=new Request(i,{headers:o});return r(c)}}class ar{raw;me;orgs;drafts;coupons;media;products;events;rooms;support;agents;conversations;customerAgent;posts;collections;bookings;bookingTypes;projects;blogs;orders;analytics;apiKeys;quotes;crm;webhooks;inbox;quickReplies;teamChat;calendar;vault;assistant;notifications;desk;campaigns;comments;newsletter;surveys;configurators;pos;dropshipping;storefront;public;chatRooms;billing;constructor(t={}){let e=t.baseUrl??pi;mi(e);let r=fi(t.token,t.fetch),n={baseUrl:e,fetch:r,headers:t.headers};this.raw=ir(n),this.me=new Xt(this.raw),this.orgs=new Zt(this.raw),this.drafts=new zt(this.raw),this.coupons=new Kt(this.raw),this.media=new Wt(this.raw),this.products=new te(this.raw),this.events=new ee(this.raw),this.rooms=new re(this.raw),this.support=new he(this.raw),this.agents=new ge(this.raw),this.conversations=new le(this.raw),this.customerAgent=new pe(this.raw),this.posts=new me(this.raw),this.collections=new ue(this.raw),this.bookings=new se(this.raw),this.bookingTypes=new ie(this.raw),this.projects=new ne(this.raw),this.blogs=new oe(this.raw),this.orders=new ae(this.raw),this.analytics=new de(this.raw),this.apiKeys=new we(this.raw),this.quotes=new ce(this.raw),this.crm=new Pe(this.raw),this.webhooks=new Ue(this.raw),this.inbox=new $e(this.raw),this.quickReplies=new De(this.raw),this.teamChat=new Ne(this.raw),this.calendar=new Ae(this.raw),this.vault=new Fe(this.raw),this.assistant=new xe(this.raw),this.notifications=new fe(this.raw),this.desk=new ye(this.raw),this.campaigns=new ve(this.raw),this.comments=new be(this.raw),this.newsletter=new ke(this.raw),this.surveys=new Ie(this.raw),this.configurators=new Ce(this.raw),this.pos=new Se(this.raw),this.dropshipping=new Oe(this.raw),this.storefront=new je(this.raw),this.public=new Ee(this.raw),this.chatRooms=new Re(this.raw),this.billing=new Te(this.raw)}}function cr(t={}){return new ar(t)}import lt from"node:fs";import vi from"node:os";import Be from"node:path";var yi=/\x1b(?:\[[0-?]*[ -/]*[@-~]|\][^\x07\x1b]*(?:\x07|\x1b\\)|[P_^X][^\x07\x1b]*(?:\x07|\x1b\\)|[^[\]P_^X])/g,hi=/[\x00-\x08\x0b-\x1f\x7f-\x9f]/g,wi=/[\u061c\u200e\u200f\u202a-\u202e\u2066-\u2069]/g;function E(t){return t.replace(yi,"").replace(hi,"").replace(wi,"")}function Dr(t){let e;try{e=new URL(t)}catch{throw Error(`Refusing to open malformed URL: ${E(t).slice(0,100)}`)}if(e.protocol==="https:")return e;if(e.protocol==="http:"&&(e.hostname==="localhost"||e.hostname==="127.0.0.1"||e.hostname==="[::1]"))return e;throw Error(`Refusing to open URL with unsafe protocol: ${e.protocol}`)}var $r=512;function O(t,e){let r=t.trim();if(!r)throw Error(`${e} must not be empty.`);if(r.length>$r)throw Error(`${e} must be at most ${$r} characters.`);if(/[\x00-\x1f\x7f]/.test(r))throw Error(`${e} must not contain control characters.`);return r}function St(t){let e;try{e=new URL(t)}catch{throw Error(`Invalid api base URL: ${t.slice(0,200)}`)}if(e.protocol==="https:")return e;if(e.protocol==="http:"&&(e.hostname==="localhost"||e.hostname==="127.0.0.1"||e.hostname==="[::1]"))return e;throw Error(`api base URL must use https:// (got: ${e.protocol}//${e.hostname}).`)}function gt(){if(process.env.VCITY_CONFIG_DIR)return Be.resolve(process.env.VCITY_CONFIG_DIR);return Be.join(vi.homedir(),".vcity")}function Me(){return Be.join(gt(),"auth.json")}function dr(){return Be.join(gt(),"config.json")}function Le(){let t=process.env.VCITY_API_BASE_URL||"https://vcity.io";return St(t),t}import dt from"node:fs";function Ot(t,e,r=384){if(process.platform==="win32"){dt.writeFileSync(t,e,{mode:r});try{dt.chmodSync(t,r)}catch{}return}let n=dt.constants.O_WRONLY|dt.constants.O_CREAT|dt.constants.O_TRUNC|dt.constants.O_NOFOLLOW,i=dt.openSync(t,n,r);try{dt.writeSync(i,e),dt.fchmodSync(i,r)}finally{dt.closeSync(i)}}function bi(){let t=gt();lt.mkdirSync(t,{recursive:!0,mode:448});try{lt.chmodSync(t,448)}catch{}if(process.platform!=="win32"){let e;try{e=lt.statSync(t)}catch{return}if((e.mode&63)!==0)throw Error(`Refusing to write CLI credentials: ${t} is group- or world-accessible (mode ${(e.mode&511).toString(8)}). Tighten its permissions (\`chmod 700 ${t}\`) or set VCITY_CONFIG_DIR to a directory you own.`)}}function ki(t){if(!t||typeof t!=="object")return!1;let e=t;return typeof e.api_base_url==="string"&&typeof e.access_token==="string"&&typeof e.refresh_token==="string"&&typeof e.access_expires_at==="number"&&typeof e.refresh_expires_at==="number"&&!!e.user&&typeof e.user==="object"}function xt(){let t=Me();if(!lt.existsSync(t))return;try{let e=JSON.parse(lt.readFileSync(t,"utf-8"));if(!ki(e))return;if(St(e.api_base_url),new URL(e.api_base_url).origin!==new URL(Le()).origin)return;return e}catch{return}}function Ii(t){let e;try{e=lt.lstatSync(t)}catch{return}if(e.isSymbolicLink()||e.isFile()&&e.nlink>1)lt.rmSync(t,{force:!0})}function qe(t){bi();let e=Me();Ii(e),Ot(e,JSON.stringify(t,null,2),384)}function $t(){let t=Me();if(lt.existsSync(t))lt.rmSync(t)}function _e(){let t=xt();if(!t)throw Error("Not logged in. Run `vcity login` first.");return t}var ur={name:"@vcityio/cli",version:"0.10.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 nt=ur.version,Tt=ur.name;var gr=60000,Mr=`vcity-cli/${nt} (${process.platform} ${process.arch})`,Nr=2048;class Dt extends Error{status;body;constructor(t,e,r){super(r??`HTTP ${t}`);this.status=t;this.body=e;this.name="ApiError"}}function Lr(t,e,r){if(e.startsWith("//")||/^[a-z][a-z0-9+.-]*:/i.test(e))throw Error(`Refusing to build URL with non-relative path: ${e.slice(0,100)}`);let n=new URL(t),i=new URL(e.startsWith("/")?e:`/${e}`,t);if(i.origin!==n.origin)throw Error(`Refusing to build URL outside base origin: ${i.origin}`);if(r){for(let[a,s]of Object.entries(r))if(s!==void 0&&s!==null&&!Number.isNaN(s))i.searchParams.set(a,String(s))}return i.toString()}var Fr=(t,e)=>typeof t==="string"&&t.length>0&&t.length<=e,Ge=Symbol("transient"),Ur=(t)=>typeof t==="number"&&Number.isFinite(t);async function Ti(t){try{let e=await fetch(Lr(t.api_base_url,"/api/cli/auth/refresh"),{method:"POST",headers:{"content-type":"application/json",authorization:`Bearer ${t.refresh_token}`},body:JSON.stringify({refresh_token:t.refresh_token}),signal:AbortSignal.timeout(gr),redirect:"error"});if(e.status===429||e.status>=500)return Ge;if(!e.ok)return;let r=await e.json();if(!Fr(r.access_token,Nr)||!Fr(r.refresh_token,Nr)||!Ur(r.access_expires_at)||!Ur(r.refresh_expires_at)||r.access_expires_at<=Date.now()||r.refresh_expires_at<=Date.now())return;let n={...t,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 qe(n),n}catch{return Ge}}async function Br(t){let e=()=>new Dt(401,void 0,"Session expired. Run `vcity login` again."),r=xt();if(r&&r.refresh_token!==t.refresh_token)return r;let n=await Ti(t);if(n&&n!==Ge)return n;let i=xt();if(i&&i.refresh_token!==t.refresh_token)return i;if(n===Ge)throw new Dt(503,void 0,"Could not refresh the session. Check your connection and try again.");throw $t(),e()}async function Nt(t,e={}){let{authed:r=!0,method:n="GET",body:i,query:a,baseUrl:s,headers:o}=e,c=r?_e():void 0,u=s??c?.api_base_url??"https://vcity.io",l={"content-type":"application/json","user-agent":Mr};if(c)l.authorization=`Bearer ${c.access_token}`;if(o)for(let[T,N]of Object.entries(o))l[T]=N;let w=await fetch(Lr(u,t,a),{method:n,headers:l,body:i===void 0?void 0:JSON.stringify(i),signal:AbortSignal.timeout(gr),redirect:"error"}),R=(w.headers.get("content-type")??"").includes("application/json")?await w.json().catch(()=>{return}):await w.text().catch(()=>{return});if(!w.ok){let T=(R&&typeof R==="object"&&"error"in R?String(R.error):void 0)??`Request failed (${w.status})`;throw new Dt(w.status,R,T)}return R}function Ei(t,e){let r=new URL(t).origin;if(r!==e)throw Error(`Refusing to attach Bearer token to cross-origin SDK request: ${r}`)}var Ri=3,Ci=60000;function Si(t,e){let r=t.headers.get("retry-after"),n=r!==null&&/^\d+$/.test(r)?Number(r)*1000:r?Date.parse(r)-Date.now():Number.NaN,i=Number.isFinite(n)?n:1000*2**e;return Math.min(Math.max(i,0),Ci)}async function Oi(t){for(let e=0;;e++){let r=await t();if(r.status!==429||e>=Ri)return r;await new Promise((n)=>setTimeout(n,Si(r,e)))}}function xi(){let t=async(e,r,n)=>{Ei(e.url,n);let i=new Headers(e.headers);i.set("authorization",`Bearer ${r}`),i.set("user-agent",Mr);let a=new Request(e,{headers:i,signal:AbortSignal.timeout(gr),redirect:e.redirect==="manual"?"manual":"error"});return globalThis.fetch(a)};return async function(r){let n=_e(),i=new URL(n.api_base_url).origin;if(Date.now()>=n.access_expires_at){if(Date.now()>=n.refresh_expires_at)throw $t(),new Dt(401,void 0,"Session expired. Run `vcity login` again.");n=await Br(n)}let a=await Oi(()=>t(r.clone(),n.access_token,i));if(a.status!==401)return a;return n=await Br(n),t(r,n.access_token,i)}}function p(){let t=_e();return cr({baseUrl:t.api_base_url,fetch:xi()})}import Et from"node:fs";import Ai from"node:path";var lr=16777216;function Pi(t){let e=new Uint8Array(t+1),r=0;while(r<e.length){let n=Et.readSync(0,e,r,e.length-r,null);if(n===0)break;r+=n}if(r>t)throw Error(`--data: stdin body exceeds the ${t}-byte cap.`);return Buffer.from(e.buffer,e.byteOffset,r).toString("utf-8")}function P(t){if(t===void 0)return;let e;if(t==="-"){if(process.stdin.isTTY)throw Error("--data: reading from stdin (-) but nothing is piped in");try{e=Pi(lr)}catch(r){let n=r instanceof Error?r.message:String(r);if(n.startsWith("--data:"))throw r;throw Error(`--data: could not read stdin: ${n}`)}}else if(t.startsWith("@")){let r=t.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 n;try{n=Et.realpathSync(r)}catch(s){let o=s instanceof Error?s.message:String(s);throw Error(`--data: could not read ${r}: ${o}`)}if(!/\.json$/i.test(n))throw Error(`--data: @file path must point to a .json file (got: ${r} → ${n})`);let i;try{i=Et.realpathSync(process.cwd())}catch(s){let o=s instanceof Error?s.message:String(s);throw Error(`--data: could not resolve cwd: ${o}`)}if(n!==i&&!n.startsWith(i+Ai.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 a;try{a=Et.openSync(n,"r")}catch(s){let o=s instanceof Error?s.message:String(s);throw Error(`--data: could not read ${r}: ${o}`)}try{let s;try{s=Et.fstatSync(a)}catch(o){let c=o instanceof Error?o.message:String(o);throw Error(`--data: could not read ${r}: ${c}`)}if(s.nlink>1)throw Error(`--data: @file path must not be a hard link (got: ${r})`);if(s.size>lr)throw Error(`--data: ${r} exceeds the ${lr}-byte body cap (got ${s.size} bytes).`);try{e=Et.readFileSync(a,"utf-8")}catch(o){let c=o instanceof Error?o.message:String(o);throw Error(`--data: could not read ${r}: ${c}`)}}finally{try{Et.closeSync(a)}catch{}}}else e=t;try{return JSON.parse(e)}catch{throw Error("--data: invalid JSON")}}import Rt from"node:fs";function $i(){let t=gt();Rt.mkdirSync(t,{recursive:!0,mode:448});try{Rt.chmodSync(t,448)}catch{}if(process.platform!=="win32"){let e;try{e=Rt.statSync(t)}catch{return}if((e.mode&63)!==0)throw Error(`Refusing to write CLI config: ${t} is group- or world-accessible (mode ${(e.mode&511).toString(8)}). Tighten its permissions (\`chmod 700 ${t}\`) or set VCITY_CONFIG_DIR to a directory you own.`)}}function Di(t){if(!t||typeof t!=="object"||Array.isArray(t))return!1;let e=t;if(e.active_org!==void 0&&typeof e.active_org!=="string")return!1;if(e.default_format!==void 0&&e.default_format!=="pretty"&&e.default_format!=="json")return!1;return!0}function Ct(){let t=dr();if(!Rt.existsSync(t))return{};try{let e=JSON.parse(Rt.readFileSync(t,"utf-8"));return Di(e)?e:{}}catch{return{}}}function Ni(t){let e;try{e=Rt.lstatSync(t)}catch{return}if(e.isSymbolicLink()||e.isFile()&&e.nlink>1)Rt.rmSync(t,{force:!0})}function qr(t){$i();let r={...Ct(),...t},n=dr();return Ni(n),Ot(n,JSON.stringify(r,null,2),384),r}function h(t){if(t)return t;let e=Ct();if(!e.active_org)throw Error("No active org. Run `vcity org use <slug>` or pass --org <slug>.");return e.active_org}function f(t){if(t)return"json";if(!process.stdout.isTTY)return"json";return"pretty"}function g(t){process.stdout.write(`${JSON.stringify(t,null,2)}
|
|
9
|
+
`)}function Fi(t,e){if(t.length===0)return"(no rows)";let r=t.map((o)=>e.map((c)=>E(c.get(o)??""))),n=e.map((o,c)=>Math.max(o.header.length,...r.map((u)=>u[c].length))),i=n.map((o)=>"-".repeat(o)).join(" "),a=e.map((o,c)=>o.header.padEnd(n[c])).join(" "),s=r.map((o)=>o.map((c,u)=>c.padEnd(n[u])).join(" "));return[a,i,...s].join(`
|
|
10
|
+
`)}function k(t,e){process.stdout.write(`${Fi(t,e)}
|
|
11
|
+
`)}function j(t){for(let[e,r]of Object.entries(t)){if(r===void 0||r===null)continue;let n=typeof r==="object"?JSON.stringify(r):String(r);process.stdout.write(`${E(e).padEnd(20)} ${E(n)}
|
|
12
|
+
`)}}import Ui from"node:readline";function _(t){let e=Ui.createInterface({input:process.stdin,output:process.stdout});return new Promise((r)=>{e.question(`${E(t)} `,(n)=>{e.close();let i=n.trim().toLowerCase();r(i==="y"||i==="yes")})})}var _r=["draft","public","hidden"];function pr(t){if(t===void 0)return;if(!_r.includes(t))throw Error(`invalid --visibility: ${t}. Allowed: ${_r.join(", ")}`);return t}var Gr=["blog","news"];function Vr(t){if(t===void 0)return;if(!Gr.includes(t))throw Error(`invalid --type: ${t}. Allowed: ${Gr.join(", ")}`);return t}function Jr(t){if(t===void 0)return;return t.split(",").map((e)=>e.trim()).filter((e)=>e.length>0)}async function Hr(t={}){let e=f(t.json),r=h(t.org),n=pr(t.visibility),i={};if(t.limit!==void 0)i.limit=t.limit;if(t.search!==void 0)i.search=t.search;if(n!==void 0)i.visibility=n;let s=await p().blogs.list(r,i),o=s.data??[];if(e==="json"){g({org:r,blogs:o,total:s.total,skip:s.skip,limit:s.limit,hasMore:s.hasMore});return}k(o,[{header:"ID",get:(c)=>c.id},{header:"TITLE",get:(c)=>c.title??""},{header:"SLUG",get:(c)=>c.slug??""},{header:"VISIBILITY",get:(c)=>c.visibility??""},{header:"TYPE",get:(c)=>c.type??"blog"},{header:"UPDATED",get:(c)=>c.updatedAt!==void 0?new Date(c.updatedAt).toISOString():""}])}async function Yr(t,e={}){let r=f(e.json),n=h(e.org),a=await p().blogs.get(n,t);if(r==="json"){g(a);return}j(a)}async function Qr(t={}){let e=f(t.json),r=h(t.org),n=pr(t.visibility),i=Vr(t.type),a=P(t.data),s=a&&typeof a==="object"?{...a}:{};if(t.title!==void 0)s.title=t.title;if(t.slug!==void 0)s.slug=t.slug;if(t.summary!==void 0)s.summary=t.summary;if(t.content!==void 0)s.content=t.content;if(n!==void 0)s.visibility=n;if(i!==void 0)s.type=i;let o=Jr(t.tags);if(o!==void 0)s.tags=o;if(s.title===void 0)throw Error("blogs create: --title is required (or supply it via --data)");let u=await p().blogs.create(r,s);if(e==="json"){g(u);return}process.stdout.write(`Created blog:
|
|
13
|
+
`),j(u)}async function Wr(t,e={}){let r=f(e.json),n=h(e.org),i=pr(e.visibility),a=Vr(e.type),s=P(e.data),o=s&&typeof s==="object"?{...s}:{};if(e.title!==void 0)o.title=e.title;if(e.slug!==void 0)o.slug=e.slug;if(e.summary!==void 0)o.summary=e.summary;if(e.content!==void 0)o.content=e.content;if(i!==void 0)o.visibility=i;if(a!==void 0)o.type=a;let c=Jr(e.tags);if(c!==void 0)o.tags=c;if(Object.keys(o).length===0)throw Error("blogs update: nothing to update (pass at least one field or --data)");let l=await p().blogs.update(n,t,o);if(r==="json"){g(l);return}process.stdout.write(`Updated blog:
|
|
14
|
+
`),j(l)}async function zr(t,e={}){let r=f(e.json),n=h(e.org);if(!e.yes){if(r==="json")throw Error("blogs delete: --yes is required in JSON / non-interactive mode");if(!await _(`Delete blog ${t} in org ${n}? [y/N]`)){process.stdout.write(`Aborted.
|
|
15
|
+
`);return}}let a=await p().blogs.delete(n,t);if(r==="json"){g(a);return}process.stdout.write(`Deleted blog ${t}.
|
|
16
|
+
`)}async function Kr(t={}){let e=f(t.json),r=h(t.org),n={};if(t.limit!==void 0)n.limit=t.limit;if(t.enabled!==void 0)n.enabled=t.enabled;let a=await p().bookingTypes.list(r,n),s=a.data??[];if(e==="json"){g({org:r,bookingTypes:s,total:a.total,skip:a.skip,limit:a.limit,hasMore:a.hasMore});return}k(s,[{header:"ID",get:(o)=>o.id},{header:"NAME",get:(o)=>o.name??""},{header:"SLUG",get:(o)=>o.slug??""},{header:"DURATION",get:(o)=>o.duration!==void 0?String(o.duration):""},{header:"ENABLED",get:(o)=>o.enabled!==void 0?String(o.enabled):""}])}async function Xr(t,e={}){let r=f(e.json),n=h(e.org),a=await p().bookingTypes.get(n,t);if(r==="json"){g(a);return}j(a)}function Zr(t){let e=P(t.data),r=e&&typeof e==="object"?{...e}:{};if(t.name!==void 0)r.name=t.name;if(t.duration!==void 0)r.duration=t.duration;if(t.description!==void 0)r.description=t.description;if(t.bufferBefore!==void 0)r.bufferBefore=t.bufferBefore;if(t.bufferAfter!==void 0)r.bufferAfter=t.bufferAfter;if(t.color!==void 0)r.color=t.color;if(t.assignee!==void 0)r.assignees=[t.assignee];if(t.roundRobin!==void 0)r.roundRobin=t.roundRobin;if(t.enabled!==void 0)r.enabled=t.enabled;if(t.sortOrder!==void 0)r.sortOrder=t.sortOrder;return r}async function ts(t={}){let e=f(t.json),r=h(t.org),n=Zr(t);if(n.name===void 0)throw Error("booking-types create: --name is required (or supply it via --data)");if(n.duration===void 0)throw Error("booking-types create: --duration is required (or supply it via --data)");let a=await p().bookingTypes.create(r,n);if(e==="json"){g(a);return}process.stdout.write(`Created booking type:
|
|
17
|
+
`),j(a)}async function es(t,e={}){let r=f(e.json),n=h(e.org),i=Zr(e);if(Object.keys(i).length===0)throw Error("booking-types update: nothing to update (pass at least one field or --data)");let s=await p().bookingTypes.update(n,t,i);if(r==="json"){g(s);return}process.stdout.write(`Updated booking type:
|
|
18
|
+
`),j(s)}async function rs(t,e={}){let r=f(e.json),n=h(e.org);if(!e.yes){if(r==="json")throw Error("booking-types delete: --yes is required in JSON / non-interactive mode");if(!await _(`Delete booking type ${t} in org ${n}? [y/N]`)){process.stdout.write(`Aborted.
|
|
19
|
+
`);return}}let a=await p().bookingTypes.delete(n,t);if(r==="json"){g(a);return}process.stdout.write(`Deleted booking type ${t}.
|
|
20
|
+
`)}function x(t){if(t==null)return"";return new Date(t).toISOString().replace("T"," ").slice(0,16)}async function ut(t,e=Number.POSITIVE_INFINITY){let r=[],n=new Set;for(let i=0;r.length<e;){let a=await t(i,Math.min(200,e-r.length)),s=a.data??[];for(let o of s){let c=o.id;if(c!==void 0&&n.has(c))continue;if(c!==void 0)n.add(c);r.push(o)}if(i+=s.length,!a.hasMore||s.length===0)break}return r}var Ve=new Set(["PENDING","APPROVED","REJECTED","CANCELED","COMPLETED","NO_SHOW"]);async function ns(t={}){let e=f(t.json),r=h(t.org);if(t.status!==void 0&&!Ve.has(t.status))throw Error(`Invalid booking status: ${t.status}. Allowed: ${[...Ve].join(", ")}`);let n={};if(t.limit!==void 0)n.limit=t.limit;if(t.status!==void 0)n.status=t.status;if(t.fromTs!==void 0)n.fromTs=t.fromTs;if(t.toTs!==void 0)n.toTs=t.toTs;let a=await p().bookings.list(r,n),s=a.data??[];if(e==="json"){g({org:r,bookings:s,total:a.total,skip:a.skip,limit:a.limit,hasMore:a.hasMore});return}k(s,[{header:"ID",get:(o)=>o.id},{header:"NAME",get:(o)=>o.name??""},{header:"EMAIL",get:(o)=>o.email??""},{header:"REQUESTED",get:(o)=>x(o.requestedDate)},{header:"STATUS",get:(o)=>o.status??""}])}async function os(t,e={}){let r=f(e.json),n=h(e.org),a=await p().bookings.get(n,t);if(r==="json"){g(a);return}j(a)}function ss(t,e){if(/^-?\d+$/.test(t)){let n=Number(t);if(Number.isFinite(n))return n}let r=Date.parse(t);if(Number.isFinite(r))return r;throw Error(`${e}: expected ISO 8601 or epoch ms (got: ${t})`)}async function is(t={}){let e=f(t.json),r=h(t.org),n=P(t.data),i=n&&typeof n==="object"?{...n}:{};if(t.name!==void 0)i.name=t.name;if(t.email!==void 0)i.email=t.email;if(t.start!==void 0)i.requestedDate=ss(t.start,"--start");if(t.end!==void 0)i.requestedEndDate=ss(t.end,"--end");if(t.timezone!==void 0)i.timezone=t.timezone;if(t.phone!==void 0)i.telephone=t.phone;if(t.company!==void 0)i.company=t.company;if(t.note!==void 0)i.note=t.note;if(t.bookingType!==void 0)i.bookingTypeId=t.bookingType;if(t.assignee!==void 0)i.assigneeUid=t.assignee;for(let[o,c]of[["name","--name"],["email","--email"],["requestedDate","--start"],["requestedEndDate","--end"],["timezone","--timezone"]])if(i[o]===void 0)throw Error(`bookings create: ${c} is required (or supply it via --data)`);let s=await p().bookings.create(r,i);if(e==="json"){g(s);return}process.stdout.write(`Created booking:
|
|
21
|
+
`),j(s)}async function as(t,e={}){let r=f(e.json),n=h(e.org);if(e.status!==void 0&&!Ve.has(e.status))throw Error(`Invalid booking status: ${e.status}. Allowed: ${[...Ve].join(", ")}`);let i=P(e.data),a=i&&typeof i==="object"?{...i}:{};if(e.status!==void 0)a.status=e.status;if(e.assignee!==void 0)a.assigneeUid=e.assignee;if(Object.keys(a).length===0)throw Error("bookings update: nothing to update (pass --status and/or --assignee)");let o=await p().bookings.update(n,t,a);if(r==="json"){g(o);return}process.stdout.write(`Updated booking:
|
|
22
|
+
`),j(o)}async function cs(t,e={}){let r=f(e.json),n=h(e.org);if(!e.yes){if(r==="json")throw Error("bookings cancel: --yes is required in JSON / non-interactive mode");if(!await _(`Cancel booking ${t} in org ${n}? [y/N]`)){process.stdout.write(`Aborted.
|
|
23
|
+
`);return}}let a=await p().bookings.delete(n,t);if(r==="json"){g(a);return}process.stdout.write(`Canceled booking ${t}.
|
|
24
|
+
`)}var Bi=new Set(["CANCELED","REJECTED"]);async function ds(t={}){let e=f(t.json),r=h(t.org),n=new Date(t.now??Date.now());n.setHours(0,0,0,0);let i=new Date(n);i.setDate(i.getDate()+1);let a=p(),s=(await ut(async(o,c)=>{let u=await a.bookings.list(r,{skip:o,limit:c,fromTs:n.getTime(),toTs:i.getTime()-1});return{data:u.data??[],hasMore:u.hasMore}})).filter((o)=>!Bi.has(o.status??"")).sort((o,c)=>(o.requestedDate??0)-(c.requestedDate??0));if(e==="json"){g({org:r,from:n.getTime(),to:i.getTime(),bookings:s});return}if(s.length===0){process.stdout.write(`No bookings today.
|
|
25
|
+
`);return}k(s,[{header:"TIME",get:(o)=>o.requestedDate?new Date(o.requestedDate).toTimeString().slice(0,5):""},{header:"NAME",get:(o)=>o.name??""},{header:"STATUS",get:(o)=>o.status??""},{header:"EMAIL",get:(o)=>o.email??""},{header:"ID",get:(o)=>o.id}])}import pt from"node:fs";class y extends Error{constructor(t){super(t);this.name="UsageError"}}function m(t,e){return typeof t[e]==="string"?t[e]:void 0}function At(t,e){let r=m(t,e);return r===void 0?void 0:O(r,`--${e}`)}function C(t,e,{min:r=0,max:n=Number.MAX_SAFE_INTEGER}={}){let i=m(t,e);if(i===void 0)return;if(!/^\d+$/.test(i)||Number(i)<r||Number(i)>n)throw new y(`--${e} must be an integer between ${r} and ${n} (got: ${i})`);return Number(i)}function A(t,e,r){let n=m(t,e);if(n===void 0)return;if(!r.includes(n))throw new y(`--${e} must be one of ${r.join(", ")} (got: ${n})`);return n}var Mi=/^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}(:\d{2}(\.\d{1,3})?)?(Z|[+-]\d{2}:\d{2})?)?$/,Li=/^(\d{4})-(\d{2})-(\d{2})$/;function M(t,e){let r=m(t,e);if(r===void 0)return;let n=r.match(Li),i=/^\d+$/.test(r)?Number(r):n?new Date(Number(n[1]),Number(n[2])-1,Number(n[3])).getTime():Mi.test(r)?Date.parse(r):Number.NaN;if(!Number.isFinite(i)||i<0)throw new y(`--${e} must be unix-ms or a date like 2026-11-01 (got: ${r})`);return i}function I(t,e,r){if(!t)throw new y(`usage: ${e}`);return O(t,r)}function G(t,e){if(t===void 0||t.trim()==="")throw new y(`usage: ${e}`);return t}var qi=16777216;function st(t){let e;try{e=pt.statSync(t)}catch{throw new y(`cannot read ${t}: no such file`)}if(!e.isFile())throw new y(`${t} is not a regular file`);if(e.size>qi)throw new y(`${t} is larger than 16 MiB`);return pt.readFileSync(t,"utf8")}function Z(t,e){let r=pt.constants.O_WRONLY|pt.constants.O_CREAT|pt.constants.O_TRUNC|(pt.constants.O_NOFOLLOW??0),n=pt.openSync(t,r,420);try{pt.writeSync(n,e)}finally{pt.closeSync(n)}}async function B(t,e){if(e.yes)return!0;if(f(e.json)==="json")throw new y("--yes is required in JSON / non-interactive mode");let r=await _(`${t} [y/N]`);if(!r)process.stdout.write(`Aborted.
|
|
26
|
+
`);return r}function q(t,e){let r=m(t,e);return r===void 0?void 0:r.split(",").map((n)=>n.trim()).filter(Boolean)}function yt(t,e=!1){if(t===void 0)return"";let r=new Date(t),n=(a)=>String(a).padStart(2,"0"),i=`${r.getFullYear()}-${n(r.getMonth()+1)}-${n(r.getDate())}`;return e?i:`${i} ${n(r.getHours())}:${n(r.getMinutes())}`}var us=86400000;function mr(t){let e=new Date(t);return e.setHours(0,0,0,0),e.getTime()}function _i(t){k([...t].sort((e,r)=>e.startMillis-r.startMillis),[{header:"START",get:(e)=>e.allDay?`${yt(e.startMillis,!0)} (all day)`:yt(e.startMillis)},{header:"END",get:(e)=>e.allDay?"":yt(e.endMillis)},{header:"TYPE",get:(e)=>e.type},{header:"TITLE",get:(e)=>e.title??""},{header:"WHERE",get:(e)=>e.locationLabel??e.calendarName??""},{header:"ID",get:(e)=>e.id}])}var Gi="vcity calendar list [--from <date>] [--to <date>] [--days <n>] | ics [<feedId>] [--output <file>] | feeds list|create|rotate|revoke | add --title <s> --start <date> --end <date> | cancel <entryId> | holidays | external list|add|refresh|remove | settings | staff";async function Vi(t,e,r,n,i){let a=p().calendar;switch(e){case void 0:case"list":{let{data:s}=await a.listFeeds(t);if(i)g({org:t,feeds:s});else k(s,[{header:"ID",get:(o)=>String(o.id)},{header:"SCOPE",get:(o)=>String(o.scope??"")},{header:"NAMES",get:(o)=>o.showCustomerNames?"shown":"hidden"},{header:"LAST USED",get:(o)=>x(o.lastAccessedAt)},{header:"SUBSCRIBE (keep private)",get:(o)=>String(o.webcalUrl??o.url??"")}]);return}case"create":{let s=await a.createFeed(t,{scope:A(n,"scope",["org","member"])??"org",...n["show-names"]===!0&&{showCustomerNames:!0},...n["hide-names"]===!0&&{showCustomerNames:!1}});if(i)g(s);else process.stdout.write(E(`Subscribe in any calendar app (anyone with this link can read the calendar):
|
|
27
|
+
${String(s.webcalUrl??"")}
|
|
28
|
+
`));return}case"rotate":{let s=I(r[0],"vcity calendar feeds rotate <feedId>","feed id"),o=await a.updateFeed(t,s,{rotate:!0});if(i)g(o);else process.stdout.write(E(`New link (the old one stops working):
|
|
29
|
+
${String(o.webcalUrl??"")}
|
|
30
|
+
`));return}case"revoke":{let s=I(r[0],"vcity calendar feeds revoke <feedId> [--yes]","feed id");if(!await B(`Revoke calendar link ${s}? Subscribed apps stop updating.`,{yes:n.yes===!0,json:i}))return;let o=await a.revokeFeed(t,s);if(i)g(o);else process.stdout.write(`Revoked.
|
|
31
|
+
`);return}default:throw new y("usage: vcity calendar feeds list|create [--scope org|member] [--show-names]|rotate <id>|revoke <id>")}}async function Ji(t,e,r,n,i){let a=p().calendar;switch(e){case void 0:case"list":{let{data:s}=await a.listExternal(t);if(i)g({org:t,calendars:s});else k(s,[{header:"ID",get:(o)=>String(o.id)},{header:"NAME",get:(o)=>String(o.name??"")},{header:"BLOCKS",get:(o)=>o.blockAvailability?"yes":"no"},{header:"LAST SYNC",get:(o)=>x(o.lastSyncedAt??o.lastFetchedAt)},{header:"ERROR",get:(o)=>String(o.lastError??"")}]);return}case"add":{let s=G(m(n,"url"),"vcity calendar external add --name <s> --url <ics url> [--block]"),o=G(m(n,"name"),"vcity calendar external add --name <s> --url <ics url> [--block]"),c=await a.addExternal(t,{name:o,url:s,blockAvailability:n.block===!0});if(i)g(c);else process.stdout.write(`Imported ${E(o)}.
|
|
32
|
+
`);return}case"refresh":{let s=I(r[0],"vcity calendar external refresh <id>","calendar id"),o=await a.updateExternal(t,s,{refresh:!0});if(i)g(o);else process.stdout.write(`Refreshed.
|
|
33
|
+
`);return}case"remove":{let s=I(r[0],"vcity calendar external remove <id> [--yes]","calendar id");if(!await B(`Remove imported calendar ${s}?`,{yes:n.yes===!0,json:i}))return;let o=await a.removeExternal(t,s);if(i)g(o);else process.stdout.write(`Removed.
|
|
34
|
+
`);return}default:throw new y("usage: vcity calendar external list|add --name <s> --url <ics url> [--block]|refresh <id>|remove <id>")}}async function gs(t,e,r){let n=f(!!r.json)==="json",i=h(m(r,"org")),a=p().calendar;switch(t){case"list":{let s=M(r,"from")??mr(Date.now()),o=C(r,"days",{min:1,max:62})??7,c=M(r,"to")??s+o*us;if(c<=s)throw new y("--to must be after --from");if(c-s>62*us)throw new y("the calendar shows at most 62 days at a time");let{data:u}=await a.list(i,{from:s,to:c,...r["no-overlays"]===!0&&{overlays:"false"}});if(n)g({org:i,from:s,to:c,items:u});else _i(u);return}case"ics":{let{data:s}=await a.listFeeds(i),o=s,c=e[0]?o.find((v)=>v.id===e[0]):o[0];if(!c?.url)throw new y(e[0]?`no calendar link ${e[0]}`:"this store has no calendar link yet; create one with `vcity calendar feeds create`");let u=new URL(c.url).searchParams.get("token");if(!u)throw Error("calendar link has no token");let l=await a.ics(i,u),w=m(r,"output");if(w)Z(w,l),process.stderr.write(`Wrote ${E(w)}
|
|
35
|
+
`);else process.stdout.write(process.stdout.isTTY?E(l):l);return}case"feeds":return Vi(i,e[0],e.slice(1),r,n);case"external":return Ji(i,e[0],e.slice(1),r,n);case"add":{let c={...P(m(r,"data"))??{}};if(m(r,"title")!==void 0)c.title=m(r,"title");if(m(r,"description")!==void 0)c.description=m(r,"description");let u=M(r,"start"),l=M(r,"end");if(u!==void 0)c.startMillis=u;if(l!==void 0)c.endMillis=l;if(r["all-day"]===!0)c.allDay=!0;c.category=A(r,"category",["custom","timeoff","meeting","holiday"])??c.category??"custom";let w=A(r,"location",["virtual","physical"]);if(w)c.locationType=w;if(c.category==="meeting"&&c.locationType===void 0)throw new y("a meeting needs --location virtual|physical");if(typeof c.title!=="string"||typeof c.startMillis!=="number"||typeof c.endMillis!=="number")throw new y("usage: vcity calendar add --title <s> --start <date|ms> --end <date|ms> [--all-day] [--category custom|timeoff|meeting --location virtual|physical] [--description <s>] [--data <json>]");if(c.timezone===void 0)c.timezone=Intl.DateTimeFormat().resolvedOptions().timeZone;let v=await a.createEntry(i,c);if(n)g(v);else process.stdout.write(`Added ${E(String(c.title))}.
|
|
36
|
+
`);return}case"cancel":{let s=I(e[0],"vcity calendar cancel <entryId> [--scope single|following|all] [--yes]","entry id");if(!await B(`Cancel calendar entry ${s}?`,{yes:r.yes===!0,json:n}))return;let o=A(r,"scope",["single","following","all"]),c=await a.cancelEntry(i,s,o?{scope:o}:{});if(n)g(c);else process.stdout.write(`Cancelled.
|
|
37
|
+
`);return}case"holidays":{let s=A(r,"country",["CO","US","MX","ES","BR","AR","CL","PE"]),o=C(r,"year",{min:1970,max:2100}),c=await a.holidays(i,{...s&&{country:s},...o!==void 0&&{year:o}});if(n)g(c);else k(c.data,[{header:"DATE",get:(u)=>u.date},{header:"HOLIDAY",get:(u)=>u.name}]);return}case"settings":{let s=await a.settings(i);g(s);return}case"staff":{let s=await a.staff(i);if(n)g(s);else k(s.data??[],[{header:"UID",get:(o)=>String(o.uid??o.id??"")},{header:"NAME",get:(o)=>String(o.name??"")}]);return}default:throw new y(`usage: ${Gi}`)}}var Hi=86400000,Yi=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];async function ls(t){let e=h(m(t,"org")),r=M(t,"from")??mr(Date.now()),n=M(t,"to")??r+(C(t,"days",{min:1,max:62})??7)*Hi;if(n<=r)throw new y("--to must be after --from");let i=At(t,"type"),a=await p().bookings.slots(e,{from:r,to:n,...i!==void 0&&{bookingTypeId:i}});if(f(!!t.json)==="json"){g({org:e,from:r,to:n,...a});return}let s=a.slots;if(s.length===0){process.stdout.write(`No free slots in that range.
|
|
38
|
+
`);return}k(s,[{header:"START",get:(o)=>yt(o.start)},{header:"END",get:(o)=>yt(o.end).slice(11)}])}async function ps(t,e,r){let n=f(!!r.json)==="json",i=h(m(r,"org")),a=p().bookings;switch(t){case void 0:case"list":{let s=At(r,"uid"),o=M(r,"from"),c=M(r,"to"),{data:u}=await a.listUnavailability(i,{...s!==void 0&&{uid:s},...o!==void 0&&{from:o},...c!==void 0&&{to:c}});if(n)g({org:i,timeOff:u});else k(u,[{header:"ID",get:(l)=>l.id},{header:"MEMBER",get:(l)=>l.uid},{header:"FROM",get:(l)=>yt(l.startDate,l.allDay)},{header:"TO",get:(l)=>yt(l.endDate,l.allDay)},{header:"REASON",get:(l)=>`${l.reason??""}${l.recurring?" (yearly)":""}`}]);return}case"add":{let o=At(r,"uid"),c=M(r,"from"),u=M(r,"to");if(o===void 0||c===void 0||u===void 0)throw new y("usage: vcity bookings time-off add --uid <uid> --from <date|ms> --to <date|ms> [--reason <s>] [--all-day] [--recurring]");if(u<=c)throw new y("--to must be after --from");let l=await a.addUnavailability(i,{uid:o,startDate:c,endDate:u,...m(r,"reason")!==void 0&&{reason:m(r,"reason")},...r["all-day"]===!0&&{allDay:!0},...r.recurring===!0&&{recurring:!0}});if(n)g(l);else process.stdout.write(`Added time off ${l.id}.
|
|
39
|
+
`);return}case"remove":{let s=I(e[0],"vcity bookings time-off remove <id> [--yes]","time off id");if(!await B(`Remove time off ${s}?`,{yes:r.yes===!0,json:n}))return;let o=await a.removeUnavailability(i,s);if(n)g(o);else process.stdout.write(`Removed.
|
|
40
|
+
`);return}default:throw new y("usage: vcity bookings time-off list [--uid] [--from] [--to] | add --uid --from --to | remove <id>")}}async function ms(t,e){let r=f(!!e.json)==="json",n=h(m(e,"org")),i=I(t[0],"vcity bookings hours <uid> [--data <json|@file|->]","uid"),a=p().bookings,s=P(m(e,"data")),o;if(s!==void 0){let u=Array.isArray(s)?{workingHours:s}:s;if(typeof u!=="object"||u===null)throw new y('--data must be a workingHours array or {"workingHours":[…]}');o=await a.setMemberHours(n,i,u)}else o=await a.getMemberHours(n,i);if(r){g(o);return}let c=o.workingHours;if(!c){process.stdout.write(`Uses the store hours (no personal schedule).
|
|
41
|
+
`);return}k(c,[{header:"DAY",get:(u)=>Yi[u.dayOfWeek]??String(u.dayOfWeek)},{header:"HOURS",get:(u)=>u.isWorkingDay?`${u.startTime}–${u.endTime}`:"off"}])}var fs=new Set(["urgent-important","not-urgent-important","urgent-not-important","not-urgent-not-important"]);function ys(t,e){if(/^-?\d+$/.test(t)){let n=Number(t);if(Number.isFinite(n))return n}let r=Date.parse(t);if(Number.isFinite(r))return r;throw Error(`${e}: expected ISO 8601 or epoch ms (got: ${t})`)}function ht(t,e){if(!t)throw Error(`cards ${e}: --project <id> is required`);return t}function hs(t){if(t!==void 0&&!fs.has(t))throw Error(`Invalid priority: ${t}. Allowed: ${[...fs].join(", ")}`)}async function ws(t={}){let e=f(t.json),r=h(t.org),n=ht(t.project,"list"),i={};if(t.limit!==void 0)i.limit=t.limit;if(t.column!==void 0)i.columnId=t.column;if(t.assignee!==void 0)i.assignee=t.assignee;if(t.archived)i.includeArchived=!0;let s=await p().projects.listCards(r,n,i),o=s.data??[];if(e==="json"){g({org:r,project:n,cards:o,total:s.total,skip:s.skip,limit:s.limit,hasMore:s.hasMore});return}k(o,[{header:"CODE",get:(c)=>c.code??""},{header:"TITLE",get:(c)=>c.title??""},{header:"COLUMN",get:(c)=>c.columnId??""},{header:"PRIORITY",get:(c)=>c.priority??""},{header:"ASSIGNEES",get:(c)=>(c.assignees??[]).join(",")},{header:"DUE",get:(c)=>c.dueDate!==void 0?new Date(c.dueDate).toISOString().slice(0,10):""},{header:"ID",get:(c)=>c.id}])}async function vs(t,e={}){let r=f(e.json),n=h(e.org),i=ht(e.project,"get"),s=await p().projects.getCard(n,i,t);if(r==="json"){g(s);return}j(s)}async function bs(t={}){let e=f(t.json),r=h(t.org),n=ht(t.project,"create");hs(t.priority);let i=P(t.data),a=i&&typeof i==="object"?{...i}:{};if(t.title!==void 0)a.title=t.title;if(t.column!==void 0)a.columnId=t.column;if(t.description!==void 0)a.description=t.description;if(t.priority!==void 0)a.priority=t.priority;if(t.due!==void 0)a.dueDate=ys(t.due,"--due");if(t.assignee!==void 0)a.assignees=[t.assignee];if(t.order!==void 0)a.order=t.order;if(a.title===void 0)throw Error("cards create: --title is required (or supply it via --data)");if(a.columnId===void 0)throw Error("cards create: --column is required (or supply it via --data)");let o=await p().projects.createCard(r,n,a);if(e==="json"){g(o);return}process.stdout.write(`Created card:
|
|
42
|
+
`),j(o)}async function ks(t,e={}){let r=f(e.json),n=h(e.org),i=ht(e.project,"update");hs(e.priority);let a=P(e.data),s=a&&typeof a==="object"?{...a}:{};if(e.title!==void 0)s.title=e.title;if(e.column!==void 0)s.columnId=e.column;if(e.description!==void 0)s.description=e.description;if(e.priority!==void 0)s.priority=e.priority;if(e.due!==void 0)s.dueDate=ys(e.due,"--due");if(e.assignee!==void 0)s.assignees=[e.assignee];if(e.archived!==void 0)s.archived=e.archived;if(Object.keys(s).length===0)throw Error("cards update: nothing to update (pass at least one field or --data)");let c=await p().projects.updateCard(n,i,t,s);if(r==="json"){g(c);return}process.stdout.write(`Updated card:
|
|
43
|
+
`),j(c)}async function Is(t,e={}){let r=f(e.json),n=h(e.org),i=ht(e.project,"move");if(!e.column)throw Error("cards move: --column <columnId> is required");let a={columnId:e.column};if(e.order!==void 0)a.order=e.order;let o=await p().projects.moveCard(n,i,t,a);if(r==="json"){g(o);return}process.stdout.write(`Moved card to ${e.column}:
|
|
44
|
+
`),j(o)}async function js(t,e={}){let r=f(e.json),n=h(e.org),i=ht(e.project,"delete");if(!e.yes){if(r==="json")throw Error("cards delete: --yes is required in JSON / non-interactive mode");if(!await _(`Delete card ${t} in project ${i}? [y/N]`)){process.stdout.write(`Aborted.
|
|
45
|
+
`);return}}let s=await p().projects.deleteCard(n,i,t);if(r==="json"){g(s);return}process.stdout.write(`Deleted card ${t}.
|
|
46
|
+
`)}async function Ts(t,e={}){let r=f(e.json),n=h(e.org),i=ht(e.project,"comments"),s=await p().projects.listCardComments(n,i,t,e.limit!==void 0?{limit:e.limit}:{}),o=s.data??[];if(r==="json"){g({org:n,project:i,card:t,comments:o,total:s.total,skip:s.skip,limit:s.limit,hasMore:s.hasMore});return}k(o,[{header:"AUTHOR",get:(c)=>c.authorName||(c.authorUid??"")},{header:"COMMENT",get:(c)=>c.content??""},{header:"AT",get:(c)=>c.createdAt!==void 0?new Date(c.createdAt).toISOString():""},{header:"ID",get:(c)=>c.id}])}async function Es(t,e={}){let r=f(e.json),n=h(e.org),i=ht(e.project,"comment");if(!e.message)throw Error("cards comment: --message <text> is required");let s=await p().projects.createCardComment(n,i,t,{content:e.message});if(r==="json"){g(s);return}process.stdout.write(`Posted comment:
|
|
47
|
+
`),j(s)}async function Rs(t={}){let e=f(t.json),r=h(t.org),n={};if(t.limit!==void 0)n.limit=t.limit;if(t.search!==void 0)n.search=t.search;if(t.status!==void 0)n.status=t.status;let a=await p().events.list(r,n),s=a.data??[];if(e==="json"){g({org:r,events:s,total:a.total,skip:a.skip,limit:a.limit,hasMore:a.hasMore});return}k(s,[{header:"ID",get:(o)=>o.id},{header:"NAME",get:(o)=>o.name??""},{header:"STARTS_AT",get:(o)=>o.startsAt!==void 0?new Date(o.startsAt).toISOString():""},{header:"STATUS",get:(o)=>o.status??""},{header:"CATEGORIES",get:(o)=>(o.categories??[]).join(",")}])}async function Cs(t,e={}){let r=f(e.json),n=h(e.org),a=await p().events.get(n,t);if(r==="json"){g(a);return}j(a)}function Je(t,e){if(/^-?\d+$/.test(t)){let n=Number(t);if(Number.isFinite(n))return n}let r=Date.parse(t);if(Number.isFinite(r))return r;throw Error(`${e}: expected ISO 8601 or epoch ms (got: ${t})`)}async function Ss(t={}){let e=f(t.json),r=h(t.org),n=P(t.data),i=n&&typeof n==="object"?{...n}:{};if(t.name!==void 0)i.name=t.name;if(t.slug!==void 0)i.slug=t.slug;if(t.startsAt!==void 0)i.startsAt=Je(t.startsAt,"--starts-at");if(t.endsAt!==void 0)i.endsAt=Je(t.endsAt,"--ends-at");if(i.name===void 0)throw Error("events create: --name is required (or supply it via --data)");let s=await p().events.create(r,i);if(e==="json"){g(s);return}process.stdout.write(`Created event:
|
|
48
|
+
`),j(s)}async function Os(t,e={}){let r=f(e.json),n=h(e.org),i=P(e.data),a=i&&typeof i==="object"?{...i}:{};if(e.name!==void 0)a.name=e.name;if(e.slug!==void 0)a.slug=e.slug;if(e.status!==void 0)a.status=e.status;if(e.startsAt!==void 0)a.startsAt=Je(e.startsAt,"--starts-at");if(e.endsAt!==void 0)a.endsAt=Je(e.endsAt,"--ends-at");if(Object.keys(a).length===0)throw Error("events update: nothing to update (pass at least one field or --data)");let o=await p().events.update(n,t,a);if(r==="json"){g(o);return}process.stdout.write(`Updated event:
|
|
49
|
+
`),j(o)}async function xs(t,e={}){let r=f(e.json),n=h(e.org);if(!e.yes){if(r==="json")throw Error("events delete: --yes is required in JSON / non-interactive mode");if(!await _(`Delete event ${t} in org ${n}? [y/N]`)){process.stdout.write(`Aborted.
|
|
50
|
+
`);return}}let a=await p().events.delete(n,t);if(r==="json"){g(a);return}process.stdout.write(`Deleted event ${t}.
|
|
51
|
+
`)}function wt(t){return[...t].sort((e,r)=>(e.createdAt??0)-(r.createdAt??0)).map((e)=>{let r=e.mine?"you":e.sender?.name??"customer",n=e.deleted?"(deleted)":e.content??"",i=(e.files??[]).map((a)=>` [file: ${a.name??a.url??""}]`).join("");return E(`${x(e.createdAt)} ${r}: ${n}${i}`)}).join(`
|
|
52
|
+
`)}var Qi="vcity inbox list|show|search|reply|assign|close|reopen|read|customer|unread (reply: vcity inbox reply <id> --message <s> | --quick-reply <shortcut>)";function He(t){return t.trim().replace(/^\//,"").toLowerCase()}async function Wi(t,e){let{data:r}=await p().quickReplies.list(t),n=He(e),i=r.find((a)=>a.id===e||a.shortcut&&He(a.shortcut)===n);if(!i)throw new y(`no quick reply with id or shortcut "${e}" (see \`vcity quick-replies list\`)`);return i.body}async function As(t,e,r){let n=f(!!r.json)==="json",i=h(m(r,"org")),a=p();switch(t){case"list":{let s=await a.inbox.list(i,{...A(r,"status",["open","closed","all"])&&{status:A(r,"status",["open","closed","all"])},...m(r,"assigned-to")!==void 0&&{assignedTo:m(r,"assigned-to")},...C(r,"limit",{min:1,max:200})!==void 0&&{limit:C(r,"limit")},...C(r,"skip")!==void 0&&{skip:C(r,"skip")}});if(n)g({org:i,conversations:s.data,total:s.total,skip:s.skip,limit:s.limit,hasMore:s.hasMore});else k(s.data,[{header:"ID",get:(o)=>o.id},{header:"",get:(o)=>o.unread?"●":""},{header:"STATUS",get:(o)=>o.status??""},{header:"CUSTOMER",get:(o)=>o.contactName??o.contactEmail??""},{header:"CHANNEL",get:(o)=>o.messagingChannel??""},{header:"UPDATED",get:(o)=>x(o.updatedAt)},{header:"LAST MESSAGE",get:(o)=>String(o.lastMessage?.content??"").slice(0,60)}]);return}case"show":{let s=I(e[0],"vcity inbox show <conversationId> [--limit <n>]","conversation id"),[{conversation:o},c]=await Promise.all([a.inbox.get(i,s),a.inbox.listMessages(i,s,{...C(r,"limit",{min:1,max:200})!==void 0&&{limit:C(r,"limit")}})]);if(n)g({conversation:o,messages:c.data,hasMore:c.hasMore});else{let u=o;process.stdout.write(E(`${String(u.contactName??u.contactEmail??s)} · ${String(u.status??"")}
|
|
53
|
+
|
|
54
|
+
`)+`${wt(c.data)}
|
|
55
|
+
`)}return}case"search":{let s=I(e[0],"vcity inbox search <conversationId> --query <text>","conversation id"),o=m(r,"query")??e.slice(1).join(" ");if(!o||o.trim().length<2)throw new y("usage: vcity inbox search <conversationId> --query <text> (2+ characters)");let c=await a.inbox.search(i,s,o);if(n)g(c);else process.stdout.write(`${wt(c.data)}
|
|
56
|
+
`);return}case"reply":{let s=I(e[0],"vcity inbox reply <conversationId> --message <s>","conversation id"),o=m(r,"quick-reply"),c=o?await Wi(i,o):G(m(r,"message"),"vcity inbox reply <conversationId> --message <s> | --quick-reply <shortcut>"),u=await a.inbox.reply(i,s,{content:c,...m(r,"reply-to")&&{replyToId:m(r,"reply-to")}});if(n)g(u);else process.stdout.write(`Sent.
|
|
57
|
+
`);return}case"assign":{let s=I(e[0],"vcity inbox assign <conversationId> <uid|me> | --unassign","conversation id"),o=r.unassign===!0?null:I(e[1],"vcity inbox assign <conversationId> <uid>","uid"),c=await a.inbox.update(i,s,{assignedTo:o});if(n)g(c);else process.stdout.write(o?`Assigned to ${o}.
|
|
58
|
+
`:`Unassigned.
|
|
59
|
+
`);return}case"close":case"reopen":{let s=I(e[0],`vcity inbox ${t} <conversationId>`,"conversation id"),o=await a.inbox.update(i,s,{status:t==="close"?"closed":"open"});if(n)g(o);else process.stdout.write(t==="close"?`Closed.
|
|
60
|
+
`:`Reopened.
|
|
61
|
+
`);return}case"read":{let s=I(e[0],"vcity inbox read <conversationId>","conversation id"),o=await a.inbox.markRead(i,s);if(n)g(o);else process.stdout.write(`Marked read.
|
|
62
|
+
`);return}case"customer":{let s=I(e[0],"vcity inbox customer <conversationId>","conversation id"),o=await a.inbox.customer(i,s);if(n)g(o);else j(o);return}case"unread":{let{count:s}=await a.inbox.unreadCount(i);if(n)g({org:i,count:s});else process.stdout.write(`${s}
|
|
63
|
+
`);return}default:throw new y(`usage: ${Qi}`)}}async function Ps(t,e,r){let n=f(!!r.json)==="json",i=h(m(r,"org")),a=p().quickReplies,s=m(r,"shortcut");switch(t){case"list":{let{data:o}=await a.list(i);if(n)g({org:i,quickReplies:o});else k(o,[{header:"ID",get:(c)=>c.id},{header:"SHORTCUT",get:(c)=>c.shortcut??""},{header:"TITLE",get:(c)=>c.title},{header:"BODY",get:(c)=>c.body.replace(/\s+/g," ").slice(0,60)}]);return}case"create":{let o=G(m(r,"title"),"vcity quick-replies create --title <s> --body <s> [--shortcut <s>]"),c=G(m(r,"body"),"vcity quick-replies create --title <s> --body <s> [--shortcut <s>]"),u=await a.create(i,{title:o,body:c,...s!==void 0&&{shortcut:s}});if(n)g(u);else process.stdout.write(`Created quick reply ${E(String(u.id??""))}.
|
|
64
|
+
`);return}case"update":{let o=I(e[0],"vcity quick-replies update <id> [--title] [--body] [--shortcut]","quick reply id"),c={...m(r,"title")!==void 0&&{title:m(r,"title")},...m(r,"body")!==void 0&&{body:m(r,"body")},...s!==void 0&&{shortcut:s===""?null:s}};if(Object.keys(c).length===0)throw new y("quick-replies update: nothing to change");let u=await a.update(i,o,c);if(n)g(u);else process.stdout.write(`Updated quick reply ${o}.
|
|
65
|
+
`);return}case"delete":{let o=I(e[0],"vcity quick-replies delete <id> [--yes]","quick reply id");if(!await B(`Delete quick reply ${o}?`,{yes:r.yes===!0,json:n}))return;let c=await a.delete(i,o);if(n)g(c);else process.stdout.write(`Deleted quick reply ${o}.
|
|
66
|
+
`);return}case"export":{let{data:o}=await a.list(i);g(o.map((c)=>({title:c.title,body:c.body,shortcut:c.shortcut??null})));return}case"import":{let o=e[0];if(!o)throw new y("usage: vcity quick-replies import <file.json> (the output of `quick-replies export`)");let c;try{c=JSON.parse(st(o))}catch(T){if(T instanceof y)throw T;throw new y(`${o}: invalid JSON`)}if(!Array.isArray(c))throw new y(`${o}: expected a JSON array`);let u=(await a.list(i)).data,l=new Set(u.flatMap((T)=>T.shortcut?[He(T.shortcut)]:[])),w=new Set(u.map((T)=>T.title.trim().toLowerCase())),v=[];for(let T of c){if(typeof T?.title!=="string"||typeof T.body!=="string"){v.push({title:String(T?.title??""),action:"error",error:"needs title and body"});continue}let N=T.shortcut?He(T.shortcut):void 0,F=T.title.trim().toLowerCase();if(N?l.has(N):w.has(F)){v.push({title:T.title,action:"skip"});continue}try{await a.create(i,{title:T.title,body:T.body,...N&&{shortcut:N}}),v.push({title:T.title,action:"create"})}catch(D){if(D.status===409)v.push({title:T.title,action:"skip"});else v.push({title:T.title,action:"error",error:D.message})}if(N)l.add(N);w.add(F)}if(n)g({org:i,results:v});else k(v,[{header:"TITLE",get:(T)=>T.title},{header:"RESULT",get:(T)=>T.action},{header:"ERROR",get:(T)=>T.error??""}]);let R=v.filter((T)=>T.action==="error").length;if(R>0)throw Error(`${R} of ${v.length} quick replies failed`);return}default:throw new y("usage: vcity quick-replies list|create|update|delete|export|import")}}var $s="vcity chat rooms|members|messages <room>|send <room> --message <s>|thread <room> <messageId>|react|unreact <room> <messageId> <emoji>|search <text>|read <room>|channel create --name <s>|channel rename|delete <channelId>|dm <uid> (<room> is a room id or #channel-slug)";async function Ft(t,e){if(!e)throw new y(`usage: ${$s}`);if(!e.startsWith("#"))return O(e,"room id");let r=e.slice(1),{channels:n}=await p().teamChat.listRooms(t),i=n.find((a)=>a.slug===r||a.name===r);if(!i)throw new y(`no channel #${r} (see \`vcity chat rooms\`)`);return i.id}async function Ds(t,e,r){let n=f(!!r.json)==="json",i=h(m(r,"org")),a=p().teamChat;switch(t){case"rooms":{let s=await a.listRooms(i);if(n)g(s);else k([...s.channels.map((o)=>({...o,name:`#${o.slug??o.name}`})),...s.dms],[{header:"ID",get:(o)=>o.id},{header:"ROOM",get:(o)=>o.name??""},{header:"UNREAD",get:(o)=>String(o.unreadCount??0)},{header:"@",get:(o)=>String(o.mentionCount??0)}]);return}case"members":{let{data:s}=await a.members(i);if(n)g({org:i,members:s});else k(s,[{header:"UID",get:(o)=>o.uid},{header:"NAME",get:(o)=>o.name??""},{header:"ROLE",get:(o)=>o.role??""}]);return}case"messages":{let s=await Ft(i,e[0]),o=C(r,"before"),c=m(r,"before-id");if(o===void 0!==(c===void 0))throw new y("--before <ms> and --before-id <messageId> go together (the oldest message you have)");let u=await a.listMessages(i,s,{...C(r,"limit",{min:1,max:200})!==void 0&&{limit:C(r,"limit")},...o!==void 0&&c!==void 0&&{beforeTs:o,beforeId:c}});if(n)g({roomId:s,messages:u.data,hasMore:u.hasMore});else process.stdout.write(`${wt(u.data)}
|
|
67
|
+
`);return}case"send":{let s=await Ft(i,e[0]),o=G(m(r,"message"),"vcity chat send <room> --message <s> [--reply-to <id>] [--mention uid,uid]"),c=q(r,"mention"),u=await a.send(i,s,{content:o,...m(r,"reply-to")!==void 0&&{replyToId:m(r,"reply-to")},...c&&{mentionIds:c}});if(n)g(u);else process.stdout.write(`Sent.
|
|
68
|
+
`);return}case"thread":{let s=await Ft(i,e[0]),o=I(e[1],"vcity chat thread <room> <messageId>","message id"),c=await a.thread(i,s,o);if(n)g(c);else{let u=c;process.stdout.write(`${wt([u.root,...u.replies??[]].filter(Boolean))}
|
|
69
|
+
`)}return}case"react":case"unreact":{let s=await Ft(i,e[0]),o=I(e[1],`vcity chat ${t} <room> <messageId> <emoji>`,"message id"),c=G(e[2],`vcity chat ${t} <room> <messageId> <emoji>`),u=t==="unreact"?await a.unreact(i,s,o,c):await a.react(i,s,o,c);if(n)g(u);else process.stdout.write(t==="unreact"?`Reaction removed.
|
|
70
|
+
`:`Reacted.
|
|
71
|
+
`);return}case"search":{let s=G(e.join(" ")||m(r,"q"),"vcity chat search <text>"),{data:o}=await a.search(i,{q:s});if(n)g({org:i,results:o});else k(o,[{header:"ROOM",get:(c)=>c.roomId},{header:"WHEN",get:(c)=>x(c.message.createdAt)},{header:"FROM",get:(c)=>String(c.message.sender?.name??"")},{header:"MESSAGE",get:(c)=>String(c.message.content??"").slice(0,80)}]);return}case"read":{let s=await Ft(i,e[0]),o=await a.markRead(i,s);if(n)g(o);else process.stdout.write(`Marked read.
|
|
72
|
+
`);return}case"channel":{if(e[0]==="rename"||e[0]==="delete"){let c=I(e[1],`vcity chat channel ${e[0]} <channelId>`,"channel id"),u=e[0]==="delete"?await a.deleteChannel(i,c):await a.updateChannel(i,c,{...m(r,"name")!==void 0&&{name:m(r,"name")},...m(r,"description")!==void 0&&{description:m(r,"description")}});if(n)g(u);else process.stdout.write(e[0]==="delete"?`Deleted.
|
|
73
|
+
`:`Updated.
|
|
74
|
+
`);return}if(e[0]!=="create")throw new y("usage: vcity chat channel create --name <s> [--description <s>] | rename <channelId> [--name <s>] [--description <s>] | delete <channelId>");let s=G(m(r,"name"),"vcity chat channel create --name <s> [--description <s>]"),o=await a.createChannel(i,{name:s,...m(r,"description")!==void 0&&{description:m(r,"description")}});if(n)g(o);else process.stdout.write(`Created #${E(s)}.
|
|
75
|
+
`);return}case"dm":{let s=I(e[0],"vcity chat dm <uid>","uid"),o=await a.openDm(i,{memberId:s});if(n)g(o);else process.stdout.write(`DM room ${E(String(o.id??""))}. Send with \`vcity chat send ${E(String(o.id??""))} --message …\`
|
|
76
|
+
`);return}default:throw new y(`usage: ${$s}`)}}function zi(t){let e=[],r=[],n="",i=!1,a=1,s=1,o=t.charCodeAt(0)===65279?1:0;for(;o<t.length;o++){let c=t[o];if(c===`
|
|
77
|
+
`)a++;if(i){if(c==='"'&&t[o+1]==='"')n+='"',o++;else if(c==='"')i=!1;else n+=c;continue}if(c==='"'&&n==="")i=!0;else if(c===",")r.push(n),n="";else if(c===`
|
|
78
|
+
`||c==="\r"){if(c==="\r"&&t[o+1]===`
|
|
79
|
+
`)o++,a++;else if(c==="\r")a++;r.push(n),e.push({line:s,cells:r}),r=[],n="",s=a}else n+=c}if(i)throw Error("CSV: unterminated quoted field");if(n!==""||r.length>0)r.push(n),e.push({line:s,cells:r});return e.filter((c)=>c.cells.some((u)=>u.trim()!==""))}function Ye(t){let[e,...r]=zi(t);if(!e)return[];let n=e.cells.map((i)=>i.trim());return r.map(({line:i,cells:a})=>({line:i,record:Object.fromEntries(n.map((s,o)=>[s,Ki(a[o]??"")]))}))}var Ns=/^[=+\-@\t\r]/;function Ki(t){return t.startsWith("'")&&Ns.test(t.slice(1))?t.slice(1):t}function Xi(t){if(t===void 0||t===null)return"";if(typeof t==="number"||typeof t==="boolean")return String(t);let e=typeof t==="object"?JSON.stringify(t):String(t);if(Ns.test(e))e=`'${e}`;return/[",\r\n]/.test(e)?`"${e.replace(/"/g,'""')}"`:e}function Qe(t,e){return[t,...e].map((r)=>r.map(Xi).join(",")).join(`\r
|
|
80
|
+
`)+`\r
|
|
81
|
+
`}var hr=["name","email","phone","company","jobTitle","website","address","whatsapp","facebook","twitter","linkedin","instagram","notes","tags","source","lang"],Fs=["lastInteraction","totalInteractions","score","name"],Bs="vcity crm contacts list|get|create|update|archive|restore|tag|timeline|export|import · vcity crm tags list|create · vcity crm follow-ups · vcity crm audiences [<id>]";function Us(t){let e=P(m(t,"data"));if(e!==void 0&&(typeof e!=="object"||e===null||Array.isArray(e)))throw new y("--data must be a JSON object");let r={...e},n={jobTitle:"job-title"};for(let a of hr){if(a==="tags")continue;let s=m(t,n[a]??a);if(s!==void 0)r[a]=s}let i=q(t,"tags");if(i)r.tags=i;return r}function yr(t){k(t,[{header:"ID",get:(e)=>e.id},{header:"NAME",get:(e)=>e.name??""},{header:"EMAIL",get:(e)=>e.email??""},{header:"COMPANY",get:(e)=>e.company??""},{header:"TAGS",get:(e)=>(e.tags??[]).join(",")},{header:"LAST SEEN",get:(e)=>x(e.lastInteraction)}])}function fr(t){return{...m(t,"q")!==void 0&&{q:m(t,"q")},...q(t,"tags")&&{tags:q(t,"tags")?.join(",")},...A(t,"sort",Fs)&&{sort:A(t,"sort",Fs)},...t.archived===!0&&{includeArchived:"true"}}}function Zi(t){let e=["id",...hr,"createdAt","lastInteraction","totalInteractions"];return Qe(e,t.map((r)=>e.map((n)=>{let i=r[n];if(Array.isArray(i))return i.join("|");if((n==="createdAt"||n==="lastInteraction")&&typeof i==="number")return new Date(i).toISOString();return i})))}function ta(t){let e={};for(let[r,n]of Object.entries(t)){let i=n.trim();if(i===""||r==="id"||r==="createdAt"||r==="lastInteraction"||r==="totalInteractions")continue;if(!hr.includes(r))throw Error(`unknown column "${r}"`);e[r]=r==="tags"?i.split("|").map((a)=>a.trim()).filter(Boolean):i}return e}function ea(t){let e=[];for(let[r,n]of Object.entries(t)){if(!Array.isArray(n))continue;for(let i of n){let a=[i.registerDate,i.createdAt,i.at,i.date].find((o)=>typeof o==="number"),s=Object.entries(i).filter(([o,c])=>!["registerDate","createdAt","at","date"].includes(o)&&c!==void 0&&c!==null).map(([o,c])=>`${o}=${typeof c==="object"?JSON.stringify(c):String(c)}`).join(" ");e.push({kind:r,at:a,detail:s})}}return e.sort((r,n)=>(n.at??0)-(r.at??0))}async function ra(t){let{data:e}=await p().crm.listTags(t);return(r)=>{let n=r.toLowerCase(),i=e.find((a)=>a.id===r||a.slug?.toLowerCase()===n||a.name?.toLowerCase()===n);if(!i)throw new y(`no CRM tag "${r}" (see \`vcity crm tags list\`)`);return i.id}}async function sa(t,e,r,n){let i=Ye(st(e));if(i.length===0)throw new y(`${e}: no contact rows`);let a=p(),s=new Map,o=new Set,c=new Set;for(let T of await ut(async(N,F)=>{let D=await a.crm.listContacts(t,{skip:N,limit:F,includeArchived:"true"});return{data:D.data,hasMore:D.hasMore}})){if(T.isCustom===!1){if(T.email)c.add(T.email.toLowerCase());continue}if(o.add(T.id),T.email)s.set(T.email.toLowerCase(),T.id)}let u=r["dry-run"]===!0,l=[];for(let{line:T,record:N}of i){let F;try{F=ta(N)}catch(kt){l.push({row:T,action:"error",error:kt.message});continue}let D=typeof F.email==="string"?F.email:void 0,X=N.id?.trim(),L=X&&o.has(X)?X:D?s.get(D.toLowerCase()):void 0;if(!L&&D&&c.has(D.toLowerCase())){l.push({row:T,email:D,action:"skip",error:"matches a platform contact, which cannot be edited"});continue}if(!L&&typeof F.name!=="string"){l.push({row:T,email:D,action:"error",error:"a new contact needs a name"});continue}let rt=L?"update":"create";if(u){if(D&&!L)s.set(D.toLowerCase(),"(new)");l.push({row:T,email:D,action:rt,id:L==="(new)"?void 0:L});continue}try{let It=(L?await a.crm.updateContact(t,L,F):await a.crm.createContact(t,{source:"csv",...F})).id??L;if(D&&It)s.set(D.toLowerCase(),It);l.push({row:T,email:D,action:rt,id:It})}catch(kt){l.push({row:T,email:D,action:"error",error:kt.message})}}let w=l.filter((T)=>T.action==="error"),v={org:t,dryRun:u,total:l.length,created:l.filter((T)=>T.action==="create").length,updated:l.filter((T)=>T.action==="update").length,skipped:l.filter((T)=>T.action==="skip").length,failed:w.length},R=m(r,"report");if(R)Z(R,`${JSON.stringify({...v,rows:l},null,2)}
|
|
82
|
+
`);if(n)g({...v,rows:l});else if(process.stdout.write(`${u?"Dry run: ":""}created ${v.created}, updated ${v.updated}, skipped ${v.skipped}, failed ${v.failed} of ${v.total}.
|
|
83
|
+
`),w.length>0)k(w,[{header:"ROW",get:(T)=>String(T.row)},{header:"EMAIL",get:(T)=>T.email??""},{header:"ERROR",get:(T)=>T.error??""}]);if(w.length>0)throw Error(`${w.length} of ${l.length} rows failed`)}async function na(t,e,r){let n=f(!!r.json)==="json",i=h(m(r,"org")),a=p();switch(t){case"list":{if(r.all===!0){let o=await ut(async(c,u)=>{let l=await a.crm.listContacts(i,{...fr(r),skip:c,limit:u});return{data:l.data,hasMore:l.hasMore}});if(n)g({org:i,contacts:o,total:o.length});else yr(o);return}let s=await a.crm.listContacts(i,{...fr(r),...C(r,"limit",{min:1,max:200})!==void 0&&{limit:C(r,"limit")},...C(r,"skip")!==void 0&&{skip:C(r,"skip")}});if(n)g({org:i,contacts:s.data,total:s.total,skip:s.skip,limit:s.limit,hasMore:s.hasMore});else yr(s.data);return}case"get":{let s=I(e[0],"vcity crm contacts get <id>","contact id"),o=await a.crm.getContact(i,s);if(n)g(o);else j(o);return}case"create":{let s=Us(r);if(typeof s.name!=="string")throw new y("usage: vcity crm contacts create --name <s> [--email …]");let o=await a.crm.createContact(i,s);if(n)g(o);else process.stdout.write(`Created contact ${E(String(o.id))}.
|
|
84
|
+
`);return}case"update":{let s=I(e[0],"vcity crm contacts update <id> [--name …]","contact id"),o=Us(r);if(Object.keys(o).length===0)throw new y("crm contacts update: nothing to change");let c=await a.crm.updateContact(i,s,o);if(n)g(c);else process.stdout.write(`Updated contact ${s}.
|
|
85
|
+
`);return}case"archive":{let s=I(e[0],"vcity crm contacts archive <id> [--yes]","contact id");if(!await B(`Archive contact ${s} in ${i}?`,{yes:r.yes===!0,json:n}))return;let o=await a.crm.archiveContact(i,s);if(n)g(o);else process.stdout.write(`Archived contact ${s} (restore with \`vcity crm contacts restore ${s}\`).
|
|
86
|
+
`);return}case"restore":{let s=I(e[0],"vcity crm contacts restore <id>","contact id"),o=await a.crm.restoreContact(i,s);if(n)g(o);else process.stdout.write(`Restored contact ${s}.
|
|
87
|
+
`);return}case"tag":{let s=I(e[0],"vcity crm contacts tag <id> [--add a,b] [--remove c]","contact id"),o=q(r,"add"),c=q(r,"remove");if(!o&&!c)throw new y("usage: vcity crm contacts tag <id> [--add a,b] [--remove c]");let u=await ra(i),l=o?.map(u),w=c?.map(u),v=await a.crm.setContactTags(i,s,{...l&&{add:l},...w&&{remove:w}});if(n)g(v);else j(v);return}case"timeline":{let s=I(e[0],"vcity crm contacts timeline <id>","contact id"),o=await a.crm.contactTimeline(i,s);if(n)g(o);else k(ea(o),[{header:"WHEN",get:(c)=>x(c.at)},{header:"KIND",get:(c)=>c.kind},{header:"DETAIL",get:(c)=>c.detail}]);return}case"export":{let s=await ut(async(u,l)=>{let w=await a.crm.listContacts(i,{...fr(r),skip:u,limit:l});return{data:w.data,hasMore:w.hasMore}}),o=A(r,"format",["csv","json"])==="json"?`${JSON.stringify(s,null,2)}
|
|
88
|
+
`:Zi(s),c=m(r,"output");if(c)Z(c,o),process.stderr.write(`Wrote ${s.length} contacts to ${E(c)}
|
|
89
|
+
`);else process.stdout.write(process.stdout.isTTY?E(o):o);return}case"import":{let s=e[0];if(!s)throw new y("usage: vcity crm contacts import <file.csv> [--dry-run] [--report <file>]");return sa(i,s,r,n)}default:throw new y(`usage: ${Bs}`)}}async function Ms(t,e,r){if(t==="contacts")return na(e[0],e.slice(1),r);let n=f(!!r.json)==="json",i=h(m(r,"org")),a=p();if(t==="tags"){if(e[0]==="create"){let s=m(r,"name")??e[1];if(!s)throw new y("usage: vcity crm tags create --name <s> [--color <hex>]");let o=m(r,"color"),c=await a.crm.createTag(i,{name:s,...o!==void 0&&{color:o}});if(n)g(c);else process.stdout.write(`Created tag ${E(s)}.
|
|
90
|
+
`);return}if(e[0]===void 0||e[0]==="list"){let s=await a.crm.listTags(i);if(n)g(s);else k(s.data??[],[{header:"ID",get:(o)=>String(o.id??"")},{header:"SLUG",get:(o)=>String(o.slug??"")},{header:"NAME",get:(o)=>String(o.name??"")},{header:"CONTACTS",get:(o)=>String(o.contactCount??"")}]);return}}if(t==="follow-ups"){let s=M(r,"due-before"),o=await a.crm.listFollowUps(i,{...s!==void 0&&{dueBefore:s},...C(r,"limit",{min:1,max:200})!==void 0&&{limit:C(r,"limit")}});if(n)g(o);else k(o.data,[{header:"DUE",get:(c)=>x(c.dueDate)},{header:"CARD",get:(c)=>c.code},{header:"TITLE",get:(c)=>c.title},{header:"CONTACTS",get:(c)=>c.contacts.map((u)=>u.name).join(", ")}]);return}if(t==="audiences"){if(e[0]){let o=I(e[0],"vcity crm audiences <id>","audience id"),c=await a.crm.listAudienceContacts(i,o,{});if(n)g(c);else yr(c.data);return}let s=await a.crm.listAudiences(i);if(n)g(s);else k(s.data??[],[{header:"ID",get:(o)=>String(o.id??"")},{header:"NAME",get:(o)=>String(o.name??"")},{header:"TYPE",get:(o)=>String(o.type??"")},{header:"CONTACTS",get:(o)=>String(o.contactCount??"")}]);return}throw new y(`usage: ${Bs}`)}var oa=["mac","windows","linux"];function ia(){if(process.platform==="darwin")return"mac";if(process.platform==="win32")return"windows";return"linux"}async function Ls(t,e){let r=f(!!e.json)==="json",n=p();if(t==="latest"){let i=await n.desk.latest();if(r)g(i);else j(i);return}if(t==="download"){let i=A(e,"os",oa)??ia(),a=await n.desk.downloadUrl(i);if(r)g({os:i,url:a});else process.stdout.write(`${E(a)}
|
|
91
|
+
`);return}throw new y("usage: vcity desk latest | vcity desk download [--os mac|windows|linux]")}import{setTimeout as aa}from"node:timers/promises";var ca=1,da=30,ua=900,ga=64,la=512,qs=2048,wr=512;function pa(t){if(t===!1)return!1;if(process.env.VCITY_NO_OPEN_BROWSER)return!1;if(!process.stdout.isTTY)return!1;return!0}function vr(t,e,r){if(typeof t!=="string"||t.length===0||t.length>e)throw Error(`Invalid device flow response: ${r} is missing, empty, or too long.`);return t}var ma=60000;function _s(t,e){if(typeof t!=="number"||!Number.isFinite(t))throw Error(`Invalid device flow response: ${e} is missing or non-finite.`);if(t<=Date.now()-ma)throw Error(`Invalid device flow response: ${e} is already expired.`);return t}function fa(t){if(vr(t.access_token,qs,"access_token"),vr(t.refresh_token,qs,"refresh_token"),_s(t.access_expires_at,"access_expires_at"),_s(t.refresh_expires_at,"refresh_expires_at"),!t.user||typeof t.user!=="object")throw Error("Invalid device flow response: user object is missing.");if(vr(t.user.id,wr,"user.id"),t.user.email!==void 0){if(typeof t.user.email!=="string"||t.user.email.length>wr)throw Error("Invalid device flow response: user.email is invalid.")}if(t.user.name!==void 0){if(typeof t.user.name!=="string"||t.user.name.length>wr)throw Error("Invalid device flow response: user.name is invalid.")}}function ya(t){if(t&&typeof t==="object"&&"status"in t){let e=t.status;if(typeof e==="number")return e}return}async function ha(t){try{let e=(await import("open")).default;await e(t)}catch{}}async function Gs(t={}){let e=t.apiBaseUrl??Le(),r=St(e),n=await Nt("/api/cli/auth/device/code",{method:"POST",body:{},authed:!1,baseUrl:r.toString()});if(typeof n.user_code!=="string"||n.user_code.length===0||n.user_code.length>ga)throw Error("Invalid device flow response: user_code is missing or too long.");if(typeof n.device_code!=="string"||n.device_code.length===0||n.device_code.length>la)throw Error("Invalid device flow response: device_code is missing or too long.");let i=new URL("/cli-auth",r),a=new URL(i);if(a.searchParams.set("user_code",n.user_code),process.stdout.write(`
|
|
29
92
|
Open this URL to approve the session:
|
|
30
|
-
${
|
|
93
|
+
${i.toString()}
|
|
31
94
|
Enter this code:
|
|
32
|
-
${E(
|
|
95
|
+
${E(n.user_code)}
|
|
33
96
|
|
|
34
97
|
Only enter this code if you just ran \`vcity login\` yourself. Never paste a code someone else sent you.
|
|
35
98
|
|
|
36
99
|
`),process.stdout.write(`Waiting for approval…
|
|
37
|
-
`),
|
|
38
|
-
Logged in as ${E(
|
|
39
|
-
`);return}throw Error(`Login ${
|
|
40
|
-
`);return}try{await
|
|
41
|
-
`)}var
|
|
42
|
-
`)}async function
|
|
43
|
-
`)
|
|
44
|
-
`)
|
|
45
|
-
|
|
46
|
-
`);
|
|
47
|
-
`)}
|
|
48
|
-
|
|
49
|
-
`)}
|
|
50
|
-
`)}async function
|
|
51
|
-
`),
|
|
52
|
-
`);return}}let
|
|
53
|
-
`)}
|
|
54
|
-
|
|
55
|
-
`)
|
|
56
|
-
`)
|
|
57
|
-
`)
|
|
58
|
-
`)
|
|
59
|
-
`),
|
|
60
|
-
`)
|
|
61
|
-
`)
|
|
62
|
-
`)
|
|
63
|
-
`),
|
|
64
|
-
`)
|
|
65
|
-
`)
|
|
66
|
-
`),
|
|
67
|
-
`),
|
|
68
|
-
`)
|
|
69
|
-
`)
|
|
100
|
+
`),pa(t.openBrowser))await ha(Dr(a.toString()).toString());let s=(w)=>{let v=typeof w==="number"&&Number.isFinite(w)?w:0;return Math.max(v,ca)},o=Math.min(Math.max(typeof n.expires_in==="number"&&Number.isFinite(n.expires_in)?n.expires_in:0,da),ua),c=Date.now()+o*1000,u=s(n.interval),l=0;while(Date.now()<c){await aa(u*1000);let w;try{w=await Nt("/api/cli/auth/device/token",{method:"POST",body:{device_code:n.device_code},authed:!1,baseUrl:r.toString()})}catch(v){let R=ya(v);if(R===400)w=v.body;else if(R!==void 0)throw v;else{l++;continue}}if(!w)continue;if(w.status==="pending"){u=s(w.interval);continue}if(w.status==="approved"){fa(w),qe({api_base_url:r.toString(),access_token:w.access_token,refresh_token:w.refresh_token,access_expires_at:w.access_expires_at,refresh_expires_at:w.refresh_expires_at,user:w.user});let v=w.user.email??w.user.name??w.user.id;process.stdout.write(`
|
|
101
|
+
Logged in as ${E(v)}.
|
|
102
|
+
`);return}throw Error(`Login ${w.status}. Run \`vcity login\` again.`)}if(l>0)throw Error(`Login timed out after ${l} network error${l===1?"":"s"} while polling. Check your connection and run \`vcity login\` again.`);throw Error("Login timed out. Run `vcity login` again.")}async function Vs(){let t=xt();if(!t){process.stdout.write(`Not logged in.
|
|
103
|
+
`);return}try{await Nt("/api/cli/auth/logout",{method:"POST",body:{refresh_token:t.refresh_token},headers:{"x-refresh-token":t.refresh_token}})}catch{}$t(),process.stdout.write(`Logged out.
|
|
104
|
+
`)}var wa=/^\d{4}-\d{2}-\d{2}$/;function Js(t,e){if(t===void 0)return;if(!wa.test(t))throw Error(`${e} must be a date, YYYY-MM-DD (UTC). Got: ${t}`);return t}function br(t){let e={},r=Js(t.from,"--from"),n=Js(t.to,"--to");if(r)e.from=r;if(n)e.to=n;return e}function kr(t,e){let r=t.clamped?` (shortened to the ${e} plan limit)`:"";process.stderr.write(`${E(`${t.from} to ${t.to}, ${t.days} days${r}`)}
|
|
105
|
+
`)}async function Hs(t={}){let e=f(t.json),r=h(t.org),n=await p().analytics.summary(r,br(t));if(e==="json"){g({org:r,...n});return}kr(n.range,n.plan),j({totalVisits:n.totalVisits,productViews:n.productViews}),k(n.visitsByType,[{header:"PAGE TYPE",get:(i)=>i.value},{header:"VISITS",get:(i)=>String(i.count)}])}async function Ys(t={}){let e=f(t.json),r=h(t.org);if(t.groupBy!==void 0&&t.groupBy!=="day"&&t.groupBy!=="type")throw Error(`--group-by must be day or type. Got: ${t.groupBy}`);let n=await p().analytics.visits(r,{...br(t),groupBy:t.groupBy});if(e==="json"){g({org:r,...n});return}kr(n.range,n.plan),k(n.data,[{header:n.groupBy==="day"?"DAY":"PAGE TYPE",get:(i)=>i.value},{header:"VISITS",get:(i)=>String(i.count)}])}async function Qs(t={}){let e=f(t.json),r=h(t.org),n=await p().analytics.topProducts(r,{...br(t),limit:t.limit});if(e==="json"){g({org:r,...n});return}kr(n.range,n.plan),k(n.data,[{header:"PRODUCT",get:(i)=>i.name??"(unknown)"},{header:"ID",get:(i)=>i.productId},{header:"VIEWS",get:(i)=>String(i.views)}])}async function Ws(t,e,r){let n=f(!!r.json)==="json",i=p(),a=At(r,"org"),s=a===void 0?void 0:String((await i.orgs.get(a)).id),o=r["all-stores"]===!0?"stores":void 0;if(t===void 0||t==="list"){let c=await i.notifications.list({...r.unread===!0&&{status:"unread"},...s!==void 0&&{orgId:s},...o&&{include:o},...C(r,"limit",{min:1,max:200})!==void 0&&{limit:C(r,"limit")},...C(r,"skip")!==void 0&&{skip:C(r,"skip")}});if(n)g(c);else k(c.data,[{header:"ID",get:(u)=>u.id},{header:"",get:(u)=>u.read?"":"●"},{header:"WHEN",get:(u)=>x(u.createdAt)},{header:"TYPE",get:(u)=>u.type??""},{header:"MESSAGE",get:(u)=>(u.message??"").slice(0,80)}]),process.stdout.write(`${c.unreadCount} unread
|
|
106
|
+
`);return}if(t==="read"){let c=r.all===!0,u=c?void 0:I(e[0],"vcity notifications read <id> | --all [--org <slug>]","notification id"),l=await i.notifications.markRead({...u!==void 0&&{id:u},...c&&{all:!0},...s!==void 0&&{orgId:s},...o&&{include:o}});if(n)g(l);else process.stdout.write(`Marked read.
|
|
107
|
+
`);return}if(t==="unread"){let c=await i.me.unread();if(n)g(c);else k(c.orgs,[{header:"STORE",get:(u)=>u.slug??u.orgId},{header:"INBOX",get:(u)=>String(u.inboxUnread??0)},{header:"NOTIFICATIONS",get:(u)=>String(u.notificationsUnread??0)}]);return}throw new y("usage: vcity notifications [list] [--unread] [--org <slug>] [--all-stores] [--limit <n>] | read <id>|--all | unread")}var We=new Set(["ACCEPTED","REJECTED","PENDING","FAILED","REVERSED","RETAINED","STARTED","EXPIRED","ABANDONED","CANCELED","ANTIFRAUD"]);async function Xs(t={}){let e=f(t.json),r=h(t.org);if(t.status!==void 0&&!We.has(t.status))throw Error(`Invalid order status: ${t.status}. Allowed: ${[...We].join(", ")}`);let n={};if(t.limit!==void 0)n.limit=t.limit;if(t.status!==void 0)n.status=t.status;let a=await p().orders.list(r,n),s=a.data??[];if(e==="json"){g({org:r,orders:s,total:a.total,skip:a.skip,limit:a.limit,hasMore:a.hasMore});return}k(s,[{header:"ID",get:(o)=>o.id},{header:"STATUS",get:(o)=>o.status??""},{header:"TOTAL",get:(o)=>o.total!==void 0?`${o.total.toLocaleString()} ${o.currencyCode??""}`.trim():""},{header:"CREATED",get:(o)=>x(o.createdAt)}])}async function Zs(t,e={}){let r=f(e.json),n=h(e.org),a=await p().orders.get(n,t);if(r==="json"){g(a);return}j(a)}var zs=["id","status","createdAt","currencyCode","subtotal","taxes","shipping","discount","total","processed","paymentIntentId"];async function tn(t={}){let e=h(t.org);if(t.status!==void 0&&!We.has(t.status))throw new y(`Invalid order status: ${t.status}. Allowed: ${[...We].join(", ")}`);let r=p(),n=await ut(async(a,s)=>{let o=await r.orders.list(e,{skip:a,limit:s,...t.status!==void 0&&{status:t.status},...t.fromTs!==void 0&&{fromTs:t.fromTs},...t.toTs!==void 0&&{toTs:t.toTs}});return{data:o.data??[],hasMore:o.hasMore}}),i=(t.format??"csv")==="json"?`${JSON.stringify(n,null,2)}
|
|
108
|
+
`:Qe([...zs],n.map((a)=>zs.map((s)=>s==="createdAt"&&typeof a.createdAt==="number"?new Date(a.createdAt).toISOString():a[s])));if(t.output)Z(t.output,i),process.stderr.write(`Wrote ${n.length} orders to ${E(t.output)}
|
|
109
|
+
`);else process.stdout.write(i)}var Ks=["pending","shipped","delivered"];async function en(t,e,r={}){let n=f(r.json),i=h(r.org),a=r.status??"shipped";if(a!=="shipped"&&a!=="delivered")throw new y("--status must be shipped or delivered");let s=p(),o=[],c=e;if(c.length===0){let w=((await s.orders.get(i,t)).lineItems??[]).filter((R)=>typeof R.id==="string");if(w.length===0)throw Error(`Order ${t} has no line items`);let v=Ks.indexOf(a);c=[];for(let R of w)if(Ks.indexOf(R.shippingStatus??"pending")>=v)o.push({lineItemId:R.id,shippingStatus:R.shippingStatus,skipped:!0});else c.push(R.id)}for(let l of c)try{await s.orders.updateLineItemShipping(i,t,l,{shippingStatus:a}),o.push({lineItemId:l,shippingStatus:a})}catch(w){o.push({lineItemId:l,error:w.message})}if(n==="json")g({org:i,orderId:t,results:o});else k(o,[{header:"LINE ITEM",get:(l)=>l.lineItemId},{header:"SHIPPING",get:(l)=>`${l.shippingStatus??""}${l.skipped?" (unchanged)":""}`},{header:"ERROR",get:(l)=>l.error??""}]);let u=o.filter((l)=>l.error).length;if(u>0)throw Error(`${u} of ${o.length} line items failed`)}var va=128,ba=/^[a-z0-9_-]+$/i;function ka(t){if(!t||t.length>va||!ba.test(t))throw Error("Server returned an unexpected org slug format. Run `vcity org list` to see valid orgs.")}async function rn(){let e=await p().me.get();if(e&&typeof e==="object"&&"orgs"in e){let r=e.orgs;return Array.isArray(r)?r:[]}return[]}function Ia(t){if(!t)return"";let e=[];if(t.admin)e.push("admin");if(t.admins?.create||t.admins?.update||t.admins?.delete)e.push("admins");if(t.products?.create||t.products?.update||t.products?.delete)e.push("products");if(t.orders?.retrieve||t.orders?.update)e.push("orders");if(t.quotes?.retrieve||t.quotes?.update)e.push("quotes");if(t.surveys?.create||t.surveys?.update||t.surveys?.delete||t.surveys?.retrieve)e.push("surveys");return e.join(",")}async function sn(t={}){let e=f(t.json),r=await rn(),n=Ct().active_org;if(e==="json"){g({orgs:r,active_org:n??null});return}k(r,[{header:"*",get:(i)=>i.slug===n?"*":" "},{header:"SLUG",get:(i)=>i.slug},{header:"NAME",get:(i)=>i.name??""},{header:"ID",get:(i)=>i.id}])}async function nn(t){let r=(await rn()).find((n)=>n.slug===t||n.id===t);if(!r)throw Error(`No accessible org matches "${t}". Run \`vcity org list\` to see options.`);ka(r.slug),qr({active_org:r.slug}),process.stdout.write(`Active org set to ${E(r.slug)} (${E(r.name??r.id)}).
|
|
110
|
+
`)}async function on(t={}){let e=f(t.json),r=h(t.org),n={};if(t.limit!==void 0)n.limit=t.limit;let a=await p().orgs.listMembers(r,n),s=a.data??[];if(e==="json"){g({org:r,members:s,total:a.total,skip:a.skip,limit:a.limit,hasMore:a.hasMore});return}k(s,[{header:"ID",get:(o)=>o.id},{header:"PROFILE_ID",get:(o)=>o.profileId??""},{header:"ACTIVE",get:(o)=>o.active?"yes":"no"},{header:"PERMISSIONS",get:(o)=>Ia(o.permissions)}])}async function an(t,e={}){let r=f(e.json),i=await p().orgs.get(t);if(r==="json"){g(i);return}j(i)}var cn=["name","slug","description","website","contactEmail","billingEmail","email","telephone","whatsapp","instagram","facebook","linkedin","youtube","locale","timezone","countryCode","seoTitle","seoDescription","colorMain"],dn=(t)=>t.replace(/[A-Z]/g,(e)=>`-${e.toLowerCase()}`);async function un(t={}){let e=h(t.org),r=await p().orgs.getSettings(e);if(f(t.json)==="json")g(r);else j(r)}function ja(t){let e=P(m(t,"data"));if(e!==void 0&&(typeof e!=="object"||e===null||Array.isArray(e)))throw new y("--data must be a JSON object");let r={...e};for(let n of cn){let i=m(t,dn(n));if(i!==void 0)r[n]=i}if(m(t,"phone")!==void 0)r.telephone=m(t,"phone");return r}async function gn(t){let e=h(m(t,"org")),r=ja(t);if(Object.keys(r).length===0)throw new y(`usage: vcity org set [--org <slug>] ${cn.map((i)=>`--${dn(i)} <s>`).slice(0,6).join(" ")} … [--data <json|@file|->]`);let n=await p().orgs.update(e,r);if(f(!!t.json)==="json")g(n);else process.stdout.write(`Updated ${Object.keys(r).map(E).join(", ")} on ${e}.
|
|
111
|
+
`)}import{readFileSync as Ta}from"node:fs";async function ln(t={}){let e=f(t.json),r=h(t.org),i=await p().agents.list(r,t.limit!==void 0?{limit:t.limit}:{}),a=i.data??[];if(e==="json"){g({org:r,agents:a,total:i.total,skip:i.skip,limit:i.limit,hasMore:i.hasMore});return}k(a,[{header:"ID",get:(s)=>s.id},{header:"NAME",get:(s)=>s.name??""},{header:"KIND",get:(s)=>s.kind??""},{header:"ENABLED",get:(s)=>s.enabled?"yes":"no"},{header:"AUTONOMY",get:(s)=>s.autonomy??""},{header:"TRIGGER",get:(s)=>s.trigger?.type??""}])}async function pn(t,e={}){let r=f(e.json),n=h(e.org),a=await p().agents.get(n,t);if(r==="json"){g(a);return}j(a)}async function mn(t,e={}){let r=f(e.json),n=h(e.org);if(e.instructions!==void 0&&e.instructionsFile!==void 0)throw Error("agents update: pass --instructions or --instructions-file, not both");let i=e.instructionsFile!==void 0?Ta(e.instructionsFile,"utf8"):e.instructions,a={name:e.name,description:e.description,emoji:e.emoji,avatar:e.avatar,instructions:i,enabled:e.disable?!1:void 0},s=Object.fromEntries(Object.entries(a).filter(([,l])=>l!==void 0));if(Object.keys(s).length===0)throw Error("agents update: nothing to update (pass --name, --description, --emoji, --avatar, --instructions, --instructions-file or --disable)");let o=p(),c=await o.agents.get(n,t);if(typeof c.updatedAt!=="number")throw Error("agents update: the agent has no updatedAt to edit against");let u=await o.agents.update(n,t,{...s,expectedUpdatedAt:c.updatedAt});if(r==="json"){g(u);return}process.stdout.write(`Updated agent:
|
|
112
|
+
`),j(u)}async function fn(t={}){let e=f(t.json),r=h(t.org);if(t.status!==void 0&&t.status!=="open"&&t.status!=="all")throw Error('conversations list: --status must be "open" or "all"');let i=await p().conversations.list(r,{...t.status?{status:t.status}:{},...t.awaitingReply?{awaitingReply:"true"}:{}}),a=i.data??[];if(e==="json"){g({org:r,conversations:a,notice:i.notice});return}k(a,[{header:"ID",get:(s)=>s.id},{header:"VISITOR",get:(s)=>s.visitor??""},{header:"STATUS",get:(s)=>s.status??""},{header:"WAITING",get:(s)=>s.awaitingReply?"yes":"no"},{header:"LAST",get:(s)=>s.lastMessageExcerpt??""}])}async function yn(t,e={}){let r=f(e.json),n=h(e.org),a=await p().conversations.get(n,t,e.limit!==void 0?{limit:e.limit}:{});if(r==="json"){g(a);return}j(a.conversation),k(a.messages??[],[{header:"FROM",get:(s)=>s.from},{header:"AT",get:(s)=>s.at!==void 0?new Date(s.at).toISOString():""},{header:"TEXT",get:(s)=>s.text}])}async function hn(t={}){let e=f(t.json),r=h(t.org),n=await p().customerAgent.get(r);if(e==="json"){g(n);return}j(n)}async function wn(t={}){let e=f(t.json),r=h(t.org),i=(await p().customerAgent.listKnowledge(r)).data??[];if(e==="json"){g({org:r,documents:i});return}k(i,[{header:"ID",get:(a)=>a.id},{header:"NAME",get:(a)=>a.name},{header:"CHUNKS",get:(a)=>String(a.chunks)},{header:"EXCERPT",get:(a)=>a.excerpt}])}function vn(t){let e=P(t.data),r=e&&typeof e==="object"?{...e}:{};if(t.name!==void 0)r.name=t.name;if(t.description!==void 0)r.description=t.description;if(t.slug!==void 0)r.slug=t.slug;if(t.seoTitle!==void 0)r.seoTitle=t.seoTitle;if(t.seoDescription!==void 0)r.seoDescription=t.seoDescription;return r}async function bn(t={}){let e=f(t.json),r=h(t.org),n=await p().collections.list(r),i=n.data??[];if(e==="json"){g({org:r,collections:i,total:n.total});return}k(i,[{header:"ID",get:(a)=>a.id},{header:"NAME",get:(a)=>a.name??""},{header:"SLUG",get:(a)=>a.slug??""},{header:"DESCRIPTION",get:(a)=>a.description??""}])}async function kn(t,e={}){let r=f(e.json),n=h(e.org),i=await p().collections.get(n,t);if(r==="json"){g(i);return}j(i)}async function In(t={}){let e=f(t.json),r=h(t.org),n=vn(t);if(n.name===void 0)throw Error("collections create: --name is required (or supply it via --data)");let a=await p().collections.create(r,n);if(e==="json"){g(a);return}process.stdout.write(`Created collection:
|
|
113
|
+
`),j(a)}async function jn(t,e={}){let r=f(e.json),n=h(e.org),i=vn(e);if(Object.keys(i).length===0)throw Error("collections update: nothing to update (pass at least one field or --data)");let s=await p().collections.update(n,t,i);if(r==="json"){g(s);return}process.stdout.write(`Updated collection:
|
|
114
|
+
`),j(s)}async function Tn(t,e={}){let r=f(e.json),n=h(e.org);if(!e.yes){if(r==="json")throw Error("collections delete: --yes is required in JSON / non-interactive mode");if(!await _(`Delete collection ${t} in org ${n}? [y/N]`)){process.stdout.write(`Aborted.
|
|
115
|
+
`);return}}let i=await p().collections.delete(n,t);if(r==="json"){g(i);return}process.stdout.write(`Deleted collection ${t}.
|
|
116
|
+
`)}import{closeSync as Ea,existsSync as En,openSync as Ra,readFileSync as Ca,readSync as Sa,statSync as Ut}from"node:fs";var Rn=["draft","published","all"];async function Sn(t={}){let e=f(t.json),r=h(t.org);if(t.status!==void 0&&!Rn.includes(t.status))throw Error(`posts list: --status must be one of ${Rn.join(", ")} (got: ${t.status})`);let n=await p().posts.list(r,{...t.limit!==void 0?{limit:t.limit}:{},...t.status?{status:t.status}:{}}),i=n.data??[];if(e==="json"){g({org:r,posts:i,total:n.total,skip:n.skip,limit:n.limit,hasMore:n.hasMore});return}k(i,[{header:"ID",get:(a)=>a.id},{header:"STATUS",get:(a)=>a.status??""},{header:"FILES",get:(a)=>String(a.files?.length??0)},{header:"TEXT",get:(a)=>(a.comment??"").replace(/\s+/g," ").slice(0,60)}])}async function On(t,e={}){let r=f(e.json),n=h(e.org),i=await p().posts.get(n,t);if(r==="json"){g(i);return}j(i)}async function xn(t={}){let e=f(t.json),r=h(t.org),n=t.video!==void 0?An(t.video,t.poster):void 0,i=P(t.data),a=i&&typeof i==="object"?{...i}:{};if(t.comment!==void 0)a.comment=t.comment;if(t.file!==void 0)a.files=[...a.files??[],t.file];if(a.comment===void 0)throw Error("posts create: --comment is required (or supply it via --data)");let o=await p().posts.createDraft(r,a),c;if(n)try{c=await Pn(r,String(o.id),n)}catch(l){let w=l instanceof Error?l.message:String(l);throw Error(`Draft ${String(o.id)} was filed, but the video was not attached: ${w}
|
|
117
|
+
Retry with: vcity posts attach-video ${String(o.id)} --video <file>`)}if(e==="json"){g(c??o);return}let u=c?" with its video":"";process.stdout.write(`Draft ${E(String(o.id))} filed${u}. An org admin must publish it from the proposals inbox.
|
|
118
|
+
`)}var Oa=26214400,xa=2097152;function An(t,e){if(!En(t)||!Ut(t).isFile())throw Error(`--video: file not found: ${t}`);if(!/\.mp4$/i.test(t))throw Error("--video: only .mp4 (H.264 + AAC) is accepted.");let r=Ut(t).size;if(r<1||r>Oa)throw Error("--video: the file must be between 1 byte and 25 MB.");if(String.fromCharCode(...Aa(t,8).subarray(4,8))!=="ftyp")throw Error("--video: this does not look like an MP4 file.");if(e!==void 0){if(!En(e)||!Ut(e).isFile())throw Error(`--poster: file not found: ${e}`);if(!/\.jpe?g$/i.test(e))throw Error("--poster: only JPEG images are accepted.");if(Ut(e).size>xa)throw Error("--poster: the file must be at most 2 MB.")}return{video:t,...e!==void 0?{poster:e}:{}}}function Aa(t,e){let r=Ra(t,"r");try{let n=new Uint8Array(e),i=Sa(r,n,0,e,0);return n.subarray(0,i)}finally{Ea(r)}}var Pa=/(^|\.)storage\.googleapis\.com$/;function $a(t,e){let r;try{r=new URL(t)}catch{throw Error(`the ${e} upload URL from the API is not valid`)}if(r.protocol!=="https:"||!Pa.test(r.hostname))throw Error(`refusing to upload the ${e}: the API returned a URL outside Google Cloud Storage`)}async function Cn(t,e,r,n){$a(t,n);let i;try{let a=await fetch(t,{method:"PUT",headers:e,body:new Uint8Array(Ca(r)),redirect:"error"});if(a.ok)return;i=a.status}catch{throw Error(`uploading the ${n} failed (network error)`)}throw Error(`uploading the ${n} failed (HTTP ${i})`)}async function Pn(t,e,r){let n=p(),i=await n.posts.requestVideoUpload(t,e,Ut(r.video).size);if(await Cn(i.videoUploadUrl,i.videoHeaders,r.video,"video"),r.poster)await Cn(i.posterUploadUrl,i.posterHeaders,r.poster,"poster");return await n.posts.finalizeVideo(t,e)}async function $n(t,e={}){let r=f(e.json),n=h(e.org);if(e.video===void 0)throw Error("posts attach-video: --video <file.mp4> is required");let i=await Pn(n,t,An(e.video,e.poster));if(r==="json"){g(i);return}process.stdout.write(`Video attached to draft ${t}. It stays private until an org admin publishes the post.
|
|
119
|
+
`)}async function Dn(t,e={}){let r=f(e.json),n=h(e.org),i=await p().posts.videoPreview(n,t);if(r==="json"){g(i);return}process.stdout.write(`Short-lived private links (do not share):
|
|
120
|
+
`),j(i)}async function Nn(t,e={}){let r=f(e.json),n=h(e.org);if(!e.yes){if(r==="json")throw Error("posts publish: --yes is required in JSON / non-interactive mode");if(!await _(`Publish post ${t} to the public feed of ${n}? [y/N]`)){process.stdout.write(`Aborted.
|
|
121
|
+
`);return}}let i=await p().posts.publish(n,t);if(r==="json"){g(i);return}process.stdout.write(`Published post ${t}.
|
|
122
|
+
`)}function Ir(t,e,r){if(t===void 0)return;if(!e.includes(t))throw Error(`products list: ${r} must be one of ${e.join(", ")} (got: ${t})`);return t}var Da=/^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}(:\d{2}(\.\d{1,3})?)?(Z|[+-]\d{2}:\d{2})?)?$/;function Fn(t,e){if(t===void 0)return;let r=/^\d+$/.test(t)?Number(t):Da.test(t)?Date.parse(t):Number.NaN;if(!Number.isFinite(r)||r<0)throw Error(`products list: ${e} must be unix-ms or a date like 2026-10-01 (got: ${t})`);return r}async function Un(t={}){let e=f(t.json),r=h(t.org),n={search:t.search,limit:t.limit,skip:t.skip,visibility:Ir(t.visibility,["public","draft","hidden"],"--visibility"),createdFrom:Fn(t.createdFrom,"--created-from"),updatedFrom:Fn(t.updatedFrom,"--updated-from"),collection:t.collection,sort:Ir(t.sort,["createdAt","updatedAt"],"--sort"),order:Ir(t.order,["asc","desc"],"--order"),lang:t.lang},a=await p().products.list(r,Object.fromEntries(Object.entries(n).filter(([,o])=>o!==void 0))),s=a.data??[];if(e==="json"){g({org:r,products:s,total:a.total,skip:a.skip,limit:a.limit,hasMore:a.hasMore});return}k(s,[{header:"ID",get:(o)=>o.id},{header:"NAME",get:(o)=>o.name??""},{header:"PRICE",get:(o)=>o.price!==void 0?`${o.price.toLocaleString()} ${o.currencyCode??""}`.trim():""},{header:"SKU",get:(o)=>o.sku??""},{header:"VISIBILITY",get:(o)=>o.visibility??""},{header:"STOCK",get:(o)=>o.availability!==void 0?String(o.availability):""}])}async function Bn(t,e={}){let r=f(e.json),n=h(e.org),a=await p().products.get(n,t,e.lang!==void 0?{lang:e.lang}:{});if(r==="json"){g(a);return}j(a)}async function Mn(t={}){let e=f(t.json),r=h(t.org),n=P(t.data),i=n&&typeof n==="object"?{...n}:{};if(t.name!==void 0)i.name=t.name;if(t.price!==void 0)i.price=t.price;if(t.currency!==void 0)i.currencyCode=t.currency;if(t.sku!==void 0)i.sku=t.sku;if(i.name===void 0)throw Error("products create: --name is required (or supply it via --data)");let s=await p().products.create(r,i);if(e==="json"){g(s);return}process.stdout.write(`Created product:
|
|
123
|
+
`),j(s)}async function Ln(t,e={}){let r=f(e.json),n=h(e.org),i=P(e.data),a=i&&typeof i==="object"?{...i}:{};if(e.name!==void 0)a.name=e.name;if(e.price!==void 0)a.price=e.price;if(e.currency!==void 0)a.currencyCode=e.currency;if(e.sku!==void 0)a.sku=e.sku;if(e.visibility!==void 0)a.visibility=e.visibility;if(e.availability!==void 0)a.availability=e.availability;if(Object.keys(a).length===0)throw Error("products update: nothing to update (pass at least one field or --data)");let o=await p().products.update(n,t,a);if(r==="json"){g(o);return}process.stdout.write(`Updated product:
|
|
124
|
+
`),j(o)}async function qn(t,e={}){let r=f(e.json),n=h(e.org);if(!e.yes){if(r==="json")throw Error("products delete: --yes is required in JSON / non-interactive mode");if(!await _(`Delete product ${t} in org ${n}? [y/N]`)){process.stdout.write(`Aborted.
|
|
125
|
+
`);return}}let a=await p().products.delete(n,t);if(r==="json"){g(a);return}process.stdout.write(`Deleted product ${t}.
|
|
126
|
+
`)}import Gn from"node:fs";import _n from"node:path";var mt=1048576,Na={".png":{contentType:"image/png",max:10*mt},".jpg":{contentType:"image/jpeg",max:10*mt},".jpeg":{contentType:"image/jpeg",max:10*mt},".gif":{contentType:"image/gif",max:10*mt},".webp":{contentType:"image/webp",max:10*mt},".pdf":{contentType:"application/pdf",max:25*mt},".mp4":{contentType:"video/mp4",max:100*mt},".mov":{contentType:"video/quicktime",max:100*mt}};function Bt(t){let e=Na[_n.extname(t).toLowerCase()];if(!e)throw new y(`${t}: unsupported file type (PNG, JPEG, GIF, WebP, PDF, MP4 or MOV)`);let r;try{r=Gn.statSync(t)}catch{throw new y(`${t}: no such file`)}if(!r.isFile())throw new y(`${t} is not a regular file`);if(r.size>e.max)throw new y(`${t} is larger than ${e.max/mt} MB`);return{name:_n.basename(t),contentType:e.contentType,size:r.size}}async function ze(t,e,r){let{name:n,contentType:i}=Bt(r),a=new Uint8Array(Gn.readFileSync(r)),s=await t.media.upload(e,{name:n,contentType:i,data:a});return{url:s.url,id:s.id,kind:s.kind}}var Vn=(t)=>/^https?:\/\//i.test(t);async function Jn(t,e,r){if(t!=="upload"||e.length===0)throw new y("usage: vcity media upload <file> [file…] [--org <slug>] [--json] (PNG/JPEG/GIF/WebP ≤10 MB, PDF ≤25 MB, MP4/MOV ≤100 MB)");for(let o of e)Bt(o);let n=h(m(r,"org")),i=p(),a=[];for(let o of e)try{a.push({file:o,...await ze(i,n,o)})}catch(c){a.push({file:o,error:c.message})}if(f(!!r.json)==="json")g({org:n,files:a});else k(a,[{header:"FILE",get:(o)=>o.file},{header:"URL",get:(o)=>o.url??""},{header:"ERROR",get:(o)=>o.error??""}]);let s=a.filter((o)=>o.error).length;if(s>0)throw Error(`${s} of ${a.length} uploads failed`)}import{randomUUID as Fa}from"node:crypto";import jr from"node:path";var Ua=new Set(["price","availability"]),Ba=new Set(["tags","categories","collections"]),Ma=new Set(["name","price","currencyCode","sku","visibility","availability","cta","type","slug","description","tags","categories","collections","thumbnail","gallery"]),La={currency:"currencyCode",stock:"availability",image:"thumbnail"};function qa(t){let e={};for(let[r,n]of Object.entries(t)){let i=La[r]??r,a=n.trim();if(a==="")continue;if(!Ma.has(i))throw Error(`unknown column "${r}"`);if(Ua.has(i)){let s=Number(a);if(!Number.isFinite(s))throw Error(`${i} must be a number (got: ${a})`);e[i]=s}else if(Ba.has(i))e[i]=a.split("|").map((s)=>s.trim()).filter(Boolean);else if(i==="thumbnail")e.thumbnail={url:a};else if(i==="gallery")e.gallery=a.split("|").map((s)=>({url:s.trim()})).filter((s)=>s.url);else e[i]=a}return e}function _a(t,e){if(jr.extname(t).toLowerCase()===".json"){let r;try{r=JSON.parse(e)}catch(n){throw new y(`${t}: invalid JSON (${n.message})`)}if(!Array.isArray(r)||r.some((n)=>typeof n!=="object"||n===null||Array.isArray(n)))throw new y(`${t}: expected a JSON array of product objects`);return r.map((n,i)=>({row:i+1,json:n}))}return Ye(e).map(({line:r,record:n})=>({row:r,csv:n}))}async function Ga(t,e,r){let n=async(o)=>{if(Vn(o))return{url:o};let c=jr.resolve(e,o);if(!r)return Bt(c),{url:o};let u=r.cache.get(c);if(u)return u;let{url:l,id:w}=await ze(r.sdk,r.org,c);return r.cache.set(c,{url:l,id:w}),{url:l,id:w}},i=async(o)=>{if(!o.url)return o;let{url:c,id:u}=await n(o.url);return{...o,url:c,id:o.id||u||Fa()}},a={...t},s=a.thumbnail;if(s?.url)a.thumbnail=await i(s);if(Array.isArray(a.gallery))a.gallery=await Promise.all(a.gallery.map(i));return a}function Hn(t){if(process.stderr.isTTY)process.stderr.write(`${E(t)}
|
|
127
|
+
`)}async function Yn(t,e={}){let r=f(e.json),n=h(e.org),i=_a(t,st(t));if(i.length===0)throw new y(`${t}: no product rows`);let a=(e.upsertBy??"sku")==="sku",s=p(),o=new Map;if(a){let v=await ut(async(R,T)=>{let N=await s.products.list(n,{skip:R,limit:T,sort:"createdAt",order:"asc"});return{data:N.data??[],hasMore:N.hasMore}});for(let R of v)if(R.sku)o.set(R.sku,R.id)}let c=[],u=new Map;for(let[v,R]of i.entries()){let{row:T}=R,N;try{N=R.csv?qa(R.csv):R.json??{}}catch(L){c.push({row:T,action:"error",error:L.message});continue}let F=typeof N.sku==="string"?N.sku:void 0,D=a&&F?o.get(F):void 0,X=D?"update":"create";if(X==="create"&&(N.name===void 0||N.price===void 0||N.currencyCode===void 0)){c.push({row:T,sku:F,action:"error",error:"a new product needs name, price and currencyCode"});continue}try{N=await Ga(N,e.images??jr.dirname(t),e.dryRun?void 0:{sdk:s,org:n,cache:u})}catch(L){c.push({row:T,sku:F,action:"error",error:L.message});continue}if(e.dryRun){if(F&&!D)o.set(F,"(new)");c.push({row:T,sku:F,action:X,id:D==="(new)"?void 0:D});continue}try{let rt=(D?await s.products.update(n,D,N):await s.products.create(n,N)).id??D;if(F&&rt)o.set(F,rt);c.push({row:T,sku:F,action:X,id:rt}),Hn(`[${v+1}/${i.length}] ${X}d ${F??rt??""}`)}catch(L){c.push({row:T,sku:F,action:"error",error:L.message}),Hn(`[${v+1}/${i.length}] row ${T} failed: ${L.message}`)}}let l=c.filter((v)=>v.action==="error"),w={org:n,dryRun:!!e.dryRun,total:c.length,created:c.filter((v)=>v.action==="create").length,updated:c.filter((v)=>v.action==="update").length,failed:l.length};if(e.report)Z(e.report,`${JSON.stringify({...w,rows:c},null,2)}
|
|
128
|
+
`);if(r==="json")g({...w,rows:c});else if(process.stdout.write(`${w.dryRun?"Dry run: would create":"Created"} ${w.created}, ${w.dryRun?"update":"updated"} ${w.updated}, failed ${w.failed} of ${w.total} rows.
|
|
129
|
+
`),l.length>0)k(l,[{header:"ROW",get:(v)=>String(v.row)},{header:"SKU",get:(v)=>v.sku??""},{header:"ERROR",get:(v)=>v.error??""}]);if(l.length>0)throw Error(`${l.length} of ${c.length} rows failed`)}async function Qn(t={}){let e=f(t.json),r=h(t.org),i=await p().projects.list(r,t.limit!==void 0?{limit:t.limit}:{}),a=i.data??[];if(e==="json"){g({org:r,projects:a,total:i.total,skip:i.skip,limit:i.limit,hasMore:i.hasMore});return}k(a,[{header:"ID",get:(s)=>s.id},{header:"NAME",get:(s)=>s.name??""},{header:"PREFIX",get:(s)=>s.prefix??""},{header:"DESCRIPTION",get:(s)=>s.description??""}])}async function Wn(t,e={}){let r=f(e.json),n=h(e.org),a=await p().projects.get(n,t);if(r==="json"){g(a);return}j(a)}async function zn(t={}){let e=f(t.json),r=h(t.org),n=P(t.data),i=n&&typeof n==="object"?{...n}:{};if(t.name!==void 0)i.name=t.name;if(t.prefix!==void 0)i.prefix=t.prefix;if(t.description!==void 0)i.description=t.description;if(i.name===void 0)throw Error("projects create: --name is required (or supply it via --data)");if(i.prefix===void 0)throw Error("projects create: --prefix is required (or supply it via --data)");let s=await p().projects.create(r,i);if(e==="json"){g(s);return}process.stdout.write(`Created project:
|
|
130
|
+
`),j(s)}async function Kn(t,e={}){let r=f(e.json),n=h(e.org),i=P(e.data),a=i&&typeof i==="object"?{...i}:{};if(e.name!==void 0)a.name=e.name;if(e.description!==void 0)a.description=e.description;if(Object.keys(a).length===0)throw Error("projects update: nothing to update (pass at least one field or --data)");let o=await p().projects.update(n,t,a);if(r==="json"){g(o);return}process.stdout.write(`Updated project:
|
|
131
|
+
`),j(o)}async function Xn(t,e={}){let r=f(e.json),n=h(e.org);if(!e.yes){if(r==="json")throw Error("projects delete: --yes is required in JSON / non-interactive mode");if(!await _(`Delete project ${t} in org ${n}? [y/N]`)){process.stdout.write(`Aborted.
|
|
132
|
+
`);return}}let a=await p().projects.delete(n,t);if(r==="json"){g(a);return}process.stdout.write(`Deleted project ${t}.
|
|
133
|
+
`)}var Ke=new Set(["PENDING","IN_PROGRESS","SUBMITTED","CANCELED","ORDERED"]);async function Zn(t={}){let e=f(t.json),r=h(t.org);if(t.status!==void 0&&!Ke.has(t.status))throw Error(`Invalid quote status: ${t.status}. Allowed: ${[...Ke].join(", ")}`);let n={};if(t.limit!==void 0)n.limit=t.limit;if(t.status!==void 0)n.status=t.status;let a=await p().quotes.list(r,n),s=a.data??[];if(e==="json"){g({org:r,quotes:s,total:a.total,skip:a.skip,limit:a.limit,hasMore:a.hasMore});return}k(s,[{header:"ID",get:(o)=>o.id},{header:"NAME",get:(o)=>o.name??""},{header:"PRODUCT",get:(o)=>o.productId??""},{header:"QTY",get:(o)=>o.quantity!==void 0?String(o.quantity):""},{header:"STATUS",get:(o)=>o.status??""},{header:"CREATED",get:(o)=>x(o.createdAt)}])}async function to(t,e={}){let r=f(e.json),n=h(e.org),a=await p().quotes.get(n,t);if(r==="json"){g(a);return}j(a)}async function eo(t={}){let e=f(t.json),r=h(t.org),n=P(t.data),i=n&&typeof n==="object"?{...n}:{};if(t.name!==void 0)i.name=t.name;if(t.email!==void 0)i.email=t.email;if(t.product!==void 0)i.productId=t.product;if(t.quantity!==void 0)i.quantity=t.quantity;if(t.phone!==void 0)i.telephone=t.phone;if(t.variation!==void 0)i.selectedVariation=t.variation;if(t.company!==void 0)i.company=t.company;if(t.note!==void 0)i.note=t.note;if(i.name===void 0||i.email===void 0||i.productId===void 0)throw Error("quotes create: --name, --email and --product are required (or supply them via --data)");let s=await p().quotes.create(r,i);if(e==="json"){g(s);return}process.stdout.write(`Created quote:
|
|
134
|
+
`),j(s)}async function ro(t,e={}){let r=f(e.json),n=h(e.org);if(e.status!==void 0&&!Ke.has(e.status))throw Error(`Invalid quote status: ${e.status}. Allowed: ${[...Ke].join(", ")}`);let i=P(e.data),a=i&&typeof i==="object"?{...i}:{};if(e.name!==void 0)a.name=e.name;if(e.email!==void 0)a.email=e.email;if(e.product!==void 0)a.productId=e.product;if(e.quantity!==void 0)a.quantity=e.quantity;if(e.phone!==void 0)a.telephone=e.phone;if(e.variation!==void 0)a.selectedVariation=e.variation;if(e.status!==void 0)a.status=e.status;if(e.company!==void 0)a.company=e.company;if(e.note!==void 0)a.note=e.note;if(e.assignee!==void 0)a.assigneeUid=e.assignee;if(Object.keys(a).length===0)throw Error("quotes update: nothing to update (pass at least one field or --data)");let o=await p().quotes.update(n,t,a);if(r==="json"){g(o);return}process.stdout.write(`Updated quote:
|
|
135
|
+
`),j(o)}async function so(t,e={}){let r=f(e.json),n=h(e.org);if(!e.yes){if(r==="json")throw Error("quotes delete: --yes is required in JSON / non-interactive mode");if(!await _(`Delete quote ${t} in org ${n}? [y/N]`)){process.stdout.write(`Aborted.
|
|
136
|
+
`);return}}let a=await p().quotes.delete(n,t);if(r==="json"){g(a);return}process.stdout.write(`Deleted quote ${t}.
|
|
137
|
+
`)}async function no(t={}){let e=f(t.json),r=h(t.org),n={};if(t.limit!==void 0)n.limit=t.limit;let a=await p().rooms.list(r,n),s=a.data??[];if(e==="json"){g({org:r,rooms:s,total:a.total,skip:a.skip,limit:a.limit,hasMore:a.hasMore});return}k(s,[{header:"ID",get:(o)=>o.id},{header:"TITLE",get:(o)=>o.title??""},{header:"DISABLED",get:(o)=>o.disabled?"yes":"no"},{header:"TYPE",get:(o)=>o.type??""}])}async function oo(t,e={}){let r=f(e.json),n=h(e.org),a=await p().rooms.get(n,t);if(r==="json"){g(a);return}j(a)}async function io(t={}){let e=f(t.json),r=h(t.org),n=P(t.data),i=n&&typeof n==="object"?{...n}:{};if(t.title!==void 0)i.title=t.title;if(t.description!==void 0)i.description=t.description;if(t.type!==void 0)i.type=t.type;if(i.title===void 0)throw Error("rooms create: --title is required (or supply it via --data)");let s=await p().rooms.create(r,i);if(e==="json"){g(s);return}process.stdout.write(`Created room:
|
|
138
|
+
`),j(s)}async function ao(t,e={}){let r=f(e.json),n=h(e.org),i=P(e.data),a=i&&typeof i==="object"?{...i}:{};if(e.title!==void 0)a.title=e.title;if(e.description!==void 0)a.description=e.description;if(e.type!==void 0)a.type=e.type;if(e.disabled!==void 0)a.disabled=e.disabled;if(Object.keys(a).length===0)throw Error("rooms update: nothing to update (pass at least one field or --data)");let o=await p().rooms.update(n,t,a);if(r==="json"){g(o);return}process.stdout.write(`Updated room:
|
|
139
|
+
`),j(o)}async function co(t,e={}){let r=f(e.json),n=h(e.org);if(!e.yes){if(r==="json")throw Error("rooms delete: --yes is required in JSON / non-interactive mode");if(!await _(`Delete room ${t} in org ${n}? [y/N]`)){process.stdout.write(`Aborted.
|
|
140
|
+
`);return}}let a=await p().rooms.delete(n,t);if(r==="json"){g(a);return}process.stdout.write(`Deleted room ${t}.
|
|
141
|
+
`)}var uo=["today","week","month","quarter","year","all"];async function go(t={}){let e=f(t.json),r=h(t.org),n=p(),[i,a,s]=await Promise.all([n.orgs.summary(r),n.orgs.overview(r,{timeframe:t.timeframe??"week"}),n.orgs.attention(r)]);if(e==="json"){g({org:r,summary:i,overview:a,attention:s});return}let o=a.sales;if(process.stdout.write(E([`${r} — ${a.timeframe}`,` inbox ${i.inboxUnread} unread · ${i.openConversations} open · ${i.unassignedConversations} unassigned`,` orders ${i.pendingOrders} pending · ${a.totalOrders} in ${a.timeframe}`,` bookings ${i.pendingBookings} pending`,` sales ${o?`${o.revenue.toLocaleString()} ${o.currencyCode} from ${o.orders} paid orders`:"none"}`,` visits ${a.totalVisits}`,""].join(`
|
|
142
|
+
`))),s.tasks.length>0)process.stdout.write(`Needs attention:
|
|
143
|
+
`),k(s.tasks,[{header:"KIND",get:(c)=>c.kind},{header:"WHEN",get:(c)=>x(c.at)},{header:"DETAIL",get:(c)=>c.detail}])}import{spawn as yo}from"node:child_process";import Mt from"node:path";var lo="https://vcity.io/cli/install.sh",po=1e4,ho=64,Va=/^(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;function Ja(t){return t.length>0&&t.length<=ho&&Va.test(t)}function Ha(){return typeof process.versions.bun==="string"?"binary":"npm"}async function Ya(){let t=`https://registry.npmjs.org/${Tt}/latest`,e;try{e=await fetch(t,{headers:{accept:"application/json"},signal:AbortSignal.timeout(po)})}catch(n){if(n instanceof Error&&n.name==="TimeoutError")throw Error(`npm registry did not respond within ${po/1000}s. Try again later.`,{cause:n});throw Error("Could not reach the npm registry. Check your internet connection.",{cause:n})}if(!e.ok)throw Error(`Failed to fetch latest version from npm (HTTP ${e.status})`);let r=await e.json();if(!r.version||typeof r.version!=="string"||r.version.length>ho)throw Error("Latest version response from npm is missing or invalid `version` field");return r.version}function mo(t){let[e,...r]=t.split("-"),[n,i,a]=e.split(".").map((s)=>parseInt(s,10));return{major:Number.isFinite(n)?n:0,minor:Number.isFinite(i)?i:0,patch:Number.isFinite(a)?a:0,prerelease:r.join("-")}}function Tr(t,e){let r=mo(t),n=mo(e);if(r.major!==n.major)return r.major-n.major;if(r.minor!==n.minor)return r.minor-n.minor;if(r.patch!==n.patch)return r.patch-n.patch;if(r.prerelease===n.prerelease)return 0;if(r.prerelease==="")return 1;if(n.prerelease==="")return-1;return r.prerelease<n.prerelease?-1:1}function Qa(t,e){return new Promise((r,n)=>{let i=yo(t,e,{stdio:"inherit",shell:!1});i.on("error",n),i.on("exit",(a)=>r({exitCode:a??1}))})}function Wa(t,e=["--version"]){return new Promise((r)=>{let n=yo(t,e,{stdio:"ignore",shell:!1});n.on("error",()=>r(!1)),n.on("exit",(i)=>r(i===0))})}async function za(){let t=Mt.dirname(process.execPath),e=process.platform==="win32"?[Mt.join(t,"npm.cmd"),Mt.join(t,"npm")]:[Mt.join(t,"npm")];for(let r of e)if(await Wa(r))return r;return}function fo(){process.stdout.write(`Download, inspect, then run (recommended):
|
|
70
144
|
`),process.stdout.write(` f=$(mktemp)
|
|
71
|
-
`),process.stdout.write(` curl -fsSL ${
|
|
145
|
+
`),process.stdout.write(` curl -fsSL ${lo} -o "$f"
|
|
72
146
|
`),process.stdout.write(` less "$f"
|
|
73
147
|
`),process.stdout.write(` bash "$f"
|
|
74
148
|
`),process.stdout.write(`
|
|
75
149
|
Or, if you trust the origin (no signature verification is performed):
|
|
76
|
-
`),process.stdout.write(` curl -fsSL ${
|
|
77
|
-
`)}async function
|
|
78
|
-
`),process.stdout.write(`latest: ${
|
|
79
|
-
`),!
|
|
150
|
+
`),process.stdout.write(` curl -fsSL ${lo} | bash
|
|
151
|
+
`)}async function wo(t={}){let e=f(t.json),r=Ha(),n=await Ya(),i=E(n),s=Tr(nt,i)<0;if(e==="json"){if(g({current:nt,latest:i,outdated:s,installMethod:r}),t.check||!s)return}else{if(process.stdout.write(`current: ${nt}
|
|
152
|
+
`),process.stdout.write(`latest: ${i}
|
|
153
|
+
`),!s){process.stdout.write(`vcity is up to date.
|
|
80
154
|
`);return}process.stdout.write(`install: ${r==="binary"?"standalone binary":"npm global"}
|
|
81
|
-
`)}if(
|
|
155
|
+
`)}if(t.check)return;if(!t.yes&&e!=="json"){if(process.stdout.write(`
|
|
82
156
|
Run with --yes to apply the update, or use the command below:
|
|
83
|
-
`),r==="binary")
|
|
84
|
-
`);return}if(r==="binary"){if(
|
|
157
|
+
`),r==="binary")fo();else process.stdout.write(` npm install -g ${Tt}@latest
|
|
158
|
+
`);return}if(r==="binary"){if(e!=="json")process.stdout.write(`
|
|
85
159
|
This CLI was installed from a standalone binary.
|
|
86
|
-
`),
|
|
87
|
-
npm install -g ${
|
|
160
|
+
`),fo();return}if(!Ja(i))throw Error(`Refusing to install: registry returned a non-semver \`latest\` value. Expected MAJOR.MINOR.PATCH; got: ${i.slice(0,100)}`);let o=await za();if(!o)throw Error(`Could not find \`npm\` alongside the current Node.js binary (${Mt.dirname(process.execPath)}). Run this yourself with a trusted npm:
|
|
161
|
+
npm install -g ${Tt}@${i}`);process.stdout.write(`
|
|
88
162
|
Installing latest from npm…
|
|
89
|
-
`);let{exitCode:
|
|
90
|
-
Updated to ${
|
|
91
|
-
`)}
|
|
92
|
-
`)
|
|
93
|
-
`),
|
|
94
|
-
`)
|
|
95
|
-
|
|
96
|
-
`)
|
|
97
|
-
`),
|
|
163
|
+
`);let{exitCode:c}=await Qa(o,["install","-g",`${Tt}@${i}`]);if(c!==0)throw Error(`npm install exited with code ${c}`);process.stdout.write(`
|
|
164
|
+
Updated to ${i}. Run \`vcity --version\` to confirm.
|
|
165
|
+
`)}import Lt from"node:fs";import ot from"node:path";var Xe=".vcity-vault.json",Ka=/^---\n([\s\S]*?)\n---\n?/;function Er(t){return["---",`id: ${t.id}`,`title: ${JSON.stringify(t.title)}`,`tags: ${JSON.stringify(t.tags??[])}`,"---",t.content??""].join(`
|
|
166
|
+
`)}function qt(t){let e=t.replace(/\r\n/g,`
|
|
167
|
+
`),r=e.match(Ka);if(!r)return{content:e};let n={};for(let a of r[1].split(`
|
|
168
|
+
`)){let s=a.indexOf(":");if(s>0)n[a.slice(0,s).trim()]=a.slice(s+1).trim()}let i=(a)=>{if(a===void 0)return;try{return JSON.parse(a)}catch{return a}};return{id:n.id||void 0,title:i(n.title),tags:i(n.tags),content:e.slice(r[0].length)}}function Xa(t,e){let r=(t.slug||t.title||t.id).toLowerCase().replace(/[^a-z0-9_-]+/g,"-").replace(/^-+|-+$/g,"")||t.id,n=`${r.slice(0,80)}.md`;if(e.has(n))n=`${r.slice(0,60)}-${t.id.replace(/[^a-zA-Z0-9_-]/g,"")}.md`;return e.add(n),n}function Cr(t){let e=ot.join(t,Xe);if(!Lt.existsSync(e))return;return JSON.parse(st(e))}function Rr(t,e){return{file:e,version:t.version??0,content:t.content??"",title:t.title,tags:t.tags??[]}}function vo(t,e){let r=ot.join(t,e.file);if(!Lt.existsSync(r))return!1;let n=qt(st(r));return n.content!==e.content||n.title!==void 0&&n.title!==e.title||n.tags!==void 0&&JSON.stringify(n.tags)!==JSON.stringify(e.tags)}async function Za(t,e,r,n){let i=p().vault,a=Cr(e);if(a&&a.org!==t)throw new y(`${e} was pulled from ${a.org}, not ${t}`);let s=a?Object.values(a.notes).filter((w)=>vo(e,w)):[];if(s.length>0&&r.force!==!0)throw new y(`${s.length} page(s) have local edits that were not pushed (${s.map((w)=>w.file).slice(0,5).join(", ")}). Run \`vcity vault push\` first, or pass --force to overwrite them.`);Lt.mkdirSync(e,{recursive:!0});let{data:o}=await i.listNotes(t),c=new Set,u={org:t,notes:{}};for(let w of o){let{note:v}=await i.getNote(t,w.id),R=Xa(v,c);Z(ot.join(e,R),Er(v)),u.notes[v.id]=Rr(v,R)}Z(ot.join(e,Xe),`${JSON.stringify(u,null,2)}
|
|
169
|
+
`);let l=Lt.readdirSync(e).filter((w)=>w.endsWith(".md")&&!c.has(w)).filter((w)=>{let v=qt(st(ot.join(e,w))).id;return v!==void 0&&!u.notes[v]});if(n)g({org:t,dir:e,pulled:Object.keys(u.notes).length,orphans:l});else if(process.stdout.write(`Pulled ${Object.keys(u.notes).length} pages into ${E(e)}.
|
|
170
|
+
`),l.length>0)process.stdout.write(E(`Not on the server any more (left untouched; push ignores them): ${l.join(", ")}
|
|
171
|
+
`))}async function tc(t,e,r,n){let i=Cr(e);if(!i)throw new y(`${e} has no ${Xe}; run \`vcity vault pull ${e}\` first`);if(i.org!==t)throw new y(`${e} was pulled from ${i.org}, not ${t}`);let a=p().vault,s=r["dry-run"]===!0,o=[],u=Lt.readdirSync(e).filter((v)=>v.endsWith(".md")).sort().map((v)=>({file:v,parsed:qt(st(ot.join(e,v)))})),l=new Map;for(let{file:v,parsed:R}of u){if(!R.id)continue;let T=l.get(R.id);if(T)throw new y(`${T} and ${v} both carry id ${R.id}; keep one (or delete the id line to create a new page)`);l.set(R.id,v)}for(let{file:v,parsed:R}of u){let T=R.id?i.notes[R.id]:void 0;try{if(R.id&&(!T||T.file!==v)){o.push({file:v,action:"skip",id:R.id,error:T?`page now lives in ${T.file}`:"page was deleted or renamed on the server since the last pull"});continue}if(!R.id||!T){let D=R.title??v.replace(/\.md$/,"");if(!s){let X=await a.createNote(t,{title:D,content:R.content,tags:R.tags??[]}),L=X.note??X,rt={...L,content:R.content};i.notes[L.id]=Rr(rt,v),Z(ot.join(e,v),Er(rt)),o.push({file:v,action:"create",id:L.id})}else o.push({file:v,action:"create"});continue}if(!vo(e,T)){o.push({file:v,action:"unchanged",id:R.id});continue}if(s){o.push({file:v,action:"save",id:R.id});continue}let N=await a.saveNote(t,R.id,{content:R.content,...R.title!==void 0&&{title:R.title},...R.tags!==void 0&&{tags:R.tags},baseVersion:T.version,baseContent:T.content}),F=N.note;if(i.notes[R.id]=Rr({...F,content:F.content??R.content},v),N.merged)Z(ot.join(e,v),Er(F));o.push({file:v,action:N.merged?"merged":"save",id:R.id})}catch(N){o.push({file:v,action:"error",id:R.id,error:N.message})}}if(!s)Z(ot.join(e,Xe),`${JSON.stringify(i,null,2)}
|
|
172
|
+
`);if(n)g({org:t,dir:e,dryRun:s,results:o});else k(o.filter((v)=>v.action!=="unchanged"),[{header:"FILE",get:(v)=>v.file},{header:"RESULT",get:(v)=>v.action==="merged"?"merged with newer server edits (file updated)":v.action},{header:"NOTE",get:(v)=>v.error??""}]);let w=o.filter((v)=>v.action==="error").length;if(w>0)throw Error(`${w} of ${o.length} pages failed`)}function ec(t,e){let n=Cr(ot.dirname(ot.resolve(t)))?.notes[e];return n&&n.file===ot.basename(t)?n:void 0}var rc="vcity vault list|get <id>|create --title <s> [--file <f.md>|--content <s>]|save <id> --file <f.md>|delete <id>|move <id> --parent <id|root> [--order n]|search <text>|pull <dir>|push <dir> [--dry-run]";async function bo(t,e,r){let n=f(!!r.json)==="json",i=h(m(r,"org")),a=p().vault;switch(t){case"list":{let{data:s}=await a.listNotes(i);if(n)g({org:i,notes:s});else k(s,[{header:"ID",get:(o)=>o.id},{header:"TITLE",get:(o)=>o.title},{header:"PARENT",get:(o)=>o.parentId??""},{header:"TAGS",get:(o)=>(o.tags??[]).join(",")},{header:"UPDATED",get:(o)=>x(o.updatedAt)}]);return}case"get":{let s=I(e[0],"vcity vault get <id>","note id"),o=await a.getNote(i,s);if(n)g(o);else process.stdout.write(`${E(`# ${o.note.title}
|
|
173
|
+
|
|
174
|
+
${o.note.content??""}`)}
|
|
175
|
+
`);return}case"create":{let s=G(m(r,"title"),"vcity vault create --title <s> [--file <f.md>|--content <s>] [--parent <id>] [--tags a,b]"),o=m(r,"file"),c=o?qt(st(o)).content:m(r,"content")??"",u=await a.createNote(i,{title:s,content:c,tags:q(r,"tags")??[],...m(r,"parent")!==void 0&&{parentId:m(r,"parent")}});if(n)g(u);else process.stdout.write(`Created page ${E(s)}.
|
|
176
|
+
`);return}case"save":{let s=I(e[0],"vcity vault save <id> --file <f.md> | --content <s>","note id"),o=m(r,"file"),u=(o?qt(st(o)):void 0)?.content??G(m(r,"content"),"vcity vault save <id> --file <f.md> | --content <s>"),l=o?ec(o,s):void 0,w=l?.version??(await a.getNote(i,s)).note.version??0,v=await a.saveNote(i,s,{content:u,...m(r,"title")!==void 0&&{title:m(r,"title")},baseVersion:w,...l&&{baseContent:l.content}});if(n)g(v);else process.stdout.write(v.merged?`Saved (merged with newer edits).
|
|
177
|
+
`:`Saved.
|
|
178
|
+
`);return}case"delete":{let s=I(e[0],"vcity vault delete <id> [--yes]","note id");if(!await B(`Delete vault page ${s}?`,{yes:r.yes===!0,json:n}))return;let o=await a.deleteNote(i,s);if(n)g(o);else process.stdout.write(`Deleted.
|
|
179
|
+
`);return}case"move":{let s=I(e[0],"vcity vault move <id> --parent <id|root> [--order <n>]","note id"),o=G(m(r,"parent"),"vcity vault move <id> --parent <id|root> [--order <n>]"),c=await a.moveNote(i,s,{parentId:o==="root"?null:o,order:C(r,"order")??0});if(n)g(c);else process.stdout.write(`Moved.
|
|
180
|
+
`);return}case"search":{let s=G(e.join(" ")||m(r,"q"),"vcity vault search <text>"),o=await a.search(i,{q:s});if(n)g(o);else k(o.data??[],[{header:"ID",get:(c)=>String(c.id??"")},{header:"TITLE",get:(c)=>String(c.title??"")},{header:"MATCH",get:(c)=>String(c.snippet??c.excerpt??"").replace(/\s+/g," ").slice(0,80)}]);return}case"pull":return Za(i,G(e[0],"vcity vault pull <dir> [--force]"),r,n);case"push":return tc(i,G(e[0],"vcity vault push <dir> [--dry-run]"),r,n);default:throw new y(`usage: ${rc}`)}}var ko=["order.created","product.created","booking.created"],sc="vcity webhooks list|get|create|update|delete|test|deliveries|rotate (create: --url <https://…> --events order.created,booking.created)";function nc(t){let e=q(t,"events");if(!e)return;let r=e.filter((n)=>!ko.includes(n));if(r.length>0)throw new y(`unknown event ${r.join(", ")}. Allowed: ${ko.join(", ")}`);return e}function oc(t,e){let r=m(t,"header");if(r===void 0)return;if(e)throw new y(`an update replaces every custom header, so --header would drop the others; pass them all with --data '{"headers":{…}}'`);let n=r.indexOf(":");if(n<=0)throw new y('--header must look like "Name: value"');return{[r.slice(0,n).trim()]:r.slice(n+1).trim()}}function Io(t,e=!1){let r=P(m(t,"data"));if(r!==void 0&&(typeof r!=="object"||r===null||Array.isArray(r)))throw new y("--data must be a JSON object");let n={...r},i=m(t,"url");if(i!==void 0){if(!i.startsWith("https://"))throw new y("--url must be an https:// URL");n.url=i}let a=nc(t);if(a)n.events=a;let s=oc(t,e);if(s)n.headers={...n.headers,...s};let o=m(t,"description");if(o!==void 0)n.description=o;let c=A(t,"status",["active","paused"]);if(c)n.status=c;return n}function jo(t){process.stdout.write(`Signing secret (shown once — store it now):
|
|
181
|
+
${E(String(t))}
|
|
182
|
+
Verify the X-Vcity-Signature header of each delivery with it.
|
|
183
|
+
`)}async function To(t,e,r){let n=f(!!r.json)==="json",i=h(m(r,"org")),a=p();switch(t){case"list":{let s=await a.webhooks.list(i,{...C(r,"limit",{min:1,max:200})!==void 0&&{limit:C(r,"limit")},...C(r,"skip")!==void 0&&{skip:C(r,"skip")}});if(n)g({org:i,webhooks:s.data,total:s.total,skip:s.skip,limit:s.limit,hasMore:s.hasMore});else k(s.data,[{header:"ID",get:(o)=>o.id},{header:"STATUS",get:(o)=>o.status},{header:"EVENTS",get:(o)=>o.events.join(",")},{header:"URL",get:(o)=>o.url},{header:"FAILURES",get:(o)=>String(o.consecutiveFailures??0)}]);return}case"get":{let s=I(e[0],"vcity webhooks get <id>","webhook id"),o=await a.webhooks.get(i,s);if(n)g(o);else j(o);return}case"create":{let s=Io(r);if(typeof s.url!=="string"||!Array.isArray(s.events))throw new y('usage: vcity webhooks create --url <https://…> --events order.created[,…] [--header "X-Key: v"] [--description <s>]');let o=await a.webhooks.create(i,s);if(n)g(o);else process.stdout.write(`Created webhook ${E(o.id)}.
|
|
184
|
+
`),jo(o.signingSecret);return}case"update":{let s=I(e[0],"vcity webhooks update <id> [--url …] [--events …] [--status active|paused]","webhook id"),o=Io(r,!0);if(Object.keys(o).length===0)throw new y("webhooks update: nothing to change");let c=await a.webhooks.update(i,s,o);if(n)g(c);else process.stdout.write(`Updated webhook ${s}.
|
|
185
|
+
`);return}case"delete":{let s=I(e[0],"vcity webhooks delete <id> [--yes]","webhook id");if(!await B(`Delete webhook ${s} in ${i}?`,{yes:r.yes===!0,json:n}))return;let o=await a.webhooks.delete(i,s);if(n)g(o);else process.stdout.write(`Deleted webhook ${s}.
|
|
186
|
+
`);return}case"test":{let s=I(e[0],"vcity webhooks test <id>","webhook id"),o=await a.webhooks.test(i,s);if(n)g(o);else process.stdout.write(E(`${o.ok?"OK":"FAILED"} — receiver answered ${o.status??"nothing"} in ${o.durationMs} ms${o.error?` (${o.error})`:""}
|
|
187
|
+
${o.responseBody?`${o.responseBody}
|
|
188
|
+
`:""}`));if(!o.ok)throw Error("test delivery failed");return}case"deliveries":{let s=I(e[0],"vcity webhooks deliveries <id> [--failed] [--limit n] [--before <ms>]","webhook id"),o=await a.webhooks.deliveries(i,s,{...C(r,"limit",{min:1,max:200})!==void 0&&{limit:C(r,"limit")},...C(r,"before")!==void 0&&{beforeTs:C(r,"before")},...r.failed===!0&&{success:"false"}});if(n)g(o);else if(k(o.data,[{header:"WHEN",get:(c)=>x(c.createdAt)},{header:"EVENT",get:(c)=>c.eventName},{header:"OK",get:(c)=>c.success?"yes":"no"},{header:"STATUS",get:(c)=>String(c.responseStatus??"")},{header:"TRY",get:(c)=>String(c.attempt??"")},{header:"ERROR",get:(c)=>c.error??""}]),o.nextCursor)process.stdout.write(`More: --before ${o.nextCursor}
|
|
189
|
+
`);return}case"rotate":{let s=I(e[0],"vcity webhooks rotate <id> [--yes]","webhook id");if(!await B(`Rotate the signing secret of ${s}? The old secret stops working immediately.`,{yes:r.yes===!0,json:n}))return;let o=await a.webhooks.rotateSecret(i,s);if(n)g(o);else jo(o.signingSecret);return}default:throw new y(`usage: ${sc}`)}}function V(t){let e=P(m(t,"data"));if(e===void 0)return{};if(typeof e!=="object"||e===null||Array.isArray(e))throw new y("--data must be a JSON object");return{...e}}function it(t,e){let r=m(t,e);if(r===void 0)return;let n=Number(r);if(r.trim()===""||!Number.isFinite(n))throw new y(`--${e} must be a number (got: ${r})`);return n}function U(t){return Object.fromEntries(Object.entries(t).filter(([,e])=>e!==void 0))}var Ze=["run","runs","run-get","cancel-run","proposals","approve","reject"];async function Eo(t,e,r){let n=f(!!r.json)==="json",i=h(m(r,"org")),a=p();switch(t){case"run":{let s=I(e[0],"vcity agents run <agentId>","agent id"),o=await a.agents.run(i,s);if(n)g(o);else process.stdout.write(`Queued a run of ${s}${o.run?.id?` (${E(o.run.id)})`:""}. The reply lands in conversation ${E(o.roomId??"?")}.
|
|
190
|
+
`);return}case"runs":{let o=(await a.agents.listRuns(i,U({agentId:m(r,"agent"),limit:C(r,"limit",{min:1,max:200})}))).data??[];if(n)g({org:i,runs:o});else k(o,[{header:"ID",get:(c)=>c.id},{header:"AGENT",get:(c)=>c.agentId??""},{header:"STATUS",get:(c)=>c.status??""},{header:"TRIGGER",get:(c)=>c.trigger??""},{header:"STARTED",get:(c)=>c.startedAt?x(c.startedAt):""},{header:"ERROR",get:(c)=>c.error??""}]);return}case"run-get":{let s=I(e[0],"vcity agents run-get <runId>","run id"),o=await a.agents.getRun(i,s);if(n)g(o);else j(o);return}case"cancel-run":{let s=I(e[0],"vcity agents cancel-run <runId>","run id"),o=await a.agents.cancelRun(i,s);if(n)g(o);else process.stdout.write(`Cancelled run ${s}.
|
|
191
|
+
`);return}case"proposals":{let o=(await a.agents.listProposals(i,U({status:A(r,"status",["pending","approved","rejected"]),agentId:m(r,"agent"),limit:C(r,"limit",{min:1,max:200})}))).data??[];if(n)g({org:i,proposals:o});else k(o,[{header:"ID",get:(c)=>c.id},{header:"AGENT",get:(c)=>c.agentId??""},{header:"KIND",get:(c)=>c.kind??""},{header:"CONCEPT",get:(c)=>c.concept??""},{header:"STATUS",get:(c)=>c.status??""},{header:"CREATED",get:(c)=>c.createdAt?x(c.createdAt):""}]);return}case"approve":{let s=I(e[0],"vcity agents approve <proposalId> [--confirm-destructive] [--notify-customer]","proposal id");if(!await B(`Approve proposal ${s}? Its change is applied to the store.`,{yes:r.yes===!0,json:n}))return;let o=await a.agents.approveProposal(i,s,U({confirmDestructive:r["confirm-destructive"]===!0?!0:void 0,notifyCustomer:r["notify-customer"]===!0?!0:void 0}));if(n)g(o);else process.stdout.write(`Approved proposal ${s}.
|
|
192
|
+
`);return}case"reject":{let s=I(e[0],"vcity agents reject <proposalId>","proposal id"),o=await a.agents.rejectProposal(i,s);if(n)g(o);else process.stdout.write(`Rejected proposal ${s}.
|
|
193
|
+
`);return}default:throw new y(`usage: vcity agents list|get|${Ze.join("|")}`)}}var ic="vcity campaigns list|get|create|update|delete|activate|pause|stats|contacts|add-contacts|remove-contact",ac=["event","product","room","custom"],cc=["invitation-link","pre-register","product-launch","product-reminder","scene-invitation","broadcast"],dc=["event-cadence","scheduled","immediate"];function Ro(t){return{...V(t),...U({name:m(t,"name"),resourceType:A(t,"resource-type",ac),resourceId:m(t,"resource"),mode:A(t,"mode",cc),sendType:A(t,"send",dc),scheduledAt:M(t,"at"),emailSubject:m(t,"subject"),emailBody:m(t,"body")})}}function uc(t){let e=V(t),r=q(t,"emails");if(r)e.contacts=[...e.contacts??[],...r.map((n)=>({email:n}))];return e}async function Co(t,e,r){let n=f(!!r.json)==="json",i=h(m(r,"org")),a=p(),s=(o)=>I(e[0],o,"campaign id");switch(t){case"list":{let o=await a.campaigns.list(i,U({status:m(r,"status"),search:m(r,"search"),limit:C(r,"limit",{min:1,max:200}),skip:C(r,"skip")})),c=o.data??[];if(n)g({org:i,campaigns:c,total:o.total,skip:o.skip,limit:o.limit,hasMore:o.hasMore});else k(c,[{header:"ID",get:(u)=>u.id},{header:"NAME",get:(u)=>u.name??""},{header:"STATUS",get:(u)=>u.status??""},{header:"MODE",get:(u)=>u.mode??""},{header:"SEND",get:(u)=>u.sendType??""}]);return}case"get":case"stats":{let o=s(`vcity campaigns ${t} <id>`),c=t==="get"?await a.campaigns.get(i,o):await a.campaigns.stats(i,o);if(n)g(c);else j(c);return}case"create":{let o=Ro(r);for(let u of["name","resourceType","mode","emailSubject","emailBody"])if(o[u]===void 0)throw new y("usage: vcity campaigns create --name <s> --resource-type event|product|room|custom [--resource <id>] --mode <mode> --subject <s> --body <html> [--send immediate|scheduled|event-cadence] [--at <date>] [--data <json>]");let c=await a.campaigns.create(i,o);if(n)g(c);else process.stdout.write(`Created campaign ${E(c.id)} (draft). Add recipients with \`vcity campaigns add-contacts\`.
|
|
194
|
+
`);return}case"update":{let o=s("vcity campaigns update <id> [--name …] [--subject …] [--data <json>]"),c=Ro(r);if(Object.keys(c).length===0)throw new y("campaigns update: nothing to change");let u=await a.campaigns.update(i,o,c);if(n)g(u);else process.stdout.write(`Updated campaign ${o}.
|
|
195
|
+
`);return}case"delete":{let o=s("vcity campaigns delete <id> [--yes]");if(!await B(`Delete campaign ${o} in ${i}?`,{yes:r.yes===!0,json:n}))return;let c=await a.campaigns.delete(i,o);if(n)g(c);else process.stdout.write(`Deleted campaign ${o}.
|
|
196
|
+
`);return}case"activate":case"pause":{let o=s(`vcity campaigns ${t} <id>`);if(t==="activate"&&!await B(`Activate campaign ${o}? Emails start going out to its recipients.`,{yes:r.yes===!0,json:n}))return;let c=t==="activate"?await a.campaigns.activate(i,o):await a.campaigns.pause(i,o);if(n)g(c);else process.stdout.write(`${t==="activate"?"Activated":"Paused"} campaign ${o}.
|
|
197
|
+
`);return}case"contacts":{let o=s("vcity campaigns contacts <id> [--limit n] [--skip n]"),c=await a.campaigns.listContacts(i,o,U({limit:C(r,"limit",{min:1,max:200}),skip:C(r,"skip")})),u=c.data??[];if(n)g({org:i,campaign:o,contacts:u,total:c.total,hasMore:c.hasMore});else k(u,[{header:"ID",get:(l)=>l.id},{header:"EMAIL",get:(l)=>l.email??""},{header:"NAME",get:(l)=>l.name??""},{header:"STATUS",get:(l)=>l.status??""}]);return}case"add-contacts":{let o=s(`vcity campaigns add-contacts <id> --emails a@b.com,c@d.com | --data '{"contacts":[…]}'`),c=uc(r);if(!Array.isArray(c.contacts)||c.contacts.length===0)throw new y("campaigns add-contacts: pass --emails or --data with contacts");let u=await a.campaigns.addContacts(i,o,c);if(n)g(u);else j(u);return}case"remove-contact":{let o=s("vcity campaigns remove-contact <id> <contactId>"),c=I(e[1],"vcity campaigns remove-contact <id> <contactId>","contact id"),u=await a.campaigns.removeContact(i,o,c);if(n)g(u);else process.stdout.write(`Removed ${c} from campaign ${o}.
|
|
198
|
+
`);return}default:throw new y(`usage: ${ic}`)}}var gc="vcity coupons list|get|create|update|activate|deactivate|validate",lc=["percentage","fixed","free-shipping","bxgy"];function So(t){let e=it(t,"percent"),r=it(t,"amount"),n=A(t,"type",lc);if(!n&&e!==void 0)n="percentage";if(!n&&r!==void 0)n="fixed";return{...V(t),...U({code:m(t,"code"),discountType:n,percentageOff:e,fixedAmountOff:r,currencyCode:A(t,"currency",["USD","COP"]),maxDiscountAmount:it(t,"max-discount"),minOrderAmount:it(t,"min-order"),maxTotalUses:C(t,"max-uses",{min:1}),maxUsesPerUser:C(t,"max-uses-per-user",{min:1}),startDate:M(t,"from"),endDate:M(t,"until"),productIds:q(t,"products"),collectionIds:q(t,"collections")})}}function pc(t){if(t.discountType==="percentage")return`${t.percentageOff??"?"}%`;if(t.discountType==="fixed")return`${t.fixedAmountOff??"?"} ${t.currencyCode??""}`.trim();return t.discountType??""}async function Oo(t,e,r){let n=f(!!r.json)==="json",i=h(m(r,"org")),a=p();switch(t){case"list":{let s=await a.coupons.list(i,U({active:r.active===!0?"true":void 0,limit:C(r,"limit",{min:1,max:200}),skip:C(r,"skip")})),o=s.data??[];if(n)g({org:i,coupons:o,total:s.total,skip:s.skip,limit:s.limit,hasMore:s.hasMore});else k(o,[{header:"ID",get:(c)=>c.id},{header:"CODE",get:(c)=>c.code??""},{header:"DISCOUNT",get:pc},{header:"ACTIVE",get:(c)=>c.active?"yes":"no"},{header:"ENDS",get:(c)=>c.endDate?x(c.endDate):""}]);return}case"get":{let s=I(e[0],"vcity coupons get <id>","coupon id"),o=await a.coupons.get(i,s);if(n)g(o);else j(o);return}case"create":{let s=So(r);if(typeof s.code!=="string"||typeof s.discountType!=="string")throw new y("usage: vcity coupons create --code <CODE> (--percent <n> | --amount <n> --currency USD|COP | --type free-shipping) [--until <date>] [--max-uses <n>] [--min-order <n>] [--data <json>]");let o=await a.coupons.create(i,s);if(n)g(o);else process.stdout.write(`Created coupon ${E(o.code??"")} (${E(o.id)}).
|
|
199
|
+
`);return}case"update":{let s=I(e[0],"vcity coupons update <id> [--percent …] [--until …] [--data <json>]","coupon id"),o=So(r);if(Object.keys(o).length===0)throw new y("coupons update: nothing to change");let c=await a.coupons.update(i,s,o);if(n)g(c);else process.stdout.write(`Updated coupon ${s}.
|
|
200
|
+
`);return}case"activate":case"deactivate":{let s=I(e[0],`vcity coupons ${t} <id>`,"coupon id"),o=t==="activate"?await a.coupons.activate(i,s):await a.coupons.deactivate(i,s);if(n)g(o);else process.stdout.write(`${t==="activate"?"Activated":"Deactivated"} coupon ${s}.
|
|
201
|
+
`);return}case"validate":{let s=I(e[0]??m(r,"code"),`vcity coupons validate <CODE> [--data '{"cart":{…}}']`,"coupon code"),o=await a.coupons.validate(i,{...V(r),code:s});if(n)g(o);else j(o);return}default:throw new y(`usage: ${gc}`)}}var at=(t)=>t===void 0||t===null?"":String(t),xo="vcity dropshipping connections | products | import --connection <id> --products a,b (--markup-percent <n> | --markup-fixed <n> [--currency COP]) | fulfillments <orderId> | retry <fulfillmentId>";function _t(t,e,r){if(f(!!t.json)==="json"||!r)g(e);else r()}async function Ao(t,e,r){let n=h(m(r,"org")),i=p().dropshipping;switch(t){case"connections":{let a=await i.connections(n);return _t(r,a,()=>k(a.data??[],[{header:"ID",get:(s)=>at(s.id)},{header:"PROVIDER",get:(s)=>at(s.provider)}]))}case"products":{let a=await i.products(n,{...C(r,"limit",{min:1,max:100})!==void 0&&{limit:C(r,"limit")}});return _t(r,a,()=>k(a.data??[],[{header:"ID",get:(s)=>at(s.id)},{header:"NAME",get:(s)=>at(s.name)},{header:"PRICE",get:(s)=>`${at(s.price)} ${at(s.currencyCode)}`},{header:"SOURCE",get:(s)=>at(s.dropshippingSource?.externalProductId)}]))}case"import":{let a=m(r,"connection"),s=q(r,"products")??[],o=it(r,"markup-percent"),c=it(r,"markup-fixed");if(!a||s.length===0||o===void 0&&c===void 0)throw new y(`usage: ${xo}`);let u=o!==void 0?{type:"percentage",value:o}:{type:"fixed",value:c,...m(r,"currency")!==void 0&&{currencyCode:m(r,"currency")}};return _t(r,await i.import(n,{connectionId:a,externalProductIds:s,markup:u}))}case"fulfillments":{let a=I(e[0],"vcity dropshipping fulfillments <orderId>","order id"),s=await i.fulfillments(n,a);return _t(r,s,()=>k(s.data??[],[{header:"ID",get:(o)=>at(o.id)},{header:"STATUS",get:(o)=>at(o.status)},{header:"TRACKING",get:(o)=>at(o.trackingNumber)},{header:"SUPPLIER ORDER",get:(o)=>at(o.externalOrderId)}]))}case"retry":{let a=I(e[0],"vcity dropshipping retry <fulfillmentId>","fulfillment id");return _t(r,await i.retryFulfillment(n,a))}default:throw new y(`usage: ${xo}`)}}var tr=(t)=>t===void 0||t===null?"":String(t),mc="vcity pos session | open --cash <n> --currency USD|COP | close <sessionId> --cash <n> [--notes <s>] | summary <sessionId> | sales [--session <id>] [--method cash|epayco] [--from <date>] [--to <date>] | sale <saleId> | sell --data <json|@file> | favorites [--set a,b]";function vt(t,e,r){if(f(!!t.json)==="json"||!r)g(e);else r()}async function Po(t,e,r){let n=h(m(r,"org")),i=p().pos;switch(t){case"session":{let a=await i.activeSession(n);return vt(r,a,()=>a.session?j(a.session):process.stdout.write(`No register session is open.
|
|
202
|
+
`))}case"open":{let a=it(r,"cash"),s=A(r,"currency",["USD","COP"]);if(a===void 0||!s)throw new y("usage: vcity pos open --cash <n> --currency USD|COP");return vt(r,await i.openSession(n,{openingCash:a,currencyCode:s}))}case"close":{let a=I(e[0],"vcity pos close <sessionId> --cash <n>","session id"),s=it(r,"cash");if(s===void 0)throw new y("usage: vcity pos close <sessionId> --cash <n> [--notes <s>]");let o=await i.closeSession(n,a,U({closingCash:s,notes:m(r,"notes")}));return vt(r,o,()=>j({status:o.status,expectedCash:o.expectedCash,closingCash:o.closingCash,discrepancy:o.discrepancy}))}case"summary":{let a=I(e[0],"vcity pos summary <sessionId>","session id"),s=await i.sessionSummary(n,a);return vt(r,s,()=>j(s))}case"sales":{let a=await i.sales(n,U({sessionId:m(r,"session"),paymentMethod:A(r,"method",["cash","epayco"]),startDate:M(r,"from"),endDate:M(r,"to"),limit:C(r,"limit",{min:1,max:100}),skip:C(r,"skip")}));return vt(r,a,()=>k(a.data??[],[{header:"RECEIPT",get:(s)=>tr(s.receiptNumber)},{header:"TOTAL",get:(s)=>`${tr(s.total)} ${tr(s.currencyCode)}`},{header:"WHEN",get:(s)=>typeof s.createdAt==="number"?x(s.createdAt):""},{header:"ID",get:(s)=>tr(s.id)}]))}case"sale":{let a=I(e[0],"vcity pos sale <saleId>","sale id");return vt(r,await i.sale(n,a))}case"sell":{let a=V(r);if(!a.sessionId||!a.lineItems)throw new y(`usage: vcity pos sell --data '{"sessionId":…,"lineItems":[…],"payments":[…]}' [--idempotency-key <k>]`);return vt(r,await i.createSale(n,a,m(r,"idempotency-key")))}case"favorites":{let a=m(r,"set"),s=a!==void 0?await i.setFavorites(n,a.split(",").map((o)=>o.trim()).filter(Boolean)):await i.favorites(n);return vt(r,s,()=>process.stdout.write(`${(s.productIds??[]).join(`
|
|
203
|
+
`)}
|
|
204
|
+
`))}default:throw new y(`usage: ${mc}`)}}var Gt=(t)=>t===void 0||t===null?"":String(t);function J(t,e,r){if(f(!!t.json)==="json"||!r)g(e);else r()}async function $o(t,e,r){let n=h(m(r,"org")),i=p().configurators;switch(t){case"list":{let a=await i.list(n);return J(r,a,()=>k(a.data??[],[{header:"ID",get:(s)=>Gt(s.id)},{header:"NAME",get:(s)=>Gt(s.name)},{header:"VERSION",get:(s)=>Gt(s.version)}]))}case"seeds":{let a=await i.seeds(n);return J(r,a,()=>k(a.data??[],[{header:"ID",get:(s)=>Gt(s.id)},{header:"NAME",get:(s)=>Gt(s.name)}]))}case"get":{let a=I(e[0],"vcity configurators get <id>","configurator id");return J(r,await i.get(n,a))}case"create":{let a=m(r,"seed"),s=r.data!==void 0?V(r):void 0;if(!a&&!s)throw new y("usage: vcity configurators create --seed <seedId> | --data <json|@file|->");return J(r,await i.create(n,a?{seedId:a}:{definition:s}))}case"update":{let a=I(e[0],"vcity configurators update <id> --data <patch json> [--bump-version]","configurator id");return J(r,await i.update(n,a,{patch:V(r),...r["bump-version"]===!0&&{bumpVersion:!0}}))}case"delete":{let a=I(e[0],"vcity configurators delete <id>","configurator id");return J(r,await i.delete(n,a))}default:throw new y("usage: vcity configurators list|seeds|get|create|update|delete")}}async function Do(t,e,r){let n=p().chatRooms,i="usage: vcity rooms show|messages|send|search|read <roomId> … (user login only)",a=I(e[0],"usage: vcity rooms show|messages|send|search|read <roomId> … (user login only)","room id");switch(t){case"show":{let s=await n.get(a);return J(r,s,()=>j(s))}case"messages":{let s=await n.messages(a,U({limit:C(r,"limit",{min:1,max:200}),around:m(r,"around")}));return J(r,s,()=>process.stdout.write(`${wt(s.data)}
|
|
205
|
+
`))}case"send":{let s=m(r,"message");if(!s)throw new y("usage: vcity rooms send <roomId> --message <text> [--reply-to <messageId>] [--as-org]");return J(r,await n.send(a,U({content:s,replyToId:m(r,"reply-to"),asOrg:r["as-org"]===!0?!0:void 0})))}case"search":{let s=m(r,"query")??e.slice(1).join(" ");if(!s)throw new y("usage: vcity rooms search <roomId> --query <text>");let o=await n.search(a,s);return J(r,o,()=>process.stdout.write(`${wt(o.data)}
|
|
206
|
+
`))}case"read":return J(r,await n.markRead(a));default:throw new y("usage: vcity rooms show|messages|send|search|read <roomId> … (user login only)")}}async function No(t,e,r){let n=h(m(r,"org")),i=p().surveys;if(t==="create"){let s=m(r,"title");if(!s)throw new y("usage: vcity surveys create --title <s> [--data <json with questions…>]");return J(r,await i.create(n,{questions:[],...V(r),title:s}))}let a=I(e[0],`vcity surveys ${t} <surveyId>`,"survey id");if(t==="update")return J(r,await i.update(n,a,{...V(r),...U({title:m(r,"title")})}));if(t==="publish")return J(r,await i.publish(n,a));if(t==="close")return J(r,await i.close(n,a));if(t==="delete")return J(r,await i.delete(n,a));throw new y("usage: vcity surveys create|update|publish|close|delete")}async function Fo(t,e,r){let n=p().comments,i=I(e[0],`vcity comments ${t} <commentId>`,"comment id");if(t==="edit"){let a=m(r,"message");if(!a)throw new y("usage: vcity comments edit <commentId> --message <text>");return J(r,await n.edit(i,a))}if(t==="delete")return J(r,await n.delete(i));if(t==="pin")return J(r,await n.pin(i));if(t==="unpin")return J(r,await n.unpin(i));throw new y("usage: vcity comments edit|delete|pin|unpin <commentId>")}var H=(t)=>t===void 0||t===null?"":String(t),Uo=(t)=>typeof t==="number"?x(t):"";function Y(t,e,r){if(f(!!t.json)==="json"||!r)g(e);else r()}var Vt=(t)=>U({limit:C(t,"limit",{min:1,max:200}),skip:C(t,"skip")});async function Bo(t,e,r){let n=h(m(r,"org")),i=p();switch(t){case"config":return Y(r,await i.newsletter.getConfig(n));case"subscribers":{let a=await i.newsletter.subscribers(n,Vt(r)),s=a.data??[];return Y(r,a,()=>k(s,[{header:"EMAIL",get:(o)=>H(o.email)},{header:"STATUS",get:(o)=>H(o.status)},{header:"SOURCE",get:(o)=>H(o.source)},{header:"SINCE",get:(o)=>Uo(o.createdAt)}]))}case"stats":{let a=await i.newsletter.stats(n,U({days:C(r,"days",{min:1,max:365})}));return Y(r,a,()=>j(a))}default:throw new y("usage: vcity newsletter config|subscribers|stats [--org <slug>] [--json]")}}async function Mo(t,e,r){let n=h(m(r,"org")),i=p();switch(t){case"list":{let a=await i.surveys.list(n,{...Vt(r),...U({status:A(r,"status",["draft","active","closed"])})});return Y(r,a,()=>k(a.data??[],[{header:"ID",get:(s)=>H(s.id)},{header:"TITLE",get:(s)=>H(s.title)},{header:"STATUS",get:(s)=>H(s.status)},{header:"RESPONSES",get:(s)=>H(s.responseCount)}]))}case"get":{let a=I(e[0],"vcity surveys get <surveyId>","survey id"),s=await i.surveys.get(n,a);return Y(r,s,()=>j(s))}case"responses":{let a=I(e[0],"vcity surveys responses <surveyId>","survey id");return Y(r,await i.surveys.responses(n,a,Vt(r)))}case"create":case"update":case"publish":case"close":case"delete":return No(t,e,r);default:throw new y("usage: vcity surveys list|get|responses|create|update|publish|close|delete [--status draft|active|closed] [--json]")}}async function Lo(t,e,r){let n=p();switch(t){case"list":{let i=I(e[0],"vcity comments list <table:id>","target"),a=await n.comments.list({target:i,...Vt(r)});return Y(r,a,()=>k(a.data??[],[{header:"ID",get:(s)=>H(s.id)},{header:"AUTHOR",get:(s)=>H(s.author?.name)},{header:"WHEN",get:(s)=>Uo(s.createdAt)},{header:"COMMENT",get:(s)=>H(s.content).slice(0,80)}]))}case"add":{let i=I(e[0],"vcity comments add <table:id> --message <text>","target"),a=m(r,"message");if(!a)throw new y("usage: vcity comments add <table:id> --message <text> [--parent <commentId>]");return Y(r,await n.comments.create(U({target:i,content:a,parent:m(r,"parent")})))}case"reactions":{let i=I(e[0],"vcity comments reactions <table:id>","target");return Y(r,await n.comments.reactions(i))}case"react":{let i=I(e[0],"vcity comments react <table:id> <emoji> [--remove]","target"),a=I(e[1],"vcity comments react <table:id> <emoji> [--remove]","emoji");return Y(r,await n.comments.react({target:i,emoji:a,action:r.remove===!0?"remove":"add"}))}case"edit":case"delete":case"pin":case"unpin":return Fo(t,e,r);default:throw new y("usage: vcity comments list|add|reactions|react <table:id> … | edit|delete|pin|unpin <commentId> [--json] (user login only)")}}async function qo(t,e,r){let n=h(m(r,"org")),i=p();switch(t??"summary"){case"summary":{let a=await i.billing.summary(n);return Y(r,a,()=>k(a.plan?.modules??[],[{header:"MODULE",get:(s)=>H(s.module)},{header:"PLAN",get:(s)=>H(s.plan)},{header:"NEXT",get:(s)=>H(s.pendingPlan)},{header:"SUSPENDED",get:(s)=>s.suspended?"yes":""}]))}case"invoices":{let a=await i.billing.invoices(n,Vt(r));return Y(r,a,()=>k(a.data??[],[{header:"ID",get:(s)=>H(s.id)},{header:"PERIOD",get:(s)=>H(s.billingPeriod)},{header:"AMOUNT",get:(s)=>`${H(s.amount)} ${H(s.currencyCode)}`},{header:"STATUS",get:(s)=>s.voided?"void":s.processed?"paid":"open"}]))}case"usage":return Y(r,await i.billing.usage(n));case"credits":return Y(r,await i.billing.credits(n,U({limit:C(r,"limit",{min:1,max:200})})));default:throw new y("usage: vcity billing [summary|invoices|usage|credits] [--org <slug>] [--json]")}}async function _o(t,e,r){let n=h(m(r,"org")),i=p();switch(t??"get"){case"get":{let a=await i.storefront.get(n);return Y(r,a,()=>{j({domain:a.domain?.customDomain??"(none)",status:a.domain?.status??"",error:a.domain?.error??""});let s=[...a.dnsRecords?.host??[],...a.dnsRecords?.txt??[]];if(s.length)k(s,[{header:"TYPE",get:(o)=>H(o.type)},{header:"NAME",get:(o)=>H(o.name)},{header:"VALUE",get:(o)=>H(o.value)}])})}case"domain":{let a=I(e[0],"vcity storefront domain <host>","domain");return Y(r,await i.storefront.setDomain(n,a))}case"verify":return Y(r,await i.storefront.verifyDomain(n));case"remove-domain":return Y(r,await i.storefront.removeDomain(n));case"redirects":return Y(r,await i.storefront.redirects(n));default:throw new y("usage: vcity storefront [get|domain <host>|verify|remove-domain|redirects] [--org <slug>] [--json]")}}var bt=["draft","stage","publish","discard-draft","visibility"],fc={products:"product",events:"event",blogs:"blog post"};async function er(t,e,r,n){let i=f(!!n.json)==="json",a=h(m(n,"org")),s=p().drafts,o=fc[t],c=I(r[0],`vcity ${t} ${e} <id>`,`${o} id`),u;switch(e){case"draft":u=t==="products"?await s.getProductDraft(a,c):t==="events"?await s.getEventDraft(a,c):await s.getBlogDraft(a,c);break;case"stage":{let l=V(n);if(Object.keys(l).length===0)throw new y(`usage: vcity ${t} stage <id> --data <json|@file|->`);u=t==="products"?await s.stageProductDraft(a,c,l):t==="events"?await s.stageEventDraft(a,c,l):await s.stageBlogDraft(a,c,l);break}case"publish":u=t==="products"?await s.publishProduct(a,c):t==="events"?await s.publishEvent(a,c):await s.publishBlog(a,c);break;case"discard-draft":if(!await B(`Discard the unpublished changes of ${o} ${c}?`,{yes:n.yes===!0,json:i}))return;u=t==="products"?await s.discardProductDraft(a,c):t==="events"?await s.discardEventDraft(a,c):await s.discardBlogDraft(a,c);break;case"visibility":{if(t==="blogs")throw new y("blogs have no visibility switch; publish or discard the draft instead");let l=r[1];if(l!=="public"&&l!=="hidden")throw new y(`usage: vcity ${t} visibility <id> public|hidden`);u=t==="products"?await s.setProductVisibility(a,c,l):await s.setEventVisibility(a,c,l);break}default:throw new y(`usage: vcity ${t} ${bt.join("|")} <id>`)}if(i)g(u);else if(e==="draft")j(u??{});else process.stdout.write(`${e==="publish"?"Published":e==="discard-draft"?"Discarded the draft of":e==="stage"?"Staged changes to":"Updated"} ${o} ${c}.
|
|
207
|
+
`)}var yc="vcity keys list|create|revoke|rotate (store API keys; needs a signed-in admin)";function Go(t){process.stdout.write(`API key (shown once — store it now):
|
|
208
|
+
${E(String(t))}
|
|
209
|
+
`)}async function Vo(t,e,r){let n=f(!!r.json)==="json",i=h(m(r,"org")),a=p();switch(t){case"list":{let s=await a.apiKeys.list(i,U({revoked:r.revoked===!0?"true":void 0,limit:C(r,"limit",{min:1,max:200}),skip:C(r,"skip")})),o=s.data??[];if(n)g({org:i,keys:o,total:s.total,hasMore:s.hasMore});else k(o,[{header:"ID",get:(c)=>c.id},{header:"LABEL",get:(c)=>c.label??""},{header:"SCOPES",get:(c)=>(c.scopes??[]).join(",")},{header:"LAST USED",get:(c)=>c.lastUsedAt?x(c.lastUsedAt):""},{header:"REVOKED",get:(c)=>c.revokedAt?x(c.revokedAt):""},{header:"EXPIRES",get:(c)=>c.expiresAt?x(c.expiresAt):""}]);return}case"create":{let s=m(r,"label"),o=q(r,"scopes")??q(r,"scope");if(!s||!o||o.length===0)throw new y("usage: vcity keys create --label <name> --scopes products:read,orders:read");let c=await a.apiKeys.create(i,{label:s,scopes:o});if(n)g(c);else process.stdout.write(`Created API key ${E(c.id)}.
|
|
210
|
+
`),Go(c.token);return}case"revoke":{let s=I(e[0],"vcity keys revoke <id> [--yes]","key id");if(!await B(`Revoke API key ${s} in ${i}? Integrations using it stop working.`,{yes:r.yes===!0,json:n}))return;let o=await a.apiKeys.revoke(i,s);if(n)g(o);else process.stdout.write(`Revoked API key ${s}.
|
|
211
|
+
`);return}case"rotate":{let s=I(e[0],"vcity keys rotate <id> [--yes]","key id");if(!await B(`Rotate API key ${s}? A new token is issued; the old one keeps working for a grace period.`,{yes:r.yes===!0,json:n}))return;let o=await a.apiKeys.rotate(i,s);if(n)g(o);else{if(o.newId)process.stdout.write(`New key ${E(o.newId)}.
|
|
212
|
+
`);if(Go(o.token),o.oldExpiresAt)process.stdout.write(`The old token stops working at ${x(o.oldExpiresAt)}.
|
|
213
|
+
`)}return}default:throw new y(`usage: ${yc}`)}}var hc=["admin","member"];async function Jo(t,e,r){let n=f(!!r.json)==="json",i=h(m(r,"org")),a=p().orgs;switch(t){case"add":{let s=I(e[0],"vcity org members add <email|uid> [--role admin|member]","email or user id"),o=A(r,"role",hc),c=await a.addMember(i,{userIdOrEmail:s,...o&&{role:o}});if(n)g(c);else if(c.invited)process.stdout.write(`Invited ${s} to ${i}.
|
|
214
|
+
`);else process.stdout.write(`Added ${s} to ${i}.
|
|
215
|
+
`);return}case"role":{let o=I(e[0],"vcity org members role <uid> admin|member","user id"),c=e[1];if(c!=="admin"&&c!=="member")throw new y("usage: vcity org members role <uid> admin|member");let u=await a.setMemberRole(i,o,c);if(n)g(u);else process.stdout.write(`${o} is now ${c} of ${i}.
|
|
216
|
+
`);return}case"remove":{let s=I(e[0],"vcity org members remove <uid> [--yes]","user id");if(!await B(`Remove ${s} from ${i}?`,{yes:r.yes===!0,json:n}))return;let o=await a.removeMember(i,s);if(n)g(o);else process.stdout.write(`Removed ${s} from ${i}.
|
|
217
|
+
`);return}default:throw new y("usage: vcity org members list|add|role|remove")}}async function Ho(t,e,r){let n=f(!!r.json)==="json",i=h(m(r,"org")),a=p().orgs;switch(t){case"list":{let o=(await a.listInvitations(i)).data??[];if(n)g({org:i,invitations:o});else k(o,[{header:"ID",get:(c)=>c.id},{header:"EMAIL",get:(c)=>c.email??""},{header:"INVITED BY",get:(c)=>c.invitedBy??""},{header:"STATUS",get:(c)=>c.status??""},{header:"EXPIRES",get:(c)=>c.expiresAt?x(c.expiresAt):""}]);return}case"revoke":{let s=I(e[0],"vcity org invitations revoke <id> [--yes]","invitation id");if(!await B(`Revoke invitation ${s}?`,{yes:r.yes===!0,json:n}))return;let o=await a.revokeInvitation(i,s);if(n)g(o);else process.stdout.write(`Revoked invitation ${s}.
|
|
218
|
+
`);return}case"resend":{let s=I(e[0],"vcity org invitations resend <id>","invitation id"),o=await a.resendInvitation(i,s);if(n)g(o);else j({resent:s,...o});return}default:throw new y("usage: vcity org invitations list|revoke|resend")}}async function Yo(t,e,r){let n=f(!!r.json)==="json",i=h(m(r,"org")),a=p();switch(t){case"comments":{let o=I(e[0],"vcity orders comments <orderId> <lineItemId>","order id"),c=I(e[1],"vcity orders comments <orderId> <lineItemId>","line item id"),l=(await a.orders.listLineItemComments(i,o,c)).data??[];if(n)g({org:i,orderId:o,lineItemId:c,comments:l});else k(l,[{header:"ID",get:(w)=>w.id},{header:"WHEN",get:(w)=>w.createdAt?x(w.createdAt):""},{header:"BY",get:(w)=>w.uid??""},{header:"COMMENT",get:(w)=>w.content??""}]);return}case"comment":{let o=I(e[0],'vcity orders comment <orderId> <lineItemId> --text "…" [--parent <commentId>]',"order id"),c=I(e[1],'vcity orders comment <orderId> <lineItemId> --text "…" [--parent <commentId>]',"line item id"),u=G(m(r,"text")??e.slice(2).join(" "),'vcity orders comment <orderId> <lineItemId> --text "…" [--parent <commentId>]'),l=m(r,"parent"),w=await a.orders.commentLineItem(i,o,c,{content:u,...l&&{parent:l}});if(n)g(w);else process.stdout.write(`Comment added.
|
|
219
|
+
`);return}case"breakdown":{let s=V(r),o=q(r,"products");if(o)s.lineItems=o.map((u)=>{let[l,w="1"]=u.split(":"),v=Number(w);if(!l||!Number.isFinite(v)||v<=0)throw new y(`--products expects id:qty pairs (got: ${u})`);return{type:"product",targetId:l,quantity:v}});if(!Array.isArray(s.lineItems)||s.lineItems.length===0)throw new y(`usage: vcity orders breakdown --products <id:qty,…> | --data '{"lineItems":[…],"shippingAddress":{…}}'`);let c=await a.orders.breakdown(i,s);if(n)g(c);else j(c);return}default:throw new y("usage: vcity orders comments|comment|breakdown")}}var wc=["en","de","el","es","fr","it","pt","ru","zh"];async function Qo(t,e){let r=f(!!e.json)==="json",n=p().me;if(t===void 0||t==="get"){let i=await n.get();if(r)g(i.user??i);else j(i.user??i);return}if(t==="set"){let i=m(e,"company"),a={...V(e),...U({firstName:m(e,"first-name"),lastName:m(e,"last-name"),company:i===""?null:i,lang:A(e,"lang",wc)})};if(Object.keys(a).length===0)throw new y("usage: vcity profile set [--first-name <s>] [--last-name <s>] [--company <s>] [--lang en|es|…]");let s=await n.update(a);if(r)g(s.user??s);else process.stdout.write(`Profile updated.
|
|
220
|
+
`);return}throw new y("usage: vcity profile [get] | set …")}var vc="vcity support tickets|get|update|stats",Wo=["open","in_progress","waiting_on_customer","resolved","closed"],zo=["low","medium","high","urgent"];async function Ko(t,e,r){let n=f(!!r.json)==="json",i=h(m(r,"org")),a=p();switch(t){case"tickets":case"list":{let s=await a.support.listTickets(i,U({status:A(r,"status",Wo),priority:A(r,"priority",zo),category:m(r,"category"),limit:C(r,"limit",{min:1,max:200}),skip:C(r,"skip")})),o=s.data??[];if(n)g({org:i,tickets:o,total:s.total,hasMore:s.hasMore});else k(o,[{header:"ID",get:(c)=>c.id},{header:"SUBJECT",get:(c)=>c.subject??""},{header:"STATUS",get:(c)=>c.status??""},{header:"PRIORITY",get:(c)=>c.priority??""},{header:"ASSIGNED",get:(c)=>c.assignedTo??""},{header:"UPDATED",get:(c)=>c.updatedAt?x(c.updatedAt):""}]);return}case"get":{let s=I(e[0],"vcity support get <ticketId>","ticket id"),o=await a.support.getTicket(i,s);if(n)g(o);else j(o);return}case"update":{let s=I(e[0],"vcity support update <ticketId> [--status …] [--priority …] [--assign <uid>] [--category <s>] [--tags a,b]","ticket id"),o={...V(r),...U({status:A(r,"status",Wo),priority:A(r,"priority",zo),assignedTo:m(r,"assign"),category:m(r,"category"),tags:q(r,"tags")})};if(Object.keys(o).length===0)throw new y("support update: nothing to change");let c=await a.support.updateTicket(i,s,o);if(n)g(c);else process.stdout.write(`Updated ticket ${s}.
|
|
221
|
+
`);return}case"stats":{let s=await a.support.stats(i);if(n)g(s);else j(s);return}default:throw new y(`usage: ${vc}`)}}function bc(t){if(t&&typeof t==="object"&&"user"in t){let e=t;return{user:e.user,orgs:e.orgs??[]}}throw Error("Logged-in token is an API key, not a CLI user token. `vcity whoami` is only valid for CLI sessions.")}async function Xo(t={}){let e=f(t.json),n=await p().me.get(),{user:i,orgs:a}=bc(n),s=Ct();if(e==="json"){g({user:i,orgs:a,active_org:s.active_org??null});return}let o=E(i.email??i.name??i.id);process.stdout.write(`User: ${o}
|
|
222
|
+
`),process.stdout.write(`User ID: ${E(i.id)}
|
|
223
|
+
`),process.stdout.write(`Active org: ${s.active_org?E(s.active_org):"(none — run `vcity org use <slug>`)"}
|
|
224
|
+
`)}var kc=new Set(["json","yes","check","no-browser","disabled","dry-run","all","failed","unassign","unread","all-stores","no-overlays","show-names","hide-names","force","all-day","block","recurring"]);function Zo(t){let e=[],r={};for(let n=0;n<t.length;n++){let i=t[n];if(i==="--"){e.push(...t.slice(n+1));break}if(!i.startsWith("--")){e.push(i);continue}let a=i.indexOf("=");if(a>=0){r[i.slice(2,a)]=i.slice(a+1);continue}let s=i.slice(2),o=t[n+1];if(kc.has(s)||o===void 0||o.startsWith("--"))r[s]=!0;else r[s]=o,n++}return{positional:e,flags:r}}import{chmodSync as Ic,lstatSync as jc,mkdirSync as Tc,readFileSync as Ec,rmSync as Rc}from"node:fs";import Cc from"node:path";var Sc=86400000,Oc=1500,ti=64;function ei(){return Cc.join(gt(),"update-check.json")}function xc(){try{let t=Ec(ei(),"utf8"),e=JSON.parse(t);if(typeof e.latest==="string"&&e.latest.length>0&&e.latest.length<=ti&&typeof e.checkedAt==="number")return e;return}catch{return}}function Ac(t){try{let e=gt();Tc(e,{recursive:!0,mode:448});try{Ic(e,448)}catch{}let r=ei();try{let n=jc(r);if(n.isSymbolicLink()||n.isFile()&&n.nlink>1)Rc(r,{force:!0})}catch{}Ot(r,JSON.stringify(t,null,2),384)}catch{}}async function Pc(){let t=new AbortController,e=setTimeout(()=>t.abort(),Oc);try{let r=await fetch(`https://registry.npmjs.org/${Tt}/latest`,{headers:{accept:"application/json"},signal:t.signal});if(!r.ok)return;let i=(await r.json()).version;return typeof i==="string"&&i.length>0&&i.length<=ti?i:void 0}catch{return}finally{clearTimeout(e)}}function ri(t){if(process.env.VCITY_NO_UPDATE_CHECK==="1")return!1;if(!process.stderr.isTTY)return!1;if(t.includes("--json"))return!1;if(t[0]==="update")return!1;return!0}function si(){let t=xc(),e=Date.now();if(t&&e-t.checkedAt<Sc)return Promise.resolve(t.latest);return Pc().then((r)=>{if(r)Ac({latest:r,checkedAt:e});return r??t?.latest})}function ni(t){if(!t)return;if(Tr(nt,t)>=0)return;process.stderr.write(`
|
|
225
|
+
→ vcity ${E(t)} available (you have ${nt}). Run \`vcity update\` to upgrade.
|
|
226
|
+
`)}function S(t){process.stderr.write(`error: ${E(t)}
|
|
227
|
+
`),process.exit(2)}function $c(){process.stdout.write(`vcity ${nt}
|
|
98
228
|
|
|
99
229
|
Usage:
|
|
100
230
|
vcity login [--api-base-url <url>] [--no-browser]
|
|
@@ -104,18 +234,40 @@ Usage:
|
|
|
104
234
|
vcity org use <slug>
|
|
105
235
|
vcity org get <id> [--json]
|
|
106
236
|
vcity org members list [--org <slug>] [--limit <n>] [--json]
|
|
107
|
-
vcity
|
|
237
|
+
vcity org members add <email|uid> [--role admin|member] [--json] (invites when the person has no account)
|
|
238
|
+
vcity org members role <uid> admin|member [--json]
|
|
239
|
+
vcity org members remove <uid> [--yes] [--json]
|
|
240
|
+
vcity org invitations list|revoke <id> [--yes]|resend <id> [--json]
|
|
241
|
+
vcity profile [get] [--json]
|
|
242
|
+
vcity profile set [--first-name <s>] [--last-name <s>] [--company <s>] [--lang en|es|de|fr|it|pt|ru|zh|el] [--json]
|
|
243
|
+
vcity org settings [--org <slug>] [--json] (editable store settings)
|
|
244
|
+
vcity org set [--org <slug>] [--name <s>] [--description <s>] [--website <url>] [--contact-email <s>] [--phone <s>] [--whatsapp <s>] [--instagram <s>] [--timezone <tz>] [--locale <l>] [--country-code <cc>] [--seo-title <s>] [--seo-description <s>] [--color-main <hex>] [--data <json|@file|->] [--json]
|
|
245
|
+
vcity products list [--org <slug>] [--search <text>] [--limit <n>] [--skip <n>] [--visibility public|draft|hidden] [--created-from <date|ms>] [--updated-from <date|ms>] [--collection <id>] [--sort createdAt|updatedAt] [--order asc|desc] [--lang <locale>] [--json]
|
|
108
246
|
vcity products get <id> [--org <slug>] [--lang <locale>] [--json]
|
|
109
247
|
vcity products create [--org <slug>] [--name <s>] [--price <n>] [--currency <c>] [--sku <s>] [--data <json|@file|->] [--json]
|
|
110
248
|
vcity products update <id> [--org <slug>] [--name <s>] [--price <n>] [--currency <c>] [--sku <s>] [--visibility <v>] [--availability <n>] [--data <json|@file|->] [--json]
|
|
111
249
|
vcity products delete <id> [--org <slug>] [--yes] [--json]
|
|
112
|
-
vcity events
|
|
250
|
+
vcity products|events|blogs draft <id> [--json] (staged, unpublished edits)
|
|
251
|
+
vcity products|events|blogs stage <id> --data <json|@file|-> (autosave into the draft; nothing goes live)
|
|
252
|
+
vcity products|events|blogs publish <id> [--json]
|
|
253
|
+
vcity products|events|blogs discard-draft <id> [--yes] [--json]
|
|
254
|
+
vcity products|events visibility <id> public|hidden [--json]
|
|
255
|
+
vcity products import <file.csv|file.json> [--org <slug>] [--upsert-by sku|none] [--images <dir>] [--dry-run] [--report <errors.json>] [--json]
|
|
256
|
+
vcity media upload <file> [file…] [--org <slug>] [--json] (prints public URLs; images ≤10 MB, PDF ≤25 MB, video ≤100 MB)
|
|
257
|
+
vcity events list [--org <slug>] [--search <text>] [--limit <n>] [--status active|disabled] [--json]
|
|
113
258
|
vcity events get <id> [--org <slug>] [--json]
|
|
114
259
|
vcity events create [--org <slug>] [--name <s>] [--starts-at <iso|ms>] [--ends-at <iso|ms>] [--slug <s>] [--data <json|@file|->] [--json]
|
|
115
260
|
vcity events update <id> [--org <slug>] [--name <s>] [--starts-at <iso|ms>] [--ends-at <iso|ms>] [--slug <s>] [--status <s>] [--data <json|@file|->] [--json]
|
|
116
261
|
vcity events delete <id> [--org <slug>] [--yes] [--json]
|
|
117
262
|
vcity agents list [--org <slug>] [--limit <n>] [--json]
|
|
118
263
|
vcity agents get <id> [--org <slug>] [--json]
|
|
264
|
+
vcity agents update <id> [--name <s>] [--description <s>] [--emoji <s>] [--avatar <https-url>] [--instructions <s> | --instructions-file <path>] [--disable] [--org <slug>] [--json]
|
|
265
|
+
vcity agents run <agentId> [--json] (user tokens only)
|
|
266
|
+
vcity agents runs [--agent <id>] [--limit <n>] [--json]
|
|
267
|
+
vcity agents run-get <runId> | cancel-run <runId> [--json]
|
|
268
|
+
vcity agents proposals [--status pending|approved|rejected] [--agent <id>] [--limit <n>] [--json]
|
|
269
|
+
vcity agents approve <proposalId> [--yes] [--confirm-destructive] [--notify-customer] [--json]
|
|
270
|
+
vcity agents reject <proposalId> [--json]
|
|
119
271
|
vcity customer-agent get [--org <slug>] [--json]
|
|
120
272
|
vcity customer-agent knowledge [--org <slug>] [--json]
|
|
121
273
|
vcity conversations list [--org <slug>] [--status open|all] [--awaiting-reply] [--json]
|
|
@@ -136,7 +288,11 @@ Usage:
|
|
|
136
288
|
vcity rooms create [--org <slug>] [--title <s>] [--description <s>] [--type <s>] [--data <json|@file|->] [--json]
|
|
137
289
|
vcity rooms update <id> [--org <slug>] [--title <s>] [--description <s>] [--type <s>] [--disabled] [--data <json|@file|->] [--json]
|
|
138
290
|
vcity rooms delete <id> [--org <slug>] [--yes] [--json]
|
|
139
|
-
vcity bookings list [--org <slug>] [--limit <n>] [--status <s>] [--json]
|
|
291
|
+
vcity bookings list [--org <slug>] [--limit <n>] [--status <s>] [--from <date|ms>] [--to <date|ms>] [--json]
|
|
292
|
+
vcity bookings today [--org <slug>] [--json] (local day, earliest first, cancellations hidden)
|
|
293
|
+
vcity bookings slots [--from <date|ms>] [--to <date|ms>] [--days <n>] [--type <bookingTypeId>] [--json] (free slots; default next 7 days)
|
|
294
|
+
vcity bookings time-off list [--uid <uid>] [--from <d>] [--to <d>] · add --uid <uid> --from <d> --to <d> [--reason <s>] [--all-day] [--recurring] · remove <id> [--yes]
|
|
295
|
+
vcity bookings hours <uid> [--data <workingHours json|@file|->] [--json] (read, or replace with --data)
|
|
140
296
|
vcity bookings get <id> [--org <slug>] [--json]
|
|
141
297
|
vcity bookings create [--org <slug>] [--name <s>] [--email <s>] [--start <iso|ms>] [--end <iso|ms>] [--timezone <tz>] [--phone <s>] [--company <s>] [--note <s>] [--booking-type <id>] [--assignee <uid>] [--data <json|@file|->] [--json]
|
|
142
298
|
vcity bookings update <id> [--org <slug>] [--status <s>] [--assignee <uid>] [--data <json|@file|->] [--json]
|
|
@@ -151,7 +307,7 @@ Usage:
|
|
|
151
307
|
vcity projects create [--org <slug>] [--name <s>] [--prefix <s>] [--description <s>] [--data <json|@file|->] [--json]
|
|
152
308
|
vcity projects update <id> [--org <slug>] [--name <s>] [--description <s>] [--data <json|@file|->] [--json]
|
|
153
309
|
vcity projects delete <id> [--org <slug>] [--yes] [--json]
|
|
154
|
-
vcity blogs list [--org <slug>] [--limit <n>] [--visibility draft|public|hidden] [--json]
|
|
310
|
+
vcity blogs list [--org <slug>] [--search <text>] [--limit <n>] [--visibility draft|public|hidden] [--json]
|
|
155
311
|
vcity blogs get <id|slug> [--org <slug>] [--json]
|
|
156
312
|
vcity blogs create [--org <slug>] [--title <s>] [--slug <s>] [--summary <s>] [--content <s>] [--visibility <v>] [--type blog|news] [--tags a,b,c] [--data <json|@file|->] [--json]
|
|
157
313
|
vcity blogs update <id|slug> [--org <slug>] [--title <s>] [--slug <s>] [--summary <s>] [--content <s>] [--visibility <v>] [--type blog|news] [--tags a,b,c] [--data <json|@file|->] [--json]
|
|
@@ -169,11 +325,96 @@ Usage:
|
|
|
169
325
|
vcity analytics top-products [--org <slug>] [--from <YYYY-MM-DD>] [--to <YYYY-MM-DD>] [--limit <n>] [--json]
|
|
170
326
|
vcity orders list [--org <slug>] [--limit <n>] [--status <s>] [--json]
|
|
171
327
|
vcity orders get <id> [--org <slug>] [--json]
|
|
328
|
+
vcity orders export [--org <slug>] [--from <date|ms>] [--to <date|ms>] [--status <s>] [--format csv|json] [--output <file>]
|
|
329
|
+
vcity orders comments <orderId> <lineItemId> [--json]
|
|
330
|
+
vcity orders comment <orderId> <lineItemId> --text "…" [--parent <commentId>] [--json] (internal note)
|
|
331
|
+
vcity orders breakdown --products <id:qty,…> | --data <json> [--json] (cart totals, discounts, shipping)
|
|
332
|
+
vcity orders ship <orderId> [lineItemId...] [--org <slug>] [--status shipped|delivered] [--json] (no line ids: every line not yet there)
|
|
333
|
+
vcity status [--org <slug>] [--timeframe today|week|month|quarter|year|all] [--json]
|
|
172
334
|
vcity quotes list [--org <slug>] [--limit <n>] [--status PENDING|IN_PROGRESS|SUBMITTED|CANCELED|ORDERED] [--json]
|
|
173
335
|
vcity quotes get <id> [--org <slug>] [--json]
|
|
174
336
|
vcity quotes create [--org <slug>] [--name <s>] [--email <s>] [--product <id>] [--quantity <n>] [--phone <s>] [--variation <s>] [--company <s>] [--note <s>] [--data <json|@file|->] [--json]
|
|
175
337
|
vcity quotes update <id> [--org <slug>] [--status <s>] [--assignee <uid>] [--name <s>] [--email <s>] [--product <id>] [--quantity <n>] [--phone <s>] [--variation <s>] [--company <s>] [--note <s>] [--data <json|@file|->] [--json]
|
|
176
338
|
vcity quotes delete <id> [--org <slug>] [--yes] [--json]
|
|
339
|
+
vcity crm contacts list [--org <slug>] [--q <text>] [--tags a,b] [--sort lastInteraction|totalInteractions|score|name] [--archived] [--limit <n>] [--skip <n>] [--all] [--json]
|
|
340
|
+
vcity crm contacts get <id> [--org <slug>] [--json]
|
|
341
|
+
vcity crm contacts create --name <s> [--email <s>] [--phone <s>] [--company <s>] [--job-title <s>] [--notes <s>] [--tags a,b] [--source <s>] [--data <json|@file|->] [--json]
|
|
342
|
+
vcity crm contacts update <id> [--name <s>] [--email <s>] [...same fields] [--data <json|@file|->] [--json]
|
|
343
|
+
vcity crm contacts archive <id> [--yes] [--json] | vcity crm contacts restore <id> [--json]
|
|
344
|
+
vcity crm contacts tag <id> [--add a,b] [--remove c] [--json]
|
|
345
|
+
vcity crm contacts timeline <id> [--json]
|
|
346
|
+
vcity crm contacts export [--q <text>] [--tags a,b] [--archived] [--format csv|json] [--output <file>]
|
|
347
|
+
vcity crm contacts import <file.csv> [--dry-run] [--report <errors.json>] [--json] (upsert by email)
|
|
348
|
+
vcity crm tags list|create [--name <s>] [--color <#hex>] [--json]
|
|
349
|
+
vcity crm follow-ups [--due-before <date|ms>] [--limit <n>] [--json]
|
|
350
|
+
vcity crm audiences [<audienceId>] [--json]
|
|
351
|
+
vcity configurators list|seeds|get <id>|create --seed <id> | --data <json>|update <id> --data <patch> [--bump-version]|delete <id> [--json]
|
|
352
|
+
vcity rooms show|messages|send|search|read <roomId> [--message <s>] [--query <s>] [--around <messageId>] [--as-org] (any chat room you can open; user login only)
|
|
353
|
+
vcity surveys create --title <s> [--data <json>] | update|publish|close|delete <surveyId>
|
|
354
|
+
vcity comments edit <commentId> --message <s> | delete|pin|unpin <commentId>
|
|
355
|
+
vcity billing [summary|invoices|usage|credits] [--json] (plan, invoices, AI credits, recording storage)
|
|
356
|
+
vcity storefront [get|domain <host>|verify|remove-domain|redirects] [--json] (domain changes: user login only)
|
|
357
|
+
vcity newsletter config|subscribers|stats [--days <n>] [--json]
|
|
358
|
+
vcity surveys list [--status draft|active|closed] | get <id> | responses <id> [--json]
|
|
359
|
+
vcity comments list|reactions <table:id> · add <table:id> --message <s> [--parent <id>] · react <table:id> <emoji> [--remove] (user login only)
|
|
360
|
+
vcity dropshipping connections|products|import --connection <id> --products a,b (--markup-percent <n> | --markup-fixed <n>)|fulfillments <orderId>|retry <fulfillmentId>
|
|
361
|
+
vcity pos session|open --cash <n> --currency USD|COP|close <sessionId> --cash <n>|summary <sessionId>|sales [--session <id>]|sale <id>|sell --data <json>|favorites [--set a,b]
|
|
362
|
+
vcity coupons list [--active] [--limit <n>] [--skip <n>] [--json]
|
|
363
|
+
vcity coupons get <id> [--json]
|
|
364
|
+
vcity coupons create --code <CODE> (--percent <n> | --amount <n> --currency USD|COP | --type free-shipping) [--until <date>] [--from <date>] [--max-uses <n>] [--max-uses-per-user <n>] [--min-order <n>] [--products a,b] [--collections a,b] [--data <json|@file|->] [--json]
|
|
365
|
+
vcity coupons update <id> [same flags] [--json]
|
|
366
|
+
vcity coupons activate|deactivate <id> [--json]
|
|
367
|
+
vcity coupons validate <CODE> [--data '{"cart":{…}}'] [--json]
|
|
368
|
+
vcity campaigns list [--status <s>] [--search <text>] [--limit <n>] [--json]
|
|
369
|
+
vcity campaigns get|stats <id> [--json]
|
|
370
|
+
vcity campaigns create --name <s> --resource-type event|product|room|custom [--resource <id>] --mode <mode> --subject <s> --body <html> [--send immediate|scheduled|event-cadence] [--at <date>] [--data <json>] [--json]
|
|
371
|
+
vcity campaigns update <id> [--name <s>] [--subject <s>] [--body <html>] [--data <json>] [--json]
|
|
372
|
+
vcity campaigns activate <id> [--yes] | pause <id> | delete <id> [--yes] [--json]
|
|
373
|
+
vcity campaigns contacts <id> [--limit <n>] | add-contacts <id> --emails a@b.com,… | remove-contact <id> <contactId> [--json]
|
|
374
|
+
vcity keys list [--revoked] [--json] (store API keys; user tokens only)
|
|
375
|
+
vcity keys create --label <name> --scopes products:read,orders:read [--json] (token shown once)
|
|
376
|
+
vcity keys revoke <id> [--yes] | rotate <id> [--yes] [--json]
|
|
377
|
+
vcity support tickets [--status <s>] [--priority <p>] [--category <c>] [--limit <n>] [--json]
|
|
378
|
+
vcity support get <ticketId> [--json]
|
|
379
|
+
vcity support update <ticketId> [--status open|in_progress|waiting_on_customer|resolved|closed] [--priority low|medium|high|urgent] [--assign <uid>] [--category <s>] [--tags a,b] [--json]
|
|
380
|
+
vcity support stats [--json]
|
|
381
|
+
vcity webhooks list [--org <slug>] [--limit <n>] [--skip <n>] [--json]
|
|
382
|
+
vcity webhooks get <id> [--json]
|
|
383
|
+
vcity webhooks create --url <https://…> --events order.created,product.created,booking.created [--header "Name: value"] [--description <s>] [--data <json|@file|->] [--json]
|
|
384
|
+
vcity webhooks update <id> [--url <s>] [--events <list>] [--status active|paused] [--description <s>] [--data <json|@file|->] [--json] (headers: all via --data)
|
|
385
|
+
vcity webhooks delete <id> [--yes] [--json]
|
|
386
|
+
vcity webhooks test <id> [--json] (sends a signed test event; exit 1 if the receiver fails)
|
|
387
|
+
vcity webhooks deliveries <id> [--failed] [--limit <n>] [--before <ms>] [--json]
|
|
388
|
+
vcity webhooks rotate <id> [--yes] [--json] (new signing secret, shown once)
|
|
389
|
+
vcity inbox list [--org <slug>] [--status open|closed|all] [--assigned-to <uid|me>] [--limit <n>] [--skip <n>] [--json] (user login only)
|
|
390
|
+
vcity inbox show <conversationId> [--limit <n>] [--json]
|
|
391
|
+
vcity inbox search <conversationId> --query <text> [--json]
|
|
392
|
+
vcity inbox reply <conversationId> --message <s> | --quick-reply <shortcut|id> [--reply-to <messageId>] [--json]
|
|
393
|
+
vcity inbox assign <conversationId> <uid|me> | --unassign · close|reopen|read|customer <conversationId> · unread
|
|
394
|
+
vcity quick-replies list|export [--org <slug>] [--json]
|
|
395
|
+
vcity quick-replies create --title <s> --body <s> [--shortcut <s>] [--json]
|
|
396
|
+
vcity quick-replies update <id> [--title <s>] [--body <s>] [--shortcut <s>] [--json] · delete <id> [--yes]
|
|
397
|
+
vcity quick-replies import <file.json> (the output of export; skips replies whose shortcut/title exists)
|
|
398
|
+
vcity chat rooms|members [--org <slug>] [--json] (team chat; user login only)
|
|
399
|
+
vcity chat messages <room> [--limit <n>] [--before <ms> --before-id <messageId>] [--json] (<room>: room id or #channel-slug)
|
|
400
|
+
vcity chat send <room> --message <s> [--reply-to <messageId>] [--mention uid,uid] [--json]
|
|
401
|
+
vcity chat thread <room> <messageId> · react|unreact <room> <messageId> <emoji> · read <room>
|
|
402
|
+
vcity chat search <text> [--json] · channel create --name <s> [--description <s>] · dm <uid>
|
|
403
|
+
vcity notifications [list] [--unread] [--org <slug>] [--all-stores] [--limit <n>] [--skip <n>] [--json]
|
|
404
|
+
vcity notifications read <id> | --all [--org <slug>] [--all-stores] · unread (counts per store)
|
|
405
|
+
vcity calendar list [--org <slug>] [--from <date|ms>] [--to <date|ms>] [--days <n>] [--no-overlays] [--json] (default: today + 7 days, max 62; user login only)
|
|
406
|
+
vcity calendar ics [<feedId>] [--output <file.ics>] (the iCalendar text of a subscription link)
|
|
407
|
+
vcity calendar feeds list|create [--scope org|member] [--show-names|--hide-names]|rotate <feedId>|revoke <feedId> [--yes]
|
|
408
|
+
vcity calendar add --title <s> --start <date|ms> --end <date|ms> [--all-day] [--category custom|timeoff|meeting] [--location virtual|physical] [--description <s>] [--data <json|@file|->] [--json]
|
|
409
|
+
vcity calendar cancel <entryId> [--scope single|following|all] [--yes]
|
|
410
|
+
vcity calendar holidays [--country CO|US|MX|ES|BR|AR|CL|PE] [--year <n>] · settings · staff
|
|
411
|
+
vcity calendar external list|add --name <s> --url <ics url> [--block]|refresh <id>|remove <id> [--yes]
|
|
412
|
+
vcity vault list|get <id>|search <text> [--org <slug>] [--json] (Knowledge Vault; user login only)
|
|
413
|
+
vcity vault create --title <s> [--file <page.md>|--content <s>] [--parent <id>] [--tags a,b]
|
|
414
|
+
vcity vault save <id> --file <page.md>|--content <s> [--title <s>] (a pulled file merges; otherwise replaces)
|
|
415
|
+
vcity vault move <id> --parent <id|root> [--order <n>] · delete <id> [--yes]
|
|
416
|
+
vcity vault pull <dir> [--force] · vcity vault push <dir> [--dry-run] (the vault as a folder of Markdown files)
|
|
417
|
+
vcity desk latest | vcity desk download [--os mac|windows|linux] (Vcity Desk, the desktop admin app)
|
|
177
418
|
vcity update [--check] [--yes] [--json]
|
|
178
419
|
|
|
179
420
|
The --data flag:
|
|
@@ -196,7 +437,7 @@ Exit codes:
|
|
|
196
437
|
0 success
|
|
197
438
|
1 runtime error (no active org, not logged in, request failed)
|
|
198
439
|
2 usage error (unknown command, bad flag, missing argument)
|
|
199
|
-
`)}function
|
|
200
|
-
`);return}let[t,r,...o]=e,s=e.slice(1),{positional:i,flags:n}=hn(s),a=i.slice(r&&!r.startsWith("--")?1:0);switch(t){case"login":return or({apiBaseUrl:typeof n["api-base-url"]==="string"?n["api-base-url"]:void 0,openBrowser:n["no-browser"]===!0?!1:void 0});case"logout":return sr();case"whoami":return yn({json:!!n.json});case"org":{if(r==="list")return pr({json:!!n.json});if(r==="use"){let d=a[0];if(!d)y("usage: vcity org use <slug>");return fr(d)}if(r==="get"){let d=a[0];if(!d)y("usage: vcity org get <id>");return hr(v(d,"org id"))}if(r==="members"){let d=I(n);if(a[0]==="list")return yr({org:d.org,limit:d.limit,json:d.json});y("usage: vcity org members list")}y("usage: vcity org list | vcity org use <slug> | vcity org get <id> | vcity org members list")}case"products":{let d=I(n);if(r==="list")return Mr({org:d.org,limit:d.limit,skip:Jo(n.skip),visibility:u(n,"visibility"),createdFrom:u(n,"created-from"),updatedFrom:u(n,"updated-from"),collection:u(n,"collection"),sort:u(n,"sort"),order:u(n,"order"),lang:u(n,"lang"),json:d.json});if(r==="get"){let c=a[0];if(!c)y("usage: vcity products get <id>");return Gr(v(c,"product id"),{org:d.org,lang:u(n,"lang"),json:d.json})}if(r==="create")return Vr({org:d.org,name:u(n,"name"),price:P(n.price,"--price"),currency:u(n,"currency"),sku:u(n,"sku"),data:u(n,"data"),json:d.json});if(r==="update"){let c=a[0];if(!c)y("usage: vcity products update <id>");return Yr(v(c,"product id"),{org:d.org,name:u(n,"name"),price:P(n.price,"--price"),currency:u(n,"currency"),sku:u(n,"sku"),visibility:u(n,"visibility"),availability:P(n.availability,"--availability"),data:u(n,"data"),json:d.json})}if(r==="delete"){let c=a[0];if(!c)y("usage: vcity products delete <id>");return zr(v(c,"product id"),{org:d.org,yes:n.yes===!0,json:d.json})}y("usage: vcity products list|get|create|update|delete")}case"events":{let d=I(n);if(r==="list"){let c=d.status;if(c!==void 0&&c!=="active"&&c!=="disabled")y(`invalid --status: ${c}. Allowed: active, disabled`);return Xt({org:d.org,limit:d.limit,status:c,json:d.json})}if(r==="get"){let c=a[0];if(!c)y("usage: vcity events get <id>");return Kt(v(c,"event id"),{org:d.org,json:d.json})}if(r==="create")return Zt({org:d.org,name:u(n,"name"),startsAt:u(n,"starts-at"),endsAt:u(n,"ends-at"),slug:u(n,"slug"),data:u(n,"data"),json:d.json});if(r==="update"){let c=a[0];if(!c)y("usage: vcity events update <id>");return er(v(c,"event id"),{org:d.org,name:u(n,"name"),startsAt:u(n,"starts-at"),endsAt:u(n,"ends-at"),slug:u(n,"slug"),status:u(n,"status"),data:u(n,"data"),json:d.json})}if(r==="delete"){let c=a[0];if(!c)y("usage: vcity events delete <id>");return tr(v(c,"event id"),{org:d.org,yes:n.yes===!0,json:d.json})}y("usage: vcity events list|get|create|update|delete")}case"collections":{let d=I(n),c={org:d.org,name:u(n,"name"),description:u(n,"description"),slug:u(n,"slug"),seoTitle:u(n,"seo-title"),seoDescription:u(n,"seo-description"),data:u(n,"data"),json:d.json};if(r==="list")return Rr({org:d.org,json:d.json});if(r==="create")return Sr(c);if(r==="get"||r==="update"||r==="delete"){let w=a[0];if(!w)y(`usage: vcity collections ${r} <id>`);let h=v(w,"collection id");if(r==="get")return Tr(h,{org:d.org,json:d.json});if(r==="update")return Ir(h,c);return Or(h,{org:d.org,yes:n.yes===!0,json:d.json})}y("usage: vcity collections list|get|create|update|delete")}case"agents":{let d=I(n);if(r==="list")return br({org:d.org,limit:d.limit,json:d.json});if(r==="get"){let c=a[0];if(!c)y("usage: vcity agents get <id>");return wr(v(c,"agent id"),{org:d.org,json:d.json})}y("usage: vcity agents list|get")}case"customer-agent":{let d=I(n);if(r==="get")return kr({org:d.org,json:d.json});if(r==="knowledge")return Cr({org:d.org,json:d.json});y("usage: vcity customer-agent get|knowledge")}case"conversations":{let d=I(n);if(r==="list")return vr({org:d.org,status:d.status,awaitingReply:n["awaiting-reply"]===!0,json:d.json});if(r==="get"){let c=a[0];if(!c)y("usage: vcity conversations get <id>");return jr(v(c,"conversation id"),{org:d.org,limit:d.limit,json:d.json})}y("usage: vcity conversations list|get")}case"posts":{let d=I(n);if(r==="list")return _r({org:d.org,limit:d.limit,status:d.status,json:d.json});if(r==="get"){let c=a[0];if(!c)y("usage: vcity posts get <id>");return Dr(v(c,"post id"),{org:d.org,json:d.json})}if(r==="create")return Nr({org:d.org,comment:u(n,"comment"),file:u(n,"file"),video:u(n,"video"),poster:u(n,"poster"),data:u(n,"data"),json:d.json});if(r==="attach-video"){let c=a[0];if(!c)y("usage: vcity posts attach-video <id> --video <file.mp4>");return qr(v(c,"post id"),{org:d.org,video:u(n,"video"),poster:u(n,"poster"),json:d.json})}if(r==="preview"){let c=a[0];if(!c)y("usage: vcity posts preview <id>");return Lr(v(c,"post id"),{org:d.org,json:d.json})}if(r==="publish"){let c=a[0];if(!c)y("usage: vcity posts publish <id>");return Br(v(c,"post id"),{org:d.org,yes:n.yes===!0,json:d.json})}y("usage: vcity posts list|get|create|attach-video|preview|publish")}case"rooms":{let d=I(n);if(r==="list")return nn({org:d.org,limit:d.limit,json:d.json});if(r==="get"){let c=a[0];if(!c)y("usage: vcity rooms get <id>");return on(v(c,"room id"),{org:d.org,json:d.json})}if(r==="create")return sn({org:d.org,title:u(n,"title"),description:u(n,"description"),type:u(n,"type"),data:u(n,"data"),json:d.json});if(r==="update"){let c=a[0];if(!c)y("usage: vcity rooms update <id>");return an(v(c,"room id"),{org:d.org,title:u(n,"title"),description:u(n,"description"),type:u(n,"type"),disabled:n.disabled===!0?!0:void 0,data:u(n,"data"),json:d.json})}if(r==="delete"){let c=a[0];if(!c)y("usage: vcity rooms delete <id>");return dn(v(c,"room id"),{org:d.org,yes:n.yes===!0,json:d.json})}y("usage: vcity rooms list|get|create|update|delete")}case"bookings":{let d=I(n);if(r==="list")return Nt(d);if(r==="get"){let c=a[0];if(!c)y("usage: vcity bookings get <id>");return $t(v(c,"booking id"),{org:d.org,json:d.json})}if(r==="create")return Ut({org:d.org,name:u(n,"name"),email:u(n,"email"),start:u(n,"start"),end:u(n,"end"),timezone:u(n,"timezone"),phone:u(n,"phone"),company:u(n,"company"),note:u(n,"note"),bookingType:O(n,"booking-type","--booking-type"),assignee:O(n,"assignee","--assignee"),data:u(n,"data"),json:d.json});if(r==="update"){let c=a[0];if(!c)y("usage: vcity bookings update <id>");return qt(v(c,"booking id"),{org:d.org,status:u(n,"status"),assignee:O(n,"assignee","--assignee"),data:u(n,"data"),json:d.json})}if(r==="cancel"||r==="delete"){let c=a[0];if(!c)y(`usage: vcity bookings ${r} <id>`);return Lt(v(c,"booking id"),{org:d.org,yes:n.yes===!0,json:d.json})}y("usage: vcity bookings list|get|create|update|cancel")}case"booking-types":{let d=I(n);if(r==="list")return It({org:d.org,limit:d.limit,enabled:n.enabled===!0?!0:void 0,json:d.json});if(r==="get"){let c=a[0];if(!c)y("usage: vcity booking-types get <id>");return Ot(v(c,"booking type id"),{org:d.org,json:d.json})}if(r==="create")return Pt({org:d.org,name:u(n,"name"),duration:P(n.duration,"--duration"),description:u(n,"description"),bufferBefore:P(n["buffer-before"],"--buffer-before"),bufferAfter:P(n["buffer-after"],"--buffer-after"),color:u(n,"color"),assignee:O(n,"assignee","--assignee"),roundRobin:n["round-robin"]===!0?!0:void 0,sortOrder:P(n["sort-order"],"--sort-order"),data:u(n,"data"),json:d.json});if(r==="update"){let c=a[0];if(!c)y("usage: vcity booking-types update <id>");let w=n.disabled===!0?!1:n.enabled===!0?!0:void 0;return xt(v(c,"booking type id"),{org:d.org,name:u(n,"name"),duration:P(n.duration,"--duration"),description:u(n,"description"),bufferBefore:P(n["buffer-before"],"--buffer-before"),bufferAfter:P(n["buffer-after"],"--buffer-after"),color:u(n,"color"),assignee:O(n,"assignee","--assignee"),roundRobin:n["round-robin"]===!0?!0:void 0,enabled:w,sortOrder:P(n["sort-order"],"--sort-order"),data:u(n,"data"),json:d.json})}if(r==="delete"){let c=a[0];if(!c)y("usage: vcity booking-types delete <id>");return _t(v(c,"booking type id"),{org:d.org,yes:n.yes===!0,json:d.json})}y("usage: vcity booking-types list|get|create|update|delete")}case"projects":{let d=I(n);if(r==="list")return Jr({org:d.org,limit:d.limit,json:d.json});if(r==="get"){let c=a[0];if(!c)y("usage: vcity projects get <id>");return Hr(v(c,"project id"),{org:d.org,json:d.json})}if(r==="create")return Wr({org:d.org,name:u(n,"name"),prefix:u(n,"prefix"),description:u(n,"description"),data:u(n,"data"),json:d.json});if(r==="update"){let c=a[0];if(!c)y("usage: vcity projects update <id>");return Qr(v(c,"project id"),{org:d.org,name:u(n,"name"),description:u(n,"description"),data:u(n,"data"),json:d.json})}if(r==="delete"){let c=a[0];if(!c)y("usage: vcity projects delete <id>");return Xr(v(c,"project id"),{org:d.org,yes:n.yes===!0,json:d.json})}y("usage: vcity projects list|get|create|update|delete")}case"blogs":{let d=I(n);if(r==="list")return Ct({org:d.org,limit:d.limit,visibility:u(n,"visibility"),json:d.json});if(r==="get"){let c=a[0];if(!c)y("usage: vcity blogs get <id|slug>");return Et(v(c,"blog id"),{org:d.org,json:d.json})}if(r==="create")return Rt({org:d.org,title:u(n,"title"),slug:u(n,"slug"),summary:u(n,"summary"),content:u(n,"content"),visibility:u(n,"visibility"),type:u(n,"type"),tags:u(n,"tags"),data:u(n,"data"),json:d.json});if(r==="update"){let c=a[0];if(!c)y("usage: vcity blogs update <id|slug>");return Tt(v(c,"blog id"),{org:d.org,title:u(n,"title"),slug:u(n,"slug"),summary:u(n,"summary"),content:u(n,"content"),visibility:u(n,"visibility"),type:u(n,"type"),tags:u(n,"tags"),data:u(n,"data"),json:d.json})}if(r==="delete"){let c=a[0];if(!c)y("usage: vcity blogs delete <id|slug>");return St(v(c,"blog id"),{org:d.org,yes:n.yes===!0,json:d.json})}y("usage: vcity blogs list|get|create|update|delete")}case"cards":{let d=I(n),c=O(n,"project","--project");if(r==="list")return Gt({org:d.org,project:c,column:O(n,"column","--column"),assignee:O(n,"assignee","--assignee"),archived:n.archived===!0,limit:d.limit,json:d.json});if(r==="get"){let w=a[0];if(!w)y("usage: vcity cards get <id|CODE-n> --project <id>");return Vt(v(w,"card id"),{org:d.org,project:c,json:d.json})}if(r==="create")return Yt({org:d.org,project:c,title:u(n,"title"),column:O(n,"column","--column"),description:u(n,"description"),priority:u(n,"priority"),due:u(n,"due"),assignee:O(n,"assignee","--assignee"),order:P(n.order,"--order"),data:u(n,"data"),json:d.json});if(r==="update"){let w=a[0];if(!w)y("usage: vcity cards update <id|CODE-n> --project <id>");return zt(v(w,"card id"),{org:d.org,project:c,title:u(n,"title"),column:O(n,"column","--column"),description:u(n,"description"),priority:u(n,"priority"),due:u(n,"due"),assignee:O(n,"assignee","--assignee"),archived:n.archived===!0?!0:void 0,data:u(n,"data"),json:d.json})}if(r==="move"){let w=a[0];if(!w)y("usage: vcity cards move <id|CODE-n> --project <id> --column <col>");return Jt(v(w,"card id"),{org:d.org,project:c,column:O(n,"column","--column"),order:P(n.order,"--order"),json:d.json})}if(r==="delete"){let w=a[0];if(!w)y("usage: vcity cards delete <id|CODE-n> --project <id>");return Ht(v(w,"card id"),{org:d.org,project:c,yes:n.yes===!0,json:d.json})}if(r==="comments"){let w=a[0];if(!w)y("usage: vcity cards comments <id|CODE-n> --project <id>");return Wt(v(w,"card id"),{org:d.org,project:c,limit:d.limit,json:d.json})}if(r==="comment"){let w=a[0];if(!w)y("usage: vcity cards comment <id|CODE-n> --project <id> --message <text>");return Qt(v(w,"card id"),{org:d.org,project:c,message:u(n,"message"),json:d.json})}y("usage: vcity cards list|get|create|update|move|delete|comments|comment")}case"analytics":{let d=I(n),c={org:d.org,from:u(n,"from"),to:u(n,"to"),json:d.json};if(r==="summary")return ar(c);if(r==="visits")return dr({...c,groupBy:u(n,"group-by")});if(r==="top-products")return cr({...c,limit:d.limit});y("usage: vcity analytics summary | vcity analytics visits | vcity analytics top-products")}case"orders":{let d=I(n);if(r==="list")return gr(d);if(r==="get"){let c=a[0];if(!c)y("usage: vcity orders get <id>");return lr(v(c,"order id"),{org:d.org,json:d.json})}y("usage: vcity orders list | vcity orders get <id>")}case"quotes":{let d=I(n);if(r==="list")return Kr(d);if(r==="get"){let c=a[0];if(!c)y("usage: vcity quotes get <id>");return Zr(v(c,"quote id"),{org:d.org,json:d.json})}if(r==="create")return en({org:d.org,name:u(n,"name"),email:u(n,"email"),product:O(n,"product","--product"),quantity:P(n.quantity,"--quantity"),phone:u(n,"phone"),variation:u(n,"variation"),company:u(n,"company"),note:u(n,"note"),data:u(n,"data"),json:d.json});if(r==="update"){let c=a[0];if(!c)y("usage: vcity quotes update <id>");return tn(v(c,"quote id"),{org:d.org,status:u(n,"status"),assignee:O(n,"assignee","--assignee"),name:u(n,"name"),email:u(n,"email"),product:O(n,"product","--product"),quantity:P(n.quantity,"--quantity"),phone:u(n,"phone"),variation:u(n,"variation"),company:u(n,"company"),note:u(n,"note"),data:u(n,"data"),json:d.json})}if(r==="delete"){let c=a[0];if(!c)y("usage: vcity quotes delete <id>");return rn(v(c,"quote id"),{org:d.org,yes:n.yes===!0,json:d.json})}y("usage: vcity quotes list|get|create|update|delete")}case"update":return fn({check:n.check===!0,yes:n.yes===!0,json:!!n.json});default:y(`unknown command: ${t}. Run \`vcity --help\`.`)}}async function Wo(){let e=process.argv.slice(2),t=vn(e)?jn():void 0;try{await Ho(e)}finally{if(t)kn(await t)}}Wo().catch((e)=>{let t=e instanceof Error?e.message:String(e);if(process.stderr.write(`error: ${E(t)}
|
|
201
|
-
`),process.env.VCITY_DEBUG&&
|
|
440
|
+
`)}function Dc(t){if(typeof t!=="string")return;let e=parseInt(t,10);if(Number.isNaN(e)||e<0)S(`--limit must be a non-negative integer (got: ${t})`);return e}function Nc(t){if(typeof t!=="string")return;if(!/^\d+$/.test(t))S(`--skip must be a non-negative integer (got: ${t})`);return Number(t)}function tt(t,e){if(t===void 0)return;if(typeof t!=="string")return;let r=Number(t);if(!Number.isFinite(r))S(`${e} must be a number (got: ${t})`);return r}function b(t,e){return typeof t[e]==="string"?t[e]:void 0}function Q(t,e,r){let n=b(t,e);if(n===void 0)return;return O(n,r)}function z(t){return{org:Q(t,"org","--org"),limit:Dc(t.limit),status:typeof t.status==="string"?t.status:void 0,json:!!t.json}}async function Fc(t){if(t.length===0||t[0]==="--help"||t[0]==="-h"||t[0]==="help"){$c();return}if(t[0]==="--version"||t[0]==="-v"){process.stdout.write(`${nt}
|
|
441
|
+
`);return}let[e,r,...n]=t,i=t.slice(1),{positional:a,flags:s}=Zo(i),o=a.slice(r&&!r.startsWith("--")?1:0);switch(e){case"login":return Gs({apiBaseUrl:typeof s["api-base-url"]==="string"?s["api-base-url"]:void 0,openBrowser:s["no-browser"]===!0?!1:void 0});case"logout":return Vs();case"whoami":return Xo({json:!!s.json});case"org":{if(r==="list")return sn({json:!!s.json});if(r==="use"){let c=o[0];if(!c)S("usage: vcity org use <slug>");return nn(c)}if(r==="get"){let c=o[0];if(!c)S("usage: vcity org get <id>");return an(O(c,"org id"))}if(r==="members"){let c=z(s),u=o[0];if(u==="list")return on({org:c.org,limit:c.limit,json:c.json});if(u==="add"||u==="role"||u==="remove")return Jo(u,o.slice(1),s);S("usage: vcity org members list|add|role|remove")}if(r==="invitations")return Ho(o[0],o.slice(1),s);if(r==="settings")return un({org:Q(s,"org","--org"),json:!!s.json});if(r==="set")return gn(s);S("usage: vcity org list | use <slug> | get <id> | members list|add|role|remove | invitations | settings | set --name <s> …")}case"products":{let c=z(s);if(r==="list")return Un({org:c.org,search:b(s,"search"),limit:c.limit,skip:Nc(s.skip),visibility:b(s,"visibility"),createdFrom:b(s,"created-from"),updatedFrom:b(s,"updated-from"),collection:b(s,"collection"),sort:b(s,"sort"),order:b(s,"order"),lang:b(s,"lang"),json:c.json});if(r==="get"){let u=o[0];if(!u)S("usage: vcity products get <id>");return Bn(O(u,"product id"),{org:c.org,lang:b(s,"lang"),json:c.json})}if(r==="create")return Mn({org:c.org,name:b(s,"name"),price:tt(s.price,"--price"),currency:b(s,"currency"),sku:b(s,"sku"),data:b(s,"data"),json:c.json});if(r==="update"){let u=o[0];if(!u)S("usage: vcity products update <id>");return Ln(O(u,"product id"),{org:c.org,name:b(s,"name"),price:tt(s.price,"--price"),currency:b(s,"currency"),sku:b(s,"sku"),visibility:b(s,"visibility"),availability:tt(s.availability,"--availability"),data:b(s,"data"),json:c.json})}if(r==="delete"){let u=o[0];if(!u)S("usage: vcity products delete <id>");return qn(O(u,"product id"),{org:c.org,yes:s.yes===!0,json:c.json})}if(r==="import"){let u=o[0];if(!u)S("usage: vcity products import <file.csv|file.json>");return Yn(u,{org:c.org,upsertBy:A(s,"upsert-by",["sku","none"]),dryRun:s["dry-run"]===!0,report:m(s,"report"),images:m(s,"images"),json:c.json})}if(bt.includes(r??""))return er("products",r,o,s);S(`usage: vcity products list|get|create|update|delete|import|${bt.join("|")}`)}case"events":{let c=z(s);if(r==="list"){let u=c.status;if(u!==void 0&&u!=="active"&&u!=="disabled")S(`invalid --status: ${u}. Allowed: active, disabled`);return Rs({org:c.org,limit:c.limit,status:u,search:b(s,"search"),json:c.json})}if(r==="get"){let u=o[0];if(!u)S("usage: vcity events get <id>");return Cs(O(u,"event id"),{org:c.org,json:c.json})}if(r==="create")return Ss({org:c.org,name:b(s,"name"),startsAt:b(s,"starts-at"),endsAt:b(s,"ends-at"),slug:b(s,"slug"),data:b(s,"data"),json:c.json});if(r==="update"){let u=o[0];if(!u)S("usage: vcity events update <id>");return Os(O(u,"event id"),{org:c.org,name:b(s,"name"),startsAt:b(s,"starts-at"),endsAt:b(s,"ends-at"),slug:b(s,"slug"),status:b(s,"status"),data:b(s,"data"),json:c.json})}if(r==="delete"){let u=o[0];if(!u)S("usage: vcity events delete <id>");return xs(O(u,"event id"),{org:c.org,yes:s.yes===!0,json:c.json})}if(bt.includes(r??""))return er("events",r,o,s);S(`usage: vcity events list|get|create|update|delete|${bt.join("|")}`)}case"collections":{let c=z(s),u={org:c.org,name:b(s,"name"),description:b(s,"description"),slug:b(s,"slug"),seoTitle:b(s,"seo-title"),seoDescription:b(s,"seo-description"),data:b(s,"data"),json:c.json};if(r==="list")return bn({org:c.org,json:c.json});if(r==="create")return In(u);if(r==="get"||r==="update"||r==="delete"){let l=o[0];if(!l)S(`usage: vcity collections ${r} <id>`);let w=O(l,"collection id");if(r==="get")return kn(w,{org:c.org,json:c.json});if(r==="update")return jn(w,u);return Tn(w,{org:c.org,yes:s.yes===!0,json:c.json})}S("usage: vcity collections list|get|create|update|delete")}case"agents":{let c=z(s);if(r==="list")return ln({org:c.org,limit:c.limit,json:c.json});if(r==="get"){let u=o[0];if(!u)S("usage: vcity agents get <id>");return pn(O(u,"agent id"),{org:c.org,json:c.json})}if(r==="update"){let u=o[0];if(!u)S("usage: vcity agents update <id> [--name ..] [--instructions ..] [--disable]");return mn(O(u,"agent id"),{org:c.org,json:c.json,name:b(s,"name"),description:b(s,"description"),emoji:b(s,"emoji"),avatar:b(s,"avatar"),instructions:b(s,"instructions"),instructionsFile:b(s,"instructions-file"),disable:s.disable===!0})}if(Ze.includes(r??""))return Eo(r,o,s);S(`usage: vcity agents list|get|update|${Ze.join("|")}`)}case"customer-agent":{let c=z(s);if(r==="get")return hn({org:c.org,json:c.json});if(r==="knowledge")return wn({org:c.org,json:c.json});S("usage: vcity customer-agent get|knowledge")}case"conversations":{let c=z(s);if(r==="list")return fn({org:c.org,status:c.status,awaitingReply:s["awaiting-reply"]===!0,json:c.json});if(r==="get"){let u=o[0];if(!u)S("usage: vcity conversations get <id>");return yn(O(u,"conversation id"),{org:c.org,limit:c.limit,json:c.json})}S("usage: vcity conversations list|get")}case"posts":{let c=z(s);if(r==="list")return Sn({org:c.org,limit:c.limit,status:c.status,json:c.json});if(r==="get"){let u=o[0];if(!u)S("usage: vcity posts get <id>");return On(O(u,"post id"),{org:c.org,json:c.json})}if(r==="create")return xn({org:c.org,comment:b(s,"comment"),file:b(s,"file"),video:b(s,"video"),poster:b(s,"poster"),data:b(s,"data"),json:c.json});if(r==="attach-video"){let u=o[0];if(!u)S("usage: vcity posts attach-video <id> --video <file.mp4>");return $n(O(u,"post id"),{org:c.org,video:b(s,"video"),poster:b(s,"poster"),json:c.json})}if(r==="preview"){let u=o[0];if(!u)S("usage: vcity posts preview <id>");return Dn(O(u,"post id"),{org:c.org,json:c.json})}if(r==="publish"){let u=o[0];if(!u)S("usage: vcity posts publish <id>");return Nn(O(u,"post id"),{org:c.org,yes:s.yes===!0,json:c.json})}S("usage: vcity posts list|get|create|attach-video|preview|publish")}case"rooms":{if(r==="show"||r==="messages"||r==="send"||r==="search"||r==="read")return Do(r,o,s);let c=z(s);if(r==="list")return no({org:c.org,limit:c.limit,json:c.json});if(r==="get"){let u=o[0];if(!u)S("usage: vcity rooms get <id>");return oo(O(u,"room id"),{org:c.org,json:c.json})}if(r==="create")return io({org:c.org,title:b(s,"title"),description:b(s,"description"),type:b(s,"type"),data:b(s,"data"),json:c.json});if(r==="update"){let u=o[0];if(!u)S("usage: vcity rooms update <id>");return ao(O(u,"room id"),{org:c.org,title:b(s,"title"),description:b(s,"description"),type:b(s,"type"),disabled:s.disabled===!0?!0:void 0,data:b(s,"data"),json:c.json})}if(r==="delete"){let u=o[0];if(!u)S("usage: vcity rooms delete <id>");return co(O(u,"room id"),{org:c.org,yes:s.yes===!0,json:c.json})}S("usage: vcity rooms list|get|create|update|delete|show|messages|send|search|read")}case"bookings":{let c=z(s);if(r==="list")return ns({...c,fromTs:M(s,"from"),toTs:M(s,"to")});if(r==="today")return ds({org:c.org,json:c.json});if(r==="slots")return ls(s);if(r==="time-off")return ps(o[0],o.slice(1),s);if(r==="hours")return ms(o,s);if(r==="get"){let u=o[0];if(!u)S("usage: vcity bookings get <id>");return os(O(u,"booking id"),{org:c.org,json:c.json})}if(r==="create")return is({org:c.org,name:b(s,"name"),email:b(s,"email"),start:b(s,"start"),end:b(s,"end"),timezone:b(s,"timezone"),phone:b(s,"phone"),company:b(s,"company"),note:b(s,"note"),bookingType:Q(s,"booking-type","--booking-type"),assignee:Q(s,"assignee","--assignee"),data:b(s,"data"),json:c.json});if(r==="update"){let u=o[0];if(!u)S("usage: vcity bookings update <id>");return as(O(u,"booking id"),{org:c.org,status:b(s,"status"),assignee:Q(s,"assignee","--assignee"),data:b(s,"data"),json:c.json})}if(r==="cancel"||r==="delete"){let u=o[0];if(!u)S(`usage: vcity bookings ${r} <id>`);return cs(O(u,"booking id"),{org:c.org,yes:s.yes===!0,json:c.json})}S("usage: vcity bookings list|get|create|update|cancel")}case"booking-types":{let c=z(s);if(r==="list")return Kr({org:c.org,limit:c.limit,enabled:s.enabled===!0?!0:void 0,json:c.json});if(r==="get"){let u=o[0];if(!u)S("usage: vcity booking-types get <id>");return Xr(O(u,"booking type id"),{org:c.org,json:c.json})}if(r==="create")return ts({org:c.org,name:b(s,"name"),duration:tt(s.duration,"--duration"),description:b(s,"description"),bufferBefore:tt(s["buffer-before"],"--buffer-before"),bufferAfter:tt(s["buffer-after"],"--buffer-after"),color:b(s,"color"),assignee:Q(s,"assignee","--assignee"),roundRobin:s["round-robin"]===!0?!0:void 0,sortOrder:tt(s["sort-order"],"--sort-order"),data:b(s,"data"),json:c.json});if(r==="update"){let u=o[0];if(!u)S("usage: vcity booking-types update <id>");let l=s.disabled===!0?!1:s.enabled===!0?!0:void 0;return es(O(u,"booking type id"),{org:c.org,name:b(s,"name"),duration:tt(s.duration,"--duration"),description:b(s,"description"),bufferBefore:tt(s["buffer-before"],"--buffer-before"),bufferAfter:tt(s["buffer-after"],"--buffer-after"),color:b(s,"color"),assignee:Q(s,"assignee","--assignee"),roundRobin:s["round-robin"]===!0?!0:void 0,enabled:l,sortOrder:tt(s["sort-order"],"--sort-order"),data:b(s,"data"),json:c.json})}if(r==="delete"){let u=o[0];if(!u)S("usage: vcity booking-types delete <id>");return rs(O(u,"booking type id"),{org:c.org,yes:s.yes===!0,json:c.json})}S("usage: vcity booking-types list|get|create|update|delete")}case"projects":{let c=z(s);if(r==="list")return Qn({org:c.org,limit:c.limit,json:c.json});if(r==="get"){let u=o[0];if(!u)S("usage: vcity projects get <id>");return Wn(O(u,"project id"),{org:c.org,json:c.json})}if(r==="create")return zn({org:c.org,name:b(s,"name"),prefix:b(s,"prefix"),description:b(s,"description"),data:b(s,"data"),json:c.json});if(r==="update"){let u=o[0];if(!u)S("usage: vcity projects update <id>");return Kn(O(u,"project id"),{org:c.org,name:b(s,"name"),description:b(s,"description"),data:b(s,"data"),json:c.json})}if(r==="delete"){let u=o[0];if(!u)S("usage: vcity projects delete <id>");return Xn(O(u,"project id"),{org:c.org,yes:s.yes===!0,json:c.json})}S("usage: vcity projects list|get|create|update|delete")}case"blogs":{let c=z(s);if(r==="list")return Hr({org:c.org,limit:c.limit,visibility:b(s,"visibility"),search:b(s,"search"),json:c.json});if(r==="get"){let u=o[0];if(!u)S("usage: vcity blogs get <id|slug>");return Yr(O(u,"blog id"),{org:c.org,json:c.json})}if(r==="create")return Qr({org:c.org,title:b(s,"title"),slug:b(s,"slug"),summary:b(s,"summary"),content:b(s,"content"),visibility:b(s,"visibility"),type:b(s,"type"),tags:b(s,"tags"),data:b(s,"data"),json:c.json});if(r==="update"){let u=o[0];if(!u)S("usage: vcity blogs update <id|slug>");return Wr(O(u,"blog id"),{org:c.org,title:b(s,"title"),slug:b(s,"slug"),summary:b(s,"summary"),content:b(s,"content"),visibility:b(s,"visibility"),type:b(s,"type"),tags:b(s,"tags"),data:b(s,"data"),json:c.json})}if(r==="delete"){let u=o[0];if(!u)S("usage: vcity blogs delete <id|slug>");return zr(O(u,"blog id"),{org:c.org,yes:s.yes===!0,json:c.json})}if(bt.includes(r??""))return er("blogs",r,o,s);S(`usage: vcity blogs list|get|create|update|delete|${bt.join("|")}`)}case"cards":{let c=z(s),u=Q(s,"project","--project");if(r==="list")return ws({org:c.org,project:u,column:Q(s,"column","--column"),assignee:Q(s,"assignee","--assignee"),archived:s.archived===!0,limit:c.limit,json:c.json});if(r==="get"){let l=o[0];if(!l)S("usage: vcity cards get <id|CODE-n> --project <id>");return vs(O(l,"card id"),{org:c.org,project:u,json:c.json})}if(r==="create")return bs({org:c.org,project:u,title:b(s,"title"),column:Q(s,"column","--column"),description:b(s,"description"),priority:b(s,"priority"),due:b(s,"due"),assignee:Q(s,"assignee","--assignee"),order:tt(s.order,"--order"),data:b(s,"data"),json:c.json});if(r==="update"){let l=o[0];if(!l)S("usage: vcity cards update <id|CODE-n> --project <id>");return ks(O(l,"card id"),{org:c.org,project:u,title:b(s,"title"),column:Q(s,"column","--column"),description:b(s,"description"),priority:b(s,"priority"),due:b(s,"due"),assignee:Q(s,"assignee","--assignee"),archived:s.archived===!0?!0:void 0,data:b(s,"data"),json:c.json})}if(r==="move"){let l=o[0];if(!l)S("usage: vcity cards move <id|CODE-n> --project <id> --column <col>");return Is(O(l,"card id"),{org:c.org,project:u,column:Q(s,"column","--column"),order:tt(s.order,"--order"),json:c.json})}if(r==="delete"){let l=o[0];if(!l)S("usage: vcity cards delete <id|CODE-n> --project <id>");return js(O(l,"card id"),{org:c.org,project:u,yes:s.yes===!0,json:c.json})}if(r==="comments"){let l=o[0];if(!l)S("usage: vcity cards comments <id|CODE-n> --project <id>");return Ts(O(l,"card id"),{org:c.org,project:u,limit:c.limit,json:c.json})}if(r==="comment"){let l=o[0];if(!l)S("usage: vcity cards comment <id|CODE-n> --project <id> --message <text>");return Es(O(l,"card id"),{org:c.org,project:u,message:b(s,"message"),json:c.json})}S("usage: vcity cards list|get|create|update|move|delete|comments|comment")}case"analytics":{let c=z(s),u={org:c.org,from:b(s,"from"),to:b(s,"to"),json:c.json};if(r==="summary")return Hs(u);if(r==="visits")return Ys({...u,groupBy:b(s,"group-by")});if(r==="top-products")return Qs({...u,limit:c.limit});S("usage: vcity analytics summary | vcity analytics visits | vcity analytics top-products")}case"orders":{let c=z(s);if(r==="list")return Xs(c);if(r==="get"){let u=o[0];if(!u)S("usage: vcity orders get <id>");return Zs(O(u,"order id"),{org:c.org,json:c.json})}if(r==="export")return tn({org:c.org,status:c.status,fromTs:M(s,"from"),toTs:M(s,"to"),format:A(s,"format",["csv","json"]),output:m(s,"output")});if(r==="ship"){let[u,...l]=o;if(!u)S("usage: vcity orders ship <orderId> [lineItemId...]");return en(O(u,"order id"),l.map((w)=>O(w,"line item id")),{org:c.org,status:A(s,"status",["shipped","delivered"]),json:c.json})}if(r==="comments"||r==="comment"||r==="breakdown")return Yo(r,o,s);S("usage: vcity orders list|get|export|ship|comments|comment|breakdown")}case"media":return Jn(r,o,s);case"status":return go({org:Q(s,"org","--org"),timeframe:A(s,"timeframe",uo),json:!!s.json});case"quotes":{let c=z(s);if(r==="list")return Zn(c);if(r==="get"){let u=o[0];if(!u)S("usage: vcity quotes get <id>");return to(O(u,"quote id"),{org:c.org,json:c.json})}if(r==="create")return eo({org:c.org,name:b(s,"name"),email:b(s,"email"),product:Q(s,"product","--product"),quantity:tt(s.quantity,"--quantity"),phone:b(s,"phone"),variation:b(s,"variation"),company:b(s,"company"),note:b(s,"note"),data:b(s,"data"),json:c.json});if(r==="update"){let u=o[0];if(!u)S("usage: vcity quotes update <id>");return ro(O(u,"quote id"),{org:c.org,status:b(s,"status"),assignee:Q(s,"assignee","--assignee"),name:b(s,"name"),email:b(s,"email"),product:Q(s,"product","--product"),quantity:tt(s.quantity,"--quantity"),phone:b(s,"phone"),variation:b(s,"variation"),company:b(s,"company"),note:b(s,"note"),data:b(s,"data"),json:c.json})}if(r==="delete"){let u=o[0];if(!u)S("usage: vcity quotes delete <id>");return so(O(u,"quote id"),{org:c.org,yes:s.yes===!0,json:c.json})}S("usage: vcity quotes list|get|create|update|delete")}case"crm":return Ms(r,o,s);case"inbox":return As(r,o,s);case"quick-replies":return Ps(r,o,s);case"chat":return Ds(r,o,s);case"notifications":return Ws(r&&!r.startsWith("--")?r:void 0,o,s);case"webhooks":return To(r,o,s);case"configurators":return $o(r,o,s);case"billing":return qo(r&&!r.startsWith("--")?r:void 0,o,s);case"storefront":return _o(r&&!r.startsWith("--")?r:void 0,o,s);case"newsletter":return Bo(r,o,s);case"surveys":return Mo(r,o,s);case"comments":return Lo(r,o,s);case"dropshipping":return Ao(r,o,s);case"pos":return Po(r,o,s);case"coupons":return Oo(r,o,s);case"campaigns":return Co(r,o,s);case"keys":return Vo(r,o,s);case"support":return Ko(r,o,s);case"profile":return Qo(r,s);case"calendar":return gs(r,o,s);case"vault":return bo(r,o,s);case"desk":return Ls(r,s);case"update":return wo({check:s.check===!0,yes:s.yes===!0,json:!!s.json});default:S(`unknown command: ${e}. Run \`vcity --help\`.`)}}async function Uc(){let t=process.argv.slice(2),e=ri(t)?si():void 0;try{await Fc(t)}finally{if(e)ni(await e)}}Uc().catch((t)=>{if(t instanceof y)S(t.message);let e=t instanceof Error?t.message:String(t);if(process.stderr.write(`error: ${E(e)}
|
|
442
|
+
`),process.env.VCITY_DEBUG&&t instanceof Error&&t.stack)process.stderr.write(`${E(t.stack)}
|
|
202
443
|
`);process.exit(1)});
|