@ecodrix/erix-api 1.4.3 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +8 -8
- package/dist/ts/cjs/index.cjs +1 -1
- package/dist/ts/esm/index.d.ts +2424 -8
- package/dist/ts/esm/index.js +1 -1
- package/package.json +1 -1
package/dist/ts/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var xe=Object.defineProperty,Pe=Object.defineProperties;var we=Object.getOwnPropertyDescriptors;var fe=Object.getOwnPropertySymbols;var Re=Object.prototype.hasOwnProperty,ke=Object.prototype.propertyIsEnumerable;var Ce=(s,e)=>(e=Symbol[s])?e:Symbol.for("Symbol."+s);var se=(s,e,t)=>e in s?xe(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,T=(s,e)=>{for(var t in e||(e={}))Re.call(e,t)&&se(s,t,e[t]);if(fe)for(var t of fe(e))ke.call(e,t)&&se(s,t,e[t]);return s},x=(s,e)=>Pe(s,we(e));var i=(s,e,t)=>se(s,typeof e!="symbol"?e+"":e,t);var ae=function(s,e){this[0]=s,this[1]=e},be=(s,e,t)=>{var a=(l,p,d,y)=>{try{var v=t[l](p),h=(p=v.value)instanceof ae,b=v.done;Promise.resolve(h?p[0]:p).then(u=>h?a(l==="return"?l:"next",p[1]?{done:u.done,value:u.value}:u,d,y):d({value:u,done:b})).catch(u=>a("throw",u,d,y))}catch(u){y(u)}},r=(l,p,d,y)=>c[l]=v=>(p=new Promise((h,b,u)=>(u=()=>a(l,v,h,b),o?o.then(u):u())),y=()=>o===d&&(o=0),o=d=p.then(y,y),p),o,c={};return t=t.apply(s,e),c[Ce("asyncIterator")]=()=>c,r("next"),r("throw"),r("return"),c};import $e from"axios";import de from"axios-retry";var ne=class extends Error{constructor(e){super(e),this.name="EcodrixError"}},g=class extends ne{constructor(t,a,r){super(t);i(this,"status");i(this,"code");this.name="APIError",this.status=a,this.code=r}},m=class extends g{constructor(e="Invalid API Key or Client Code"){super(e,401,"AUTH_FAILED"),this.name="AuthenticationError"}},f=class extends g{constructor(e="Too many requests. Please slow down."){super(e,429,"RATE_LIMIT_EXCEEDED"),this.name="RateLimitError"}};var n=class{constructor(e){i(this,"client",e)}async post(e,t,a){try{let r=this.buildConfig(a);return(await this.client.post(e,t,r)).data}catch(r){this.handleError(r)}}async get(e,t){try{let a=this.buildConfig(t);return(await this.client.get(e,a)).data}catch(a){this.handleError(a)}}async patch(e,t,a){try{let r=this.buildConfig(a);return(await this.client.patch(e,t,r)).data}catch(r){this.handleError(r)}}async put(e,t,a){try{let r=this.buildConfig(a);return(await this.client.put(e,t,r)).data}catch(r){this.handleError(r)}}async deleteRequest(e,t){try{let a=this.buildConfig(t);return(await this.client.delete(e,a)).data}catch(a){this.handleError(a)}}buildConfig(e){if(!e)return;let t=T({},e);return e.idempotencyKey&&(t.headers=x(T({},t.headers),{"Idempotency-Key":e.idempotencyKey})),t}handleError(e){var t,a,r;if(e.response){let o=e.response.status,c=((t=e.response.data)==null?void 0:t.message)||((a=e.response.data)==null?void 0:a.error)||"API Request Failed",l=(r=e.response.data)==null?void 0:r.code;switch(o){case 401:throw new m(c);case 403:throw new m(c);case 429:throw new f(c);default:throw new g(c,o,l)}}throw new g(e.message||"Network Error")}};var R=class extends n{async listBlueprints(){return this.get("/api/agency/blueprints")}async createBlueprint(e){return this.post("/api/agency/blueprints",e)}async deployBlueprint(e){return this.post("/api/agency/blueprints/deploy",e)}async getPortfolioStats(e){return this.get(`/api/agency/portfolio/${e}/stats`)}async getPortfolioHealth(e){return this.get(`/api/agency/portfolio/${e}/health`)}async getUsage(e){return this.get(`/api/agency/usage/${e}`)}async listStaff(e){return this.get(`/api/agency/staff/${e}`)}async createStaff(e){return this.post("/api/agency/staff",e)}};var k=class extends n{async getProduct(e){return this.get(`/api/v1/checkout/products/${e}`)}async createSession(e){return this.post("/api/v1/checkout/session",e)}async applyCoupon(e){return this.post("/api/v1/checkout/coupon",e)}async verify(e){return this.post("/api/v1/checkout/verify",e)}async createOrder(e){return this.post("/api/v1/checkout/order",e)}};var C=class extends n{async providers(){return this.get("/api/connect/v1/providers")}async list(){return this.get("/api/connect/v1/connections")}async get_(e){return this.get(`/api/connect/v1/connections/${e}`)}async connect(e,t){return this.post(`/api/connect/v1/connections/${e}/connect`,t)}async configure(e,t){return this.put(`/api/connect/v1/connections/${e}/configure`,t)}async disconnect(e){return this.post(`/api/connect/v1/connections/${e}/disconnect`,{})}async reveal(e){return this.post(`/api/connect/v1/connections/${e}/reveal`,{})}async setAccess(e,t){return this.put(`/api/connect/v1/connections/${e}/access`,t)}};var A=class extends n{async list(){return this.get("/api/saas/cors")}async create(e){return this.post("/api/saas/cors",e)}async update(e,t){return this.patch(`/api/saas/cors/${e}`,t)}async delete(e){return this.deleteRequest(`/api/saas/cors/${e}`)}};var re=class extends n{async list(e){return this.get(`/api/crm/leads/${e}/notes`)}async create(e,t){return this.post(`/api/crm/leads/${e}/notes`,t)}async update(e,t){return this.patch(`/api/crm/notes/${e}`,{content:t})}async pin(e,t=!0){return this.patch(`/api/crm/notes/${e}/pin`,{isPinned:t})}async delete(e){return this.deleteRequest(`/api/crm/notes/${e}`)}},$=class extends n{constructor(t){super(t);i(this,"notes");this.notes=new re(t)}async timeline(t,a){return this.get(`/api/crm/leads/${t}/timeline`,{params:a})}async list(t,a){return this.get(`/api/crm/leads/${t}/activities`,{params:T({},a)})}async log(t){return this.post(`/api/crm/leads/${t.leadId}/activities`,t)}async logCall(t,a){return this.post(`/api/crm/leads/${t}/calls`,a)}};var I=class extends n{async overview(e){return this.get("/api/crm/analytics/overview",{params:e})}async funnel(e){return this.get("/api/crm/analytics/funnel",{params:{pipelineId:e}})}async forecast(e){return this.get("/api/crm/analytics/forecast",{params:{pipelineId:e}})}async sources(e){return this.get("/api/crm/analytics/sources",{params:e})}async team(e){return this.get("/api/crm/analytics/team",{params:e})}async heatmap(e){return this.get("/api/crm/analytics/heatmap",{params:e})}async scores(){return this.get("/api/crm/analytics/scores")}async stageTime(e){return this.get("/api/crm/analytics/stage-time",{params:{pipelineId:e}})}async tiered(e){return this.get("/api/crm/analytics/tiered",{params:e})}async summary(e){return this.get("/api/crm/analytics/summary",{params:e})}async whatsapp(e){return this.get("/api/crm/analytics/whatsapp",{params:e})}};var E=class extends n{async stats(){return this.get("/api/crm/automation/stats")}async logs(e){return this.get("/api/crm/automation/logs",{params:e})}async retryFailedEvent(e){return this.post(`/api/crm/automation/logs/${e}/retry`,{})}};var S=class extends n{async list(){return this.get("/api/crm/automations")}async create(e){return this.post("/api/crm/automations",e)}async update(e,t){return this.patch(`/api/crm/automations/${e}`,t)}async toggle(e){return this.patch(`/api/crm/automations/${e}/toggle`)}async delete(e){return this.deleteRequest(`/api/crm/automations/${e}`)}async bulkDelete(e){return this.post("/api/crm/automations/bulk-delete",{ids:e})}async test(e,t){return this.post(`/api/crm/automations/${e}/test`,{leadId:t})}async getAvailableEvents(){return this.post("/api/crm/automations/events",{})}async enrollments(e,t){return this.get(`/api/crm/automations/${e}/enrollments`,{params:t})}async getEnrollment(e){return this.get(`/api/crm/automations/enrollments/${e}`)}async pauseEnrollment(e,t){return this.post(`/api/crm/automations/${e}/enrollments/${t}/pause`,{})}async resumeEnrollment(e,t){return this.post(`/api/crm/automations/${e}/enrollments/${t}/resume`,{})}async runs(e){return this.get(`/api/crm/automations/${e}/runs`)}async getRun(e){return this.get(`/api/crm/automations/runs/${e}`)}async resumeRun(e){return this.post(`/api/crm/automations/runs/${e}/resume`,{})}async abortRun(e){return this.post(`/api/crm/automations/runs/${e}/abort`,{})}async webhookEvent(e,t,a){return this.post("/api/crm/automations/webhook-event",{ruleId:e,eventName:t,payload:a})}async trigger(e){return this.post("/api/saas/workflows/trigger",e)}};var L=class extends n{async create(e){return this.post("/api/crm/leads",e)}async describe(){let e=await this.fields(),t=Array.isArray(e.data)?e.data:[],a=[{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:[{label:"New",value:"new"},{label:"Contacted",value:"contacted"},{label:"Qualified",value:"qualified"},{label:"Won",value:"won"},{label:"Lost",value:"lost"}]},{key:"value",label:"Lead Value",type:"currency",required:!1},{key:"source",label:"Source",type:"string",required:!1}],r=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:[...a,...r],uiHints:{icon:"User",primaryColor:"#3b82f6",defaultSort:{field:"createdAt",direction:"desc"},summaryFields:["firstName","lastName","phone","status"]}}}async upsert(e){return this.post("/api/crm/leads/upsert",e)}async createMany(e,t=50){let a=[];for(let r=0;r<e.length;r+=t){let c=e.slice(r,r+t).map(p=>this.create(p)),l=await Promise.allSettled(c);for(let p of l)if(p.status==="fulfilled")a.push(p.value);else throw p.reason}return a}async import(e){return this.post("/api/crm/leads/import",{leads:e})}async bulkUpsert(e){return this.import(e)}async list(e){let t=T({},e);return Array.isArray(t.tags)&&(t.tags=t.tags.join(",")),this.get("/api/crm/leads",{params:t})}listAutoPaging(e){return be(this,null,function*(){let t=(e==null?void 0:e.page)||1,a=!0;for(;a;){let r=yield new ae(this.list(x(T({},e),{page:t}))),o=Array.isArray(r.data)?r.data:r||[];if(o.length===0){a=!1;break}for(let c of o)yield c;r.pagination&&t<r.pagination.pages||!r.pagination&&o.length>0?t++:a=!1}})}async retrieve(e){return this.get(`/api/crm/leads/${e}`)}async retrieveByPhone(e){return this.get(`/api/crm/leads/phone/${encodeURIComponent(e)}`)}async byStage(e,t,a={}){return this.get(`/api/crm/pipelines/${e}/stages/${t}/leads`,{params:a})}async retrieveByRef(e,t){return this.get(`/api/crm/leads/ref/${encodeURIComponent(e)}/${encodeURIComponent(t)}`)}async update(e,t){return this.patch(`/api/crm/leads/${e}`,t)}async move(e,t){return this.patch(`/api/crm/leads/${e}/move`,{stageId:t})}async convert(e,t,a){return this.post(`/api/crm/leads/${e}/convert`,{outcome:t,reason:a})}async tags(e,t){return this.patch(`/api/crm/leads/${e}/tags`,t)}async recalculateScore(e){return this.post(`/api/crm/leads/${e}/score`,{})}async updateMetadata(e,t){return this.patch(`/api/crm/leads/${e}/metadata`,t)}async fields(){return this.get("/api/crm/leads/fields")}async notes(e){return this.get(`/api/crm/leads/${e}/notes`)}async activities(e,t){return this.get(`/api/crm/leads/${e}/timeline`,{params:t})}async createNote(e,t){return this.post(`/api/crm/leads/${e}/notes`,t)}async updateNote(e,t,a){return this.patch(`/api/crm/notes/${t}`,a)}async deleteNote(e,t){return this.deleteRequest(`/api/crm/notes/${t}`)}async delete(e){return this.deleteRequest(`/api/crm/leads/${e}`)}async bulkArchive(e){return this.patch("/api/crm/leads/bulk-archive",{ids:e})}async bulkDelete(e){return this.deleteRequest("/api/crm/leads",{data:{ids:e}})}async archive(e){return this.patch(`/api/crm/leads/${e}/archive`,{})}};var q=class extends n{async capture(e){return this.post("/api/crm/payments/capture",e)}};var D=class extends n{async list(){return this.get("/api/crm/pipelines")}async getStageManifest(e){var r,o;let t=await this.retrieve(e),a=Array.isArray((r=t.data)==null?void 0:r.stages)?t.data.stages:[];return{name:`Pipeline: ${((o=t.data)==null?void 0:o.name)||e}`,fields:a.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("/api/crm/pipelines",e)}async retrieve(e){return this.get(`/api/crm/pipelines/${e}`)}async update(e,t){return this.patch(`/api/crm/pipelines/${e}`,t)}async setDefault(e){return this.patch(`/api/crm/pipelines/${e}/default`,{})}async duplicate(e,t){return this.post(`/api/crm/pipelines/${e}/duplicate`,{newName:t})}async archive(e){return this.patch(`/api/crm/pipelines/${e}/archive`,{})}async delete(e){return this.deleteRequest(`/api/crm/pipelines/${e}`)}async checkInUse(e){return this.get(`/api/crm/pipelines/${e}/in-use`)}async board(e){return this.get(`/api/crm/pipelines/${e}/board`)}async forecast(e){return this.get(`/api/crm/pipelines/${e}/forecast`)}async addStage(e,t){return this.post(`/api/crm/pipelines/${e}/stages`,t)}async reorderStages(e,t){return this.patch(`/api/crm/pipelines/${e}/stages/reorder`,{order:t})}async updateStage(e,t){return this.patch(`/api/crm/stages/${e}`,t)}async deleteStage(e,t){return this.deleteRequest(`/api/crm/stages/${e}`,{data:t?{moveLeadsToStageId:t}:void 0})}};var U=class extends n{async getConfig(){return this.get("/api/crm/scoring")}async updateConfig(e){return this.patch("/api/crm/scoring",e)}async recalculate(e){return this.post(`/api/crm/scoring/${e}/recalculate`,{})}};var M=class extends n{async enroll(e){return this.post("/api/crm/sequences/enroll",e)}async unenroll(e){return this.deleteRequest(`/api/crm/sequences/unenroll/${e}`)}async listForLead(e){return this.get(`/api/crm/sequences/lead/${e}`)}};var O=class{constructor(e){i(this,"leads");i(this,"pipelines");i(this,"activities");i(this,"analytics");i(this,"automations");i(this,"sequences");i(this,"scoring");i(this,"payments");i(this,"automationDashboard");this.leads=new L(e),this.pipelines=new D(e),this.activities=new $(e),this.analytics=new I(e),this.automations=new S(e),this.sequences=new M(e),this.scoring=new U(e),this.payments=new q(e),this.automationDashboard=new E(e)}};var N=class extends n{async sendCampaign(e){return this.post("/api/saas/marketing/emails/campaign",e)}async sendTest(e){return this.post("/api/saas/marketing/emails/test",{to:e})}async listTemplates(e){return this.get("/api/saas/marketing/mail/templates",{params:e})}async getTemplate(e){return this.get(`/api/saas/marketing/mail/templates/${e}`)}async createTemplate(e){return this.post("/api/saas/marketing/mail/templates",e)}async updateTemplate(e,t){return this.put(`/api/saas/marketing/mail/templates/${e}`,t)}async deleteTemplate(e,t=!1){return this.deleteRequest(`/api/saas/marketing/mail/templates/${e}`,{params:{force:t}})}async previewTemplate(e,t){return this.post(`/api/saas/marketing/mail/templates/${e}/preview`,t)}};var _=class extends n{async list(){return this.get("/api/saas/events")}async assign(e){return this.post("/api/saas/events/assign",e)}async unassign(e){return this.post("/api/saas/events/unassign",{name:e})}async unassignBulk(e){return this.post("/api/saas/events/unassign/bulk",{names:e})}async trigger(e){return this.post("/api/saas/workflows/trigger",e)}async listCustomEvents(){return this.get("/api/saas/crm/custom-events")}async createCustomEvent(e){return this.post("/api/saas/crm/custom-events",e)}async deleteCustomEvent(e){return this.deleteRequest(`/api/saas/crm/custom-events/${e}`)}async emit(e){return this.post("/api/crm/events/emit",e)}};var B=class extends n{async system(){return(await this.get("/api/saas/health")).data}async clientHealth(){return(await this.get("/api/saas/health/client")).data}async getDiagnosticReport(){return this.clientHealth()}async jobStatus(e){return(await this.get(`/api/saas/jobs/status/${e}`)).data}};var H=class extends n{async listEventLogs(e){return this.get("/api/saas/events/logs",{params:e})}async getEventLog(e){return this.get(`/api/saas/events/logs/${e}`)}async listCallbackLogs(e){return this.get("/api/saas/callbacks/logs",{params:e})}async getStats(){return this.get("/api/saas/events/stats")}};var ie=class extends n{async sendCampaign(e){return this.post("/api/saas/marketing/emails/campaign",e)}async sendTest(e){return this.post("/api/saas/marketing/emails/test",{to:e})}},oe=class extends n{async list(e){return this.get("/api/saas/marketing/emails/campaigns",{params:e})}async stats(e){return this.get(`/api/saas/marketing/emails/campaigns/${e}/analytics`)}},ce=class extends n{async sendTemplate(e){return this.post("/api/saas/marketing/whatsapp/send-template",e)}},F=class extends n{constructor(t){super(t);i(this,"emails");i(this,"campaigns");i(this,"whatsapp");this.emails=new ie(t),this.campaigns=new oe(t),this.whatsapp=new ce(t)}};import Ae from"axios";var j=class extends n{async getUsage(){return this.get("/api/saas/storage/usage")}async createFolder(e){return this.post("/api/saas/storage/folders",{name:e})}async list(e,t){return this.get(`/api/saas/storage/files/${e}`,{params:t})}async delete(e){return this.deleteRequest("/api/saas/storage/files",{params:{key:e}})}async getDownloadUrl(e){return this.post("/api/saas/storage/download-url",{key:e})}async aiDescribe(e){return this.post("/api/saas/storage/ai/describe",{key:e})}async upload(e,t){let a=await this.post("/api/saas/storage/upload-url",t),{uploadUrl:r,key:o}=a.data;await Ae.put(r,e,{headers:{"Content-Type":t.contentType}});let c=e.size||e.byteLength||0;return this.post("/api/saas/storage/confirm-upload",{key:o,sizeBytes:c})}};var K=class extends n{async create(e){return this.post("/api/saas/meet",e)}async list(e){return this.get("/api/saas/meet",{params:e})}async retrieve(e){return this.get(`/api/saas/meet/${e}`)}async update(e,t){return this.patch(`/api/saas/meet/${e}`,t)}async reschedule(e,t){return this.patch(`/api/saas/meet/${e}`,t)}async delete(e){return this.update(e,{status:"cancelled"})}};var V=class extends n{async listLogs(e){return this.get("/api/saas/events/logs",{params:e})}async retrieveLog(e){return this.get(`/api/saas/events/logs/${e}`)}async getStats(e){return this.get("/api/saas/events/stats",{params:e})}async listCallbacks(e){return this.get("/api/saas/callbacks/logs",{params:e})}async listAlerts(e){return this.get("/api/crm/notifications",{params:e})}async dismissAlert(e){return this.patch(`/api/crm/notifications/${e}/dismiss`)}async clearAllAlerts(){return this.deleteRequest("/api/crm/notifications/clear-all")}async retryAction(e){return this.post(`/api/crm/notifications/${e}/retry`,{})}};var Q=class extends n{async listFailed(){return this.get("/api/saas/admin/queue/failed")}async getStats(){return this.get("/api/saas/admin/queue/stats")}async retryJob(e){return this.post(`/api/saas/admin/queue/${e}/retry`,{})}async deleteJob(e){return this.deleteRequest(`/api/saas/admin/queue/${e}`)}};var pe=class extends n{async list(){return this.get("/api/clients")}async getCountAndGenerateCode(){return this.get("/api/clients/count")}async retrieve(e){return this.get(`/api/clients/${e}`)}async getApiKey(e){return this.get(`/api/clients/${e}/api-key`)}async rotateApiKey(e){return this.post(`/api/clients/${e}/api-key`,{})}async create(e){return this.post("/api/clients",e)}async getConfig(e){return this.get(`/api/clients/${e}/config`)}async updateConfig(e,t){return this.patch(`/api/clients/${e}/config`,t)}async getConnections(e){return this.get(`/api/clients/${e}/connections`)}async getConnectProviders(e){return this.get(`/api/clients/${e}/connections/providers`)}async connectProvider(e,t,a){return this.post(`/api/clients/${e}/connections/${t}/connect`,a)}async configureProvider(e,t,a){return this.put(`/api/clients/${e}/connections/${t}/configure`,a)}async disconnectProvider(e,t){return this.post(`/api/clients/${e}/connections/${t}/disconnect`,{})}async revealConnection(e,t){return this.post(`/api/clients/${e}/connections/${t}/reveal`,{})}async setConnectionAccess(e,t,a){return this.put(`/api/clients/${e}/connections/${t}/access`,a)}async getDataSource(e){return this.get(`/api/clients/${e}/datasource`)}async manageDataSource(e,t){return this.post(`/api/clients/${e}/datasource`,t)}async updateIdentity(e,t){return this.patch(`/api/clients/${e}/identity`,t)}async googleReauth(e,t={}){return this.post(`/api/clients/${e}/google/reauth`,t)}async delete(e){return this.deleteRequest(`/api/clients/${e}`)}},le=class extends n{async list(){return this.get("/api/services/blogs")}},ge=class extends n{async add(e){return this.post("/api/services/add-lead",e)}},J=class extends n{constructor(t){super(t);i(this,"clients");i(this,"blogs");i(this,"globalLeads");this.clients=new pe(t),this.blogs=new le(t),this.globalLeads=new ge(t)}};var ue=class extends n{async getConfig(){return this.get("/api/settings/email")}async switchProvider(e){return this.post("/api/settings/email/provider",{provider:e})}async saveSmtp(e){return this.post("/api/settings/email/smtp",e)}async initDomainVerification(e){return this.post("/api/settings/email/ses/domain",{domain:e})}async saveEmailConfig(e){return this.post("/api/settings/email/ses/config",e)}async checkSesVerification(){return this.get("/api/settings/email/ses/verify")}async removeSesIdentity(){return this.deleteRequest("/api/settings/email/ses/domain")}async sendTest(e){return this.post("/api/settings/email/test",{toEmail:e})}async saveAdvancedConfig(e){return this.post("/api/settings/email/advanced",e)}async getHealth(){return this.get("/api/settings/email/health")}async fixDmarc(){return this.post("/api/settings/email/ses/fix-dmarc",{})}async listProviders(){return this.get("/api/settings/email/providers")}},W=class extends n{constructor(t){super(t);i(this,"email");this.email=new ue(t)}};var me=class extends n{async create(e){return this.post("/api/saas/storage/folders",{name:e})}async delete(e){return this.deleteRequest(`/api/saas/storage/folders/${encodeURIComponent(e)}`)}},ye=class extends n{async list(e,t){return this.get(`/api/saas/storage/files/${e}`,{params:t})}async getUploadUrl(e){return this.post("/api/saas/storage/upload-url",e)}async confirmUpload(e){return this.post("/api/saas/storage/confirm-upload",e)}async getDownloadUrl(e){return this.post("/api/saas/storage/download-url",{key:e})}async delete(e){return this.deleteRequest("/api/saas/storage/files",{params:{key:e}})}},G=class extends n{constructor(t){super(t);i(this,"folders");i(this,"files");this.folders=new me(t),this.files=new ye(t)}async usage(){return this.get("/api/saas/storage/usage")}};var P=class extends g{constructor(e){super(e,400,"invalid_signature"),this.name="WebhookSignatureError"}},z=class{async constructEvent(e,t,a){if(!t)throw new P("No webhook signature provided");let r=Array.isArray(t)?t[0]:t;r.startsWith("sha256=")&&(r=r.slice(7));try{let o=await import("crypto"),l=o.createHmac("sha256",a).update(e).digest("hex");if(!o.timingSafeEqual(Buffer.from(l),Buffer.from(r)))throw new P("Invalid webhook signature provided");return JSON.parse(e.toString("utf8"))}catch(o){throw o instanceof P?o:new P(`Webhook payload parsing failed: ${o.message}`)}}};var X=class extends n{async list(e){return this.get("/api/saas/chat/broadcasts",{params:e})}async retrieve(e){return this.get(`/api/saas/chat/broadcasts/${e}`)}async create(e){return this.post("/api/saas/chat/broadcast",e)}async update(e,t){return this.patch(`/api/saas/chat/broadcasts/${e}`,t)}async delete(e){return this.deleteRequest(`/api/saas/chat/broadcasts/${e}`)}};var Y=class extends n{async list(e){return this.get("/api/saas/chat/conversations",{params:e})}async create(e){return this.post("/api/saas/chat/conversations",e)}async retrieve(e){return this.get(`/api/saas/chat/conversations/${e}`)}async messages(e,t){return this.get(`/api/saas/chat/conversations/${e}/messages`,{params:t})}async linkLead(e,t,a){return this.post(`/api/saas/chat/conversations/${e}/link-lead`,{leadId:t,leadData:a})}async markRead(e){return this.post(`/api/saas/chat/conversations/${e}/read`,{})}async delete(e){return this.deleteRequest(`/api/saas/chat/conversations/${e}`)}async bulkDelete(e){return this.post("/api/saas/chat/conversations/bulk-delete",{ids:e})}};var Z=class extends n{async send(e){return this.post("/api/saas/chat/send",e)}async sendTemplate(e){return this.post("/api/saas/chat/send",x(T({},e),{templateLanguage:e.language||e.templateLanguage||"en_US"}))}async star(e,t){return this.post(`/api/saas/chat/messages/${e}/star`,{isStarred:t})}async react(e,t){return this.post(`/api/saas/chat/messages/${e}/react`,{reaction:t})}async markRead(e){return this.post(`/api/saas/chat/conversations/${e}/read`)}async upload(e){let t=new FormData;return t.append("file",e),this.post("/api/saas/chat/upload",t,{headers:{"Content-Type":"multipart/form-data"}})}};var ee=class extends n{async list(e){return this.get("/api/saas/chat/templates",{params:e})}async sync(){return this.post("/api/saas/chat/templates/sync",{})}async retrieve(e){return this.get(`/api/saas/chat/templates/${encodeURIComponent(e)}`)}async create(e){return this.post("/api/saas/chat/templates",e)}async update(e,t){return this.put(`/api/saas/chat/templates/${e}`,t)}async deleteTemplate(e,t){return this.deleteRequest(`/api/saas/chat/templates/${encodeURIComponent(e)}${t?"?force=true":""}`)}async mappingConfig(){return this.get("/api/saas/chat/templates/mapping/config")}async collections(){return this.get("/api/saas/chat/templates/collections")}async collectionFields(e){return this.get(`/api/saas/chat/templates/collections/${encodeURIComponent(e)}/fields`)}async updateMapping(e,t){return this.put(`/api/saas/chat/templates/${encodeURIComponent(e)}/mapping`,t)}async validate(e){return this.get(`/api/saas/chat/templates/${encodeURIComponent(e)}/validate`)}async preview(e,t){return this.post(`/api/saas/chat/templates/${encodeURIComponent(e)}/preview`,{context:t})}async getVariableManifest(e){var o,c;let t=await this.retrieve(e),a=Array.isArray((o=t.data)==null?void 0:o.components)?t.data.components:[],r=[];for(let l of a)if(l.text){let p=l.text.match(/{{(\d+)}}/g);if(p)for(let d of p){let y=d.replace(/{{|}}/g,"");r.push({key:`var_${y}`,label:`${l.type} Var {{${y}}}`,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:r,uiHints:{icon:"Variables",primaryColor:"#059669"}}}async checkUsage(e){return this.get(`/api/saas/chat/templates/${encodeURIComponent(e)}/usage`)}};var te=class extends n{constructor(t){super(t);i(this,"messages");i(this,"conversations");i(this,"broadcasts");i(this,"templates");this.messages=new Z(t),this.conversations=new Y(t),this.broadcasts=new X(t),this.templates=new ee(t)}async upload(t,a){let r=new FormData;return r.append("file",t,a),this.post("/api/saas/chat/upload",r,{headers:typeof r.getHeaders=="function"?r.getHeaders():void 0})}async sendTemplate(t){return this.post("/api/saas/marketing/whatsapp/send-template",t)}};var Ie="https://api.ecodrix.com",w=class{constructor(e){i(this,"client");i(this,"socket",null);i(this,"socketPromise",null);i(this,"socketQueue",[]);i(this,"clientCode");i(this,"whatsapp");i(this,"crm");i(this,"media");i(this,"meet");i(this,"notifications");i(this,"email");i(this,"logs");i(this,"events");i(this,"webhooks");i(this,"storage");i(this,"marketing");i(this,"health");i(this,"queue");i(this,"agency");i(this,"services");i(this,"settings");i(this,"cors");i(this,"checkout");i(this,"connect");var p,d,y,v;if(!e.apiKey)throw new m("API Key is required");this.clientCode=(p=e.clientCode)==null?void 0:p.toUpperCase();let t=(d=e.baseUrl)!=null?d:Ie,a=e.socketUrl||t,r=typeof window!="undefined"&&typeof window.document!="undefined",o=r?"browser":typeof process!="undefined"?`node ${process.version}`:"unknown",c=r?((y=globalThis.navigator)==null?void 0:y.userAgent)||"browser":typeof process!="undefined"?process.platform:"unknown",l={"x-api-key":e.apiKey,"x-client-code":((v=e.clientCode)==null?void 0:v.toUpperCase())||"","Content-Type":"application/json","x-ecodrix-client-agent":JSON.stringify({sdk_version:"1.0.0",runtime:o,os:c})};if(e.coreApiKey&&(l["x-core-api-key"]=e.coreApiKey),this.client=$e.create({baseURL:t,headers:l}),de(this.client,{retries:3,retryDelay:de.exponentialDelay,retryCondition:h=>{var b;return de.isNetworkOrIdempotentRequestError(h)||((b=h.response)==null?void 0:b.status)===429},onRetry:(h,b,u)=>{var he,Te;typeof process!="undefined"&&((he=process.env)==null?void 0:he.NODE_ENV)==="development"&&console.warn(`[ECODrIx SDK] Retrying request (${h}/3): ${(Te=u.method)==null?void 0:Te.toUpperCase()} ${u.url}. Reason: ${b.message}`)}}),this.whatsapp=new te(this.client),this.crm=new O(this.client),this.media=new j(this.client),this.meet=new K(this.client),this.notifications=new V(this.client),this.email=new N(this.client),this.logs=new H(this.client),this.events=new _(this.client),this.webhooks=new z,this.storage=new G(this.client),this.marketing=new F(this.client),this.health=new B(this.client),this.queue=new Q(this.client),this.agency=new R(this.client),this.services=new J(this.client),this.settings=new W(this.client),this.cors=new A(this.client),this.checkout=new k(this.client),this.connect=new C(this.client),this.initSocket(a,e.apiKey,e.clientCode),r){let h={version:"1.2.2",clientCode:e.clientCode,initializedAt:new Date().toISOString()};window.__ECODRIX_SDK__=h,window.ecodrix||(window.ecodrix=this)}}initSocket(e,t,a){return this.socketPromise?this.socketPromise:(this.socketPromise=import("socket.io-client").then(({io:r})=>{this.socket=r(e,{extraHeaders:{"x-api-key":t,"x-client-code":(a==null?void 0:a.toUpperCase())||""}}),this.setupSocket(a);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){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(e){this.socket&&this.socket.on("connect",()=>{e&&this.socket.emit("join-room",e.toUpperCase())})}on(e,t){return this.socket?this.socket.on(e,t):this.socketQueue.push({type:"on",args:[e,t]}),this}disconnect(){this.socket?this.socket.disconnect():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,a,r){var o,c,l;try{return(await this.client.request({method:e,url:t,data:a,params:r})).data}catch(p){throw p.response?new g(((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 g(p.message||"Network Error")}}};var Ee={401:m,403:m,429:f};function Hs(s){var e,t,a;if(s.response){let r=s.response.status,o=((e=s.response.data)==null?void 0:e.message)||((t=s.response.data)==null?void 0:t.error)||"API Request Failed",c=(a=s.response.data)==null?void 0:a.code,l=Ee[r]||g;throw l===m?new m(o):l===f?new f(o):new g(o,r,c)}throw new g(s.message||"Network Error")}function Fs(s,e){return s instanceof e}function js(s){return s instanceof m?{message:s.message,status:s.status,code:s.code,type:"AuthenticationError"}:s instanceof f?{message:s.message,status:s.status,code:s.code,type:"RateLimitError"}:s instanceof g?{message:s.message,status:s.status,code:s.code,type:"APIError"}:{message:s.message||"Unknown error",type:"UnknownError"}}var ve={[m.name]:{shouldRetry:!1,reason:"Authentication errors require fixing credentials, not retrying"},[f.name]:{shouldRetry:!0,maxRetries:3,baseDelay:1e3,backoffMultiplier:2,reason:"Rate limit errors can be retried with exponential backoff"},[g.name]:{shouldRetry:!0,maxRetries:2,baseDelay:500,backoffMultiplier:1.5,reason:"Generic API errors may be transient and worth retrying"}};function Ks(s){let e=s.constructor.name;return ve[e]||ve[g.name]}var Js=w;export{g as APIError,m as AuthenticationError,w as ECODrIx,w as ECODrIxAPI,ve as ERROR_RETRY_CONFIG,ne as EcodrixError,Ee as HTTP_STATUS_ERROR_MAP,f as RateLimitError,Js as default,js as getErrorDetails,Ks as getRetryConfig,Hs as handleAPIError,Fs as isAPIError};
|
|
1
|
+
var Se=Object.defineProperty,Ee=Object.defineProperties;var $e=Object.getOwnPropertyDescriptors;var Ce=Object.getOwnPropertySymbols;var Le=Object.prototype.hasOwnProperty,Ne=Object.prototype.propertyIsEnumerable;var De=(s,e)=>(e=Symbol[s])?e:Symbol.for("Symbol."+s);var le=(s,e,t)=>e in s?Se(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,f=(s,e)=>{for(var t in e||(e={}))Le.call(e,t)&&le(s,t,e[t]);if(Ce)for(var t of Ce(e))Ne.call(e,t)&&le(s,t,e[t]);return s},x=(s,e)=>Ee(s,$e(e));var i=(s,e,t)=>le(s,typeof e!="symbol"?e+"":e,t);var ue=function(s,e){this[0]=s,this[1]=e},Ie=(s,e,t)=>{var n=(g,p,y,m)=>{try{var P=t[g](p),h=(p=P.value)instanceof ue,T=P.done;Promise.resolve(h?p[0]:p).then(u=>h?n(g==="return"?g:"next",p[1]?{done:u.done,value:u.value}:u,y,m):y({value:u,done:T})).catch(u=>n("throw",u,y,m))}catch(u){m(u)}},r=(g,p,y,m)=>c[g]=P=>(p=new Promise((h,T,u)=>(u=()=>n(g,P,h,T),o?o.then(u):u())),m=()=>o===y&&(o=0),o=y=p.then(m,m),p),o,c={};return t=t.apply(s,e),c[De("asyncIterator")]=()=>c,r("next"),r("throw"),r("return"),c};import Me from"axios";import we from"axios-retry";var de=class extends Error{constructor(e){super(e),this.name="EcodrixError"}},l=class extends de{constructor(t,n,r){super(t);i(this,"status");i(this,"code");this.name="APIError",this.status=n,this.code=r}},d=class extends l{constructor(e="Invalid API Key or Client Code"){super(e,401,"AUTH_FAILED"),this.name="AuthenticationError"}},b=class extends l{constructor(e="Too many requests. Please slow down."){super(e,429,"RATE_LIMIT_EXCEEDED"),this.name="RateLimitError"}};var a=class{constructor(e){i(this,"client",e)}async post(e,t,n){try{let r=this.buildConfig(n);return(await this.client.post(e,t,r)).data}catch(r){this.handleError(r)}}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 r=this.buildConfig(n);return(await this.client.patch(e,t,r)).data}catch(r){this.handleError(r)}}async put(e,t,n){try{let r=this.buildConfig(n);return(await this.client.put(e,t,r)).data}catch(r){this.handleError(r)}}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=f({},e);return e.idempotencyKey&&(t.headers=x(f({},t.headers),{"Idempotency-Key":e.idempotencyKey})),t}handleError(e){var t,n,r;if(e.response){let o=e.response.status,c=((t=e.response.data)==null?void 0:t.message)||((n=e.response.data)==null?void 0:n.error)||"API Request Failed",g=(r=e.response.data)==null?void 0:r.code;switch(o){case 401:throw new d(c);case 403:throw new d(c);case 429:throw new b(c);default:throw new l(c,o,g)}}throw new l(e.message||"Network Error")}};var $=class extends a{async listBlueprints(){return this.get("/api/agency/blueprints")}async createBlueprint(e){return this.post("/api/agency/blueprints",e)}async deployBlueprint(e){return this.post("/api/agency/blueprints/deploy",e)}async getPortfolioStats(e){return this.get(`/api/agency/portfolio/${e}/stats`)}async getPortfolioHealth(e){return this.get(`/api/agency/portfolio/${e}/health`)}async getUsage(e){return this.get(`/api/agency/usage/${e}`)}async listStaff(e){return this.get(`/api/agency/staff/${e}`)}async createStaff(e){return this.post("/api/agency/staff",e)}};var k=class extends a{async listNichePacks(e={}){return this.get("/api/admin/onboarding/niche-packs",{params:R(e)})}async getNichePack(e,t){let n=t?{version:t}:void 0;return this.get(`/api/admin/onboarding/niche-packs/${encodeURIComponent(e)}`,{params:n})}async createNichePack(e){return this.post("/api/admin/onboarding/niche-packs",e)}async updateNichePack(e,t,n){let r=n?{version:n}:void 0;return this.patch(`/api/admin/onboarding/niche-packs/${encodeURIComponent(e)}`,t,{params:r})}async publishNichePack(e,t){let n=t?{version:t}:void 0;return this.post(`/api/admin/onboarding/niche-packs/${encodeURIComponent(e)}/publish`,void 0,{params:n})}async unpublishNichePack(e,t){let n=t?{version:t}:void 0;return this.post(`/api/admin/onboarding/niche-packs/${encodeURIComponent(e)}/unpublish`,void 0,{params:n})}async forkNichePack(e,t={}){return this.post(`/api/admin/onboarding/niche-packs/${encodeURIComponent(e)}/fork`,t)}async smokeTestNichePack(e,t={},n){let r=n?{version:n}:void 0;return this.post(`/api/admin/onboarding/niche-packs/${encodeURIComponent(e)}/smoke-test`,t,{params:r})}async listOnboardingConfigs(e={}){return this.get("/api/admin/onboarding/configs",{params:R(e)})}async createOnboardingConfig(e){return this.post("/api/admin/onboarding/configs",e)}async updateOnboardingConfig(e,t,n){return this.patch(`/api/admin/onboarding/configs/${encodeURIComponent(e)}/${encodeURIComponent(t)}`,n)}async publishOnboardingConfig(e,t){return this.post(`/api/admin/onboarding/configs/${encodeURIComponent(e)}/${encodeURIComponent(t)}/publish`)}async listOnboardingExperiments(e={}){return this.get("/api/admin/onboarding/experiments",{params:R(e)})}async getOnboardingExperiment(e){return this.get(`/api/admin/onboarding/experiments/${encodeURIComponent(e)}`)}async createOnboardingExperiment(e){return this.post("/api/admin/onboarding/experiments",e)}async updateOnboardingExperiment(e,t){return this.patch(`/api/admin/onboarding/experiments/${encodeURIComponent(e)}`,t)}async deleteOnboardingExperiment(e){return this.deleteRequest(`/api/admin/onboarding/experiments/${encodeURIComponent(e)}`)}async getOnboardingFunnel(e={}){return this.get("/api/admin/onboarding/analytics/funnel",{params:R(e)})}async getOnboardingTimeOnStep(e={}){return this.get("/api/admin/onboarding/analytics/time-on-step",{params:R(e)})}async getOnboardingAbandonment(e={}){return this.get("/api/admin/onboarding/analytics/abandonment",{params:R(e)})}};function R(s){let e={};for(let[t,n]of Object.entries(s))n!==void 0&&(e[t]=n);return e}var L=class extends a{async getProduct(e){return this.get(`/api/v1/checkout/products/${e}`)}async createSession(e){return this.post("/api/v1/checkout/session",e)}async applyCoupon(e){return this.post("/api/v1/checkout/coupon",e)}async verify(e){return this.post("/api/v1/checkout/verify",e)}async createOrder(e){return this.post("/api/v1/checkout/order",e)}};var N=class extends a{async providers(){return this.get("/api/connect/v1/providers")}async list(){return this.get("/api/connect/v1/connections")}async get_(e){return this.get(`/api/connect/v1/connections/${e}`)}async connect(e,t){return this.post(`/api/connect/v1/connections/${e}/connect`,t)}async configure(e,t){return this.put(`/api/connect/v1/connections/${e}/configure`,t)}async disconnect(e){return this.post(`/api/connect/v1/connections/${e}/disconnect`,{})}async reveal(e){return this.post(`/api/connect/v1/connections/${e}/reveal`,{})}async setAccess(e,t){return this.put(`/api/connect/v1/connections/${e}/access`,t)}};var D=class extends a{async list(){return this.get("/api/saas/cors")}async create(e){return this.post("/api/saas/cors",e)}async update(e,t){return this.patch(`/api/saas/cors/${e}`,t)}async delete(e){return this.deleteRequest(`/api/saas/cors/${e}`)}};var me=class extends a{async list(e){return this.get(`/api/crm/leads/${e}/notes`)}async create(e,t){return this.post(`/api/crm/leads/${e}/notes`,t)}async update(e,t){return this.patch(`/api/crm/notes/${e}`,{content:t})}async pin(e,t=!0){return this.patch(`/api/crm/notes/${e}/pin`,{isPinned:t})}async delete(e){return this.deleteRequest(`/api/crm/notes/${e}`)}},U=class extends a{constructor(t){super(t);i(this,"notes");this.notes=new me(t)}async timeline(t,n){return this.get(`/api/crm/leads/${t}/timeline`,{params:n})}async list(t,n){return this.get(`/api/crm/leads/${t}/activities`,{params:f({},n)})}async log(t){return this.post(`/api/crm/leads/${t.leadId}/activities`,t)}async logCall(t,n){return this.post(`/api/crm/leads/${t}/calls`,n)}};var q=class extends a{async overview(e){return this.get("/api/crm/analytics/overview",{params:e})}async funnel(e){return this.get("/api/crm/analytics/funnel",{params:{pipelineId:e}})}async forecast(e){return this.get("/api/crm/analytics/forecast",{params:{pipelineId:e}})}async sources(e){return this.get("/api/crm/analytics/sources",{params:e})}async team(e){return this.get("/api/crm/analytics/team",{params:e})}async heatmap(e){return this.get("/api/crm/analytics/heatmap",{params:e})}async scores(){return this.get("/api/crm/analytics/scores")}async stageTime(e){return this.get("/api/crm/analytics/stage-time",{params:{pipelineId:e}})}async tiered(e){return this.get("/api/crm/analytics/tiered",{params:e})}async summary(e){return this.get("/api/crm/analytics/summary",{params:e})}async whatsapp(e){return this.get("/api/crm/analytics/whatsapp",{params:e})}};var M=class extends a{async stats(){return this.get("/api/crm/automation/stats")}async logs(e){return this.get("/api/crm/automation/logs",{params:e})}async retryFailedEvent(e){return this.post(`/api/crm/automation/logs/${e}/retry`,{})}};var _=class extends a{async list(){return this.get("/api/crm/automations")}async create(e){return this.post("/api/crm/automations",e)}async update(e,t){return this.patch(`/api/crm/automations/${e}`,t)}async toggle(e){return this.patch(`/api/crm/automations/${e}/toggle`)}async delete(e){return this.deleteRequest(`/api/crm/automations/${e}`)}async bulkDelete(e){return this.post("/api/crm/automations/bulk-delete",{ids:e})}async test(e,t){return this.post(`/api/crm/automations/${e}/test`,{leadId:t})}async getAvailableEvents(){return this.post("/api/crm/automations/events",{})}async enrollments(e,t){return this.get(`/api/crm/automations/${e}/enrollments`,{params:t})}async getEnrollment(e){return this.get(`/api/crm/automations/enrollments/${e}`)}async pauseEnrollment(e,t){return this.post(`/api/crm/automations/${e}/enrollments/${t}/pause`,{})}async resumeEnrollment(e,t){return this.post(`/api/crm/automations/${e}/enrollments/${t}/resume`,{})}async runs(e){return this.get(`/api/crm/automations/${e}/runs`)}async getRun(e){return this.get(`/api/crm/automations/runs/${e}`)}async resumeRun(e){return this.post(`/api/crm/automations/runs/${e}/resume`,{})}async abortRun(e){return this.post(`/api/crm/automations/runs/${e}/abort`,{})}async webhookEvent(e,t,n){return this.post("/api/crm/automations/webhook-event",{ruleId:e,eventName:t,payload:n})}async trigger(e){return this.post("/api/saas/workflows/trigger",e)}};var Ue=["open","won","lost","archived"],F=class extends a{async create(e){return this.post("/api/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:[{label:"New",value:"new"},{label:"Contacted",value:"contacted"},{label:"Qualified",value:"qualified"},{label:"Won",value:"won"},{label:"Lost",value:"lost"}]},{key:"value",label:"Lead Value",type:"currency",required:!1},{key:"source",label:"Source",type:"string",required:!1}],r=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,...r],uiHints:{icon:"User",primaryColor:"#3b82f6",defaultSort:{field:"createdAt",direction:"desc"},summaryFields:["firstName","lastName","phone","status"]}}}async upsert(e){return this.post("/api/crm/leads/upsert",e)}async createMany(e,t=50){let n=[];for(let r=0;r<e.length;r+=t){let c=e.slice(r,r+t).map(p=>this.create(p)),g=await Promise.allSettled(c);for(let p of g)if(p.status==="fulfilled")n.push(p.value);else throw p.reason}return n}async import(e){return this.post("/api/crm/leads/import",{leads:e})}async bulkUpsert(e){return this.import(e)}async list(e){let t=f({},e);return Array.isArray(t.tags)&&(t.tags=t.tags.join(",")),this.get("/api/crm/leads",{params:t})}listAutoPaging(e){return Ie(this,null,function*(){let t=(e==null?void 0:e.page)||1,n=!0;for(;n;){let r=yield new ue(this.list(x(f({},e),{page:t}))),o=Array.isArray(r.data)?r.data:r||[];if(o.length===0){n=!1;break}for(let c of o)yield c;r.pagination&&t<r.pagination.pages||!r.pagination&&o.length>0?t++:n=!1}})}async retrieve(e){return this.get(`/api/crm/leads/${e}`)}async retrieveByPhone(e){return this.get(`/api/crm/leads/phone/${encodeURIComponent(e)}`)}async byStage(e,t,n={}){return this.get(`/api/crm/pipelines/${e}/stages/${t}/leads`,{params:n})}async retrieveByRef(e,t){return this.get(`/api/crm/leads/ref/${encodeURIComponent(e)}/${encodeURIComponent(t)}`)}async update(e,t){return this.patch(`/api/crm/leads/${e}`,t)}async move(e,t){return this.patch(`/api/crm/leads/${e}/move`,{stageId:t})}async convert(e,t,n){return this.post(`/api/crm/leads/${e}/convert`,{outcome:t,reason:n})}async tags(e,t){return this.patch(`/api/crm/leads/${e}/tags`,t)}async recalculateScore(e){return this.post(`/api/crm/leads/${e}/score`,{})}async updateMetadata(e,t){return this.patch(`/api/crm/leads/${e}/metadata`,t)}async fields(){return this.get("/api/crm/leads/fields")}async notes(e){return this.get(`/api/crm/leads/${e}/notes`)}async activities(e,t){return this.get(`/api/crm/leads/${e}/timeline`,{params:t})}async createNote(e,t){return this.post(`/api/crm/leads/${e}/notes`,t)}async updateNote(e,t,n){return this.patch(`/api/crm/notes/${t}`,n)}async deleteNote(e,t){return this.deleteRequest(`/api/crm/notes/${t}`)}async delete(e){return this.deleteRequest(`/api/crm/leads/${e}`)}async bulkArchive(e){return this.patch("/api/crm/leads/bulk-archive",{ids:e})}async bulkDelete(e){return this.deleteRequest("/api/crm/leads",{data:{ids:e}})}async archive(e){return this.patch(`/api/crm/leads/${e}/archive`,{})}};var B=class extends a{async capture(e){return this.post("/api/crm/payments/capture",e)}};var V=class extends a{async list(){return this.get("/api/crm/pipelines")}async getStageManifest(e){var r,o;let t=await this.retrieve(e),n=Array.isArray((r=t.data)==null?void 0:r.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("/api/crm/pipelines",e)}async retrieve(e){return this.get(`/api/crm/pipelines/${e}`)}async update(e,t){return this.patch(`/api/crm/pipelines/${e}`,t)}async setDefault(e){return this.patch(`/api/crm/pipelines/${e}/default`,{})}async duplicate(e,t){return this.post(`/api/crm/pipelines/${e}/duplicate`,{newName:t})}async archive(e){return this.patch(`/api/crm/pipelines/${e}/archive`,{})}async delete(e){return this.deleteRequest(`/api/crm/pipelines/${e}`)}async checkInUse(e){return this.get(`/api/crm/pipelines/${e}/in-use`)}async board(e){return this.get(`/api/crm/pipelines/${e}/board`)}async forecast(e){return this.get(`/api/crm/pipelines/${e}/forecast`)}async addStage(e,t){return this.post(`/api/crm/pipelines/${e}/stages`,t)}async reorderStages(e,t){return this.patch(`/api/crm/pipelines/${e}/stages/reorder`,{order:t})}async updateStage(e,t){return this.patch(`/api/crm/stages/${e}`,t)}async deleteStage(e,t){return this.deleteRequest(`/api/crm/stages/${e}`,{data:t?{moveLeadsToStageId:t}:void 0})}};var j=class extends a{async getConfig(){return this.get("/api/crm/scoring")}async updateConfig(e){return this.patch("/api/crm/scoring",e)}async recalculate(e){return this.post(`/api/crm/scoring/${e}/recalculate`,{})}};var H=class extends a{async enroll(e){return this.post("/api/crm/sequences/enroll",e)}async unenroll(e){return this.deleteRequest(`/api/crm/sequences/unenroll/${e}`)}async listForLead(e){return this.get(`/api/crm/sequences/lead/${e}`)}};var K=class{constructor(e){i(this,"leads");i(this,"pipelines");i(this,"activities");i(this,"analytics");i(this,"automations");i(this,"sequences");i(this,"scoring");i(this,"payments");i(this,"automationDashboard");this.leads=new F(e),this.pipelines=new V(e),this.activities=new U(e),this.analytics=new q(e),this.automations=new _(e),this.sequences=new H(e),this.scoring=new j(e),this.payments=new B(e),this.automationDashboard=new M(e)}};var Q=class extends a{async sendCampaign(e){return this.post("/api/saas/marketing/emails/campaign",e)}async sendTest(e){return this.post("/api/saas/marketing/emails/test",{to:e})}async listTemplates(e){return this.get("/api/saas/marketing/mail/templates",{params:e})}async getTemplate(e){return this.get(`/api/saas/marketing/mail/templates/${e}`)}async createTemplate(e){return this.post("/api/saas/marketing/mail/templates",e)}async updateTemplate(e,t){return this.put(`/api/saas/marketing/mail/templates/${e}`,t)}async deleteTemplate(e,t=!1){return this.deleteRequest(`/api/saas/marketing/mail/templates/${e}`,{params:{force:t}})}async previewTemplate(e,t){return this.post(`/api/saas/marketing/mail/templates/${e}/preview`,t)}};var W=class extends a{async list(){return this.get("/api/saas/events")}async assign(e){return this.post("/api/saas/events/assign",e)}async unassign(e){return this.post("/api/saas/events/unassign",{name:e})}async unassignBulk(e){return this.post("/api/saas/events/unassign/bulk",{names:e})}async trigger(e){return this.post("/api/saas/workflows/trigger",e)}async listCustomEvents(){return this.get("/api/saas/crm/custom-events")}async createCustomEvent(e){return this.post("/api/saas/crm/custom-events",e)}async deleteCustomEvent(e){return this.deleteRequest(`/api/saas/crm/custom-events/${e}`)}async emit(e){return this.post("/api/crm/events/emit",e)}};var A=class extends a{async list(e){return this.get("/api/flow/v1/workflows",{params:e})}async create(e){return this.post("/api/flow/v1/workflows",e)}async getWorkflow(e){return this.get(`/api/flow/v1/workflows/${e}`)}async update(e,t){return this.put(`/api/flow/v1/workflows/${e}`,t)}async run(e,t){return this.post(`/api/flow/v1/workflows/${e}/run`,t!=null?t:{})}async getRun(e){return this.get(`/api/flow/v1/runs/${e}`)}async getRunRecords(e){return this.get(`/api/flow/v1/runs/${e}/records`)}async retry(e){return this.post(`/api/flow/v1/runs/${e}/retry`,{})}async approve(e,t){return this.post(`/api/flow/v1/runs/${e}/approve`,t)}async getRunLogs(e){return this.get(`/api/flow/v1/runs/${e}/logs`)}async templates(e){return this.get("/api/flow/v1/templates",{params:e})}async installTemplate(e,t){return this.post(`/api/flow/v1/templates/${e}/install`,t!=null?t:{})}};var z=class extends a{async system(){return(await this.get("/api/saas/health")).data}async clientHealth(){return(await this.get("/api/saas/health/client")).data}async getDiagnosticReport(){return this.clientHealth()}async jobStatus(e){return(await this.get(`/api/saas/jobs/status/${e}`)).data}};var C=class extends a{async list(e){return this.get("/api/saas/invoices",{params:e})}async getInvoice(e){return this.get(`/api/saas/invoices/${e}`)}async create(e){return this.post("/api/saas/invoices",e)}async update(e,t){return this.patch(`/api/saas/invoices/${e}`,t)}async delete(e){return this.deleteRequest(`/api/saas/invoices/${e}`)}async sendViaWhatsApp(e){return this.post(`/api/saas/invoices/${e}/send-whatsapp`,{})}async getSettings(){return this.get("/api/saas/invoice-settings")}async updateSettings(e){return this.patch("/api/saas/invoice-settings",e)}};var J=class extends a{async listEventLogs(e){return this.get("/api/saas/events/logs",{params:e})}async getEventLog(e){return this.get(`/api/saas/events/logs/${e}`)}async listCallbackLogs(e){return this.get("/api/saas/callbacks/logs",{params:e})}async getStats(){return this.get("/api/saas/events/stats")}};var ye=class extends a{async sendCampaign(e){return this.post("/api/saas/marketing/emails/campaign",e)}async sendTest(e){return this.post("/api/saas/marketing/emails/test",{to:e})}},he=class extends a{async list(e){return this.get("/api/saas/marketing/emails/campaigns",{params:e})}async stats(e){return this.get(`/api/saas/marketing/emails/campaigns/${e}/analytics`)}},fe=class extends a{async sendTemplate(e){return this.post("/api/saas/marketing/whatsapp/send-template",e)}},G=class extends a{constructor(t){super(t);i(this,"emails");i(this,"campaigns");i(this,"whatsapp");this.emails=new ye(t),this.campaigns=new he(t),this.whatsapp=new fe(t)}};import qe from"axios";var Y=class extends a{async getUsage(){return this.get("/api/saas/storage/usage")}async createFolder(e){return this.post("/api/saas/storage/folders",{name:e})}async list(e,t){return this.get(`/api/saas/storage/files/${e}`,{params:t})}async delete(e){return this.deleteRequest("/api/saas/storage/files",{params:{key:e}})}async getDownloadUrl(e){return this.post("/api/saas/storage/download-url",{key:e})}async aiDescribe(e){return this.post("/api/saas/storage/ai/describe",{key:e})}async upload(e,t){let n=await this.post("/api/saas/storage/upload-url",t),{uploadUrl:r,key:o}=n.data;await qe.put(r,e,{headers:{"Content-Type":t.contentType}});let c=e.size||e.byteLength||0;return this.post("/api/saas/storage/confirm-upload",{key:o,sizeBytes:c})}};var X=class extends a{async create(e){return this.post("/api/saas/meet",e)}async list(e){return this.get("/api/saas/meet",{params:e})}async retrieve(e){return this.get(`/api/saas/meet/${e}`)}async update(e,t){return this.patch(`/api/saas/meet/${e}`,t)}async reschedule(e,t){return this.patch(`/api/saas/meet/${e}`,t)}async delete(e){return this.update(e,{status:"cancelled"})}};var Z=class extends a{async listLogs(e){return this.get("/api/saas/events/logs",{params:e})}async retrieveLog(e){return this.get(`/api/saas/events/logs/${e}`)}async getStats(e){return this.get("/api/saas/events/stats",{params:e})}async listCallbacks(e){return this.get("/api/saas/callbacks/logs",{params:e})}async listAlerts(e){return this.get("/api/crm/notifications",{params:e})}async dismissAlert(e){return this.patch(`/api/crm/notifications/${e}/dismiss`)}async clearAllAlerts(){return this.deleteRequest("/api/crm/notifications/clear-all")}async retryAction(e){return this.post(`/api/crm/notifications/${e}/retry`,{})}};var I=class extends a{async global(e){return this.post("/api/onboarding/global",e)}async start(e){return this.post("/api/onboarding/start",e)}async answer(e){return this.post("/api/onboarding/answer",e)}async state(e){return this.get("/api/onboarding/state",{params:{productId:e}})}async complete(e){return this.post("/api/onboarding/complete",e)}async edit(e){return this.post("/api/onboarding/edit",e)}async previewWorkspace(e){return this.get("/api/onboarding/preview-workspace",{params:{sessionId:e}})}};var O=class extends a{async get(e){return super.get(`/api/persona/${e}`)}async reinforce(e){return this.post("/api/persona/reinforce",e)}async confidence(e){return super.get("/api/persona/confidence",{params:{productId:e}})}async timeline(e,t){var r;let n=await super.get(`/api/persona/${e}/timeline`,{params:t});return(r=n==null?void 0:n.data)!=null?r:{entries:[],hasMore:!1}}async followups(e){var n,r;let t=await super.get(`/api/persona/${e}/followups`);return(r=(n=t==null?void 0:t.data)==null?void 0:n.entries)!=null?r:[]}};var S=class extends a{async conversations(){return this.get("/api/saas/portal-inbox/conversations")}async messages(e){return this.get(`/api/saas/portal-inbox/conversations/${e}/messages`)}async reply(e,t){return this.post(`/api/saas/portal-inbox/conversations/${e}/messages`,t)}};var E=class extends a{async list(e){return this.get(`/api/saas/projects/${e}/documents`)}async upload(e,t){return this.post(`/api/saas/projects/${e}/documents`,t)}async toggleSignature(e,t,n){return this.patch(`/api/saas/projects/${e}/documents/${t}/signature`,{required:n})}async addSigner(e,t,n){return this.post(`/api/saas/projects/${e}/documents/${t}/signers`,n)}async sign(e,t,n){return this.post(`/api/saas/projects/${e}/documents/${t}/sign`,n!=null?n:{})}async decline(e,t){return this.post(`/api/saas/projects/${e}/documents/${t}/decline`,{})}async stampSign(e,t,n){return this.post(`/api/saas/projects/${e}/documents/${t}/stamp-sign`,n)}};var ee=class extends a{async listFailed(){return this.get("/api/saas/admin/queue/failed")}async getStats(){return this.get("/api/saas/admin/queue/stats")}async retryJob(e){return this.post(`/api/saas/admin/queue/${e}/retry`,{})}async deleteJob(e){return this.deleteRequest(`/api/saas/admin/queue/${e}`)}};var te=class extends a{async list(){return this.get("/api/laie/v1/relays")}async create(e){return this.post("/api/laie/v1/relays",e)}async update(e,t){return this.patch(`/api/laie/v1/relays/${e}`,t)}async delete(e){return this.deleteRequest(`/api/laie/v1/relays/${e}`)}async getConfig(){return this.get("/api/laie/v1/relays/config")}async updateConfig(e){return this.patch("/api/laie/v1/relays/config",e)}async ping(){return this.post("/api/laie/v1/relays/ping")}async provision(e={}){return this.post("/api/laie/v1/relays/provision",e)}async retire(e){return this.post(`/api/laie/v1/relays/${e}/retire`)}};var be=class extends a{async list(){return this.get("/api/clients")}async getCountAndGenerateCode(){return this.get("/api/clients/count")}async retrieve(e){return this.get(`/api/clients/${e}`)}async getApiKey(e){return this.get(`/api/clients/${e}/api-key`)}async rotateApiKey(e){return this.post(`/api/clients/${e}/api-key`,{})}async create(e){return this.post("/api/clients",e)}async getConfig(e){return this.get(`/api/clients/${e}/config`)}async updateConfig(e,t){return this.patch(`/api/clients/${e}/config`,t)}async getConnections(e){return this.get(`/api/clients/${e}/connections`)}async getConnectProviders(e){return this.get(`/api/clients/${e}/connections/providers`)}async connectProvider(e,t,n){return this.post(`/api/clients/${e}/connections/${t}/connect`,n)}async configureProvider(e,t,n){return this.put(`/api/clients/${e}/connections/${t}/configure`,n)}async disconnectProvider(e,t){return this.post(`/api/clients/${e}/connections/${t}/disconnect`,{})}async revealConnection(e,t){return this.post(`/api/clients/${e}/connections/${t}/reveal`,{})}async setConnectionAccess(e,t,n){return this.put(`/api/clients/${e}/connections/${t}/access`,n)}async getDataSource(e){return this.get(`/api/clients/${e}/datasource`)}async manageDataSource(e,t){return this.post(`/api/clients/${e}/datasource`,t)}async updateIdentity(e,t){return this.patch(`/api/clients/${e}/identity`,t)}async googleReauth(e,t={}){return this.post(`/api/clients/${e}/google/reauth`,t)}async delete(e){return this.deleteRequest(`/api/clients/${e}`)}},Te=class extends a{async list(){return this.get("/api/services/blogs")}},Pe=class extends a{async add(e){return this.post("/api/services/add-lead",e)}},ne=class extends a{constructor(t){super(t);i(this,"clients");i(this,"blogs");i(this,"globalLeads");this.clients=new be(t),this.blogs=new Te(t),this.globalLeads=new Pe(t)}};var xe=class extends a{async getConfig(){return this.get("/api/settings/email")}async switchProvider(e){return this.post("/api/settings/email/provider",{provider:e})}async saveSmtp(e){return this.post("/api/settings/email/smtp",e)}async initDomainVerification(e){return this.post("/api/settings/email/ses/domain",{domain:e})}async saveEmailConfig(e){return this.post("/api/settings/email/ses/config",e)}async checkSesVerification(){return this.get("/api/settings/email/ses/verify")}async removeSesIdentity(){return this.deleteRequest("/api/settings/email/ses/domain")}async sendTest(e){return this.post("/api/settings/email/test",{toEmail:e})}async saveAdvancedConfig(e){return this.post("/api/settings/email/advanced",e)}async getHealth(){return this.get("/api/settings/email/health")}async fixDmarc(){return this.post("/api/settings/email/ses/fix-dmarc",{})}async listProviders(){return this.get("/api/settings/email/providers")}},se=class extends a{constructor(t){super(t);i(this,"email");this.email=new xe(t)}};var Re=class extends a{async create(e){return this.post("/api/saas/storage/folders",{name:e})}async delete(e){return this.deleteRequest(`/api/saas/storage/folders/${encodeURIComponent(e)}`)}},ve=class extends a{async list(e,t){return this.get(`/api/saas/storage/files/${e}`,{params:t})}async getUploadUrl(e){return this.post("/api/saas/storage/upload-url",e)}async confirmUpload(e){return this.post("/api/saas/storage/confirm-upload",e)}async getDownloadUrl(e){return this.post("/api/saas/storage/download-url",{key:e})}async delete(e){return this.deleteRequest("/api/saas/storage/files",{params:{key:e}})}},ae=class extends a{constructor(t){super(t);i(this,"folders");i(this,"files");this.folders=new Re(t),this.files=new ve(t)}async usage(){return this.get("/api/saas/storage/usage")}};var v=class extends l{constructor(e){super(e,400,"invalid_signature"),this.name="WebhookSignatureError"}},re=class{async constructEvent(e,t,n){if(!t)throw new v("No webhook signature provided");let r=Array.isArray(t)?t[0]:t;r.startsWith("sha256=")&&(r=r.slice(7));try{let o=await import("crypto"),g=o.createHmac("sha256",n).update(e).digest("hex");if(!o.timingSafeEqual(Buffer.from(g),Buffer.from(r)))throw new v("Invalid webhook signature provided");return JSON.parse(e.toString("utf8"))}catch(o){throw o instanceof v?o:new v(`Webhook payload parsing failed: ${o.message}`)}}};var ie=class extends a{async list(e){return this.get("/api/saas/chat/broadcasts",{params:e})}async retrieve(e){return this.get(`/api/saas/chat/broadcasts/${e}`)}async create(e){return this.post("/api/saas/chat/broadcast",e)}async update(e,t){return this.patch(`/api/saas/chat/broadcasts/${e}`,t)}async delete(e){return this.deleteRequest(`/api/saas/chat/broadcasts/${e}`)}};var oe=class extends a{async list(e){return this.get("/api/saas/chat/conversations",{params:e})}async create(e){return this.post("/api/saas/chat/conversations",e)}async retrieve(e){return this.get(`/api/saas/chat/conversations/${e}`)}async messages(e,t){return this.get(`/api/saas/chat/conversations/${e}/messages`,{params:t})}async linkLead(e,t,n){return this.post(`/api/saas/chat/conversations/${e}/link-lead`,{leadId:t,leadData:n})}async markRead(e){return this.post(`/api/saas/chat/conversations/${e}/read`,{})}async delete(e){return this.deleteRequest(`/api/saas/chat/conversations/${e}`)}async bulkDelete(e){return this.post("/api/saas/chat/conversations/bulk-delete",{ids:e})}};var ce=class extends a{async send(e){return this.post("/api/saas/chat/send",e)}async sendTemplate(e){return this.post("/api/saas/chat/send",x(f({},e),{templateLanguage:e.language||e.templateLanguage||"en_US"}))}async star(e,t){return this.post(`/api/saas/chat/messages/${e}/star`,{isStarred:t})}async react(e,t){return this.post(`/api/saas/chat/messages/${e}/react`,{reaction:t})}async markRead(e){return this.post(`/api/saas/chat/conversations/${e}/read`)}async upload(e){let t=new FormData;return t.append("file",e),this.post("/api/saas/chat/upload",t,{headers:{"Content-Type":"multipart/form-data"}})}};var pe=class extends a{async list(e){return this.get("/api/saas/chat/templates",{params:e})}async sync(){return this.post("/api/saas/chat/templates/sync",{})}async retrieve(e){return this.get(`/api/saas/chat/templates/${encodeURIComponent(e)}`)}async create(e){return this.post("/api/saas/chat/templates",e)}async update(e,t){return this.put(`/api/saas/chat/templates/${e}`,t)}async deleteTemplate(e,t){return this.deleteRequest(`/api/saas/chat/templates/${encodeURIComponent(e)}${t?"?force=true":""}`)}async mappingConfig(){return this.get("/api/saas/chat/templates/mapping/config")}async collections(){return this.get("/api/saas/chat/templates/collections")}async collectionFields(e){return this.get(`/api/saas/chat/templates/collections/${encodeURIComponent(e)}/fields`)}async updateMapping(e,t){return this.put(`/api/saas/chat/templates/${encodeURIComponent(e)}/mapping`,t)}async validate(e){return this.get(`/api/saas/chat/templates/${encodeURIComponent(e)}/validate`)}async preview(e,t){return this.post(`/api/saas/chat/templates/${encodeURIComponent(e)}/preview`,{context:t})}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:[],r=[];for(let g of n)if(g.text){let p=g.text.match(/{{(\d+)}}/g);if(p)for(let y of p){let m=y.replace(/{{|}}/g,"");r.push({key:`var_${m}`,label:`${g.type} Var {{${m}}}`,type:"string",required:!0,group:g.type,description:`Variable placeholder in template ${g.type}`})}}return{name:`Template variables: ${((c=t.data)==null?void 0:c.name)||e}`,fields:r,uiHints:{icon:"Variables",primaryColor:"#059669"}}}async checkUsage(e){return this.get(`/api/saas/chat/templates/${encodeURIComponent(e)}/usage`)}};var ge=class extends a{constructor(t){super(t);i(this,"messages");i(this,"conversations");i(this,"broadcasts");i(this,"templates");this.messages=new ce(t),this.conversations=new oe(t),this.broadcasts=new ie(t),this.templates=new pe(t)}async upload(t,n){let r=new FormData;return r.append("file",t,n),this.post("/api/saas/chat/upload",r,{headers:typeof r.getHeaders=="function"?r.getHeaders():void 0})}async sendTemplate(t){return this.post("/api/saas/marketing/whatsapp/send-template",t)}};var _e="https://api.ecodrix.com",w=class{constructor(e){i(this,"client");i(this,"socket",null);i(this,"socketPromise",null);i(this,"socketQueue",[]);i(this,"clientCode");i(this,"whatsapp");i(this,"crm");i(this,"media");i(this,"meet");i(this,"notifications");i(this,"email");i(this,"logs");i(this,"events");i(this,"webhooks");i(this,"storage");i(this,"marketing");i(this,"health");i(this,"queue");i(this,"agency");i(this,"services");i(this,"settings");i(this,"cors");i(this,"relays");i(this,"checkout");i(this,"connect");i(this,"onboarding");i(this,"adminOnboarding");i(this,"persona");i(this,"flow");i(this,"portalInbox");i(this,"projectDocuments");i(this,"invoices");var p,y,m,P;if(!e.apiKey)throw new d("API Key is required");this.clientCode=(p=e.clientCode)==null?void 0:p.toUpperCase();let t=(y=e.baseUrl)!=null?y:_e,n=e.socketUrl||t,r=typeof window!="undefined"&&typeof window.document!="undefined",o=r?"browser":typeof process!="undefined"?`node ${process.version}`:"unknown",c=r?((m=globalThis.navigator)==null?void 0:m.userAgent)||"browser":typeof process!="undefined"?process.platform:"unknown",g={"x-api-key":e.apiKey,"x-client-code":((P=e.clientCode)==null?void 0:P.toUpperCase())||"","Content-Type":"application/json","x-ecodrix-client-agent":JSON.stringify({sdk_version:"1.0.0",runtime:o,os:c})};if(e.coreApiKey&&(g["x-core-api-key"]=e.coreApiKey),this.client=Me.create({baseURL:t,headers:g}),we(this.client,{retries:3,retryDelay:we.exponentialDelay,retryCondition:h=>{var T;return we.isNetworkOrIdempotentRequestError(h)||((T=h.response)==null?void 0:T.status)===429},onRetry:(h,T,u)=>{var ke,Ae;typeof process!="undefined"&&((ke=process.env)==null?void 0:ke.NODE_ENV)==="development"&&console.warn(`[ECODrIx SDK] Retrying request (${h}/3): ${(Ae=u.method)==null?void 0:Ae.toUpperCase()} ${u.url}. Reason: ${T.message}`)}}),this.whatsapp=new ge(this.client),this.crm=new K(this.client),this.media=new Y(this.client),this.meet=new X(this.client),this.notifications=new Z(this.client),this.email=new Q(this.client),this.logs=new J(this.client),this.events=new W(this.client),this.webhooks=new re,this.storage=new ae(this.client),this.marketing=new G(this.client),this.health=new z(this.client),this.queue=new ee(this.client),this.agency=new $(this.client),this.services=new ne(this.client),this.settings=new se(this.client),this.cors=new D(this.client),this.relays=new te(this.client),this.checkout=new L(this.client),this.connect=new N(this.client),this.onboarding=new I(this.client),this.adminOnboarding=new k(this.client),this.persona=new O(this.client),this.flow=new A(this.client),this.portalInbox=new S(this.client),this.projectDocuments=new E(this.client),this.invoices=new C(this.client),this.initSocket(n,e.apiKey,e.clientCode),r){let h={version:"1.2.2",clientCode:e.clientCode,initializedAt:new Date().toISOString()};window.__ECODRIX_SDK__=h,window.ecodrix||(window.ecodrix=this)}}initSocket(e,t,n){return this.socketPromise?this.socketPromise:(this.socketPromise=import("socket.io-client").then(({io:r})=>{this.socket=r(e,{extraHeaders:{"x-api-key":t,"x-client-code":(n==null?void 0:n.toUpperCase())||""}}),this.setupSocket(n);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){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(e){this.socket&&this.socket.on("connect",()=>{e&&this.socket.emit("join-room",e.toUpperCase())})}on(e,t){return this.socket?this.socket.on(e,t):this.socketQueue.push({type:"on",args:[e,t]}),this}disconnect(){this.socket?this.socket.disconnect():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,r){var o,c,g;try{return(await this.client.request({method:e,url:t,data:n,params:r})).data}catch(p){throw p.response?new l(((o=p.response.data)==null?void 0:o.message)||((c=p.response.data)==null?void 0:c.error)||"Raw Execution Failed",p.response.status,(g=p.response.data)==null?void 0:g.code):new l(p.message||"Network Error")}}};var Fe={401:d,403:d,429:b};function Rs(s){var e,t,n;if(s.response){let r=s.response.status,o=((e=s.response.data)==null?void 0:e.message)||((t=s.response.data)==null?void 0:t.error)||"API Request Failed",c=(n=s.response.data)==null?void 0:n.code,g=Fe[r]||l;throw g===d?new d(o):g===b?new b(o):new l(o,r,c)}throw new l(s.message||"Network Error")}function vs(s,e){return s instanceof e}function ws(s){return s instanceof d?{message:s.message,status:s.status,code:s.code,type:"AuthenticationError"}:s instanceof b?{message:s.message,status:s.status,code:s.code,type:"RateLimitError"}:s instanceof l?{message:s.message,status:s.status,code:s.code,type:"APIError"}:{message:s.message||"Unknown error",type:"UnknownError"}}var Oe={[d.name]:{shouldRetry:!1,reason:"Authentication errors require fixing credentials, not retrying"},[b.name]:{shouldRetry:!0,maxRetries:3,baseDelay:1e3,backoffMultiplier:2,reason:"Rate limit errors can be retried with exponential backoff"},[l.name]:{shouldRetry:!0,maxRetries:2,baseDelay:500,backoffMultiplier:1.5,reason:"Generic API errors may be transient and worth retrying"}};function ks(s){let e=s.constructor.name;return Oe[e]||Oe[l.name]}var Is=w;export{l as APIError,k as AdminOnboarding,d as AuthenticationError,w as ECODrIx,w as ECODrIxAPI,Oe as ERROR_RETRY_CONFIG,de as EcodrixError,A as Flow,Fe as HTTP_STATUS_ERROR_MAP,C as Invoices,Ue as LEAD_STATUS_VALUES,I as Onboarding,O as Persona,S as PortalInbox,E as ProjectDocuments,b as RateLimitError,te as Relays,Is as default,ws as getErrorDetails,ks as getRetryConfig,Rs as handleAPIError,vs as isAPIError};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ecodrix/erix-api",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"author": "ECODrIx Team <contact@ecodrix.com>",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "Official Isomorphic SDK for the ECODrIx platform. Native support for WhatsApp, CRM, Storage, and Meetings across TS, JS, Python, and Java.",
|