@clianta/sdk 1.6.0 → 1.6.2

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,580 +1,3 @@
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('http://localhost:5000', '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 a contact by email address.
482
- * Returns the first matching contact from a search query.
483
- */
484
- getContactByEmail(email: string): Promise<ApiResponse<PaginatedResponse<Contact>>>;
485
- /**
486
- * Get activity timeline for a contact
487
- */
488
- getContactActivity(contactId: string, params?: {
489
- page?: number;
490
- limit?: number;
491
- type?: string;
492
- startDate?: string;
493
- endDate?: string;
494
- }): Promise<ApiResponse<PaginatedResponse<Activity>>>;
495
- /**
496
- * Get engagement metrics for a contact (via their linked visitor data)
497
- */
498
- getContactEngagement(contactId: string): Promise<ApiResponse<{
499
- totalTimeOnSiteSeconds: number;
500
- averageSessionDurationSeconds: number;
501
- totalPageViews: number;
502
- totalSessions: number;
503
- engagementScore: number;
504
- lastActiveAt: string;
505
- }>>;
506
- /**
507
- * Get a full timeline for a contact including events, activities, and opportunities
508
- */
509
- getContactTimeline(contactId: string, params?: {
510
- page?: number;
511
- limit?: number;
512
- }): Promise<ApiResponse<PaginatedResponse<{
513
- type: 'event' | 'activity' | 'opportunity' | 'note';
514
- title: string;
515
- description?: string;
516
- timestamp: string;
517
- metadata?: Record<string, unknown>;
518
- }>>>;
519
- /**
520
- * Search contacts with advanced filters
521
- */
522
- searchContacts(query: string, filters?: {
523
- status?: string;
524
- lifecycleStage?: string;
525
- source?: string;
526
- tags?: string[];
527
- page?: number;
528
- limit?: number;
529
- }): Promise<ApiResponse<PaginatedResponse<Contact>>>;
530
- /**
531
- * List all webhook subscriptions
532
- */
533
- listWebhooks(params?: {
534
- page?: number;
535
- limit?: number;
536
- }): Promise<ApiResponse<PaginatedResponse<{
537
- _id: string;
538
- url: string;
539
- events: string[];
540
- isActive: boolean;
541
- createdAt: string;
542
- }>>>;
543
- /**
544
- * Create a new webhook subscription
545
- */
546
- createWebhook(data: {
547
- url: string;
548
- events: string[];
549
- secret?: string;
550
- }): Promise<ApiResponse<{
551
- _id: string;
552
- url: string;
553
- events: string[];
554
- isActive: boolean;
555
- }>>;
556
- /**
557
- * Delete a webhook subscription
558
- */
559
- deleteWebhook(webhookId: string): Promise<ApiResponse<void>>;
560
- /**
561
- * Get all event triggers
562
- */
563
- getEventTriggers(): Promise<ApiResponse<EventTrigger[]>>;
564
- /**
565
- * Create a new event trigger
566
- */
567
- createEventTrigger(trigger: Partial<EventTrigger>): Promise<ApiResponse<EventTrigger>>;
568
- /**
569
- * Update an event trigger
570
- */
571
- updateEventTrigger(triggerId: string, updates: Partial<EventTrigger>): Promise<ApiResponse<EventTrigger>>;
572
- /**
573
- * Delete an event trigger
574
- */
575
- deleteEventTrigger(triggerId: string): Promise<ApiResponse<void>>;
576
- }
577
-
578
1
  /**
579
2
  * Clianta SDK - Type Definitions
580
3
  * @see SDK_VERSION in core/config.ts
@@ -584,10 +7,6 @@ interface CliantaConfig {
584
7
  projectId?: string;
585
8
  /** Backend API endpoint URL */
586
9
  apiEndpoint?: string;
587
- /** Auth token for server-side API access (user JWT) */
588
- authToken?: string;
589
- /** Workspace API key for server-to-server access (use instead of authToken for external apps) */
590
- apiKey?: string;
591
10
  /** Enable debug mode with verbose logging */
592
11
  debug?: boolean;
593
12
  /** Automatically track page views on load and navigation */
@@ -743,24 +162,6 @@ interface TrackerCore {
743
162
  onReady(callback: () => void): void;
744
163
  /** Check if the SDK is fully initialized and ready */
745
164
  isReady(): boolean;
746
- /** Get the current visitor's profile from the CRM */
747
- getVisitorProfile(): Promise<VisitorProfile | null>;
748
- /** Get the current visitor's recent activity */
749
- getVisitorActivity(options?: VisitorActivityOptions): Promise<{
750
- data: VisitorActivity[];
751
- pagination: {
752
- page: number;
753
- limit: number;
754
- total: number;
755
- pages: number;
756
- };
757
- } | null>;
758
- /** Get a summarized journey timeline for the current visitor */
759
- getVisitorTimeline(): Promise<VisitorTimeline | null>;
760
- /** Get engagement metrics for the current visitor */
761
- getVisitorEngagement(): Promise<EngagementMetrics | null>;
762
- /** Send a server-side inbound event (requires apiKey in config) */
763
- sendEvent(payload: InboundEventPayload): Promise<InboundEventResult>;
764
165
  /** Create or update a contact by email (upsert) */
765
166
  createContact(data: PublicContactData): Promise<PublicCrmResult>;
766
167
  /** Update an existing contact by ID (limited fields) */
@@ -771,341 +172,8 @@ interface TrackerCore {
771
172
  logActivity(data: PublicActivityData): Promise<PublicCrmResult>;
772
173
  /** Create an opportunity (e.g., from "Request Demo" forms) */
773
174
  createOpportunity(data: PublicOpportunityData): Promise<PublicCrmResult>;
774
- }
775
- interface Contact {
776
- _id?: string;
777
- workspaceId: string;
778
- email: string;
779
- firstName?: string;
780
- lastName?: string;
781
- company?: string;
782
- jobTitle?: string;
783
- phone?: string;
784
- status?: 'lead' | 'contact' | 'customer';
785
- lifecycleStage?: 'subscriber' | 'lead' | 'mql' | 'sql' | 'opportunity' | 'customer' | 'evangelist';
786
- source?: string;
787
- tags?: string[];
788
- leadScore?: number;
789
- customFields?: Record<string, unknown>;
790
- companyId?: string;
791
- assignedTo?: string;
792
- createdAt?: string;
793
- updatedAt?: string;
794
- }
795
- interface Company {
796
- _id?: string;
797
- workspaceId: string;
798
- name: string;
799
- industry?: string;
800
- website?: string;
801
- phone?: string;
802
- address?: {
803
- street?: string;
804
- city?: string;
805
- state?: string;
806
- country?: string;
807
- postalCode?: string;
808
- };
809
- companySize?: string;
810
- annualRevenue?: number;
811
- status?: 'prospect' | 'active' | 'inactive' | 'churned';
812
- accountTier?: 'enterprise' | 'mid-market' | 'smb';
813
- isTargetAccount?: boolean;
814
- tags?: string[];
815
- customFields?: Record<string, unknown>;
816
- assignedTo?: string;
817
- createdAt?: string;
818
- updatedAt?: string;
819
- }
820
- interface Pipeline {
821
- _id?: string;
822
- workspaceId: string;
823
- name: string;
824
- description?: string;
825
- stages: PipelineStage[];
826
- isDefault?: boolean;
827
- isActive?: boolean;
828
- createdAt?: string;
829
- updatedAt?: string;
830
- }
831
- interface PipelineStage {
832
- _id?: string;
833
- name: string;
834
- order: number;
835
- probability?: number;
836
- color?: string;
837
- rottenDays?: number;
838
- }
839
- interface Task {
840
- _id?: string;
841
- workspaceId: string;
842
- title: string;
843
- description?: string;
844
- status?: 'pending' | 'in_progress' | 'completed' | 'cancelled';
845
- priority?: 'low' | 'medium' | 'high' | 'urgent';
846
- dueDate?: string;
847
- reminderDate?: string;
848
- completedAt?: string;
849
- tags?: string[];
850
- relatedContactId?: string;
851
- relatedCompanyId?: string;
852
- relatedOpportunityId?: string;
853
- assignedTo?: string;
854
- createdAt?: string;
855
- updatedAt?: string;
856
- }
857
- interface Activity {
858
- _id?: string;
859
- workspaceId: string;
860
- type: 'call' | 'email' | 'meeting' | 'note' | 'task' | 'other';
861
- title: string;
862
- description?: string;
863
- direction?: 'inbound' | 'outbound';
864
- duration?: number;
865
- outcome?: string;
866
- emailSubject?: string;
867
- emailBody?: string;
868
- metadata?: Record<string, unknown>;
869
- contactId?: string;
870
- companyId?: string;
871
- opportunityId?: string;
872
- userId?: string;
873
- createdAt?: string;
874
- updatedAt?: string;
875
- }
876
- interface Opportunity {
877
- _id?: string;
878
- workspaceId: string;
879
- contactId: string;
880
- companyId?: string;
881
- pipelineId: string;
882
- stageId: string;
883
- title: string;
884
- value?: number;
885
- currency?: string;
886
- probability?: number;
887
- expectedCloseDate?: string;
888
- status?: 'open' | 'won' | 'lost';
889
- priority?: 'low' | 'medium' | 'high';
890
- lostReason?: string;
891
- customFields?: Record<string, unknown>;
892
- assignedTo?: string;
893
- createdAt?: string;
894
- updatedAt?: string;
895
- }
896
- interface ApiResponse<T> {
897
- success: boolean;
898
- data?: T;
899
- error?: string;
900
- status: number;
901
- }
902
- interface PaginatedResponse<T> {
903
- data: T[];
904
- pagination: {
905
- page: number;
906
- limit: number;
907
- total: number;
908
- pages: number;
909
- };
910
- }
911
- 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';
912
- interface TriggerCondition {
913
- /**
914
- * Field to check - supports dynamic field names including custom fields
915
- * Examples: 'status', 'lifecycleStage', 'leadScore', 'customFields.industry'
916
- * Use dot notation for nested fields: 'contact.email', 'customFields.accountType'
917
- */
918
- field: string;
919
- /** Operator for comparison */
920
- operator: 'equals' | 'not_equals' | 'contains' | 'greater_than' | 'less_than' | 'in' | 'not_in';
921
- /** Value to compare against */
922
- value: unknown;
923
- }
924
- interface EmailTemplate {
925
- /** Template ID */
926
- _id?: string;
927
- /** Template name */
928
- name: string;
929
- /** Email subject line (supports variables) */
930
- subject: string;
931
- /** Email body (supports HTML and variables) */
932
- body: string;
933
- /** Variables available in this template */
934
- variables?: string[];
935
- /** Sender email address */
936
- fromEmail?: string;
937
- /** Sender name */
938
- fromName?: string;
939
- }
940
- interface EmailAction {
941
- /** Action type identifier */
942
- type: 'send_email';
943
- /** Email template ID or inline template */
944
- templateId?: string;
945
- /** Inline email subject (if not using template) */
946
- subject?: string;
947
- /** Inline email body (if not using template) */
948
- body?: string;
949
- /** Recipient email (supports variables like {{contact.email}}) */
950
- to: string;
951
- /** CC recipients */
952
- cc?: string[];
953
- /** BCC recipients */
954
- bcc?: string[];
955
- /** Sender email */
956
- from?: string;
957
- /** Delay in minutes before sending */
958
- delayMinutes?: number;
959
- }
960
- interface WebhookAction {
961
- /** Action type identifier */
962
- type: 'webhook';
963
- /** Webhook URL to call */
964
- url: string;
965
- /** HTTP method */
966
- method: 'POST' | 'PUT' | 'PATCH';
967
- /** Custom headers */
968
- headers?: Record<string, string>;
969
- /** Request body template (supports variables) */
970
- body?: string;
971
- }
972
- interface TaskAction {
973
- /** Action type identifier */
974
- type: 'create_task';
975
- /** Task title (supports variables) */
976
- title: string;
977
- /** Task description */
978
- description?: string;
979
- /** Task priority */
980
- priority?: 'low' | 'medium' | 'high' | 'urgent';
981
- /** Due date in days from trigger */
982
- dueDays?: number;
983
- /** Assign to user ID */
984
- assignedTo?: string;
985
- }
986
- interface ContactUpdateAction {
987
- /** Action type identifier */
988
- type: 'update_contact';
989
- /** Fields to update */
990
- updates: Partial<Contact>;
991
- }
992
- type TriggerAction = EmailAction | WebhookAction | TaskAction | ContactUpdateAction;
993
- interface EventTrigger {
994
- /** Trigger ID */
995
- _id?: string;
996
- /** Workspace ID */
997
- workspaceId: string;
998
- /** Trigger name */
999
- name: string;
1000
- /** Description of what this trigger does */
1001
- description?: string;
1002
- /** Event type that activates this trigger */
1003
- eventType: TriggerEventType;
1004
- /** Conditions that must be met for trigger to fire */
1005
- conditions?: TriggerCondition[];
1006
- /** Actions to execute when trigger fires */
1007
- actions: TriggerAction[];
1008
- /** Whether this trigger is active */
1009
- isActive?: boolean;
1010
- /** Created timestamp */
1011
- createdAt?: string;
1012
- /** Updated timestamp */
1013
- updatedAt?: string;
1014
- }
1015
- interface TriggerExecution {
1016
- /** Execution ID */
1017
- _id?: string;
1018
- /** Trigger ID that was executed */
1019
- triggerId: string;
1020
- /** Event that triggered the execution */
1021
- eventType: TriggerEventType;
1022
- /** Entity ID that triggered the event */
1023
- entityId: string;
1024
- /** Execution status */
1025
- status: 'pending' | 'success' | 'failed';
1026
- /** Error message if failed */
1027
- error?: string;
1028
- /** Actions executed */
1029
- actionsExecuted: number;
1030
- /** Execution timestamp */
1031
- executedAt: string;
1032
- }
1033
- interface VisitorProfile {
1034
- visitorId: string;
1035
- contactId?: string;
1036
- email?: string;
1037
- firstName?: string;
1038
- lastName?: string;
1039
- company?: string;
1040
- jobTitle?: string;
1041
- phone?: string;
1042
- status?: string;
1043
- lifecycleStage?: string;
1044
- tags?: string[];
1045
- leadScore?: number;
1046
- firstSeen?: string;
1047
- lastSeen?: string;
1048
- sessionCount?: number;
1049
- pageViewCount?: number;
1050
- totalTimeSpent?: number;
1051
- customFields?: Record<string, unknown>;
1052
- }
1053
- interface VisitorActivity {
1054
- _id?: string;
1055
- eventType: string;
1056
- eventName: string;
1057
- url: string;
1058
- properties?: Record<string, unknown>;
1059
- timestamp: string;
1060
- }
1061
- interface VisitorTimeline {
1062
- visitorId: string;
1063
- contactId?: string;
1064
- firstSeen: string;
1065
- lastSeen: string;
1066
- totalSessions: number;
1067
- totalPageViews: number;
1068
- totalEvents: number;
1069
- totalTimeSpentSeconds: number;
1070
- averageSessionDurationSeconds: number;
1071
- topPages: Array<{
1072
- url: string;
1073
- views: number;
1074
- avgTimeSeconds?: number;
1075
- }>;
1076
- recentActivities: VisitorActivity[];
1077
- devices: Array<{
1078
- userAgent: string;
1079
- lastSeen: string;
1080
- }>;
1081
- }
1082
- interface EngagementMetrics {
1083
- visitorId: string;
1084
- totalTimeOnSiteSeconds: number;
1085
- averageSessionDurationSeconds: number;
1086
- totalPageViews: number;
1087
- totalSessions: number;
1088
- engagementScore: number;
1089
- bounceRate: number;
1090
- lastActiveAt: string;
1091
- topEvents: Array<{
1092
- eventType: string;
1093
- count: number;
1094
- }>;
1095
- }
1096
- interface VisitorActivityOptions {
1097
- page?: number;
1098
- limit?: number;
1099
- eventType?: string;
1100
- startDate?: string;
1101
- endDate?: string;
1102
- }
1103
- interface ContactTimelineOptions {
1104
- page?: number;
1105
- limit?: number;
1106
- includeEvents?: boolean;
1107
- includeActivities?: boolean;
1108
- includeOpportunities?: boolean;
175
+ /** Destroy the tracker instance, flush pending events, and clean up plugins */
176
+ destroy(): Promise<void>;
1109
177
  }
1110
178
  interface PublicContactData {
1111
179
  email: string;
@@ -1165,68 +233,10 @@ interface PublicCrmResult {
1165
233
  }
1166
234
 
1167
235
  /**
1168
- * VisitorClient Standalone client for visitor-related API calls.
1169
- * Extracted from Tracker to keep the core Tracker class focused on tracking.
1170
- *
1171
- * Usage (standalone):
1172
- * const visitor = new VisitorClient(transport, workspaceId, visitorId);
1173
- * const profile = await visitor.getProfile();
1174
- *
1175
- * Usage (via Tracker):
1176
- * const tracker = clianta({ projectId: '...' });
1177
- * const profile = await tracker.visitor.getProfile();
236
+ * Clianta SDK - Main Tracker Class
237
+ * @see SDK_VERSION in core/config.ts
1178
238
  */
1179
239
 
1180
- /** Minimal transport interface — only fetchData is needed */
1181
- interface VisitorTransport {
1182
- fetchData<T>(url: string, params?: Record<string, string>): Promise<{
1183
- success: boolean;
1184
- data?: T;
1185
- error?: Error | string;
1186
- }>;
1187
- }
1188
- /**
1189
- * Privacy-safe visitor API client.
1190
- * All methods return data for the current visitor only (no cross-visitor access).
1191
- */
1192
- declare class VisitorClient {
1193
- private transport;
1194
- private workspaceId;
1195
- private visitorId;
1196
- constructor(transport: VisitorTransport, workspaceId: string, visitorId: string);
1197
- /** Update visitorId (e.g. after reset) */
1198
- setVisitorId(id: string): void;
1199
- private basePath;
1200
- /**
1201
- * Get the current visitor's profile from the CRM.
1202
- * Returns visitor data and linked contact info if identified.
1203
- */
1204
- getProfile(): Promise<VisitorProfile | null>;
1205
- /**
1206
- * Get the current visitor's recent activity/events.
1207
- * Returns paginated list of tracking events.
1208
- */
1209
- getActivity(options?: VisitorActivityOptions): Promise<{
1210
- data: VisitorActivity[];
1211
- pagination: {
1212
- page: number;
1213
- limit: number;
1214
- total: number;
1215
- pages: number;
1216
- };
1217
- } | null>;
1218
- /**
1219
- * Get a summarized journey timeline for the current visitor.
1220
- * Includes top pages, sessions, time spent, and recent activities.
1221
- */
1222
- getTimeline(): Promise<VisitorTimeline | null>;
1223
- /**
1224
- * Get engagement metrics for the current visitor.
1225
- * Includes time on site, page views, bounce rate, and engagement score.
1226
- */
1227
- getEngagement(): Promise<EngagementMetrics | null>;
1228
- }
1229
-
1230
240
  /**
1231
241
  * Main Clianta Tracker Class
1232
242
  */
@@ -1252,8 +262,6 @@ declare class Tracker implements TrackerCore {
1252
262
  private middlewares;
1253
263
  /** Ready callbacks */
1254
264
  private readyCallbacks;
1255
- /** Visitor API client (standalone, also accessible via tracker.visitor) */
1256
- visitor: VisitorClient;
1257
265
  constructor(workspaceId: string, userConfig?: CliantaConfig);
1258
266
  /**
1259
267
  * Create visitor ID based on storage mode
@@ -1286,39 +294,6 @@ declare class Tracker implements TrackerCore {
1286
294
  * All subsequent track() calls will include the contactId automatically.
1287
295
  */
1288
296
  identify(email: string, traits?: UserTraits): Promise<string | null>;
1289
- /**
1290
- * Send a server-side inbound event via the API key endpoint.
1291
- * Convenience proxy to CRMClient.sendEvent() — requires apiKey in config.
1292
- */
1293
- sendEvent(payload: InboundEventPayload): Promise<InboundEventResult>;
1294
- /**
1295
- * Get the current visitor's profile from the CRM.
1296
- * @deprecated Use `tracker.visitor.getProfile()` instead.
1297
- */
1298
- getVisitorProfile(): Promise<VisitorProfile | null>;
1299
- /**
1300
- * Get the current visitor's recent activity/events.
1301
- * @deprecated Use `tracker.visitor.getActivity()` instead.
1302
- */
1303
- getVisitorActivity(options?: VisitorActivityOptions): Promise<{
1304
- data: VisitorActivity[];
1305
- pagination: {
1306
- page: number;
1307
- limit: number;
1308
- total: number;
1309
- pages: number;
1310
- };
1311
- } | null>;
1312
- /**
1313
- * Get a summarized journey timeline for the current visitor.
1314
- * @deprecated Use `tracker.visitor.getTimeline()` instead.
1315
- */
1316
- getVisitorTimeline(): Promise<VisitorTimeline | null>;
1317
- /**
1318
- * Get engagement metrics for the current visitor.
1319
- * @deprecated Use `tracker.visitor.getEngagement()` instead.
1320
- */
1321
- getVisitorEngagement(): Promise<EngagementMetrics | null>;
1322
297
  /**
1323
298
  * Retry pending identify call
1324
299
  */
@@ -1549,11 +524,16 @@ interface StoredConsent {
1549
524
  */
1550
525
 
1551
526
  /** SDK Version */
1552
- declare const SDK_VERSION = "1.6.0";
527
+ declare const SDK_VERSION = "1.6.2";
1553
528
 
1554
529
  /**
1555
530
  * Clianta SDK
1556
- * Professional CRM and tracking SDK for lead generation
531
+ * Client-side tracking SDK for CRM — tracks visitors, identifies contacts,
532
+ * captures forms, and writes CRM data from client websites.
533
+ *
534
+ * This SDK is designed to run on CLIENT WEBSITES (React, Next.js, Vue, etc.)
535
+ * It only SENDS data to your CRM — it never reads CRM data back.
536
+ *
1557
537
  * @see SDK_VERSION in core/config.ts
1558
538
  */
1559
539
 
@@ -1583,5 +563,5 @@ declare const SDK_VERSION = "1.6.0";
1583
563
  */
1584
564
  declare function clianta(workspaceId: string, config?: CliantaConfig): TrackerCore;
1585
565
 
1586
- export { CRMClient, ConsentManager, EventTriggersManager, SDK_VERSION, Tracker, clianta, clianta as default };
1587
- export type { Activity, ApiResponse, CliantaConfig, Company, ConsentChangeCallback, ConsentConfig, ConsentManagerConfig, ConsentState, Contact, ContactTimelineOptions, ContactUpdateAction, EmailAction, EmailTemplate, EngagementMetrics, EventTrigger, EventType, GroupTraits, InboundEventPayload, InboundEventResult, InboundEventType, MiddlewareFn, Opportunity, PaginatedResponse, Pipeline, PipelineStage, Plugin, PluginName, PublicActivityData, PublicContactData, PublicContactUpdate, PublicCrmResult, PublicFormSubmission, PublicOpportunityData, StoredConsent, Task, TaskAction, TrackerCore, TrackingEvent, TriggerAction, TriggerCondition, TriggerEventType, TriggerExecution, UserTraits, VisitorActivity, VisitorActivityOptions, VisitorProfile, VisitorTimeline, WebhookAction };
566
+ export { ConsentManager, SDK_VERSION, Tracker, clianta, clianta as default };
567
+ export type { CliantaConfig, ConsentChangeCallback, ConsentConfig, ConsentManagerConfig, ConsentState, EventType, GroupTraits, MiddlewareFn, Plugin, PluginName, PublicActivityData, PublicContactData, PublicContactUpdate, PublicCrmResult, PublicFormSubmission, PublicOpportunityData, StoredConsent, TrackerCore, TrackingEvent, UserTraits };