@clianta/sdk 1.7.2 → 1.7.3
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/angular.cjs.js +53 -47
- package/dist/angular.cjs.js.map +1 -1
- package/dist/angular.d.ts +12 -9
- package/dist/angular.esm.js +53 -47
- package/dist/angular.esm.js.map +1 -1
- package/dist/clianta.cjs.js +1237 -47
- package/dist/clianta.cjs.js.map +1 -1
- package/dist/clianta.esm.js +1237 -48
- package/dist/clianta.esm.js.map +1 -1
- package/dist/clianta.umd.js +1237 -47
- package/dist/clianta.umd.js.map +1 -1
- package/dist/clianta.umd.min.js +2 -2
- package/dist/clianta.umd.min.js.map +1 -1
- package/dist/index.d.ts +831 -11
- package/dist/react.cjs.js +53 -47
- package/dist/react.cjs.js.map +1 -1
- package/dist/react.d.ts +12 -9
- package/dist/react.esm.js +53 -47
- package/dist/react.esm.js.map +1 -1
- package/dist/svelte.cjs.js +53 -47
- package/dist/svelte.cjs.js.map +1 -1
- package/dist/svelte.d.ts +12 -9
- package/dist/svelte.esm.js +53 -47
- package/dist/svelte.esm.js.map +1 -1
- package/dist/vue.cjs.js +53 -47
- package/dist/vue.cjs.js.map +1 -1
- package/dist/vue.d.ts +12 -9
- package/dist/vue.esm.js +53 -47
- package/dist/vue.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -57,6 +57,10 @@ interface TrackingEvent {
|
|
|
57
57
|
visitorId: string;
|
|
58
58
|
/** Session identifier */
|
|
59
59
|
sessionId: string;
|
|
60
|
+
/** CRM contact ID (set after a successful identify() call) */
|
|
61
|
+
contactId?: string;
|
|
62
|
+
/** Group ID (set after a successful group() call) */
|
|
63
|
+
groupId?: string;
|
|
60
64
|
/** Event type category */
|
|
61
65
|
eventType: EventType;
|
|
62
66
|
/** Human-readable event name */
|
|
@@ -69,8 +73,12 @@ interface TrackingEvent {
|
|
|
69
73
|
properties: Record<string, unknown>;
|
|
70
74
|
/** Device information */
|
|
71
75
|
device: DeviceInfo;
|
|
72
|
-
/** UTM parameters */
|
|
73
|
-
|
|
76
|
+
/** UTM parameters (flat, root-level — matches backend schema) */
|
|
77
|
+
utmSource?: string;
|
|
78
|
+
utmMedium?: string;
|
|
79
|
+
utmCampaign?: string;
|
|
80
|
+
utmTerm?: string;
|
|
81
|
+
utmContent?: string;
|
|
74
82
|
/** ISO timestamp */
|
|
75
83
|
timestamp: string;
|
|
76
84
|
/** SDK version */
|
|
@@ -82,13 +90,6 @@ interface DeviceInfo {
|
|
|
82
90
|
language: string;
|
|
83
91
|
timezone?: string;
|
|
84
92
|
}
|
|
85
|
-
interface UTMParams {
|
|
86
|
-
utmSource?: string;
|
|
87
|
-
utmMedium?: string;
|
|
88
|
-
utmCampaign?: string;
|
|
89
|
-
utmTerm?: string;
|
|
90
|
-
utmContent?: string;
|
|
91
|
-
}
|
|
92
93
|
interface GroupTraits {
|
|
93
94
|
/** Company/account name */
|
|
94
95
|
name?: string;
|
|
@@ -162,6 +163,8 @@ interface TrackerCore {
|
|
|
162
163
|
onReady(callback: () => void): void;
|
|
163
164
|
/** Check if the SDK is fully initialized and ready */
|
|
164
165
|
isReady(): boolean;
|
|
166
|
+
/** Register a schema for event validation (active in debug mode) */
|
|
167
|
+
registerEventSchema(eventType: string, schema: Record<string, 'string' | 'number' | 'boolean' | 'object' | 'array'>): void;
|
|
165
168
|
/** Create or update a contact by email (upsert) */
|
|
166
169
|
createContact(data: PublicContactData): Promise<PublicCrmResult>;
|
|
167
170
|
/** Update an existing contact by ID (limited fields) */
|
|
@@ -175,6 +178,246 @@ interface TrackerCore {
|
|
|
175
178
|
/** Destroy the tracker instance, flush pending events, and clean up plugins */
|
|
176
179
|
destroy(): Promise<void>;
|
|
177
180
|
}
|
|
181
|
+
interface Contact {
|
|
182
|
+
_id?: string;
|
|
183
|
+
workspaceId: string;
|
|
184
|
+
email: string;
|
|
185
|
+
firstName?: string;
|
|
186
|
+
lastName?: string;
|
|
187
|
+
company?: string;
|
|
188
|
+
jobTitle?: string;
|
|
189
|
+
phone?: string;
|
|
190
|
+
status?: 'lead' | 'contact' | 'customer';
|
|
191
|
+
lifecycleStage?: 'subscriber' | 'lead' | 'mql' | 'sql' | 'opportunity' | 'customer' | 'evangelist';
|
|
192
|
+
source?: string;
|
|
193
|
+
tags?: string[];
|
|
194
|
+
leadScore?: number;
|
|
195
|
+
customFields?: Record<string, unknown>;
|
|
196
|
+
companyId?: string;
|
|
197
|
+
assignedTo?: string;
|
|
198
|
+
createdAt?: string;
|
|
199
|
+
updatedAt?: string;
|
|
200
|
+
}
|
|
201
|
+
interface Company {
|
|
202
|
+
_id?: string;
|
|
203
|
+
workspaceId: string;
|
|
204
|
+
name: string;
|
|
205
|
+
industry?: string;
|
|
206
|
+
website?: string;
|
|
207
|
+
phone?: string;
|
|
208
|
+
address?: {
|
|
209
|
+
street?: string;
|
|
210
|
+
city?: string;
|
|
211
|
+
state?: string;
|
|
212
|
+
country?: string;
|
|
213
|
+
postalCode?: string;
|
|
214
|
+
};
|
|
215
|
+
companySize?: string;
|
|
216
|
+
annualRevenue?: number;
|
|
217
|
+
status?: 'prospect' | 'active' | 'inactive' | 'churned';
|
|
218
|
+
accountTier?: 'enterprise' | 'mid-market' | 'smb';
|
|
219
|
+
isTargetAccount?: boolean;
|
|
220
|
+
tags?: string[];
|
|
221
|
+
customFields?: Record<string, unknown>;
|
|
222
|
+
assignedTo?: string;
|
|
223
|
+
createdAt?: string;
|
|
224
|
+
updatedAt?: string;
|
|
225
|
+
}
|
|
226
|
+
interface Pipeline {
|
|
227
|
+
_id?: string;
|
|
228
|
+
workspaceId: string;
|
|
229
|
+
name: string;
|
|
230
|
+
description?: string;
|
|
231
|
+
stages: PipelineStage[];
|
|
232
|
+
isDefault?: boolean;
|
|
233
|
+
isActive?: boolean;
|
|
234
|
+
createdAt?: string;
|
|
235
|
+
updatedAt?: string;
|
|
236
|
+
}
|
|
237
|
+
interface PipelineStage {
|
|
238
|
+
_id?: string;
|
|
239
|
+
name: string;
|
|
240
|
+
order: number;
|
|
241
|
+
probability?: number;
|
|
242
|
+
color?: string;
|
|
243
|
+
rottenDays?: number;
|
|
244
|
+
}
|
|
245
|
+
interface Task {
|
|
246
|
+
_id?: string;
|
|
247
|
+
workspaceId: string;
|
|
248
|
+
title: string;
|
|
249
|
+
description?: string;
|
|
250
|
+
status?: 'pending' | 'in_progress' | 'completed' | 'cancelled';
|
|
251
|
+
priority?: 'low' | 'medium' | 'high' | 'urgent';
|
|
252
|
+
dueDate?: string;
|
|
253
|
+
reminderDate?: string;
|
|
254
|
+
completedAt?: string;
|
|
255
|
+
tags?: string[];
|
|
256
|
+
relatedContactId?: string;
|
|
257
|
+
relatedCompanyId?: string;
|
|
258
|
+
relatedOpportunityId?: string;
|
|
259
|
+
assignedTo?: string;
|
|
260
|
+
createdAt?: string;
|
|
261
|
+
updatedAt?: string;
|
|
262
|
+
}
|
|
263
|
+
interface Activity {
|
|
264
|
+
_id?: string;
|
|
265
|
+
workspaceId: string;
|
|
266
|
+
type: 'call' | 'email' | 'meeting' | 'note' | 'task' | 'other';
|
|
267
|
+
title: string;
|
|
268
|
+
description?: string;
|
|
269
|
+
direction?: 'inbound' | 'outbound';
|
|
270
|
+
duration?: number;
|
|
271
|
+
outcome?: string;
|
|
272
|
+
emailSubject?: string;
|
|
273
|
+
emailBody?: string;
|
|
274
|
+
metadata?: Record<string, unknown>;
|
|
275
|
+
contactId?: string;
|
|
276
|
+
companyId?: string;
|
|
277
|
+
opportunityId?: string;
|
|
278
|
+
userId?: string;
|
|
279
|
+
createdAt?: string;
|
|
280
|
+
updatedAt?: string;
|
|
281
|
+
}
|
|
282
|
+
interface Opportunity {
|
|
283
|
+
_id?: string;
|
|
284
|
+
workspaceId: string;
|
|
285
|
+
contactId: string;
|
|
286
|
+
companyId?: string;
|
|
287
|
+
pipelineId: string;
|
|
288
|
+
stageId: string;
|
|
289
|
+
title: string;
|
|
290
|
+
value?: number;
|
|
291
|
+
currency?: string;
|
|
292
|
+
probability?: number;
|
|
293
|
+
expectedCloseDate?: string;
|
|
294
|
+
status?: 'open' | 'won' | 'lost';
|
|
295
|
+
priority?: 'low' | 'medium' | 'high';
|
|
296
|
+
lostReason?: string;
|
|
297
|
+
customFields?: Record<string, unknown>;
|
|
298
|
+
assignedTo?: string;
|
|
299
|
+
createdAt?: string;
|
|
300
|
+
updatedAt?: string;
|
|
301
|
+
}
|
|
302
|
+
interface ApiResponse<T> {
|
|
303
|
+
success: boolean;
|
|
304
|
+
data?: T;
|
|
305
|
+
error?: string;
|
|
306
|
+
status: number;
|
|
307
|
+
}
|
|
308
|
+
interface PaginatedResponse<T> {
|
|
309
|
+
data: T[];
|
|
310
|
+
pagination: {
|
|
311
|
+
page: number;
|
|
312
|
+
limit: number;
|
|
313
|
+
total: number;
|
|
314
|
+
pages: number;
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
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';
|
|
318
|
+
interface TriggerCondition {
|
|
319
|
+
/**
|
|
320
|
+
* Field to check - supports dynamic field names including custom fields
|
|
321
|
+
* Examples: 'status', 'lifecycleStage', 'leadScore', 'customFields.industry'
|
|
322
|
+
* Use dot notation for nested fields: 'contact.email', 'customFields.accountType'
|
|
323
|
+
*/
|
|
324
|
+
field: string;
|
|
325
|
+
/** Operator for comparison */
|
|
326
|
+
operator: 'equals' | 'not_equals' | 'contains' | 'greater_than' | 'less_than' | 'in' | 'not_in';
|
|
327
|
+
/** Value to compare against */
|
|
328
|
+
value: unknown;
|
|
329
|
+
}
|
|
330
|
+
interface EmailTemplate {
|
|
331
|
+
/** Template ID */
|
|
332
|
+
_id?: string;
|
|
333
|
+
/** Template name */
|
|
334
|
+
name: string;
|
|
335
|
+
/** Email subject line (supports variables) */
|
|
336
|
+
subject: string;
|
|
337
|
+
/** Email body (supports HTML and variables) */
|
|
338
|
+
body: string;
|
|
339
|
+
/** Variables available in this template */
|
|
340
|
+
variables?: string[];
|
|
341
|
+
/** Sender email address */
|
|
342
|
+
fromEmail?: string;
|
|
343
|
+
/** Sender name */
|
|
344
|
+
fromName?: string;
|
|
345
|
+
}
|
|
346
|
+
interface EmailAction {
|
|
347
|
+
/** Action type identifier */
|
|
348
|
+
type: 'send_email';
|
|
349
|
+
/** Email template ID or inline template */
|
|
350
|
+
templateId?: string;
|
|
351
|
+
/** Inline email subject (if not using template) */
|
|
352
|
+
subject?: string;
|
|
353
|
+
/** Inline email body (if not using template) */
|
|
354
|
+
body?: string;
|
|
355
|
+
/** Recipient email (supports variables like {{contact.email}}) */
|
|
356
|
+
to: string;
|
|
357
|
+
/** CC recipients */
|
|
358
|
+
cc?: string[];
|
|
359
|
+
/** BCC recipients */
|
|
360
|
+
bcc?: string[];
|
|
361
|
+
/** Sender email */
|
|
362
|
+
from?: string;
|
|
363
|
+
/** Delay in minutes before sending */
|
|
364
|
+
delayMinutes?: number;
|
|
365
|
+
}
|
|
366
|
+
interface WebhookAction {
|
|
367
|
+
/** Action type identifier */
|
|
368
|
+
type: 'webhook';
|
|
369
|
+
/** Webhook URL to call */
|
|
370
|
+
url: string;
|
|
371
|
+
/** HTTP method */
|
|
372
|
+
method: 'POST' | 'PUT' | 'PATCH';
|
|
373
|
+
/** Custom headers */
|
|
374
|
+
headers?: Record<string, string>;
|
|
375
|
+
/** Request body template (supports variables) */
|
|
376
|
+
body?: string;
|
|
377
|
+
}
|
|
378
|
+
interface TaskAction {
|
|
379
|
+
/** Action type identifier */
|
|
380
|
+
type: 'create_task';
|
|
381
|
+
/** Task title (supports variables) */
|
|
382
|
+
title: string;
|
|
383
|
+
/** Task description */
|
|
384
|
+
description?: string;
|
|
385
|
+
/** Task priority */
|
|
386
|
+
priority?: 'low' | 'medium' | 'high' | 'urgent';
|
|
387
|
+
/** Due date in days from trigger */
|
|
388
|
+
dueDays?: number;
|
|
389
|
+
/** Assign to user ID */
|
|
390
|
+
assignedTo?: string;
|
|
391
|
+
}
|
|
392
|
+
interface ContactUpdateAction {
|
|
393
|
+
/** Action type identifier */
|
|
394
|
+
type: 'update_contact';
|
|
395
|
+
/** Fields to update */
|
|
396
|
+
updates: Partial<Contact>;
|
|
397
|
+
}
|
|
398
|
+
type TriggerAction = EmailAction | WebhookAction | TaskAction | ContactUpdateAction;
|
|
399
|
+
interface EventTrigger {
|
|
400
|
+
/** Trigger ID */
|
|
401
|
+
_id?: string;
|
|
402
|
+
/** Workspace ID */
|
|
403
|
+
workspaceId: string;
|
|
404
|
+
/** Trigger name */
|
|
405
|
+
name: string;
|
|
406
|
+
/** Description of what this trigger does */
|
|
407
|
+
description?: string;
|
|
408
|
+
/** Event type that activates this trigger */
|
|
409
|
+
eventType: TriggerEventType;
|
|
410
|
+
/** Conditions that must be met for trigger to fire */
|
|
411
|
+
conditions?: TriggerCondition[];
|
|
412
|
+
/** Actions to execute when trigger fires */
|
|
413
|
+
actions: TriggerAction[];
|
|
414
|
+
/** Whether this trigger is active */
|
|
415
|
+
isActive?: boolean;
|
|
416
|
+
/** Created timestamp */
|
|
417
|
+
createdAt?: string;
|
|
418
|
+
/** Updated timestamp */
|
|
419
|
+
updatedAt?: string;
|
|
420
|
+
}
|
|
178
421
|
interface PublicContactData {
|
|
179
422
|
email: string;
|
|
180
423
|
firstName?: string;
|
|
@@ -526,6 +769,583 @@ interface StoredConsent {
|
|
|
526
769
|
/** SDK Version */
|
|
527
770
|
declare const SDK_VERSION = "1.7.2";
|
|
528
771
|
|
|
772
|
+
/**
|
|
773
|
+
* Clianta SDK - Event Triggers Manager
|
|
774
|
+
* Manages event-driven automation and email notifications
|
|
775
|
+
*/
|
|
776
|
+
|
|
777
|
+
/**
|
|
778
|
+
* Event Triggers Manager
|
|
779
|
+
* Handles event-driven automation based on CRM actions
|
|
780
|
+
*
|
|
781
|
+
* Similar to:
|
|
782
|
+
* - Salesforce: Process Builder, Flow Automation
|
|
783
|
+
* - HubSpot: Workflows, Email Sequences
|
|
784
|
+
* - Pipedrive: Workflow Automation
|
|
785
|
+
*/
|
|
786
|
+
declare class EventTriggersManager {
|
|
787
|
+
private apiEndpoint;
|
|
788
|
+
private workspaceId;
|
|
789
|
+
private authToken?;
|
|
790
|
+
private triggers;
|
|
791
|
+
private listeners;
|
|
792
|
+
constructor(apiEndpoint: string, workspaceId: string, authToken?: string);
|
|
793
|
+
/**
|
|
794
|
+
* Set authentication token
|
|
795
|
+
*/
|
|
796
|
+
setAuthToken(token: string): void;
|
|
797
|
+
/**
|
|
798
|
+
* Make authenticated API request
|
|
799
|
+
*/
|
|
800
|
+
private request;
|
|
801
|
+
/**
|
|
802
|
+
* Get all event triggers
|
|
803
|
+
*/
|
|
804
|
+
getTriggers(): Promise<ApiResponse<EventTrigger[]>>;
|
|
805
|
+
/**
|
|
806
|
+
* Get a single trigger by ID
|
|
807
|
+
*/
|
|
808
|
+
getTrigger(triggerId: string): Promise<ApiResponse<EventTrigger>>;
|
|
809
|
+
/**
|
|
810
|
+
* Create a new event trigger
|
|
811
|
+
*/
|
|
812
|
+
createTrigger(trigger: Partial<EventTrigger>): Promise<ApiResponse<EventTrigger>>;
|
|
813
|
+
/**
|
|
814
|
+
* Update an existing trigger
|
|
815
|
+
*/
|
|
816
|
+
updateTrigger(triggerId: string, updates: Partial<EventTrigger>): Promise<ApiResponse<EventTrigger>>;
|
|
817
|
+
/**
|
|
818
|
+
* Delete a trigger
|
|
819
|
+
*/
|
|
820
|
+
deleteTrigger(triggerId: string): Promise<ApiResponse<void>>;
|
|
821
|
+
/**
|
|
822
|
+
* Activate a trigger
|
|
823
|
+
*/
|
|
824
|
+
activateTrigger(triggerId: string): Promise<ApiResponse<EventTrigger>>;
|
|
825
|
+
/**
|
|
826
|
+
* Deactivate a trigger
|
|
827
|
+
*/
|
|
828
|
+
deactivateTrigger(triggerId: string): Promise<ApiResponse<EventTrigger>>;
|
|
829
|
+
/**
|
|
830
|
+
* Register a local event listener for client-side triggers
|
|
831
|
+
* This allows immediate client-side reactions to events
|
|
832
|
+
*/
|
|
833
|
+
on(eventType: TriggerEventType, callback: (data: unknown) => void): void;
|
|
834
|
+
/**
|
|
835
|
+
* Remove an event listener
|
|
836
|
+
*/
|
|
837
|
+
off(eventType: TriggerEventType, callback: (data: unknown) => void): void;
|
|
838
|
+
/**
|
|
839
|
+
* Emit an event (client-side only)
|
|
840
|
+
* This will trigger any registered local listeners
|
|
841
|
+
*/
|
|
842
|
+
emit(eventType: TriggerEventType, data: unknown): void;
|
|
843
|
+
/**
|
|
844
|
+
* Check if conditions are met for a trigger
|
|
845
|
+
* Supports dynamic field evaluation including custom fields and nested paths
|
|
846
|
+
*/
|
|
847
|
+
private evaluateConditions;
|
|
848
|
+
/**
|
|
849
|
+
* Execute actions for a triggered event (client-side preview)
|
|
850
|
+
* Note: Actual execution happens on the backend
|
|
851
|
+
*/
|
|
852
|
+
executeActions(trigger: EventTrigger, data: Record<string, unknown>): Promise<void>;
|
|
853
|
+
/**
|
|
854
|
+
* Execute a single action
|
|
855
|
+
*/
|
|
856
|
+
private executeAction;
|
|
857
|
+
/**
|
|
858
|
+
* Execute send email action (via backend API)
|
|
859
|
+
*/
|
|
860
|
+
private executeSendEmail;
|
|
861
|
+
/**
|
|
862
|
+
* Execute webhook action
|
|
863
|
+
*/
|
|
864
|
+
private executeWebhook;
|
|
865
|
+
/**
|
|
866
|
+
* Execute create task action
|
|
867
|
+
*/
|
|
868
|
+
private executeCreateTask;
|
|
869
|
+
/**
|
|
870
|
+
* Execute update contact action
|
|
871
|
+
*/
|
|
872
|
+
private executeUpdateContact;
|
|
873
|
+
/**
|
|
874
|
+
* Replace variables in a string template
|
|
875
|
+
* Supports syntax like {{contact.email}}, {{opportunity.value}}
|
|
876
|
+
*/
|
|
877
|
+
private replaceVariables;
|
|
878
|
+
/**
|
|
879
|
+
* Get nested value from object using dot notation
|
|
880
|
+
* Supports dynamic field access including custom fields
|
|
881
|
+
*/
|
|
882
|
+
private getNestedValue;
|
|
883
|
+
/**
|
|
884
|
+
* Extract all available field paths from a data object
|
|
885
|
+
* Useful for dynamic field discovery based on platform-specific attributes
|
|
886
|
+
* @param obj - The data object to extract fields from
|
|
887
|
+
* @param prefix - Internal use for nested paths
|
|
888
|
+
* @param maxDepth - Maximum depth to traverse (default: 3)
|
|
889
|
+
* @returns Array of field paths (e.g., ['email', 'contact.firstName', 'customFields.industry'])
|
|
890
|
+
*/
|
|
891
|
+
private extractAvailableFields;
|
|
892
|
+
/**
|
|
893
|
+
* Get available fields from sample data
|
|
894
|
+
* Helps with dynamic field detection for platform-specific attributes
|
|
895
|
+
* @param sampleData - Sample data object to analyze
|
|
896
|
+
* @returns Array of available field paths
|
|
897
|
+
*/
|
|
898
|
+
getAvailableFields(sampleData: Record<string, unknown>): string[];
|
|
899
|
+
/**
|
|
900
|
+
* Create a simple email trigger
|
|
901
|
+
* Helper method for common use case
|
|
902
|
+
*/
|
|
903
|
+
createEmailTrigger(config: {
|
|
904
|
+
name: string;
|
|
905
|
+
eventType: TriggerEventType;
|
|
906
|
+
to: string;
|
|
907
|
+
subject: string;
|
|
908
|
+
body: string;
|
|
909
|
+
conditions?: TriggerCondition[];
|
|
910
|
+
}): Promise<ApiResponse<EventTrigger>>;
|
|
911
|
+
/**
|
|
912
|
+
* Create a task creation trigger
|
|
913
|
+
*/
|
|
914
|
+
createTaskTrigger(config: {
|
|
915
|
+
name: string;
|
|
916
|
+
eventType: TriggerEventType;
|
|
917
|
+
taskTitle: string;
|
|
918
|
+
taskDescription?: string;
|
|
919
|
+
priority?: 'low' | 'medium' | 'high' | 'urgent';
|
|
920
|
+
dueDays?: number;
|
|
921
|
+
conditions?: TriggerCondition[];
|
|
922
|
+
}): Promise<ApiResponse<EventTrigger>>;
|
|
923
|
+
/**
|
|
924
|
+
* Create a webhook trigger
|
|
925
|
+
*/
|
|
926
|
+
createWebhookTrigger(config: {
|
|
927
|
+
name: string;
|
|
928
|
+
eventType: TriggerEventType;
|
|
929
|
+
webhookUrl: string;
|
|
930
|
+
method?: 'POST' | 'PUT' | 'PATCH';
|
|
931
|
+
conditions?: TriggerCondition[];
|
|
932
|
+
}): Promise<ApiResponse<EventTrigger>>;
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
/**
|
|
936
|
+
* Clianta SDK - CRM API Client
|
|
937
|
+
* @see SDK_VERSION in core/config.ts
|
|
938
|
+
*/
|
|
939
|
+
|
|
940
|
+
type InboundEventType = 'user.registered' | 'user.updated' | 'user.subscribed' | 'user.unsubscribed' | 'contact.created' | 'contact.updated' | 'purchase.completed';
|
|
941
|
+
interface InboundEventPayload {
|
|
942
|
+
/** Event type (e.g. "user.registered") */
|
|
943
|
+
event: InboundEventType;
|
|
944
|
+
/** Contact data — at least email or phone is required */
|
|
945
|
+
contact: {
|
|
946
|
+
email?: string;
|
|
947
|
+
phone?: string;
|
|
948
|
+
firstName?: string;
|
|
949
|
+
lastName?: string;
|
|
950
|
+
company?: string;
|
|
951
|
+
jobTitle?: string;
|
|
952
|
+
tags?: string[];
|
|
953
|
+
};
|
|
954
|
+
/** Optional extra data stored as customFields on the contact */
|
|
955
|
+
data?: Record<string, unknown>;
|
|
956
|
+
}
|
|
957
|
+
interface InboundEventResult {
|
|
958
|
+
success: boolean;
|
|
959
|
+
contactCreated: boolean;
|
|
960
|
+
contactId?: string;
|
|
961
|
+
event: string;
|
|
962
|
+
error?: string;
|
|
963
|
+
}
|
|
964
|
+
/**
|
|
965
|
+
* CRM API Client for managing contacts and opportunities
|
|
966
|
+
*/
|
|
967
|
+
declare class CRMClient {
|
|
968
|
+
private apiEndpoint;
|
|
969
|
+
private workspaceId;
|
|
970
|
+
private authToken?;
|
|
971
|
+
private apiKey?;
|
|
972
|
+
triggers: EventTriggersManager;
|
|
973
|
+
constructor(apiEndpoint: string, workspaceId: string, authToken?: string, apiKey?: string);
|
|
974
|
+
/**
|
|
975
|
+
* Set authentication token for API requests (user JWT)
|
|
976
|
+
*/
|
|
977
|
+
setAuthToken(token: string): void;
|
|
978
|
+
/**
|
|
979
|
+
* Set workspace API key for server-to-server requests.
|
|
980
|
+
* Use this instead of setAuthToken when integrating from an external app.
|
|
981
|
+
*/
|
|
982
|
+
setApiKey(key: string): void;
|
|
983
|
+
/**
|
|
984
|
+
* Validate required parameter exists
|
|
985
|
+
* @throws {Error} if value is null/undefined or empty string
|
|
986
|
+
*/
|
|
987
|
+
private validateRequired;
|
|
988
|
+
/**
|
|
989
|
+
* Make authenticated API request
|
|
990
|
+
*/
|
|
991
|
+
private request;
|
|
992
|
+
/**
|
|
993
|
+
* Send an inbound event from an external app (e.g. user signup on client website).
|
|
994
|
+
* Requires the client to be initialized with an API key via setApiKey() or the constructor.
|
|
995
|
+
*
|
|
996
|
+
* The contact is upserted in the CRM and matching workflow automations fire automatically.
|
|
997
|
+
*
|
|
998
|
+
* @example
|
|
999
|
+
* const crm = new CRMClient('http://localhost:5000', 'WORKSPACE_ID');
|
|
1000
|
+
* crm.setApiKey('mm_live_...');
|
|
1001
|
+
*
|
|
1002
|
+
* await crm.sendEvent({
|
|
1003
|
+
* event: 'user.registered',
|
|
1004
|
+
* contact: { email: 'alice@example.com', firstName: 'Alice' },
|
|
1005
|
+
* data: { plan: 'free', signupSource: 'homepage' },
|
|
1006
|
+
* });
|
|
1007
|
+
*/
|
|
1008
|
+
sendEvent(payload: InboundEventPayload): Promise<InboundEventResult>;
|
|
1009
|
+
/**
|
|
1010
|
+
* Get all contacts with pagination
|
|
1011
|
+
*/
|
|
1012
|
+
getContacts(params?: {
|
|
1013
|
+
page?: number;
|
|
1014
|
+
limit?: number;
|
|
1015
|
+
search?: string;
|
|
1016
|
+
status?: string;
|
|
1017
|
+
}): Promise<ApiResponse<PaginatedResponse<Contact>>>;
|
|
1018
|
+
/**
|
|
1019
|
+
* Get a single contact by ID
|
|
1020
|
+
*/
|
|
1021
|
+
getContact(contactId: string): Promise<ApiResponse<Contact>>;
|
|
1022
|
+
/**
|
|
1023
|
+
* Create a new contact
|
|
1024
|
+
*/
|
|
1025
|
+
createContact(contact: Partial<Contact>): Promise<ApiResponse<Contact>>;
|
|
1026
|
+
/**
|
|
1027
|
+
* Update an existing contact
|
|
1028
|
+
*/
|
|
1029
|
+
updateContact(contactId: string, updates: Partial<Contact>): Promise<ApiResponse<Contact>>;
|
|
1030
|
+
/**
|
|
1031
|
+
* Delete a contact
|
|
1032
|
+
*/
|
|
1033
|
+
deleteContact(contactId: string): Promise<ApiResponse<void>>;
|
|
1034
|
+
/**
|
|
1035
|
+
* Get all opportunities with pagination
|
|
1036
|
+
*/
|
|
1037
|
+
getOpportunities(params?: {
|
|
1038
|
+
page?: number;
|
|
1039
|
+
limit?: number;
|
|
1040
|
+
pipelineId?: string;
|
|
1041
|
+
stageId?: string;
|
|
1042
|
+
}): Promise<ApiResponse<PaginatedResponse<Opportunity>>>;
|
|
1043
|
+
/**
|
|
1044
|
+
* Get a single opportunity by ID
|
|
1045
|
+
*/
|
|
1046
|
+
getOpportunity(opportunityId: string): Promise<ApiResponse<Opportunity>>;
|
|
1047
|
+
/**
|
|
1048
|
+
* Create a new opportunity
|
|
1049
|
+
*/
|
|
1050
|
+
createOpportunity(opportunity: Partial<Opportunity>): Promise<ApiResponse<Opportunity>>;
|
|
1051
|
+
/**
|
|
1052
|
+
* Update an existing opportunity
|
|
1053
|
+
*/
|
|
1054
|
+
updateOpportunity(opportunityId: string, updates: Partial<Opportunity>): Promise<ApiResponse<Opportunity>>;
|
|
1055
|
+
/**
|
|
1056
|
+
* Delete an opportunity
|
|
1057
|
+
*/
|
|
1058
|
+
deleteOpportunity(opportunityId: string): Promise<ApiResponse<void>>;
|
|
1059
|
+
/**
|
|
1060
|
+
* Move opportunity to a different stage
|
|
1061
|
+
*/
|
|
1062
|
+
moveOpportunity(opportunityId: string, stageId: string): Promise<ApiResponse<Opportunity>>;
|
|
1063
|
+
/**
|
|
1064
|
+
* Get all companies with pagination
|
|
1065
|
+
*/
|
|
1066
|
+
getCompanies(params?: {
|
|
1067
|
+
page?: number;
|
|
1068
|
+
limit?: number;
|
|
1069
|
+
search?: string;
|
|
1070
|
+
status?: string;
|
|
1071
|
+
industry?: string;
|
|
1072
|
+
}): Promise<ApiResponse<PaginatedResponse<Company>>>;
|
|
1073
|
+
/**
|
|
1074
|
+
* Get a single company by ID
|
|
1075
|
+
*/
|
|
1076
|
+
getCompany(companyId: string): Promise<ApiResponse<Company>>;
|
|
1077
|
+
/**
|
|
1078
|
+
* Create a new company
|
|
1079
|
+
*/
|
|
1080
|
+
createCompany(company: Partial<Company>): Promise<ApiResponse<Company>>;
|
|
1081
|
+
/**
|
|
1082
|
+
* Update an existing company
|
|
1083
|
+
*/
|
|
1084
|
+
updateCompany(companyId: string, updates: Partial<Company>): Promise<ApiResponse<Company>>;
|
|
1085
|
+
/**
|
|
1086
|
+
* Delete a company
|
|
1087
|
+
*/
|
|
1088
|
+
deleteCompany(companyId: string): Promise<ApiResponse<void>>;
|
|
1089
|
+
/**
|
|
1090
|
+
* Get contacts belonging to a company
|
|
1091
|
+
*/
|
|
1092
|
+
getCompanyContacts(companyId: string, params?: {
|
|
1093
|
+
page?: number;
|
|
1094
|
+
limit?: number;
|
|
1095
|
+
}): Promise<ApiResponse<PaginatedResponse<Contact>>>;
|
|
1096
|
+
/**
|
|
1097
|
+
* Get deals/opportunities belonging to a company
|
|
1098
|
+
*/
|
|
1099
|
+
getCompanyDeals(companyId: string, params?: {
|
|
1100
|
+
page?: number;
|
|
1101
|
+
limit?: number;
|
|
1102
|
+
}): Promise<ApiResponse<PaginatedResponse<Opportunity>>>;
|
|
1103
|
+
/**
|
|
1104
|
+
* Get all pipelines
|
|
1105
|
+
*/
|
|
1106
|
+
getPipelines(): Promise<ApiResponse<Pipeline[]>>;
|
|
1107
|
+
/**
|
|
1108
|
+
* Get a single pipeline by ID
|
|
1109
|
+
*/
|
|
1110
|
+
getPipeline(pipelineId: string): Promise<ApiResponse<Pipeline>>;
|
|
1111
|
+
/**
|
|
1112
|
+
* Create a new pipeline
|
|
1113
|
+
*/
|
|
1114
|
+
createPipeline(pipeline: Partial<Pipeline>): Promise<ApiResponse<Pipeline>>;
|
|
1115
|
+
/**
|
|
1116
|
+
* Update an existing pipeline
|
|
1117
|
+
*/
|
|
1118
|
+
updatePipeline(pipelineId: string, updates: Partial<Pipeline>): Promise<ApiResponse<Pipeline>>;
|
|
1119
|
+
/**
|
|
1120
|
+
* Delete a pipeline
|
|
1121
|
+
*/
|
|
1122
|
+
deletePipeline(pipelineId: string): Promise<ApiResponse<void>>;
|
|
1123
|
+
/**
|
|
1124
|
+
* Get all tasks with pagination
|
|
1125
|
+
*/
|
|
1126
|
+
getTasks(params?: {
|
|
1127
|
+
page?: number;
|
|
1128
|
+
limit?: number;
|
|
1129
|
+
status?: string;
|
|
1130
|
+
priority?: string;
|
|
1131
|
+
contactId?: string;
|
|
1132
|
+
companyId?: string;
|
|
1133
|
+
opportunityId?: string;
|
|
1134
|
+
}): Promise<ApiResponse<PaginatedResponse<Task>>>;
|
|
1135
|
+
/**
|
|
1136
|
+
* Get a single task by ID
|
|
1137
|
+
*/
|
|
1138
|
+
getTask(taskId: string): Promise<ApiResponse<Task>>;
|
|
1139
|
+
/**
|
|
1140
|
+
* Create a new task
|
|
1141
|
+
*/
|
|
1142
|
+
createTask(task: Partial<Task>): Promise<ApiResponse<Task>>;
|
|
1143
|
+
/**
|
|
1144
|
+
* Update an existing task
|
|
1145
|
+
*/
|
|
1146
|
+
updateTask(taskId: string, updates: Partial<Task>): Promise<ApiResponse<Task>>;
|
|
1147
|
+
/**
|
|
1148
|
+
* Mark a task as completed
|
|
1149
|
+
*/
|
|
1150
|
+
completeTask(taskId: string): Promise<ApiResponse<Task>>;
|
|
1151
|
+
/**
|
|
1152
|
+
* Delete a task
|
|
1153
|
+
*/
|
|
1154
|
+
deleteTask(taskId: string): Promise<ApiResponse<void>>;
|
|
1155
|
+
/**
|
|
1156
|
+
* Get activities for a contact
|
|
1157
|
+
*/
|
|
1158
|
+
getContactActivities(contactId: string, params?: {
|
|
1159
|
+
page?: number;
|
|
1160
|
+
limit?: number;
|
|
1161
|
+
type?: string;
|
|
1162
|
+
}): Promise<ApiResponse<PaginatedResponse<Activity>>>;
|
|
1163
|
+
/**
|
|
1164
|
+
* Get activities for an opportunity/deal
|
|
1165
|
+
*/
|
|
1166
|
+
getOpportunityActivities(opportunityId: string, params?: {
|
|
1167
|
+
page?: number;
|
|
1168
|
+
limit?: number;
|
|
1169
|
+
type?: string;
|
|
1170
|
+
}): Promise<ApiResponse<PaginatedResponse<Activity>>>;
|
|
1171
|
+
/**
|
|
1172
|
+
* Create a new activity
|
|
1173
|
+
*/
|
|
1174
|
+
createActivity(activity: Partial<Activity>): Promise<ApiResponse<Activity>>;
|
|
1175
|
+
/**
|
|
1176
|
+
* Update an existing activity
|
|
1177
|
+
*/
|
|
1178
|
+
updateActivity(activityId: string, updates: Partial<Activity>): Promise<ApiResponse<Activity>>;
|
|
1179
|
+
/**
|
|
1180
|
+
* Delete an activity
|
|
1181
|
+
*/
|
|
1182
|
+
deleteActivity(activityId: string): Promise<ApiResponse<void>>;
|
|
1183
|
+
/**
|
|
1184
|
+
* Log a call activity
|
|
1185
|
+
*/
|
|
1186
|
+
logCall(data: {
|
|
1187
|
+
contactId?: string;
|
|
1188
|
+
opportunityId?: string;
|
|
1189
|
+
direction: 'inbound' | 'outbound';
|
|
1190
|
+
duration?: number;
|
|
1191
|
+
outcome?: string;
|
|
1192
|
+
notes?: string;
|
|
1193
|
+
}): Promise<ApiResponse<Activity>>;
|
|
1194
|
+
/**
|
|
1195
|
+
* Log a meeting activity
|
|
1196
|
+
*/
|
|
1197
|
+
logMeeting(data: {
|
|
1198
|
+
contactId?: string;
|
|
1199
|
+
opportunityId?: string;
|
|
1200
|
+
title: string;
|
|
1201
|
+
duration?: number;
|
|
1202
|
+
outcome?: string;
|
|
1203
|
+
notes?: string;
|
|
1204
|
+
}): Promise<ApiResponse<Activity>>;
|
|
1205
|
+
/**
|
|
1206
|
+
* Add a note to a contact or opportunity
|
|
1207
|
+
*/
|
|
1208
|
+
addNote(data: {
|
|
1209
|
+
contactId?: string;
|
|
1210
|
+
opportunityId?: string;
|
|
1211
|
+
content: string;
|
|
1212
|
+
}): Promise<ApiResponse<Activity>>;
|
|
1213
|
+
/**
|
|
1214
|
+
* Get all email templates
|
|
1215
|
+
*/
|
|
1216
|
+
getEmailTemplates(params?: {
|
|
1217
|
+
page?: number;
|
|
1218
|
+
limit?: number;
|
|
1219
|
+
}): Promise<ApiResponse<PaginatedResponse<EmailTemplate>>>;
|
|
1220
|
+
/**
|
|
1221
|
+
* Get a single email template by ID
|
|
1222
|
+
*/
|
|
1223
|
+
getEmailTemplate(templateId: string): Promise<ApiResponse<EmailTemplate>>;
|
|
1224
|
+
/**
|
|
1225
|
+
* Create a new email template
|
|
1226
|
+
*/
|
|
1227
|
+
createEmailTemplate(template: Partial<EmailTemplate>): Promise<ApiResponse<EmailTemplate>>;
|
|
1228
|
+
/**
|
|
1229
|
+
* Update an email template
|
|
1230
|
+
*/
|
|
1231
|
+
updateEmailTemplate(templateId: string, updates: Partial<EmailTemplate>): Promise<ApiResponse<EmailTemplate>>;
|
|
1232
|
+
/**
|
|
1233
|
+
* Delete an email template
|
|
1234
|
+
*/
|
|
1235
|
+
deleteEmailTemplate(templateId: string): Promise<ApiResponse<void>>;
|
|
1236
|
+
/**
|
|
1237
|
+
* Send an email using a template
|
|
1238
|
+
*/
|
|
1239
|
+
sendEmail(data: {
|
|
1240
|
+
to: string;
|
|
1241
|
+
templateId?: string;
|
|
1242
|
+
subject?: string;
|
|
1243
|
+
body?: string;
|
|
1244
|
+
cc?: string[];
|
|
1245
|
+
bcc?: string[];
|
|
1246
|
+
variables?: Record<string, unknown>;
|
|
1247
|
+
contactId?: string;
|
|
1248
|
+
}): Promise<ApiResponse<{
|
|
1249
|
+
messageId: string;
|
|
1250
|
+
}>>;
|
|
1251
|
+
/**
|
|
1252
|
+
* Get a contact by email address.
|
|
1253
|
+
* Returns the first matching contact from a search query.
|
|
1254
|
+
*/
|
|
1255
|
+
getContactByEmail(email: string): Promise<ApiResponse<PaginatedResponse<Contact>>>;
|
|
1256
|
+
/**
|
|
1257
|
+
* Get activity timeline for a contact
|
|
1258
|
+
*/
|
|
1259
|
+
getContactActivity(contactId: string, params?: {
|
|
1260
|
+
page?: number;
|
|
1261
|
+
limit?: number;
|
|
1262
|
+
type?: string;
|
|
1263
|
+
startDate?: string;
|
|
1264
|
+
endDate?: string;
|
|
1265
|
+
}): Promise<ApiResponse<PaginatedResponse<Activity>>>;
|
|
1266
|
+
/**
|
|
1267
|
+
* Get engagement metrics for a contact (via their linked visitor data)
|
|
1268
|
+
*/
|
|
1269
|
+
getContactEngagement(contactId: string): Promise<ApiResponse<{
|
|
1270
|
+
totalTimeOnSiteSeconds: number;
|
|
1271
|
+
averageSessionDurationSeconds: number;
|
|
1272
|
+
totalPageViews: number;
|
|
1273
|
+
totalSessions: number;
|
|
1274
|
+
engagementScore: number;
|
|
1275
|
+
lastActiveAt: string;
|
|
1276
|
+
}>>;
|
|
1277
|
+
/**
|
|
1278
|
+
* Get a full timeline for a contact including events, activities, and opportunities
|
|
1279
|
+
*/
|
|
1280
|
+
getContactTimeline(contactId: string, params?: {
|
|
1281
|
+
page?: number;
|
|
1282
|
+
limit?: number;
|
|
1283
|
+
}): Promise<ApiResponse<PaginatedResponse<{
|
|
1284
|
+
type: 'event' | 'activity' | 'opportunity' | 'note';
|
|
1285
|
+
title: string;
|
|
1286
|
+
description?: string;
|
|
1287
|
+
timestamp: string;
|
|
1288
|
+
metadata?: Record<string, unknown>;
|
|
1289
|
+
}>>>;
|
|
1290
|
+
/**
|
|
1291
|
+
* Search contacts with advanced filters
|
|
1292
|
+
*/
|
|
1293
|
+
searchContacts(query: string, filters?: {
|
|
1294
|
+
status?: string;
|
|
1295
|
+
lifecycleStage?: string;
|
|
1296
|
+
source?: string;
|
|
1297
|
+
tags?: string[];
|
|
1298
|
+
page?: number;
|
|
1299
|
+
limit?: number;
|
|
1300
|
+
}): Promise<ApiResponse<PaginatedResponse<Contact>>>;
|
|
1301
|
+
/**
|
|
1302
|
+
* List all webhook subscriptions
|
|
1303
|
+
*/
|
|
1304
|
+
listWebhooks(params?: {
|
|
1305
|
+
page?: number;
|
|
1306
|
+
limit?: number;
|
|
1307
|
+
}): Promise<ApiResponse<PaginatedResponse<{
|
|
1308
|
+
_id: string;
|
|
1309
|
+
url: string;
|
|
1310
|
+
events: string[];
|
|
1311
|
+
isActive: boolean;
|
|
1312
|
+
createdAt: string;
|
|
1313
|
+
}>>>;
|
|
1314
|
+
/**
|
|
1315
|
+
* Create a new webhook subscription
|
|
1316
|
+
*/
|
|
1317
|
+
createWebhook(data: {
|
|
1318
|
+
url: string;
|
|
1319
|
+
events: string[];
|
|
1320
|
+
secret?: string;
|
|
1321
|
+
}): Promise<ApiResponse<{
|
|
1322
|
+
_id: string;
|
|
1323
|
+
url: string;
|
|
1324
|
+
events: string[];
|
|
1325
|
+
isActive: boolean;
|
|
1326
|
+
}>>;
|
|
1327
|
+
/**
|
|
1328
|
+
* Delete a webhook subscription
|
|
1329
|
+
*/
|
|
1330
|
+
deleteWebhook(webhookId: string): Promise<ApiResponse<void>>;
|
|
1331
|
+
/**
|
|
1332
|
+
* Get all event triggers
|
|
1333
|
+
*/
|
|
1334
|
+
getEventTriggers(): Promise<ApiResponse<EventTrigger[]>>;
|
|
1335
|
+
/**
|
|
1336
|
+
* Create a new event trigger
|
|
1337
|
+
*/
|
|
1338
|
+
createEventTrigger(trigger: Partial<EventTrigger>): Promise<ApiResponse<EventTrigger>>;
|
|
1339
|
+
/**
|
|
1340
|
+
* Update an event trigger
|
|
1341
|
+
*/
|
|
1342
|
+
updateEventTrigger(triggerId: string, updates: Partial<EventTrigger>): Promise<ApiResponse<EventTrigger>>;
|
|
1343
|
+
/**
|
|
1344
|
+
* Delete an event trigger
|
|
1345
|
+
*/
|
|
1346
|
+
deleteEventTrigger(triggerId: string): Promise<ApiResponse<void>>;
|
|
1347
|
+
}
|
|
1348
|
+
|
|
529
1349
|
/**
|
|
530
1350
|
* Clianta SDK
|
|
531
1351
|
* Client-side tracking SDK for CRM — tracks visitors, identifies contacts,
|
|
@@ -563,5 +1383,5 @@ declare const SDK_VERSION = "1.7.2";
|
|
|
563
1383
|
*/
|
|
564
1384
|
declare function clianta(workspaceId: string, config?: CliantaConfig): TrackerCore;
|
|
565
1385
|
|
|
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 };
|
|
1386
|
+
export { CRMClient, ConsentManager, SDK_VERSION, Tracker, clianta, clianta as default };
|
|
1387
|
+
export type { CliantaConfig, ConsentChangeCallback, ConsentConfig, ConsentManagerConfig, ConsentState, EventType, GroupTraits, InboundEventPayload, InboundEventResult, InboundEventType, MiddlewareFn, Plugin, PluginName, PublicActivityData, PublicContactData, PublicContactUpdate, PublicCrmResult, PublicFormSubmission, PublicOpportunityData, StoredConsent, TrackerCore, TrackingEvent, UserTraits };
|