@ecodrix/erix-api 1.1.6 → 1.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +3 -3
- package/dist/index.d.ts +43 -20
- package/dist/ts/browser/index.global.js +7 -7
- package/dist/ts/browser/index.global.js.map +1 -1
- package/dist/ts/cjs/index.cjs +1 -1
- package/dist/ts/cjs/index.cjs.map +1 -1
- package/dist/ts/cjs/index.d.cts +43 -20
- package/dist/ts/esm/index.d.ts +43 -20
- package/dist/ts/esm/index.js +1 -1
- package/dist/ts/esm/index.js.map +1 -1
- package/package.json +1 -1
- package/src/core.ts +17 -12
- package/src/resources/crm/activities.ts +1 -5
- package/src/resources/crm/automationDashboard.ts +0 -1
- package/src/resources/crm/automations.ts +2 -10
- package/src/resources/crm/leads.ts +8 -37
- package/src/resources/crm/payments.ts +0 -1
- package/src/resources/crm/scoring.ts +0 -1
- package/src/resources/email.ts +1 -3
- package/src/resources/events.ts +1 -3
- package/src/resources/health.ts +1 -3
- package/src/resources/marketing.ts +1 -4
- package/src/resources/storage.ts +1 -4
- package/src/resources/whatsapp/conversations.ts +9 -22
- package/src/resources/whatsapp/messages.ts +34 -7
- package/src/resources/whatsapp/templates.ts +7 -17
package/dist/ts/cjs/index.d.cts
CHANGED
|
@@ -2245,6 +2245,31 @@ interface SendTemplateParams {
|
|
|
2245
2245
|
* });
|
|
2246
2246
|
* ```
|
|
2247
2247
|
*/
|
|
2248
|
+
/**
|
|
2249
|
+
* Resolved media metadata returned by any upload endpoint.
|
|
2250
|
+
* `variants` is only present for raster images (JPEG, PNG, WebP, AVIF, GIF).
|
|
2251
|
+
*/
|
|
2252
|
+
interface ChatMediaMeta {
|
|
2253
|
+
/** Raw CDN URL — always present, all media types */
|
|
2254
|
+
url: string;
|
|
2255
|
+
/** Categorical type — "image" | "video" | "audio" | "document" */
|
|
2256
|
+
type: "image" | "video" | "audio" | "document";
|
|
2257
|
+
/** Cloudflare-optimised variant URLs. Only present for raster images. */
|
|
2258
|
+
variants?: {
|
|
2259
|
+
/** 150px WebP — use for list thumbnails and chat bubbles */
|
|
2260
|
+
thumb: string;
|
|
2261
|
+
/** 600px WebP — use for modal previews */
|
|
2262
|
+
medium: string;
|
|
2263
|
+
/** 1200px WebP — use for hero or full-screen views */
|
|
2264
|
+
full: string;
|
|
2265
|
+
/** Original CDN URL, no transformation */
|
|
2266
|
+
raw: string;
|
|
2267
|
+
};
|
|
2268
|
+
/** Storage key within the tenant bucket */
|
|
2269
|
+
key?: string;
|
|
2270
|
+
/** Original filename */
|
|
2271
|
+
fileName?: string;
|
|
2272
|
+
}
|
|
2248
2273
|
declare class Messages extends APIResource {
|
|
2249
2274
|
/**
|
|
2250
2275
|
* Send a free-text or media message to a WhatsApp number.
|
|
@@ -2323,26 +2348,24 @@ declare class Messages extends APIResource {
|
|
|
2323
2348
|
/**
|
|
2324
2349
|
* Upload a media file for WhatsApp chat.
|
|
2325
2350
|
*
|
|
2326
|
-
*
|
|
2327
|
-
*
|
|
2328
|
-
*
|
|
2351
|
+
* Works with any file type — image, video, audio, or document.
|
|
2352
|
+
* For raster images the response includes Cloudflare-optimised `variants`
|
|
2353
|
+
* (thumb 150px, medium 600px, full 1200px). Non-image types return only `url`.
|
|
2329
2354
|
*
|
|
2330
2355
|
* @param file - The file to upload (File, Blob, or Buffer).
|
|
2331
|
-
* @returns
|
|
2356
|
+
* @returns Full media metadata `{ url, type, variants?, key, fileName }`.
|
|
2332
2357
|
*
|
|
2333
2358
|
* @example
|
|
2334
2359
|
* ```typescript
|
|
2335
2360
|
* const file = input.files[0];
|
|
2336
2361
|
* const { data } = await ecod.whatsapp.messages.upload(file);
|
|
2337
|
-
*
|
|
2362
|
+
* // For images: data.variants.thumb → 150px WebP from Cloudflare
|
|
2363
|
+
* // For video/audio: use data.url directly in <video> or <audio>
|
|
2338
2364
|
* ```
|
|
2339
2365
|
*/
|
|
2340
|
-
upload
|
|
2341
|
-
url: string;
|
|
2342
|
-
type: string;
|
|
2343
|
-
}>(file: any): Promise<{
|
|
2366
|
+
upload(file: any): Promise<{
|
|
2344
2367
|
success: boolean;
|
|
2345
|
-
data:
|
|
2368
|
+
data: ChatMediaMeta;
|
|
2346
2369
|
}>;
|
|
2347
2370
|
}
|
|
2348
2371
|
|
|
@@ -2512,6 +2535,9 @@ declare class WhatsApp extends APIResource {
|
|
|
2512
2535
|
|
|
2513
2536
|
/**
|
|
2514
2537
|
* Configuration options for the Ecodrix client.
|
|
2538
|
+
*
|
|
2539
|
+
* Minimum required: `apiKey` and `clientCode`.
|
|
2540
|
+
* The backend URL is managed internally and should not need to be changed.
|
|
2515
2541
|
*/
|
|
2516
2542
|
interface EcodrixOptions {
|
|
2517
2543
|
/**
|
|
@@ -2523,22 +2549,19 @@ interface EcodrixOptions {
|
|
|
2523
2549
|
/**
|
|
2524
2550
|
* Your tenant ID (Client Code).
|
|
2525
2551
|
* This scopes all API requests to your specific organisation.
|
|
2526
|
-
* Required for most operations.
|
|
2527
2552
|
* @example "ERIX_CLNT_JHBJHF"
|
|
2528
2553
|
*/
|
|
2529
2554
|
clientCode?: string;
|
|
2530
2555
|
/**
|
|
2531
|
-
* Override
|
|
2532
|
-
*
|
|
2533
|
-
* @default "https://api.ecodrix.com"
|
|
2556
|
+
* @internal Override Socket.io URL for testing/staging.
|
|
2557
|
+
* Not documented — internal use only.
|
|
2534
2558
|
*/
|
|
2535
|
-
|
|
2559
|
+
socketUrl?: string;
|
|
2536
2560
|
/**
|
|
2537
|
-
* Override the
|
|
2538
|
-
*
|
|
2539
|
-
* @default "https://api.ecodrix.com"
|
|
2561
|
+
* @internal Override the backend API URL. Used by the CLI and internal tests only.
|
|
2562
|
+
* Host projects must never set this — the production URL is hardcoded internally.
|
|
2540
2563
|
*/
|
|
2541
|
-
|
|
2564
|
+
baseUrl?: string;
|
|
2542
2565
|
}
|
|
2543
2566
|
/**
|
|
2544
2567
|
* The primary entry point for the ECODrIx SDK.
|
|
@@ -2667,4 +2690,4 @@ declare class Ecodrix {
|
|
|
2667
2690
|
request<T = any>(method: Method, path: string, data?: any, params?: any): Promise<T>;
|
|
2668
2691
|
}
|
|
2669
2692
|
|
|
2670
|
-
export { APIError, Activities, Analytics, type AnalyticsParams, type AnalyticsRange, type AssignEventPayload, AuthenticationError, AutomationDashboard, type AutomationRulePayload, Automations, Broadcasts, CRM, type CampaignResult, Campaigns, type ClientHealth, Conversations, type CreateBroadcastParams, type CreateLeadParams, type CreateMeetingParams, type CreatePipelineParams, Ecodrix, EcodrixError, type EcodrixOptions, EmailResource, Emails, type EventDefinition, EventsResource, Files, Folders, Health, type JobStats, type JobStatus, type LeadSource, type LeadStatus, Leads, type ListLeadsParams, type ListParams, type LogActivityParams, type LogCallParams, type LogFilter, Marketing, MediaResource, Meetings, Messages, Notes, Notifications, Payments, type PipelineStageParams, Pipelines, Queue, RateLimitError, Scoring, type ScoringConfig, type SendCampaignParams, type SendCampaignPayload, type SendMessageParams, type SendTemplateParams, type SendTemplatePayload, Sequences, Storage, type SystemHealth, type TemplateMapping, Templates, type TriggerPayload, type TriggerResponse, type UpdateMeetingParams, type UploadOptions, type UpsertLeadParams, WebhookSignatureError, Webhooks, WhatsApp, WhatsAppMarketing, Ecodrix as default };
|
|
2693
|
+
export { APIError, Activities, Analytics, type AnalyticsParams, type AnalyticsRange, type AssignEventPayload, AuthenticationError, AutomationDashboard, type AutomationRulePayload, Automations, Broadcasts, CRM, type CampaignResult, Campaigns, type ChatMediaMeta, type ClientHealth, Conversations, type CreateBroadcastParams, type CreateLeadParams, type CreateMeetingParams, type CreatePipelineParams, Ecodrix, EcodrixError, type EcodrixOptions, EmailResource, Emails, type EventDefinition, EventsResource, Files, Folders, Health, type JobStats, type JobStatus, type LeadSource, type LeadStatus, Leads, type ListLeadsParams, type ListParams, type LogActivityParams, type LogCallParams, type LogFilter, Marketing, MediaResource, Meetings, Messages, Notes, Notifications, Payments, type PipelineStageParams, Pipelines, Queue, RateLimitError, Scoring, type ScoringConfig, type SendCampaignParams, type SendCampaignPayload, type SendMessageParams, type SendTemplateParams, type SendTemplatePayload, Sequences, Storage, type SystemHealth, type TemplateMapping, Templates, type TriggerPayload, type TriggerResponse, type UpdateMeetingParams, type UploadOptions, type UpsertLeadParams, WebhookSignatureError, Webhooks, WhatsApp, WhatsAppMarketing, Ecodrix as default };
|
package/dist/ts/esm/index.d.ts
CHANGED
|
@@ -2245,6 +2245,31 @@ interface SendTemplateParams {
|
|
|
2245
2245
|
* });
|
|
2246
2246
|
* ```
|
|
2247
2247
|
*/
|
|
2248
|
+
/**
|
|
2249
|
+
* Resolved media metadata returned by any upload endpoint.
|
|
2250
|
+
* `variants` is only present for raster images (JPEG, PNG, WebP, AVIF, GIF).
|
|
2251
|
+
*/
|
|
2252
|
+
interface ChatMediaMeta {
|
|
2253
|
+
/** Raw CDN URL — always present, all media types */
|
|
2254
|
+
url: string;
|
|
2255
|
+
/** Categorical type — "image" | "video" | "audio" | "document" */
|
|
2256
|
+
type: "image" | "video" | "audio" | "document";
|
|
2257
|
+
/** Cloudflare-optimised variant URLs. Only present for raster images. */
|
|
2258
|
+
variants?: {
|
|
2259
|
+
/** 150px WebP — use for list thumbnails and chat bubbles */
|
|
2260
|
+
thumb: string;
|
|
2261
|
+
/** 600px WebP — use for modal previews */
|
|
2262
|
+
medium: string;
|
|
2263
|
+
/** 1200px WebP — use for hero or full-screen views */
|
|
2264
|
+
full: string;
|
|
2265
|
+
/** Original CDN URL, no transformation */
|
|
2266
|
+
raw: string;
|
|
2267
|
+
};
|
|
2268
|
+
/** Storage key within the tenant bucket */
|
|
2269
|
+
key?: string;
|
|
2270
|
+
/** Original filename */
|
|
2271
|
+
fileName?: string;
|
|
2272
|
+
}
|
|
2248
2273
|
declare class Messages extends APIResource {
|
|
2249
2274
|
/**
|
|
2250
2275
|
* Send a free-text or media message to a WhatsApp number.
|
|
@@ -2323,26 +2348,24 @@ declare class Messages extends APIResource {
|
|
|
2323
2348
|
/**
|
|
2324
2349
|
* Upload a media file for WhatsApp chat.
|
|
2325
2350
|
*
|
|
2326
|
-
*
|
|
2327
|
-
*
|
|
2328
|
-
*
|
|
2351
|
+
* Works with any file type — image, video, audio, or document.
|
|
2352
|
+
* For raster images the response includes Cloudflare-optimised `variants`
|
|
2353
|
+
* (thumb 150px, medium 600px, full 1200px). Non-image types return only `url`.
|
|
2329
2354
|
*
|
|
2330
2355
|
* @param file - The file to upload (File, Blob, or Buffer).
|
|
2331
|
-
* @returns
|
|
2356
|
+
* @returns Full media metadata `{ url, type, variants?, key, fileName }`.
|
|
2332
2357
|
*
|
|
2333
2358
|
* @example
|
|
2334
2359
|
* ```typescript
|
|
2335
2360
|
* const file = input.files[0];
|
|
2336
2361
|
* const { data } = await ecod.whatsapp.messages.upload(file);
|
|
2337
|
-
*
|
|
2362
|
+
* // For images: data.variants.thumb → 150px WebP from Cloudflare
|
|
2363
|
+
* // For video/audio: use data.url directly in <video> or <audio>
|
|
2338
2364
|
* ```
|
|
2339
2365
|
*/
|
|
2340
|
-
upload
|
|
2341
|
-
url: string;
|
|
2342
|
-
type: string;
|
|
2343
|
-
}>(file: any): Promise<{
|
|
2366
|
+
upload(file: any): Promise<{
|
|
2344
2367
|
success: boolean;
|
|
2345
|
-
data:
|
|
2368
|
+
data: ChatMediaMeta;
|
|
2346
2369
|
}>;
|
|
2347
2370
|
}
|
|
2348
2371
|
|
|
@@ -2512,6 +2535,9 @@ declare class WhatsApp extends APIResource {
|
|
|
2512
2535
|
|
|
2513
2536
|
/**
|
|
2514
2537
|
* Configuration options for the Ecodrix client.
|
|
2538
|
+
*
|
|
2539
|
+
* Minimum required: `apiKey` and `clientCode`.
|
|
2540
|
+
* The backend URL is managed internally and should not need to be changed.
|
|
2515
2541
|
*/
|
|
2516
2542
|
interface EcodrixOptions {
|
|
2517
2543
|
/**
|
|
@@ -2523,22 +2549,19 @@ interface EcodrixOptions {
|
|
|
2523
2549
|
/**
|
|
2524
2550
|
* Your tenant ID (Client Code).
|
|
2525
2551
|
* This scopes all API requests to your specific organisation.
|
|
2526
|
-
* Required for most operations.
|
|
2527
2552
|
* @example "ERIX_CLNT_JHBJHF"
|
|
2528
2553
|
*/
|
|
2529
2554
|
clientCode?: string;
|
|
2530
2555
|
/**
|
|
2531
|
-
* Override
|
|
2532
|
-
*
|
|
2533
|
-
* @default "https://api.ecodrix.com"
|
|
2556
|
+
* @internal Override Socket.io URL for testing/staging.
|
|
2557
|
+
* Not documented — internal use only.
|
|
2534
2558
|
*/
|
|
2535
|
-
|
|
2559
|
+
socketUrl?: string;
|
|
2536
2560
|
/**
|
|
2537
|
-
* Override the
|
|
2538
|
-
*
|
|
2539
|
-
* @default "https://api.ecodrix.com"
|
|
2561
|
+
* @internal Override the backend API URL. Used by the CLI and internal tests only.
|
|
2562
|
+
* Host projects must never set this — the production URL is hardcoded internally.
|
|
2540
2563
|
*/
|
|
2541
|
-
|
|
2564
|
+
baseUrl?: string;
|
|
2542
2565
|
}
|
|
2543
2566
|
/**
|
|
2544
2567
|
* The primary entry point for the ECODrIx SDK.
|
|
@@ -2667,4 +2690,4 @@ declare class Ecodrix {
|
|
|
2667
2690
|
request<T = any>(method: Method, path: string, data?: any, params?: any): Promise<T>;
|
|
2668
2691
|
}
|
|
2669
2692
|
|
|
2670
|
-
export { APIError, Activities, Analytics, type AnalyticsParams, type AnalyticsRange, type AssignEventPayload, AuthenticationError, AutomationDashboard, type AutomationRulePayload, Automations, Broadcasts, CRM, type CampaignResult, Campaigns, type ClientHealth, Conversations, type CreateBroadcastParams, type CreateLeadParams, type CreateMeetingParams, type CreatePipelineParams, Ecodrix, EcodrixError, type EcodrixOptions, EmailResource, Emails, type EventDefinition, EventsResource, Files, Folders, Health, type JobStats, type JobStatus, type LeadSource, type LeadStatus, Leads, type ListLeadsParams, type ListParams, type LogActivityParams, type LogCallParams, type LogFilter, Marketing, MediaResource, Meetings, Messages, Notes, Notifications, Payments, type PipelineStageParams, Pipelines, Queue, RateLimitError, Scoring, type ScoringConfig, type SendCampaignParams, type SendCampaignPayload, type SendMessageParams, type SendTemplateParams, type SendTemplatePayload, Sequences, Storage, type SystemHealth, type TemplateMapping, Templates, type TriggerPayload, type TriggerResponse, type UpdateMeetingParams, type UploadOptions, type UpsertLeadParams, WebhookSignatureError, Webhooks, WhatsApp, WhatsAppMarketing, Ecodrix as default };
|
|
2693
|
+
export { APIError, Activities, Analytics, type AnalyticsParams, type AnalyticsRange, type AssignEventPayload, AuthenticationError, AutomationDashboard, type AutomationRulePayload, Automations, Broadcasts, CRM, type CampaignResult, Campaigns, type ChatMediaMeta, type ClientHealth, Conversations, type CreateBroadcastParams, type CreateLeadParams, type CreateMeetingParams, type CreatePipelineParams, Ecodrix, EcodrixError, type EcodrixOptions, EmailResource, Emails, type EventDefinition, EventsResource, Files, Folders, Health, type JobStats, type JobStatus, type LeadSource, type LeadStatus, Leads, type ListLeadsParams, type ListParams, type LogActivityParams, type LogCallParams, type LogFilter, Marketing, MediaResource, Meetings, Messages, Notes, Notifications, Payments, type PipelineStageParams, Pipelines, Queue, RateLimitError, Scoring, type ScoringConfig, type SendCampaignParams, type SendCampaignPayload, type SendMessageParams, type SendTemplateParams, type SendTemplatePayload, Sequences, Storage, type SystemHealth, type TemplateMapping, Templates, type TriggerPayload, type TriggerResponse, type UpdateMeetingParams, type UploadOptions, type UpsertLeadParams, WebhookSignatureError, Webhooks, WhatsApp, WhatsAppMarketing, Ecodrix as default };
|
package/dist/ts/esm/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var it=Object.defineProperty,ot=Object.defineProperties;var ct=Object.getOwnPropertyDescriptors;var st=Object.getOwnPropertySymbols;var pt=Object.prototype.hasOwnProperty,gt=Object.prototype.propertyIsEnumerable;var mt=(s,t)=>(t=Symbol[s])?t:Symbol.for("Symbol."+s);var V=(s,t,e)=>t in s?it(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,l=(s,t)=>{for(var e in t||(t={}))pt.call(t,e)&&V(s,e,t[e]);if(st)for(var e of st(t))gt.call(t,e)&&V(s,e,t[e]);return s},d=(s,t)=>ot(s,ct(t));var i=(s,t,e)=>V(s,typeof t!="symbol"?t+"":t,e);var W=function(s,t){this[0]=s,this[1]=t},at=(s,t,e)=>{var n=(p,g,c,u)=>{try{var T=e[p](g),f=(g=T.value)instanceof W,rt=T.done;Promise.resolve(f?g[0]:g).then(y=>f?n(p==="return"?p:"next",g[1]?{done:y.done,value:y.value}:y,c,u):c({value:y,done:rt})).catch(y=>n("throw",y,c,u))}catch(y){u(y)}},r=p=>o[p]=g=>new Promise((c,u)=>n(p,g,c,u)),o={};return e=e.apply(s,t),o[mt("asyncIterator")]=()=>o,r("next"),r("throw"),r("return"),o};import ut from"axios";import et from"axios-retry";import{io as yt}from"socket.io-client";var z=class extends Error{constructor(t){super(t),this.name="EcodrixError"}},m=class extends z{constructor(e,n,r){super(e);i(this,"status");i(this,"code");this.name="APIError",this.status=n,this.code=r}},x=class extends m{constructor(t="Invalid API Key or Client Code"){super(t,401,"AUTH_FAILED"),this.name="AuthenticationError"}},nt=class extends m{constructor(t="Too many requests. Please slow down."){super(t,429,"RATE_LIMIT_EXCEEDED"),this.name="RateLimitError"}};var a=class{constructor(t){this.client=t}async post(t,e,n){try{let r=this.buildConfig(n);return(await this.client.post(t,e,r)).data}catch(r){this.handleError(r)}}async get(t,e){try{let n=this.buildConfig(e);return(await this.client.get(t,n)).data}catch(n){this.handleError(n)}}async patch(t,e,n){try{let r=this.buildConfig(n);return(await this.client.patch(t,e,r)).data}catch(r){this.handleError(r)}}async put(t,e,n){try{let r=this.buildConfig(n);return(await this.client.put(t,e,r)).data}catch(r){this.handleError(r)}}async deleteRequest(t,e){try{let n=this.buildConfig(e);return(await this.client.delete(t,n)).data}catch(n){this.handleError(n)}}buildConfig(t){if(!t)return;let e=l({},t);return t.idempotencyKey&&(e.headers=d(l({},e.headers),{"Idempotency-Key":t.idempotencyKey})),e}handleError(t){var e,n,r;throw t.response?new m(((e=t.response.data)==null?void 0:e.message)||((n=t.response.data)==null?void 0:n.error)||"API Request Failed",t.response.status,(r=t.response.data)==null?void 0:r.code):new m(t.message||"Network Error")}};var G=class extends a{async list(t){return this.get(`/api/crm/leads/${t}/notes`)}async create(t,e){return this.post(`/api/crm/leads/${t}/notes`,e)}async update(t,e){return this.patch(`/api/crm/notes/${t}`,{content:e})}async pin(t,e=!0){return this.patch(`/api/crm/notes/${t}/pin`,{isPinned:e})}async delete(t){return this.deleteRequest(`/api/crm/notes/${t}`)}},P=class extends a{constructor(e){super(e);i(this,"notes");this.notes=new G(e)}async timeline(e,n){return this.get(`/api/crm/leads/${e}/timeline`,{params:n})}async list(e,n){return this.get(`/api/crm/leads/${e}/activities`,{params:l({},n)})}async log(e){return this.post(`/api/crm/leads/${e.leadId}/activities`,e)}async logCall(e,n){return this.post(`/api/crm/leads/${e}/calls`,n)}};var v=class extends a{async overview(t){return this.get("/api/crm/analytics/overview",{params:t})}async funnel(t){return this.get("/api/crm/analytics/funnel",{params:{pipelineId:t}})}async forecast(t){return this.get("/api/crm/analytics/forecast",{params:{pipelineId:t}})}async sources(t){return this.get("/api/crm/analytics/sources",{params:t})}async team(t){return this.get("/api/crm/analytics/team",{params:t})}async heatmap(t){return this.get("/api/crm/analytics/heatmap",{params:t})}async scores(){return this.get("/api/crm/analytics/scores")}async stageTime(t){return this.get("/api/crm/analytics/stage-time",{params:{pipelineId:t}})}async tiered(t){return this.get("/api/crm/analytics/tiered",{params:t})}async summary(t){return this.get("/api/crm/analytics/summary",{params:t})}async whatsapp(t){return this.get("/api/crm/analytics/whatsapp",{params:t})}};var w=class extends a{async stats(){return this.get("/api/crm/automation/stats")}async logs(t){return this.get("/api/crm/automation/logs",{params:t})}async retryFailedEvent(t){return this.post(`/api/crm/automation/logs/${t}/retry`,{})}};var R=class extends a{async list(){return this.get("/api/crm/automations")}async create(t){return this.post("/api/crm/automations",t)}async update(t,e){return this.patch(`/api/crm/automations/${t}`,e)}async toggle(t){return this.patch(`/api/crm/automations/${t}/toggle`)}async delete(t){return this.deleteRequest(`/api/crm/automations/${t}`)}async bulkDelete(t){return this.post("/api/crm/automations/bulk-delete",{ids:t})}async test(t,e){return this.post(`/api/crm/automations/${t}/test`,{leadId:e})}async getAvailableEvents(){return this.post("/api/crm/automations/events",{})}async enrollments(t,e){return this.get(`/api/crm/automations/${t}/enrollments`,{params:e})}async getEnrollment(t){return this.get(`/api/crm/automations/enrollments/${t}`)}async pauseEnrollment(t,e){return this.post(`/api/crm/automations/${t}/enrollments/${e}/pause`,{})}async resumeEnrollment(t,e){return this.post(`/api/crm/automations/${t}/enrollments/${e}/resume`,{})}async runs(t){return this.get(`/api/crm/automations/${t}/runs`)}async getRun(t){return this.get(`/api/crm/automations/runs/${t}`)}async resumeRun(t){return this.post(`/api/crm/automations/runs/${t}/resume`,{})}async abortRun(t){return this.post(`/api/crm/automations/runs/${t}/abort`,{})}async webhookEvent(t,e,n){return this.post("/api/crm/webhook-event",{ruleId:t,eventName:e,payload:n})}};var $=class extends a{async create(t){return this.post("/api/crm/leads",t)}async upsert(t){return this.post("/api/crm/leads/upsert",t)}async createMany(t,e=50){let n=[];for(let r=0;r<t.length;r+=e){let p=t.slice(r,r+e).map(c=>this.create(c)),g=await Promise.allSettled(p);for(let c of g)if(c.status==="fulfilled")n.push(c.value);else throw c.reason}return n}async import(t){return this.post("/api/crm/leads/import",{leads:t})}async list(t){let e=l({},t);return Array.isArray(e.tags)&&(e.tags=e.tags.join(",")),this.get("/api/crm/leads",{params:e})}listAutoPaging(t){return at(this,null,function*(){let e=(t==null?void 0:t.page)||1,n=!0;for(;n;){let r=yield new W(this.list(d(l({},t),{page:e}))),o=Array.isArray(r.data)?r.data:r||[];if(o.length===0){n=!1;break}for(let p of o)yield p;r.pagination&&e<r.pagination.pages||!r.pagination&&o.length>0?e++:n=!1}})}async retrieve(t){return this.get(`/api/crm/leads/${t}`)}async retrieveByPhone(t){return this.get(`/api/crm/leads/phone/${encodeURIComponent(t)}`)}async retrieveByRef(t,e){return this.get(`/api/crm/leads/ref/${encodeURIComponent(t)}/${encodeURIComponent(e)}`)}async update(t,e){return this.patch(`/api/crm/leads/${t}`,e)}async move(t,e){return this.patch(`/api/crm/leads/${t}/move`,{stageId:e})}async convert(t,e,n){return this.post(`/api/crm/leads/${t}/convert`,{outcome:e,reason:n})}async tags(t,e){return this.patch(`/api/crm/leads/${t}/tags`,e)}async recalculateScore(t){return this.post(`/api/crm/leads/${t}/score`,{})}async updateMetadata(t,e){return this.patch(`/api/crm/leads/${t}/metadata`,e)}async fields(){return this.get("/api/crm/leads/fields")}async notes(t){return this.get(`/api/crm/leads/${t}/notes`)}async activities(t,e){return this.get(`/api/crm/leads/${t}/timeline`,{params:e})}async createNote(t,e){return this.post(`/api/crm/leads/${t}/notes`,e)}async updateNote(t,e,n){return this.patch(`/api/crm/notes/${e}`,n)}async deleteNote(t,e){return this.deleteRequest(`/api/crm/notes/${e}`)}async delete(t){return this.deleteRequest(`/api/crm/leads/${t}`)}async bulkDelete(t){return this.deleteRequest("/api/crm/leads",{data:{ids:t}})}};var I=class extends a{async capture(t){return this.post("/api/crm/payments/capture",t)}};var A=class extends a{async list(){return this.get("/api/crm/pipelines")}async create(t){return this.post("/api/crm/pipelines",t)}async retrieve(t){return this.get(`/api/crm/pipelines/${t}`)}async update(t,e){return this.patch(`/api/crm/pipelines/${t}`,e)}async setDefault(t){return this.patch(`/api/crm/pipelines/${t}/default`,{})}async duplicate(t,e){return this.post(`/api/crm/pipelines/${t}/duplicate`,{newName:e})}async archive(t){return this.patch(`/api/crm/pipelines/${t}/archive`,{})}async delete(t){return this.deleteRequest(`/api/crm/pipelines/${t}`)}async board(t){return this.get(`/api/crm/pipelines/${t}/board`)}async forecast(t){return this.get(`/api/crm/pipelines/${t}/forecast`)}async addStage(t,e){return this.post(`/api/crm/pipelines/${t}/stages`,e)}async reorderStages(t,e){return this.patch(`/api/crm/pipelines/${t}/stages/reorder`,{order:e})}async updateStage(t,e){return this.patch(`/api/crm/stages/${t}`,e)}async deleteStage(t,e){return this.deleteRequest(`/api/crm/stages/${t}`,{data:e?{moveLeadsToStageId:e}:void 0})}};var C=class extends a{async getConfig(){return this.get("/api/crm/scoring")}async updateConfig(t){return this.patch("/api/crm/scoring",t)}async recalculate(t){return this.post(`/api/crm/scoring/${t}/recalculate`,{})}};var k=class extends a{async enroll(t){return this.post("/api/crm/sequences/enroll",t)}async unenroll(t){return this.deleteRequest(`/api/crm/sequences/unenroll/${t}`)}async listForLead(t){return this.get(`/api/crm/sequences/lead/${t}`)}};var q=class{constructor(t){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 $(t),this.pipelines=new A(t),this.activities=new P(t),this.analytics=new v(t),this.automations=new R(t),this.sequences=new k(t),this.scoring=new C(t),this.payments=new I(t),this.automationDashboard=new w(t)}};var S=class extends a{async sendEmailCampaign(t){return this.post("/api/saas/emails/campaign",t)}async sendTestEmail(t){return this.post("/api/saas/emails/test",{to:t})}};var E=class extends a{async list(){return this.get("/api/saas/events")}async assign(t){return this.post("/api/saas/events/assign",t)}async unassign(t){return this.post("/api/saas/events/unassign",{name:t})}async unassignBulk(t){return this.post("/api/saas/events/unassign/bulk",{names:t})}async trigger(t){return this.post("/api/saas/workflows/trigger",t)}async listCustomEvents(){return this.get("/api/saas/crm/custom-events")}async createCustomEvent(t){return this.post("/api/saas/crm/custom-events",t)}async deleteCustomEvent(t){return this.deleteRequest(`/api/saas/crm/custom-events/${t}`)}async emit(t){return this.post("/api/saas/crm/events/emit",t)}};var D=class extends a{async system(){return(await this.get("/api/saas/health",{headers:{accept:"application/json"}})).data}async clientHealth(){return(await this.get("/api/saas/health/client")).data}async jobStatus(t){return(await this.get(`/api/saas/jobs/status/${t}`)).data}};var Q=class extends a{async sendCampaign(t){return this.post("/api/saas/marketing/emails/campaign",t)}async sendTest(t){return this.post("/api/saas/marketing/emails/test",{to:t})}},X=class extends a{async list(t){return this.get("/api/saas/marketing/campaigns",{params:t})}async create(t){return this.post("/api/saas/marketing/campaigns",t)}async retrieve(t){return this.get(`/api/saas/marketing/campaigns/${t}`)}async update(t,e){return this.patch(`/api/saas/marketing/campaigns/${t}`,e)}async delete(t){return this.deleteRequest(`/api/saas/marketing/campaigns/${t}`)}async send(t,e){return this.post(`/api/saas/marketing/campaigns/${t}/send`,e||{})}async stats(t){return this.get(`/api/saas/marketing/campaigns/${t}/stats`)}},Y=class extends a{async sendTemplate(t){return this.post("/api/saas/marketing/whatsapp/send-template",t)}},L=class extends a{constructor(e){super(e);i(this,"emails");i(this,"campaigns");i(this,"whatsapp");this.emails=new Q(e),this.campaigns=new X(e),this.whatsapp=new Y(e)}};import lt from"axios";var U=class extends a{async getUsage(){return this.get("/api/saas/storage/usage")}async createFolder(t){return this.post("/api/saas/storage/folders",{name:t})}async list(t,e){return this.get(`/api/saas/storage/files/${t}`,{params:e})}async delete(t){return this.deleteRequest("/api/saas/storage/files",{params:{key:t}})}async getDownloadUrl(t){return this.post("/api/saas/storage/download-url",{key:t})}async upload(t,e){let{data:n}=await this.client.post("/api/saas/storage/upload-url",e),{uploadUrl:r,key:o}=n;await lt.put(r,t,{headers:{"Content-Type":e.contentType}});let p=t.size||t.byteLength||0;return this.post("/api/saas/storage/confirm-upload",{key:o,sizeBytes:p})}};var M=class extends a{async create(t){return this.post("/api/saas/meet",t)}async list(t){return this.get("/api/saas/meet",{params:t})}async retrieve(t){return this.get(`/api/saas/meet/${t}`)}async update(t,e){return this.patch(`/api/saas/meet/${t}`,e)}async reschedule(t,e){return this.patch(`/api/saas/meet/${t}`,e)}async delete(t){return this.update(t,{status:"cancelled"})}};var N=class extends a{async listLogs(t){return this.get("/api/saas/events/logs",{params:t})}async retrieveLog(t){return this.get(`/api/saas/events/logs/${t}`)}async getStats(t){return this.get("/api/saas/events/stats",{params:t})}async listCallbacks(t){return this.get("/api/saas/callbacks/logs",{params:t})}async listAlerts(t){return this.get("/api/crm/notifications",{params:t})}async dismissAlert(t){return this.patch(`/api/crm/notifications/${t}/dismiss`)}async clearAllAlerts(){return this.deleteRequest("/api/crm/notifications/clear-all")}async retryAction(t){return this.post(`/api/crm/notifications/${t}/retry`,{})}};var O=class extends a{async listFailed(){return this.get("/api/saas/admin/queue/failed")}async getStats(){return this.get("/api/saas/admin/queue/stats")}async retryJob(t){return this.post(`/api/saas/admin/queue/${t}/retry`,{})}async deleteJob(t){return this.deleteRequest(`/api/saas/admin/queue/${t}`)}};var Z=class extends a{async create(t){return this.post("/api/saas/storage/folders",{name:t})}async delete(t){return this.deleteRequest(`/api/saas/storage/folders/${encodeURIComponent(t)}`)}},tt=class extends a{async list(t,e){return this.get(`/api/saas/storage/files/${t}`,{params:e})}async getUploadUrl(t){return this.post("/api/saas/storage/upload-url",t)}async confirmUpload(t){return this.post("/api/saas/storage/confirm-upload",t)}async getDownloadUrl(t){return this.post("/api/saas/storage/download-url",{key:t})}async delete(t){return this.deleteRequest("/api/saas/storage/files",{params:{key:t}})}},B=class extends a{constructor(e){super(e);i(this,"folders");i(this,"files");this.folders=new Z(e),this.files=new tt(e)}async usage(){return this.get("/api/saas/storage/usage")}};var h=class extends m{constructor(t){super(t,400,"invalid_signature"),this.name="WebhookSignatureError"}},F=class{async constructEvent(t,e,n){if(!e)throw new h("No webhook signature provided");let r=Array.isArray(e)?e[0]:e;r.startsWith("sha256=")&&(r=r.slice(7));try{let o=await import("crypto"),g=o.createHmac("sha256",n).update(t).digest("hex");if(!o.timingSafeEqual(Buffer.from(g),Buffer.from(r)))throw new h("Invalid webhook signature provided");return JSON.parse(t.toString("utf8"))}catch(o){throw o instanceof h?o:new h(`Webhook payload parsing failed: ${o.message}`)}}};var H=class extends a{async list(t){return this.get("/api/saas/chat/broadcasts",{params:t})}async retrieve(t){return this.get(`/api/saas/chat/broadcasts/${t}`)}async create(t){return this.post("/api/saas/chat/broadcast",t)}async update(t,e){return this.patch(`/api/saas/chat/broadcasts/${t}`,e)}async delete(t){return this.deleteRequest(`/api/saas/chat/broadcasts/${t}`)}};var j=class extends a{async list(t){return this.get("/api/saas/chat/conversations",{params:t})}async create(t){return this.post("/api/saas/chat/conversations",t)}async retrieve(t){return this.get(`/api/saas/chat/conversations/${t}`)}async messages(t,e){return this.get(`/api/saas/chat/conversations/${t}/messages`,{params:e})}async linkLead(t,e,n){return this.post(`/api/saas/chat/conversations/${t}/link-lead`,{leadId:e,leadData:n})}async markRead(t){return this.post(`/api/saas/chat/conversations/${t}/read`,{})}async delete(t){return this.deleteRequest(`/api/saas/chat/conversations/${t}`)}async bulkDelete(t){return this.post("/api/saas/chat/conversations/bulk-delete",{ids:t})}};var _=class extends a{async send(t){return this.post("/api/saas/chat/send",t)}async sendTemplate(t){return this.post("/api/saas/chat/send",d(l({},t),{templateLanguage:t.language||t.templateLanguage||"en_US"}))}async star(t,e){return this.post(`/api/saas/chat/messages/${t}/star`,{isStarred:e})}async react(t,e){return this.post(`/api/saas/chat/messages/${t}/react`,{reaction:e})}async markRead(t){return this.post(`/api/saas/chat/conversations/${t}/read`)}async upload(t){let e=new FormData;return e.append("file",t),this.post("/api/saas/chat/upload",e,{headers:{"Content-Type":"multipart/form-data"}})}};var K=class extends a{async list(t){return this.get("/api/saas/chat/templates",{params:t})}async sync(){return this.post("/api/saas/chat/templates/sync",{})}async retrieve(t){return this.get(`/api/saas/chat/templates/${encodeURIComponent(t)}`)}async create(t){return this.post("/api/saas/chat/templates",t)}async update(t,e){return this.put(`/api/saas/chat/templates/${t}`,e)}async deleteTemplate(t,e){return this.deleteRequest(`/api/saas/chat/templates/${encodeURIComponent(t)}${e?"?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(t){return this.get(`/api/saas/chat/templates/collections/${encodeURIComponent(t)}/fields`)}async updateMapping(t,e){return this.put(`/api/saas/chat/templates/${encodeURIComponent(t)}/mapping`,e)}async validate(t){return this.get(`/api/saas/chat/templates/${encodeURIComponent(t)}/validate`)}async preview(t,e){return this.post(`/api/saas/chat/templates/${encodeURIComponent(t)}/preview`,{context:e})}async checkUsage(t){return this.get(`/api/saas/chat/templates/${encodeURIComponent(t)}/usage`)}};var J=class extends a{constructor(e){super(e);i(this,"messages");i(this,"conversations");i(this,"broadcasts");i(this,"templates");this.messages=new _(e),this.conversations=new j(e),this.broadcasts=new H(e),this.templates=new K(e)}async upload(e,n){let r=new FormData;return r.append("file",e,n),this.post("/api/saas/chat/upload",r,{headers:typeof r.getHeaders=="function"?r.getHeaders():void 0})}async sendTemplate(e){return this.post("/api/saas/marketing/whatsapp/send-template",e)}};var b=class{constructor(t){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,"events");i(this,"webhooks");i(this,"storage");i(this,"marketing");i(this,"health");i(this,"queue");var g,c,u;if(!t.apiKey)throw new x("API Key is required");let e=t.baseUrl||"https://api.ecodrix.com",n=t.socketUrl||e,r=typeof window!="undefined"&&typeof window.document!="undefined",o=r?"browser":typeof process!="undefined"?`node ${process.version}`:"unknown",p=r?((g=globalThis.navigator)==null?void 0:g.userAgent)||"browser":typeof process!="undefined"?process.platform:"unknown";this.client=ut.create({baseURL:e,headers:{"x-api-key":t.apiKey,"x-client-code":(c=t.clientCode)==null?void 0:c.toUpperCase(),"Content-Type":"application/json","x-ecodrix-client-agent":JSON.stringify({sdk_version:"1.0.0",runtime:o,os:p})}}),et(this.client,{retries:3,retryDelay:et.exponentialDelay,retryCondition:T=>{var f;return et.isNetworkOrIdempotentRequestError(T)||((f=T.response)==null?void 0:f.status)===429}}),this.whatsapp=new J(this.client),this.crm=new q(this.client),this.media=new U(this.client),this.meet=new M(this.client),this.notifications=new N(this.client),this.email=new S(this.client),this.events=new E(this.client),this.webhooks=new F,this.storage=new B(this.client),this.marketing=new L(this.client),this.health=new D(this.client),this.queue=new O(this.client),this.socket=yt(n,{extraHeaders:{"x-api-key":t.apiKey,"x-client-code":((u=t.clientCode)==null?void 0:u.toUpperCase())||""}}),this.setupSocket(t.clientCode)}joinRoom(t){this.socket.emit("join-room",t)}leaveRoom(t){this.socket.emit("leave-room",t)}setupSocket(t){this.socket.on("connect",()=>{t&&this.socket.emit("join-room",t.toUpperCase())})}on(t,e){return this.socket.on(t,e),this}disconnect(){this.socket.disconnect()}off(t,e){return this.socket.off(t,e),this}async request(t,e,n,r){var o,p,g;try{return(await this.client.request({method:t,url:e,data:n,params:r})).data}catch(c){throw c.response?new m(((o=c.response.data)==null?void 0:o.message)||((p=c.response.data)==null?void 0:p.error)||"Raw Execution Failed",c.response.status,(g=c.response.data)==null?void 0:g.code):new m(c.message||"Network Error")}}};var ss=b;export{m as APIError,P as Activities,v as Analytics,x as AuthenticationError,w as AutomationDashboard,R as Automations,H as Broadcasts,q as CRM,X as Campaigns,j as Conversations,b as Ecodrix,z as EcodrixError,S as EmailResource,Q as Emails,E as EventsResource,tt as Files,Z as Folders,D as Health,$ as Leads,L as Marketing,U as MediaResource,M as Meetings,_ as Messages,G as Notes,N as Notifications,I as Payments,A as Pipelines,O as Queue,nt as RateLimitError,C as Scoring,k as Sequences,B as Storage,K as Templates,h as WebhookSignatureError,F as Webhooks,J as WhatsApp,Y as WhatsAppMarketing,ss as default};
|
|
1
|
+
var it=Object.defineProperty,ot=Object.defineProperties;var ct=Object.getOwnPropertyDescriptors;var at=Object.getOwnPropertySymbols;var pt=Object.prototype.hasOwnProperty,gt=Object.prototype.propertyIsEnumerable;var mt=(s,t)=>(t=Symbol[s])?t:Symbol.for("Symbol."+s);var W=(s,t,e)=>t in s?it(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,l=(s,t)=>{for(var e in t||(t={}))pt.call(t,e)&&W(s,e,t[e]);if(at)for(var e of at(t))gt.call(t,e)&&W(s,e,t[e]);return s},d=(s,t)=>ot(s,ct(t));var i=(s,t,e)=>W(s,typeof t!="symbol"?t+"":t,e);var z=function(s,t){this[0]=s,this[1]=t},nt=(s,t,e)=>{var n=(p,g,c,u)=>{try{var T=e[p](g),f=(g=T.value)instanceof z,x=T.done;Promise.resolve(f?g[0]:g).then(y=>f?n(p==="return"?p:"next",g[1]?{done:y.done,value:y.value}:y,c,u):c({value:y,done:x})).catch(y=>n("throw",y,c,u))}catch(y){u(y)}},r=p=>o[p]=g=>new Promise((c,u)=>n(p,g,c,u)),o={};return e=e.apply(s,t),o[mt("asyncIterator")]=()=>o,r("next"),r("throw"),r("return"),o};import ut from"axios";import st from"axios-retry";import{io as yt}from"socket.io-client";var G=class extends Error{constructor(t){super(t),this.name="EcodrixError"}},m=class extends G{constructor(e,n,r){super(e);i(this,"status");i(this,"code");this.name="APIError",this.status=n,this.code=r}},P=class extends m{constructor(t="Invalid API Key or Client Code"){super(t,401,"AUTH_FAILED"),this.name="AuthenticationError"}},rt=class extends m{constructor(t="Too many requests. Please slow down."){super(t,429,"RATE_LIMIT_EXCEEDED"),this.name="RateLimitError"}};var a=class{constructor(t){this.client=t}async post(t,e,n){try{let r=this.buildConfig(n);return(await this.client.post(t,e,r)).data}catch(r){this.handleError(r)}}async get(t,e){try{let n=this.buildConfig(e);return(await this.client.get(t,n)).data}catch(n){this.handleError(n)}}async patch(t,e,n){try{let r=this.buildConfig(n);return(await this.client.patch(t,e,r)).data}catch(r){this.handleError(r)}}async put(t,e,n){try{let r=this.buildConfig(n);return(await this.client.put(t,e,r)).data}catch(r){this.handleError(r)}}async deleteRequest(t,e){try{let n=this.buildConfig(e);return(await this.client.delete(t,n)).data}catch(n){this.handleError(n)}}buildConfig(t){if(!t)return;let e=l({},t);return t.idempotencyKey&&(e.headers=d(l({},e.headers),{"Idempotency-Key":t.idempotencyKey})),e}handleError(t){var e,n,r;throw t.response?new m(((e=t.response.data)==null?void 0:e.message)||((n=t.response.data)==null?void 0:n.error)||"API Request Failed",t.response.status,(r=t.response.data)==null?void 0:r.code):new m(t.message||"Network Error")}};var Q=class extends a{async list(t){return this.get(`/api/crm/leads/${t}/notes`)}async create(t,e){return this.post(`/api/crm/leads/${t}/notes`,e)}async update(t,e){return this.patch(`/api/crm/notes/${t}`,{content:e})}async pin(t,e=!0){return this.patch(`/api/crm/notes/${t}/pin`,{isPinned:e})}async delete(t){return this.deleteRequest(`/api/crm/notes/${t}`)}},v=class extends a{constructor(e){super(e);i(this,"notes");this.notes=new Q(e)}async timeline(e,n){return this.get(`/api/crm/leads/${e}/timeline`,{params:n})}async list(e,n){return this.get(`/api/crm/leads/${e}/activities`,{params:l({},n)})}async log(e){return this.post(`/api/crm/leads/${e.leadId}/activities`,e)}async logCall(e,n){return this.post(`/api/crm/leads/${e}/calls`,n)}};var w=class extends a{async overview(t){return this.get("/api/crm/analytics/overview",{params:t})}async funnel(t){return this.get("/api/crm/analytics/funnel",{params:{pipelineId:t}})}async forecast(t){return this.get("/api/crm/analytics/forecast",{params:{pipelineId:t}})}async sources(t){return this.get("/api/crm/analytics/sources",{params:t})}async team(t){return this.get("/api/crm/analytics/team",{params:t})}async heatmap(t){return this.get("/api/crm/analytics/heatmap",{params:t})}async scores(){return this.get("/api/crm/analytics/scores")}async stageTime(t){return this.get("/api/crm/analytics/stage-time",{params:{pipelineId:t}})}async tiered(t){return this.get("/api/crm/analytics/tiered",{params:t})}async summary(t){return this.get("/api/crm/analytics/summary",{params:t})}async whatsapp(t){return this.get("/api/crm/analytics/whatsapp",{params:t})}};var R=class extends a{async stats(){return this.get("/api/crm/automation/stats")}async logs(t){return this.get("/api/crm/automation/logs",{params:t})}async retryFailedEvent(t){return this.post(`/api/crm/automation/logs/${t}/retry`,{})}};var A=class extends a{async list(){return this.get("/api/crm/automations")}async create(t){return this.post("/api/crm/automations",t)}async update(t,e){return this.patch(`/api/crm/automations/${t}`,e)}async toggle(t){return this.patch(`/api/crm/automations/${t}/toggle`)}async delete(t){return this.deleteRequest(`/api/crm/automations/${t}`)}async bulkDelete(t){return this.post("/api/crm/automations/bulk-delete",{ids:t})}async test(t,e){return this.post(`/api/crm/automations/${t}/test`,{leadId:e})}async getAvailableEvents(){return this.post("/api/crm/automations/events",{})}async enrollments(t,e){return this.get(`/api/crm/automations/${t}/enrollments`,{params:e})}async getEnrollment(t){return this.get(`/api/crm/automations/enrollments/${t}`)}async pauseEnrollment(t,e){return this.post(`/api/crm/automations/${t}/enrollments/${e}/pause`,{})}async resumeEnrollment(t,e){return this.post(`/api/crm/automations/${t}/enrollments/${e}/resume`,{})}async runs(t){return this.get(`/api/crm/automations/${t}/runs`)}async getRun(t){return this.get(`/api/crm/automations/runs/${t}`)}async resumeRun(t){return this.post(`/api/crm/automations/runs/${t}/resume`,{})}async abortRun(t){return this.post(`/api/crm/automations/runs/${t}/abort`,{})}async webhookEvent(t,e,n){return this.post("/api/crm/webhook-event",{ruleId:t,eventName:e,payload:n})}};var I=class extends a{async create(t){return this.post("/api/crm/leads",t)}async upsert(t){return this.post("/api/crm/leads/upsert",t)}async createMany(t,e=50){let n=[];for(let r=0;r<t.length;r+=e){let p=t.slice(r,r+e).map(c=>this.create(c)),g=await Promise.allSettled(p);for(let c of g)if(c.status==="fulfilled")n.push(c.value);else throw c.reason}return n}async import(t){return this.post("/api/crm/leads/import",{leads:t})}async list(t){let e=l({},t);return Array.isArray(e.tags)&&(e.tags=e.tags.join(",")),this.get("/api/crm/leads",{params:e})}listAutoPaging(t){return nt(this,null,function*(){let e=(t==null?void 0:t.page)||1,n=!0;for(;n;){let r=yield new z(this.list(d(l({},t),{page:e}))),o=Array.isArray(r.data)?r.data:r||[];if(o.length===0){n=!1;break}for(let p of o)yield p;r.pagination&&e<r.pagination.pages||!r.pagination&&o.length>0?e++:n=!1}})}async retrieve(t){return this.get(`/api/crm/leads/${t}`)}async retrieveByPhone(t){return this.get(`/api/crm/leads/phone/${encodeURIComponent(t)}`)}async retrieveByRef(t,e){return this.get(`/api/crm/leads/ref/${encodeURIComponent(t)}/${encodeURIComponent(e)}`)}async update(t,e){return this.patch(`/api/crm/leads/${t}`,e)}async move(t,e){return this.patch(`/api/crm/leads/${t}/move`,{stageId:e})}async convert(t,e,n){return this.post(`/api/crm/leads/${t}/convert`,{outcome:e,reason:n})}async tags(t,e){return this.patch(`/api/crm/leads/${t}/tags`,e)}async recalculateScore(t){return this.post(`/api/crm/leads/${t}/score`,{})}async updateMetadata(t,e){return this.patch(`/api/crm/leads/${t}/metadata`,e)}async fields(){return this.get("/api/crm/leads/fields")}async notes(t){return this.get(`/api/crm/leads/${t}/notes`)}async activities(t,e){return this.get(`/api/crm/leads/${t}/timeline`,{params:e})}async createNote(t,e){return this.post(`/api/crm/leads/${t}/notes`,e)}async updateNote(t,e,n){return this.patch(`/api/crm/notes/${e}`,n)}async deleteNote(t,e){return this.deleteRequest(`/api/crm/notes/${e}`)}async delete(t){return this.deleteRequest(`/api/crm/leads/${t}`)}async bulkDelete(t){return this.deleteRequest("/api/crm/leads",{data:{ids:t}})}};var $=class extends a{async capture(t){return this.post("/api/crm/payments/capture",t)}};var C=class extends a{async list(){return this.get("/api/crm/pipelines")}async create(t){return this.post("/api/crm/pipelines",t)}async retrieve(t){return this.get(`/api/crm/pipelines/${t}`)}async update(t,e){return this.patch(`/api/crm/pipelines/${t}`,e)}async setDefault(t){return this.patch(`/api/crm/pipelines/${t}/default`,{})}async duplicate(t,e){return this.post(`/api/crm/pipelines/${t}/duplicate`,{newName:e})}async archive(t){return this.patch(`/api/crm/pipelines/${t}/archive`,{})}async delete(t){return this.deleteRequest(`/api/crm/pipelines/${t}`)}async board(t){return this.get(`/api/crm/pipelines/${t}/board`)}async forecast(t){return this.get(`/api/crm/pipelines/${t}/forecast`)}async addStage(t,e){return this.post(`/api/crm/pipelines/${t}/stages`,e)}async reorderStages(t,e){return this.patch(`/api/crm/pipelines/${t}/stages/reorder`,{order:e})}async updateStage(t,e){return this.patch(`/api/crm/stages/${t}`,e)}async deleteStage(t,e){return this.deleteRequest(`/api/crm/stages/${t}`,{data:e?{moveLeadsToStageId:e}:void 0})}};var k=class extends a{async getConfig(){return this.get("/api/crm/scoring")}async updateConfig(t){return this.patch("/api/crm/scoring",t)}async recalculate(t){return this.post(`/api/crm/scoring/${t}/recalculate`,{})}};var q=class extends a{async enroll(t){return this.post("/api/crm/sequences/enroll",t)}async unenroll(t){return this.deleteRequest(`/api/crm/sequences/unenroll/${t}`)}async listForLead(t){return this.get(`/api/crm/sequences/lead/${t}`)}};var S=class{constructor(t){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(t),this.pipelines=new C(t),this.activities=new v(t),this.analytics=new w(t),this.automations=new A(t),this.sequences=new q(t),this.scoring=new k(t),this.payments=new $(t),this.automationDashboard=new R(t)}};var E=class extends a{async sendEmailCampaign(t){return this.post("/api/saas/emails/campaign",t)}async sendTestEmail(t){return this.post("/api/saas/emails/test",{to:t})}};var D=class extends a{async list(){return this.get("/api/saas/events")}async assign(t){return this.post("/api/saas/events/assign",t)}async unassign(t){return this.post("/api/saas/events/unassign",{name:t})}async unassignBulk(t){return this.post("/api/saas/events/unassign/bulk",{names:t})}async trigger(t){return this.post("/api/saas/workflows/trigger",t)}async listCustomEvents(){return this.get("/api/saas/crm/custom-events")}async createCustomEvent(t){return this.post("/api/saas/crm/custom-events",t)}async deleteCustomEvent(t){return this.deleteRequest(`/api/saas/crm/custom-events/${t}`)}async emit(t){return this.post("/api/saas/crm/events/emit",t)}};var L=class extends a{async system(){return(await this.get("/api/saas/health",{headers:{accept:"application/json"}})).data}async clientHealth(){return(await this.get("/api/saas/health/client")).data}async jobStatus(t){return(await this.get(`/api/saas/jobs/status/${t}`)).data}};var X=class extends a{async sendCampaign(t){return this.post("/api/saas/marketing/emails/campaign",t)}async sendTest(t){return this.post("/api/saas/marketing/emails/test",{to:t})}},Y=class extends a{async list(t){return this.get("/api/saas/marketing/campaigns",{params:t})}async create(t){return this.post("/api/saas/marketing/campaigns",t)}async retrieve(t){return this.get(`/api/saas/marketing/campaigns/${t}`)}async update(t,e){return this.patch(`/api/saas/marketing/campaigns/${t}`,e)}async delete(t){return this.deleteRequest(`/api/saas/marketing/campaigns/${t}`)}async send(t,e){return this.post(`/api/saas/marketing/campaigns/${t}/send`,e||{})}async stats(t){return this.get(`/api/saas/marketing/campaigns/${t}/stats`)}},Z=class extends a{async sendTemplate(t){return this.post("/api/saas/marketing/whatsapp/send-template",t)}},U=class extends a{constructor(e){super(e);i(this,"emails");i(this,"campaigns");i(this,"whatsapp");this.emails=new X(e),this.campaigns=new Y(e),this.whatsapp=new Z(e)}};import lt from"axios";var M=class extends a{async getUsage(){return this.get("/api/saas/storage/usage")}async createFolder(t){return this.post("/api/saas/storage/folders",{name:t})}async list(t,e){return this.get(`/api/saas/storage/files/${t}`,{params:e})}async delete(t){return this.deleteRequest("/api/saas/storage/files",{params:{key:t}})}async getDownloadUrl(t){return this.post("/api/saas/storage/download-url",{key:t})}async upload(t,e){let{data:n}=await this.client.post("/api/saas/storage/upload-url",e),{uploadUrl:r,key:o}=n;await lt.put(r,t,{headers:{"Content-Type":e.contentType}});let p=t.size||t.byteLength||0;return this.post("/api/saas/storage/confirm-upload",{key:o,sizeBytes:p})}};var N=class extends a{async create(t){return this.post("/api/saas/meet",t)}async list(t){return this.get("/api/saas/meet",{params:t})}async retrieve(t){return this.get(`/api/saas/meet/${t}`)}async update(t,e){return this.patch(`/api/saas/meet/${t}`,e)}async reschedule(t,e){return this.patch(`/api/saas/meet/${t}`,e)}async delete(t){return this.update(t,{status:"cancelled"})}};var O=class extends a{async listLogs(t){return this.get("/api/saas/events/logs",{params:t})}async retrieveLog(t){return this.get(`/api/saas/events/logs/${t}`)}async getStats(t){return this.get("/api/saas/events/stats",{params:t})}async listCallbacks(t){return this.get("/api/saas/callbacks/logs",{params:t})}async listAlerts(t){return this.get("/api/crm/notifications",{params:t})}async dismissAlert(t){return this.patch(`/api/crm/notifications/${t}/dismiss`)}async clearAllAlerts(){return this.deleteRequest("/api/crm/notifications/clear-all")}async retryAction(t){return this.post(`/api/crm/notifications/${t}/retry`,{})}};var B=class extends a{async listFailed(){return this.get("/api/saas/admin/queue/failed")}async getStats(){return this.get("/api/saas/admin/queue/stats")}async retryJob(t){return this.post(`/api/saas/admin/queue/${t}/retry`,{})}async deleteJob(t){return this.deleteRequest(`/api/saas/admin/queue/${t}`)}};var tt=class extends a{async create(t){return this.post("/api/saas/storage/folders",{name:t})}async delete(t){return this.deleteRequest(`/api/saas/storage/folders/${encodeURIComponent(t)}`)}},et=class extends a{async list(t,e){return this.get(`/api/saas/storage/files/${t}`,{params:e})}async getUploadUrl(t){return this.post("/api/saas/storage/upload-url",t)}async confirmUpload(t){return this.post("/api/saas/storage/confirm-upload",t)}async getDownloadUrl(t){return this.post("/api/saas/storage/download-url",{key:t})}async delete(t){return this.deleteRequest("/api/saas/storage/files",{params:{key:t}})}},F=class extends a{constructor(e){super(e);i(this,"folders");i(this,"files");this.folders=new tt(e),this.files=new et(e)}async usage(){return this.get("/api/saas/storage/usage")}};var h=class extends m{constructor(t){super(t,400,"invalid_signature"),this.name="WebhookSignatureError"}},H=class{async constructEvent(t,e,n){if(!e)throw new h("No webhook signature provided");let r=Array.isArray(e)?e[0]:e;r.startsWith("sha256=")&&(r=r.slice(7));try{let o=await import("crypto"),g=o.createHmac("sha256",n).update(t).digest("hex");if(!o.timingSafeEqual(Buffer.from(g),Buffer.from(r)))throw new h("Invalid webhook signature provided");return JSON.parse(t.toString("utf8"))}catch(o){throw o instanceof h?o:new h(`Webhook payload parsing failed: ${o.message}`)}}};var _=class extends a{async list(t){return this.get("/api/saas/chat/broadcasts",{params:t})}async retrieve(t){return this.get(`/api/saas/chat/broadcasts/${t}`)}async create(t){return this.post("/api/saas/chat/broadcast",t)}async update(t,e){return this.patch(`/api/saas/chat/broadcasts/${t}`,e)}async delete(t){return this.deleteRequest(`/api/saas/chat/broadcasts/${t}`)}};var j=class extends a{async list(t){return this.get("/api/saas/chat/conversations",{params:t})}async create(t){return this.post("/api/saas/chat/conversations",t)}async retrieve(t){return this.get(`/api/saas/chat/conversations/${t}`)}async messages(t,e){return this.get(`/api/saas/chat/conversations/${t}/messages`,{params:e})}async linkLead(t,e,n){return this.post(`/api/saas/chat/conversations/${t}/link-lead`,{leadId:e,leadData:n})}async markRead(t){return this.post(`/api/saas/chat/conversations/${t}/read`,{})}async delete(t){return this.deleteRequest(`/api/saas/chat/conversations/${t}`)}async bulkDelete(t){return this.post("/api/saas/chat/conversations/bulk-delete",{ids:t})}};var K=class extends a{async send(t){return this.post("/api/saas/chat/send",t)}async sendTemplate(t){return this.post("/api/saas/chat/send",d(l({},t),{templateLanguage:t.language||t.templateLanguage||"en_US"}))}async star(t,e){return this.post(`/api/saas/chat/messages/${t}/star`,{isStarred:e})}async react(t,e){return this.post(`/api/saas/chat/messages/${t}/react`,{reaction:e})}async markRead(t){return this.post(`/api/saas/chat/conversations/${t}/read`)}async upload(t){let e=new FormData;return e.append("file",t),this.post("/api/saas/chat/upload",e,{headers:{"Content-Type":"multipart/form-data"}})}};var J=class extends a{async list(t){return this.get("/api/saas/chat/templates",{params:t})}async sync(){return this.post("/api/saas/chat/templates/sync",{})}async retrieve(t){return this.get(`/api/saas/chat/templates/${encodeURIComponent(t)}`)}async create(t){return this.post("/api/saas/chat/templates",t)}async update(t,e){return this.put(`/api/saas/chat/templates/${t}`,e)}async deleteTemplate(t,e){return this.deleteRequest(`/api/saas/chat/templates/${encodeURIComponent(t)}${e?"?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(t){return this.get(`/api/saas/chat/templates/collections/${encodeURIComponent(t)}/fields`)}async updateMapping(t,e){return this.put(`/api/saas/chat/templates/${encodeURIComponent(t)}/mapping`,e)}async validate(t){return this.get(`/api/saas/chat/templates/${encodeURIComponent(t)}/validate`)}async preview(t,e){return this.post(`/api/saas/chat/templates/${encodeURIComponent(t)}/preview`,{context:e})}async checkUsage(t){return this.get(`/api/saas/chat/templates/${encodeURIComponent(t)}/usage`)}};var V=class extends a{constructor(e){super(e);i(this,"messages");i(this,"conversations");i(this,"broadcasts");i(this,"templates");this.messages=new K(e),this.conversations=new j(e),this.broadcasts=new _(e),this.templates=new J(e)}async upload(e,n){let r=new FormData;return r.append("file",e,n),this.post("/api/saas/chat/upload",r,{headers:typeof r.getHeaders=="function"?r.getHeaders():void 0})}async sendTemplate(e){return this.post("/api/saas/marketing/whatsapp/send-template",e)}};var dt="https://api.ecodrix.com",b=class{constructor(t){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,"events");i(this,"webhooks");i(this,"storage");i(this,"marketing");i(this,"health");i(this,"queue");var g,c,u,T;if(!t.apiKey)throw new P("API Key is required");let e=(g=t.baseUrl)!=null?g:dt,n=t.socketUrl||e,r=typeof window!="undefined"&&typeof window.document!="undefined",o=r?"browser":typeof process!="undefined"?`node ${process.version}`:"unknown",p=r?((c=globalThis.navigator)==null?void 0:c.userAgent)||"browser":typeof process!="undefined"?process.platform:"unknown";this.client=ut.create({baseURL:e,headers:{"x-api-key":t.apiKey,"x-client-code":(u=t.clientCode)==null?void 0:u.toUpperCase(),"Content-Type":"application/json","x-ecodrix-client-agent":JSON.stringify({sdk_version:"1.0.0",runtime:o,os:p})}}),st(this.client,{retries:3,retryDelay:st.exponentialDelay,retryCondition:f=>{var x;return st.isNetworkOrIdempotentRequestError(f)||((x=f.response)==null?void 0:x.status)===429}}),this.whatsapp=new V(this.client),this.crm=new S(this.client),this.media=new M(this.client),this.meet=new N(this.client),this.notifications=new O(this.client),this.email=new E(this.client),this.events=new D(this.client),this.webhooks=new H,this.storage=new F(this.client),this.marketing=new U(this.client),this.health=new L(this.client),this.queue=new B(this.client),this.socket=yt(n,{extraHeaders:{"x-api-key":t.apiKey,"x-client-code":((T=t.clientCode)==null?void 0:T.toUpperCase())||""}}),this.setupSocket(t.clientCode)}joinRoom(t){this.socket.emit("join-room",t)}leaveRoom(t){this.socket.emit("leave-room",t)}setupSocket(t){this.socket.on("connect",()=>{t&&this.socket.emit("join-room",t.toUpperCase())})}on(t,e){return this.socket.on(t,e),this}disconnect(){this.socket.disconnect()}off(t,e){return this.socket.off(t,e),this}async request(t,e,n,r){var o,p,g;try{return(await this.client.request({method:t,url:e,data:n,params:r})).data}catch(c){throw c.response?new m(((o=c.response.data)==null?void 0:o.message)||((p=c.response.data)==null?void 0:p.error)||"Raw Execution Failed",c.response.status,(g=c.response.data)==null?void 0:g.code):new m(c.message||"Network Error")}}};var as=b;export{m as APIError,v as Activities,w as Analytics,P as AuthenticationError,R as AutomationDashboard,A as Automations,_ as Broadcasts,S as CRM,Y as Campaigns,j as Conversations,b as Ecodrix,G as EcodrixError,E as EmailResource,X as Emails,D as EventsResource,et as Files,tt as Folders,L as Health,I as Leads,U as Marketing,M as MediaResource,N as Meetings,K as Messages,Q as Notes,O as Notifications,$ as Payments,C as Pipelines,B as Queue,rt as RateLimitError,k as Scoring,q as Sequences,F as Storage,J as Templates,h as WebhookSignatureError,H as Webhooks,V as WhatsApp,Z as WhatsAppMarketing,as as default};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|