@ecodrix/erix-api 1.2.1 → 1.2.3

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.
@@ -1603,15 +1603,25 @@ declare class Media extends APIResource {
1603
1603
  */
1604
1604
  createFolder(name: string): Promise<unknown>;
1605
1605
  /**
1606
- * List files within a specific folder, with optional date filtering.
1606
+ * List files within a folder, with optional date / search filtering.
1607
1607
  *
1608
- * @param folder - The folder key to list.
1609
- * @param params - Optional `year`, `month`, and search `q` filters.
1610
- * @returns Array of file metadata objects.
1608
+ * @param folder - The folder name to list, **or `"*"` to fetch all folders**
1609
+ * for the tenant in a single call (returns a merged flat list with a
1610
+ * `folder` field on each file so callers can group/filter client-side).
1611
+ * @param params - Optional `year`, `month`, and keyword search `q` filters.
1612
+ * @returns `{ data: { files, count, totalSizeBytes } }`.
1611
1613
  *
1612
- * @example
1614
+ * @example Single folder
1615
+ * ```typescript
1616
+ * const { data } = await ecod.media.list("invoices", { q: "contract" });
1617
+ * // data.files → files only from the "invoices" folder
1618
+ * ```
1619
+ *
1620
+ * @example All folders
1613
1621
  * ```typescript
1614
- * const { data: files } = await ecod.media.list("invoices", { q: "contract" });
1622
+ * const { data } = await ecod.media.list("*");
1623
+ * // data.files → merged files from every folder the tenant has
1624
+ * // Each file has a `folder` field indicating its source folder
1615
1625
  * ```
1616
1626
  */
1617
1627
  list(folder: string, params?: {
@@ -2830,6 +2840,12 @@ declare class Ecodrix {
2830
2840
  * @internal Socket.io client for real-time events.
2831
2841
  */
2832
2842
  private readonly socket;
2843
+ /**
2844
+ * The tenant client code this SDK instance is scoped to.
2845
+ * Useful for components that need to read the clientCode back
2846
+ * from a context-provided SDK instance.
2847
+ */
2848
+ readonly clientCode: string | undefined;
2833
2849
  /** WhatsApp messaging and conversation management. */
2834
2850
  readonly whatsapp: WhatsApp;
2835
2851
  /** CRM resources — Leads and related sub-resources. */
@@ -1603,15 +1603,25 @@ declare class Media extends APIResource {
1603
1603
  */
1604
1604
  createFolder(name: string): Promise<unknown>;
1605
1605
  /**
1606
- * List files within a specific folder, with optional date filtering.
1606
+ * List files within a folder, with optional date / search filtering.
1607
1607
  *
1608
- * @param folder - The folder key to list.
1609
- * @param params - Optional `year`, `month`, and search `q` filters.
1610
- * @returns Array of file metadata objects.
1608
+ * @param folder - The folder name to list, **or `"*"` to fetch all folders**
1609
+ * for the tenant in a single call (returns a merged flat list with a
1610
+ * `folder` field on each file so callers can group/filter client-side).
1611
+ * @param params - Optional `year`, `month`, and keyword search `q` filters.
1612
+ * @returns `{ data: { files, count, totalSizeBytes } }`.
1611
1613
  *
1612
- * @example
1614
+ * @example Single folder
1615
+ * ```typescript
1616
+ * const { data } = await ecod.media.list("invoices", { q: "contract" });
1617
+ * // data.files → files only from the "invoices" folder
1618
+ * ```
1619
+ *
1620
+ * @example All folders
1613
1621
  * ```typescript
1614
- * const { data: files } = await ecod.media.list("invoices", { q: "contract" });
1622
+ * const { data } = await ecod.media.list("*");
1623
+ * // data.files → merged files from every folder the tenant has
1624
+ * // Each file has a `folder` field indicating its source folder
1615
1625
  * ```
1616
1626
  */
1617
1627
  list(folder: string, params?: {
@@ -2830,6 +2840,12 @@ declare class Ecodrix {
2830
2840
  * @internal Socket.io client for real-time events.
2831
2841
  */
2832
2842
  private readonly socket;
2843
+ /**
2844
+ * The tenant client code this SDK instance is scoped to.
2845
+ * Useful for components that need to read the clientCode back
2846
+ * from a context-provided SDK instance.
2847
+ */
2848
+ readonly clientCode: string | undefined;
2833
2849
  /** WhatsApp messaging and conversation management. */
2834
2850
  readonly whatsapp: WhatsApp;
2835
2851
  /** CRM resources — Leads and related sub-resources. */
@@ -1,2 +1,2 @@
1
- var ge=Object.defineProperty,me=Object.defineProperties;var ue=Object.getOwnPropertyDescriptors;var ie=Object.getOwnPropertySymbols;var de=Object.prototype.hasOwnProperty,ye=Object.prototype.propertyIsEnumerable;var he=(s,e)=>(e=Symbol[s])?e:Symbol.for("Symbol."+s);var W=(s,e,t)=>e in s?ge(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,d=(s,e)=>{for(var t in e||(e={}))de.call(e,t)&&W(s,t,e[t]);if(ie)for(var t of ie(e))ye.call(e,t)&&W(s,t,e[t]);return s},f=(s,e)=>me(s,ue(e));var i=(s,e,t)=>W(s,typeof e!="symbol"?e+"":e,t);var z=function(s,e){this[0]=s,this[1]=e},oe=(s,e,t)=>{var a=(c,l,p,u)=>{try{var y=t[c](l),h=(l=y.value)instanceof z,T=y.done;Promise.resolve(h?l[0]:l).then(m=>h?a(c==="return"?c:"next",l[1]?{done:m.done,value:m.value}:m,p,u):p({value:m,done:T})).catch(m=>a("throw",m,p,u))}catch(m){u(m)}},r=c=>o[c]=l=>new Promise((p,u)=>a(c,l,p,u)),o={};return t=t.apply(s,e),o[he("asyncIterator")]=()=>o,r("next"),r("throw"),r("return"),o};import fe from"axios";import ae from"axios-retry";import{io as be}from"socket.io-client";var G=class extends Error{constructor(e){super(e),this.name="EcodrixError"}},g=class extends G{constructor(t,a,r){super(t);i(this,"status");i(this,"code");this.name="APIError",this.status=a,this.code=r}},w=class extends g{constructor(e="Invalid API Key or Client Code"){super(e,401,"AUTH_FAILED"),this.name="AuthenticationError"}},ce=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){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=d({},e);return e.idempotencyKey&&(t.headers=f(d({},t.headers),{"Idempotency-Key":e.idempotencyKey})),t}handleError(e){var t,a,r;throw e.response?new g(((t=e.response.data)==null?void 0:t.message)||((a=e.response.data)==null?void 0:a.error)||"API Request Failed",e.response.status,(r=e.response.data)==null?void 0:r.code):new g(e.message||"Network Error")}};var X=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}`)}},R=class extends n{constructor(t){super(t);i(this,"notes");this.notes=new X(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:d({},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 $=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 A=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 C=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/webhook-event",{ruleId:e,eventName:t,payload:a})}};var I=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 list(e){let t=d({},e);return Array.isArray(t.tags)&&(t.tags=t.tags.join(",")),this.get("/api/crm/leads",{params:t})}listAutoPaging(e){return oe(this,null,function*(){let t=(e==null?void 0:e.page)||1,a=!0;for(;a;){let r=yield new z(this.list(f(d({},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 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 bulkDelete(e){return this.deleteRequest("/api/crm/leads",{data:{ids:e}})}};var k=class extends n{async capture(e){return this.post("/api/crm/payments/capture",e)}};var q=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 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 L=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 E=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 S=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 I(e),this.pipelines=new q(e),this.activities=new R(e),this.analytics=new $(e),this.automations=new C(e),this.sequences=new E(e),this.scoring=new L(e),this.payments=new k(e),this.automationDashboard=new A(e)}};var x=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)}},pe=class extends x{};var D=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 U=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 M=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 Y=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)}},N=class extends n{constructor(t){super(t);i(this,"emails");i(this,"campaigns");i(this,"whatsapp");this.emails=new Y(t),this.campaigns=new Z(t),this.whatsapp=new ee(t)}};import Te from"axios";var v=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 a=await this.post("/api/saas/storage/upload-url",t),{uploadUrl:r,key:o}=a.data;await Te.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})}},le=class extends v{};var O=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 B=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 F=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}})}},H=class extends n{constructor(t){super(t);i(this,"folders");i(this,"files");this.folders=new te(t),this.files=new se(t)}async usage(){return this.get("/api/saas/storage/usage")}};var b=class extends g{constructor(e){super(e,400,"invalid_signature"),this.name="WebhookSignatureError"}},_=class{async constructEvent(e,t,a){if(!t)throw new b("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 b("Invalid webhook signature provided");return JSON.parse(e.toString("utf8"))}catch(o){throw o instanceof b?o:new b(`Webhook payload parsing failed: ${o.message}`)}}};var j=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 V=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 K=class extends n{async send(e){return this.post("/api/saas/chat/send",e)}async sendTemplate(e){return this.post("/api/saas/chat/send",f(d({},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 J=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 u of p){let y=u.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 Q=class extends n{constructor(t){super(t);i(this,"messages");i(this,"conversations");i(this,"broadcasts");i(this,"templates");this.messages=new K(t),this.conversations=new V(t),this.broadcasts=new j(t),this.templates=new J(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 xe="https://api.ecodrix.com",P=class{constructor(e){i(this,"client");i(this,"socket");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");var l,p,u,y;if(!e.apiKey)throw new w("API Key is required");let t=(l=e.baseUrl)!=null?l:xe,a=e.socketUrl||t,r=typeof window!="undefined"&&typeof window.document!="undefined",o=r?"browser":typeof process!="undefined"?`node ${process.version}`:"unknown",c=r?((p=globalThis.navigator)==null?void 0:p.userAgent)||"browser":typeof process!="undefined"?process.platform:"unknown";this.client=fe.create({baseURL:t,headers:{"x-api-key":e.apiKey,"x-client-code":(u=e.clientCode)==null?void 0:u.toUpperCase(),"Content-Type":"application/json","x-ecodrix-client-agent":JSON.stringify({sdk_version:"1.0.0",runtime:o,os:c})}}),ae(this.client,{retries:3,retryDelay:ae.exponentialDelay,retryCondition:h=>{var T;return ae.isNetworkOrIdempotentRequestError(h)||((T=h.response)==null?void 0:T.status)===429},onRetry:(h,T,m)=>{var re,ne;typeof process!="undefined"&&((re=process.env)==null?void 0:re.NODE_ENV)==="development"&&console.warn(`[ECODrIx SDK] Retrying request (${h}/3): ${(ne=m.method)==null?void 0:ne.toUpperCase()} ${m.url}. Reason: ${T.message}`)}}),this.whatsapp=new Q(this.client),this.crm=new S(this.client),this.media=new v(this.client),this.meet=new O(this.client),this.notifications=new B(this.client),this.email=new x(this.client),this.logs=new M(this.client),this.events=new D(this.client),this.webhooks=new _,this.storage=new H(this.client),this.marketing=new N(this.client),this.health=new U(this.client),this.queue=new F(this.client),this.socket=be(a,{extraHeaders:{"x-api-key":e.apiKey,"x-client-code":((y=e.clientCode)==null?void 0:y.toUpperCase())||""}}),this.setupSocket(e.clientCode)}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,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 ms=P;export{g as APIError,R as Activities,$ as Analytics,w as AuthenticationError,A as AutomationDashboard,C as Automations,j as Broadcasts,S as CRM,Z as Campaigns,V as Conversations,P as Ecodrix,G as EcodrixError,x as Email,pe as EmailResource,Y as Emails,D as EventsResource,se as Files,te as Folders,U as Health,I as Leads,M as Logs,N as Marketing,v as Media,le as MediaResource,O as Meetings,K as Messages,X as Notes,B as Notifications,k as Payments,q as Pipelines,F as Queue,ce as RateLimitError,L as Scoring,E as Sequences,H as Storage,J as Templates,b as WebhookSignatureError,_ as Webhooks,Q as WhatsApp,ee as WhatsAppMarketing,ms as default};
1
+ var me=Object.defineProperty,ue=Object.defineProperties;var de=Object.getOwnPropertyDescriptors;var oe=Object.getOwnPropertySymbols;var ye=Object.prototype.hasOwnProperty,he=Object.prototype.propertyIsEnumerable;var Te=(a,e)=>(e=Symbol[a])?e:Symbol.for("Symbol."+a);var W=(a,e,t)=>e in a?me(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t,d=(a,e)=>{for(var t in e||(e={}))ye.call(e,t)&&W(a,t,e[t]);if(oe)for(var t of oe(e))he.call(e,t)&&W(a,t,e[t]);return a},T=(a,e)=>ue(a,de(e));var i=(a,e,t)=>W(a,typeof e!="symbol"?e+"":e,t);var z=function(a,e){this[0]=a,this[1]=e},ce=(a,e,t)=>{var r=(c,l,p,u)=>{try{var y=t[c](l),b=(l=y.value)instanceof z,h=y.done;Promise.resolve(b?l[0]:l).then(g=>b?r(c==="return"?c:"next",l[1]?{done:g.done,value:g.value}:g,p,u):p({value:g,done:h})).catch(g=>r("throw",g,p,u))}catch(g){u(g)}},s=c=>o[c]=l=>new Promise((p,u)=>r(c,l,p,u)),o={};return t=t.apply(a,e),o[Te("asyncIterator")]=()=>o,s("next"),s("throw"),s("return"),o};import be from"axios";import ae from"axios-retry";import{io as xe}from"socket.io-client";var X=class extends Error{constructor(e){super(e),this.name="EcodrixError"}},m=class extends X{constructor(t,r,s){super(t);i(this,"status");i(this,"code");this.name="APIError",this.status=r,this.code=s}},w=class extends m{constructor(e="Invalid API Key or Client Code"){super(e,401,"AUTH_FAILED"),this.name="AuthenticationError"}},pe=class extends m{constructor(e="Too many requests. Please slow down."){super(e,429,"RATE_LIMIT_EXCEEDED"),this.name="RateLimitError"}};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=d({},e);return e.idempotencyKey&&(t.headers=T(d({},t.headers),{"Idempotency-Key":e.idempotencyKey})),t}handleError(e){var t,r,s;throw e.response?new m(((t=e.response.data)==null?void 0:t.message)||((r=e.response.data)==null?void 0:r.error)||"API Request Failed",e.response.status,(s=e.response.data)==null?void 0:s.code):new m(e.message||"Network Error")}};var G=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}`)}},R=class extends n{constructor(t){super(t);i(this,"notes");this.notes=new G(t)}async timeline(t,r){return this.get(`/api/crm/leads/${t}/timeline`,{params:r})}async list(t,r){return this.get(`/api/crm/leads/${t}/activities`,{params:d({},r)})}async log(t){return this.post(`/api/crm/leads/${t.leadId}/activities`,t)}async logCall(t,r){return this.post(`/api/crm/leads/${t}/calls`,r)}};var A=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 $=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 C=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 I=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(o=>({key:`metadata.extra.${o.name}`,label:o.label||o.name,type:o.type||"string",required:!!o.required,options:o.options,group:"Custom Fields"}));return{name:"Lead",fields:[...r,...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 c=e.slice(s,s+t).map(p=>this.create(p)),l=await Promise.allSettled(c);for(let p of l)if(p.status==="fulfilled")r.push(p.value);else throw p.reason}return r}async import(e){return this.post("/api/crm/leads/import",{leads:e})}async list(e){let t=d({},e);return Array.isArray(t.tags)&&(t.tags=t.tags.join(",")),this.get("/api/crm/leads",{params:t})}listAutoPaging(e){return ce(this,null,function*(){let t=(e==null?void 0:e.page)||1,r=!0;for(;r;){let s=yield new z(this.list(T(d({},e),{page:t}))),o=Array.isArray(s.data)?s.data:s||[];if(o.length===0){r=!1;break}for(let c of o)yield c;s.pagination&&t<s.pagination.pages||!s.pagination&&o.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 k=class extends n{async capture(e){return this.post("/api/crm/payments/capture",e)}};var q=class extends n{async list(){return this.get("/api/crm/pipelines")}async getStageManifest(e){var s,o;let t=await this.retrieve(e),r=Array.isArray((s=t.data)==null?void 0:s.stages)?t.data.stages:[];return{name:`Pipeline: ${((o=t.data)==null?void 0:o.name)||e}`,fields:r.map(c=>({key:c._id,label:c.name,type:"string",required:!0,options:[{label:c.name,value:c._id}],group:"Stages",uiHints:{color:c.color||"#cbd5e1",probability:c.probability}})),uiHints:{icon:"Columns",primaryColor:"#6366f1"}}}async create(e){return this.post("/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 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 E=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 L=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 S=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 I(e),this.pipelines=new q(e),this.activities=new R(e),this.analytics=new A(e),this.automations=new C(e),this.sequences=new L(e),this.scoring=new E(e),this.payments=new k(e),this.automationDashboard=new $(e)}};var x=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)}},le=class extends x{};var D=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 U=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 M=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 Y=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)}},N=class extends n{constructor(t){super(t);i(this,"emails");i(this,"campaigns");i(this,"whatsapp");this.emails=new Y(t),this.campaigns=new Z(t),this.whatsapp=new ee(t)}};import fe from"axios";var v=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:o}=r.data;await fe.put(s,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})}},ge=class extends v{};var O=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 _=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 B=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}})}},F=class extends n{constructor(t){super(t);i(this,"folders");i(this,"files");this.folders=new te(t),this.files=new se(t)}async usage(){return this.get("/api/saas/storage/usage")}};var f=class extends m{constructor(e){super(e,400,"invalid_signature"),this.name="WebhookSignatureError"}},H=class{async constructEvent(e,t,r){if(!t)throw new f("No webhook signature provided");let s=Array.isArray(t)?t[0]:t;s.startsWith("sha256=")&&(s=s.slice(7));try{let o=await import("crypto"),l=o.createHmac("sha256",r).update(e).digest("hex");if(!o.timingSafeEqual(Buffer.from(l),Buffer.from(s)))throw new f("Invalid webhook signature provided");return JSON.parse(e.toString("utf8"))}catch(o){throw o instanceof f?o:new f(`Webhook payload parsing failed: ${o.message}`)}}};var j=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 K=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 V=class extends n{async send(e){return this.post("/api/saas/chat/send",e)}async sendTemplate(e){return this.post("/api/saas/chat/send",T(d({},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 J=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),r=Array.isArray((o=t.data)==null?void 0:o.components)?t.data.components:[],s=[];for(let l of r)if(l.text){let p=l.text.match(/{{(\d+)}}/g);if(p)for(let u of p){let y=u.replace(/{{|}}/g,"");s.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:s,uiHints:{icon:"Variables",primaryColor:"#059669"}}}async checkUsage(e){return this.get(`/api/saas/chat/templates/${encodeURIComponent(e)}/usage`)}};var Q=class extends n{constructor(t){super(t);i(this,"messages");i(this,"conversations");i(this,"broadcasts");i(this,"templates");this.messages=new V(t),this.conversations=new K(t),this.broadcasts=new j(t),this.templates=new J(t)}async upload(t,r){let s=new FormData;return s.append("file",t,r),this.post("/api/saas/chat/upload",s,{headers:typeof s.getHeaders=="function"?s.getHeaders():void 0})}async sendTemplate(t){return this.post("/api/saas/marketing/whatsapp/send-template",t)}};var ve="https://api.ecodrix.com",P=class{constructor(e){i(this,"client");i(this,"socket");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");var l,p,u,y,b;if(!e.apiKey)throw new w("API Key is required");this.clientCode=(l=e.clientCode)==null?void 0:l.toUpperCase();let t=(p=e.baseUrl)!=null?p:ve,r=e.socketUrl||t,s=typeof window!="undefined"&&typeof window.document!="undefined",o=s?"browser":typeof process!="undefined"?`node ${process.version}`:"unknown",c=s?((u=globalThis.navigator)==null?void 0:u.userAgent)||"browser":typeof process!="undefined"?process.platform:"unknown";if(this.client=be.create({baseURL:t,headers:{"x-api-key":e.apiKey,"x-client-code":(y=e.clientCode)==null?void 0:y.toUpperCase(),"Content-Type":"application/json","x-ecodrix-client-agent":JSON.stringify({sdk_version:"1.0.0",runtime:o,os:c})}}),ae(this.client,{retries:3,retryDelay:ae.exponentialDelay,retryCondition:h=>{var g;return ae.isNetworkOrIdempotentRequestError(h)||((g=h.response)==null?void 0:g.status)===429},onRetry:(h,g,re)=>{var ne,ie;typeof process!="undefined"&&((ne=process.env)==null?void 0:ne.NODE_ENV)==="development"&&console.warn(`[ECODrIx SDK] Retrying request (${h}/3): ${(ie=re.method)==null?void 0:ie.toUpperCase()} ${re.url}. Reason: ${g.message}`)}}),this.whatsapp=new Q(this.client),this.crm=new S(this.client),this.media=new v(this.client),this.meet=new O(this.client),this.notifications=new _(this.client),this.email=new x(this.client),this.logs=new M(this.client),this.events=new D(this.client),this.webhooks=new H,this.storage=new F(this.client),this.marketing=new N(this.client),this.health=new U(this.client),this.queue=new B(this.client),this.socket=xe(r,{extraHeaders:{"x-api-key":e.apiKey,"x-client-code":((b=e.clientCode)==null?void 0:b.toUpperCase())||""}}),this.setupSocket(e.clientCode),s){let h={version:"1.2.2",clientCode:e.clientCode,initializedAt:new Date().toISOString()};window.__ECODRIX_SDK__=h,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){var o,c,l;try{return(await this.client.request({method:e,url:t,data:r,params:s})).data}catch(p){throw p.response?new m(((o=p.response.data)==null?void 0:o.message)||((c=p.response.data)==null?void 0:c.error)||"Raw Execution Failed",p.response.status,(l=p.response.data)==null?void 0:l.code):new m(p.message||"Network Error")}}};var us=P;export{m as APIError,R as Activities,A as Analytics,w as AuthenticationError,$ as AutomationDashboard,C as Automations,j as Broadcasts,S as CRM,Z as Campaigns,K as Conversations,P as Ecodrix,X as EcodrixError,x as Email,le as EmailResource,Y as Emails,D as EventsResource,se as Files,te as Folders,U as Health,I as Leads,M as Logs,N as Marketing,v as Media,ge as MediaResource,O as Meetings,V as Messages,G as Notes,_ as Notifications,k as Payments,q as Pipelines,B as Queue,pe as RateLimitError,E as Scoring,L as Sequences,F as Storage,J as Templates,f as WebhookSignatureError,H as Webhooks,Q as WhatsApp,ee as WhatsAppMarketing,us as default};
2
2
  //# sourceMappingURL=index.js.map