@ecodrix/erix-api 1.3.1 → 1.3.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.
@@ -829,6 +829,10 @@ declare class Pipelines extends APIResource {
829
829
  * Delete a pipeline permanently.
830
830
  */
831
831
  delete(pipelineId: string): Promise<unknown>;
832
+ /**
833
+ * Check if a pipeline is in use (e.g. has leads attached).
834
+ */
835
+ checkInUse<T = any>(pipelineId: string): Promise<T>;
832
836
  /**
833
837
  * Retrieve a Kanban-style board representation of the pipeline with leads nested.
834
838
  *
@@ -3007,6 +3011,104 @@ declare class Cors extends APIResource {
3007
3011
  delete<T = any>(id: string): Promise<T>;
3008
3012
  }
3009
3013
 
3014
+ interface CheckoutProduct {
3015
+ externalId: string;
3016
+ name: string;
3017
+ price: number;
3018
+ image?: string;
3019
+ }
3020
+ interface CheckoutAmountBreakdown {
3021
+ subtotal: number;
3022
+ discount: number;
3023
+ delivery: number;
3024
+ total: number;
3025
+ }
3026
+ interface CheckoutSession {
3027
+ sessionId: string;
3028
+ product: {
3029
+ name: string;
3030
+ price: number;
3031
+ image?: string;
3032
+ };
3033
+ amounts: CheckoutAmountBreakdown;
3034
+ items: Array<{
3035
+ productId: string;
3036
+ quantity: number;
3037
+ }>;
3038
+ }
3039
+ interface CreateSessionPayload {
3040
+ productId: string;
3041
+ quantity: number;
3042
+ couponCode?: string;
3043
+ }
3044
+ interface ApplyCouponPayload {
3045
+ sessionId: string;
3046
+ couponCode: string;
3047
+ }
3048
+ interface VerifyPayload {
3049
+ sessionId: string;
3050
+ method: "truecaller" | "otp";
3051
+ token?: string;
3052
+ phone?: string;
3053
+ otp?: string;
3054
+ }
3055
+ interface CreateOrderPayload {
3056
+ sessionId: string;
3057
+ customer: {
3058
+ name: string;
3059
+ phone: string;
3060
+ email?: string;
3061
+ address: {
3062
+ line1: string;
3063
+ city: string;
3064
+ state: string;
3065
+ pincode: string;
3066
+ };
3067
+ };
3068
+ paymentProvider: "razorpay" | "cod";
3069
+ }
3070
+ interface CheckoutOrderResponse {
3071
+ order_id: string;
3072
+ payment_order_id?: string;
3073
+ amount?: number;
3074
+ currency?: string;
3075
+ status?: string;
3076
+ message?: string;
3077
+ }
3078
+
3079
+ /**
3080
+ * Resource for managing the ErixCheckout one-click flow.
3081
+ *
3082
+ * This resource handles session creation, coupon application,
3083
+ * identity verification, and final order placement.
3084
+ */
3085
+ declare class Checkout extends APIResource {
3086
+ /**
3087
+ * Retrieves product information for the checkout modal.
3088
+ * @param productId - External SKU/ID of the product.
3089
+ */
3090
+ getProduct(productId: string): Promise<CheckoutProduct>;
3091
+ /**
3092
+ * Initializes a new checkout session.
3093
+ */
3094
+ createSession(payload: CreateSessionPayload): Promise<CheckoutSession>;
3095
+ /**
3096
+ * Applies a discount coupon to an active session.
3097
+ */
3098
+ applyCoupon(payload: ApplyCouponPayload): Promise<CheckoutSession>;
3099
+ /**
3100
+ * Verifies user identity via Truecaller or OTP.
3101
+ */
3102
+ verify(payload: VerifyPayload): Promise<{
3103
+ verified: boolean;
3104
+ data?: any;
3105
+ }>;
3106
+ /**
3107
+ * Finalizes the order and initiates payment.
3108
+ */
3109
+ createOrder(payload: CreateOrderPayload): Promise<CheckoutOrderResponse>;
3110
+ }
3111
+
3010
3112
  /**
3011
3113
  * Configuration options for the Ecodrix client.
3012
3114
  *
@@ -3110,6 +3212,8 @@ declare class Ecodrix {
3110
3212
  readonly settings: Settings;
3111
3213
  /** Dynamic Cross-Origin Resource Sharing network policies. */
3112
3214
  readonly cors: Cors;
3215
+ /** ErixCheckout one-click checkout flow management. */
3216
+ readonly checkout: Checkout;
3113
3217
  constructor(options: EcodrixOptions);
3114
3218
  /**
3115
3219
  * Join a specific real-time room (e.g., a conversation or a lead).
@@ -3191,4 +3295,4 @@ declare class Ecodrix {
3191
3295
  request<T = any>(method: Method, path: string, data?: any, params?: any): Promise<T>;
3192
3296
  }
3193
3297
 
3194
- export { APIError, Activities, Agency, Analytics, type AnalyticsParams, type AnalyticsRange, type AssignEventPayload, AuthenticationError, AutomationDashboard, type AutomationRulePayload, Automations, Blogs, Broadcasts, CRM, type CallbackLog, type CampaignResult, Campaigns, type ChatMediaMeta, type ClientHealth, Clients, Conversations, Cors, type CorsOriginCreatePayload, type CorsOriginUpdatePayload, type CreateBroadcastParams, type CreateLeadParams, type CreateMeetingParams, type CreatePipelineParams, type CreateTemplateDTO, Ecodrix, EcodrixError, type EcodrixOptions, Email, EmailConfig, EmailResource, type EmailTemplate, Emails, type EventDefinition, type EventLog, EventsResource, type FieldManifest, type FieldType, Files, Folders, GlobalLeads, Health, type JobStats, type JobStatus, type LeadSource, type LeadStatus, Leads, type ListLeadsParams, type ListParams, type LogActivityParams, type LogCallParams, type LogFilter, type LogPaginationQuery, type LogResponse, Logs, Marketing, Media, MediaResource, Meetings, Messages, Notes, Notifications, Payments, type PipelineStageParams, Pipelines, Queue, RateLimitError, type ResourceManifest, Scoring, type ScoringConfig, type SendCampaignParams, type SendCampaignPayload, type SendMessageParams, type SendTemplateParams, type SendTemplatePayload, Sequences, Services, Settings, Storage, type SystemHealth, type TemplateMapping, type TemplatePreviewResponse, Templates, type TriggerPayload, type TriggerResponse, type UpdateMeetingParams, type UploadOptions, type UpsertLeadParams, WebhookSignatureError, Webhooks, WhatsApp, WhatsAppMarketing, Ecodrix as default };
3298
+ export { APIError, Activities, Agency, Analytics, type AnalyticsParams, type AnalyticsRange, type ApplyCouponPayload, type AssignEventPayload, AuthenticationError, AutomationDashboard, type AutomationRulePayload, Automations, Blogs, Broadcasts, CRM, type CallbackLog, type CampaignResult, Campaigns, type ChatMediaMeta, Checkout, type CheckoutAmountBreakdown, type CheckoutOrderResponse, type CheckoutProduct, type CheckoutSession, type ClientHealth, Clients, Conversations, Cors, type CorsOriginCreatePayload, type CorsOriginUpdatePayload, type CreateBroadcastParams, type CreateLeadParams, type CreateMeetingParams, type CreateOrderPayload, type CreatePipelineParams, type CreateSessionPayload, type CreateTemplateDTO, Ecodrix, EcodrixError, type EcodrixOptions, Email, EmailConfig, EmailResource, type EmailTemplate, Emails, type EventDefinition, type EventLog, EventsResource, type FieldManifest, type FieldType, Files, Folders, GlobalLeads, Health, type JobStats, type JobStatus, type LeadSource, type LeadStatus, Leads, type ListLeadsParams, type ListParams, type LogActivityParams, type LogCallParams, type LogFilter, type LogPaginationQuery, type LogResponse, Logs, Marketing, Media, MediaResource, Meetings, Messages, Notes, Notifications, Payments, type PipelineStageParams, Pipelines, Queue, RateLimitError, type ResourceManifest, Scoring, type ScoringConfig, type SendCampaignParams, type SendCampaignPayload, type SendMessageParams, type SendTemplateParams, type SendTemplatePayload, Sequences, Services, Settings, Storage, type SystemHealth, type TemplateMapping, type TemplatePreviewResponse, Templates, type TriggerPayload, type TriggerResponse, type UpdateMeetingParams, type UploadOptions, type UpsertLeadParams, type VerifyPayload, WebhookSignatureError, Webhooks, WhatsApp, WhatsAppMarketing, Ecodrix as default };
@@ -829,6 +829,10 @@ declare class Pipelines extends APIResource {
829
829
  * Delete a pipeline permanently.
830
830
  */
831
831
  delete(pipelineId: string): Promise<unknown>;
832
+ /**
833
+ * Check if a pipeline is in use (e.g. has leads attached).
834
+ */
835
+ checkInUse<T = any>(pipelineId: string): Promise<T>;
832
836
  /**
833
837
  * Retrieve a Kanban-style board representation of the pipeline with leads nested.
834
838
  *
@@ -3007,6 +3011,104 @@ declare class Cors extends APIResource {
3007
3011
  delete<T = any>(id: string): Promise<T>;
3008
3012
  }
3009
3013
 
3014
+ interface CheckoutProduct {
3015
+ externalId: string;
3016
+ name: string;
3017
+ price: number;
3018
+ image?: string;
3019
+ }
3020
+ interface CheckoutAmountBreakdown {
3021
+ subtotal: number;
3022
+ discount: number;
3023
+ delivery: number;
3024
+ total: number;
3025
+ }
3026
+ interface CheckoutSession {
3027
+ sessionId: string;
3028
+ product: {
3029
+ name: string;
3030
+ price: number;
3031
+ image?: string;
3032
+ };
3033
+ amounts: CheckoutAmountBreakdown;
3034
+ items: Array<{
3035
+ productId: string;
3036
+ quantity: number;
3037
+ }>;
3038
+ }
3039
+ interface CreateSessionPayload {
3040
+ productId: string;
3041
+ quantity: number;
3042
+ couponCode?: string;
3043
+ }
3044
+ interface ApplyCouponPayload {
3045
+ sessionId: string;
3046
+ couponCode: string;
3047
+ }
3048
+ interface VerifyPayload {
3049
+ sessionId: string;
3050
+ method: "truecaller" | "otp";
3051
+ token?: string;
3052
+ phone?: string;
3053
+ otp?: string;
3054
+ }
3055
+ interface CreateOrderPayload {
3056
+ sessionId: string;
3057
+ customer: {
3058
+ name: string;
3059
+ phone: string;
3060
+ email?: string;
3061
+ address: {
3062
+ line1: string;
3063
+ city: string;
3064
+ state: string;
3065
+ pincode: string;
3066
+ };
3067
+ };
3068
+ paymentProvider: "razorpay" | "cod";
3069
+ }
3070
+ interface CheckoutOrderResponse {
3071
+ order_id: string;
3072
+ payment_order_id?: string;
3073
+ amount?: number;
3074
+ currency?: string;
3075
+ status?: string;
3076
+ message?: string;
3077
+ }
3078
+
3079
+ /**
3080
+ * Resource for managing the ErixCheckout one-click flow.
3081
+ *
3082
+ * This resource handles session creation, coupon application,
3083
+ * identity verification, and final order placement.
3084
+ */
3085
+ declare class Checkout extends APIResource {
3086
+ /**
3087
+ * Retrieves product information for the checkout modal.
3088
+ * @param productId - External SKU/ID of the product.
3089
+ */
3090
+ getProduct(productId: string): Promise<CheckoutProduct>;
3091
+ /**
3092
+ * Initializes a new checkout session.
3093
+ */
3094
+ createSession(payload: CreateSessionPayload): Promise<CheckoutSession>;
3095
+ /**
3096
+ * Applies a discount coupon to an active session.
3097
+ */
3098
+ applyCoupon(payload: ApplyCouponPayload): Promise<CheckoutSession>;
3099
+ /**
3100
+ * Verifies user identity via Truecaller or OTP.
3101
+ */
3102
+ verify(payload: VerifyPayload): Promise<{
3103
+ verified: boolean;
3104
+ data?: any;
3105
+ }>;
3106
+ /**
3107
+ * Finalizes the order and initiates payment.
3108
+ */
3109
+ createOrder(payload: CreateOrderPayload): Promise<CheckoutOrderResponse>;
3110
+ }
3111
+
3010
3112
  /**
3011
3113
  * Configuration options for the Ecodrix client.
3012
3114
  *
@@ -3110,6 +3212,8 @@ declare class Ecodrix {
3110
3212
  readonly settings: Settings;
3111
3213
  /** Dynamic Cross-Origin Resource Sharing network policies. */
3112
3214
  readonly cors: Cors;
3215
+ /** ErixCheckout one-click checkout flow management. */
3216
+ readonly checkout: Checkout;
3113
3217
  constructor(options: EcodrixOptions);
3114
3218
  /**
3115
3219
  * Join a specific real-time room (e.g., a conversation or a lead).
@@ -3191,4 +3295,4 @@ declare class Ecodrix {
3191
3295
  request<T = any>(method: Method, path: string, data?: any, params?: any): Promise<T>;
3192
3296
  }
3193
3297
 
3194
- export { APIError, Activities, Agency, Analytics, type AnalyticsParams, type AnalyticsRange, type AssignEventPayload, AuthenticationError, AutomationDashboard, type AutomationRulePayload, Automations, Blogs, Broadcasts, CRM, type CallbackLog, type CampaignResult, Campaigns, type ChatMediaMeta, type ClientHealth, Clients, Conversations, Cors, type CorsOriginCreatePayload, type CorsOriginUpdatePayload, type CreateBroadcastParams, type CreateLeadParams, type CreateMeetingParams, type CreatePipelineParams, type CreateTemplateDTO, Ecodrix, EcodrixError, type EcodrixOptions, Email, EmailConfig, EmailResource, type EmailTemplate, Emails, type EventDefinition, type EventLog, EventsResource, type FieldManifest, type FieldType, Files, Folders, GlobalLeads, Health, type JobStats, type JobStatus, type LeadSource, type LeadStatus, Leads, type ListLeadsParams, type ListParams, type LogActivityParams, type LogCallParams, type LogFilter, type LogPaginationQuery, type LogResponse, Logs, Marketing, Media, MediaResource, Meetings, Messages, Notes, Notifications, Payments, type PipelineStageParams, Pipelines, Queue, RateLimitError, type ResourceManifest, Scoring, type ScoringConfig, type SendCampaignParams, type SendCampaignPayload, type SendMessageParams, type SendTemplateParams, type SendTemplatePayload, Sequences, Services, Settings, Storage, type SystemHealth, type TemplateMapping, type TemplatePreviewResponse, Templates, type TriggerPayload, type TriggerResponse, type UpdateMeetingParams, type UploadOptions, type UpsertLeadParams, WebhookSignatureError, Webhooks, WhatsApp, WhatsAppMarketing, Ecodrix as default };
3298
+ export { APIError, Activities, Agency, Analytics, type AnalyticsParams, type AnalyticsRange, type ApplyCouponPayload, type AssignEventPayload, AuthenticationError, AutomationDashboard, type AutomationRulePayload, Automations, Blogs, Broadcasts, CRM, type CallbackLog, type CampaignResult, Campaigns, type ChatMediaMeta, Checkout, type CheckoutAmountBreakdown, type CheckoutOrderResponse, type CheckoutProduct, type CheckoutSession, type ClientHealth, Clients, Conversations, Cors, type CorsOriginCreatePayload, type CorsOriginUpdatePayload, type CreateBroadcastParams, type CreateLeadParams, type CreateMeetingParams, type CreateOrderPayload, type CreatePipelineParams, type CreateSessionPayload, type CreateTemplateDTO, Ecodrix, EcodrixError, type EcodrixOptions, Email, EmailConfig, EmailResource, type EmailTemplate, Emails, type EventDefinition, type EventLog, EventsResource, type FieldManifest, type FieldType, Files, Folders, GlobalLeads, Health, type JobStats, type JobStatus, type LeadSource, type LeadStatus, Leads, type ListLeadsParams, type ListParams, type LogActivityParams, type LogCallParams, type LogFilter, type LogPaginationQuery, type LogResponse, Logs, Marketing, Media, MediaResource, Meetings, Messages, Notes, Notifications, Payments, type PipelineStageParams, Pipelines, Queue, RateLimitError, type ResourceManifest, Scoring, type ScoringConfig, type SendCampaignParams, type SendCampaignPayload, type SendMessageParams, type SendTemplateParams, type SendTemplatePayload, Sequences, Services, Settings, Storage, type SystemHealth, type TemplateMapping, type TemplatePreviewResponse, Templates, type TriggerPayload, type TriggerResponse, type UpdateMeetingParams, type UploadOptions, type UpsertLeadParams, type VerifyPayload, WebhookSignatureError, Webhooks, WhatsApp, WhatsAppMarketing, Ecodrix as default };
@@ -1,2 +1,2 @@
1
- var ve=Object.defineProperty,Pe=Object.defineProperties;var we=Object.getOwnPropertyDescriptors;var he=Object.getOwnPropertySymbols;var Re=Object.prototype.hasOwnProperty,$e=Object.prototype.propertyIsEnumerable;var Ce=(a,e)=>(e=Symbol[a])?e:Symbol.for("Symbol."+a);var Z=(a,e,t)=>e in a?ve(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t,y=(a,e)=>{for(var t in e||(e={}))Re.call(e,t)&&Z(a,t,e[t]);if(he)for(var t of he(e))$e.call(e,t)&&Z(a,t,e[t]);return a},h=(a,e)=>Pe(a,we(e));var i=(a,e,t)=>Z(a,typeof e!="symbol"?e+"":e,t);var ee=function(a,e){this[0]=a,this[1]=e},Te=(a,e,t)=>{var r=(c,l,p,u)=>{try{var d=t[c](l),f=(l=d.value)instanceof ee,P=d.done;Promise.resolve(f?l[0]:l).then(g=>f?r(c==="return"?c:"next",l[1]?{done:g.done,value:g.value}:g,p,u):p({value:g,done:P})).catch(g=>r("throw",g,p,u))}catch(g){u(g)}},n=c=>o[c]=l=>new Promise((p,u)=>r(c,l,p,u)),o={};return t=t.apply(a,e),o[Ce("asyncIterator")]=()=>o,n("next"),n("throw"),n("return"),o};import Ie from"axios";import me from"axios-retry";import{io as ke}from"socket.io-client";var te=class extends Error{constructor(e){super(e),this.name="EcodrixError"}},m=class extends te{constructor(t,r,n){super(t);i(this,"status");i(this,"code");this.name="APIError",this.status=r,this.code=n}},R=class extends m{constructor(e="Invalid API Key or Client Code"){super(e,401,"AUTH_FAILED"),this.name="AuthenticationError"}},fe=class extends m{constructor(e="Too many requests. Please slow down."){super(e,429,"RATE_LIMIT_EXCEEDED"),this.name="RateLimitError"}};var s=class{constructor(e){this.client=e}async post(e,t,r){try{let n=this.buildConfig(r);return(await this.client.post(e,t,n)).data}catch(n){this.handleError(n)}}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 n=this.buildConfig(r);return(await this.client.patch(e,t,n)).data}catch(n){this.handleError(n)}}async put(e,t,r){try{let n=this.buildConfig(r);return(await this.client.put(e,t,n)).data}catch(n){this.handleError(n)}}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=y({},e);return e.idempotencyKey&&(t.headers=h(y({},t.headers),{"Idempotency-Key":e.idempotencyKey})),t}handleError(e){var t,r,n;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,(n=e.response.data)==null?void 0:n.code):new m(e.message||"Network Error")}};var se=class extends s{async list(e){return this.get(`/api/crm/leads/${e}/notes`)}async create(e,t){return this.post(`/api/crm/leads/${e}/notes`,t)}async update(e,t){return this.patch(`/api/crm/notes/${e}`,{content:t})}async pin(e,t=!0){return this.patch(`/api/crm/notes/${e}/pin`,{isPinned:t})}async delete(e){return this.deleteRequest(`/api/crm/notes/${e}`)}},$=class extends s{constructor(t){super(t);i(this,"notes");this.notes=new se(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:y({},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 C=class extends s{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 s{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 I=class extends s{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 k=class extends s{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}],n=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,...n],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 n=0;n<e.length;n+=t){let c=e.slice(n,n+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=y({},e);return Array.isArray(t.tags)&&(t.tags=t.tags.join(",")),this.get("/api/crm/leads",{params:t})}listAutoPaging(e){return Te(this,null,function*(){let t=(e==null?void 0:e.page)||1,r=!0;for(;r;){let n=yield new ee(this.list(h(y({},e),{page:t}))),o=Array.isArray(n.data)?n.data:n||[];if(o.length===0){r=!1;break}for(let c of o)yield c;n.pagination&&t<n.pagination.pages||!n.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 S=class extends s{async capture(e){return this.post("/api/crm/payments/capture",e)}};var q=class extends s{async list(){return this.get("/api/crm/pipelines")}async getStageManifest(e){var n,o;let t=await this.retrieve(e),r=Array.isArray((n=t.data)==null?void 0:n.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 s{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 s{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 D=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 k(e),this.pipelines=new q(e),this.activities=new $(e),this.analytics=new C(e),this.automations=new I(e),this.sequences=new L(e),this.scoring=new E(e),this.payments=new S(e),this.automationDashboard=new A(e)}};var b=class extends s{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)}},be=class extends b{};var U=class extends s{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 M=class extends s{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 N=class extends s{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 ae=class extends s{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})}},ne=class extends s{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`)}},re=class extends s{async sendTemplate(e){return this.post("/api/saas/marketing/whatsapp/send-template",e)}},O=class extends s{constructor(t){super(t);i(this,"emails");i(this,"campaigns");i(this,"whatsapp");this.emails=new ae(t),this.campaigns=new ne(t),this.whatsapp=new re(t)}};import Ae from"axios";var x=class extends s{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:n,key:o}=r.data;await Ae.put(n,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})}},xe=class extends x{};var B=class extends s{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 s{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 H=class extends s{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 ie=class extends s{async create(e){return this.post("/api/saas/storage/folders",{name:e})}async delete(e){return this.deleteRequest(`/api/saas/storage/folders/${encodeURIComponent(e)}`)}},oe=class extends s{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 s{constructor(t){super(t);i(this,"folders");i(this,"files");this.folders=new ie(t),this.files=new oe(t)}async usage(){return this.get("/api/saas/storage/usage")}};var T=class extends m{constructor(e){super(e,400,"invalid_signature"),this.name="WebhookSignatureError"}},K=class{async constructEvent(e,t,r){if(!t)throw new T("No webhook signature provided");let n=Array.isArray(t)?t[0]:t;n.startsWith("sha256=")&&(n=n.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(n)))throw new T("Invalid webhook signature provided");return JSON.parse(e.toString("utf8"))}catch(o){throw o instanceof T?o:new T(`Webhook payload parsing failed: ${o.message}`)}}};var j=class extends s{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 s{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 J=class extends s{async send(e){return this.post("/api/saas/chat/send",e)}async sendTemplate(e){return this.post("/api/saas/chat/send",h(y({},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 Q=class extends s{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:[],n=[];for(let l of r)if(l.text){let p=l.text.match(/{{(\d+)}}/g);if(p)for(let u of p){let d=u.replace(/{{|}}/g,"");n.push({key:`var_${d}`,label:`${l.type} Var {{${d}}}`,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:n,uiHints:{icon:"Variables",primaryColor:"#059669"}}}async checkUsage(e){return this.get(`/api/saas/chat/templates/${encodeURIComponent(e)}/usage`)}};var W=class extends s{constructor(t){super(t);i(this,"messages");i(this,"conversations");i(this,"broadcasts");i(this,"templates");this.messages=new J(t),this.conversations=new V(t),this.broadcasts=new j(t),this.templates=new Q(t)}async upload(t,r){let n=new FormData;return n.append("file",t,r),this.post("/api/saas/chat/upload",n,{headers:typeof n.getHeaders=="function"?n.getHeaders():void 0})}async sendTemplate(t){return this.post("/api/saas/marketing/whatsapp/send-template",t)}};var z=class extends s{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 ce=class extends s{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}`)}},pe=class extends s{async list(){return this.get("/api/services/blogs")}},le=class extends s{async add(e){return this.post("/api/services/add-lead",e)}},G=class extends s{constructor(t){super(t);i(this,"clients");i(this,"blogs");i(this,"globalLeads");this.clients=new ce(t),this.blogs=new pe(t),this.globalLeads=new le(t)}};var ge=class extends s{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")}},X=class extends s{constructor(t){super(t);i(this,"email");this.email=new ge(t)}};var Y=class extends s{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 Se="https://api.ecodrix.com",v=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");i(this,"agency");i(this,"services");i(this,"settings");i(this,"cors");var p,u,d,f,P;if(!e.apiKey)throw new R("API Key is required");this.clientCode=(p=e.clientCode)==null?void 0:p.toUpperCase();let t=(u=e.baseUrl)!=null?u:Se,r=e.socketUrl||t,n=typeof window!="undefined"&&typeof window.document!="undefined",o=n?"browser":typeof process!="undefined"?`node ${process.version}`:"unknown",c=n?((d=globalThis.navigator)==null?void 0:d.userAgent)||"browser":typeof process!="undefined"?process.platform:"unknown",l={"x-api-key":e.apiKey,"x-client-code":((f=e.clientCode)==null?void 0:f.toUpperCase())||"","Content-Type":"application/json","x-ecodrix-client-agent":JSON.stringify({sdk_version:"1.0.0",runtime:o,os:c})};if(e.coreApiKey&&(l["x-core-api-key"]=e.coreApiKey),this.client=Ie.create({baseURL:t,headers:l}),me(this.client,{retries:3,retryDelay:me.exponentialDelay,retryCondition:g=>{var w;return me.isNetworkOrIdempotentRequestError(g)||((w=g.response)==null?void 0:w.status)===429},onRetry:(g,w,ue)=>{var ye,de;typeof process!="undefined"&&((ye=process.env)==null?void 0:ye.NODE_ENV)==="development"&&console.warn(`[ECODrIx SDK] Retrying request (${g}/3): ${(de=ue.method)==null?void 0:de.toUpperCase()} ${ue.url}. Reason: ${w.message}`)}}),this.whatsapp=new W(this.client),this.crm=new D(this.client),this.media=new x(this.client),this.meet=new B(this.client),this.notifications=new _(this.client),this.email=new b(this.client),this.logs=new N(this.client),this.events=new U(this.client),this.webhooks=new K,this.storage=new F(this.client),this.marketing=new O(this.client),this.health=new M(this.client),this.queue=new H(this.client),this.agency=new z(this.client),this.services=new G(this.client),this.settings=new X(this.client),this.cors=new Y(this.client),this.socket=ke(r,{extraHeaders:{"x-api-key":e.apiKey,"x-client-code":((P=e.clientCode)==null?void 0:P.toUpperCase())||""}}),this.setupSocket(e.clientCode),n){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,n){var o,c,l;try{return(await this.client.request({method:e,url:t,data:r,params:n})).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 Ms=v;export{m as APIError,$ as Activities,z as Agency,C as Analytics,R as AuthenticationError,A as AutomationDashboard,I as Automations,pe as Blogs,j as Broadcasts,D as CRM,ne as Campaigns,ce as Clients,V as Conversations,Y as Cors,v as Ecodrix,te as EcodrixError,b as Email,ge as EmailConfig,be as EmailResource,ae as Emails,U as EventsResource,oe as Files,ie as Folders,le as GlobalLeads,M as Health,k as Leads,N as Logs,O as Marketing,x as Media,xe as MediaResource,B as Meetings,J as Messages,se as Notes,_ as Notifications,S as Payments,q as Pipelines,H as Queue,fe as RateLimitError,E as Scoring,L as Sequences,G as Services,X as Settings,F as Storage,Q as Templates,T as WebhookSignatureError,K as Webhooks,W as WhatsApp,re as WhatsAppMarketing,Ms as default};
1
+ var Pe=Object.defineProperty,we=Object.defineProperties;var Ce=Object.getOwnPropertyDescriptors;var Te=Object.getOwnPropertySymbols;var Re=Object.prototype.hasOwnProperty,$e=Object.prototype.propertyIsEnumerable;var Ae=(a,e)=>(e=Symbol[a])?e:Symbol.for("Symbol."+a);var ee=(a,e,t)=>e in a?Pe(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t,y=(a,e)=>{for(var t in e||(e={}))Re.call(e,t)&&ee(a,t,e[t]);if(Te)for(var t of Te(e))$e.call(e,t)&&ee(a,t,e[t]);return a},h=(a,e)=>we(a,Ce(e));var i=(a,e,t)=>ee(a,typeof e!="symbol"?e+"":e,t);var te=function(a,e){this[0]=a,this[1]=e},fe=(a,e,t)=>{var n=(c,l,p,u)=>{try{var d=t[c](l),f=(l=d.value)instanceof te,P=d.done;Promise.resolve(f?l[0]:l).then(g=>f?n(c==="return"?c:"next",l[1]?{done:g.done,value:g.value}:g,p,u):p({value:g,done:P})).catch(g=>n("throw",g,p,u))}catch(g){u(g)}},r=c=>o[c]=l=>new Promise((p,u)=>n(c,l,p,u)),o={};return t=t.apply(a,e),o[Ae("asyncIterator")]=()=>o,r("next"),r("throw"),r("return"),o};import Ie from"axios";import ue from"axios-retry";import{io as Se}from"socket.io-client";var se=class extends Error{constructor(e){super(e),this.name="EcodrixError"}},m=class extends se{constructor(t,n,r){super(t);i(this,"status");i(this,"code");this.name="APIError",this.status=n,this.code=r}},C=class extends m{constructor(e="Invalid API Key or Client Code"){super(e,401,"AUTH_FAILED"),this.name="AuthenticationError"}},be=class extends m{constructor(e="Too many requests. Please slow down."){super(e,429,"RATE_LIMIT_EXCEEDED"),this.name="RateLimitError"}};var s=class{constructor(e){this.client=e}async post(e,t,n){try{let r=this.buildConfig(n);return(await this.client.post(e,t,r)).data}catch(r){this.handleError(r)}}async get(e,t){try{let n=this.buildConfig(t);return(await this.client.get(e,n)).data}catch(n){this.handleError(n)}}async patch(e,t,n){try{let r=this.buildConfig(n);return(await this.client.patch(e,t,r)).data}catch(r){this.handleError(r)}}async put(e,t,n){try{let r=this.buildConfig(n);return(await this.client.put(e,t,r)).data}catch(r){this.handleError(r)}}async deleteRequest(e,t){try{let n=this.buildConfig(t);return(await this.client.delete(e,n)).data}catch(n){this.handleError(n)}}buildConfig(e){if(!e)return;let t=y({},e);return e.idempotencyKey&&(t.headers=h(y({},t.headers),{"Idempotency-Key":e.idempotencyKey})),t}handleError(e){var t,n,r;throw e.response?new m(((t=e.response.data)==null?void 0:t.message)||((n=e.response.data)==null?void 0:n.error)||"API Request Failed",e.response.status,(r=e.response.data)==null?void 0:r.code):new m(e.message||"Network Error")}};var ae=class extends s{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 s{constructor(t){super(t);i(this,"notes");this.notes=new ae(t)}async timeline(t,n){return this.get(`/api/crm/leads/${t}/timeline`,{params:n})}async list(t,n){return this.get(`/api/crm/leads/${t}/activities`,{params:y({},n)})}async log(t){return this.post(`/api/crm/leads/${t.leadId}/activities`,t)}async logCall(t,n){return this.post(`/api/crm/leads/${t}/calls`,n)}};var $=class extends s{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 s{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 k=class extends s{async list(){return this.get("/api/crm/automations")}async create(e){return this.post("/api/crm/automations",e)}async update(e,t){return this.patch(`/api/crm/automations/${e}`,t)}async toggle(e){return this.patch(`/api/crm/automations/${e}/toggle`)}async delete(e){return this.deleteRequest(`/api/crm/automations/${e}`)}async bulkDelete(e){return this.post("/api/crm/automations/bulk-delete",{ids:e})}async test(e,t){return this.post(`/api/crm/automations/${e}/test`,{leadId:t})}async getAvailableEvents(){return this.post("/api/crm/automations/events",{})}async enrollments(e,t){return this.get(`/api/crm/automations/${e}/enrollments`,{params:t})}async getEnrollment(e){return this.get(`/api/crm/automations/enrollments/${e}`)}async pauseEnrollment(e,t){return this.post(`/api/crm/automations/${e}/enrollments/${t}/pause`,{})}async resumeEnrollment(e,t){return this.post(`/api/crm/automations/${e}/enrollments/${t}/resume`,{})}async runs(e){return this.get(`/api/crm/automations/${e}/runs`)}async getRun(e){return this.get(`/api/crm/automations/runs/${e}`)}async resumeRun(e){return this.post(`/api/crm/automations/runs/${e}/resume`,{})}async abortRun(e){return this.post(`/api/crm/automations/runs/${e}/abort`,{})}async webhookEvent(e,t,n){return this.post("/api/crm/webhook-event",{ruleId:e,eventName:t,payload:n})}};var I=class extends s{async create(e){return this.post("/api/crm/leads",e)}async describe(){let e=await this.fields(),t=Array.isArray(e.data)?e.data:[],n=[{key:"firstName",label:"First Name",type:"string",required:!0,group:"Basic Info"},{key:"lastName",label:"Last Name",type:"string",required:!1,group:"Basic Info"},{key:"phone",label:"Phone Number",type:"phone",required:!0,group:"Contact"},{key:"email",label:"Email Address",type:"email",required:!1,group:"Contact"},{key:"status",label:"Status",type:"select",required:!0,options:[{label:"New",value:"new"},{label:"Contacted",value:"contacted"},{label:"Qualified",value:"qualified"},{label:"Won",value:"won"},{label:"Lost",value:"lost"}]},{key:"value",label:"Lead Value",type:"currency",required:!1},{key:"source",label:"Source",type:"string",required:!1}],r=t.map(o=>({key:`metadata.extra.${o.name}`,label:o.label||o.name,type:o.type||"string",required:!!o.required,options:o.options,group:"Custom Fields"}));return{name:"Lead",fields:[...n,...r],uiHints:{icon:"User",primaryColor:"#3b82f6",defaultSort:{field:"createdAt",direction:"desc"},summaryFields:["firstName","lastName","phone","status"]}}}async upsert(e){return this.post("/api/crm/leads/upsert",e)}async createMany(e,t=50){let n=[];for(let r=0;r<e.length;r+=t){let c=e.slice(r,r+t).map(p=>this.create(p)),l=await Promise.allSettled(c);for(let p of l)if(p.status==="fulfilled")n.push(p.value);else throw p.reason}return n}async import(e){return this.post("/api/crm/leads/import",{leads:e})}async list(e){let t=y({},e);return Array.isArray(t.tags)&&(t.tags=t.tags.join(",")),this.get("/api/crm/leads",{params:t})}listAutoPaging(e){return fe(this,null,function*(){let t=(e==null?void 0:e.page)||1,n=!0;for(;n;){let r=yield new te(this.list(h(y({},e),{page:t}))),o=Array.isArray(r.data)?r.data:r||[];if(o.length===0){n=!1;break}for(let c of o)yield c;r.pagination&&t<r.pagination.pages||!r.pagination&&o.length>0?t++:n=!1}})}async retrieve(e){return this.get(`/api/crm/leads/${e}`)}async retrieveByPhone(e){return this.get(`/api/crm/leads/phone/${encodeURIComponent(e)}`)}async retrieveByRef(e,t){return this.get(`/api/crm/leads/ref/${encodeURIComponent(e)}/${encodeURIComponent(t)}`)}async update(e,t){return this.patch(`/api/crm/leads/${e}`,t)}async move(e,t){return this.patch(`/api/crm/leads/${e}/move`,{stageId:t})}async convert(e,t,n){return this.post(`/api/crm/leads/${e}/convert`,{outcome:t,reason:n})}async tags(e,t){return this.patch(`/api/crm/leads/${e}/tags`,t)}async recalculateScore(e){return this.post(`/api/crm/leads/${e}/score`,{})}async updateMetadata(e,t){return this.patch(`/api/crm/leads/${e}/metadata`,t)}async fields(){return this.get("/api/crm/leads/fields")}async notes(e){return this.get(`/api/crm/leads/${e}/notes`)}async activities(e,t){return this.get(`/api/crm/leads/${e}/timeline`,{params:t})}async createNote(e,t){return this.post(`/api/crm/leads/${e}/notes`,t)}async updateNote(e,t,n){return this.patch(`/api/crm/notes/${t}`,n)}async deleteNote(e,t){return this.deleteRequest(`/api/crm/notes/${t}`)}async delete(e){return this.deleteRequest(`/api/crm/leads/${e}`)}async bulkDelete(e){return this.deleteRequest("/api/crm/leads",{data:{ids:e}})}};var S=class extends s{async capture(e){return this.post("/api/crm/payments/capture",e)}};var q=class extends s{async list(){return this.get("/api/crm/pipelines")}async getStageManifest(e){var r,o;let t=await this.retrieve(e),n=Array.isArray((r=t.data)==null?void 0:r.stages)?t.data.stages:[];return{name:`Pipeline: ${((o=t.data)==null?void 0:o.name)||e}`,fields:n.map(c=>({key:c._id,label:c.name,type:"string",required:!0,options:[{label:c.name,value:c._id}],group:"Stages",uiHints:{color:c.color||"#cbd5e1",probability:c.probability}})),uiHints:{icon:"Columns",primaryColor:"#6366f1"}}}async create(e){return this.post("/api/crm/pipelines",e)}async retrieve(e){return this.get(`/api/crm/pipelines/${e}`)}async update(e,t){return this.patch(`/api/crm/pipelines/${e}`,t)}async setDefault(e){return this.patch(`/api/crm/pipelines/${e}/default`,{})}async duplicate(e,t){return this.post(`/api/crm/pipelines/${e}/duplicate`,{newName:t})}async archive(e){return this.patch(`/api/crm/pipelines/${e}/archive`,{})}async delete(e){return this.deleteRequest(`/api/crm/pipelines/${e}`)}async checkInUse(e){return this.get(`/api/crm/pipelines/${e}/in-use`)}async board(e){return this.get(`/api/crm/pipelines/${e}/board`)}async forecast(e){return this.get(`/api/crm/pipelines/${e}/forecast`)}async addStage(e,t){return this.post(`/api/crm/pipelines/${e}/stages`,t)}async reorderStages(e,t){return this.patch(`/api/crm/pipelines/${e}/stages/reorder`,{order:t})}async updateStage(e,t){return this.patch(`/api/crm/stages/${e}`,t)}async deleteStage(e,t){return this.deleteRequest(`/api/crm/stages/${e}`,{data:t?{moveLeadsToStageId:t}:void 0})}};var E=class extends s{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 s{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 D=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 k(e),this.sequences=new L(e),this.scoring=new E(e),this.payments=new S(e),this.automationDashboard=new A(e)}};var b=class extends s{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)}},xe=class extends b{};var U=class extends s{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 M=class extends s{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 N=class extends s{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 re=class extends s{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})}},ne=class extends s{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`)}},ie=class extends s{async sendTemplate(e){return this.post("/api/saas/marketing/whatsapp/send-template",e)}},O=class extends s{constructor(t){super(t);i(this,"emails");i(this,"campaigns");i(this,"whatsapp");this.emails=new re(t),this.campaigns=new ne(t),this.whatsapp=new ie(t)}};import ke from"axios";var x=class extends s{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 n=await this.post("/api/saas/storage/upload-url",t),{uploadUrl:r,key:o}=n.data;await ke.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})}},ve=class extends x{};var B=class extends s{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 s{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 H=class extends s{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 oe=class extends s{async create(e){return this.post("/api/saas/storage/folders",{name:e})}async delete(e){return this.deleteRequest(`/api/saas/storage/folders/${encodeURIComponent(e)}`)}},ce=class extends s{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 s{constructor(t){super(t);i(this,"folders");i(this,"files");this.folders=new oe(t),this.files=new ce(t)}async usage(){return this.get("/api/saas/storage/usage")}};var T=class extends m{constructor(e){super(e,400,"invalid_signature"),this.name="WebhookSignatureError"}},K=class{async constructEvent(e,t,n){if(!t)throw new T("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",n).update(e).digest("hex");if(!o.timingSafeEqual(Buffer.from(l),Buffer.from(r)))throw new T("Invalid webhook signature provided");return JSON.parse(e.toString("utf8"))}catch(o){throw o instanceof T?o:new T(`Webhook payload parsing failed: ${o.message}`)}}};var V=class extends s{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 j=class extends s{async list(e){return this.get("/api/saas/chat/conversations",{params:e})}async create(e){return this.post("/api/saas/chat/conversations",e)}async retrieve(e){return this.get(`/api/saas/chat/conversations/${e}`)}async messages(e,t){return this.get(`/api/saas/chat/conversations/${e}/messages`,{params:t})}async linkLead(e,t,n){return this.post(`/api/saas/chat/conversations/${e}/link-lead`,{leadId:t,leadData:n})}async markRead(e){return this.post(`/api/saas/chat/conversations/${e}/read`,{})}async delete(e){return this.deleteRequest(`/api/saas/chat/conversations/${e}`)}async bulkDelete(e){return this.post("/api/saas/chat/conversations/bulk-delete",{ids:e})}};var J=class extends s{async send(e){return this.post("/api/saas/chat/send",e)}async sendTemplate(e){return this.post("/api/saas/chat/send",h(y({},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 Q=class extends s{async list(e){return this.get("/api/saas/chat/templates",{params:e})}async sync(){return this.post("/api/saas/chat/templates/sync",{})}async retrieve(e){return this.get(`/api/saas/chat/templates/${encodeURIComponent(e)}`)}async create(e){return this.post("/api/saas/chat/templates",e)}async update(e,t){return this.put(`/api/saas/chat/templates/${e}`,t)}async deleteTemplate(e,t){return this.deleteRequest(`/api/saas/chat/templates/${encodeURIComponent(e)}${t?"?force=true":""}`)}async mappingConfig(){return this.get("/api/saas/chat/templates/mapping/config")}async collections(){return this.get("/api/saas/chat/templates/collections")}async collectionFields(e){return this.get(`/api/saas/chat/templates/collections/${encodeURIComponent(e)}/fields`)}async updateMapping(e,t){return this.put(`/api/saas/chat/templates/${encodeURIComponent(e)}/mapping`,t)}async validate(e){return this.get(`/api/saas/chat/templates/${encodeURIComponent(e)}/validate`)}async preview(e,t){return this.post(`/api/saas/chat/templates/${encodeURIComponent(e)}/preview`,{context:t})}async getVariableManifest(e){var o,c;let t=await this.retrieve(e),n=Array.isArray((o=t.data)==null?void 0:o.components)?t.data.components:[],r=[];for(let l of n)if(l.text){let p=l.text.match(/{{(\d+)}}/g);if(p)for(let u of p){let d=u.replace(/{{|}}/g,"");r.push({key:`var_${d}`,label:`${l.type} Var {{${d}}}`,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 W=class extends s{constructor(t){super(t);i(this,"messages");i(this,"conversations");i(this,"broadcasts");i(this,"templates");this.messages=new J(t),this.conversations=new j(t),this.broadcasts=new V(t),this.templates=new Q(t)}async upload(t,n){let r=new FormData;return r.append("file",t,n),this.post("/api/saas/chat/upload",r,{headers:typeof r.getHeaders=="function"?r.getHeaders():void 0})}async sendTemplate(t){return this.post("/api/saas/marketing/whatsapp/send-template",t)}};var z=class extends s{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 pe=class extends s{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}`)}},le=class extends s{async list(){return this.get("/api/services/blogs")}},ge=class extends s{async add(e){return this.post("/api/services/add-lead",e)}},G=class extends s{constructor(t){super(t);i(this,"clients");i(this,"blogs");i(this,"globalLeads");this.clients=new pe(t),this.blogs=new le(t),this.globalLeads=new ge(t)}};var me=class extends s{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")}},X=class extends s{constructor(t){super(t);i(this,"email");this.email=new me(t)}};var Y=class extends s{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 Z=class extends s{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 qe="https://api.ecodrix.com",v=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");i(this,"agency");i(this,"services");i(this,"settings");i(this,"cors");i(this,"checkout");var p,u,d,f,P;if(!e.apiKey)throw new C("API Key is required");this.clientCode=(p=e.clientCode)==null?void 0:p.toUpperCase();let t=(u=e.baseUrl)!=null?u:qe,n=e.socketUrl||t,r=typeof window!="undefined"&&typeof window.document!="undefined",o=r?"browser":typeof process!="undefined"?`node ${process.version}`:"unknown",c=r?((d=globalThis.navigator)==null?void 0:d.userAgent)||"browser":typeof process!="undefined"?process.platform:"unknown",l={"x-api-key":e.apiKey,"x-client-code":((f=e.clientCode)==null?void 0:f.toUpperCase())||"","Content-Type":"application/json","x-ecodrix-client-agent":JSON.stringify({sdk_version:"1.0.0",runtime:o,os:c})};if(e.coreApiKey&&(l["x-core-api-key"]=e.coreApiKey),this.client=Ie.create({baseURL:t,headers:l}),ue(this.client,{retries:3,retryDelay:ue.exponentialDelay,retryCondition:g=>{var w;return ue.isNetworkOrIdempotentRequestError(g)||((w=g.response)==null?void 0:w.status)===429},onRetry:(g,w,ye)=>{var de,he;typeof process!="undefined"&&((de=process.env)==null?void 0:de.NODE_ENV)==="development"&&console.warn(`[ECODrIx SDK] Retrying request (${g}/3): ${(he=ye.method)==null?void 0:he.toUpperCase()} ${ye.url}. Reason: ${w.message}`)}}),this.whatsapp=new W(this.client),this.crm=new D(this.client),this.media=new x(this.client),this.meet=new B(this.client),this.notifications=new _(this.client),this.email=new b(this.client),this.logs=new N(this.client),this.events=new U(this.client),this.webhooks=new K,this.storage=new F(this.client),this.marketing=new O(this.client),this.health=new M(this.client),this.queue=new H(this.client),this.agency=new z(this.client),this.services=new G(this.client),this.settings=new X(this.client),this.cors=new Y(this.client),this.checkout=new Z(this.client),this.socket=Se(n,{extraHeaders:{"x-api-key":e.apiKey,"x-client-code":((P=e.clientCode)==null?void 0:P.toUpperCase())||""}}),this.setupSocket(e.clientCode),r){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,n,r){var o,c,l;try{return(await this.client.request({method:e,url:t,data:n,params:r})).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 _s=v;export{m as APIError,R as Activities,z as Agency,$ as Analytics,C as AuthenticationError,A as AutomationDashboard,k as Automations,le as Blogs,V as Broadcasts,D as CRM,ne as Campaigns,Z as Checkout,pe as Clients,j as Conversations,Y as Cors,v as Ecodrix,se as EcodrixError,b as Email,me as EmailConfig,xe as EmailResource,re as Emails,U as EventsResource,ce as Files,oe as Folders,ge as GlobalLeads,M as Health,I as Leads,N as Logs,O as Marketing,x as Media,ve as MediaResource,B as Meetings,J as Messages,ae as Notes,_ as Notifications,S as Payments,q as Pipelines,H as Queue,be as RateLimitError,E as Scoring,L as Sequences,G as Services,X as Settings,F as Storage,Q as Templates,T as WebhookSignatureError,K as Webhooks,W as WhatsApp,ie as WhatsAppMarketing,_s as default};
2
2
  //# sourceMappingURL=index.js.map