@clianta/sdk 1.3.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/CHANGELOG.md +16 -0
- package/dist/clianta.cjs.js +759 -631
- package/dist/clianta.cjs.js.map +1 -1
- package/dist/clianta.esm.js +759 -631
- package/dist/clianta.esm.js.map +1 -1
- package/dist/clianta.umd.js +759 -631
- 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 +863 -803
- package/dist/react.cjs.js +759 -631
- package/dist/react.cjs.js.map +1 -1
- package/dist/react.d.ts +37 -3
- package/dist/react.esm.js +759 -631
- package/dist/react.esm.js.map +1 -1
- package/dist/vue.cjs.js +759 -631
- package/dist/vue.cjs.js.map +1 -1
- package/dist/vue.d.ts +37 -3
- package/dist/vue.esm.js +759 -631
- package/dist/vue.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,945 +1,1005 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Clianta SDK -
|
|
3
|
-
*
|
|
2
|
+
* Clianta SDK - Event Triggers Manager
|
|
3
|
+
* Manages event-driven automation and email notifications
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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>>;
|
|
78
162
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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>;
|
|
84
185
|
}
|
|
85
|
-
interface
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
186
|
+
interface InboundEventResult {
|
|
187
|
+
success: boolean;
|
|
188
|
+
contactCreated: boolean;
|
|
189
|
+
contactId?: string;
|
|
190
|
+
event: string;
|
|
191
|
+
error?: string;
|
|
91
192
|
}
|
|
92
|
-
interface UserTraits {
|
|
93
|
-
firstName?: string;
|
|
94
|
-
lastName?: string;
|
|
95
|
-
company?: string;
|
|
96
|
-
phone?: string;
|
|
97
|
-
title?: string;
|
|
98
|
-
[key: string]: unknown;
|
|
99
|
-
}
|
|
100
|
-
interface Plugin {
|
|
101
|
-
/** Unique plugin name */
|
|
102
|
-
name: PluginName;
|
|
103
|
-
/** Initialize the plugin (can be sync or async) */
|
|
104
|
-
init(tracker: TrackerCore): void | Promise<void>;
|
|
105
|
-
/** Cleanup when plugin is disabled */
|
|
106
|
-
destroy?(): void;
|
|
107
|
-
}
|
|
108
|
-
interface TrackerCore {
|
|
109
|
-
/** Track a custom event */
|
|
110
|
-
track(eventType: EventType | string, eventName: string, properties?: Record<string, unknown>): void;
|
|
111
|
-
/** Identify a visitor */
|
|
112
|
-
identify(email: string, traits?: UserTraits): void;
|
|
113
|
-
/** Track a page view */
|
|
114
|
-
page(name?: string, properties?: Record<string, unknown>): void;
|
|
115
|
-
/** Update consent state */
|
|
116
|
-
consent(state: ConsentState): void;
|
|
117
|
-
/** Toggle debug mode */
|
|
118
|
-
debug(enabled: boolean): void;
|
|
119
|
-
/** Get visitor ID */
|
|
120
|
-
getVisitorId(): string;
|
|
121
|
-
/** Get session ID */
|
|
122
|
-
getSessionId(): string;
|
|
123
|
-
/** Force flush event queue */
|
|
124
|
-
flush(): Promise<void>;
|
|
125
|
-
/** Reset visitor (for logout) */
|
|
126
|
-
reset(): void;
|
|
127
|
-
/** Get current configuration */
|
|
128
|
-
getConfig(): CliantaConfig;
|
|
129
|
-
/** Get workspace ID */
|
|
130
|
-
getWorkspaceId(): string;
|
|
131
|
-
/** Delete all stored user data (GDPR right-to-erasure) */
|
|
132
|
-
deleteData(): void;
|
|
133
|
-
/** Get current consent state */
|
|
134
|
-
getConsentState(): ConsentState;
|
|
135
|
-
}
|
|
136
|
-
interface Contact {
|
|
137
|
-
_id?: string;
|
|
138
|
-
workspaceId: string;
|
|
139
|
-
email: string;
|
|
140
|
-
firstName?: string;
|
|
141
|
-
lastName?: string;
|
|
142
|
-
company?: string;
|
|
143
|
-
jobTitle?: string;
|
|
144
|
-
phone?: string;
|
|
145
|
-
status?: 'lead' | 'contact' | 'customer';
|
|
146
|
-
lifecycleStage?: 'subscriber' | 'lead' | 'mql' | 'sql' | 'opportunity' | 'customer' | 'evangelist';
|
|
147
|
-
source?: string;
|
|
148
|
-
tags?: string[];
|
|
149
|
-
leadScore?: number;
|
|
150
|
-
customFields?: Record<string, unknown>;
|
|
151
|
-
companyId?: string;
|
|
152
|
-
assignedTo?: string;
|
|
153
|
-
createdAt?: string;
|
|
154
|
-
updatedAt?: string;
|
|
155
|
-
}
|
|
156
|
-
interface Company {
|
|
157
|
-
_id?: string;
|
|
158
|
-
workspaceId: string;
|
|
159
|
-
name: string;
|
|
160
|
-
industry?: string;
|
|
161
|
-
website?: string;
|
|
162
|
-
phone?: string;
|
|
163
|
-
address?: {
|
|
164
|
-
street?: string;
|
|
165
|
-
city?: string;
|
|
166
|
-
state?: string;
|
|
167
|
-
country?: string;
|
|
168
|
-
postalCode?: string;
|
|
169
|
-
};
|
|
170
|
-
companySize?: string;
|
|
171
|
-
annualRevenue?: number;
|
|
172
|
-
status?: 'prospect' | 'active' | 'inactive' | 'churned';
|
|
173
|
-
accountTier?: 'enterprise' | 'mid-market' | 'smb';
|
|
174
|
-
isTargetAccount?: boolean;
|
|
175
|
-
tags?: string[];
|
|
176
|
-
customFields?: Record<string, unknown>;
|
|
177
|
-
assignedTo?: string;
|
|
178
|
-
createdAt?: string;
|
|
179
|
-
updatedAt?: string;
|
|
180
|
-
}
|
|
181
|
-
interface Pipeline {
|
|
182
|
-
_id?: string;
|
|
183
|
-
workspaceId: string;
|
|
184
|
-
name: string;
|
|
185
|
-
description?: string;
|
|
186
|
-
stages: PipelineStage[];
|
|
187
|
-
isDefault?: boolean;
|
|
188
|
-
isActive?: boolean;
|
|
189
|
-
createdAt?: string;
|
|
190
|
-
updatedAt?: string;
|
|
191
|
-
}
|
|
192
|
-
interface PipelineStage {
|
|
193
|
-
_id?: string;
|
|
194
|
-
name: string;
|
|
195
|
-
order: number;
|
|
196
|
-
probability?: number;
|
|
197
|
-
color?: string;
|
|
198
|
-
rottenDays?: number;
|
|
199
|
-
}
|
|
200
|
-
interface Task {
|
|
201
|
-
_id?: string;
|
|
202
|
-
workspaceId: string;
|
|
203
|
-
title: string;
|
|
204
|
-
description?: string;
|
|
205
|
-
status?: 'pending' | 'in_progress' | 'completed' | 'cancelled';
|
|
206
|
-
priority?: 'low' | 'medium' | 'high' | 'urgent';
|
|
207
|
-
dueDate?: string;
|
|
208
|
-
reminderDate?: string;
|
|
209
|
-
completedAt?: string;
|
|
210
|
-
tags?: string[];
|
|
211
|
-
relatedContactId?: string;
|
|
212
|
-
relatedCompanyId?: string;
|
|
213
|
-
relatedOpportunityId?: string;
|
|
214
|
-
assignedTo?: string;
|
|
215
|
-
createdAt?: string;
|
|
216
|
-
updatedAt?: string;
|
|
217
|
-
}
|
|
218
|
-
interface Activity {
|
|
219
|
-
_id?: string;
|
|
220
|
-
workspaceId: string;
|
|
221
|
-
type: 'call' | 'email' | 'meeting' | 'note' | 'task' | 'other';
|
|
222
|
-
title: string;
|
|
223
|
-
description?: string;
|
|
224
|
-
direction?: 'inbound' | 'outbound';
|
|
225
|
-
duration?: number;
|
|
226
|
-
outcome?: string;
|
|
227
|
-
emailSubject?: string;
|
|
228
|
-
emailBody?: string;
|
|
229
|
-
metadata?: Record<string, unknown>;
|
|
230
|
-
contactId?: string;
|
|
231
|
-
companyId?: string;
|
|
232
|
-
opportunityId?: string;
|
|
233
|
-
userId?: string;
|
|
234
|
-
createdAt?: string;
|
|
235
|
-
updatedAt?: string;
|
|
236
|
-
}
|
|
237
|
-
interface Opportunity {
|
|
238
|
-
_id?: string;
|
|
239
|
-
workspaceId: string;
|
|
240
|
-
contactId: string;
|
|
241
|
-
companyId?: string;
|
|
242
|
-
pipelineId: string;
|
|
243
|
-
stageId: string;
|
|
244
|
-
title: string;
|
|
245
|
-
value?: number;
|
|
246
|
-
currency?: string;
|
|
247
|
-
probability?: number;
|
|
248
|
-
expectedCloseDate?: string;
|
|
249
|
-
status?: 'open' | 'won' | 'lost';
|
|
250
|
-
priority?: 'low' | 'medium' | 'high';
|
|
251
|
-
lostReason?: string;
|
|
252
|
-
customFields?: Record<string, unknown>;
|
|
253
|
-
assignedTo?: string;
|
|
254
|
-
createdAt?: string;
|
|
255
|
-
updatedAt?: string;
|
|
256
|
-
}
|
|
257
|
-
interface ApiResponse<T> {
|
|
258
|
-
success: boolean;
|
|
259
|
-
data?: T;
|
|
260
|
-
error?: string;
|
|
261
|
-
status: number;
|
|
262
|
-
}
|
|
263
|
-
interface PaginatedResponse<T> {
|
|
264
|
-
data: T[];
|
|
265
|
-
pagination: {
|
|
266
|
-
page: number;
|
|
267
|
-
limit: number;
|
|
268
|
-
total: number;
|
|
269
|
-
pages: number;
|
|
270
|
-
};
|
|
271
|
-
}
|
|
272
|
-
type TriggerEventType = 'contact.created' | 'contact.updated' | 'contact.deleted' | 'opportunity.created' | 'opportunity.updated' | 'opportunity.stage_changed' | 'opportunity.won' | 'opportunity.lost' | 'task.created' | 'task.completed' | 'task.overdue' | 'activity.logged' | 'form.submitted';
|
|
273
|
-
interface TriggerCondition {
|
|
274
|
-
/**
|
|
275
|
-
* Field to check - supports dynamic field names including custom fields
|
|
276
|
-
* Examples: 'status', 'lifecycleStage', 'leadScore', 'customFields.industry'
|
|
277
|
-
* Use dot notation for nested fields: 'contact.email', 'customFields.accountType'
|
|
278
|
-
*/
|
|
279
|
-
field: string;
|
|
280
|
-
/** Operator for comparison */
|
|
281
|
-
operator: 'equals' | 'not_equals' | 'contains' | 'greater_than' | 'less_than' | 'in' | 'not_in';
|
|
282
|
-
/** Value to compare against */
|
|
283
|
-
value: unknown;
|
|
284
|
-
}
|
|
285
|
-
interface EmailTemplate {
|
|
286
|
-
/** Template ID */
|
|
287
|
-
_id?: string;
|
|
288
|
-
/** Template name */
|
|
289
|
-
name: string;
|
|
290
|
-
/** Email subject line (supports variables) */
|
|
291
|
-
subject: string;
|
|
292
|
-
/** Email body (supports HTML and variables) */
|
|
293
|
-
body: string;
|
|
294
|
-
/** Variables available in this template */
|
|
295
|
-
variables?: string[];
|
|
296
|
-
/** Sender email address */
|
|
297
|
-
fromEmail?: string;
|
|
298
|
-
/** Sender name */
|
|
299
|
-
fromName?: string;
|
|
300
|
-
}
|
|
301
|
-
interface EmailAction {
|
|
302
|
-
/** Action type identifier */
|
|
303
|
-
type: 'send_email';
|
|
304
|
-
/** Email template ID or inline template */
|
|
305
|
-
templateId?: string;
|
|
306
|
-
/** Inline email subject (if not using template) */
|
|
307
|
-
subject?: string;
|
|
308
|
-
/** Inline email body (if not using template) */
|
|
309
|
-
body?: string;
|
|
310
|
-
/** Recipient email (supports variables like {{contact.email}}) */
|
|
311
|
-
to: string;
|
|
312
|
-
/** CC recipients */
|
|
313
|
-
cc?: string[];
|
|
314
|
-
/** BCC recipients */
|
|
315
|
-
bcc?: string[];
|
|
316
|
-
/** Sender email */
|
|
317
|
-
from?: string;
|
|
318
|
-
/** Delay in minutes before sending */
|
|
319
|
-
delayMinutes?: number;
|
|
320
|
-
}
|
|
321
|
-
interface WebhookAction {
|
|
322
|
-
/** Action type identifier */
|
|
323
|
-
type: 'webhook';
|
|
324
|
-
/** Webhook URL to call */
|
|
325
|
-
url: string;
|
|
326
|
-
/** HTTP method */
|
|
327
|
-
method: 'POST' | 'PUT' | 'PATCH';
|
|
328
|
-
/** Custom headers */
|
|
329
|
-
headers?: Record<string, string>;
|
|
330
|
-
/** Request body template (supports variables) */
|
|
331
|
-
body?: string;
|
|
332
|
-
}
|
|
333
|
-
interface TaskAction {
|
|
334
|
-
/** Action type identifier */
|
|
335
|
-
type: 'create_task';
|
|
336
|
-
/** Task title (supports variables) */
|
|
337
|
-
title: string;
|
|
338
|
-
/** Task description */
|
|
339
|
-
description?: string;
|
|
340
|
-
/** Task priority */
|
|
341
|
-
priority?: 'low' | 'medium' | 'high' | 'urgent';
|
|
342
|
-
/** Due date in days from trigger */
|
|
343
|
-
dueDays?: number;
|
|
344
|
-
/** Assign to user ID */
|
|
345
|
-
assignedTo?: string;
|
|
346
|
-
}
|
|
347
|
-
interface ContactUpdateAction {
|
|
348
|
-
/** Action type identifier */
|
|
349
|
-
type: 'update_contact';
|
|
350
|
-
/** Fields to update */
|
|
351
|
-
updates: Partial<Contact>;
|
|
352
|
-
}
|
|
353
|
-
type TriggerAction = EmailAction | WebhookAction | TaskAction | ContactUpdateAction;
|
|
354
|
-
interface EventTrigger {
|
|
355
|
-
/** Trigger ID */
|
|
356
|
-
_id?: string;
|
|
357
|
-
/** Workspace ID */
|
|
358
|
-
workspaceId: string;
|
|
359
|
-
/** Trigger name */
|
|
360
|
-
name: string;
|
|
361
|
-
/** Description of what this trigger does */
|
|
362
|
-
description?: string;
|
|
363
|
-
/** Event type that activates this trigger */
|
|
364
|
-
eventType: TriggerEventType;
|
|
365
|
-
/** Conditions that must be met for trigger to fire */
|
|
366
|
-
conditions?: TriggerCondition[];
|
|
367
|
-
/** Actions to execute when trigger fires */
|
|
368
|
-
actions: TriggerAction[];
|
|
369
|
-
/** Whether this trigger is active */
|
|
370
|
-
isActive?: boolean;
|
|
371
|
-
/** Created timestamp */
|
|
372
|
-
createdAt?: string;
|
|
373
|
-
/** Updated timestamp */
|
|
374
|
-
updatedAt?: string;
|
|
375
|
-
}
|
|
376
|
-
interface TriggerExecution {
|
|
377
|
-
/** Execution ID */
|
|
378
|
-
_id?: string;
|
|
379
|
-
/** Trigger ID that was executed */
|
|
380
|
-
triggerId: string;
|
|
381
|
-
/** Event that triggered the execution */
|
|
382
|
-
eventType: TriggerEventType;
|
|
383
|
-
/** Entity ID that triggered the event */
|
|
384
|
-
entityId: string;
|
|
385
|
-
/** Execution status */
|
|
386
|
-
status: 'pending' | 'success' | 'failed';
|
|
387
|
-
/** Error message if failed */
|
|
388
|
-
error?: string;
|
|
389
|
-
/** Actions executed */
|
|
390
|
-
actionsExecuted: number;
|
|
391
|
-
/** Execution timestamp */
|
|
392
|
-
executedAt: string;
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
/**
|
|
396
|
-
* Clianta SDK - Main Tracker Class
|
|
397
|
-
* @see SDK_VERSION in core/config.ts
|
|
398
|
-
*/
|
|
399
|
-
|
|
400
193
|
/**
|
|
401
|
-
*
|
|
194
|
+
* CRM API Client for managing contacts and opportunities
|
|
402
195
|
*/
|
|
403
|
-
declare class
|
|
196
|
+
declare class CRMClient {
|
|
197
|
+
private apiEndpoint;
|
|
404
198
|
private workspaceId;
|
|
405
|
-
private
|
|
406
|
-
private
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
private visitorId;
|
|
410
|
-
private sessionId;
|
|
411
|
-
private isInitialized;
|
|
412
|
-
private consentManager;
|
|
413
|
-
/** Pending identify retry on next flush */
|
|
414
|
-
private pendingIdentify;
|
|
415
|
-
constructor(workspaceId: string, userConfig?: CliantaConfig);
|
|
199
|
+
private authToken?;
|
|
200
|
+
private apiKey?;
|
|
201
|
+
triggers: EventTriggersManager;
|
|
202
|
+
constructor(apiEndpoint: string, workspaceId: string, authToken?: string, apiKey?: string);
|
|
416
203
|
/**
|
|
417
|
-
*
|
|
204
|
+
* Set authentication token for API requests (user JWT)
|
|
418
205
|
*/
|
|
419
|
-
|
|
206
|
+
setAuthToken(token: string): void;
|
|
420
207
|
/**
|
|
421
|
-
*
|
|
208
|
+
* Set workspace API key for server-to-server requests.
|
|
209
|
+
* Use this instead of setAuthToken when integrating from an external app.
|
|
422
210
|
*/
|
|
423
|
-
|
|
211
|
+
setApiKey(key: string): void;
|
|
424
212
|
/**
|
|
425
|
-
*
|
|
213
|
+
* Validate required parameter exists
|
|
214
|
+
* @throws {Error} if value is null/undefined or empty string
|
|
426
215
|
*/
|
|
427
|
-
private
|
|
216
|
+
private validateRequired;
|
|
428
217
|
/**
|
|
429
|
-
*
|
|
430
|
-
* Handles both sync and async plugin init methods
|
|
218
|
+
* Make authenticated API request
|
|
431
219
|
*/
|
|
432
|
-
private
|
|
220
|
+
private request;
|
|
433
221
|
/**
|
|
434
|
-
*
|
|
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
|
|
435
240
|
*/
|
|
436
|
-
|
|
241
|
+
getContacts(params?: {
|
|
242
|
+
page?: number;
|
|
243
|
+
limit?: number;
|
|
244
|
+
search?: string;
|
|
245
|
+
status?: string;
|
|
246
|
+
}): Promise<ApiResponse<PaginatedResponse<Contact>>>;
|
|
437
247
|
/**
|
|
438
|
-
*
|
|
248
|
+
* Get a single contact by ID
|
|
439
249
|
*/
|
|
440
|
-
|
|
250
|
+
getContact(contactId: string): Promise<ApiResponse<Contact>>;
|
|
441
251
|
/**
|
|
442
|
-
*
|
|
252
|
+
* Create a new contact
|
|
443
253
|
*/
|
|
444
|
-
|
|
254
|
+
createContact(contact: Partial<Contact>): Promise<ApiResponse<Contact>>;
|
|
445
255
|
/**
|
|
446
|
-
*
|
|
256
|
+
* Update an existing contact
|
|
447
257
|
*/
|
|
448
|
-
|
|
258
|
+
updateContact(contactId: string, updates: Partial<Contact>): Promise<ApiResponse<Contact>>;
|
|
449
259
|
/**
|
|
450
|
-
*
|
|
260
|
+
* Delete a contact
|
|
451
261
|
*/
|
|
452
|
-
|
|
262
|
+
deleteContact(contactId: string): Promise<ApiResponse<void>>;
|
|
453
263
|
/**
|
|
454
|
-
* Get
|
|
264
|
+
* Get all opportunities with pagination
|
|
455
265
|
*/
|
|
456
|
-
|
|
266
|
+
getOpportunities(params?: {
|
|
267
|
+
page?: number;
|
|
268
|
+
limit?: number;
|
|
269
|
+
pipelineId?: string;
|
|
270
|
+
stageId?: string;
|
|
271
|
+
}): Promise<ApiResponse<PaginatedResponse<Opportunity>>>;
|
|
457
272
|
/**
|
|
458
|
-
*
|
|
273
|
+
* Get a single opportunity by ID
|
|
459
274
|
*/
|
|
460
|
-
|
|
275
|
+
getOpportunity(opportunityId: string): Promise<ApiResponse<Opportunity>>;
|
|
461
276
|
/**
|
|
462
|
-
*
|
|
277
|
+
* Create a new opportunity
|
|
463
278
|
*/
|
|
464
|
-
|
|
279
|
+
createOpportunity(opportunity: Partial<Opportunity>): Promise<ApiResponse<Opportunity>>;
|
|
465
280
|
/**
|
|
466
|
-
*
|
|
281
|
+
* Update an existing opportunity
|
|
467
282
|
*/
|
|
468
|
-
|
|
283
|
+
updateOpportunity(opportunityId: string, updates: Partial<Opportunity>): Promise<ApiResponse<Opportunity>>;
|
|
469
284
|
/**
|
|
470
|
-
*
|
|
285
|
+
* Delete an opportunity
|
|
471
286
|
*/
|
|
472
|
-
|
|
287
|
+
deleteOpportunity(opportunityId: string): Promise<ApiResponse<void>>;
|
|
473
288
|
/**
|
|
474
|
-
*
|
|
289
|
+
* Move opportunity to a different stage
|
|
475
290
|
*/
|
|
476
|
-
|
|
291
|
+
moveOpportunity(opportunityId: string, stageId: string): Promise<ApiResponse<Opportunity>>;
|
|
477
292
|
/**
|
|
478
|
-
*
|
|
293
|
+
* Get all companies with pagination
|
|
479
294
|
*/
|
|
480
|
-
|
|
295
|
+
getCompanies(params?: {
|
|
296
|
+
page?: number;
|
|
297
|
+
limit?: number;
|
|
298
|
+
search?: string;
|
|
299
|
+
status?: string;
|
|
300
|
+
industry?: string;
|
|
301
|
+
}): Promise<ApiResponse<PaginatedResponse<Company>>>;
|
|
481
302
|
/**
|
|
482
|
-
*
|
|
303
|
+
* Get a single company by ID
|
|
483
304
|
*/
|
|
484
|
-
|
|
305
|
+
getCompany(companyId: string): Promise<ApiResponse<Company>>;
|
|
485
306
|
/**
|
|
486
|
-
*
|
|
307
|
+
* Create a new company
|
|
487
308
|
*/
|
|
488
|
-
|
|
309
|
+
createCompany(company: Partial<Company>): Promise<ApiResponse<Company>>;
|
|
489
310
|
/**
|
|
490
|
-
*
|
|
311
|
+
* Update an existing company
|
|
491
312
|
*/
|
|
492
|
-
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
/**
|
|
496
|
-
* Clianta SDK - Event Triggers Manager
|
|
497
|
-
* Manages event-driven automation and email notifications
|
|
498
|
-
*/
|
|
499
|
-
|
|
500
|
-
/**
|
|
501
|
-
* Event Triggers Manager
|
|
502
|
-
* Handles event-driven automation based on CRM actions
|
|
503
|
-
*
|
|
504
|
-
* Similar to:
|
|
505
|
-
* - Salesforce: Process Builder, Flow Automation
|
|
506
|
-
* - HubSpot: Workflows, Email Sequences
|
|
507
|
-
* - Pipedrive: Workflow Automation
|
|
508
|
-
*/
|
|
509
|
-
declare class EventTriggersManager {
|
|
510
|
-
private apiEndpoint;
|
|
511
|
-
private workspaceId;
|
|
512
|
-
private authToken?;
|
|
513
|
-
private triggers;
|
|
514
|
-
private listeners;
|
|
515
|
-
constructor(apiEndpoint: string, workspaceId: string, authToken?: string);
|
|
313
|
+
updateCompany(companyId: string, updates: Partial<Company>): Promise<ApiResponse<Company>>;
|
|
516
314
|
/**
|
|
517
|
-
*
|
|
315
|
+
* Delete a company
|
|
518
316
|
*/
|
|
519
|
-
|
|
317
|
+
deleteCompany(companyId: string): Promise<ApiResponse<void>>;
|
|
520
318
|
/**
|
|
521
|
-
*
|
|
319
|
+
* Get contacts belonging to a company
|
|
522
320
|
*/
|
|
523
|
-
|
|
321
|
+
getCompanyContacts(companyId: string, params?: {
|
|
322
|
+
page?: number;
|
|
323
|
+
limit?: number;
|
|
324
|
+
}): Promise<ApiResponse<PaginatedResponse<Contact>>>;
|
|
524
325
|
/**
|
|
525
|
-
* Get
|
|
326
|
+
* Get deals/opportunities belonging to a company
|
|
526
327
|
*/
|
|
527
|
-
|
|
328
|
+
getCompanyDeals(companyId: string, params?: {
|
|
329
|
+
page?: number;
|
|
330
|
+
limit?: number;
|
|
331
|
+
}): Promise<ApiResponse<PaginatedResponse<Opportunity>>>;
|
|
528
332
|
/**
|
|
529
|
-
* Get
|
|
333
|
+
* Get all pipelines
|
|
530
334
|
*/
|
|
531
|
-
|
|
335
|
+
getPipelines(): Promise<ApiResponse<Pipeline[]>>;
|
|
532
336
|
/**
|
|
533
|
-
*
|
|
337
|
+
* Get a single pipeline by ID
|
|
534
338
|
*/
|
|
535
|
-
|
|
339
|
+
getPipeline(pipelineId: string): Promise<ApiResponse<Pipeline>>;
|
|
536
340
|
/**
|
|
537
|
-
*
|
|
341
|
+
* Create a new pipeline
|
|
538
342
|
*/
|
|
539
|
-
|
|
343
|
+
createPipeline(pipeline: Partial<Pipeline>): Promise<ApiResponse<Pipeline>>;
|
|
540
344
|
/**
|
|
541
|
-
*
|
|
345
|
+
* Update an existing pipeline
|
|
542
346
|
*/
|
|
543
|
-
|
|
347
|
+
updatePipeline(pipelineId: string, updates: Partial<Pipeline>): Promise<ApiResponse<Pipeline>>;
|
|
544
348
|
/**
|
|
545
|
-
*
|
|
349
|
+
* Delete a pipeline
|
|
546
350
|
*/
|
|
547
|
-
|
|
351
|
+
deletePipeline(pipelineId: string): Promise<ApiResponse<void>>;
|
|
548
352
|
/**
|
|
549
|
-
*
|
|
353
|
+
* Get all tasks with pagination
|
|
550
354
|
*/
|
|
551
|
-
|
|
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>>>;
|
|
552
364
|
/**
|
|
553
|
-
*
|
|
554
|
-
* This allows immediate client-side reactions to events
|
|
365
|
+
* Get a single task by ID
|
|
555
366
|
*/
|
|
556
|
-
|
|
367
|
+
getTask(taskId: string): Promise<ApiResponse<Task>>;
|
|
557
368
|
/**
|
|
558
|
-
*
|
|
369
|
+
* Create a new task
|
|
559
370
|
*/
|
|
560
|
-
|
|
371
|
+
createTask(task: Partial<Task>): Promise<ApiResponse<Task>>;
|
|
561
372
|
/**
|
|
562
|
-
*
|
|
563
|
-
* This will trigger any registered local listeners
|
|
373
|
+
* Update an existing task
|
|
564
374
|
*/
|
|
565
|
-
|
|
375
|
+
updateTask(taskId: string, updates: Partial<Task>): Promise<ApiResponse<Task>>;
|
|
566
376
|
/**
|
|
567
|
-
*
|
|
568
|
-
* Supports dynamic field evaluation including custom fields and nested paths
|
|
377
|
+
* Mark a task as completed
|
|
569
378
|
*/
|
|
570
|
-
|
|
379
|
+
completeTask(taskId: string): Promise<ApiResponse<Task>>;
|
|
571
380
|
/**
|
|
572
|
-
*
|
|
573
|
-
* Note: Actual execution happens on the backend
|
|
381
|
+
* Delete a task
|
|
574
382
|
*/
|
|
575
|
-
|
|
383
|
+
deleteTask(taskId: string): Promise<ApiResponse<void>>;
|
|
576
384
|
/**
|
|
577
|
-
*
|
|
385
|
+
* Get activities for a contact
|
|
578
386
|
*/
|
|
579
|
-
|
|
387
|
+
getContactActivities(contactId: string, params?: {
|
|
388
|
+
page?: number;
|
|
389
|
+
limit?: number;
|
|
390
|
+
type?: string;
|
|
391
|
+
}): Promise<ApiResponse<PaginatedResponse<Activity>>>;
|
|
580
392
|
/**
|
|
581
|
-
*
|
|
393
|
+
* Get activities for an opportunity/deal
|
|
582
394
|
*/
|
|
583
|
-
|
|
395
|
+
getOpportunityActivities(opportunityId: string, params?: {
|
|
396
|
+
page?: number;
|
|
397
|
+
limit?: number;
|
|
398
|
+
type?: string;
|
|
399
|
+
}): Promise<ApiResponse<PaginatedResponse<Activity>>>;
|
|
584
400
|
/**
|
|
585
|
-
*
|
|
401
|
+
* Create a new activity
|
|
586
402
|
*/
|
|
587
|
-
|
|
403
|
+
createActivity(activity: Partial<Activity>): Promise<ApiResponse<Activity>>;
|
|
588
404
|
/**
|
|
589
|
-
*
|
|
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
|
|
590
451
|
*/
|
|
591
|
-
|
|
452
|
+
getEmailTemplate(templateId: string): Promise<ApiResponse<EmailTemplate>>;
|
|
592
453
|
/**
|
|
593
|
-
*
|
|
454
|
+
* Create a new email template
|
|
594
455
|
*/
|
|
595
|
-
|
|
456
|
+
createEmailTemplate(template: Partial<EmailTemplate>): Promise<ApiResponse<EmailTemplate>>;
|
|
596
457
|
/**
|
|
597
|
-
*
|
|
598
|
-
* Supports syntax like {{contact.email}}, {{opportunity.value}}
|
|
458
|
+
* Update an email template
|
|
599
459
|
*/
|
|
600
|
-
|
|
460
|
+
updateEmailTemplate(templateId: string, updates: Partial<EmailTemplate>): Promise<ApiResponse<EmailTemplate>>;
|
|
601
461
|
/**
|
|
602
|
-
*
|
|
603
|
-
* Supports dynamic field access including custom fields
|
|
462
|
+
* Delete an email template
|
|
604
463
|
*/
|
|
605
|
-
|
|
464
|
+
deleteEmailTemplate(templateId: string): Promise<ApiResponse<void>>;
|
|
606
465
|
/**
|
|
607
|
-
*
|
|
608
|
-
* Useful for dynamic field discovery based on platform-specific attributes
|
|
609
|
-
* @param obj - The data object to extract fields from
|
|
610
|
-
* @param prefix - Internal use for nested paths
|
|
611
|
-
* @param maxDepth - Maximum depth to traverse (default: 3)
|
|
612
|
-
* @returns Array of field paths (e.g., ['email', 'contact.firstName', 'customFields.industry'])
|
|
466
|
+
* Send an email using a template
|
|
613
467
|
*/
|
|
614
|
-
|
|
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
|
+
}>>;
|
|
615
480
|
/**
|
|
616
|
-
* Get
|
|
617
|
-
* Helps with dynamic field detection for platform-specific attributes
|
|
618
|
-
* @param sampleData - Sample data object to analyze
|
|
619
|
-
* @returns Array of available field paths
|
|
481
|
+
* Get all event triggers
|
|
620
482
|
*/
|
|
621
|
-
|
|
483
|
+
getEventTriggers(): Promise<ApiResponse<EventTrigger[]>>;
|
|
622
484
|
/**
|
|
623
|
-
* Create a
|
|
624
|
-
* Helper method for common use case
|
|
485
|
+
* Create a new event trigger
|
|
625
486
|
*/
|
|
626
|
-
|
|
627
|
-
name: string;
|
|
628
|
-
eventType: TriggerEventType;
|
|
629
|
-
to: string;
|
|
630
|
-
subject: string;
|
|
631
|
-
body: string;
|
|
632
|
-
conditions?: TriggerCondition[];
|
|
633
|
-
}): Promise<ApiResponse<EventTrigger>>;
|
|
487
|
+
createEventTrigger(trigger: Partial<EventTrigger>): Promise<ApiResponse<EventTrigger>>;
|
|
634
488
|
/**
|
|
635
|
-
*
|
|
489
|
+
* Update an event trigger
|
|
636
490
|
*/
|
|
637
|
-
|
|
638
|
-
name: string;
|
|
639
|
-
eventType: TriggerEventType;
|
|
640
|
-
taskTitle: string;
|
|
641
|
-
taskDescription?: string;
|
|
642
|
-
priority?: 'low' | 'medium' | 'high' | 'urgent';
|
|
643
|
-
dueDays?: number;
|
|
644
|
-
conditions?: TriggerCondition[];
|
|
645
|
-
}): Promise<ApiResponse<EventTrigger>>;
|
|
491
|
+
updateEventTrigger(triggerId: string, updates: Partial<EventTrigger>): Promise<ApiResponse<EventTrigger>>;
|
|
646
492
|
/**
|
|
647
|
-
*
|
|
493
|
+
* Delete an event trigger
|
|
648
494
|
*/
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
495
|
+
deleteEventTrigger(triggerId: string): Promise<ApiResponse<void>>;
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
/**
|
|
499
|
+
* Clianta SDK - Type Definitions
|
|
500
|
+
* @see SDK_VERSION in core/config.ts
|
|
501
|
+
*/
|
|
502
|
+
interface CliantaConfig {
|
|
503
|
+
/** Project ID (required for config file pattern) */
|
|
504
|
+
projectId?: string;
|
|
505
|
+
/** Backend API endpoint URL */
|
|
506
|
+
apiEndpoint?: string;
|
|
507
|
+
/** Auth token for server-side API access (user JWT) */
|
|
508
|
+
authToken?: string;
|
|
509
|
+
/** Workspace API key for server-to-server access (use instead of authToken for external apps) */
|
|
510
|
+
apiKey?: string;
|
|
511
|
+
/** Enable debug mode with verbose logging */
|
|
512
|
+
debug?: boolean;
|
|
513
|
+
/** Automatically track page views on load and navigation */
|
|
514
|
+
autoPageView?: boolean;
|
|
515
|
+
/** Plugins to enable (default: all core plugins) */
|
|
516
|
+
plugins?: PluginName[];
|
|
517
|
+
/** Session timeout in milliseconds (default: 30 minutes) */
|
|
518
|
+
sessionTimeout?: number;
|
|
519
|
+
/** Maximum events to batch before sending (default: 10) */
|
|
520
|
+
batchSize?: number;
|
|
521
|
+
/** Interval to flush events in milliseconds (default: 5000) */
|
|
522
|
+
flushInterval?: number;
|
|
523
|
+
/** Consent configuration */
|
|
524
|
+
consent?: ConsentConfig;
|
|
525
|
+
/** Cookie domain for cross-subdomain tracking */
|
|
526
|
+
cookieDomain?: string;
|
|
527
|
+
/** Use cookies instead of localStorage for visitor ID */
|
|
528
|
+
useCookies?: boolean;
|
|
529
|
+
/** Cookie-less mode: use sessionStorage only (no persistent storage) */
|
|
530
|
+
cookielessMode?: boolean;
|
|
531
|
+
}
|
|
532
|
+
type PluginName = 'pageView' | 'forms' | 'scroll' | 'clicks' | 'engagement' | 'downloads' | 'exitIntent' | 'errors' | 'performance' | 'popupForms';
|
|
533
|
+
interface ConsentConfig {
|
|
534
|
+
/** Default consent state before user action */
|
|
535
|
+
defaultConsent?: ConsentState;
|
|
536
|
+
/** Wait for consent before tracking anything */
|
|
537
|
+
waitForConsent?: boolean;
|
|
538
|
+
/** Storage key for consent state */
|
|
539
|
+
storageKey?: string;
|
|
540
|
+
/** Anonymous mode: track without visitor ID until explicit consent */
|
|
541
|
+
anonymousMode?: boolean;
|
|
542
|
+
}
|
|
543
|
+
interface ConsentState {
|
|
544
|
+
/** Consent for analytics/essential tracking */
|
|
545
|
+
analytics?: boolean;
|
|
546
|
+
/** Consent for marketing/advertising tracking */
|
|
547
|
+
marketing?: boolean;
|
|
548
|
+
/** Consent for personalization */
|
|
549
|
+
personalization?: boolean;
|
|
550
|
+
}
|
|
551
|
+
type EventType = 'page_view' | 'button_click' | 'form_view' | 'form_submit' | 'form_interaction' | 'scroll_depth' | 'engagement' | 'download' | 'exit_intent' | 'error' | 'performance' | 'time_on_page' | 'custom';
|
|
552
|
+
interface TrackingEvent {
|
|
553
|
+
/** Workspace/project ID */
|
|
554
|
+
workspaceId: string;
|
|
555
|
+
/** Anonymous visitor identifier */
|
|
556
|
+
visitorId: string;
|
|
557
|
+
/** Session identifier */
|
|
558
|
+
sessionId: string;
|
|
559
|
+
/** Event type category */
|
|
560
|
+
eventType: EventType;
|
|
561
|
+
/** Human-readable event name */
|
|
562
|
+
eventName: string;
|
|
563
|
+
/** Current page URL */
|
|
564
|
+
url: string;
|
|
565
|
+
/** Referrer URL */
|
|
566
|
+
referrer?: string;
|
|
567
|
+
/** Event properties/metadata */
|
|
568
|
+
properties: Record<string, unknown>;
|
|
569
|
+
/** Device information */
|
|
570
|
+
device: DeviceInfo;
|
|
571
|
+
/** UTM parameters */
|
|
572
|
+
utm?: UTMParams;
|
|
573
|
+
/** ISO timestamp */
|
|
574
|
+
timestamp: string;
|
|
575
|
+
/** SDK version */
|
|
576
|
+
sdkVersion: string;
|
|
577
|
+
}
|
|
578
|
+
interface DeviceInfo {
|
|
579
|
+
userAgent: string;
|
|
580
|
+
screen: string;
|
|
581
|
+
language: string;
|
|
582
|
+
timezone?: string;
|
|
583
|
+
}
|
|
584
|
+
interface UTMParams {
|
|
585
|
+
utmSource?: string;
|
|
586
|
+
utmMedium?: string;
|
|
587
|
+
utmCampaign?: string;
|
|
588
|
+
utmTerm?: string;
|
|
589
|
+
utmContent?: string;
|
|
590
|
+
}
|
|
591
|
+
interface UserTraits {
|
|
592
|
+
firstName?: string;
|
|
593
|
+
lastName?: string;
|
|
594
|
+
company?: string;
|
|
595
|
+
phone?: string;
|
|
596
|
+
title?: string;
|
|
597
|
+
[key: string]: unknown;
|
|
598
|
+
}
|
|
599
|
+
interface Plugin {
|
|
600
|
+
/** Unique plugin name */
|
|
601
|
+
name: PluginName;
|
|
602
|
+
/** Initialize the plugin (can be sync or async) */
|
|
603
|
+
init(tracker: TrackerCore): void | Promise<void>;
|
|
604
|
+
/** Cleanup when plugin is disabled */
|
|
605
|
+
destroy?(): void;
|
|
606
|
+
}
|
|
607
|
+
interface TrackerCore {
|
|
608
|
+
/** Track a custom event */
|
|
609
|
+
track(eventType: EventType | string, eventName: string, properties?: Record<string, unknown>): void;
|
|
610
|
+
/** Identify a visitor — returns the contactId if successful */
|
|
611
|
+
identify(email: string, traits?: UserTraits): Promise<string | null>;
|
|
612
|
+
/** Track a page view */
|
|
613
|
+
page(name?: string, properties?: Record<string, unknown>): void;
|
|
614
|
+
/** Update consent state */
|
|
615
|
+
consent(state: ConsentState): void;
|
|
616
|
+
/** Toggle debug mode */
|
|
617
|
+
debug(enabled: boolean): void;
|
|
618
|
+
/** Get visitor ID */
|
|
619
|
+
getVisitorId(): string;
|
|
620
|
+
/** Get session ID */
|
|
621
|
+
getSessionId(): string;
|
|
622
|
+
/** Force flush event queue */
|
|
623
|
+
flush(): Promise<void>;
|
|
624
|
+
/** Reset visitor (for logout) */
|
|
625
|
+
reset(): void;
|
|
626
|
+
/** Get current configuration */
|
|
627
|
+
getConfig(): CliantaConfig;
|
|
628
|
+
/** Get workspace ID */
|
|
629
|
+
getWorkspaceId(): string;
|
|
630
|
+
/** Delete all stored user data (GDPR right-to-erasure) */
|
|
631
|
+
deleteData(): void;
|
|
632
|
+
/** Get current consent state */
|
|
633
|
+
getConsentState(): ConsentState;
|
|
634
|
+
/** Send a server-side inbound event (requires apiKey in config) */
|
|
635
|
+
sendEvent(payload: InboundEventPayload): Promise<InboundEventResult>;
|
|
636
|
+
}
|
|
637
|
+
interface Contact {
|
|
638
|
+
_id?: string;
|
|
639
|
+
workspaceId: string;
|
|
640
|
+
email: string;
|
|
641
|
+
firstName?: string;
|
|
642
|
+
lastName?: string;
|
|
643
|
+
company?: string;
|
|
644
|
+
jobTitle?: string;
|
|
645
|
+
phone?: string;
|
|
646
|
+
status?: 'lead' | 'contact' | 'customer';
|
|
647
|
+
lifecycleStage?: 'subscriber' | 'lead' | 'mql' | 'sql' | 'opportunity' | 'customer' | 'evangelist';
|
|
648
|
+
source?: string;
|
|
649
|
+
tags?: string[];
|
|
650
|
+
leadScore?: number;
|
|
651
|
+
customFields?: Record<string, unknown>;
|
|
652
|
+
companyId?: string;
|
|
653
|
+
assignedTo?: string;
|
|
654
|
+
createdAt?: string;
|
|
655
|
+
updatedAt?: string;
|
|
656
|
+
}
|
|
657
|
+
interface Company {
|
|
658
|
+
_id?: string;
|
|
659
|
+
workspaceId: string;
|
|
660
|
+
name: string;
|
|
661
|
+
industry?: string;
|
|
662
|
+
website?: string;
|
|
663
|
+
phone?: string;
|
|
664
|
+
address?: {
|
|
665
|
+
street?: string;
|
|
666
|
+
city?: string;
|
|
667
|
+
state?: string;
|
|
668
|
+
country?: string;
|
|
669
|
+
postalCode?: string;
|
|
670
|
+
};
|
|
671
|
+
companySize?: string;
|
|
672
|
+
annualRevenue?: number;
|
|
673
|
+
status?: 'prospect' | 'active' | 'inactive' | 'churned';
|
|
674
|
+
accountTier?: 'enterprise' | 'mid-market' | 'smb';
|
|
675
|
+
isTargetAccount?: boolean;
|
|
676
|
+
tags?: string[];
|
|
677
|
+
customFields?: Record<string, unknown>;
|
|
678
|
+
assignedTo?: string;
|
|
679
|
+
createdAt?: string;
|
|
680
|
+
updatedAt?: string;
|
|
681
|
+
}
|
|
682
|
+
interface Pipeline {
|
|
683
|
+
_id?: string;
|
|
684
|
+
workspaceId: string;
|
|
685
|
+
name: string;
|
|
686
|
+
description?: string;
|
|
687
|
+
stages: PipelineStage[];
|
|
688
|
+
isDefault?: boolean;
|
|
689
|
+
isActive?: boolean;
|
|
690
|
+
createdAt?: string;
|
|
691
|
+
updatedAt?: string;
|
|
656
692
|
}
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
/**
|
|
740
|
-
* Get all companies with pagination
|
|
741
|
-
*/
|
|
742
|
-
getCompanies(params?: {
|
|
743
|
-
page?: number;
|
|
744
|
-
limit?: number;
|
|
745
|
-
search?: string;
|
|
746
|
-
status?: string;
|
|
747
|
-
industry?: string;
|
|
748
|
-
}): Promise<ApiResponse<PaginatedResponse<Company>>>;
|
|
749
|
-
/**
|
|
750
|
-
* Get a single company by ID
|
|
751
|
-
*/
|
|
752
|
-
getCompany(companyId: string): Promise<ApiResponse<Company>>;
|
|
753
|
-
/**
|
|
754
|
-
* Create a new company
|
|
755
|
-
*/
|
|
756
|
-
createCompany(company: Partial<Company>): Promise<ApiResponse<Company>>;
|
|
757
|
-
/**
|
|
758
|
-
* Update an existing company
|
|
759
|
-
*/
|
|
760
|
-
updateCompany(companyId: string, updates: Partial<Company>): Promise<ApiResponse<Company>>;
|
|
761
|
-
/**
|
|
762
|
-
* Delete a company
|
|
763
|
-
*/
|
|
764
|
-
deleteCompany(companyId: string): Promise<ApiResponse<void>>;
|
|
765
|
-
/**
|
|
766
|
-
* Get contacts belonging to a company
|
|
767
|
-
*/
|
|
768
|
-
getCompanyContacts(companyId: string, params?: {
|
|
769
|
-
page?: number;
|
|
770
|
-
limit?: number;
|
|
771
|
-
}): Promise<ApiResponse<PaginatedResponse<Contact>>>;
|
|
772
|
-
/**
|
|
773
|
-
* Get deals/opportunities belonging to a company
|
|
774
|
-
*/
|
|
775
|
-
getCompanyDeals(companyId: string, params?: {
|
|
776
|
-
page?: number;
|
|
777
|
-
limit?: number;
|
|
778
|
-
}): Promise<ApiResponse<PaginatedResponse<Opportunity>>>;
|
|
779
|
-
/**
|
|
780
|
-
* Get all pipelines
|
|
781
|
-
*/
|
|
782
|
-
getPipelines(): Promise<ApiResponse<Pipeline[]>>;
|
|
783
|
-
/**
|
|
784
|
-
* Get a single pipeline by ID
|
|
785
|
-
*/
|
|
786
|
-
getPipeline(pipelineId: string): Promise<ApiResponse<Pipeline>>;
|
|
787
|
-
/**
|
|
788
|
-
* Create a new pipeline
|
|
789
|
-
*/
|
|
790
|
-
createPipeline(pipeline: Partial<Pipeline>): Promise<ApiResponse<Pipeline>>;
|
|
791
|
-
/**
|
|
792
|
-
* Update an existing pipeline
|
|
793
|
-
*/
|
|
794
|
-
updatePipeline(pipelineId: string, updates: Partial<Pipeline>): Promise<ApiResponse<Pipeline>>;
|
|
795
|
-
/**
|
|
796
|
-
* Delete a pipeline
|
|
797
|
-
*/
|
|
798
|
-
deletePipeline(pipelineId: string): Promise<ApiResponse<void>>;
|
|
799
|
-
/**
|
|
800
|
-
* Get all tasks with pagination
|
|
801
|
-
*/
|
|
802
|
-
getTasks(params?: {
|
|
803
|
-
page?: number;
|
|
804
|
-
limit?: number;
|
|
805
|
-
status?: string;
|
|
806
|
-
priority?: string;
|
|
807
|
-
contactId?: string;
|
|
808
|
-
companyId?: string;
|
|
809
|
-
opportunityId?: string;
|
|
810
|
-
}): Promise<ApiResponse<PaginatedResponse<Task>>>;
|
|
811
|
-
/**
|
|
812
|
-
* Get a single task by ID
|
|
813
|
-
*/
|
|
814
|
-
getTask(taskId: string): Promise<ApiResponse<Task>>;
|
|
815
|
-
/**
|
|
816
|
-
* Create a new task
|
|
817
|
-
*/
|
|
818
|
-
createTask(task: Partial<Task>): Promise<ApiResponse<Task>>;
|
|
693
|
+
interface PipelineStage {
|
|
694
|
+
_id?: string;
|
|
695
|
+
name: string;
|
|
696
|
+
order: number;
|
|
697
|
+
probability?: number;
|
|
698
|
+
color?: string;
|
|
699
|
+
rottenDays?: number;
|
|
700
|
+
}
|
|
701
|
+
interface Task {
|
|
702
|
+
_id?: string;
|
|
703
|
+
workspaceId: string;
|
|
704
|
+
title: string;
|
|
705
|
+
description?: string;
|
|
706
|
+
status?: 'pending' | 'in_progress' | 'completed' | 'cancelled';
|
|
707
|
+
priority?: 'low' | 'medium' | 'high' | 'urgent';
|
|
708
|
+
dueDate?: string;
|
|
709
|
+
reminderDate?: string;
|
|
710
|
+
completedAt?: string;
|
|
711
|
+
tags?: string[];
|
|
712
|
+
relatedContactId?: string;
|
|
713
|
+
relatedCompanyId?: string;
|
|
714
|
+
relatedOpportunityId?: string;
|
|
715
|
+
assignedTo?: string;
|
|
716
|
+
createdAt?: string;
|
|
717
|
+
updatedAt?: string;
|
|
718
|
+
}
|
|
719
|
+
interface Activity {
|
|
720
|
+
_id?: string;
|
|
721
|
+
workspaceId: string;
|
|
722
|
+
type: 'call' | 'email' | 'meeting' | 'note' | 'task' | 'other';
|
|
723
|
+
title: string;
|
|
724
|
+
description?: string;
|
|
725
|
+
direction?: 'inbound' | 'outbound';
|
|
726
|
+
duration?: number;
|
|
727
|
+
outcome?: string;
|
|
728
|
+
emailSubject?: string;
|
|
729
|
+
emailBody?: string;
|
|
730
|
+
metadata?: Record<string, unknown>;
|
|
731
|
+
contactId?: string;
|
|
732
|
+
companyId?: string;
|
|
733
|
+
opportunityId?: string;
|
|
734
|
+
userId?: string;
|
|
735
|
+
createdAt?: string;
|
|
736
|
+
updatedAt?: string;
|
|
737
|
+
}
|
|
738
|
+
interface Opportunity {
|
|
739
|
+
_id?: string;
|
|
740
|
+
workspaceId: string;
|
|
741
|
+
contactId: string;
|
|
742
|
+
companyId?: string;
|
|
743
|
+
pipelineId: string;
|
|
744
|
+
stageId: string;
|
|
745
|
+
title: string;
|
|
746
|
+
value?: number;
|
|
747
|
+
currency?: string;
|
|
748
|
+
probability?: number;
|
|
749
|
+
expectedCloseDate?: string;
|
|
750
|
+
status?: 'open' | 'won' | 'lost';
|
|
751
|
+
priority?: 'low' | 'medium' | 'high';
|
|
752
|
+
lostReason?: string;
|
|
753
|
+
customFields?: Record<string, unknown>;
|
|
754
|
+
assignedTo?: string;
|
|
755
|
+
createdAt?: string;
|
|
756
|
+
updatedAt?: string;
|
|
757
|
+
}
|
|
758
|
+
interface ApiResponse<T> {
|
|
759
|
+
success: boolean;
|
|
760
|
+
data?: T;
|
|
761
|
+
error?: string;
|
|
762
|
+
status: number;
|
|
763
|
+
}
|
|
764
|
+
interface PaginatedResponse<T> {
|
|
765
|
+
data: T[];
|
|
766
|
+
pagination: {
|
|
767
|
+
page: number;
|
|
768
|
+
limit: number;
|
|
769
|
+
total: number;
|
|
770
|
+
pages: number;
|
|
771
|
+
};
|
|
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 {
|
|
819
775
|
/**
|
|
820
|
-
*
|
|
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'
|
|
821
779
|
*/
|
|
822
|
-
|
|
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
|
+
}
|
|
895
|
+
|
|
896
|
+
/**
|
|
897
|
+
* Clianta SDK - Main Tracker Class
|
|
898
|
+
* @see SDK_VERSION in core/config.ts
|
|
899
|
+
*/
|
|
900
|
+
|
|
901
|
+
/**
|
|
902
|
+
* Main Clianta Tracker Class
|
|
903
|
+
*/
|
|
904
|
+
declare class Tracker implements TrackerCore {
|
|
905
|
+
private workspaceId;
|
|
906
|
+
private config;
|
|
907
|
+
private transport;
|
|
908
|
+
private queue;
|
|
909
|
+
private plugins;
|
|
910
|
+
private visitorId;
|
|
911
|
+
private sessionId;
|
|
912
|
+
private isInitialized;
|
|
913
|
+
private consentManager;
|
|
914
|
+
/** contactId after a successful identify() call */
|
|
915
|
+
private contactId;
|
|
916
|
+
/** Pending identify retry on next flush */
|
|
917
|
+
private pendingIdentify;
|
|
918
|
+
constructor(workspaceId: string, userConfig?: CliantaConfig);
|
|
823
919
|
/**
|
|
824
|
-
*
|
|
920
|
+
* Create visitor ID based on storage mode
|
|
825
921
|
*/
|
|
826
|
-
|
|
922
|
+
private createVisitorId;
|
|
827
923
|
/**
|
|
828
|
-
*
|
|
924
|
+
* Create session ID
|
|
829
925
|
*/
|
|
830
|
-
|
|
926
|
+
private createSessionId;
|
|
831
927
|
/**
|
|
832
|
-
*
|
|
928
|
+
* Handle consent state changes
|
|
833
929
|
*/
|
|
834
|
-
|
|
835
|
-
page?: number;
|
|
836
|
-
limit?: number;
|
|
837
|
-
type?: string;
|
|
838
|
-
}): Promise<ApiResponse<PaginatedResponse<Activity>>>;
|
|
930
|
+
private onConsentChange;
|
|
839
931
|
/**
|
|
840
|
-
*
|
|
932
|
+
* Initialize enabled plugins
|
|
933
|
+
* Handles both sync and async plugin init methods
|
|
841
934
|
*/
|
|
842
|
-
|
|
843
|
-
page?: number;
|
|
844
|
-
limit?: number;
|
|
845
|
-
type?: string;
|
|
846
|
-
}): Promise<ApiResponse<PaginatedResponse<Activity>>>;
|
|
935
|
+
private initPlugins;
|
|
847
936
|
/**
|
|
848
|
-
*
|
|
937
|
+
* Track a custom event
|
|
849
938
|
*/
|
|
850
|
-
|
|
939
|
+
track(eventType: EventType | string, eventName: string, properties?: Record<string, unknown>): void;
|
|
851
940
|
/**
|
|
852
|
-
*
|
|
941
|
+
* Track a page view
|
|
853
942
|
*/
|
|
854
|
-
|
|
943
|
+
page(name?: string, properties?: Record<string, unknown>): void;
|
|
855
944
|
/**
|
|
856
|
-
*
|
|
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.
|
|
857
948
|
*/
|
|
858
|
-
|
|
949
|
+
identify(email: string, traits?: UserTraits): Promise<string | null>;
|
|
859
950
|
/**
|
|
860
|
-
*
|
|
951
|
+
* Send a server-side inbound event via the API key endpoint.
|
|
952
|
+
* Convenience proxy to CRMClient.sendEvent() — requires apiKey in config.
|
|
861
953
|
*/
|
|
862
|
-
|
|
863
|
-
contactId?: string;
|
|
864
|
-
opportunityId?: string;
|
|
865
|
-
direction: 'inbound' | 'outbound';
|
|
866
|
-
duration?: number;
|
|
867
|
-
outcome?: string;
|
|
868
|
-
notes?: string;
|
|
869
|
-
}): Promise<ApiResponse<Activity>>;
|
|
954
|
+
sendEvent(payload: InboundEventPayload): Promise<InboundEventResult>;
|
|
870
955
|
/**
|
|
871
|
-
*
|
|
956
|
+
* Retry pending identify call
|
|
872
957
|
*/
|
|
873
|
-
|
|
874
|
-
contactId?: string;
|
|
875
|
-
opportunityId?: string;
|
|
876
|
-
title: string;
|
|
877
|
-
duration?: number;
|
|
878
|
-
outcome?: string;
|
|
879
|
-
notes?: string;
|
|
880
|
-
}): Promise<ApiResponse<Activity>>;
|
|
958
|
+
private retryPendingIdentify;
|
|
881
959
|
/**
|
|
882
|
-
*
|
|
960
|
+
* Update consent state
|
|
883
961
|
*/
|
|
884
|
-
|
|
885
|
-
contactId?: string;
|
|
886
|
-
opportunityId?: string;
|
|
887
|
-
content: string;
|
|
888
|
-
}): Promise<ApiResponse<Activity>>;
|
|
962
|
+
consent(state: ConsentState): void;
|
|
889
963
|
/**
|
|
890
|
-
* Get
|
|
964
|
+
* Get current consent state
|
|
891
965
|
*/
|
|
892
|
-
|
|
893
|
-
page?: number;
|
|
894
|
-
limit?: number;
|
|
895
|
-
}): Promise<ApiResponse<PaginatedResponse<EmailTemplate>>>;
|
|
966
|
+
getConsentState(): ConsentState;
|
|
896
967
|
/**
|
|
897
|
-
*
|
|
968
|
+
* Toggle debug mode
|
|
898
969
|
*/
|
|
899
|
-
|
|
970
|
+
debug(enabled: boolean): void;
|
|
900
971
|
/**
|
|
901
|
-
*
|
|
972
|
+
* Get visitor ID
|
|
902
973
|
*/
|
|
903
|
-
|
|
974
|
+
getVisitorId(): string;
|
|
904
975
|
/**
|
|
905
|
-
*
|
|
976
|
+
* Get session ID
|
|
906
977
|
*/
|
|
907
|
-
|
|
978
|
+
getSessionId(): string;
|
|
908
979
|
/**
|
|
909
|
-
*
|
|
980
|
+
* Get workspace ID
|
|
910
981
|
*/
|
|
911
|
-
|
|
982
|
+
getWorkspaceId(): string;
|
|
912
983
|
/**
|
|
913
|
-
*
|
|
984
|
+
* Get current configuration
|
|
914
985
|
*/
|
|
915
|
-
|
|
916
|
-
to: string;
|
|
917
|
-
templateId?: string;
|
|
918
|
-
subject?: string;
|
|
919
|
-
body?: string;
|
|
920
|
-
cc?: string[];
|
|
921
|
-
bcc?: string[];
|
|
922
|
-
variables?: Record<string, unknown>;
|
|
923
|
-
contactId?: string;
|
|
924
|
-
}): Promise<ApiResponse<{
|
|
925
|
-
messageId: string;
|
|
926
|
-
}>>;
|
|
986
|
+
getConfig(): CliantaConfig;
|
|
927
987
|
/**
|
|
928
|
-
*
|
|
988
|
+
* Force flush event queue
|
|
929
989
|
*/
|
|
930
|
-
|
|
990
|
+
flush(): Promise<void>;
|
|
931
991
|
/**
|
|
932
|
-
*
|
|
992
|
+
* Reset visitor and session (for logout)
|
|
933
993
|
*/
|
|
934
|
-
|
|
994
|
+
reset(): void;
|
|
935
995
|
/**
|
|
936
|
-
*
|
|
996
|
+
* Delete all stored user data (GDPR right-to-erasure)
|
|
937
997
|
*/
|
|
938
|
-
|
|
998
|
+
deleteData(): void;
|
|
939
999
|
/**
|
|
940
|
-
*
|
|
1000
|
+
* Destroy tracker and cleanup
|
|
941
1001
|
*/
|
|
942
|
-
|
|
1002
|
+
destroy(): Promise<void>;
|
|
943
1003
|
}
|
|
944
1004
|
|
|
945
1005
|
/**
|
|
@@ -1038,7 +1098,7 @@ interface StoredConsent {
|
|
|
1038
1098
|
*/
|
|
1039
1099
|
|
|
1040
1100
|
/** SDK Version */
|
|
1041
|
-
declare const SDK_VERSION = "1.
|
|
1101
|
+
declare const SDK_VERSION = "1.4.0";
|
|
1042
1102
|
|
|
1043
1103
|
/**
|
|
1044
1104
|
* Clianta SDK
|
|
@@ -1073,4 +1133,4 @@ declare const SDK_VERSION = "1.3.0";
|
|
|
1073
1133
|
declare function clianta(workspaceId: string, config?: CliantaConfig): TrackerCore;
|
|
1074
1134
|
|
|
1075
1135
|
export { CRMClient, ConsentManager, EventTriggersManager, SDK_VERSION, Tracker, clianta, clianta as default };
|
|
1076
|
-
export type { Activity, ApiResponse, CliantaConfig, Company, ConsentChangeCallback, ConsentConfig, ConsentManagerConfig, ConsentState, Contact, ContactUpdateAction, EmailAction, EmailTemplate, EventTrigger, EventType, Opportunity, PaginatedResponse, Pipeline, PipelineStage, Plugin, PluginName, StoredConsent, Task, TaskAction, TrackerCore, TrackingEvent, TriggerAction, TriggerCondition, TriggerEventType, TriggerExecution, UserTraits, WebhookAction };
|
|
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 };
|