@ecodrix/erix-api 3.1.2 → 3.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- var Qe=Object.defineProperty,Ye=Object.defineProperties;var Je=Object.getOwnPropertyDescriptors;var Fe=Object.getOwnPropertySymbols;var Xe=Object.prototype.hasOwnProperty,Ze=Object.prototype.propertyIsEnumerable;var et=(n,e)=>(e=Symbol[n])?e:Symbol.for("Symbol."+n);var Re=(n,e,t)=>e in n?Qe(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,u=(n,e)=>{for(var t in e||(e={}))Xe.call(e,t)&&Re(n,t,e[t]);if(Fe)for(var t of Fe(e))Ze.call(e,t)&&Re(n,t,e[t]);return n},b=(n,e)=>Ye(n,Je(e));var s=(n,e,t)=>Re(n,typeof e!="symbol"?e+"":e,t);var ke=function(n,e){this[0]=n,this[1]=e},Ke=(n,e,t)=>{var r=(l,p,y,g)=>{try{var h=t[l](p),x=(p=h.value)instanceof ke,k=h.done;Promise.resolve(x?p[0]:p).then(d=>x?r(l==="return"?l:"next",p[1]?{done:d.done,value:d.value}:d,y,g):y({value:d,done:k})).catch(d=>r("throw",d,y,g))}catch(d){g(d)}},a=(l,p,y,g)=>c[l]=h=>(p=new Promise((x,k,d)=>(d=()=>r(l,h,x,k),o?o.then(d):d())),g=()=>o===y&&(o=0),o=y=p.then(g,g),p),o,c={};return t=t.apply(n,e),c[et("asyncIterator")]=()=>c,a("next"),a("throw"),a("return"),c};import st from"axios";import We from"axios-retry";var Pe="https://api.ecodrix.com";function je(n="v1",e=Pe){return`${e.replace(/\/+$/,"")}/${n}/api`}var Ae=class extends Error{constructor(e){super(e),this.name="EcodrixError"}},m=class extends Ae{constructor(t,r,a){super(t);s(this,"status");s(this,"code");this.name="APIError",this.status=r,this.code=a}},T=class extends m{constructor(e="Invalid API Key or Client Code",t="AUTH_FAILED",r=401){super(e,r,t),this.name="AuthenticationError"}},v=class extends T{constructor(e="You don't have permission to do this.",t="FORBIDDEN"){super(e,t,403),this.name="PermissionError"}},w=class extends m{constructor(e="Too many requests. Please slow down."){super(e,429,"RATE_LIMIT_EXCEEDED"),this.name="RateLimitError"}};function q(n){var o;if(!(n!=null&&n.response))return new m((n==null?void 0:n.message)||"Network Error");let{status:e,data:t}=n.response,r=(t==null?void 0:t.message)||(t==null?void 0:t.error)||"API Request Failed",a=(o=t==null?void 0:t.code)!=null?o:typeof(t==null?void 0:t.error)=="string"&&/^[A-Z][A-Z0-9_]*$/.test(t.error)?t.error:void 0;switch(e){case 401:return new T(r,a);case 403:return new v(r,a);case 429:return new w(r);default:return new m(r,e,a)}}var i=class{constructor(e){s(this,"client",e)}async post(e,t,r){try{let a=this.buildConfig(r);return(await this.client.post(e,t,a)).data}catch(a){this.handleError(a)}}async get(e,t){try{let r=this.buildConfig(t);return(await this.client.get(e,r)).data}catch(r){this.handleError(r)}}async patch(e,t,r){try{let a=this.buildConfig(r);return(await this.client.patch(e,t,a)).data}catch(a){this.handleError(a)}}async put(e,t,r){try{let a=this.buildConfig(r);return(await this.client.put(e,t,a)).data}catch(a){this.handleError(a)}}async deleteRequest(e,t){try{let r=this.buildConfig(t);return(await this.client.delete(e,r)).data}catch(r){this.handleError(r)}}buildConfig(e){if(!e)return;let t=u({},e);return e.idempotencyKey&&(t.headers=b(u({},t.headers),{"Idempotency-Key":e.idempotencyKey})),t}handleError(e){throw q(e)}};var ve=class extends i{async list(e){return this.get(`/product/erix/crm/leads/${e}/notes`)}async create(e,t){return this.post(`/product/erix/crm/leads/${e}/notes`,t)}async update(e,t){return this.patch(`/product/erix/crm/notes/${e}`,{content:t})}async pin(e,t=!0){return this.patch(`/product/erix/crm/notes/${e}/pin`,{isPinned:t})}async delete(e){return this.deleteRequest(`/product/erix/crm/notes/${e}`)}},U=class extends i{constructor(t){super(t);s(this,"notes");this.notes=new ve(t)}async timeline(t,r){return this.get(`/product/erix/crm/leads/${t}/timeline`,{params:r})}async list(t,r){return this.get(`/product/erix/crm/leads/${t}/activities`,{params:u({},r)})}async log(t){return this.post(`/product/erix/crm/leads/${t.leadId}/activities`,t)}async logCall(t,r){return this.post(`/product/erix/crm/leads/${t}/calls`,r)}};var _=class extends i{async overview(e){return this.get("/product/erix/crm/analytics/overview",{params:e})}async funnel(e){return this.get("/product/erix/crm/analytics/funnel",{params:{pipelineId:e}})}async forecast(e){return this.get("/product/erix/crm/analytics/forecast",{params:{pipelineId:e}})}async sources(e){return this.get("/product/erix/crm/analytics/sources",{params:e})}async team(e){return this.get("/product/erix/crm/analytics/team",{params:e})}async heatmap(e){return this.get("/product/erix/crm/analytics/heatmap",{params:e})}async scores(){return this.get("/product/erix/crm/analytics/scores")}async stageTime(e){return this.get("/product/erix/crm/analytics/stage-time",{params:{pipelineId:e}})}async tiered(e){return this.get("/product/erix/crm/analytics/tiered",{params:e})}async summary(e){return this.get("/product/erix/crm/analytics/summary",{params:e})}async whatsapp(e){return this.get("/product/erix/crm/analytics/whatsapp",{params:e})}async revenue(){return this.get("/product/erix/crm/analytics/revenue")}async health(){return this.get("/product/erix/crm/analytics/health")}async payments(){return this.get("/product/erix/crm/analytics/payments")}async reviews(){return this.get("/product/erix/crm/analytics/reviews")}async retention(){return this.get("/product/erix/crm/analytics/retention")}};var N=class extends i{async getChecklist(e){return this.get(`/product/erix/crm/documents/checklist/${e}`)}async createChecklist(e,t){return this.post(`/product/erix/crm/documents/checklist/${e}`,{templateNiche:t})}async markReceived(e,t,r){return this.patch(`/product/erix/crm/documents/checklist/${e}/${t}`,r?{fileUrl:r}:{})}async sendReminder(e){return this.post(`/product/erix/crm/documents/checklist/${e}/remind`)}async listIncomplete(){return this.get("/product/erix/crm/documents/checklist/incomplete")}async listTemplates(){return this.get("/product/erix/crm/documents/templates")}};var B=class extends i{async csv(e){return this.get("/product/erix/commerce/invoices/export/csv",{params:e})}async tally(e){return this.get("/product/erix/commerce/invoices/export/tally",{params:e})}async zoho(e){return this.get("/product/erix/commerce/invoices/export/zoho",{params:e})}};var He=["open","won","lost","archived"],V=class extends i{async create(e){return this.post("/product/erix/crm/leads",e)}async describe(){let e=await this.fields(),t=Array.isArray(e.data)?e.data:[],r=[{key:"firstName",label:"First Name",type:"string",required:!0,group:"Basic Info"},{key:"lastName",label:"Last Name",type:"string",required:!1,group:"Basic Info"},{key:"phone",label:"Phone Number",type:"phone",required:!0,group:"Contact"},{key:"email",label:"Email Address",type:"email",required:!1,group:"Contact"},{key:"status",label:"Status",type:"select",required:!0,options:He.map(o=>({label:`${o.charAt(0).toUpperCase()}${o.slice(1)}`,value:o}))},{key:"value",label:"Lead Value",type:"currency",required:!1},{key:"source",label:"Source",type:"string",required:!1}],a=t.map(o=>({key:`metadata.extra.${o.name}`,label:o.label||o.name,type:o.type||"string",required:!!o.required,options:o.options,group:"Custom Fields"}));return{name:"Lead",fields:[...r,...a],uiHints:{icon:"User",primaryColor:"#3b82f6",defaultSort:{field:"createdAt",direction:"desc"},summaryFields:["firstName","lastName","phone","status"]}}}async upsert(e){return this.post("/product/erix/crm/leads/upsert",e)}async createMany(e,t=50){let r=[];for(let a=0;a<e.length;a+=t){let c=e.slice(a,a+t).map(p=>this.create(p)),l=await Promise.allSettled(c);for(let p of l)if(p.status==="fulfilled")r.push(p.value);else throw p.reason}return r}async import(e){return this.post("/product/erix/crm/leads/import",{leads:e})}async bulkUpsert(e){return this.import(e)}async list(e){let t=u({},e);return Array.isArray(t.tags)&&(t.tags=t.tags.join(",")),this.get("/product/erix/crm/leads",{params:t})}listAutoPaging(e){return Ke(this,null,function*(){let t=(e==null?void 0:e.page)||1,r=!0;for(;r;){let a=yield new ke(this.list(b(u({},e),{page:t}))),o=Array.isArray(a.data)?a.data:a||[];if(o.length===0){r=!1;break}for(let c of o)yield c;a.pagination&&t<a.pagination.pages||!a.pagination&&o.length>0?t++:r=!1}})}async retrieve(e){return this.get(`/product/erix/crm/leads/${e}`)}async retrieveByPhone(e){return this.get(`/product/erix/crm/leads/phone/${encodeURIComponent(e)}`)}async byStage(e,t,r={}){return this.get(`/product/erix/crm/pipelines/${e}/stages/${t}/leads`,{params:r})}async retrieveByRef(e,t){return this.get(`/product/erix/crm/leads/ref/${encodeURIComponent(e)}/${encodeURIComponent(t)}`)}async update(e,t){return this.patch(`/product/erix/crm/leads/${e}`,t)}async setFollowUp(e,t,r){return this.patch(`/product/erix/crm/leads/${e}`,{nextFollowUpAt:t,nextFollowUpNote:t&&r!=null?r:null})}async move(e,t){return this.patch(`/product/erix/crm/leads/${e}/move`,{stageId:t})}async convert(e,t,r){return this.post(`/product/erix/crm/leads/${e}/convert`,{outcome:t,reason:r})}async tags(e,t){return this.patch(`/product/erix/crm/leads/${e}/tags`,t)}async recalculateScore(e){return this.post(`/product/erix/crm/leads/${e}/score`,{})}async updateMetadata(e,t){return this.patch(`/product/erix/crm/leads/${e}/metadata`,t)}async fields(){return this.get("/product/erix/crm/fields")}async notes(e){return this.get(`/product/erix/crm/leads/${e}/notes`)}async activities(e,t){return this.get(`/product/erix/crm/leads/${e}/timeline`,{params:t})}async createNote(e,t){return this.post(`/product/erix/crm/leads/${e}/notes`,t)}async updateNote(e,t,r){return this.patch(`/product/erix/crm/notes/${t}`,r)}async deleteNote(e,t){return this.deleteRequest(`/product/erix/crm/notes/${t}`)}async delete(e){return this.deleteRequest(`/product/erix/crm/leads/${e}`)}async export(e){return this.get(`/product/erix/crm/leads/${encodeURIComponent(e)}/export`)}async erase(e){return this.post(`/product/erix/crm/leads/${encodeURIComponent(e)}/erase`,{confirm:"ERASE"})}async bulkArchive(e){return this.patch("/product/erix/crm/leads/bulk-archive",{ids:e})}async bulkDelete(e){return this.deleteRequest("/product/erix/crm/leads",{data:{ids:e}})}async archive(e){return this.deleteRequest(`/product/erix/crm/leads/${e}`)}async profile(e){return this.get(`/product/erix/crm/leads/${e}/profile`)}async invoices(e){return this.get(`/product/erix/crm/leads/${e}/invoices`)}async projects(e){return this.get(`/product/erix/crm/leads/${e}/projects`)}async conversations(e){return this.get(`/product/erix/crm/leads/${e}/conversations`)}async meetings(e){return this.get(`/product/erix/crm/leads/${e}/meetings`)}async flowRuns(e){return this.get(`/product/erix/crm/leads/${e}/flow-runs`)}async merge(e,t){return this.post("/product/erix/crm/leads/merge",{primaryId:e,secondaryId:t})}};var F=class extends i{async capture(e){return this.post("/product/erix/crm/payments/capture",e)}};var K=class extends i{async list(){return this.get("/product/erix/crm/pipelines")}async getStageManifest(e){var a,o;let t=await this.retrieve(e),r=Array.isArray((a=t.data)==null?void 0:a.stages)?t.data.stages:[];return{name:`Pipeline: ${((o=t.data)==null?void 0:o.name)||e}`,fields:r.map(c=>({key:c._id,label:c.name,type:"string",required:!0,options:[{label:c.name,value:c._id}],group:"Stages",uiHints:{color:c.color||"#cbd5e1",probability:c.probability}})),uiHints:{icon:"Columns",primaryColor:"#6366f1"}}}async create(e){return this.post("/product/erix/crm/pipelines",e)}async retrieve(e){return this.get(`/product/erix/crm/pipelines/${e}`)}async update(e,t){return this.patch(`/product/erix/crm/pipelines/${e}`,t)}async setDefault(e){return this.patch(`/product/erix/crm/pipelines/${e}/default`,{})}async duplicate(e,t){return this.post(`/product/erix/crm/pipelines/${e}/duplicate`,{name:t})}async archive(e){return this.patch(`/product/erix/crm/pipelines/${e}/archive`,{})}async delete(e){return this.deleteRequest(`/product/erix/crm/pipelines/${e}`)}async checkInUse(e){return this.get(`/product/erix/crm/pipelines/${e}/in-use`)}async board(e){return this.get(`/product/erix/crm/pipelines/${e}/board`)}async forecast(e){return this.get(`/product/erix/crm/pipelines/${e}/forecast`)}async addStage(e,t){return this.post(`/product/erix/crm/pipelines/${e}/stages`,t)}async reorderStages(e,t){return this.patch(`/product/erix/crm/pipelines/${e}/stages/reorder`,{order:t})}async updateStage(e,t){return this.patch(`/product/erix/crm/stages/${e}`,t)}async deleteStage(e,t){return this.deleteRequest(`/product/erix/crm/stages/${e}`,{data:t?{moveLeadsToStageId:t}:void 0})}};var j=class extends i{async getConfig(){return this.get("/product/erix/crm/scoring")}async updateConfig(e){return this.patch("/product/erix/crm/scoring",e)}async recalculate(e){return this.post(`/product/erix/crm/scoring/${e}/recalculate`,{})}async preview(e){return this.get(`/product/erix/crm/scoring/preview/${e}`)}};var H=class extends i{async list(e){return this.get("/platform/inbox/conversations",{params:e})}async create(e){var t;return this.post("/platform/inbox/conversations",{address:e.phone,channel:(t=e.channel)!=null?t:"whatsapp",userName:e.name})}async linkLead(e,t){return this.patch(`/platform/inbox/conversations/${e}/lead`,{leadId:t})}async retrieve(e){return this.get(`/platform/inbox/conversations/${e}`)}async messages(e,t){return this.get(`/platform/inbox/conversations/${e}/messages`,{params:t})}async markRead(e){return this.post(`/platform/inbox/conversations/${e}/read`,{})}async delete(e){return this.deleteRequest(`/platform/inbox/conversations/${e}`)}async bulkDelete(e){return this.post("/platform/inbox/conversations/bulk-delete",{ids:e})}};var P=class extends i{async send(e){if(e.conversationId)return this.post(`/platform/inbox/conversations/${e.conversationId}/messages`,{text:e.text,media:e.media});if(!e.to)throw new Error("send: conversationId or to is required");if(e.media)throw new Error("send: media goes to an inbox thread (conversationId)");return this.post("/infra/connect/send/whatsapp",{phone:e.to,text:e.text})}async sendTemplate(e){return this.post("/infra/connect/send/whatsapp",{phone:e.to,templateName:e.templateName,language:e.language,variables:e.variables})}async star(e,t){return this.post(`/platform/inbox/messages/${e}/star`,{starred:t})}async markRead(e){return this.post(`/platform/inbox/conversations/${e}/read`,{})}async upload(e,t={}){var y,g,h;let r=(g=(y=t.fileName)!=null?y:e.name)!=null?g:"file",a=e.type||"application/octet-stream",o=await this.post("/infra/storage/files/upload-url",{folder:(h=t.folder)!=null?h:"inbox",filename:r,contentType:a}),{uploadUrl:c,key:l}=o.data,p=await fetch(c,{method:"PUT",headers:{"Content-Type":a},body:e});if(!p.ok)throw new Error(`upload failed (${p.status})`);return await this.post("/infra/storage/files/confirm-upload",{key:l,sizeBytes:e.size}),{key:l,mimeType:a,fileName:r}}};var W=class extends i{async getProduct(e){return this.get(`/product/erix/commerce/checkout/products/${e}`)}async createSession(e){return this.post("/product/erix/commerce/checkout/session",e)}async applyCoupon(e){return this.post("/product/erix/commerce/checkout/coupon",e)}async verify(e){return this.post("/product/erix/commerce/checkout/verify",e)}async createOrder(e){return this.post("/product/erix/commerce/checkout/order",e)}};var z=class extends i{async trigger(e){return this.post("/product/erix/events/trigger",e)}async listCustomEvents(){return this.get("/product/flow/config/triggers")}async createCustomEvent(e){return this.post("/product/flow/config/triggers",e)}async deleteCustomEvent(e){return this.deleteRequest(`/product/flow/config/triggers/${e}`)}};var G=class extends i{async list(e){return this.get("/product/erix/commerce/invoices",{params:e})}async getInvoice(e){return this.get(`/product/erix/commerce/invoices/${e}`)}async create(e){return this.post("/product/erix/commerce/invoices",e)}async update(e,t){return this.patch(`/product/erix/commerce/invoices/${e}`,t)}async void(e){return this.post(`/product/erix/commerce/invoices/${e}/void`,{})}async sendViaWhatsApp(e){return this.post(`/product/erix/commerce/invoices/${e}/send-whatsapp`,{})}async getSettings(){return this.get("/product/erix/commerce/settings")}async updateSettings(e){return this.put("/product/erix/commerce/settings",e)}async paymentLink(e){return this.post(`/product/erix/commerce/invoices/${encodeURIComponent(e)}/payment-link`,{})}async recordPayment(e,t){return this.post(`/product/erix/commerce/invoices/${encodeURIComponent(e)}/payments`,t)}async sendWhatsApp(e){return this.post(`/product/erix/commerce/invoices/${encodeURIComponent(e)}/send-whatsapp`,{})}async sendEmail(e){return this.post(`/product/erix/commerce/invoices/${encodeURIComponent(e)}/send-email`,{})}};var Q=class extends i{async workflowPacks(){return this.get("/product/erix/crm/niche/workflow-packs")}async workflowPackDetail(e){return this.get(`/product/erix/crm/niche/workflow-packs/${e}`)}async installWorkflowPack(e){return this.post(`/product/erix/crm/niche/workflow-packs/${e}/install`)}async templateSuggestions(){return this.get("/product/erix/crm/niche/template-suggestions")}};var Y=class extends i{async list(e){return this.get(`/product/erix/commerce/projects/${e}/documents`)}async upload(e,t){return this.post(`/product/erix/commerce/projects/${e}/documents`,t)}async toggleSignature(e,t,r){return this.patch(`/product/erix/commerce/projects/${e}/documents/${t}/signature`,{required:r})}async addSigner(e,t,r){return this.post(`/product/erix/commerce/projects/${e}/documents/${t}/signers`,r)}async decline(e,t){return this.post(`/product/erix/commerce/projects/${e}/documents/${t}/decline`,{})}async stampSign(e,t,r){return this.post(`/product/erix/commerce/projects/${e}/documents/${t}/stamp-sign`,r)}};var J=class extends i{async providers(){return this.get("/infra/connect/providers")}async list(){return this.get("/infra/connect/connections")}async get_(e){return this.get(`/infra/connect/connections/${e}`)}async connect(e,t){return this.post(`/infra/connect/connections/${e}/connect`,t)}async configure(e,t){return this.put(`/infra/connect/connections/${e}/configure`,t)}async disconnect(e){return this.post(`/infra/connect/connections/${e}/disconnect`,{})}async reveal(e){return this.post(`/infra/connect/connections/${e}/reveal`,{})}async test(e){return this.post(`/infra/connect/connections/${e}/test`,{})}async setAccess(e,t){return this.put(`/infra/connect/connections/${e}/access`,t)}async googleConnectUrl(){return this.post("/infra/connect/google/connect-url",{})}async createPaymentLink(e){return this.post("/infra/connect/connections/payments/payment-link",e)}};var X=class extends i{async sendTest(e){return this.post("/infra/connect/email/test",{to:e})}async listTemplates(e){return this.get("/infra/connect/email/templates",{params:e})}async getTemplate(e){return this.get(`/infra/connect/email/templates/${e}`)}async createTemplate(e){return this.post("/infra/connect/email/templates",e)}async updateTemplate(e,t){return this.put(`/infra/connect/email/templates/${e}`,t)}async deleteTemplate(e,t=!1){return this.deleteRequest(`/infra/connect/email/templates/${e}`,{params:{force:t}})}async previewTemplate(e,t){return this.post(`/infra/connect/email/templates/${e}/preview`,t)}};var Z=class extends i{async create(e){return this.post("/infra/connect/meet",e)}async list(e){return this.get("/infra/connect/meet",{params:e})}async retrieve(e){return this.get(`/infra/connect/meet/${e}`)}async update(e,t){return this.patch(`/infra/connect/meet/${e}`,t)}async reschedule(e,t){return this.patch(`/infra/connect/meet/${e}`,t)}async delete(e){return this.update(e,{status:"cancelled"})}};var ee=class extends i{async getConfig(){return this.get("/infra/connect/email/config")}async initDomainVerification(e){return this.post("/infra/connect/email/config/ses/domain",{domain:e})}async saveEmailConfig(e){return this.post("/infra/connect/email/config/ses/config",e)}async checkSesVerification(){return this.get("/infra/connect/email/config/ses/verify")}async removeSesIdentity(){return this.deleteRequest("/infra/connect/email/config/ses/domain")}async sendTest(e){return this.post("/infra/connect/email/config/test",{toEmail:e})}async saveAdvancedConfig(e){return this.post("/infra/connect/email/config/advanced",e)}async getHealth(){return this.get("/infra/connect/email/config/health")}async fixDmarc(){return this.post("/infra/connect/email/config/ses/fix-dmarc",{})}async listProviders(){return this.get("/infra/connect/email/config/providers")}};var te=class extends i{async list(e){return this.get("/infra/connect/whatsapp/templates",{params:e})}async sync(){return this.post("/infra/connect/whatsapp/templates/sync",{})}async retrieve(e){return this.get(`/infra/connect/whatsapp/templates/${encodeURIComponent(e)}`)}async create(e){return this.post("/infra/connect/whatsapp/templates",e)}async update(e,t){return this.put(`/infra/connect/whatsapp/templates/${e}`,t)}async deleteTemplate(e,t){return this.deleteRequest(`/infra/connect/whatsapp/templates/${encodeURIComponent(e)}${t?"?force=true":""}`)}async mappingConfig(){return this.get("/infra/connect/whatsapp/templates/mapping/config")}async mappingSources(){return this.get("/infra/connect/whatsapp/templates/mapping/sources")}async collections(){return this.get("/infra/connect/whatsapp/templates/collections")}async collectionFields(e){return this.get(`/infra/connect/whatsapp/templates/collections/${encodeURIComponent(e)}/fields`)}async updateMapping(e,t){return this.put(`/infra/connect/whatsapp/templates/${encodeURIComponent(e)}/mapping`,t)}async validate(e,t){let r=`/infra/connect/whatsapp/templates/${encodeURIComponent(e)}/validate`;return t?this.post(r,t):this.get(r)}async preview(e,t,r,a){return this.post(`/infra/connect/whatsapp/templates/${encodeURIComponent(e)}/preview`,{context:t,mappings:r,onEmptyVariable:a})}async getVariableManifest(e){var o,c;let t=await this.retrieve(e),r=Array.isArray((o=t.data)==null?void 0:o.components)?t.data.components:[],a=[];for(let l of r)if(l.text){let p=l.text.match(/{{(\d+)}}/g);if(p)for(let y of p){let g=y.replace(/{{|}}/g,"");a.push({key:`var_${g}`,label:`${l.type} Var {{${g}}}`,type:"string",required:!0,group:l.type,description:`Variable placeholder in template ${l.type}`})}}return{name:`Template variables: ${((c=t.data)==null?void 0:c.name)||e}`,fields:a,uiHints:{icon:"Variables",primaryColor:"#059669"}}}};import tt from"axios";var ne=class extends i{async getUsage(){return this.get("/infra/storage/files/usage")}async createFolder(e){return this.post("/infra/storage/files/folders",{name:e})}async list(e,t){return this.get(`/infra/storage/files/files/${e}`,{params:t})}async delete(e){return this.deleteRequest("/infra/storage/files/files",{params:{key:e}})}async getDownloadUrl(e){return this.post("/infra/storage/files/download-url",{key:e})}async aiDescribe(e){return this.post("/infra/storage/files/ai/describe",{key:e})}async upload(e,t){let r=await this.post("/infra/storage/files/upload-url",t),{uploadUrl:a,key:o}=r.data;await tt.put(a,e,{headers:{"Content-Type":t.contentType}});let c=e.size||e.byteLength||0;return this.post("/infra/storage/files/confirm-upload",{key:o,sizeBytes:c})}};var re=class extends i{async create(e){return this.post("/infra/storage/files/folders",{name:e})}},se=class extends i{async list(e,t){return this.get(`/infra/storage/files/files/${e}`,{params:t})}async getUploadUrl(e){return this.post("/infra/storage/files/upload-url",e)}async confirmUpload(e){return this.post("/infra/storage/files/confirm-upload",e)}async getDownloadUrl(e){return this.post("/infra/storage/files/download-url",{key:e})}async delete(e){return this.deleteRequest("/infra/storage/files/files",{params:{key:e}})}};var ie=class extends i{async system(){return(await this.get("/health")).data}};var ae=class extends i{async listAlerts(e){return this.get("/platform/users/notifications",{params:e})}async dismissAlert(e){return this.patch(`/platform/users/notifications/${e}/dismiss`)}async clearAllAlerts(){return this.deleteRequest("/platform/users/notifications/dismiss-all")}};var I=class extends i{async global(e){return this.post("/platform/tenants/onboarding/global",e)}async complete(e){return this.post("/platform/tenants/onboarding/complete",e)}};var S=class extends i{async get(e){return super.get(`/platform/tenants/persona/${e}`)}async reinforce(e){return this.post(`/platform/tenants/persona/${e.productId}/reinforce`,e)}async confidence(e){return super.get(`/platform/tenants/persona/${e}/confidence`,{params:{productId:e}})}async timeline(e,t){var a;let r=await super.get(`/platform/tenants/persona/${e}/timeline`,{params:t});return(a=r==null?void 0:r.data)!=null?a:{entries:[],hasMore:!1}}async followups(e){var r,a;let t=await super.get(`/platform/tenants/persona/${e}/followups`);return(a=(r=t==null?void 0:t.data)==null?void 0:r.entries)!=null?a:[]}};var Ie=class extends i{async chatSync(e){return this.post("/platform/ai/copilot/chat/sync",e)}async confirm(e){return this.post("/platform/ai/copilot/confirm",e)}async listSessions(){return this.get("/platform/ai/copilot/sessions")}async getSession(e){return this.get(`/platform/ai/copilot/sessions/${e}`)}async deleteSession(e){return this.deleteRequest(`/platform/ai/copilot/sessions/${e}`)}chatStreamUrl(){return"/platform/ai/copilot/chat"}},oe=class{constructor(e){s(this,"copilot");this.copilot=new Ie(e)}};var nt=["application/pdf","application/vnd.openxmlformats-officedocument.wordprocessingml.document","text/plain","text/markdown","text/csv","text/html","image/png","image/jpeg","image/webp"],C=class extends i{async list(){return this.get("/platform/knowledge/sources")}async addText(e){return this.post("/platform/knowledge/sources",u({kind:"text"},e))}async addUrl(e){return this.post("/platform/knowledge/sources",u({kind:"url"},e))}async addFile(e,t={}){var a,o;let r=await new P(this.client).upload(e,{folder:"knowledge"});return this.post("/platform/knowledge/sources",{kind:"file",key:r.key,mimeType:r.mimeType,title:(o=(a=t.title)!=null?a:r.fileName)!=null?o:"Document"})}async remove(e){return this.deleteRequest(`/platform/knowledge/sources/${e}`)}async reindex(e){return this.post(`/platform/knowledge/sources/${e}/reindex`,{})}async search(e,t){return this.post("/platform/knowledge/search",u({query:e},t?{limit:t}:{}))}};var E=class extends i{async settings(){return this.get("/product/erix/ai/settings")}async updateSettings(e){return this.patch("/product/erix/ai/settings",e)}async reviews(e){return this.get(`/product/erix/ai/reviews${e?`?status=${e}`:""}`)}async review(e,t,r){return this.post(`/product/erix/ai/reviews/${encodeURIComponent(e)}`,u({verdict:t},r?{note:r}:{}))}async suggestion(e){return this.get(`/product/erix/ai/suggestion/${e}`)}async approveAction(e){return this.post(`/product/erix/ai/suggestion/${e}/approve-action`,{})}async markSent(e,t,r){return this.post(`/product/erix/ai/suggestion/${e}/send`,{text:t,confidence:r})}async dismiss(e){return this.post(`/product/erix/ai/suggestion/${e}/dismiss`,{})}async approvals(){return this.get("/product/flow/approvals")}async agents(){return this.get("/product/flow/agents")}async updateAgent(e,t){return this.patch(`/product/flow/agents/${encodeURIComponent(e)}`,t)}async decideRun(e,t,r){return this.post(`/product/flow/runs/${encodeURIComponent(e)}/approve`,u({decision:t},r&&{nodeId:r}))}};var ce=class extends i{async register(e){return this.post("/platform/auth/register",e)}async login(e){return this.post("/platform/auth/login",e)}async logout(e){return this.post("/platform/auth/logout",e)}async logoutAll(e){return this.post("/platform/auth/logout-all",e)}async validateSession(e){return this.post("/platform/auth/session/validate",e)}async listSessions(){return this.get("/platform/auth/sessions")}async revokeSession(e){return this.deleteRequest(`/platform/auth/sessions/${e}`)}async requestPasswordOtp(e){return this.post("/platform/auth/password/request-otp",e)}async setPassword(e){return this.post("/platform/auth/password/set",e)}async changePassword(e){return this.post("/platform/auth/password/change",e)}async forgotPassword(e){return this.post("/platform/auth/forgot",e)}async resetPassword(e){return this.post("/platform/auth/reset",e)}async linkOAuth(e){return this.post("/platform/auth/oauth-link",e)}async getInvitation(e){return this.get(`/platform/auth/invitations/${e}`)}async acceptInvitation(e,t){return this.post(`/platform/auth/invitations/${e}/accept`,t)}};var Se=class extends i{async get(){return super.get("/platform/billing/entitlements/entitlements")}async usage(){return super.get("/platform/billing/entitlements/usage")}},Ce=class extends i{async upgrade(e){return this.post("/platform/billing/subscriptions/subscriptions/upgrade",e)}async downgrade(e){return this.post("/platform/billing/subscriptions/subscriptions/downgrade",e)}async cancel(e){return this.post("/platform/billing/subscriptions/subscriptions/cancel",e)}async purchaseAddon(e){return this.post("/platform/billing/subscriptions/addons/purchase",e)}async cancelAddon(e){return this.post("/platform/billing/subscriptions/addons/cancel",e)}},Ee=class extends i{async listPublic(){return this.get("/platform/billing/plans/public")}},$e=class extends i{async plans(){return this.get("/platform/billing/checkout/plans")}async subscribe(e){return this.post("/platform/billing/checkout/subscribe",e)}async verify(e){return this.post("/platform/billing/checkout/verify",e)}async cancel(e){return this.post("/platform/billing/checkout/cancel",e)}async status(){return this.get("/platform/billing/checkout/status")}async syncPlan(e){return this.post("/platform/billing/checkout/sync-plan",e)}},Oe=class extends i{async transactions(){return this.get("/platform/billing/user/transactions")}async subscription(){return this.get("/platform/billing/user/subscription")}async raiseDispute(e){return this.post("/platform/billing/user/dispute",e)}async disputes(){return this.get("/platform/billing/user/disputes")}},Me=class extends i{async balance(){return this.get("/platform/billing/credits/balance")}async transactions(){return this.get("/platform/billing/credits/transactions")}async packs(){return this.get("/platform/billing/credits/packs")}async topupOrder(e){return this.post("/platform/billing/credits/topup/order",e)}async verifyTopup(e){return this.post("/platform/billing/credits/topup/verify",e)}async setAutoTopup(e){return this.patch("/platform/billing/credits/auto-topup",e)}async setSpendCap(e){return this.patch("/platform/billing/credits/spend-cap",e)}},pe=class{constructor(e){s(this,"entitlements");s(this,"subscriptions");s(this,"plans");s(this,"checkout");s(this,"user");s(this,"credits");this.entitlements=new Se(e),this.subscriptions=new Ce(e),this.plans=new Ee(e),this.checkout=new $e(e),this.user=new Oe(e),this.credits=new Me(e)}};var le=class extends i{async categories(){return this.get("/platform/support/categories")}async listTickets(e){return this.get("/platform/support/tickets",{params:e})}async createTicket(e){return this.post("/platform/support/tickets",e)}async getTicket(e){return this.get(`/platform/support/tickets/${e}`)}async reply(e,t){return this.post(`/platform/support/tickets/${e}/reply`,t)}async close(e){return this.patch(`/platform/support/tickets/${e}/close`,{})}};var ue=class extends i{async get(){return super.get("/platform/users/me")}async update(e){return this.patch("/platform/users/me",e)}async updateOrganization(e){return this.patch("/platform/users/me/organization",e)}async toggleModules(e){return this.post("/platform/users/me/modules",e)}async workspaces(){return super.get("/platform/users/me/workspaces")}async setActiveOrg(e){return this.post("/platform/users/me/active-org",e)}async dismissWorkspaceSetup(){return this.post("/platform/users/me/workspace/dismiss-setup",{})}},ge=class extends i{async list(){return this.get("/platform/users/members")}async invite(e){return this.post("/platform/users/members/invite",e)}async updateRole(e,t){return this.patch(`/platform/users/members/${e}`,{role:t})}async remove(e){return this.deleteRequest(`/platform/users/members/${e}`)}},de=class extends i{async list(){return this.get("/platform/auth/sessions")}async revoke(e){return this.deleteRequest(`/platform/auth/sessions/${e}`)}};var me=class{constructor(e){s(this,"messages");s(this,"conversations");this.messages=new P(e),this.conversations=new H(e)}},ye=class{constructor(e){s(this,"leads");s(this,"pipelines");s(this,"activities");s(this,"analytics");s(this,"scoring");s(this,"payments");s(this,"chat");s(this,"events");s(this,"invoices");s(this,"checkout");s(this,"projects");s(this,"niche");s(this,"documents");s(this,"invoiceExport");s(this,"ai");this.leads=new V(e),this.pipelines=new K(e),this.activities=new U(e),this.analytics=new _(e),this.scoring=new j(e),this.payments=new F(e),this.chat=new me(e),this.events=new z(e),this.invoices=new G(e),this.checkout=new W(e),this.projects=new Y(e),this.niche=new Q(e),this.documents=new N(e),this.invoiceExport=new B(e),this.ai=new E(e)}},$=class{constructor(e){s(this,"erix");this.erix=new ye(e)}},fe=class{constructor(e){s(this,"config");s(this,"templates");this.config=new ee(e),this.templates=new X(e)}},he=class{constructor(e){s(this,"templates");this.templates=new te(e)}},Te=class{constructor(e){s(this,"email");s(this,"whatsapp");s(this,"meet");s(this,"connections");this.email=new fe(e),this.whatsapp=new he(e),this.meet=new Z(e),this.connections=new J(e)}},xe=class{constructor(e){s(this,"files");s(this,"folders");s(this,"media");this.files=new se(e),this.folders=new re(e),this.media=new ne(e)}},O=class{constructor(e){s(this,"connect");s(this,"storage");this.connect=new Te(e),this.storage=new xe(e)}},be=class{constructor(e){s(this,"onboarding");s(this,"persona");this.onboarding=new I(e),this.persona=new S(e)}},we=class{constructor(e){s(this,"me");s(this,"members");s(this,"sessions");s(this,"notifications");this.me=new ue(e),this.members=new ge(e),this.sessions=new de(e),this.notifications=new ae(e)}},M=class{constructor(e){s(this,"auth");s(this,"users");s(this,"tenants");s(this,"billing");s(this,"support");s(this,"ai");s(this,"knowledge");s(this,"health");this.auth=new ce(e),this.users=new we(e),this.tenants=new be(e),this.billing=new pe(e),this.support=new le(e),this.ai=new oe(e),this.knowledge=new C(e),this.health=new ie(e)}};var R=class extends m{constructor(e){super(e,400,"invalid_signature"),this.name="WebhookSignatureError"}},D=class{async constructEvent(e,t,r){if(!t)throw new R("No webhook signature provided");let a=Array.isArray(t)?t[0]:t;a.startsWith("sha256=")&&(a=a.slice(7));try{let o=await import("crypto"),l=o.createHmac("sha256",r).update(e).digest("hex");if(!o.timingSafeEqual(Buffer.from(l),Buffer.from(a)))throw new R("Invalid webhook signature provided");return JSON.parse(e.toString("utf8"))}catch(o){throw o instanceof R?o:new R(`Webhook payload parsing failed: ${o.message}`)}}};var De=typeof process!="undefined"&&"3.1.2"||"3.1.1";var ze,Le=(ze=We.default)!=null?ze:We,A=class{constructor(e){s(this,"client");s(this,"socket",null);s(this,"startSocket",null);s(this,"socketPromise",null);s(this,"socketQueue",[]);s(this,"clientCode");s(this,"apiVersion");s(this,"platform");s(this,"product");s(this,"infra");s(this,"webhooks");s(this,"lastSeq");s(this,"closed",!1);var g,h,x,k,d,qe,Ue,_e;let t=e.proxy;if(!e.apiKey&&!t)throw new T("API Key is required");this.clientCode=(g=e.clientCode)==null?void 0:g.toUpperCase(),this.apiVersion=(h=e.version)!=null?h:"v1";let r=(x=e.baseUrl)!=null?x:Pe,a=je(this.apiVersion,(k=t==null?void 0:t.url)!=null?k:r),o=e.socketUrl||r,c=typeof window!="undefined"&&typeof window.document!="undefined",l=c?"browser":typeof process!="undefined"?`node ${process.version}`:"unknown",p=c?((d=globalThis.navigator)==null?void 0:d.userAgent)||"browser":typeof process!="undefined"?process.platform:"unknown",y=b(u({},t?{}:{"x-api-key":e.apiKey,"x-client-code":((qe=e.clientCode)==null?void 0:qe.toUpperCase())||""}),{"Content-Type":"application/json","x-ecodrix-client-agent":JSON.stringify({sdk_version:De,runtime:l,os:p})});if(this.client=st.create({baseURL:a,headers:y,timeout:(Ue=e.timeout)!=null?Ue:3e4}),Le(this.client,{retries:3,retryDelay:Le.exponentialDelay,retryCondition:f=>{var L;return Le.isNetworkOrIdempotentRequestError(f)||((L=f.response)==null?void 0:L.status)===429},onRetry:(f,L,Ne)=>{var Be,Ve;typeof process!="undefined"&&((Be=process.env)==null?void 0:Be.NODE_ENV)==="development"&&console.warn(`[ECODrIx SDK] Retrying request (${f}/3): ${(Ve=Ne.method)==null?void 0:Ve.toUpperCase()} ${Ne.url}. Reason: ${L.message}`)}}),this.platform=new M(this.client),this.product=new $(this.client),this.infra=new O(this.client),this.webhooks=new D,t){if(t.ticket){let f=t.ticket;this.startSocket=()=>this.initSocket(o,async()=>({ticket:await f()}))}}else{let f={apiKey:e.apiKey,clientCode:((_e=e.clientCode)==null?void 0:_e.toUpperCase())||""};this.startSocket=()=>this.initSocket(o,async()=>f,{"x-api-key":f.apiKey,"x-client-code":f.clientCode})}if(c){let f={version:De,clientCode:e.clientCode,initializedAt:new Date().toISOString()};window.__ECODRIX_SDK__=f}}initSocket(e,t,r){return this.socketPromise?this.socketPromise:(this.socketPromise=import("socket.io-client").then(({io:a})=>{this.socket=a(e,{auth:o=>{t().then(c=>o(b(u({},c),{lastSeq:this.lastSeq})),()=>o({lastSeq:this.lastSeq}))},extraHeaders:r}),this.setupSocket();for(let{type:o,args:c}of this.socketQueue)o==="joinRoom"?this.socket.emit("join-room",c[0]):o==="leaveRoom"?this.socket.emit("leave-room",c[0]):o==="on"?this.socket.on(c[0],c[1]):o==="off"?this.socket.off(c[0],c[1]):o==="disconnect"&&this.socket.disconnect();this.socketQueue=[]}),this.socketPromise)}joinRoom(e){var t;this.closed||(t=this.startSocket)==null||t.call(this),this.socket?this.socket.emit("join-room",e):this.socketQueue.push({type:"joinRoom",args:[e]})}leaveRoom(e){this.socket?this.socket.emit("leave-room",e):this.socketQueue.push({type:"leaveRoom",args:[e]})}setupSocket(){this.socket&&(this.socket.on("connect_error",()=>{var e;(e=this.socket)!=null&&e.active||setTimeout(()=>{var t;this.closed||(t=this.socket)==null||t.connect()},5e3)}),this.socket.onAny((...e)=>{var r,a;let t=(r=e.at(-1))==null?void 0:r.seq;typeof t=="number"&&t>((a=this.lastSeq)!=null?a:0)&&(this.lastSeq=t)}))}on(e,t){var r;return this.closed||(r=this.startSocket)==null||r.call(this),this.socket?this.socket.on(e,t):this.socketQueue.push({type:"on",args:[e,t]}),this}disconnect(){this.closed=!0,this.socket?this.socket.disconnect():this.socketPromise&&this.socketQueue.push({type:"disconnect",args:[]})}off(e,t){return this.socket?this.socket.off(e,t):this.socketQueue.push({type:"off",args:[e,t]}),this}async request(e,t,r,a){var o,c,l;try{return(await this.client.request({method:e,url:t,data:r,params:a})).data}catch(p){throw p.response?new m(((o=p.response.data)==null?void 0:o.message)||((c=p.response.data)==null?void 0:c.error)||"Raw Execution Failed",p.response.status,(l=p.response.data)==null?void 0:l.code):new m(p.message||"Network Error")}}};var $r={401:T,403:v,429:w};function Or(n){throw q(n)}function Mr(n,e){return n instanceof e}function Dr(n){return n instanceof T?{message:n.message,status:n.status,code:n.code,type:"AuthenticationError"}:n instanceof w?{message:n.message,status:n.status,code:n.code,type:"RateLimitError"}:n instanceof m?{message:n.message,status:n.status,code:n.code,type:"APIError"}:{message:n.message||"Unknown error",type:"UnknownError"}}var Ge={[T.name]:{shouldRetry:!1,reason:"Authentication errors require fixing credentials, not retrying"},[w.name]:{shouldRetry:!0,maxRetries:3,baseDelay:1e3,backoffMultiplier:2,reason:"Rate limit errors can be retried with exponential backoff"},[m.name]:{shouldRetry:!0,maxRetries:2,baseDelay:500,backoffMultiplier:1.5,reason:"Generic API errors may be transient and worth retrying"}};function Lr(n){let e=n.constructor.name;return Ge[e]||Ge[m.name]}var _r=A;export{m as APIError,i as APIResource,E as AiAgent,T as AuthenticationError,Te as ConnectInfra,A as ECODrIx,A as ECODrIxAPI,Ge as ERROR_RETRY_CONFIG,Ae as EcodrixError,fe as EmailConnect,me as ErixChat,ye as ErixProduct,$r as HTTP_STATUS_ERROR_MAP,O as InfraDomain,nt as KNOWLEDGE_FILE_TYPES,C as Knowledge,He as LEAD_STATUS_VALUES,I as Onboarding,v as PermissionError,S as Persona,M as PlatformDomain,be as PlatformTenants,we as PlatformUsers,$ as ProductDomain,w as RateLimitError,xe as StorageInfra,R as WebhookSignatureError,D as Webhooks,he as WhatsAppConnect,_r as default,Dr as getErrorDetails,Lr as getRetryConfig,Or as handleAPIError,Mr as isAPIError,q as toAPIError};
1
+ import{a as l,b as y,d as i,e as Ue,f as Ne,g as _e,h as Be,i as Je,j as d,k as T,l as Ve,m as E,n as O}from"./chunk-XPXDFZWU.js";import Qe from"axios";import Ke from"axios-retry";var s=class{constructor(e){i(this,"client",e)}async post(e,t,n){try{let a=this.buildConfig(n);return(await this.client.post(e,t,a)).data}catch(a){this.handleError(a)}}async get(e,t){try{let n=this.buildConfig(t);return(await this.client.get(e,n)).data}catch(n){this.handleError(n)}}async patch(e,t,n){try{let a=this.buildConfig(n);return(await this.client.patch(e,t,a)).data}catch(a){this.handleError(a)}}async put(e,t,n){try{let a=this.buildConfig(n);return(await this.client.put(e,t,a)).data}catch(a){this.handleError(a)}}async deleteRequest(e,t){try{let n=this.buildConfig(t);return(await this.client.delete(e,n)).data}catch(n){this.handleError(n)}}buildConfig(e){if(!e)return;let t=l({},e);return e.idempotencyKey&&(t.headers=y(l({},t.headers),{"Idempotency-Key":e.idempotencyKey})),t}handleError(e){throw O(e)}};var Te=class extends s{async list(e){return this.get(`/product/erix/crm/leads/${e}/notes`)}async create(e,t){return this.post(`/product/erix/crm/leads/${e}/notes`,t)}async update(e,t){return this.patch(`/product/erix/crm/notes/${e}`,{content:t})}async pin(e,t=!0){return this.patch(`/product/erix/crm/notes/${e}/pin`,{isPinned:t})}async delete(e){return this.deleteRequest(`/product/erix/crm/notes/${e}`)}},M=class extends s{constructor(t){super(t);i(this,"notes");this.notes=new Te(t)}async timeline(t,n){return this.get(`/product/erix/crm/leads/${t}/timeline`,{params:n})}async list(t,n){return this.get(`/product/erix/crm/leads/${t}/activities`,{params:l({},n)})}async log(t){return this.post(`/product/erix/crm/leads/${t.leadId}/activities`,t)}async logCall(t,n){return this.post(`/product/erix/crm/leads/${t}/calls`,n)}};var D=class extends s{async overview(e){return this.get("/product/erix/crm/analytics/overview",{params:e})}async funnel(e){return this.get("/product/erix/crm/analytics/funnel",{params:{pipelineId:e}})}async forecast(e){return this.get("/product/erix/crm/analytics/forecast",{params:{pipelineId:e}})}async sources(e){return this.get("/product/erix/crm/analytics/sources",{params:e})}async team(e){return this.get("/product/erix/crm/analytics/team",{params:e})}async heatmap(e){return this.get("/product/erix/crm/analytics/heatmap",{params:e})}async scores(){return this.get("/product/erix/crm/analytics/scores")}async stageTime(e){return this.get("/product/erix/crm/analytics/stage-time",{params:{pipelineId:e}})}async tiered(e){return this.get("/product/erix/crm/analytics/tiered",{params:e})}async summary(e){return this.get("/product/erix/crm/analytics/summary",{params:e})}async whatsapp(e){return this.get("/product/erix/crm/analytics/whatsapp",{params:e})}async revenue(){return this.get("/product/erix/crm/analytics/revenue")}async health(){return this.get("/product/erix/crm/analytics/health")}async payments(){return this.get("/product/erix/crm/analytics/payments")}async reviews(){return this.get("/product/erix/crm/analytics/reviews")}async retention(){return this.get("/product/erix/crm/analytics/retention")}};var L=class extends s{async getChecklist(e){return this.get(`/product/erix/crm/documents/checklist/${e}`)}async createChecklist(e,t){return this.post(`/product/erix/crm/documents/checklist/${e}`,{templateNiche:t})}async markReceived(e,t,n){return this.patch(`/product/erix/crm/documents/checklist/${e}/${t}`,n?{fileUrl:n}:{})}async sendReminder(e){return this.post(`/product/erix/crm/documents/checklist/${e}/remind`)}async listIncomplete(){return this.get("/product/erix/crm/documents/checklist/incomplete")}async listTemplates(){return this.get("/product/erix/crm/documents/templates")}};var q=class extends s{async csv(e){return this.get("/product/erix/commerce/invoices/export/csv",{params:e})}async tally(e){return this.get("/product/erix/commerce/invoices/export/tally",{params:e})}async zoho(e){return this.get("/product/erix/commerce/invoices/export/zoho",{params:e})}};var Fe=["open","won","lost","archived"],U=class extends s{async create(e){return this.post("/product/erix/crm/leads",e)}async describe(){let e=await this.fields(),t=Array.isArray(e.data)?e.data:[],n=[{key:"firstName",label:"First Name",type:"string",required:!0,group:"Basic Info"},{key:"lastName",label:"Last Name",type:"string",required:!1,group:"Basic Info"},{key:"phone",label:"Phone Number",type:"phone",required:!0,group:"Contact"},{key:"email",label:"Email Address",type:"email",required:!1,group:"Contact"},{key:"status",label:"Status",type:"select",required:!0,options:Fe.map(o=>({label:`${o.charAt(0).toUpperCase()}${o.slice(1)}`,value:o}))},{key:"value",label:"Lead Value",type:"currency",required:!1},{key:"source",label:"Source",type:"string",required:!1}],a=t.map(o=>({key:`metadata.extra.${o.name}`,label:o.label||o.name,type:o.type||"string",required:!!o.required,options:o.options,group:"Custom Fields"}));return{name:"Lead",fields:[...n,...a],uiHints:{icon:"User",primaryColor:"#3b82f6",defaultSort:{field:"createdAt",direction:"desc"},summaryFields:["firstName","lastName","phone","status"]}}}async upsert(e){return this.post("/product/erix/crm/leads/upsert",e)}async createMany(e,t=50){let n=[];for(let a=0;a<e.length;a+=t){let c=e.slice(a,a+t).map(p=>this.create(p)),u=await Promise.allSettled(c);for(let p of u)if(p.status==="fulfilled")n.push(p.value);else throw p.reason}return n}async import(e){return this.post("/product/erix/crm/leads/import",{leads:e})}async bulkUpsert(e){return this.import(e)}async list(e){let t=l({},e);return Array.isArray(t.tags)&&(t.tags=t.tags.join(",")),this.get("/product/erix/crm/leads",{params:t})}listAutoPaging(e){return Ne(this,null,function*(){let t=(e==null?void 0:e.page)||1,n=!0;for(;n;){let a=yield new Ue(this.list(y(l({},e),{page:t}))),o=Array.isArray(a.data)?a.data:a||[];if(o.length===0){n=!1;break}for(let c of o)yield c;a.pagination&&t<a.pagination.pages||!a.pagination&&o.length>0?t++:n=!1}})}async retrieve(e){return this.get(`/product/erix/crm/leads/${e}`)}async retrieveByPhone(e){return this.get(`/product/erix/crm/leads/phone/${encodeURIComponent(e)}`)}async byStage(e,t,n={}){return this.get(`/product/erix/crm/pipelines/${e}/stages/${t}/leads`,{params:n})}async retrieveByRef(e,t){return this.get(`/product/erix/crm/leads/ref/${encodeURIComponent(e)}/${encodeURIComponent(t)}`)}async update(e,t){return this.patch(`/product/erix/crm/leads/${e}`,t)}async setFollowUp(e,t,n){return this.patch(`/product/erix/crm/leads/${e}`,{nextFollowUpAt:t,nextFollowUpNote:t&&n!=null?n:null})}async move(e,t){return this.patch(`/product/erix/crm/leads/${e}/move`,{stageId:t})}async convert(e,t,n){return this.post(`/product/erix/crm/leads/${e}/convert`,{outcome:t,reason:n})}async tags(e,t){return this.patch(`/product/erix/crm/leads/${e}/tags`,t)}async recalculateScore(e){return this.post(`/product/erix/crm/leads/${e}/score`,{})}async updateMetadata(e,t){return this.patch(`/product/erix/crm/leads/${e}/metadata`,t)}async fields(){return this.get("/product/erix/crm/fields")}async notes(e){return this.get(`/product/erix/crm/leads/${e}/notes`)}async activities(e,t){return this.get(`/product/erix/crm/leads/${e}/timeline`,{params:t})}async createNote(e,t){return this.post(`/product/erix/crm/leads/${e}/notes`,t)}async updateNote(e,t,n){return this.patch(`/product/erix/crm/notes/${t}`,n)}async deleteNote(e,t){return this.deleteRequest(`/product/erix/crm/notes/${t}`)}async delete(e){return this.deleteRequest(`/product/erix/crm/leads/${e}`)}async export(e){return this.get(`/product/erix/crm/leads/${encodeURIComponent(e)}/export`)}async erase(e){return this.post(`/product/erix/crm/leads/${encodeURIComponent(e)}/erase`,{confirm:"ERASE"})}async bulkArchive(e){return this.patch("/product/erix/crm/leads/bulk-archive",{ids:e})}async bulkDelete(e){return this.deleteRequest("/product/erix/crm/leads",{data:{ids:e}})}async archive(e){return this.deleteRequest(`/product/erix/crm/leads/${e}`)}async profile(e){return this.get(`/product/erix/crm/leads/${e}/profile`)}async invoices(e){return this.get(`/product/erix/crm/leads/${e}/invoices`)}async projects(e){return this.get(`/product/erix/crm/leads/${e}/projects`)}async conversations(e){return this.get(`/product/erix/crm/leads/${e}/conversations`)}async meetings(e){return this.get(`/product/erix/crm/leads/${e}/meetings`)}async flowRuns(e){return this.get(`/product/erix/crm/leads/${e}/flow-runs`)}async merge(e,t){return this.post("/product/erix/crm/leads/merge",{primaryId:e,secondaryId:t})}};var N=class extends s{async capture(e){return this.post("/product/erix/crm/payments/capture",e)}};var _=class extends s{async list(){return this.get("/product/erix/crm/pipelines")}async getStageManifest(e){var a,o;let t=await this.retrieve(e),n=Array.isArray((a=t.data)==null?void 0:a.stages)?t.data.stages:[];return{name:`Pipeline: ${((o=t.data)==null?void 0:o.name)||e}`,fields:n.map(c=>({key:c._id,label:c.name,type:"string",required:!0,options:[{label:c.name,value:c._id}],group:"Stages",uiHints:{color:c.color||"#cbd5e1",probability:c.probability}})),uiHints:{icon:"Columns",primaryColor:"#6366f1"}}}async create(e){return this.post("/product/erix/crm/pipelines",e)}async retrieve(e){return this.get(`/product/erix/crm/pipelines/${e}`)}async update(e,t){return this.patch(`/product/erix/crm/pipelines/${e}`,t)}async setDefault(e){return this.patch(`/product/erix/crm/pipelines/${e}/default`,{})}async duplicate(e,t){return this.post(`/product/erix/crm/pipelines/${e}/duplicate`,{name:t})}async archive(e){return this.patch(`/product/erix/crm/pipelines/${e}/archive`,{})}async delete(e){return this.deleteRequest(`/product/erix/crm/pipelines/${e}`)}async checkInUse(e){return this.get(`/product/erix/crm/pipelines/${e}/in-use`)}async board(e){return this.get(`/product/erix/crm/pipelines/${e}/board`)}async forecast(e){return this.get(`/product/erix/crm/pipelines/${e}/forecast`)}async addStage(e,t){return this.post(`/product/erix/crm/pipelines/${e}/stages`,t)}async reorderStages(e,t){return this.patch(`/product/erix/crm/pipelines/${e}/stages/reorder`,{order:t})}async updateStage(e,t){return this.patch(`/product/erix/crm/stages/${e}`,t)}async deleteStage(e,t){return this.deleteRequest(`/product/erix/crm/stages/${e}`,{data:t?{moveLeadsToStageId:t}:void 0})}};var B=class extends s{async getConfig(){return this.get("/product/erix/crm/scoring")}async updateConfig(e){return this.patch("/product/erix/crm/scoring",e)}async recalculate(e){return this.post(`/product/erix/crm/scoring/${e}/recalculate`,{})}async preview(e){return this.get(`/product/erix/crm/scoring/preview/${e}`)}};var V=class extends s{async list(e){return this.get("/platform/inbox/conversations",{params:e})}async create(e){var t;return this.post("/platform/inbox/conversations",{address:e.phone,channel:(t=e.channel)!=null?t:"whatsapp",userName:e.name})}async linkLead(e,t){return this.patch(`/platform/inbox/conversations/${e}/lead`,{leadId:t})}async retrieve(e){return this.get(`/platform/inbox/conversations/${e}`)}async messages(e,t){return this.get(`/platform/inbox/conversations/${e}/messages`,{params:t})}async markRead(e){return this.post(`/platform/inbox/conversations/${e}/read`,{})}async delete(e){return this.deleteRequest(`/platform/inbox/conversations/${e}`)}async bulkDelete(e){return this.post("/platform/inbox/conversations/bulk-delete",{ids:e})}};var b=class extends s{async send(e){if(e.conversationId)return this.post(`/platform/inbox/conversations/${e.conversationId}/messages`,{text:e.text,media:e.media});if(!e.to)throw new Error("send: conversationId or to is required");if(e.media)throw new Error("send: media goes to an inbox thread (conversationId)");return this.post("/infra/connect/send/whatsapp",{phone:e.to,text:e.text})}async sendTemplate(e){return this.post("/infra/connect/send/whatsapp",{phone:e.to,templateName:e.templateName,language:e.language,variables:e.variables})}async star(e,t){return this.post(`/platform/inbox/messages/${e}/star`,{starred:t})}async markRead(e){return this.post(`/platform/inbox/conversations/${e}/read`,{})}async upload(e,t={}){var f,m,w;let n=(m=(f=t.fileName)!=null?f:e.name)!=null?m:"file",a=e.type||"application/octet-stream",o=await this.post("/infra/storage/files/upload-url",{folder:(w=t.folder)!=null?w:"inbox",filename:n,contentType:a}),{uploadUrl:c,key:u}=o.data,p=await fetch(c,{method:"PUT",headers:{"Content-Type":a},body:e});if(!p.ok)throw new Error(`upload failed (${p.status})`);return await this.post("/infra/storage/files/confirm-upload",{key:u,sizeBytes:e.size}),{key:u,mimeType:a,fileName:n}}};var F=class extends s{async getProduct(e){return this.get(`/product/erix/commerce/checkout/products/${e}`)}async createSession(e){return this.post("/product/erix/commerce/checkout/session",e)}async applyCoupon(e){return this.post("/product/erix/commerce/checkout/coupon",e)}async verify(e){return this.post("/product/erix/commerce/checkout/verify",e)}async createOrder(e){return this.post("/product/erix/commerce/checkout/order",e)}};var K=class extends s{async trigger(e){return this.post("/product/erix/events/trigger",e)}async listCustomEvents(){return this.get("/product/flow/config/triggers")}async createCustomEvent(e){return this.post("/product/flow/config/triggers",e)}async deleteCustomEvent(e){return this.deleteRequest(`/product/flow/config/triggers/${e}`)}};var j=class extends s{async list(e){return this.get("/product/erix/commerce/invoices",{params:e})}async getInvoice(e){return this.get(`/product/erix/commerce/invoices/${e}`)}async create(e){return this.post("/product/erix/commerce/invoices",e)}async update(e,t){return this.patch(`/product/erix/commerce/invoices/${e}`,t)}async void(e){return this.post(`/product/erix/commerce/invoices/${e}/void`,{})}async sendViaWhatsApp(e){return this.post(`/product/erix/commerce/invoices/${e}/send-whatsapp`,{})}async getSettings(){return this.get("/product/erix/commerce/settings")}async updateSettings(e){return this.put("/product/erix/commerce/settings",e)}async paymentLink(e){return this.post(`/product/erix/commerce/invoices/${encodeURIComponent(e)}/payment-link`,{})}async recordPayment(e,t){return this.post(`/product/erix/commerce/invoices/${encodeURIComponent(e)}/payments`,t)}async sendWhatsApp(e){return this.post(`/product/erix/commerce/invoices/${encodeURIComponent(e)}/send-whatsapp`,{})}async sendEmail(e){return this.post(`/product/erix/commerce/invoices/${encodeURIComponent(e)}/send-email`,{})}};var W=class extends s{async workflowPacks(){return this.get("/product/erix/crm/niche/workflow-packs")}async workflowPackDetail(e){return this.get(`/product/erix/crm/niche/workflow-packs/${e}`)}async installWorkflowPack(e){return this.post(`/product/erix/crm/niche/workflow-packs/${e}/install`)}async templateSuggestions(){return this.get("/product/erix/crm/niche/template-suggestions")}};var H=class extends s{async list(e){return this.get(`/product/erix/commerce/projects/${e}/documents`)}async upload(e,t){return this.post(`/product/erix/commerce/projects/${e}/documents`,t)}async toggleSignature(e,t,n){return this.patch(`/product/erix/commerce/projects/${e}/documents/${t}/signature`,{required:n})}async addSigner(e,t,n){return this.post(`/product/erix/commerce/projects/${e}/documents/${t}/signers`,n)}async decline(e,t){return this.post(`/product/erix/commerce/projects/${e}/documents/${t}/decline`,{})}async stampSign(e,t,n){return this.post(`/product/erix/commerce/projects/${e}/documents/${t}/stamp-sign`,n)}};var z=class extends s{async providers(){return this.get("/infra/connect/providers")}async list(){return this.get("/infra/connect/connections")}async get_(e){return this.get(`/infra/connect/connections/${e}`)}async connect(e,t){return this.post(`/infra/connect/connections/${e}/connect`,t)}async configure(e,t){return this.put(`/infra/connect/connections/${e}/configure`,t)}async configureWebchat(e){return this.configure("webchat",{method:"domain",config:e})}async webchatSettings(){return this.get("/infra/connect/connections/webchat/settings")}async removeWebchatDomain(e){return this.deleteRequest(`/infra/connect/connections/webchat/domains/${encodeURIComponent(e)}`)}async disconnect(e){return this.post(`/infra/connect/connections/${e}/disconnect`,{})}async reveal(e){return this.post(`/infra/connect/connections/${e}/reveal`,{})}async test(e){return this.post(`/infra/connect/connections/${e}/test`,{})}async setAccess(e,t){return this.put(`/infra/connect/connections/${e}/access`,t)}async googleConnectUrl(){return this.post("/infra/connect/google/connect-url",{})}async createPaymentLink(e){return this.post("/infra/connect/connections/payments/payment-link",e)}};var G=class extends s{async sendTest(e){return this.post("/infra/connect/email/test",{to:e})}async listTemplates(e){return this.get("/infra/connect/email/templates",{params:e})}async getTemplate(e){return this.get(`/infra/connect/email/templates/${e}`)}async createTemplate(e){return this.post("/infra/connect/email/templates",e)}async updateTemplate(e,t){return this.put(`/infra/connect/email/templates/${e}`,t)}async deleteTemplate(e,t=!1){return this.deleteRequest(`/infra/connect/email/templates/${e}`,{params:{force:t}})}async previewTemplate(e,t){return this.post(`/infra/connect/email/templates/${e}/preview`,t)}};var Q=class extends s{async create(e){return this.post("/infra/connect/meet",e)}async list(e){return this.get("/infra/connect/meet",{params:e})}async retrieve(e){return this.get(`/infra/connect/meet/${e}`)}async update(e,t){return this.patch(`/infra/connect/meet/${e}`,t)}async reschedule(e,t){return this.patch(`/infra/connect/meet/${e}`,t)}async delete(e){return this.update(e,{status:"cancelled"})}};var Y=class extends s{async getConfig(){return this.get("/infra/connect/email/config")}async initDomainVerification(e){return this.post("/infra/connect/email/config/ses/domain",{domain:e})}async saveEmailConfig(e){return this.post("/infra/connect/email/config/ses/config",e)}async checkSesVerification(){return this.get("/infra/connect/email/config/ses/verify")}async removeSesIdentity(){return this.deleteRequest("/infra/connect/email/config/ses/domain")}async sendTest(e){return this.post("/infra/connect/email/config/test",{toEmail:e})}async saveAdvancedConfig(e){return this.post("/infra/connect/email/config/advanced",e)}async getHealth(){return this.get("/infra/connect/email/config/health")}async fixDmarc(){return this.post("/infra/connect/email/config/ses/fix-dmarc",{})}async listProviders(){return this.get("/infra/connect/email/config/providers")}};var J=class extends s{async list(e){return this.get("/infra/connect/whatsapp/templates",{params:e})}async sync(){return this.post("/infra/connect/whatsapp/templates/sync",{})}async retrieve(e){return this.get(`/infra/connect/whatsapp/templates/${encodeURIComponent(e)}`)}async create(e){return this.post("/infra/connect/whatsapp/templates",e)}async update(e,t){return this.put(`/infra/connect/whatsapp/templates/${e}`,t)}async deleteTemplate(e,t){return this.deleteRequest(`/infra/connect/whatsapp/templates/${encodeURIComponent(e)}${t?"?force=true":""}`)}async mappingConfig(){return this.get("/infra/connect/whatsapp/templates/mapping/config")}async mappingSources(){return this.get("/infra/connect/whatsapp/templates/mapping/sources")}async collections(){return this.get("/infra/connect/whatsapp/templates/collections")}async collectionFields(e){return this.get(`/infra/connect/whatsapp/templates/collections/${encodeURIComponent(e)}/fields`)}async updateMapping(e,t){return this.put(`/infra/connect/whatsapp/templates/${encodeURIComponent(e)}/mapping`,t)}async validate(e,t){let n=`/infra/connect/whatsapp/templates/${encodeURIComponent(e)}/validate`;return t?this.post(n,t):this.get(n)}async preview(e,t,n,a){return this.post(`/infra/connect/whatsapp/templates/${encodeURIComponent(e)}/preview`,{context:t,mappings:n,onEmptyVariable:a})}async getVariableManifest(e){var o,c;let t=await this.retrieve(e),n=Array.isArray((o=t.data)==null?void 0:o.components)?t.data.components:[],a=[];for(let u of n)if(u.text){let p=u.text.match(/{{(\d+)}}/g);if(p)for(let f of p){let m=f.replace(/{{|}}/g,"");a.push({key:`var_${m}`,label:`${u.type} Var {{${m}}}`,type:"string",required:!0,group:u.type,description:`Variable placeholder in template ${u.type}`})}}return{name:`Template variables: ${((c=t.data)==null?void 0:c.name)||e}`,fields:a,uiHints:{icon:"Variables",primaryColor:"#059669"}}}};import He from"axios";var X=class extends s{async getUsage(){return this.get("/infra/storage/files/usage")}async createFolder(e){return this.post("/infra/storage/files/folders",{name:e})}async list(e,t){return this.get(`/infra/storage/files/files/${e}`,{params:t})}async delete(e){return this.deleteRequest("/infra/storage/files/files",{params:{key:e}})}async getDownloadUrl(e){return this.post("/infra/storage/files/download-url",{key:e})}async aiDescribe(e){return this.post("/infra/storage/files/ai/describe",{key:e})}async upload(e,t){let n=await this.post("/infra/storage/files/upload-url",t),{uploadUrl:a,key:o}=n.data;await He.put(a,e,{headers:{"Content-Type":t.contentType}});let c=e.size||e.byteLength||0;return this.post("/infra/storage/files/confirm-upload",{key:o,sizeBytes:c})}};var Z=class extends s{async create(e){return this.post("/infra/storage/files/folders",{name:e})}},ee=class extends s{async list(e,t){return this.get(`/infra/storage/files/files/${e}`,{params:t})}async getUploadUrl(e){return this.post("/infra/storage/files/upload-url",e)}async confirmUpload(e){return this.post("/infra/storage/files/confirm-upload",e)}async getDownloadUrl(e){return this.post("/infra/storage/files/download-url",{key:e})}async delete(e){return this.deleteRequest("/infra/storage/files/files",{params:{key:e}})}};var te=class extends s{async system(){return(await this.get("/health")).data}};var ne=class extends s{async listAlerts(e){return this.get("/platform/users/notifications",{params:e})}async dismissAlert(e){return this.patch(`/platform/users/notifications/${e}/dismiss`)}async clearAllAlerts(){return this.deleteRequest("/platform/users/notifications/dismiss-all")}};var R=class extends s{async global(e){return this.post("/platform/tenants/onboarding/global",e)}async complete(e){return this.post("/platform/tenants/onboarding/complete",e)}};var k=class extends s{async get(e){return super.get(`/platform/tenants/persona/${e}`)}async reinforce(e){return this.post(`/platform/tenants/persona/${e.productId}/reinforce`,e)}async confidence(e){return super.get(`/platform/tenants/persona/${e}/confidence`,{params:{productId:e}})}async timeline(e,t){var a;let n=await super.get(`/platform/tenants/persona/${e}/timeline`,{params:t});return(a=n==null?void 0:n.data)!=null?a:{entries:[],hasMore:!1}}async followups(e){var n,a;let t=await super.get(`/platform/tenants/persona/${e}/followups`);return(a=(n=t==null?void 0:t.data)==null?void 0:n.entries)!=null?a:[]}};var be=class extends s{async chatSync(e){return this.post("/platform/ai/copilot/chat/sync",e)}async confirm(e){return this.post("/platform/ai/copilot/confirm",e)}async listSessions(){return this.get("/platform/ai/copilot/sessions")}async getSession(e){return this.get(`/platform/ai/copilot/sessions/${e}`)}async deleteSession(e){return this.deleteRequest(`/platform/ai/copilot/sessions/${e}`)}chatStreamUrl(){return"/platform/ai/copilot/chat"}},re=class{constructor(e){i(this,"copilot");this.copilot=new be(e)}};var ze=["application/pdf","application/vnd.openxmlformats-officedocument.wordprocessingml.document","text/plain","text/markdown","text/csv","text/html","image/png","image/jpeg","image/webp"],P=class extends s{async list(){return this.get("/platform/knowledge/sources")}async addText(e){return this.post("/platform/knowledge/sources",l({kind:"text"},e))}async addUrl(e){return this.post("/platform/knowledge/sources",l({kind:"url"},e))}async addWebsite(e){return this.post("/platform/knowledge/sources",{type:"website",url:e.url})}async addFile(e,t={}){var a,o;let n=await new b(this.client).upload(e,{folder:"knowledge"});return this.post("/platform/knowledge/sources",{kind:"file",key:n.key,mimeType:n.mimeType,title:(o=(a=t.title)!=null?a:n.fileName)!=null?o:"Document"})}async remove(e){return this.deleteRequest(`/platform/knowledge/sources/${e}`)}async reindex(e){return this.post(`/platform/knowledge/sources/${e}/reindex`,{})}async search(e,t){return this.post("/platform/knowledge/search",l({query:e},t?{limit:t}:{}))}};var A=class extends s{async settings(){return this.get("/product/erix/ai/settings")}async updateSettings(e){return this.patch("/product/erix/ai/settings",e)}async outcomes(e={}){return this.get("/product/erix/ai/outcomes",{params:e})}async reviews(e){return this.get(`/product/erix/ai/reviews${e?`?status=${e}`:""}`)}async review(e,t,n){return this.post(`/product/erix/ai/reviews/${encodeURIComponent(e)}`,l({verdict:t},n?{note:n}:{}))}async suggestion(e){return this.get(`/product/erix/ai/suggestion/${e}`)}async approveAction(e){return this.post(`/product/erix/ai/suggestion/${e}/approve-action`,{})}async markSent(e,t,n){return this.post(`/product/erix/ai/suggestion/${e}/send`,{text:t,confidence:n})}async dismiss(e){return this.post(`/product/erix/ai/suggestion/${e}/dismiss`,{})}async approvals(){return this.get("/product/flow/approvals")}async agents(){return this.get("/product/flow/agents")}async updateAgent(e,t){return this.patch(`/product/flow/agents/${encodeURIComponent(e)}`,t)}async decideRun(e,t,n){return this.post(`/product/flow/runs/${encodeURIComponent(e)}/approve`,l({decision:t},n&&{nodeId:n}))}};var se=class extends s{async register(e){return this.post("/platform/auth/register",e)}async login(e){return this.post("/platform/auth/login",e)}async logout(e){return this.post("/platform/auth/logout",e)}async logoutAll(e){return this.post("/platform/auth/logout-all",e)}async validateSession(e){return this.post("/platform/auth/session/validate",e)}async listSessions(){return this.get("/platform/auth/sessions")}async revokeSession(e){return this.deleteRequest(`/platform/auth/sessions/${e}`)}async requestPasswordOtp(e){return this.post("/platform/auth/password/request-otp",e)}async setPassword(e){return this.post("/platform/auth/password/set",e)}async changePassword(e){return this.post("/platform/auth/password/change",e)}async forgotPassword(e){return this.post("/platform/auth/forgot",e)}async resetPassword(e){return this.post("/platform/auth/reset",e)}async linkOAuth(e){return this.post("/platform/auth/oauth-link",e)}async getInvitation(e){return this.get(`/platform/auth/invitations/${e}`)}async acceptInvitation(e,t){return this.post(`/platform/auth/invitations/${e}/accept`,t)}};var xe=class extends s{async get(){return super.get("/platform/billing/entitlements/entitlements")}async usage(){return super.get("/platform/billing/entitlements/usage")}},we=class extends s{async upgrade(e){return this.post("/platform/billing/subscriptions/subscriptions/upgrade",e)}async downgrade(e){return this.post("/platform/billing/subscriptions/subscriptions/downgrade",e)}async cancel(e){return this.post("/platform/billing/subscriptions/subscriptions/cancel",e)}async purchaseAddon(e){return this.post("/platform/billing/subscriptions/addons/purchase",e)}async cancelAddon(e){return this.post("/platform/billing/subscriptions/addons/cancel",e)}},Re=class extends s{async listPublic(){return this.get("/platform/billing/plans/public")}},ke=class extends s{async plans(){return this.get("/platform/billing/checkout/plans")}async subscribe(e){return this.post("/platform/billing/checkout/subscribe",e)}async verify(e){return this.post("/platform/billing/checkout/verify",e)}async cancel(e){return this.post("/platform/billing/checkout/cancel",e)}async status(){return this.get("/platform/billing/checkout/status")}async syncPlan(e){return this.post("/platform/billing/checkout/sync-plan",e)}},Pe=class extends s{async transactions(){return this.get("/platform/billing/user/transactions")}async transactionInvoice(e){return this.get(`/platform/billing/user/transactions/${encodeURIComponent(e)}/invoice`)}async subscription(){return this.get("/platform/billing/user/subscription")}async raiseDispute(e){return this.post("/platform/billing/user/dispute",e)}async disputes(){return this.get("/platform/billing/user/disputes")}},Ae=class extends s{async balance(){return this.get("/platform/billing/credits/balance")}async transactions(){return this.get("/platform/billing/credits/transactions")}async packs(){return this.get("/platform/billing/credits/packs")}async topupOrder(e){return this.post("/platform/billing/credits/topup/order",e)}async verifyTopup(e){return this.post("/platform/billing/credits/topup/verify",e)}async setAutoTopup(e){return this.patch("/platform/billing/credits/auto-topup",e)}async setSpendCap(e){return this.patch("/platform/billing/credits/spend-cap",e)}},ie=class{constructor(e){i(this,"entitlements");i(this,"subscriptions");i(this,"plans");i(this,"checkout");i(this,"user");i(this,"credits");this.entitlements=new xe(e),this.subscriptions=new we(e),this.plans=new Re(e),this.checkout=new ke(e),this.user=new Pe(e),this.credits=new Ae(e)}};var ae=class extends s{async categories(){return this.get("/platform/support/categories")}async listTickets(e){return this.get("/platform/support/tickets",{params:e})}async createTicket(e){return this.post("/platform/support/tickets",e)}async getTicket(e){return this.get(`/platform/support/tickets/${e}`)}async reply(e,t){return this.post(`/platform/support/tickets/${e}/reply`,t)}async close(e){return this.patch(`/platform/support/tickets/${e}/close`,{})}};var oe=class extends s{async get(){return super.get("/platform/users/me")}async update(e){return this.patch("/platform/users/me",e)}async updateOrganization(e){return this.patch("/platform/users/me/organization",e)}async toggleModules(e){return this.post("/platform/users/me/modules",e)}async workspaces(){return super.get("/platform/users/me/workspaces")}async setActiveOrg(e){return this.post("/platform/users/me/active-org",e)}async dismissWorkspaceSetup(){return this.post("/platform/users/me/workspace/dismiss-setup",{})}},ce=class extends s{async list(){return this.get("/platform/users/members")}async invite(e){return this.post("/platform/users/members/invite",e)}async updateRole(e,t){return this.patch(`/platform/users/members/${e}`,{role:t})}async remove(e){return this.deleteRequest(`/platform/users/members/${e}`)}},pe=class extends s{async list(){return this.get("/platform/auth/sessions")}async revoke(e){return this.deleteRequest(`/platform/auth/sessions/${e}`)}};var le=class{constructor(e){i(this,"messages");i(this,"conversations");this.messages=new b(e),this.conversations=new V(e)}},ue=class{constructor(e){i(this,"leads");i(this,"pipelines");i(this,"activities");i(this,"analytics");i(this,"scoring");i(this,"payments");i(this,"chat");i(this,"events");i(this,"invoices");i(this,"checkout");i(this,"projects");i(this,"niche");i(this,"documents");i(this,"invoiceExport");i(this,"ai");this.leads=new U(e),this.pipelines=new _(e),this.activities=new M(e),this.analytics=new D(e),this.scoring=new B(e),this.payments=new N(e),this.chat=new le(e),this.events=new K(e),this.invoices=new j(e),this.checkout=new F(e),this.projects=new H(e),this.niche=new W(e),this.documents=new L(e),this.invoiceExport=new q(e),this.ai=new A(e)}},v=class{constructor(e){i(this,"erix");this.erix=new ue(e)}},ge=class{constructor(e){i(this,"config");i(this,"templates");this.config=new Y(e),this.templates=new G(e)}},de=class{constructor(e){i(this,"templates");this.templates=new J(e)}},me=class{constructor(e){i(this,"email");i(this,"whatsapp");i(this,"meet");i(this,"connections");this.email=new ge(e),this.whatsapp=new de(e),this.meet=new Q(e),this.connections=new z(e)}},ye=class{constructor(e){i(this,"files");i(this,"folders");i(this,"media");this.files=new ee(e),this.folders=new Z(e),this.media=new X(e)}},I=class{constructor(e){i(this,"connect");i(this,"storage");this.connect=new me(e),this.storage=new ye(e)}},he=class{constructor(e){i(this,"onboarding");i(this,"persona");this.onboarding=new R(e),this.persona=new k(e)}},fe=class{constructor(e){i(this,"me");i(this,"members");i(this,"sessions");i(this,"notifications");this.me=new oe(e),this.members=new ce(e),this.sessions=new pe(e),this.notifications=new ne(e)}},S=class{constructor(e){i(this,"auth");i(this,"users");i(this,"tenants");i(this,"billing");i(this,"support");i(this,"ai");i(this,"knowledge");i(this,"health");this.auth=new se(e),this.users=new fe(e),this.tenants=new he(e),this.billing=new ie(e),this.support=new ae(e),this.ai=new re(e),this.knowledge=new P(e),this.health=new te(e)}};var h=class extends d{constructor(e){super(e,400,"invalid_signature"),this.name="WebhookSignatureError"}},C=class{async constructEvent(e,t,n){if(!t)throw new h("No webhook signature provided");let a=Array.isArray(t)?t[0]:t;a.startsWith("sha256=")&&(a=a.slice(7));try{let o=await import("crypto"),u=o.createHmac("sha256",n).update(e).digest("hex");if(!o.timingSafeEqual(Buffer.from(u),Buffer.from(a)))throw new h("Invalid webhook signature provided");return JSON.parse(e.toString("utf8"))}catch(o){throw o instanceof h?o:new h(`Webhook payload parsing failed: ${o.message}`)}}};var ve=typeof process!="undefined"&&"3.3.0"||"3.1.1";var je,Ie=(je=Ke.default)!=null?je:Ke,x=class{constructor(e){i(this,"client");i(this,"socket",null);i(this,"startSocket",null);i(this,"socketPromise",null);i(this,"socketQueue",[]);i(this,"clientCode");i(this,"apiVersion");i(this,"platform");i(this,"product");i(this,"infra");i(this,"webhooks");i(this,"lastSeq");i(this,"closed",!1);var m,w,Se,Ce,$e,Ee,Oe,Me;let t=e.proxy;if(!e.apiKey&&!t)throw new T("API Key is required");this.clientCode=(m=e.clientCode)==null?void 0:m.toUpperCase(),this.apiVersion=(w=e.version)!=null?w:"v1";let n=(Se=e.baseUrl)!=null?Se:_e,a=Be(this.apiVersion,(Ce=t==null?void 0:t.url)!=null?Ce:n),o=e.socketUrl||n,c=typeof window!="undefined"&&typeof window.document!="undefined",u=c?"browser":typeof process!="undefined"?`node ${process.version}`:"unknown",p=c?(($e=globalThis.navigator)==null?void 0:$e.userAgent)||"browser":typeof process!="undefined"?process.platform:"unknown",f=y(l({},t?{}:{"x-api-key":e.apiKey,"x-client-code":((Ee=e.clientCode)==null?void 0:Ee.toUpperCase())||""}),{"Content-Type":"application/json","x-ecodrix-client-agent":JSON.stringify({sdk_version:ve,runtime:u,os:p})});if(this.client=Qe.create({baseURL:a,headers:f,timeout:(Oe=e.timeout)!=null?Oe:3e4}),Ie(this.client,{retries:3,retryDelay:Ie.exponentialDelay,retryCondition:g=>{var $;return Ie.isNetworkOrIdempotentRequestError(g)||(($=g.response)==null?void 0:$.status)===429},onRetry:(g,$,De)=>{var Le,qe;typeof process!="undefined"&&((Le=process.env)==null?void 0:Le.NODE_ENV)==="development"&&console.warn(`[ECODrIx SDK] Retrying request (${g}/3): ${(qe=De.method)==null?void 0:qe.toUpperCase()} ${De.url}. Reason: ${$.message}`)}}),this.platform=new S(this.client),this.product=new v(this.client),this.infra=new I(this.client),this.webhooks=new C,t){if(t.ticket){let g=t.ticket;this.startSocket=()=>this.initSocket(o,async()=>({ticket:await g()}))}}else{let g={apiKey:e.apiKey,clientCode:((Me=e.clientCode)==null?void 0:Me.toUpperCase())||""};this.startSocket=()=>this.initSocket(o,async()=>g,{"x-api-key":g.apiKey,"x-client-code":g.clientCode})}if(c){let g={version:ve,clientCode:e.clientCode,initializedAt:new Date().toISOString()};window.__ECODRIX_SDK__=g}}initSocket(e,t,n){return this.socketPromise?this.socketPromise:(this.socketPromise=import("socket.io-client").then(({io:a})=>{this.socket=a(e,{auth:o=>{t().then(c=>o(y(l({},c),{lastSeq:this.lastSeq})),()=>o({lastSeq:this.lastSeq}))},extraHeaders:n}),this.setupSocket();for(let{type:o,args:c}of this.socketQueue)o==="joinRoom"?this.socket.emit("join-room",c[0]):o==="leaveRoom"?this.socket.emit("leave-room",c[0]):o==="on"?this.socket.on(c[0],c[1]):o==="off"?this.socket.off(c[0],c[1]):o==="disconnect"&&this.socket.disconnect();this.socketQueue=[]}),this.socketPromise)}joinRoom(e){var t;this.closed||(t=this.startSocket)==null||t.call(this),this.socket?this.socket.emit("join-room",e):this.socketQueue.push({type:"joinRoom",args:[e]})}leaveRoom(e){this.socket?this.socket.emit("leave-room",e):this.socketQueue.push({type:"leaveRoom",args:[e]})}setupSocket(){this.socket&&(this.socket.on("connect_error",()=>{var e;(e=this.socket)!=null&&e.active||setTimeout(()=>{var t;this.closed||(t=this.socket)==null||t.connect()},5e3)}),this.socket.onAny((...e)=>{var n,a;let t=(n=e.at(-1))==null?void 0:n.seq;typeof t=="number"&&t>((a=this.lastSeq)!=null?a:0)&&(this.lastSeq=t)}))}on(e,t){var n;return this.closed||(n=this.startSocket)==null||n.call(this),this.socket?this.socket.on(e,t):this.socketQueue.push({type:"on",args:[e,t]}),this}disconnect(){this.closed=!0,this.socket?this.socket.disconnect():this.socketPromise&&this.socketQueue.push({type:"disconnect",args:[]})}off(e,t){return this.socket?this.socket.off(e,t):this.socketQueue.push({type:"off",args:[e,t]}),this}async request(e,t,n,a){var o,c,u;try{return(await this.client.request({method:e,url:t,data:n,params:a})).data}catch(p){throw p.response?new d(((o=p.response.data)==null?void 0:o.message)||((c=p.response.data)==null?void 0:c.error)||"Raw Execution Failed",p.response.status,(u=p.response.data)==null?void 0:u.code):new d(p.message||"Network Error")}}};var br={401:T,403:Ve,429:E};function xr(r){throw O(r)}function wr(r,e){return r instanceof e}function Rr(r){return r instanceof T?{message:r.message,status:r.status,code:r.code,type:"AuthenticationError"}:r instanceof E?{message:r.message,status:r.status,code:r.code,type:"RateLimitError"}:r instanceof d?{message:r.message,status:r.status,code:r.code,type:"APIError"}:{message:r.message||"Unknown error",type:"UnknownError"}}var We={[T.name]:{shouldRetry:!1,reason:"Authentication errors require fixing credentials, not retrying"},[E.name]:{shouldRetry:!0,maxRetries:3,baseDelay:1e3,backoffMultiplier:2,reason:"Rate limit errors can be retried with exponential backoff"},[d.name]:{shouldRetry:!0,maxRetries:2,baseDelay:500,backoffMultiplier:1.5,reason:"Generic API errors may be transient and worth retrying"}};function kr(r){let e=r.constructor.name;return We[e]||We[d.name]}var vr=x;export{d as APIError,s as APIResource,A as AiAgent,T as AuthenticationError,me as ConnectInfra,x as ECODrIx,x as ECODrIxAPI,We as ERROR_RETRY_CONFIG,Je as EcodrixError,ge as EmailConnect,le as ErixChat,ue as ErixProduct,br as HTTP_STATUS_ERROR_MAP,I as InfraDomain,ze as KNOWLEDGE_FILE_TYPES,P as Knowledge,Fe as LEAD_STATUS_VALUES,R as Onboarding,Ve as PermissionError,k as Persona,S as PlatformDomain,he as PlatformTenants,fe as PlatformUsers,v as ProductDomain,E as RateLimitError,ye as StorageInfra,h as WebhookSignatureError,C as Webhooks,de as WhatsAppConnect,vr as default,Rr as getErrorDetails,kr as getRetryConfig,xr as handleAPIError,wr as isAPIError,O as toAPIError};
@@ -0,0 +1,163 @@
1
+ import { V as VisitorMessage, d as VisitorTyping, f as VisitorStatus, A as APIError, e as WebchatSettings } from './error-Bl2AN2QP.js';
2
+ export { g as VisitorMessageStatus, W as WebchatSettingsPatch } from './error-Bl2AN2QP.js';
3
+
4
+ /**
5
+ * @module visitor
6
+ * @responsibility `@ecodrix/erix-api/visitor` — the anonymous website-chat
7
+ * visitor client. No API key and no workspace data: a visitor reads and
8
+ * writes only their own thread, identified by their session id. Uses `fetch`
9
+ * for HTTP and loads `socket.io-client` only when `connect()` is called, so a
10
+ * chat widget doesn't ship the full SDK (no axios on this path).
11
+ *
12
+ * Every import here must stay free of axios: the subpath's whole point is a
13
+ * small bundle (checked by `visitor.test.ts` and `scripts/smoke-dist.mjs`).
14
+ */
15
+
16
+ /** The widget's look, as a visitor reads it (no domains, no staff-name switch). */
17
+ type WebchatWidget = Omit<WebchatSettings, "allowedDomains" | "showStaffNames">;
18
+ /**
19
+ * Why a visitor call failed. Server codes, plus `NETWORK_ERROR` when no
20
+ * answer came back (offline, timed out): only that one and `INTERNAL_ERROR`
21
+ * are worth an immediate "Try again".
22
+ */
23
+ type WebchatErrorCode = "VALIDATION_ERROR" | "NOT_FOUND" | "ORIGIN_NOT_ALLOWED" | "RATE_LIMITED" | "INTERNAL_ERROR" | "MALICIOUS_INPUT" | "NETWORK_ERROR";
24
+ /**
25
+ * A failed visitor call or a refused live connection. `status` is the HTTP
26
+ * status (absent for network and socket errors); `field` names the input a
27
+ * `VALIDATION_ERROR` is about (`text`, `name`, `phone`, `email`, …) and
28
+ * `message` is copy the visitor can read.
29
+ */
30
+ declare class WebchatVisitorError extends APIError {
31
+ code: WebchatErrorCode;
32
+ field?: string;
33
+ constructor(message: string, code: WebchatErrorCode, status?: number, field?: string);
34
+ }
35
+ interface WebchatVisitorOptions {
36
+ /** API host, scheme and domain only. Default `https://api.ecodrix.com`. */
37
+ apiUrl?: string;
38
+ /** The workspace's public client code (from the embed snippet). */
39
+ clientCode: string;
40
+ /**
41
+ * The visitor's id and only secret: random, 20–80 characters of
42
+ * `A-Z a-z 0-9 _ -` (e.g. `crypto.randomUUID()`). Keep it for the visitor's
43
+ * next visit to continue the same thread.
44
+ */
45
+ sessionId: string;
46
+ /** The origin of the site the chat runs on, checked against the workspace's allowed domains. */
47
+ parent: string;
48
+ }
49
+ /** The page the visitor is on. Query string and hash are dropped before sending. */
50
+ interface VisitorPage {
51
+ /** Starts with `/`, up to 200 characters. */
52
+ path: string;
53
+ /** Up to 120 characters. */
54
+ title?: string;
55
+ }
56
+ interface VisitorSendOptions {
57
+ /**
58
+ * Your id for this message, 8–64 characters of `A-Z a-z 0-9 _ -`. Resend
59
+ * with the same id after a failure: it's stored (and answered) once.
60
+ */
61
+ messageId?: string;
62
+ /** The visitor's name, if known. */
63
+ name?: string;
64
+ page?: VisitorPage;
65
+ }
66
+ /** The visitor's details (name plus a phone or an email). */
67
+ interface VisitorContact {
68
+ name: string;
69
+ phone?: string;
70
+ email?: string;
71
+ /** Ticked the consent box (shown only when `messages()` returned `consentNotice`). */
72
+ consent?: boolean;
73
+ }
74
+ /** `messages()`: the thread, the widget's look, and the consent notice when the workspace has a privacy link. */
75
+ interface VisitorThread {
76
+ success: boolean;
77
+ data: VisitorMessage[];
78
+ widget: WebchatWidget;
79
+ consentNotice?: string;
80
+ privacyPolicyUrl?: string;
81
+ }
82
+ /** `send()`: the stored message, or `{ duplicate: true }` when a resent `messageId` was already stored. */
83
+ interface VisitorSendResult {
84
+ success: boolean;
85
+ data: VisitorMessage | {
86
+ duplicate: true;
87
+ };
88
+ }
89
+ /** `receipts()`: the replies whose ticks moved (already there, or not this visitor's, are left out). */
90
+ interface VisitorReceiptsResult {
91
+ success: boolean;
92
+ data: {
93
+ updated: string[];
94
+ };
95
+ }
96
+ interface VisitorLiveHandlers {
97
+ /** A new message on the thread (team, AI or system; also the visitor's own). */
98
+ onMessage?: (message: VisitorMessage) => void;
99
+ onTyping?: (typing: VisitorTyping) => void;
100
+ /** The visitor's messages moved on: `{ ids, status: "read" }` once the team opened the chat. */
101
+ onStatus?: (status: VisitorStatus) => void;
102
+ /**
103
+ * The live connection failed or was refused. Fall back to polling
104
+ * `messages()` until `onReconnect`. Network drops retry on their own;
105
+ * `RATE_LIMITED` and `INTERNAL_ERROR` refusals retry after a minute; other
106
+ * refusals (`ORIGIN_NOT_ALLOWED`, `NOT_FOUND`, `VALIDATION_ERROR`) don't.
107
+ */
108
+ onError?: (error: WebchatVisitorError) => void;
109
+ /**
110
+ * Live again after a drop or a refusal. Nothing missed in between is
111
+ * replayed: call `messages()` now.
112
+ */
113
+ onReconnect?: () => void;
114
+ }
115
+ /**
116
+ * One website visitor's chat with a workspace: send, read, leave contact
117
+ * details, and get replies live.
118
+ *
119
+ * @example
120
+ * ```ts
121
+ * import { WebchatVisitor } from "@ecodrix/erix-api/visitor";
122
+ *
123
+ * const chat = new WebchatVisitor({ clientCode: "ERIX_CLNT_XXXXXX", sessionId, parent: location.origin });
124
+ * const { data: thread, widget } = await chat.messages();
125
+ * await chat.send("Do you open on Sunday?", { messageId: crypto.randomUUID() });
126
+ * chat.connect({ onMessage: (m) => render(m), onReconnect: () => chat.messages().then(redraw) });
127
+ * ```
128
+ */
129
+ declare class WebchatVisitor {
130
+ private readonly options;
131
+ private readonly host;
132
+ private readonly base;
133
+ private socket;
134
+ private opening;
135
+ private retry;
136
+ constructor(options: WebchatVisitorOptions);
137
+ /** Send the visitor's message. */
138
+ send(text: string, opts?: VisitorSendOptions): Promise<VisitorSendResult>;
139
+ /** The visitor's thread, oldest first, with the widget's look. */
140
+ messages(): Promise<VisitorThread>;
141
+ /**
142
+ * Tell the business its replies reached the visitor (`delivered`: the chat
143
+ * got them) or were seen (`read`: the chat was open and on screen). Up to 50
144
+ * reply ids per call; ticks only move forward, and ids that aren't this
145
+ * visitor's replies are ignored.
146
+ */
147
+ receipts(ids: string[], state: "delivered" | "read"): Promise<VisitorReceiptsResult>;
148
+ /** Save the visitor's details and link the thread to a contact. */
149
+ contact(details: VisitorContact): Promise<{
150
+ success: boolean;
151
+ }>;
152
+ /**
153
+ * Get replies, typing and read ticks live over the `/visitor` socket. Only works inside
154
+ * the ERIX widget frame: the server refuses sockets opened from other
155
+ * origins, so a chat UI on your own page polls `messages()` instead.
156
+ */
157
+ connect(handlers: VisitorLiveHandlers): Promise<void>;
158
+ /** Close the live connection. `connect()` again to reopen. */
159
+ disconnect(): void;
160
+ private call;
161
+ }
162
+
163
+ export { type VisitorContact, type VisitorLiveHandlers, VisitorMessage, type VisitorPage, type VisitorReceiptsResult, type VisitorSendOptions, type VisitorSendResult, VisitorStatus, type VisitorThread, VisitorTyping, type WebchatErrorCode, WebchatSettings, WebchatVisitor, WebchatVisitorError, type WebchatVisitorOptions, type WebchatWidget };
@@ -0,0 +1 @@
1
+ import{a as R,b as T,c as d,d as p,g as h,h as O,j as f}from"./chunk-XPXDFZWU.js";var u=class extends f{constructor(i,n,c,s){super(i,c,n);p(this,"field");this.name="WebchatVisitorError",this.field=s}},S=3e4,y=6e4,_=new Set(["RATE_LIMITED","INTERNAL_ERROR"]),N={400:"VALIDATION_ERROR",403:"ORIGIN_NOT_ALLOWED",404:"NOT_FOUND",429:"RATE_LIMITED"},V=class{constructor(t){p(this,"options",t);p(this,"host");p(this,"base");p(this,"socket",null);p(this,"opening",null);p(this,"retry");var i;this.host=((i=t.apiUrl)!=null?i:h).replace(/\/+$/,""),this.base=`${O("v1",this.host)}/infra/connect/webhooks/webchat/${encodeURIComponent(t.clientCode)}`}send(t,i={}){let{sessionId:n,parent:c}=this.options,e=i,{page:s}=e,a=d(e,["page"]);return this.call("/message",R(R({sessionId:n,text:t,parent:c},a),s&&{page:T(R({},s),{path:s.path.split(/[?#]/)[0]})}))}messages(){let{sessionId:t,parent:i}=this.options;return this.call(`/messages?${new URLSearchParams({sessionId:t,parent:i})}`)}receipts(t,i){let{sessionId:n,parent:c}=this.options;return this.call("/receipts",{sessionId:n,parent:c,ids:t,state:i})}contact(t){let{sessionId:i,parent:n}=this.options;return this.call("/contact",R({sessionId:i,parent:n},t))}connect(t){if(this.opening)return this.opening;let{clientCode:i,sessionId:n,parent:c}=this.options,s=import("socket.io-client").then(({io:a})=>{if(this.opening!==s)return;let e=a(`${this.host}/visitor`,{auth:{clientCode:i,sessionId:n,parent:c}});this.socket=e;let g=!1;e.on("connect",()=>{var r;g&&((r=t.onReconnect)==null||r.call(t)),g=!1}),e.on("disconnect",()=>{g=!0}),e.on("connect_error",r=>{var l,E,m;g=!0;let o=(E=(l=r.data)==null?void 0:l.code)!=null?E:"NETWORK_ERROR";(m=t.onError)==null||m.call(t,new u(r.message,o)),!e.active&&_.has(o)&&(clearTimeout(this.retry),this.retry=setTimeout(()=>{this.socket===e&&e.connect()},y))}),e.on("webchat.message",r=>{var o;return(o=t.onMessage)==null?void 0:o.call(t,r)}),e.on("webchat.typing",r=>{var o;return(o=t.onTyping)==null?void 0:o.call(t,r)}),e.on("webchat.status",r=>{var o;return(o=t.onStatus)==null?void 0:o.call(t,r)})},a=>{var e;this.opening===s&&(this.opening=null,(e=t.onError)==null||e.call(t,new u((a==null?void 0:a.message)||"Network error","NETWORK_ERROR")))});return this.opening=s,s}disconnect(){var t;clearTimeout(this.retry),(t=this.socket)==null||t.disconnect(),this.socket=null,this.opening=null}async call(t,i){var g,r;let n=new AbortController,c=setTimeout(()=>n.abort(),S),s,a;try{s=await fetch(`${this.base}${t}`,{method:i?"POST":"GET",headers:i?{"content-type":"application/json"}:void 0,body:i?JSON.stringify(i):void 0,signal:n.signal}),a=await s.text()}catch(o){throw new u((o==null?void 0:o.message)||"Network error","NETWORK_ERROR")}finally{clearTimeout(c)}let e=null;try{e=JSON.parse(a)}catch(o){}if(s.ok&&(e!=null&&e.success))return e;throw new u((e==null?void 0:e.message)||(e==null?void 0:e.error)||`Request failed (${s.status})`,(r=(g=e==null?void 0:e.code)!=null?g:N[s.status])!=null?r:"INTERNAL_ERROR",s.status,e==null?void 0:e.field)}};export{V as WebchatVisitor,u as WebchatVisitorError};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ecodrix/erix-api",
3
- "version": "3.1.2",
3
+ "version": "3.3.0",
4
4
  "author": "ECODrIx Team <contact@ecodrix.com>",
5
5
  "license": "MIT",
6
6
  "description": "Official TypeScript SDK for the ERIX API by ECODrIx: CRM, Flow automations, one inbox across WhatsApp, Instagram and email, GST invoices and payments. Node and browser (proxy mode).",
@@ -33,6 +33,11 @@
33
33
  "types": "./dist/ts/esm/index.d.ts",
34
34
  "import": "./dist/ts/esm/index.js",
35
35
  "require": "./dist/ts/cjs/index.cjs"
36
+ },
37
+ "./visitor": {
38
+ "types": "./dist/ts/esm/visitor.d.ts",
39
+ "import": "./dist/ts/esm/visitor.js",
40
+ "require": "./dist/ts/cjs/visitor.cjs"
36
41
  }
37
42
  },
38
43
  "files": [