@ecodrix/erix-api 1.1.6 → 1.1.8
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 +46 -22
- 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 +46 -22
- package/dist/ts/esm/index.d.ts +46 -22
- package/dist/ts/esm/index.js +1 -1
- package/dist/ts/esm/index.js.map +1 -1
- package/package.json +2 -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/media.ts +10 -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
|
@@ -1380,17 +1380,18 @@ declare class MediaResource extends APIResource {
|
|
|
1380
1380
|
* List files within a specific folder, with optional date filtering.
|
|
1381
1381
|
*
|
|
1382
1382
|
* @param folder - The folder key to list.
|
|
1383
|
-
* @param params - Optional `year` and `
|
|
1383
|
+
* @param params - Optional `year`, `month`, and search `q` filters.
|
|
1384
1384
|
* @returns Array of file metadata objects.
|
|
1385
1385
|
*
|
|
1386
1386
|
* @example
|
|
1387
1387
|
* ```typescript
|
|
1388
|
-
* const { data: files } = await ecod.media.list("invoices", {
|
|
1388
|
+
* const { data: files } = await ecod.media.list("invoices", { q: "contract" });
|
|
1389
1389
|
* ```
|
|
1390
1390
|
*/
|
|
1391
1391
|
list(folder: string, params?: {
|
|
1392
1392
|
year?: string;
|
|
1393
1393
|
month?: string;
|
|
1394
|
+
q?: string;
|
|
1394
1395
|
}): Promise<unknown>;
|
|
1395
1396
|
/**
|
|
1396
1397
|
* Delete a file from R2 by its storage key.
|
|
@@ -2245,6 +2246,31 @@ interface SendTemplateParams {
|
|
|
2245
2246
|
* });
|
|
2246
2247
|
* ```
|
|
2247
2248
|
*/
|
|
2249
|
+
/**
|
|
2250
|
+
* Resolved media metadata returned by any upload endpoint.
|
|
2251
|
+
* `variants` is only present for raster images (JPEG, PNG, WebP, AVIF, GIF).
|
|
2252
|
+
*/
|
|
2253
|
+
interface ChatMediaMeta {
|
|
2254
|
+
/** Raw CDN URL — always present, all media types */
|
|
2255
|
+
url: string;
|
|
2256
|
+
/** Categorical type — "image" | "video" | "audio" | "document" */
|
|
2257
|
+
type: "image" | "video" | "audio" | "document";
|
|
2258
|
+
/** Cloudflare-optimised variant URLs. Only present for raster images. */
|
|
2259
|
+
variants?: {
|
|
2260
|
+
/** 150px WebP — use for list thumbnails and chat bubbles */
|
|
2261
|
+
thumb: string;
|
|
2262
|
+
/** 600px WebP — use for modal previews */
|
|
2263
|
+
medium: string;
|
|
2264
|
+
/** 1200px WebP — use for hero or full-screen views */
|
|
2265
|
+
full: string;
|
|
2266
|
+
/** Original CDN URL, no transformation */
|
|
2267
|
+
raw: string;
|
|
2268
|
+
};
|
|
2269
|
+
/** Storage key within the tenant bucket */
|
|
2270
|
+
key?: string;
|
|
2271
|
+
/** Original filename */
|
|
2272
|
+
fileName?: string;
|
|
2273
|
+
}
|
|
2248
2274
|
declare class Messages extends APIResource {
|
|
2249
2275
|
/**
|
|
2250
2276
|
* Send a free-text or media message to a WhatsApp number.
|
|
@@ -2323,26 +2349,24 @@ declare class Messages extends APIResource {
|
|
|
2323
2349
|
/**
|
|
2324
2350
|
* Upload a media file for WhatsApp chat.
|
|
2325
2351
|
*
|
|
2326
|
-
*
|
|
2327
|
-
*
|
|
2328
|
-
*
|
|
2352
|
+
* Works with any file type — image, video, audio, or document.
|
|
2353
|
+
* For raster images the response includes Cloudflare-optimised `variants`
|
|
2354
|
+
* (thumb 150px, medium 600px, full 1200px). Non-image types return only `url`.
|
|
2329
2355
|
*
|
|
2330
2356
|
* @param file - The file to upload (File, Blob, or Buffer).
|
|
2331
|
-
* @returns
|
|
2357
|
+
* @returns Full media metadata `{ url, type, variants?, key, fileName }`.
|
|
2332
2358
|
*
|
|
2333
2359
|
* @example
|
|
2334
2360
|
* ```typescript
|
|
2335
2361
|
* const file = input.files[0];
|
|
2336
2362
|
* const { data } = await ecod.whatsapp.messages.upload(file);
|
|
2337
|
-
*
|
|
2363
|
+
* // For images: data.variants.thumb → 150px WebP from Cloudflare
|
|
2364
|
+
* // For video/audio: use data.url directly in <video> or <audio>
|
|
2338
2365
|
* ```
|
|
2339
2366
|
*/
|
|
2340
|
-
upload
|
|
2341
|
-
url: string;
|
|
2342
|
-
type: string;
|
|
2343
|
-
}>(file: any): Promise<{
|
|
2367
|
+
upload(file: any): Promise<{
|
|
2344
2368
|
success: boolean;
|
|
2345
|
-
data:
|
|
2369
|
+
data: ChatMediaMeta;
|
|
2346
2370
|
}>;
|
|
2347
2371
|
}
|
|
2348
2372
|
|
|
@@ -2512,6 +2536,9 @@ declare class WhatsApp extends APIResource {
|
|
|
2512
2536
|
|
|
2513
2537
|
/**
|
|
2514
2538
|
* Configuration options for the Ecodrix client.
|
|
2539
|
+
*
|
|
2540
|
+
* Minimum required: `apiKey` and `clientCode`.
|
|
2541
|
+
* The backend URL is managed internally and should not need to be changed.
|
|
2515
2542
|
*/
|
|
2516
2543
|
interface EcodrixOptions {
|
|
2517
2544
|
/**
|
|
@@ -2523,22 +2550,19 @@ interface EcodrixOptions {
|
|
|
2523
2550
|
/**
|
|
2524
2551
|
* Your tenant ID (Client Code).
|
|
2525
2552
|
* This scopes all API requests to your specific organisation.
|
|
2526
|
-
* Required for most operations.
|
|
2527
2553
|
* @example "ERIX_CLNT_JHBJHF"
|
|
2528
2554
|
*/
|
|
2529
2555
|
clientCode?: string;
|
|
2530
2556
|
/**
|
|
2531
|
-
* Override
|
|
2532
|
-
*
|
|
2533
|
-
* @default "https://api.ecodrix.com"
|
|
2557
|
+
* @internal Override Socket.io URL for testing/staging.
|
|
2558
|
+
* Not documented — internal use only.
|
|
2534
2559
|
*/
|
|
2535
|
-
|
|
2560
|
+
socketUrl?: string;
|
|
2536
2561
|
/**
|
|
2537
|
-
* Override the
|
|
2538
|
-
*
|
|
2539
|
-
* @default "https://api.ecodrix.com"
|
|
2562
|
+
* @internal Override the backend API URL. Used by the CLI and internal tests only.
|
|
2563
|
+
* Host projects must never set this — the production URL is hardcoded internally.
|
|
2540
2564
|
*/
|
|
2541
|
-
|
|
2565
|
+
baseUrl?: string;
|
|
2542
2566
|
}
|
|
2543
2567
|
/**
|
|
2544
2568
|
* The primary entry point for the ECODrIx SDK.
|
|
@@ -2667,4 +2691,4 @@ declare class Ecodrix {
|
|
|
2667
2691
|
request<T = any>(method: Method, path: string, data?: any, params?: any): Promise<T>;
|
|
2668
2692
|
}
|
|
2669
2693
|
|
|
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 };
|
|
2694
|
+
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
|
@@ -1380,17 +1380,18 @@ declare class MediaResource extends APIResource {
|
|
|
1380
1380
|
* List files within a specific folder, with optional date filtering.
|
|
1381
1381
|
*
|
|
1382
1382
|
* @param folder - The folder key to list.
|
|
1383
|
-
* @param params - Optional `year` and `
|
|
1383
|
+
* @param params - Optional `year`, `month`, and search `q` filters.
|
|
1384
1384
|
* @returns Array of file metadata objects.
|
|
1385
1385
|
*
|
|
1386
1386
|
* @example
|
|
1387
1387
|
* ```typescript
|
|
1388
|
-
* const { data: files } = await ecod.media.list("invoices", {
|
|
1388
|
+
* const { data: files } = await ecod.media.list("invoices", { q: "contract" });
|
|
1389
1389
|
* ```
|
|
1390
1390
|
*/
|
|
1391
1391
|
list(folder: string, params?: {
|
|
1392
1392
|
year?: string;
|
|
1393
1393
|
month?: string;
|
|
1394
|
+
q?: string;
|
|
1394
1395
|
}): Promise<unknown>;
|
|
1395
1396
|
/**
|
|
1396
1397
|
* Delete a file from R2 by its storage key.
|
|
@@ -2245,6 +2246,31 @@ interface SendTemplateParams {
|
|
|
2245
2246
|
* });
|
|
2246
2247
|
* ```
|
|
2247
2248
|
*/
|
|
2249
|
+
/**
|
|
2250
|
+
* Resolved media metadata returned by any upload endpoint.
|
|
2251
|
+
* `variants` is only present for raster images (JPEG, PNG, WebP, AVIF, GIF).
|
|
2252
|
+
*/
|
|
2253
|
+
interface ChatMediaMeta {
|
|
2254
|
+
/** Raw CDN URL — always present, all media types */
|
|
2255
|
+
url: string;
|
|
2256
|
+
/** Categorical type — "image" | "video" | "audio" | "document" */
|
|
2257
|
+
type: "image" | "video" | "audio" | "document";
|
|
2258
|
+
/** Cloudflare-optimised variant URLs. Only present for raster images. */
|
|
2259
|
+
variants?: {
|
|
2260
|
+
/** 150px WebP — use for list thumbnails and chat bubbles */
|
|
2261
|
+
thumb: string;
|
|
2262
|
+
/** 600px WebP — use for modal previews */
|
|
2263
|
+
medium: string;
|
|
2264
|
+
/** 1200px WebP — use for hero or full-screen views */
|
|
2265
|
+
full: string;
|
|
2266
|
+
/** Original CDN URL, no transformation */
|
|
2267
|
+
raw: string;
|
|
2268
|
+
};
|
|
2269
|
+
/** Storage key within the tenant bucket */
|
|
2270
|
+
key?: string;
|
|
2271
|
+
/** Original filename */
|
|
2272
|
+
fileName?: string;
|
|
2273
|
+
}
|
|
2248
2274
|
declare class Messages extends APIResource {
|
|
2249
2275
|
/**
|
|
2250
2276
|
* Send a free-text or media message to a WhatsApp number.
|
|
@@ -2323,26 +2349,24 @@ declare class Messages extends APIResource {
|
|
|
2323
2349
|
/**
|
|
2324
2350
|
* Upload a media file for WhatsApp chat.
|
|
2325
2351
|
*
|
|
2326
|
-
*
|
|
2327
|
-
*
|
|
2328
|
-
*
|
|
2352
|
+
* Works with any file type — image, video, audio, or document.
|
|
2353
|
+
* For raster images the response includes Cloudflare-optimised `variants`
|
|
2354
|
+
* (thumb 150px, medium 600px, full 1200px). Non-image types return only `url`.
|
|
2329
2355
|
*
|
|
2330
2356
|
* @param file - The file to upload (File, Blob, or Buffer).
|
|
2331
|
-
* @returns
|
|
2357
|
+
* @returns Full media metadata `{ url, type, variants?, key, fileName }`.
|
|
2332
2358
|
*
|
|
2333
2359
|
* @example
|
|
2334
2360
|
* ```typescript
|
|
2335
2361
|
* const file = input.files[0];
|
|
2336
2362
|
* const { data } = await ecod.whatsapp.messages.upload(file);
|
|
2337
|
-
*
|
|
2363
|
+
* // For images: data.variants.thumb → 150px WebP from Cloudflare
|
|
2364
|
+
* // For video/audio: use data.url directly in <video> or <audio>
|
|
2338
2365
|
* ```
|
|
2339
2366
|
*/
|
|
2340
|
-
upload
|
|
2341
|
-
url: string;
|
|
2342
|
-
type: string;
|
|
2343
|
-
}>(file: any): Promise<{
|
|
2367
|
+
upload(file: any): Promise<{
|
|
2344
2368
|
success: boolean;
|
|
2345
|
-
data:
|
|
2369
|
+
data: ChatMediaMeta;
|
|
2346
2370
|
}>;
|
|
2347
2371
|
}
|
|
2348
2372
|
|
|
@@ -2512,6 +2536,9 @@ declare class WhatsApp extends APIResource {
|
|
|
2512
2536
|
|
|
2513
2537
|
/**
|
|
2514
2538
|
* Configuration options for the Ecodrix client.
|
|
2539
|
+
*
|
|
2540
|
+
* Minimum required: `apiKey` and `clientCode`.
|
|
2541
|
+
* The backend URL is managed internally and should not need to be changed.
|
|
2515
2542
|
*/
|
|
2516
2543
|
interface EcodrixOptions {
|
|
2517
2544
|
/**
|
|
@@ -2523,22 +2550,19 @@ interface EcodrixOptions {
|
|
|
2523
2550
|
/**
|
|
2524
2551
|
* Your tenant ID (Client Code).
|
|
2525
2552
|
* This scopes all API requests to your specific organisation.
|
|
2526
|
-
* Required for most operations.
|
|
2527
2553
|
* @example "ERIX_CLNT_JHBJHF"
|
|
2528
2554
|
*/
|
|
2529
2555
|
clientCode?: string;
|
|
2530
2556
|
/**
|
|
2531
|
-
* Override
|
|
2532
|
-
*
|
|
2533
|
-
* @default "https://api.ecodrix.com"
|
|
2557
|
+
* @internal Override Socket.io URL for testing/staging.
|
|
2558
|
+
* Not documented — internal use only.
|
|
2534
2559
|
*/
|
|
2535
|
-
|
|
2560
|
+
socketUrl?: string;
|
|
2536
2561
|
/**
|
|
2537
|
-
* Override the
|
|
2538
|
-
*
|
|
2539
|
-
* @default "https://api.ecodrix.com"
|
|
2562
|
+
* @internal Override the backend API URL. Used by the CLI and internal tests only.
|
|
2563
|
+
* Host projects must never set this — the production URL is hardcoded internally.
|
|
2540
2564
|
*/
|
|
2541
|
-
|
|
2565
|
+
baseUrl?: string;
|
|
2542
2566
|
}
|
|
2543
2567
|
/**
|
|
2544
2568
|
* The primary entry point for the ECODrIx SDK.
|
|
@@ -2667,4 +2691,4 @@ declare class Ecodrix {
|
|
|
2667
2691
|
request<T = any>(method: Method, path: string, data?: any, params?: any): Promise<T>;
|
|
2668
2692
|
}
|
|
2669
2693
|
|
|
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 };
|
|
2694
|
+
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
|