@ecodrix/erix-api 1.3.3 → 1.3.4
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 +4 -4
- package/dist/index.d.ts +120 -34
- package/dist/ts/browser/index.global.js +14 -14
- package/dist/ts/browser/index.global.js.map +1 -1
- package/dist/ts/cjs/index.cjs +1 -1
- package/dist/ts/cjs/index.cjs.map +1 -1
- package/dist/ts/cjs/index.d.cts +120 -34
- package/dist/ts/esm/index.d.ts +120 -34
- package/dist/ts/esm/index.js +1 -1
- package/dist/ts/esm/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import he from"repl";import{Command as Te}from"commander";import fe from"dotenv";import o from"picocolors";import ue from"axios";import oe from"axios-retry";import{io as ye}from"socket.io-client";var z=class extends Error{constructor(e){super(e),this.name="EcodrixError"}},u=class extends z{status;code;constructor(e,t,r){super(e),this.name="APIError",this.status=t,this.code=r}},T=class extends u{constructor(e="Invalid API Key or Client Code"){super(e,401,"AUTH_FAILED"),this.name="AuthenticationError"}};var n=class{constructor(e){this.client=e}async post(e,t,r){try{let s=this.buildConfig(r);return(await this.client.post(e,t,s)).data}catch(s){this.handleError(s)}}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 s=this.buildConfig(r);return(await this.client.patch(e,t,s)).data}catch(s){this.handleError(s)}}async put(e,t,r){try{let s=this.buildConfig(r);return(await this.client.put(e,t,s)).data}catch(s){this.handleError(s)}}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={...e};return e.idempotencyKey&&(t.headers={...t.headers,"Idempotency-Key":e.idempotencyKey}),t}handleError(e){throw e.response?new u(e.response.data?.message||e.response.data?.error||"API Request Failed",e.response.status,e.response.data?.code):new u(e.message||"Network Error")}};var Q=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}`)}},f=class extends n{notes;constructor(e){super(e),this.notes=new Q(e)}async timeline(e,t){return this.get(`/api/crm/leads/${e}/timeline`,{params:t})}async list(e,t){return this.get(`/api/crm/leads/${e}/activities`,{params:{...t}})}async log(e){return this.post(`/api/crm/leads/${e.leadId}/activities`,e)}async logCall(e,t){return this.post(`/api/crm/leads/${e}/calls`,t)}};var b=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 v=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 x=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,r){return this.post("/api/crm/webhook-event",{ruleId:e,eventName:t,payload:r})}};var P=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:[],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:[{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}],s=t.map(i=>({key:`metadata.extra.${i.name}`,label:i.label||i.name,type:i.type||"string",required:!!i.required,options:i.options,group:"Custom Fields"}));return{name:"Lead",fields:[...r,...s],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 r=[];for(let s=0;s<e.length;s+=t){let l=e.slice(s,s+t).map(g=>this.create(g)),m=await Promise.allSettled(l);for(let g of m)if(g.status==="fulfilled")r.push(g.value);else throw g.reason}return r}async import(e){return this.post("/api/crm/leads/import",{leads:e})}async list(e){let t={...e};return Array.isArray(t.tags)&&(t.tags=t.tags.join(",")),this.get("/api/crm/leads",{params:t})}async*listAutoPaging(e){let t=e?.page||1,r=!0;for(;r;){let s=await this.list({...e,page:t}),i=Array.isArray(s.data)?s.data:s||[];if(i.length===0){r=!1;break}for(let l of i)yield l;s.pagination&&t<s.pagination.pages||!s.pagination&&i.length>0?t++:r=!1}}async retrieve(e){return this.get(`/api/crm/leads/${e}`)}async retrieveByPhone(e){return this.get(`/api/crm/leads/phone/${encodeURIComponent(e)}`)}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,r){return this.post(`/api/crm/leads/${e}/convert`,{outcome:t,reason:r})}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,r){return this.patch(`/api/crm/notes/${t}`,r)}async deleteNote(e,t){return this.deleteRequest(`/api/crm/notes/${t}`)}async delete(e){return this.deleteRequest(`/api/crm/leads/${e}`)}async bulkDelete(e){return this.deleteRequest("/api/crm/leads",{data:{ids:e}})}};var w=class extends n{async capture(e){return this.post("/api/crm/payments/capture",e)}};var C=class extends n{async list(){return this.get("/api/crm/pipelines")}async getStageManifest(e){let t=await this.retrieve(e),r=Array.isArray(t.data?.stages)?t.data.stages:[];return{name:`Pipeline: ${t.data?.name||e}`,fields:r.map(s=>({key:s._id,label:s.name,type:"string",required:!0,options:[{label:s.name,value:s._id}],group:"Stages",uiHints:{color:s.color||"#cbd5e1",probability:s.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 $=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 R=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 A=class{leads;pipelines;activities;analytics;automations;sequences;scoring;payments;automationDashboard;constructor(e){this.leads=new P(e),this.pipelines=new C(e),this.activities=new f(e),this.analytics=new b(e),this.automations=new x(e),this.sequences=new R(e),this.scoring=new $(e),this.payments=new w(e),this.automationDashboard=new v(e)}};var I=class extends n{async sendCampaign(e){return this.post("/api/saas/emails/campaign",e)}async sendTest(e){return this.post("/api/saas/emails/test",{to:e})}async listTemplates(e){return this.get("/api/saas/mail/templates",{params:e})}async getTemplate(e){return this.get(`/api/saas/mail/templates/${e}`)}async createTemplate(e){return this.post("/api/saas/mail/templates",e)}async updateTemplate(e,t){return this.put(`/api/saas/mail/templates/${e}`,t)}async deleteTemplate(e,t=!1){return this.deleteRequest(`/api/saas/mail/templates/${e}`,{params:{force:t}})}async previewTemplate(e,t){return this.post(`/api/saas/mail/templates/${e}/preview`,t)}};var k=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/saas/crm/events/emit",e)}};var S=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 E=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 X=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})}},Z=class extends n{async list(e){return this.get("/api/saas/marketing/campaigns",{params:e})}async create(e){return this.post("/api/saas/marketing/campaigns",e)}async retrieve(e){return this.get(`/api/saas/marketing/campaigns/${e}`)}async update(e,t){return this.patch(`/api/saas/marketing/campaigns/${e}`,t)}async delete(e){return this.deleteRequest(`/api/saas/marketing/campaigns/${e}`)}async send(e,t){return this.post(`/api/saas/marketing/campaigns/${e}/send`,t||{})}async stats(e){return this.get(`/api/saas/marketing/campaigns/${e}/stats`)}},ee=class extends n{async sendTemplate(e){return this.post("/api/saas/marketing/whatsapp/send-template",e)}},D=class extends n{emails;campaigns;whatsapp;constructor(e){super(e),this.emails=new X(e),this.campaigns=new Z(e),this.whatsapp=new ee(e)}};import me from"axios";var L=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 upload(e,t){let r=await this.post("/api/saas/storage/upload-url",t),{uploadUrl:s,key:i}=r.data;await me.put(s,e,{headers:{"Content-Type":t.contentType}});let l=e.size||e.byteLength||0;return this.post("/api/saas/storage/confirm-upload",{key:i,sizeBytes:l})}};var q=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 O=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 M=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 te=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)}`)}},se=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}})}},N=class extends n{folders;files;constructor(e){super(e),this.folders=new te(e),this.files=new se(e)}async usage(){return this.get("/api/saas/storage/usage")}};var h=class extends u{constructor(e){super(e,400,"invalid_signature"),this.name="WebhookSignatureError"}},U=class{async constructEvent(e,t,r){if(!t)throw new h("No webhook signature provided");let s=Array.isArray(t)?t[0]:t;s.startsWith("sha256=")&&(s=s.slice(7));try{let i=await import("crypto"),m=i.createHmac("sha256",r).update(e).digest("hex");if(!i.timingSafeEqual(Buffer.from(m),Buffer.from(s)))throw new h("Invalid webhook signature provided");return JSON.parse(e.toString("utf8"))}catch(i){throw i instanceof h?i:new h(`Webhook payload parsing failed: ${i.message}`)}}};var _=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 F=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,r){return this.post(`/api/saas/chat/conversations/${e}/link-lead`,{leadId:t,leadData:r})}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 B=class extends n{async send(e){return this.post("/api/saas/chat/send",e)}async sendTemplate(e){return this.post("/api/saas/chat/send",{...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 K=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){let t=await this.retrieve(e),r=Array.isArray(t.data?.components)?t.data.components:[],s=[];for(let i of r)if(i.text){let l=i.text.match(/{{(\d+)}}/g);if(l)for(let m of l){let g=m.replace(/{{|}}/g,"");s.push({key:`var_${g}`,label:`${i.type} Var {{${g}}}`,type:"string",required:!0,group:i.type,description:`Variable placeholder in template ${i.type}`})}}return{name:`Template variables: ${t.data?.name||e}`,fields:s,uiHints:{icon:"Variables",primaryColor:"#059669"}}}async checkUsage(e){return this.get(`/api/saas/chat/templates/${encodeURIComponent(e)}/usage`)}};var V=class extends n{messages;conversations;broadcasts;templates;constructor(e){super(e),this.messages=new B(e),this.conversations=new F(e),this.broadcasts=new _(e),this.templates=new K(e)}async upload(e,t){let r=new FormData;return r.append("file",e,t),this.post("/api/saas/chat/upload",r,{headers:typeof r.getHeaders=="function"?r.getHeaders():void 0})}async sendTemplate(e){return this.post("/api/saas/marketing/whatsapp/send-template",e)}};var H=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 ae=class extends n{async list(){return this.get("/api/services/clients")}async getCountAndGenerateCode(){return this.get("/api/services/clients/count")}async retrieve(e){return this.get(`/api/services/clients/${e}`)}async getApiKey(e){return this.get(`/api/services/clients/${e}/api-key`)}async rotateApiKey(e){return this.post(`/api/services/clients/${e}/api-key`,{})}async create(e){return this.post("/api/services/clients",e)}async getConfig(e){return this.get(`/api/services/clients/${e}/config`)}async updateConfig(e,t){return this.patch(`/api/services/clients/${e}/config`,t)}async getSecrets(e){return this.get(`/api/services/clients/${e}/secrets`)}async updateSecrets(e,t){return this.post(`/api/services/clients/${e}/secrets`,t)}async replaceSecrets(e,t){return this.put(`/api/services/clients/${e}/secrets`,t)}async patchSecrets(e,t){return this.patch(`/api/services/clients/${e}/secrets`,t)}async getDataSource(e){return this.get(`/api/services/clients/${e}/datasource`)}async manageDataSource(e,t){return this.post(`/api/services/clients/${e}/datasource`,t)}async updateIdentity(e,t){return this.patch(`/api/services/clients/${e}/identity`,t)}async googleReauth(e,t={}){return this.post(`/api/services/clients/${e}/google/reauth`,t)}async delete(e){return this.deleteRequest(`/api/services/clients/${e}`)}},ne=class extends n{async list(){return this.get("/api/services/blogs")}},re=class extends n{async add(e){return this.post("/api/services/add-lead",e)}},W=class extends n{clients;blogs;globalLeads;constructor(e){super(e),this.clients=new ae(e),this.blogs=new ne(e),this.globalLeads=new re(e)}};var ie=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")}},j=class extends n{email;constructor(e){super(e),this.email=new ie(e)}};var J=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 Y=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 de="https://api.ecodrix.com",G=class{client;socket;clientCode;whatsapp;crm;media;meet;notifications;email;logs;events;webhooks;storage;marketing;health;queue;agency;services;settings;cors;checkout;constructor(e){if(!e.apiKey)throw new T("API Key is required");this.clientCode=e.clientCode?.toUpperCase();let t=e.baseUrl??de,r=e.socketUrl||t,s=typeof window<"u"&&typeof window.document<"u",i=s?"browser":typeof process<"u"?`node ${process.version}`:"unknown",l=s?globalThis.navigator?.userAgent||"browser":typeof process<"u"?process.platform:"unknown",m={"x-api-key":e.apiKey,"x-client-code":e.clientCode?.toUpperCase()||"","Content-Type":"application/json","x-ecodrix-client-agent":JSON.stringify({sdk_version:"1.0.0",runtime:i,os:l})};if(e.coreApiKey&&(m["x-core-api-key"]=e.coreApiKey),this.client=ue.create({baseURL:t,headers:m}),oe(this.client,{retries:3,retryDelay:oe.exponentialDelay,retryCondition:g=>oe.isNetworkOrIdempotentRequestError(g)||g.response?.status===429,onRetry:(g,ge,ce)=>{typeof process<"u"&&process.env?.NODE_ENV==="development"&&console.warn(`[ECODrIx SDK] Retrying request (${g}/3): ${ce.method?.toUpperCase()} ${ce.url}. Reason: ${ge.message}`)}}),this.whatsapp=new V(this.client),this.crm=new A(this.client),this.media=new L(this.client),this.meet=new q(this.client),this.notifications=new O(this.client),this.email=new I(this.client),this.logs=new E(this.client),this.events=new k(this.client),this.webhooks=new U,this.storage=new N(this.client),this.marketing=new D(this.client),this.health=new S(this.client),this.queue=new M(this.client),this.agency=new H(this.client),this.services=new W(this.client),this.settings=new j(this.client),this.cors=new J(this.client),this.checkout=new Y(this.client),this.socket=ye(r,{extraHeaders:{"x-api-key":e.apiKey,"x-client-code":e.clientCode?.toUpperCase()||""}}),this.setupSocket(e.clientCode),s){let g={version:"1.2.2",clientCode:e.clientCode,initializedAt:new Date().toISOString()};window.__ECODRIX_SDK__=g,window.ecodrix||(window.ecodrix=this)}}joinRoom(e){this.socket.emit("join-room",e)}leaveRoom(e){this.socket.emit("leave-room",e)}setupSocket(e){this.socket.on("connect",()=>{e&&this.socket.emit("join-room",e.toUpperCase())})}on(e,t){return this.socket.on(e,t),this}disconnect(){this.socket.disconnect()}off(e,t){return this.socket.off(e,t),this}async request(e,t,r,s){try{return(await this.client.request({method:e,url:t,data:r,params:s})).data}catch(i){throw i.response?new u(i.response.data?.message||i.response.data?.error||"Raw Execution Failed",i.response.status,i.response.data?.code):new u(i.message||"Network Error")}}};fe.config();var pe="1.3.3";var be="Official Isomorphic SDK for the ECODrIx platform. Native support for WhatsApp, CRM, Storage, and Meetings across TS, JS, Python, and Java.",y=new Te;y.name("erix").description(be).version(pe);function d(a){let e=a.key||process.env.ECOD_API_KEY,t=a.client||process.env.ECOD_CLIENT_CODE;return e||(console.error(o.red("Error: API Key is missing.")),console.log(o.yellow("Set ECOD_API_KEY environment variable or use --key <key>")),process.exit(1)),new G({apiKey:e,clientCode:t,baseUrl:a.baseUrl||process.env.ECOD_BASE_URL})}y.option("-k, --key <key>","ECODrIx API Key").option("-c, --client <code...","Tenant Client Code").option("--base-url <url>","API Base URL override");y.command("whoami").description("Verify current authentication and tenant status").action(async(a,e)=>{let t=e.parent.opts(),r=d(t);console.log(o.cyan("Checking connection to ECODrIx Platform..."));try{let s=await r.request("GET","/api/saas/me/profile");console.log(o.green("\u2714 Authenticated successfully!")),console.log(`${o.bold("User ID:")} ${s.id}`),console.log(`${o.bold("Organisation:")} ${s.organisation?.name||"N/A"}`),t.client&&console.log(`${o.bold("Tenant Code:")} ${o.magenta(t.client)}`)}catch(s){console.error(o.red("\u2716 Authentication failed")),console.error(o.dim(s.message)),process.exit(1)}});var ve=y.command("whatsapp").description("WhatsApp Business API operations");ve.command("send-template").description("Send a WhatsApp template message").argument("<phone>","Recipient phone number").argument("<template>","Template name").option("-v, --vars <json>","Template variables as JSON string","[]").action(async(a,e,t,r)=>{let s=r.parent.parent.opts(),i=d(s);try{let l=JSON.parse(t.vars);console.log(o.cyan(`Sending template '${e}' to ${a}...`));let m=await i.whatsapp.messages.sendTemplate({to:a,templateName:e,language:"en_US",variables:l});console.log(o.green("\u2714 Message sent successfully!")),console.log(o.dim(`ID: ${m?.id||"N/A"}`))}catch(l){console.error(o.red("\u2716 Failed to send message")),console.error(o.dim(l.message))}});var le=y.command("crm").description("CRM and Lead management");le.command("leads").description("List recent leads").option("-l, --limit <number>","Number of leads to fetch","10").option("-s, --status <status>","Filter by lead status").option("-p, --pipeline <id>","Filter by pipeline ID").option("-q, --search <query>","Search by name or email").action(async(a,e)=>{let t=e.parent.parent.opts(),r=d(t);try{let s=Number.parseInt(a.limit);console.log(o.cyan(`Fetching last ${s} leads...`));let i={limit:s};a.status&&(i.status=a.status),a.pipeline&&(i.pipelineId=a.pipeline),a.search&&(i.search=a.search);let l=await r.crm.leads.list(i),m=Array.isArray(l.data)?l.data:Array.isArray(l)?l:[];if(m.length===0){console.log(o.yellow("No leads found."));return}console.table(m.map(g=>({ID:g.id||g._id,Name:`${g.firstName} ${g.lastName||""}`.trim(),Phone:g.phone,Status:g.status,Score:g.score||0,Created:new Date(g.createdAt).toLocaleDateString()})))}catch(s){console.error(o.red("\u2716 Failed to fetch leads")),console.error(o.dim(s.message))}});le.command("pipelines").description("List all CRM pipelines").action(async(a,e)=>{let t=e.parent.parent.opts(),r=d(t);try{console.log(o.cyan("Fetching pipelines..."));let s=await r.crm.pipelines.list(),i=s.data||s||[];if(i.length===0){console.log(o.yellow("No pipelines found."));return}console.table(i.map(l=>({ID:l.id||l._id,Name:l.name,Default:l.isDefault?"Yes":"No",Stages:l.stages?.length||0})))}catch(s){console.error(o.red("\u2716 Failed to fetch pipelines")),console.error(o.dim(s.message))}});var xe=y.command("analytics").description("Business Intelligence Analytics");xe.command("overview").description("Get high-level CRM KPIs").option("-r, --range <range>","Date range (e.g., 24h, 7d, 30d, 365d)","30d").action(async(a,e)=>{let t=e.parent.parent.opts(),r=d(t);try{console.log(o.cyan(`Fetching overview metrics for last ${a.range}...`));let s=await r.crm.analytics.overview({range:a.range}),i=s.data||s;console.log(`
|
|
2
|
+
import he from"repl";import{Command as Te}from"commander";import fe from"dotenv";import o from"picocolors";import ue from"axios";import oe from"axios-retry";import{io as de}from"socket.io-client";var z=class extends Error{constructor(e){super(e),this.name="EcodrixError"}},u=class extends z{status;code;constructor(e,t,r){super(e),this.name="APIError",this.status=t,this.code=r}},T=class extends u{constructor(e="Invalid API Key or Client Code"){super(e,401,"AUTH_FAILED"),this.name="AuthenticationError"}};var n=class{constructor(e){this.client=e}async post(e,t,r){try{let s=this.buildConfig(r);return(await this.client.post(e,t,s)).data}catch(s){this.handleError(s)}}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 s=this.buildConfig(r);return(await this.client.patch(e,t,s)).data}catch(s){this.handleError(s)}}async put(e,t,r){try{let s=this.buildConfig(r);return(await this.client.put(e,t,s)).data}catch(s){this.handleError(s)}}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={...e};return e.idempotencyKey&&(t.headers={...t.headers,"Idempotency-Key":e.idempotencyKey}),t}handleError(e){throw e.response?new u(e.response.data?.message||e.response.data?.error||"API Request Failed",e.response.status,e.response.data?.code):new u(e.message||"Network Error")}};var Q=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}`)}},f=class extends n{notes;constructor(e){super(e),this.notes=new Q(e)}async timeline(e,t){return this.get(`/api/crm/leads/${e}/timeline`,{params:t})}async list(e,t){return this.get(`/api/crm/leads/${e}/activities`,{params:{...t}})}async log(e){return this.post(`/api/crm/leads/${e.leadId}/activities`,e)}async logCall(e,t){return this.post(`/api/crm/leads/${e}/calls`,t)}};var b=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 v=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 x=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,r){return this.post("/api/crm/automations/webhook-event",{ruleId:e,eventName:t,payload:r})}async trigger(e){return this.post("/api/saas/workflows/trigger",e)}};var P=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:[],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:[{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}],s=t.map(i=>({key:`metadata.extra.${i.name}`,label:i.label||i.name,type:i.type||"string",required:!!i.required,options:i.options,group:"Custom Fields"}));return{name:"Lead",fields:[...r,...s],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 r=[];for(let s=0;s<e.length;s+=t){let l=e.slice(s,s+t).map(g=>this.create(g)),m=await Promise.allSettled(l);for(let g of m)if(g.status==="fulfilled")r.push(g.value);else throw g.reason}return r}async import(e){return this.post("/api/crm/leads/import",{leads:e})}async bulkUpsert(e){return this.import(e)}async list(e){let t={...e};return Array.isArray(t.tags)&&(t.tags=t.tags.join(",")),this.get("/api/crm/leads",{params:t})}async*listAutoPaging(e){let t=e?.page||1,r=!0;for(;r;){let s=await this.list({...e,page:t}),i=Array.isArray(s.data)?s.data:s||[];if(i.length===0){r=!1;break}for(let l of i)yield l;s.pagination&&t<s.pagination.pages||!s.pagination&&i.length>0?t++:r=!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,r={}){return this.get(`/api/crm/pipelines/${e}/stages/${t}/leads`,{params:r})}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,r){return this.post(`/api/crm/leads/${e}/convert`,{outcome:t,reason:r})}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,r){return this.patch(`/api/crm/notes/${t}`,r)}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 w=class extends n{async capture(e){return this.post("/api/crm/payments/capture",e)}};var C=class extends n{async list(){return this.get("/api/crm/pipelines")}async getStageManifest(e){let t=await this.retrieve(e),r=Array.isArray(t.data?.stages)?t.data.stages:[];return{name:`Pipeline: ${t.data?.name||e}`,fields:r.map(s=>({key:s._id,label:s.name,type:"string",required:!0,options:[{label:s.name,value:s._id}],group:"Stages",uiHints:{color:s.color||"#cbd5e1",probability:s.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 $=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 R=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 A=class{leads;pipelines;activities;analytics;automations;sequences;scoring;payments;automationDashboard;constructor(e){this.leads=new P(e),this.pipelines=new C(e),this.activities=new f(e),this.analytics=new b(e),this.automations=new x(e),this.sequences=new R(e),this.scoring=new $(e),this.payments=new w(e),this.automationDashboard=new v(e)}};var I=class extends n{async sendCampaign(e){return this.post("/api/saas/emails/campaign",e)}async sendTest(e){return this.post("/api/saas/emails/test",{to:e})}async listTemplates(e){return this.get("/api/saas/mail/templates",{params:e})}async getTemplate(e){return this.get(`/api/saas/mail/templates/${e}`)}async createTemplate(e){return this.post("/api/saas/mail/templates",e)}async updateTemplate(e,t){return this.put(`/api/saas/mail/templates/${e}`,t)}async deleteTemplate(e,t=!1){return this.deleteRequest(`/api/saas/mail/templates/${e}`,{params:{force:t}})}async previewTemplate(e,t){return this.post(`/api/saas/mail/templates/${e}/preview`,t)}};var k=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 S=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 E=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 X=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})}},Z=class extends n{async list(e){return this.get("/api/saas/marketing/campaigns",{params:e})}async create(e){return this.post("/api/saas/marketing/campaigns",e)}async retrieve(e){return this.get(`/api/saas/marketing/campaigns/${e}`)}async update(e,t){return this.patch(`/api/saas/marketing/campaigns/${e}`,t)}async delete(e){return this.deleteRequest(`/api/saas/marketing/campaigns/${e}`)}async send(e,t){return this.post(`/api/saas/marketing/campaigns/${e}/send`,t||{})}async stats(e){return this.get(`/api/saas/marketing/campaigns/${e}/stats`)}},ee=class extends n{async sendTemplate(e){return this.post("/api/saas/marketing/whatsapp/send-template",e)}},D=class extends n{emails;campaigns;whatsapp;constructor(e){super(e),this.emails=new X(e),this.campaigns=new Z(e),this.whatsapp=new ee(e)}};import me from"axios";var L=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 upload(e,t){let r=await this.post("/api/saas/storage/upload-url",t),{uploadUrl:s,key:i}=r.data;await me.put(s,e,{headers:{"Content-Type":t.contentType}});let l=e.size||e.byteLength||0;return this.post("/api/saas/storage/confirm-upload",{key:i,sizeBytes:l})}};var q=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 O=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 M=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 te=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)}`)}},se=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}})}},N=class extends n{folders;files;constructor(e){super(e),this.folders=new te(e),this.files=new se(e)}async usage(){return this.get("/api/saas/storage/usage")}};var h=class extends u{constructor(e){super(e,400,"invalid_signature"),this.name="WebhookSignatureError"}},U=class{async constructEvent(e,t,r){if(!t)throw new h("No webhook signature provided");let s=Array.isArray(t)?t[0]:t;s.startsWith("sha256=")&&(s=s.slice(7));try{let i=await import("crypto"),m=i.createHmac("sha256",r).update(e).digest("hex");if(!i.timingSafeEqual(Buffer.from(m),Buffer.from(s)))throw new h("Invalid webhook signature provided");return JSON.parse(e.toString("utf8"))}catch(i){throw i instanceof h?i:new h(`Webhook payload parsing failed: ${i.message}`)}}};var _=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 F=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,r){return this.post(`/api/saas/chat/conversations/${e}/link-lead`,{leadId:t,leadData:r})}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 B=class extends n{async send(e){return this.post("/api/saas/chat/send",e)}async sendTemplate(e){return this.post("/api/saas/chat/send",{...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 K=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){let t=await this.retrieve(e),r=Array.isArray(t.data?.components)?t.data.components:[],s=[];for(let i of r)if(i.text){let l=i.text.match(/{{(\d+)}}/g);if(l)for(let m of l){let g=m.replace(/{{|}}/g,"");s.push({key:`var_${g}`,label:`${i.type} Var {{${g}}}`,type:"string",required:!0,group:i.type,description:`Variable placeholder in template ${i.type}`})}}return{name:`Template variables: ${t.data?.name||e}`,fields:s,uiHints:{icon:"Variables",primaryColor:"#059669"}}}async checkUsage(e){return this.get(`/api/saas/chat/templates/${encodeURIComponent(e)}/usage`)}};var V=class extends n{messages;conversations;broadcasts;templates;constructor(e){super(e),this.messages=new B(e),this.conversations=new F(e),this.broadcasts=new _(e),this.templates=new K(e)}async upload(e,t){let r=new FormData;return r.append("file",e,t),this.post("/api/saas/chat/upload",r,{headers:typeof r.getHeaders=="function"?r.getHeaders():void 0})}async sendTemplate(e){return this.post("/api/saas/marketing/whatsapp/send-template",e)}};var H=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 ae=class extends n{async list(){return this.get("/api/services/clients")}async getCountAndGenerateCode(){return this.get("/api/services/clients/count")}async retrieve(e){return this.get(`/api/services/clients/${e}`)}async getApiKey(e){return this.get(`/api/services/clients/${e}/api-key`)}async rotateApiKey(e){return this.post(`/api/services/clients/${e}/api-key`,{})}async create(e){return this.post("/api/services/clients",e)}async getConfig(e){return this.get(`/api/services/clients/${e}/config`)}async updateConfig(e,t){return this.patch(`/api/services/clients/${e}/config`,t)}async getSecrets(e){return this.get(`/api/services/clients/${e}/secrets`)}async updateSecrets(e,t){return this.post(`/api/services/clients/${e}/secrets`,t)}async replaceSecrets(e,t){return this.put(`/api/services/clients/${e}/secrets`,t)}async patchSecrets(e,t){return this.patch(`/api/services/clients/${e}/secrets`,t)}async getDataSource(e){return this.get(`/api/services/clients/${e}/datasource`)}async manageDataSource(e,t){return this.post(`/api/services/clients/${e}/datasource`,t)}async updateIdentity(e,t){return this.patch(`/api/services/clients/${e}/identity`,t)}async googleReauth(e,t={}){return this.post(`/api/services/clients/${e}/google/reauth`,t)}async delete(e){return this.deleteRequest(`/api/services/clients/${e}`)}},ne=class extends n{async list(){return this.get("/api/services/blogs")}},re=class extends n{async add(e){return this.post("/api/services/add-lead",e)}},W=class extends n{clients;blogs;globalLeads;constructor(e){super(e),this.clients=new ae(e),this.blogs=new ne(e),this.globalLeads=new re(e)}};var ie=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")}},j=class extends n{email;constructor(e){super(e),this.email=new ie(e)}};var J=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 Y=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 ye="https://api.ecodrix.com",G=class{client;socket;clientCode;whatsapp;crm;media;meet;notifications;email;logs;events;webhooks;storage;marketing;health;queue;agency;services;settings;cors;checkout;constructor(e){if(!e.apiKey)throw new T("API Key is required");this.clientCode=e.clientCode?.toUpperCase();let t=e.baseUrl??ye,r=e.socketUrl||t,s=typeof window<"u"&&typeof window.document<"u",i=s?"browser":typeof process<"u"?`node ${process.version}`:"unknown",l=s?globalThis.navigator?.userAgent||"browser":typeof process<"u"?process.platform:"unknown",m={"x-api-key":e.apiKey,"x-client-code":e.clientCode?.toUpperCase()||"","Content-Type":"application/json","x-ecodrix-client-agent":JSON.stringify({sdk_version:"1.0.0",runtime:i,os:l})};if(e.coreApiKey&&(m["x-core-api-key"]=e.coreApiKey),this.client=ue.create({baseURL:t,headers:m}),oe(this.client,{retries:3,retryDelay:oe.exponentialDelay,retryCondition:g=>oe.isNetworkOrIdempotentRequestError(g)||g.response?.status===429,onRetry:(g,ge,ce)=>{typeof process<"u"&&process.env?.NODE_ENV==="development"&&console.warn(`[ECODrIx SDK] Retrying request (${g}/3): ${ce.method?.toUpperCase()} ${ce.url}. Reason: ${ge.message}`)}}),this.whatsapp=new V(this.client),this.crm=new A(this.client),this.media=new L(this.client),this.meet=new q(this.client),this.notifications=new O(this.client),this.email=new I(this.client),this.logs=new E(this.client),this.events=new k(this.client),this.webhooks=new U,this.storage=new N(this.client),this.marketing=new D(this.client),this.health=new S(this.client),this.queue=new M(this.client),this.agency=new H(this.client),this.services=new W(this.client),this.settings=new j(this.client),this.cors=new J(this.client),this.checkout=new Y(this.client),this.socket=de(r,{extraHeaders:{"x-api-key":e.apiKey,"x-client-code":e.clientCode?.toUpperCase()||""}}),this.setupSocket(e.clientCode),s){let g={version:"1.2.2",clientCode:e.clientCode,initializedAt:new Date().toISOString()};window.__ECODRIX_SDK__=g,window.ecodrix||(window.ecodrix=this)}}joinRoom(e){this.socket.emit("join-room",e)}leaveRoom(e){this.socket.emit("leave-room",e)}setupSocket(e){this.socket.on("connect",()=>{e&&this.socket.emit("join-room",e.toUpperCase())})}on(e,t){return this.socket.on(e,t),this}disconnect(){this.socket.disconnect()}off(e,t){return this.socket.off(e,t),this}async request(e,t,r,s){try{return(await this.client.request({method:e,url:t,data:r,params:s})).data}catch(i){throw i.response?new u(i.response.data?.message||i.response.data?.error||"Raw Execution Failed",i.response.status,i.response.data?.code):new u(i.message||"Network Error")}}};fe.config();var pe="1.3.4";var be="Official Isomorphic SDK for the ECODrIx platform. Native support for WhatsApp, CRM, Storage, and Meetings across TS, JS, Python, and Java.",d=new Te;d.name("erix").description(be).version(pe);function y(a){let e=a.key||process.env.ECOD_API_KEY,t=a.client||process.env.ECOD_CLIENT_CODE;return e||(console.error(o.red("Error: API Key is missing.")),console.log(o.yellow("Set ECOD_API_KEY environment variable or use --key <key>")),process.exit(1)),new G({apiKey:e,clientCode:t,baseUrl:a.baseUrl||process.env.ECOD_BASE_URL})}d.option("-k, --key <key>","ECODrIx API Key").option("-c, --client <code...","Tenant Client Code").option("--base-url <url>","API Base URL override");d.command("whoami").description("Verify current authentication and tenant status").action(async(a,e)=>{let t=e.parent.opts(),r=y(t);console.log(o.cyan("Checking connection to ECODrIx Platform..."));try{let s=await r.request("GET","/api/saas/me/profile");console.log(o.green("\u2714 Authenticated successfully!")),console.log(`${o.bold("User ID:")} ${s.id}`),console.log(`${o.bold("Organisation:")} ${s.organisation?.name||"N/A"}`),t.client&&console.log(`${o.bold("Tenant Code:")} ${o.magenta(t.client)}`)}catch(s){console.error(o.red("\u2716 Authentication failed")),console.error(o.dim(s.message)),process.exit(1)}});var ve=d.command("whatsapp").description("WhatsApp Business API operations");ve.command("send-template").description("Send a WhatsApp template message").argument("<phone>","Recipient phone number").argument("<template>","Template name").option("-v, --vars <json>","Template variables as JSON string","[]").action(async(a,e,t,r)=>{let s=r.parent.parent.opts(),i=y(s);try{let l=JSON.parse(t.vars);console.log(o.cyan(`Sending template '${e}' to ${a}...`));let m=await i.whatsapp.messages.sendTemplate({to:a,templateName:e,language:"en_US",variables:l});console.log(o.green("\u2714 Message sent successfully!")),console.log(o.dim(`ID: ${m?.id||"N/A"}`))}catch(l){console.error(o.red("\u2716 Failed to send message")),console.error(o.dim(l.message))}});var le=d.command("crm").description("CRM and Lead management");le.command("leads").description("List recent leads").option("-l, --limit <number>","Number of leads to fetch","10").option("-s, --status <status>","Filter by lead status").option("-p, --pipeline <id>","Filter by pipeline ID").option("-q, --search <query>","Search by name or email").action(async(a,e)=>{let t=e.parent.parent.opts(),r=y(t);try{let s=Number.parseInt(a.limit);console.log(o.cyan(`Fetching last ${s} leads...`));let i={limit:s};a.status&&(i.status=a.status),a.pipeline&&(i.pipelineId=a.pipeline),a.search&&(i.search=a.search);let l=await r.crm.leads.list(i),m=Array.isArray(l.data)?l.data:Array.isArray(l)?l:[];if(m.length===0){console.log(o.yellow("No leads found."));return}console.table(m.map(g=>({ID:g.id||g._id,Name:`${g.firstName} ${g.lastName||""}`.trim(),Phone:g.phone,Status:g.status,Score:g.score||0,Created:new Date(g.createdAt).toLocaleDateString()})))}catch(s){console.error(o.red("\u2716 Failed to fetch leads")),console.error(o.dim(s.message))}});le.command("pipelines").description("List all CRM pipelines").action(async(a,e)=>{let t=e.parent.parent.opts(),r=y(t);try{console.log(o.cyan("Fetching pipelines..."));let s=await r.crm.pipelines.list(),i=s.data||s||[];if(i.length===0){console.log(o.yellow("No pipelines found."));return}console.table(i.map(l=>({ID:l.id||l._id,Name:l.name,Default:l.isDefault?"Yes":"No",Stages:l.stages?.length||0})))}catch(s){console.error(o.red("\u2716 Failed to fetch pipelines")),console.error(o.dim(s.message))}});var xe=d.command("analytics").description("Business Intelligence Analytics");xe.command("overview").description("Get high-level CRM KPIs").option("-r, --range <range>","Date range (e.g., 24h, 7d, 30d, 365d)","30d").action(async(a,e)=>{let t=e.parent.parent.opts(),r=y(t);try{console.log(o.cyan(`Fetching overview metrics for last ${a.range}...`));let s=await r.crm.analytics.overview({range:a.range}),i=s.data||s;console.log(`
|
|
3
3
|
${o.bold("OVERVIEW KPIs:")}`),console.log(`Total Leads: ${o.green(i.totalLeads||0)}`),console.log(`Open Value: ${o.yellow(`$${(i.openValue||0).toLocaleString()}`)}`),console.log(`Won Revenue: ${o.green(`$${(i.wonRevenue||0).toLocaleString()}`)}`),console.log(`Avg Score: ${o.blue(i.avgScore?.toFixed(1)||0)}`),console.log(`Conversion: ${o.magenta(`${(i.conversionRate||0).toFixed(2)}%`)}
|
|
4
|
-
`)}catch(s){console.error(o.red("\u2716 Failed to fetch analytics overview")),console.error(o.dim(s.message))}});var Pe=
|
|
4
|
+
`)}catch(s){console.error(o.red("\u2716 Failed to fetch analytics overview")),console.error(o.dim(s.message))}});var Pe=d.command("webhooks").description("Webhook utility tools");Pe.command("verify").description("Verify a cryptographic webhook signature").argument("<payload>","The raw request body string").argument("<signature>","The 'x-ecodrix-signature' header value").argument("<secret>","Your webhook signing secret").action(async(a,e,t,r,s)=>{let i=s.parent.parent.opts(),l=y(i);try{await l.webhooks.constructEvent(a,e,t),console.log(o.green("\u2714 Signature is VALID"))}catch(m){console.error(o.red("\u2716 Error during verification")),console.error(o.dim(m.message))}});d.command("shell").alias("repl").description("Start an interactive SDK shell").action(async(a,e)=>{let t=e.parent.opts(),r=y(t);console.log(o.magenta(o.bold(`
|
|
5
5
|
Welcome to the Erix Interactive Shell`))),console.log(o.dim(`SDK Version: ${pe}`)),console.log(o.dim(`The 'ecod' client is pre-initialized and ready.
|
|
6
6
|
`));let s=he.start({prompt:o.cyan("erix > "),useColors:!0});s.context.ecod=r,s.context.whatsapp=r.whatsapp,s.context.crm=r.crm,s.context.meet=r.meet,s.context.media=r.media,s.on("exit",()=>{console.log(o.yellow(`
|
|
7
|
-
Goodbye!`)),process.exit(0)})});
|
|
7
|
+
Goodbye!`)),process.exit(0)})});d.command("completion").description("Generate Bash auto-completion script").action(()=>{console.log(`
|
|
8
8
|
# Erix Bash Completion
|
|
9
9
|
_erix_completions() {
|
|
10
10
|
local cur opts
|
|
@@ -35,4 +35,4 @@ _erix_completions() {
|
|
|
35
35
|
}
|
|
36
36
|
complete -F _erix_completions erix
|
|
37
37
|
`.trim()),console.error(o.yellow(`
|
|
38
|
-
# To enable, run: eval "$(erix completion)"`)),console.error(o.dim("# Or add it to your ~/.bashrc: erix completion >> ~/.bashrc"))});
|
|
38
|
+
# To enable, run: eval "$(erix completion)"`)),console.error(o.dim("# Or add it to your ~/.bashrc: erix completion >> ~/.bashrc"))});d.parse();
|
package/dist/index.d.ts
CHANGED
|
@@ -211,6 +211,12 @@ declare class Analytics extends APIResource {
|
|
|
211
211
|
* Consolidated analytics including CRM overview and WhatsApp messaging metrics.
|
|
212
212
|
*
|
|
213
213
|
* @param params - Time range filters.
|
|
214
|
+
* @returns {Promise<any>} Consolidated analytics object containing CRM overview and WhatsApp messaging metrics.
|
|
215
|
+
* @example
|
|
216
|
+
* ```typescript
|
|
217
|
+
* const stats = await erixClient.crm.analytics.summary({ range: "30d" });
|
|
218
|
+
* console.log(stats.overview.totalLeads);
|
|
219
|
+
* ```
|
|
214
220
|
*/
|
|
215
221
|
summary<T = any>(params?: AnalyticsParams): Promise<T>;
|
|
216
222
|
/**
|
|
@@ -376,6 +382,21 @@ declare class Automations extends APIResource {
|
|
|
376
382
|
* @param payload - Arbitrary data forwarded to the node context.
|
|
377
383
|
*/
|
|
378
384
|
webhookEvent<T = any>(ruleId: string, eventName: string, payload?: any): Promise<T>;
|
|
385
|
+
/**
|
|
386
|
+
* Fire a CRM automation trigger for a given phone number.
|
|
387
|
+
*
|
|
388
|
+
* @param params - Trigger payload (trigger name, phone, variables, etc.)
|
|
389
|
+
*/
|
|
390
|
+
trigger<T = any>(params: {
|
|
391
|
+
trigger: string;
|
|
392
|
+
phone: string;
|
|
393
|
+
email?: string;
|
|
394
|
+
variables?: Record<string, string>;
|
|
395
|
+
createLeadIfMissing?: boolean;
|
|
396
|
+
leadData?: any;
|
|
397
|
+
delayMinutes?: number;
|
|
398
|
+
runAt?: Date | string;
|
|
399
|
+
}): Promise<T>;
|
|
379
400
|
}
|
|
380
401
|
|
|
381
402
|
/**
|
|
@@ -451,18 +472,32 @@ type LeadSource = "website" | "whatsapp" | "direct" | "referral" | string;
|
|
|
451
472
|
* Parameters for creating a new CRM Lead.
|
|
452
473
|
*/
|
|
453
474
|
interface CreateLeadParams {
|
|
454
|
-
/** Lead's
|
|
455
|
-
|
|
475
|
+
/** Lead's full name (alternative to firstName/lastName). */
|
|
476
|
+
name?: string;
|
|
477
|
+
/** Lead's first name. Required for creation if name is not provided. */
|
|
478
|
+
firstName?: string;
|
|
456
479
|
/** Lead's last name. */
|
|
457
480
|
lastName?: string;
|
|
458
481
|
/** Lead's email address. */
|
|
459
482
|
email?: string;
|
|
460
483
|
/** Lead's phone number in E.164 format (e.g. "+919876543210"). */
|
|
461
484
|
phone?: string;
|
|
485
|
+
/**
|
|
486
|
+
* Current status of the lead.
|
|
487
|
+
*/
|
|
488
|
+
status?: LeadStatus;
|
|
489
|
+
/**
|
|
490
|
+
* Estimated value of the lead.
|
|
491
|
+
*/
|
|
492
|
+
value?: number;
|
|
462
493
|
/**
|
|
463
494
|
* Acquisition channel.
|
|
464
495
|
*/
|
|
465
496
|
source?: LeadSource;
|
|
497
|
+
/** Primary message or enquiry from the lead. */
|
|
498
|
+
message?: string;
|
|
499
|
+
/** Internal note about the lead activity. */
|
|
500
|
+
activityNote?: string;
|
|
466
501
|
/** Arbitrary key-value metadata (UTM params, order IDs, etc.). */
|
|
467
502
|
metadata?: Record<string, any>;
|
|
468
503
|
/** Pipeline ID to assign the lead */
|
|
@@ -568,11 +603,19 @@ declare class Leads extends APIResource {
|
|
|
568
603
|
*/
|
|
569
604
|
createMany(leads: CreateLeadParams[], chunkSize?: number): Promise<any[]>;
|
|
570
605
|
/**
|
|
571
|
-
* Bulk upsert (import) leads.
|
|
606
|
+
* Bulk upsert (import) leads. Supports high-volume synchronization.
|
|
572
607
|
*
|
|
573
608
|
* @param leads - Array of leads to import.
|
|
609
|
+
* ---- **Done** ---- API Endpoint
|
|
574
610
|
*/
|
|
575
611
|
import<T = any>(leads: Partial<CreateLeadParams>[]): Promise<T>;
|
|
612
|
+
/**
|
|
613
|
+
* Alias for bulk upserting leads.
|
|
614
|
+
*
|
|
615
|
+
* @param leads - Array of leads to import.
|
|
616
|
+
* ---- **Done** ---- API Endpoint
|
|
617
|
+
*/
|
|
618
|
+
bulkUpsert<T = any>(leads: Partial<CreateLeadParams>[]): Promise<T>;
|
|
576
619
|
/**
|
|
577
620
|
* List CRM leads with optional filtering and pagination.
|
|
578
621
|
*
|
|
@@ -615,8 +658,22 @@ declare class Leads extends APIResource {
|
|
|
615
658
|
* Retrieve a single lead by its phone number.
|
|
616
659
|
*
|
|
617
660
|
* @param phone - Lead's phone number.
|
|
661
|
+
* ---- **Done** ---- API Endpoint
|
|
618
662
|
*/
|
|
619
663
|
retrieveByPhone<T = any>(phone: string): Promise<T>;
|
|
664
|
+
/**
|
|
665
|
+
* Fetches all leads belonging to a specific Kanban column in a pipeline.
|
|
666
|
+
*
|
|
667
|
+
* @param pipelineId - Parent pipeline ID.
|
|
668
|
+
* @param stageId - Target stage ID.
|
|
669
|
+
* @param params - Pagination controls.
|
|
670
|
+
* @returns Paginated result set.
|
|
671
|
+
* ---- **Done** ---- API Endpoint
|
|
672
|
+
*/
|
|
673
|
+
byStage<T = any>(pipelineId: string, stageId: string, params?: {
|
|
674
|
+
page?: number;
|
|
675
|
+
limit?: number;
|
|
676
|
+
}): Promise<T>;
|
|
620
677
|
/**
|
|
621
678
|
* Retrieve a single lead by a reference key and value.
|
|
622
679
|
*
|
|
@@ -712,17 +769,32 @@ declare class Leads extends APIResource {
|
|
|
712
769
|
*/
|
|
713
770
|
deleteNote<T = any>(leadId: string, noteId: string): Promise<unknown>;
|
|
714
771
|
/**
|
|
715
|
-
*
|
|
772
|
+
* Delete a single lead permanently.
|
|
716
773
|
*
|
|
717
|
-
* @param leadId - The ID of the lead to
|
|
774
|
+
* @param leadId - The ID of the lead to delete.
|
|
775
|
+
* ---- **Done** ---- API Endpoint
|
|
718
776
|
*/
|
|
719
777
|
delete(leadId: string): Promise<unknown>;
|
|
720
778
|
/**
|
|
721
779
|
* Bulk archive multiple leads.
|
|
722
780
|
*
|
|
723
781
|
* @param ids - Array of lead IDs to archive.
|
|
782
|
+
* ---- **Done** ---- API Endpoint
|
|
783
|
+
*/
|
|
784
|
+
bulkArchive<T = any>(ids: string[]): Promise<T>;
|
|
785
|
+
/**
|
|
786
|
+
* Bulk delete multiple leads permanently.
|
|
787
|
+
*
|
|
788
|
+
* @param ids - Array of lead IDs to archive.
|
|
789
|
+
* ---- **Done** ---- API Endpoint
|
|
724
790
|
*/
|
|
725
791
|
bulkDelete(ids: string[]): Promise<unknown>;
|
|
792
|
+
/**
|
|
793
|
+
* Archive a single lead.
|
|
794
|
+
*
|
|
795
|
+
* @param leadId - The ID of the lead to archive.
|
|
796
|
+
*/
|
|
797
|
+
archive<T = any>(leadId: string): Promise<T>;
|
|
726
798
|
}
|
|
727
799
|
|
|
728
800
|
declare class Payments extends APIResource {
|
|
@@ -749,15 +821,12 @@ declare class Payments extends APIResource {
|
|
|
749
821
|
}): Promise<T>;
|
|
750
822
|
}
|
|
751
823
|
|
|
752
|
-
interface CreatePipelineParams {
|
|
753
|
-
name: string;
|
|
754
|
-
isDefault?: boolean;
|
|
755
|
-
stages?: any[];
|
|
756
|
-
}
|
|
757
824
|
interface PipelineStageParams {
|
|
758
825
|
name: string;
|
|
759
826
|
color?: string;
|
|
760
827
|
probability?: number;
|
|
828
|
+
isWon?: boolean;
|
|
829
|
+
isLost?: boolean;
|
|
761
830
|
}
|
|
762
831
|
declare class Pipelines extends APIResource {
|
|
763
832
|
/**
|
|
@@ -880,12 +949,23 @@ declare class Pipelines extends APIResource {
|
|
|
880
949
|
}
|
|
881
950
|
|
|
882
951
|
interface ScoringConfig {
|
|
883
|
-
|
|
884
|
-
thresholds: {
|
|
885
|
-
hot: number;
|
|
886
|
-
warm: number;
|
|
887
|
-
};
|
|
952
|
+
/** Scoring rules — each rule adds/subtracts points based on field conditions. */
|
|
888
953
|
rules: any[];
|
|
954
|
+
/**
|
|
955
|
+
* Score threshold above which a lead is considered "hot".
|
|
956
|
+
* @default 70
|
|
957
|
+
*/
|
|
958
|
+
hotThreshold?: number;
|
|
959
|
+
/**
|
|
960
|
+
* Score threshold below which a lead is considered "cold".
|
|
961
|
+
* @default 20
|
|
962
|
+
*/
|
|
963
|
+
coldThreshold?: number;
|
|
964
|
+
/**
|
|
965
|
+
* List of CRM trigger names that cause an automatic score recalculation.
|
|
966
|
+
* @example ["lead_created", "appointment_booked"]
|
|
967
|
+
*/
|
|
968
|
+
recalculateOnTriggers?: string[];
|
|
889
969
|
}
|
|
890
970
|
declare class Scoring extends APIResource {
|
|
891
971
|
/**
|
|
@@ -1079,9 +1159,6 @@ declare class Email extends APIResource {
|
|
|
1079
1159
|
variables?: Record<string, any>;
|
|
1080
1160
|
}): Promise<TemplatePreviewResponse>;
|
|
1081
1161
|
}
|
|
1082
|
-
/** @deprecated Use Email instead */
|
|
1083
|
-
declare class EmailResource extends Email {
|
|
1084
|
-
}
|
|
1085
1162
|
|
|
1086
1163
|
/**
|
|
1087
1164
|
* Event definition representing an entry point capable of triggering automations.
|
|
@@ -1695,9 +1772,6 @@ declare class Media extends APIResource {
|
|
|
1695
1772
|
*/
|
|
1696
1773
|
upload(file: any, options: UploadOptions): Promise<any>;
|
|
1697
1774
|
}
|
|
1698
|
-
/** @deprecated Use Media instead */
|
|
1699
|
-
declare class MediaResource extends Media {
|
|
1700
|
-
}
|
|
1701
1775
|
|
|
1702
1776
|
/**
|
|
1703
1777
|
* Parameters for scheduling a new Google Meet appointment.
|
|
@@ -1709,6 +1783,8 @@ interface CreateMeetingParams {
|
|
|
1709
1783
|
participantName: string;
|
|
1710
1784
|
/** Phone number of the participant in E.164 format. */
|
|
1711
1785
|
participantPhone: string;
|
|
1786
|
+
/** Email addresses of the participants. */
|
|
1787
|
+
participantEmails?: string[];
|
|
1712
1788
|
/**
|
|
1713
1789
|
* Meeting start time.
|
|
1714
1790
|
* @example new Date("2026-04-10T10:00:00.000Z")
|
|
@@ -1719,8 +1795,19 @@ interface CreateMeetingParams {
|
|
|
1719
1795
|
* @example new Date("2026-04-10T10:30:00.000Z")
|
|
1720
1796
|
*/
|
|
1721
1797
|
endTime: Date | string;
|
|
1798
|
+
/** Duration in minutes. */
|
|
1799
|
+
duration?: number;
|
|
1800
|
+
/** Whether the meeting is online (Google Meet) or offline (In-person). */
|
|
1801
|
+
meetingMode?: "online" | "offline";
|
|
1802
|
+
/** Whether this is a free or paid consultation. */
|
|
1803
|
+
type?: "free" | "paid";
|
|
1804
|
+
/** Amount charged for paid consultations. */
|
|
1805
|
+
amount?: number;
|
|
1722
1806
|
/** Arbitrary metadata to attach to the meeting record. */
|
|
1723
|
-
metadata?:
|
|
1807
|
+
metadata?: {
|
|
1808
|
+
refs?: Record<string, string | undefined>;
|
|
1809
|
+
extra?: Record<string, any>;
|
|
1810
|
+
};
|
|
1724
1811
|
}
|
|
1725
1812
|
/**
|
|
1726
1813
|
* Parameters for updating an existing meeting.
|
|
@@ -1730,15 +1817,17 @@ interface UpdateMeetingParams {
|
|
|
1730
1817
|
* Update the meeting status.
|
|
1731
1818
|
* @example "scheduled" | "completed" | "cancelled"
|
|
1732
1819
|
*/
|
|
1733
|
-
status?: string;
|
|
1820
|
+
status?: "scheduled" | "completed" | "cancelled" | string;
|
|
1734
1821
|
/** Update the payment status for paid consultations. */
|
|
1735
|
-
paymentStatus?: string;
|
|
1822
|
+
paymentStatus?: "pending" | "paid" | "na" | string;
|
|
1736
1823
|
/** New start time for rescheduling. */
|
|
1737
1824
|
startTime?: Date | string;
|
|
1738
1825
|
/** New end time for rescheduling. */
|
|
1739
1826
|
endTime?: Date | string;
|
|
1740
1827
|
/** Duration in minutes. */
|
|
1741
1828
|
duration?: number;
|
|
1829
|
+
/** Update metadata. */
|
|
1830
|
+
metadata?: any;
|
|
1742
1831
|
}
|
|
1743
1832
|
/**
|
|
1744
1833
|
* Google Meet appointment scheduling resource.
|
|
@@ -2184,9 +2273,6 @@ declare class RateLimitError extends APIError {
|
|
|
2184
2273
|
constructor(message?: string);
|
|
2185
2274
|
}
|
|
2186
2275
|
|
|
2187
|
-
declare class WebhookSignatureError extends APIError {
|
|
2188
|
-
constructor(message: string);
|
|
2189
|
-
}
|
|
2190
2276
|
/**
|
|
2191
2277
|
* Validates and constructs webhook events sent by the ECODrIx platform.
|
|
2192
2278
|
* Ensures the payload has not been tampered with.
|
|
@@ -3110,12 +3196,12 @@ declare class Checkout extends APIResource {
|
|
|
3110
3196
|
}
|
|
3111
3197
|
|
|
3112
3198
|
/**
|
|
3113
|
-
* Configuration options for the
|
|
3199
|
+
* Configuration options for the ECODrIxAPI client.
|
|
3114
3200
|
*
|
|
3115
3201
|
* Minimum required: `apiKey` and `clientCode`.
|
|
3116
3202
|
* The backend URL is managed internally and should not need to be changed.
|
|
3117
3203
|
*/
|
|
3118
|
-
interface
|
|
3204
|
+
interface ECODrIxAPIOptions {
|
|
3119
3205
|
/**
|
|
3120
3206
|
* Your ECODrIx Platform API key.
|
|
3121
3207
|
* Obtain this from the ECODrIx dashboard under Settings → API Keys.
|
|
@@ -3152,9 +3238,9 @@ interface EcodrixOptions {
|
|
|
3152
3238
|
*
|
|
3153
3239
|
* @example
|
|
3154
3240
|
* ```typescript
|
|
3155
|
-
* import {
|
|
3241
|
+
* import { ECODrIxAPI } from "@ecodrix/erix-api";
|
|
3156
3242
|
*
|
|
3157
|
-
* const ecod = new
|
|
3243
|
+
* const ecod = new ECODrIxAPI({
|
|
3158
3244
|
* apiKey: process.env.ECOD_API_KEY!,
|
|
3159
3245
|
* clientCode: "ERIX_CLNT_JHBJHF",
|
|
3160
3246
|
* });
|
|
@@ -3163,7 +3249,7 @@ interface EcodrixOptions {
|
|
|
3163
3249
|
* const lead = await ecod.crm.leads.create({ firstName: "Alice", phone: "+91..." });
|
|
3164
3250
|
* ```
|
|
3165
3251
|
*/
|
|
3166
|
-
declare class
|
|
3252
|
+
declare class ECODrIxAPI {
|
|
3167
3253
|
/**
|
|
3168
3254
|
* @internal Axios HTTP client for making API requests.
|
|
3169
3255
|
*/
|
|
@@ -3214,7 +3300,7 @@ declare class Ecodrix {
|
|
|
3214
3300
|
readonly cors: Cors;
|
|
3215
3301
|
/** ErixCheckout one-click checkout flow management. */
|
|
3216
3302
|
readonly checkout: Checkout;
|
|
3217
|
-
constructor(options:
|
|
3303
|
+
constructor(options: ECODrIxAPIOptions);
|
|
3218
3304
|
/**
|
|
3219
3305
|
* Join a specific real-time room (e.g., a conversation or a lead).
|
|
3220
3306
|
*
|
|
@@ -3295,4 +3381,4 @@ declare class Ecodrix {
|
|
|
3295
3381
|
request<T = any>(method: Method, path: string, data?: any, params?: any): Promise<T>;
|
|
3296
3382
|
}
|
|
3297
3383
|
|
|
3298
|
-
export { APIError,
|
|
3384
|
+
export { APIError, type ApplyCouponPayload, AuthenticationError, type CheckoutAmountBreakdown, type CheckoutOrderResponse, type CheckoutProduct, type CheckoutSession, type CreateOrderPayload, type CreateSessionPayload, ECODrIxAPI as ECODrIx, ECODrIxAPI, type ECODrIxAPIOptions, EcodrixError, type FieldManifest, type FieldType, RateLimitError, type ResourceManifest, type VerifyPayload, ECODrIxAPI as default };
|