@clianta/sdk 1.2.0 → 1.4.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
@@ -1,3 +1,500 @@
1
+ /**
2
+ * Clianta SDK - Event Triggers Manager
3
+ * Manages event-driven automation and email notifications
4
+ */
5
+
6
+ /**
7
+ * Event Triggers Manager
8
+ * Handles event-driven automation based on CRM actions
9
+ *
10
+ * Similar to:
11
+ * - Salesforce: Process Builder, Flow Automation
12
+ * - HubSpot: Workflows, Email Sequences
13
+ * - Pipedrive: Workflow Automation
14
+ */
15
+ declare class EventTriggersManager {
16
+ private apiEndpoint;
17
+ private workspaceId;
18
+ private authToken?;
19
+ private triggers;
20
+ private listeners;
21
+ constructor(apiEndpoint: string, workspaceId: string, authToken?: string);
22
+ /**
23
+ * Set authentication token
24
+ */
25
+ setAuthToken(token: string): void;
26
+ /**
27
+ * Make authenticated API request
28
+ */
29
+ private request;
30
+ /**
31
+ * Get all event triggers
32
+ */
33
+ getTriggers(): Promise<ApiResponse<EventTrigger[]>>;
34
+ /**
35
+ * Get a single trigger by ID
36
+ */
37
+ getTrigger(triggerId: string): Promise<ApiResponse<EventTrigger>>;
38
+ /**
39
+ * Create a new event trigger
40
+ */
41
+ createTrigger(trigger: Partial<EventTrigger>): Promise<ApiResponse<EventTrigger>>;
42
+ /**
43
+ * Update an existing trigger
44
+ */
45
+ updateTrigger(triggerId: string, updates: Partial<EventTrigger>): Promise<ApiResponse<EventTrigger>>;
46
+ /**
47
+ * Delete a trigger
48
+ */
49
+ deleteTrigger(triggerId: string): Promise<ApiResponse<void>>;
50
+ /**
51
+ * Activate a trigger
52
+ */
53
+ activateTrigger(triggerId: string): Promise<ApiResponse<EventTrigger>>;
54
+ /**
55
+ * Deactivate a trigger
56
+ */
57
+ deactivateTrigger(triggerId: string): Promise<ApiResponse<EventTrigger>>;
58
+ /**
59
+ * Register a local event listener for client-side triggers
60
+ * This allows immediate client-side reactions to events
61
+ */
62
+ on(eventType: TriggerEventType, callback: (data: unknown) => void): void;
63
+ /**
64
+ * Remove an event listener
65
+ */
66
+ off(eventType: TriggerEventType, callback: (data: unknown) => void): void;
67
+ /**
68
+ * Emit an event (client-side only)
69
+ * This will trigger any registered local listeners
70
+ */
71
+ emit(eventType: TriggerEventType, data: unknown): void;
72
+ /**
73
+ * Check if conditions are met for a trigger
74
+ * Supports dynamic field evaluation including custom fields and nested paths
75
+ */
76
+ private evaluateConditions;
77
+ /**
78
+ * Execute actions for a triggered event (client-side preview)
79
+ * Note: Actual execution happens on the backend
80
+ */
81
+ executeActions(trigger: EventTrigger, data: Record<string, unknown>): Promise<void>;
82
+ /**
83
+ * Execute a single action
84
+ */
85
+ private executeAction;
86
+ /**
87
+ * Execute send email action (via backend API)
88
+ */
89
+ private executeSendEmail;
90
+ /**
91
+ * Execute webhook action
92
+ */
93
+ private executeWebhook;
94
+ /**
95
+ * Execute create task action
96
+ */
97
+ private executeCreateTask;
98
+ /**
99
+ * Execute update contact action
100
+ */
101
+ private executeUpdateContact;
102
+ /**
103
+ * Replace variables in a string template
104
+ * Supports syntax like {{contact.email}}, {{opportunity.value}}
105
+ */
106
+ private replaceVariables;
107
+ /**
108
+ * Get nested value from object using dot notation
109
+ * Supports dynamic field access including custom fields
110
+ */
111
+ private getNestedValue;
112
+ /**
113
+ * Extract all available field paths from a data object
114
+ * Useful for dynamic field discovery based on platform-specific attributes
115
+ * @param obj - The data object to extract fields from
116
+ * @param prefix - Internal use for nested paths
117
+ * @param maxDepth - Maximum depth to traverse (default: 3)
118
+ * @returns Array of field paths (e.g., ['email', 'contact.firstName', 'customFields.industry'])
119
+ */
120
+ private extractAvailableFields;
121
+ /**
122
+ * Get available fields from sample data
123
+ * Helps with dynamic field detection for platform-specific attributes
124
+ * @param sampleData - Sample data object to analyze
125
+ * @returns Array of available field paths
126
+ */
127
+ getAvailableFields(sampleData: Record<string, unknown>): string[];
128
+ /**
129
+ * Create a simple email trigger
130
+ * Helper method for common use case
131
+ */
132
+ createEmailTrigger(config: {
133
+ name: string;
134
+ eventType: TriggerEventType;
135
+ to: string;
136
+ subject: string;
137
+ body: string;
138
+ conditions?: TriggerCondition[];
139
+ }): Promise<ApiResponse<EventTrigger>>;
140
+ /**
141
+ * Create a task creation trigger
142
+ */
143
+ createTaskTrigger(config: {
144
+ name: string;
145
+ eventType: TriggerEventType;
146
+ taskTitle: string;
147
+ taskDescription?: string;
148
+ priority?: 'low' | 'medium' | 'high' | 'urgent';
149
+ dueDays?: number;
150
+ conditions?: TriggerCondition[];
151
+ }): Promise<ApiResponse<EventTrigger>>;
152
+ /**
153
+ * Create a webhook trigger
154
+ */
155
+ createWebhookTrigger(config: {
156
+ name: string;
157
+ eventType: TriggerEventType;
158
+ webhookUrl: string;
159
+ method?: 'POST' | 'PUT' | 'PATCH';
160
+ conditions?: TriggerCondition[];
161
+ }): Promise<ApiResponse<EventTrigger>>;
162
+ }
163
+
164
+ /**
165
+ * Clianta SDK - CRM API Client
166
+ * @see SDK_VERSION in core/config.ts
167
+ */
168
+
169
+ type InboundEventType = 'user.registered' | 'user.updated' | 'user.subscribed' | 'user.unsubscribed' | 'contact.created' | 'contact.updated' | 'purchase.completed';
170
+ interface InboundEventPayload {
171
+ /** Event type (e.g. "user.registered") */
172
+ event: InboundEventType;
173
+ /** Contact data — at least email or phone is required */
174
+ contact: {
175
+ email?: string;
176
+ phone?: string;
177
+ firstName?: string;
178
+ lastName?: string;
179
+ company?: string;
180
+ jobTitle?: string;
181
+ tags?: string[];
182
+ };
183
+ /** Optional extra data stored as customFields on the contact */
184
+ data?: Record<string, unknown>;
185
+ }
186
+ interface InboundEventResult {
187
+ success: boolean;
188
+ contactCreated: boolean;
189
+ contactId?: string;
190
+ event: string;
191
+ error?: string;
192
+ }
193
+ /**
194
+ * CRM API Client for managing contacts and opportunities
195
+ */
196
+ declare class CRMClient {
197
+ private apiEndpoint;
198
+ private workspaceId;
199
+ private authToken?;
200
+ private apiKey?;
201
+ triggers: EventTriggersManager;
202
+ constructor(apiEndpoint: string, workspaceId: string, authToken?: string, apiKey?: string);
203
+ /**
204
+ * Set authentication token for API requests (user JWT)
205
+ */
206
+ setAuthToken(token: string): void;
207
+ /**
208
+ * Set workspace API key for server-to-server requests.
209
+ * Use this instead of setAuthToken when integrating from an external app.
210
+ */
211
+ setApiKey(key: string): void;
212
+ /**
213
+ * Validate required parameter exists
214
+ * @throws {Error} if value is null/undefined or empty string
215
+ */
216
+ private validateRequired;
217
+ /**
218
+ * Make authenticated API request
219
+ */
220
+ private request;
221
+ /**
222
+ * Send an inbound event from an external app (e.g. user signup on client website).
223
+ * Requires the client to be initialized with an API key via setApiKey() or the constructor.
224
+ *
225
+ * The contact is upserted in the CRM and matching workflow automations fire automatically.
226
+ *
227
+ * @example
228
+ * const crm = new CRMClient('https://api.clianta.online', 'WORKSPACE_ID');
229
+ * crm.setApiKey('mm_live_...');
230
+ *
231
+ * await crm.sendEvent({
232
+ * event: 'user.registered',
233
+ * contact: { email: 'alice@example.com', firstName: 'Alice' },
234
+ * data: { plan: 'free', signupSource: 'homepage' },
235
+ * });
236
+ */
237
+ sendEvent(payload: InboundEventPayload): Promise<InboundEventResult>;
238
+ /**
239
+ * Get all contacts with pagination
240
+ */
241
+ getContacts(params?: {
242
+ page?: number;
243
+ limit?: number;
244
+ search?: string;
245
+ status?: string;
246
+ }): Promise<ApiResponse<PaginatedResponse<Contact>>>;
247
+ /**
248
+ * Get a single contact by ID
249
+ */
250
+ getContact(contactId: string): Promise<ApiResponse<Contact>>;
251
+ /**
252
+ * Create a new contact
253
+ */
254
+ createContact(contact: Partial<Contact>): Promise<ApiResponse<Contact>>;
255
+ /**
256
+ * Update an existing contact
257
+ */
258
+ updateContact(contactId: string, updates: Partial<Contact>): Promise<ApiResponse<Contact>>;
259
+ /**
260
+ * Delete a contact
261
+ */
262
+ deleteContact(contactId: string): Promise<ApiResponse<void>>;
263
+ /**
264
+ * Get all opportunities with pagination
265
+ */
266
+ getOpportunities(params?: {
267
+ page?: number;
268
+ limit?: number;
269
+ pipelineId?: string;
270
+ stageId?: string;
271
+ }): Promise<ApiResponse<PaginatedResponse<Opportunity>>>;
272
+ /**
273
+ * Get a single opportunity by ID
274
+ */
275
+ getOpportunity(opportunityId: string): Promise<ApiResponse<Opportunity>>;
276
+ /**
277
+ * Create a new opportunity
278
+ */
279
+ createOpportunity(opportunity: Partial<Opportunity>): Promise<ApiResponse<Opportunity>>;
280
+ /**
281
+ * Update an existing opportunity
282
+ */
283
+ updateOpportunity(opportunityId: string, updates: Partial<Opportunity>): Promise<ApiResponse<Opportunity>>;
284
+ /**
285
+ * Delete an opportunity
286
+ */
287
+ deleteOpportunity(opportunityId: string): Promise<ApiResponse<void>>;
288
+ /**
289
+ * Move opportunity to a different stage
290
+ */
291
+ moveOpportunity(opportunityId: string, stageId: string): Promise<ApiResponse<Opportunity>>;
292
+ /**
293
+ * Get all companies with pagination
294
+ */
295
+ getCompanies(params?: {
296
+ page?: number;
297
+ limit?: number;
298
+ search?: string;
299
+ status?: string;
300
+ industry?: string;
301
+ }): Promise<ApiResponse<PaginatedResponse<Company>>>;
302
+ /**
303
+ * Get a single company by ID
304
+ */
305
+ getCompany(companyId: string): Promise<ApiResponse<Company>>;
306
+ /**
307
+ * Create a new company
308
+ */
309
+ createCompany(company: Partial<Company>): Promise<ApiResponse<Company>>;
310
+ /**
311
+ * Update an existing company
312
+ */
313
+ updateCompany(companyId: string, updates: Partial<Company>): Promise<ApiResponse<Company>>;
314
+ /**
315
+ * Delete a company
316
+ */
317
+ deleteCompany(companyId: string): Promise<ApiResponse<void>>;
318
+ /**
319
+ * Get contacts belonging to a company
320
+ */
321
+ getCompanyContacts(companyId: string, params?: {
322
+ page?: number;
323
+ limit?: number;
324
+ }): Promise<ApiResponse<PaginatedResponse<Contact>>>;
325
+ /**
326
+ * Get deals/opportunities belonging to a company
327
+ */
328
+ getCompanyDeals(companyId: string, params?: {
329
+ page?: number;
330
+ limit?: number;
331
+ }): Promise<ApiResponse<PaginatedResponse<Opportunity>>>;
332
+ /**
333
+ * Get all pipelines
334
+ */
335
+ getPipelines(): Promise<ApiResponse<Pipeline[]>>;
336
+ /**
337
+ * Get a single pipeline by ID
338
+ */
339
+ getPipeline(pipelineId: string): Promise<ApiResponse<Pipeline>>;
340
+ /**
341
+ * Create a new pipeline
342
+ */
343
+ createPipeline(pipeline: Partial<Pipeline>): Promise<ApiResponse<Pipeline>>;
344
+ /**
345
+ * Update an existing pipeline
346
+ */
347
+ updatePipeline(pipelineId: string, updates: Partial<Pipeline>): Promise<ApiResponse<Pipeline>>;
348
+ /**
349
+ * Delete a pipeline
350
+ */
351
+ deletePipeline(pipelineId: string): Promise<ApiResponse<void>>;
352
+ /**
353
+ * Get all tasks with pagination
354
+ */
355
+ getTasks(params?: {
356
+ page?: number;
357
+ limit?: number;
358
+ status?: string;
359
+ priority?: string;
360
+ contactId?: string;
361
+ companyId?: string;
362
+ opportunityId?: string;
363
+ }): Promise<ApiResponse<PaginatedResponse<Task>>>;
364
+ /**
365
+ * Get a single task by ID
366
+ */
367
+ getTask(taskId: string): Promise<ApiResponse<Task>>;
368
+ /**
369
+ * Create a new task
370
+ */
371
+ createTask(task: Partial<Task>): Promise<ApiResponse<Task>>;
372
+ /**
373
+ * Update an existing task
374
+ */
375
+ updateTask(taskId: string, updates: Partial<Task>): Promise<ApiResponse<Task>>;
376
+ /**
377
+ * Mark a task as completed
378
+ */
379
+ completeTask(taskId: string): Promise<ApiResponse<Task>>;
380
+ /**
381
+ * Delete a task
382
+ */
383
+ deleteTask(taskId: string): Promise<ApiResponse<void>>;
384
+ /**
385
+ * Get activities for a contact
386
+ */
387
+ getContactActivities(contactId: string, params?: {
388
+ page?: number;
389
+ limit?: number;
390
+ type?: string;
391
+ }): Promise<ApiResponse<PaginatedResponse<Activity>>>;
392
+ /**
393
+ * Get activities for an opportunity/deal
394
+ */
395
+ getOpportunityActivities(opportunityId: string, params?: {
396
+ page?: number;
397
+ limit?: number;
398
+ type?: string;
399
+ }): Promise<ApiResponse<PaginatedResponse<Activity>>>;
400
+ /**
401
+ * Create a new activity
402
+ */
403
+ createActivity(activity: Partial<Activity>): Promise<ApiResponse<Activity>>;
404
+ /**
405
+ * Update an existing activity
406
+ */
407
+ updateActivity(activityId: string, updates: Partial<Activity>): Promise<ApiResponse<Activity>>;
408
+ /**
409
+ * Delete an activity
410
+ */
411
+ deleteActivity(activityId: string): Promise<ApiResponse<void>>;
412
+ /**
413
+ * Log a call activity
414
+ */
415
+ logCall(data: {
416
+ contactId?: string;
417
+ opportunityId?: string;
418
+ direction: 'inbound' | 'outbound';
419
+ duration?: number;
420
+ outcome?: string;
421
+ notes?: string;
422
+ }): Promise<ApiResponse<Activity>>;
423
+ /**
424
+ * Log a meeting activity
425
+ */
426
+ logMeeting(data: {
427
+ contactId?: string;
428
+ opportunityId?: string;
429
+ title: string;
430
+ duration?: number;
431
+ outcome?: string;
432
+ notes?: string;
433
+ }): Promise<ApiResponse<Activity>>;
434
+ /**
435
+ * Add a note to a contact or opportunity
436
+ */
437
+ addNote(data: {
438
+ contactId?: string;
439
+ opportunityId?: string;
440
+ content: string;
441
+ }): Promise<ApiResponse<Activity>>;
442
+ /**
443
+ * Get all email templates
444
+ */
445
+ getEmailTemplates(params?: {
446
+ page?: number;
447
+ limit?: number;
448
+ }): Promise<ApiResponse<PaginatedResponse<EmailTemplate>>>;
449
+ /**
450
+ * Get a single email template by ID
451
+ */
452
+ getEmailTemplate(templateId: string): Promise<ApiResponse<EmailTemplate>>;
453
+ /**
454
+ * Create a new email template
455
+ */
456
+ createEmailTemplate(template: Partial<EmailTemplate>): Promise<ApiResponse<EmailTemplate>>;
457
+ /**
458
+ * Update an email template
459
+ */
460
+ updateEmailTemplate(templateId: string, updates: Partial<EmailTemplate>): Promise<ApiResponse<EmailTemplate>>;
461
+ /**
462
+ * Delete an email template
463
+ */
464
+ deleteEmailTemplate(templateId: string): Promise<ApiResponse<void>>;
465
+ /**
466
+ * Send an email using a template
467
+ */
468
+ sendEmail(data: {
469
+ to: string;
470
+ templateId?: string;
471
+ subject?: string;
472
+ body?: string;
473
+ cc?: string[];
474
+ bcc?: string[];
475
+ variables?: Record<string, unknown>;
476
+ contactId?: string;
477
+ }): Promise<ApiResponse<{
478
+ messageId: string;
479
+ }>>;
480
+ /**
481
+ * Get all event triggers
482
+ */
483
+ getEventTriggers(): Promise<ApiResponse<EventTrigger[]>>;
484
+ /**
485
+ * Create a new event trigger
486
+ */
487
+ createEventTrigger(trigger: Partial<EventTrigger>): Promise<ApiResponse<EventTrigger>>;
488
+ /**
489
+ * Update an event trigger
490
+ */
491
+ updateEventTrigger(triggerId: string, updates: Partial<EventTrigger>): Promise<ApiResponse<EventTrigger>>;
492
+ /**
493
+ * Delete an event trigger
494
+ */
495
+ deleteEventTrigger(triggerId: string): Promise<ApiResponse<void>>;
496
+ }
497
+
1
498
  /**
2
499
  * Clianta SDK - Type Definitions
3
500
  * @see SDK_VERSION in core/config.ts
@@ -7,8 +504,10 @@ interface CliantaConfig {
7
504
  projectId?: string;
8
505
  /** Backend API endpoint URL */
9
506
  apiEndpoint?: string;
10
- /** Auth token for server-side API access */
507
+ /** Auth token for server-side API access (user JWT) */
11
508
  authToken?: string;
509
+ /** Workspace API key for server-to-server access (use instead of authToken for external apps) */
510
+ apiKey?: string;
12
511
  /** Enable debug mode with verbose logging */
13
512
  debug?: boolean;
14
513
  /** Automatically track page views on load and navigation */
@@ -108,8 +607,8 @@ interface Plugin {
108
607
  interface TrackerCore {
109
608
  /** Track a custom event */
110
609
  track(eventType: EventType | string, eventName: string, properties?: Record<string, unknown>): void;
111
- /** Identify a visitor */
112
- identify(email: string, traits?: UserTraits): void;
610
+ /** Identify a visitor — returns the contactId if successful */
611
+ identify(email: string, traits?: UserTraits): Promise<string | null>;
113
612
  /** Track a page view */
114
613
  page(name?: string, properties?: Record<string, unknown>): void;
115
614
  /** Update consent state */
@@ -132,6 +631,8 @@ interface TrackerCore {
132
631
  deleteData(): void;
133
632
  /** Get current consent state */
134
633
  getConsentState(): ConsentState;
634
+ /** Send a server-side inbound event (requires apiKey in config) */
635
+ sendEvent(payload: InboundEventPayload): Promise<InboundEventResult>;
135
636
  }
136
637
  interface Contact {
137
638
  _id?: string;
@@ -269,6 +770,128 @@ interface PaginatedResponse<T> {
269
770
  pages: number;
270
771
  };
271
772
  }
773
+ 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';
774
+ interface TriggerCondition {
775
+ /**
776
+ * Field to check - supports dynamic field names including custom fields
777
+ * Examples: 'status', 'lifecycleStage', 'leadScore', 'customFields.industry'
778
+ * Use dot notation for nested fields: 'contact.email', 'customFields.accountType'
779
+ */
780
+ field: string;
781
+ /** Operator for comparison */
782
+ operator: 'equals' | 'not_equals' | 'contains' | 'greater_than' | 'less_than' | 'in' | 'not_in';
783
+ /** Value to compare against */
784
+ value: unknown;
785
+ }
786
+ interface EmailTemplate {
787
+ /** Template ID */
788
+ _id?: string;
789
+ /** Template name */
790
+ name: string;
791
+ /** Email subject line (supports variables) */
792
+ subject: string;
793
+ /** Email body (supports HTML and variables) */
794
+ body: string;
795
+ /** Variables available in this template */
796
+ variables?: string[];
797
+ /** Sender email address */
798
+ fromEmail?: string;
799
+ /** Sender name */
800
+ fromName?: string;
801
+ }
802
+ interface EmailAction {
803
+ /** Action type identifier */
804
+ type: 'send_email';
805
+ /** Email template ID or inline template */
806
+ templateId?: string;
807
+ /** Inline email subject (if not using template) */
808
+ subject?: string;
809
+ /** Inline email body (if not using template) */
810
+ body?: string;
811
+ /** Recipient email (supports variables like {{contact.email}}) */
812
+ to: string;
813
+ /** CC recipients */
814
+ cc?: string[];
815
+ /** BCC recipients */
816
+ bcc?: string[];
817
+ /** Sender email */
818
+ from?: string;
819
+ /** Delay in minutes before sending */
820
+ delayMinutes?: number;
821
+ }
822
+ interface WebhookAction {
823
+ /** Action type identifier */
824
+ type: 'webhook';
825
+ /** Webhook URL to call */
826
+ url: string;
827
+ /** HTTP method */
828
+ method: 'POST' | 'PUT' | 'PATCH';
829
+ /** Custom headers */
830
+ headers?: Record<string, string>;
831
+ /** Request body template (supports variables) */
832
+ body?: string;
833
+ }
834
+ interface TaskAction {
835
+ /** Action type identifier */
836
+ type: 'create_task';
837
+ /** Task title (supports variables) */
838
+ title: string;
839
+ /** Task description */
840
+ description?: string;
841
+ /** Task priority */
842
+ priority?: 'low' | 'medium' | 'high' | 'urgent';
843
+ /** Due date in days from trigger */
844
+ dueDays?: number;
845
+ /** Assign to user ID */
846
+ assignedTo?: string;
847
+ }
848
+ interface ContactUpdateAction {
849
+ /** Action type identifier */
850
+ type: 'update_contact';
851
+ /** Fields to update */
852
+ updates: Partial<Contact>;
853
+ }
854
+ type TriggerAction = EmailAction | WebhookAction | TaskAction | ContactUpdateAction;
855
+ interface EventTrigger {
856
+ /** Trigger ID */
857
+ _id?: string;
858
+ /** Workspace ID */
859
+ workspaceId: string;
860
+ /** Trigger name */
861
+ name: string;
862
+ /** Description of what this trigger does */
863
+ description?: string;
864
+ /** Event type that activates this trigger */
865
+ eventType: TriggerEventType;
866
+ /** Conditions that must be met for trigger to fire */
867
+ conditions?: TriggerCondition[];
868
+ /** Actions to execute when trigger fires */
869
+ actions: TriggerAction[];
870
+ /** Whether this trigger is active */
871
+ isActive?: boolean;
872
+ /** Created timestamp */
873
+ createdAt?: string;
874
+ /** Updated timestamp */
875
+ updatedAt?: string;
876
+ }
877
+ interface TriggerExecution {
878
+ /** Execution ID */
879
+ _id?: string;
880
+ /** Trigger ID that was executed */
881
+ triggerId: string;
882
+ /** Event that triggered the execution */
883
+ eventType: TriggerEventType;
884
+ /** Entity ID that triggered the event */
885
+ entityId: string;
886
+ /** Execution status */
887
+ status: 'pending' | 'success' | 'failed';
888
+ /** Error message if failed */
889
+ error?: string;
890
+ /** Actions executed */
891
+ actionsExecuted: number;
892
+ /** Execution timestamp */
893
+ executedAt: string;
894
+ }
272
895
 
273
896
  /**
274
897
  * Clianta SDK - Main Tracker Class
@@ -288,6 +911,10 @@ declare class Tracker implements TrackerCore {
288
911
  private sessionId;
289
912
  private isInitialized;
290
913
  private consentManager;
914
+ /** contactId after a successful identify() call */
915
+ private contactId;
916
+ /** Pending identify retry on next flush */
917
+ private pendingIdentify;
291
918
  constructor(workspaceId: string, userConfig?: CliantaConfig);
292
919
  /**
293
920
  * Create visitor ID based on storage mode
@@ -315,9 +942,20 @@ declare class Tracker implements TrackerCore {
315
942
  */
316
943
  page(name?: string, properties?: Record<string, unknown>): void;
317
944
  /**
318
- * Identify a visitor
945
+ * Identify a visitor.
946
+ * Links the anonymous visitorId to a CRM contact and returns the contactId.
947
+ * All subsequent track() calls will include the contactId automatically.
948
+ */
949
+ identify(email: string, traits?: UserTraits): Promise<string | null>;
950
+ /**
951
+ * Send a server-side inbound event via the API key endpoint.
952
+ * Convenience proxy to CRMClient.sendEvent() — requires apiKey in config.
319
953
  */
320
- identify(email: string, traits?: UserTraits): Promise<void>;
954
+ sendEvent(payload: InboundEventPayload): Promise<InboundEventResult>;
955
+ /**
956
+ * Retry pending identify call
957
+ */
958
+ private retryPendingIdentify;
321
959
  /**
322
960
  * Update consent state
323
961
  */
@@ -364,233 +1002,6 @@ declare class Tracker implements TrackerCore {
364
1002
  destroy(): Promise<void>;
365
1003
  }
366
1004
 
367
- /**
368
- * Clianta SDK - CRM API Client
369
- * @see SDK_VERSION in core/config.ts
370
- */
371
-
372
- /**
373
- * CRM API Client for managing contacts and opportunities
374
- */
375
- declare class CRMClient {
376
- private apiEndpoint;
377
- private workspaceId;
378
- private authToken?;
379
- constructor(apiEndpoint: string, workspaceId: string, authToken?: string);
380
- /**
381
- * Set authentication token for API requests
382
- */
383
- setAuthToken(token: string): void;
384
- /**
385
- * Make authenticated API request
386
- */
387
- private request;
388
- /**
389
- * Get all contacts with pagination
390
- */
391
- getContacts(params?: {
392
- page?: number;
393
- limit?: number;
394
- search?: string;
395
- status?: string;
396
- }): Promise<ApiResponse<PaginatedResponse<Contact>>>;
397
- /**
398
- * Get a single contact by ID
399
- */
400
- getContact(contactId: string): Promise<ApiResponse<Contact>>;
401
- /**
402
- * Create a new contact
403
- */
404
- createContact(contact: Partial<Contact>): Promise<ApiResponse<Contact>>;
405
- /**
406
- * Update an existing contact
407
- */
408
- updateContact(contactId: string, updates: Partial<Contact>): Promise<ApiResponse<Contact>>;
409
- /**
410
- * Delete a contact
411
- */
412
- deleteContact(contactId: string): Promise<ApiResponse<void>>;
413
- /**
414
- * Get all opportunities with pagination
415
- */
416
- getOpportunities(params?: {
417
- page?: number;
418
- limit?: number;
419
- pipelineId?: string;
420
- stageId?: string;
421
- }): Promise<ApiResponse<PaginatedResponse<Opportunity>>>;
422
- /**
423
- * Get a single opportunity by ID
424
- */
425
- getOpportunity(opportunityId: string): Promise<ApiResponse<Opportunity>>;
426
- /**
427
- * Create a new opportunity
428
- */
429
- createOpportunity(opportunity: Partial<Opportunity>): Promise<ApiResponse<Opportunity>>;
430
- /**
431
- * Update an existing opportunity
432
- */
433
- updateOpportunity(opportunityId: string, updates: Partial<Opportunity>): Promise<ApiResponse<Opportunity>>;
434
- /**
435
- * Delete an opportunity
436
- */
437
- deleteOpportunity(opportunityId: string): Promise<ApiResponse<void>>;
438
- /**
439
- * Move opportunity to a different stage
440
- */
441
- moveOpportunity(opportunityId: string, stageId: string): Promise<ApiResponse<Opportunity>>;
442
- /**
443
- * Get all companies with pagination
444
- */
445
- getCompanies(params?: {
446
- page?: number;
447
- limit?: number;
448
- search?: string;
449
- status?: string;
450
- industry?: string;
451
- }): Promise<ApiResponse<PaginatedResponse<Company>>>;
452
- /**
453
- * Get a single company by ID
454
- */
455
- getCompany(companyId: string): Promise<ApiResponse<Company>>;
456
- /**
457
- * Create a new company
458
- */
459
- createCompany(company: Partial<Company>): Promise<ApiResponse<Company>>;
460
- /**
461
- * Update an existing company
462
- */
463
- updateCompany(companyId: string, updates: Partial<Company>): Promise<ApiResponse<Company>>;
464
- /**
465
- * Delete a company
466
- */
467
- deleteCompany(companyId: string): Promise<ApiResponse<void>>;
468
- /**
469
- * Get contacts belonging to a company
470
- */
471
- getCompanyContacts(companyId: string, params?: {
472
- page?: number;
473
- limit?: number;
474
- }): Promise<ApiResponse<PaginatedResponse<Contact>>>;
475
- /**
476
- * Get deals/opportunities belonging to a company
477
- */
478
- getCompanyDeals(companyId: string, params?: {
479
- page?: number;
480
- limit?: number;
481
- }): Promise<ApiResponse<PaginatedResponse<Opportunity>>>;
482
- /**
483
- * Get all pipelines
484
- */
485
- getPipelines(): Promise<ApiResponse<Pipeline[]>>;
486
- /**
487
- * Get a single pipeline by ID
488
- */
489
- getPipeline(pipelineId: string): Promise<ApiResponse<Pipeline>>;
490
- /**
491
- * Create a new pipeline
492
- */
493
- createPipeline(pipeline: Partial<Pipeline>): Promise<ApiResponse<Pipeline>>;
494
- /**
495
- * Update an existing pipeline
496
- */
497
- updatePipeline(pipelineId: string, updates: Partial<Pipeline>): Promise<ApiResponse<Pipeline>>;
498
- /**
499
- * Delete a pipeline
500
- */
501
- deletePipeline(pipelineId: string): Promise<ApiResponse<void>>;
502
- /**
503
- * Get all tasks with pagination
504
- */
505
- getTasks(params?: {
506
- page?: number;
507
- limit?: number;
508
- status?: string;
509
- priority?: string;
510
- contactId?: string;
511
- companyId?: string;
512
- opportunityId?: string;
513
- }): Promise<ApiResponse<PaginatedResponse<Task>>>;
514
- /**
515
- * Get a single task by ID
516
- */
517
- getTask(taskId: string): Promise<ApiResponse<Task>>;
518
- /**
519
- * Create a new task
520
- */
521
- createTask(task: Partial<Task>): Promise<ApiResponse<Task>>;
522
- /**
523
- * Update an existing task
524
- */
525
- updateTask(taskId: string, updates: Partial<Task>): Promise<ApiResponse<Task>>;
526
- /**
527
- * Mark a task as completed
528
- */
529
- completeTask(taskId: string): Promise<ApiResponse<Task>>;
530
- /**
531
- * Delete a task
532
- */
533
- deleteTask(taskId: string): Promise<ApiResponse<void>>;
534
- /**
535
- * Get activities for a contact
536
- */
537
- getContactActivities(contactId: string, params?: {
538
- page?: number;
539
- limit?: number;
540
- type?: string;
541
- }): Promise<ApiResponse<PaginatedResponse<Activity>>>;
542
- /**
543
- * Get activities for an opportunity/deal
544
- */
545
- getOpportunityActivities(opportunityId: string, params?: {
546
- page?: number;
547
- limit?: number;
548
- type?: string;
549
- }): Promise<ApiResponse<PaginatedResponse<Activity>>>;
550
- /**
551
- * Create a new activity
552
- */
553
- createActivity(activity: Partial<Activity>): Promise<ApiResponse<Activity>>;
554
- /**
555
- * Update an existing activity
556
- */
557
- updateActivity(activityId: string, updates: Partial<Activity>): Promise<ApiResponse<Activity>>;
558
- /**
559
- * Delete an activity
560
- */
561
- deleteActivity(activityId: string): Promise<ApiResponse<void>>;
562
- /**
563
- * Log a call activity
564
- */
565
- logCall(data: {
566
- contactId?: string;
567
- opportunityId?: string;
568
- direction: 'inbound' | 'outbound';
569
- duration?: number;
570
- outcome?: string;
571
- notes?: string;
572
- }): Promise<ApiResponse<Activity>>;
573
- /**
574
- * Log a meeting activity
575
- */
576
- logMeeting(data: {
577
- contactId?: string;
578
- opportunityId?: string;
579
- title: string;
580
- duration?: number;
581
- outcome?: string;
582
- notes?: string;
583
- }): Promise<ApiResponse<Activity>>;
584
- /**
585
- * Add a note to a contact or opportunity
586
- */
587
- addNote(data: {
588
- contactId?: string;
589
- opportunityId?: string;
590
- content: string;
591
- }): Promise<ApiResponse<Activity>>;
592
- }
593
-
594
1005
  /**
595
1006
  * Clianta SDK - Consent Manager
596
1007
  * Manages consent state and event buffering for GDPR/CCPA compliance
@@ -687,7 +1098,7 @@ interface StoredConsent {
687
1098
  */
688
1099
 
689
1100
  /** SDK Version */
690
- declare const SDK_VERSION = "1.2.0";
1101
+ declare const SDK_VERSION = "1.4.0";
691
1102
 
692
1103
  /**
693
1104
  * Clianta SDK
@@ -721,5 +1132,5 @@ declare const SDK_VERSION = "1.2.0";
721
1132
  */
722
1133
  declare function clianta(workspaceId: string, config?: CliantaConfig): TrackerCore;
723
1134
 
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 };
1135
+ export { CRMClient, ConsentManager, EventTriggersManager, SDK_VERSION, Tracker, clianta, clianta as default };
1136
+ export type { Activity, ApiResponse, CliantaConfig, Company, ConsentChangeCallback, ConsentConfig, ConsentManagerConfig, ConsentState, Contact, ContactUpdateAction, EmailAction, EmailTemplate, EventTrigger, EventType, InboundEventPayload, InboundEventResult, InboundEventType, Opportunity, PaginatedResponse, Pipeline, PipelineStage, Plugin, PluginName, StoredConsent, Task, TaskAction, TrackerCore, TrackingEvent, TriggerAction, TriggerCondition, TriggerEventType, TriggerExecution, UserTraits, WebhookAction };