@clianta/sdk 1.2.0 → 1.3.0

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/index.d.ts CHANGED
@@ -269,6 +269,128 @@ interface PaginatedResponse<T> {
269
269
  pages: number;
270
270
  };
271
271
  }
272
+ type TriggerEventType = 'contact.created' | 'contact.updated' | 'contact.deleted' | 'opportunity.created' | 'opportunity.updated' | 'opportunity.stage_changed' | 'opportunity.won' | 'opportunity.lost' | 'task.created' | 'task.completed' | 'task.overdue' | 'activity.logged' | 'form.submitted';
273
+ interface TriggerCondition {
274
+ /**
275
+ * Field to check - supports dynamic field names including custom fields
276
+ * Examples: 'status', 'lifecycleStage', 'leadScore', 'customFields.industry'
277
+ * Use dot notation for nested fields: 'contact.email', 'customFields.accountType'
278
+ */
279
+ field: string;
280
+ /** Operator for comparison */
281
+ operator: 'equals' | 'not_equals' | 'contains' | 'greater_than' | 'less_than' | 'in' | 'not_in';
282
+ /** Value to compare against */
283
+ value: unknown;
284
+ }
285
+ interface EmailTemplate {
286
+ /** Template ID */
287
+ _id?: string;
288
+ /** Template name */
289
+ name: string;
290
+ /** Email subject line (supports variables) */
291
+ subject: string;
292
+ /** Email body (supports HTML and variables) */
293
+ body: string;
294
+ /** Variables available in this template */
295
+ variables?: string[];
296
+ /** Sender email address */
297
+ fromEmail?: string;
298
+ /** Sender name */
299
+ fromName?: string;
300
+ }
301
+ interface EmailAction {
302
+ /** Action type identifier */
303
+ type: 'send_email';
304
+ /** Email template ID or inline template */
305
+ templateId?: string;
306
+ /** Inline email subject (if not using template) */
307
+ subject?: string;
308
+ /** Inline email body (if not using template) */
309
+ body?: string;
310
+ /** Recipient email (supports variables like {{contact.email}}) */
311
+ to: string;
312
+ /** CC recipients */
313
+ cc?: string[];
314
+ /** BCC recipients */
315
+ bcc?: string[];
316
+ /** Sender email */
317
+ from?: string;
318
+ /** Delay in minutes before sending */
319
+ delayMinutes?: number;
320
+ }
321
+ interface WebhookAction {
322
+ /** Action type identifier */
323
+ type: 'webhook';
324
+ /** Webhook URL to call */
325
+ url: string;
326
+ /** HTTP method */
327
+ method: 'POST' | 'PUT' | 'PATCH';
328
+ /** Custom headers */
329
+ headers?: Record<string, string>;
330
+ /** Request body template (supports variables) */
331
+ body?: string;
332
+ }
333
+ interface TaskAction {
334
+ /** Action type identifier */
335
+ type: 'create_task';
336
+ /** Task title (supports variables) */
337
+ title: string;
338
+ /** Task description */
339
+ description?: string;
340
+ /** Task priority */
341
+ priority?: 'low' | 'medium' | 'high' | 'urgent';
342
+ /** Due date in days from trigger */
343
+ dueDays?: number;
344
+ /** Assign to user ID */
345
+ assignedTo?: string;
346
+ }
347
+ interface ContactUpdateAction {
348
+ /** Action type identifier */
349
+ type: 'update_contact';
350
+ /** Fields to update */
351
+ updates: Partial<Contact>;
352
+ }
353
+ type TriggerAction = EmailAction | WebhookAction | TaskAction | ContactUpdateAction;
354
+ interface EventTrigger {
355
+ /** Trigger ID */
356
+ _id?: string;
357
+ /** Workspace ID */
358
+ workspaceId: string;
359
+ /** Trigger name */
360
+ name: string;
361
+ /** Description of what this trigger does */
362
+ description?: string;
363
+ /** Event type that activates this trigger */
364
+ eventType: TriggerEventType;
365
+ /** Conditions that must be met for trigger to fire */
366
+ conditions?: TriggerCondition[];
367
+ /** Actions to execute when trigger fires */
368
+ actions: TriggerAction[];
369
+ /** Whether this trigger is active */
370
+ isActive?: boolean;
371
+ /** Created timestamp */
372
+ createdAt?: string;
373
+ /** Updated timestamp */
374
+ updatedAt?: string;
375
+ }
376
+ interface TriggerExecution {
377
+ /** Execution ID */
378
+ _id?: string;
379
+ /** Trigger ID that was executed */
380
+ triggerId: string;
381
+ /** Event that triggered the execution */
382
+ eventType: TriggerEventType;
383
+ /** Entity ID that triggered the event */
384
+ entityId: string;
385
+ /** Execution status */
386
+ status: 'pending' | 'success' | 'failed';
387
+ /** Error message if failed */
388
+ error?: string;
389
+ /** Actions executed */
390
+ actionsExecuted: number;
391
+ /** Execution timestamp */
392
+ executedAt: string;
393
+ }
272
394
 
273
395
  /**
274
396
  * Clianta SDK - Main Tracker Class
@@ -288,6 +410,8 @@ declare class Tracker implements TrackerCore {
288
410
  private sessionId;
289
411
  private isInitialized;
290
412
  private consentManager;
413
+ /** Pending identify retry on next flush */
414
+ private pendingIdentify;
291
415
  constructor(workspaceId: string, userConfig?: CliantaConfig);
292
416
  /**
293
417
  * Create visitor ID based on storage mode
@@ -318,6 +442,10 @@ declare class Tracker implements TrackerCore {
318
442
  * Identify a visitor
319
443
  */
320
444
  identify(email: string, traits?: UserTraits): Promise<void>;
445
+ /**
446
+ * Retry pending identify call
447
+ */
448
+ private retryPendingIdentify;
321
449
  /**
322
450
  * Update consent state
323
451
  */
@@ -364,6 +492,169 @@ declare class Tracker implements TrackerCore {
364
492
  destroy(): Promise<void>;
365
493
  }
366
494
 
495
+ /**
496
+ * Clianta SDK - Event Triggers Manager
497
+ * Manages event-driven automation and email notifications
498
+ */
499
+
500
+ /**
501
+ * Event Triggers Manager
502
+ * Handles event-driven automation based on CRM actions
503
+ *
504
+ * Similar to:
505
+ * - Salesforce: Process Builder, Flow Automation
506
+ * - HubSpot: Workflows, Email Sequences
507
+ * - Pipedrive: Workflow Automation
508
+ */
509
+ declare class EventTriggersManager {
510
+ private apiEndpoint;
511
+ private workspaceId;
512
+ private authToken?;
513
+ private triggers;
514
+ private listeners;
515
+ constructor(apiEndpoint: string, workspaceId: string, authToken?: string);
516
+ /**
517
+ * Set authentication token
518
+ */
519
+ setAuthToken(token: string): void;
520
+ /**
521
+ * Make authenticated API request
522
+ */
523
+ private request;
524
+ /**
525
+ * Get all event triggers
526
+ */
527
+ getTriggers(): Promise<ApiResponse<EventTrigger[]>>;
528
+ /**
529
+ * Get a single trigger by ID
530
+ */
531
+ getTrigger(triggerId: string): Promise<ApiResponse<EventTrigger>>;
532
+ /**
533
+ * Create a new event trigger
534
+ */
535
+ createTrigger(trigger: Partial<EventTrigger>): Promise<ApiResponse<EventTrigger>>;
536
+ /**
537
+ * Update an existing trigger
538
+ */
539
+ updateTrigger(triggerId: string, updates: Partial<EventTrigger>): Promise<ApiResponse<EventTrigger>>;
540
+ /**
541
+ * Delete a trigger
542
+ */
543
+ deleteTrigger(triggerId: string): Promise<ApiResponse<void>>;
544
+ /**
545
+ * Activate a trigger
546
+ */
547
+ activateTrigger(triggerId: string): Promise<ApiResponse<EventTrigger>>;
548
+ /**
549
+ * Deactivate a trigger
550
+ */
551
+ deactivateTrigger(triggerId: string): Promise<ApiResponse<EventTrigger>>;
552
+ /**
553
+ * Register a local event listener for client-side triggers
554
+ * This allows immediate client-side reactions to events
555
+ */
556
+ on(eventType: TriggerEventType, callback: (data: unknown) => void): void;
557
+ /**
558
+ * Remove an event listener
559
+ */
560
+ off(eventType: TriggerEventType, callback: (data: unknown) => void): void;
561
+ /**
562
+ * Emit an event (client-side only)
563
+ * This will trigger any registered local listeners
564
+ */
565
+ emit(eventType: TriggerEventType, data: unknown): void;
566
+ /**
567
+ * Check if conditions are met for a trigger
568
+ * Supports dynamic field evaluation including custom fields and nested paths
569
+ */
570
+ private evaluateConditions;
571
+ /**
572
+ * Execute actions for a triggered event (client-side preview)
573
+ * Note: Actual execution happens on the backend
574
+ */
575
+ executeActions(trigger: EventTrigger, data: Record<string, unknown>): Promise<void>;
576
+ /**
577
+ * Execute a single action
578
+ */
579
+ private executeAction;
580
+ /**
581
+ * Execute send email action (via backend API)
582
+ */
583
+ private executeSendEmail;
584
+ /**
585
+ * Execute webhook action
586
+ */
587
+ private executeWebhook;
588
+ /**
589
+ * Execute create task action
590
+ */
591
+ private executeCreateTask;
592
+ /**
593
+ * Execute update contact action
594
+ */
595
+ private executeUpdateContact;
596
+ /**
597
+ * Replace variables in a string template
598
+ * Supports syntax like {{contact.email}}, {{opportunity.value}}
599
+ */
600
+ private replaceVariables;
601
+ /**
602
+ * Get nested value from object using dot notation
603
+ * Supports dynamic field access including custom fields
604
+ */
605
+ private getNestedValue;
606
+ /**
607
+ * Extract all available field paths from a data object
608
+ * Useful for dynamic field discovery based on platform-specific attributes
609
+ * @param obj - The data object to extract fields from
610
+ * @param prefix - Internal use for nested paths
611
+ * @param maxDepth - Maximum depth to traverse (default: 3)
612
+ * @returns Array of field paths (e.g., ['email', 'contact.firstName', 'customFields.industry'])
613
+ */
614
+ private extractAvailableFields;
615
+ /**
616
+ * Get available fields from sample data
617
+ * Helps with dynamic field detection for platform-specific attributes
618
+ * @param sampleData - Sample data object to analyze
619
+ * @returns Array of available field paths
620
+ */
621
+ getAvailableFields(sampleData: Record<string, unknown>): string[];
622
+ /**
623
+ * Create a simple email trigger
624
+ * Helper method for common use case
625
+ */
626
+ createEmailTrigger(config: {
627
+ name: string;
628
+ eventType: TriggerEventType;
629
+ to: string;
630
+ subject: string;
631
+ body: string;
632
+ conditions?: TriggerCondition[];
633
+ }): Promise<ApiResponse<EventTrigger>>;
634
+ /**
635
+ * Create a task creation trigger
636
+ */
637
+ createTaskTrigger(config: {
638
+ name: string;
639
+ eventType: TriggerEventType;
640
+ taskTitle: string;
641
+ taskDescription?: string;
642
+ priority?: 'low' | 'medium' | 'high' | 'urgent';
643
+ dueDays?: number;
644
+ conditions?: TriggerCondition[];
645
+ }): Promise<ApiResponse<EventTrigger>>;
646
+ /**
647
+ * Create a webhook trigger
648
+ */
649
+ createWebhookTrigger(config: {
650
+ name: string;
651
+ eventType: TriggerEventType;
652
+ webhookUrl: string;
653
+ method?: 'POST' | 'PUT' | 'PATCH';
654
+ conditions?: TriggerCondition[];
655
+ }): Promise<ApiResponse<EventTrigger>>;
656
+ }
657
+
367
658
  /**
368
659
  * Clianta SDK - CRM API Client
369
660
  * @see SDK_VERSION in core/config.ts
@@ -376,11 +667,17 @@ declare class CRMClient {
376
667
  private apiEndpoint;
377
668
  private workspaceId;
378
669
  private authToken?;
670
+ triggers: EventTriggersManager;
379
671
  constructor(apiEndpoint: string, workspaceId: string, authToken?: string);
380
672
  /**
381
673
  * Set authentication token for API requests
382
674
  */
383
675
  setAuthToken(token: string): void;
676
+ /**
677
+ * Validate required parameter exists
678
+ * @throws {Error} if value is null/undefined or empty string
679
+ */
680
+ private validateRequired;
384
681
  /**
385
682
  * Make authenticated API request
386
683
  */
@@ -589,6 +886,60 @@ declare class CRMClient {
589
886
  opportunityId?: string;
590
887
  content: string;
591
888
  }): Promise<ApiResponse<Activity>>;
889
+ /**
890
+ * Get all email templates
891
+ */
892
+ getEmailTemplates(params?: {
893
+ page?: number;
894
+ limit?: number;
895
+ }): Promise<ApiResponse<PaginatedResponse<EmailTemplate>>>;
896
+ /**
897
+ * Get a single email template by ID
898
+ */
899
+ getEmailTemplate(templateId: string): Promise<ApiResponse<EmailTemplate>>;
900
+ /**
901
+ * Create a new email template
902
+ */
903
+ createEmailTemplate(template: Partial<EmailTemplate>): Promise<ApiResponse<EmailTemplate>>;
904
+ /**
905
+ * Update an email template
906
+ */
907
+ updateEmailTemplate(templateId: string, updates: Partial<EmailTemplate>): Promise<ApiResponse<EmailTemplate>>;
908
+ /**
909
+ * Delete an email template
910
+ */
911
+ deleteEmailTemplate(templateId: string): Promise<ApiResponse<void>>;
912
+ /**
913
+ * Send an email using a template
914
+ */
915
+ sendEmail(data: {
916
+ to: string;
917
+ templateId?: string;
918
+ subject?: string;
919
+ body?: string;
920
+ cc?: string[];
921
+ bcc?: string[];
922
+ variables?: Record<string, unknown>;
923
+ contactId?: string;
924
+ }): Promise<ApiResponse<{
925
+ messageId: string;
926
+ }>>;
927
+ /**
928
+ * Get all event triggers
929
+ */
930
+ getEventTriggers(): Promise<ApiResponse<EventTrigger[]>>;
931
+ /**
932
+ * Create a new event trigger
933
+ */
934
+ createEventTrigger(trigger: Partial<EventTrigger>): Promise<ApiResponse<EventTrigger>>;
935
+ /**
936
+ * Update an event trigger
937
+ */
938
+ updateEventTrigger(triggerId: string, updates: Partial<EventTrigger>): Promise<ApiResponse<EventTrigger>>;
939
+ /**
940
+ * Delete an event trigger
941
+ */
942
+ deleteEventTrigger(triggerId: string): Promise<ApiResponse<void>>;
592
943
  }
593
944
 
594
945
  /**
@@ -687,7 +1038,7 @@ interface StoredConsent {
687
1038
  */
688
1039
 
689
1040
  /** SDK Version */
690
- declare const SDK_VERSION = "1.2.0";
1041
+ declare const SDK_VERSION = "1.3.0";
691
1042
 
692
1043
  /**
693
1044
  * Clianta SDK
@@ -721,5 +1072,5 @@ declare const SDK_VERSION = "1.2.0";
721
1072
  */
722
1073
  declare function clianta(workspaceId: string, config?: CliantaConfig): TrackerCore;
723
1074
 
724
- export { CRMClient, ConsentManager, SDK_VERSION, Tracker, clianta, clianta as default };
725
- export type { Activity, ApiResponse, CliantaConfig, Company, ConsentChangeCallback, ConsentConfig, ConsentManagerConfig, ConsentState, Contact, EventType, Opportunity, PaginatedResponse, Pipeline, PipelineStage, Plugin, PluginName, StoredConsent, Task, TrackerCore, TrackingEvent, UserTraits };
1075
+ export { CRMClient, ConsentManager, EventTriggersManager, SDK_VERSION, Tracker, clianta, clianta as default };
1076
+ export type { Activity, ApiResponse, CliantaConfig, Company, ConsentChangeCallback, ConsentConfig, ConsentManagerConfig, ConsentState, Contact, ContactUpdateAction, EmailAction, EmailTemplate, EventTrigger, EventType, Opportunity, PaginatedResponse, Pipeline, PipelineStage, Plugin, PluginName, StoredConsent, Task, TaskAction, TrackerCore, TrackingEvent, TriggerAction, TriggerCondition, TriggerEventType, TriggerExecution, UserTraits, WebhookAction };