@clianta/sdk 1.5.1 → 1.6.1

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.d.ts CHANGED
@@ -1,33 +1,3 @@
1
- /**
2
- * Clianta SDK - CRM API Client
3
- * @see SDK_VERSION in core/config.ts
4
- */
5
-
6
- type InboundEventType = 'user.registered' | 'user.updated' | 'user.subscribed' | 'user.unsubscribed' | 'contact.created' | 'contact.updated' | 'purchase.completed';
7
- interface InboundEventPayload {
8
- /** Event type (e.g. "user.registered") */
9
- event: InboundEventType;
10
- /** Contact data — at least email or phone is required */
11
- contact: {
12
- email?: string;
13
- phone?: string;
14
- firstName?: string;
15
- lastName?: string;
16
- company?: string;
17
- jobTitle?: string;
18
- tags?: string[];
19
- };
20
- /** Optional extra data stored as customFields on the contact */
21
- data?: Record<string, unknown>;
22
- }
23
- interface InboundEventResult {
24
- success: boolean;
25
- contactCreated: boolean;
26
- contactId?: string;
27
- event: string;
28
- error?: string;
29
- }
30
-
31
1
  /**
32
2
  * Clianta SDK - Type Definitions
33
3
  * @see SDK_VERSION in core/config.ts
@@ -37,10 +7,6 @@ interface CliantaConfig {
37
7
  projectId?: string;
38
8
  /** Backend API endpoint URL */
39
9
  apiEndpoint?: string;
40
- /** Auth token for server-side API access (user JWT) */
41
- authToken?: string;
42
- /** Workspace API key for server-to-server access (use instead of authToken for external apps) */
43
- apiKey?: string;
44
10
  /** Enable debug mode with verbose logging */
45
11
  debug?: boolean;
46
12
  /** Automatically track page views on load and navigation */
@@ -84,6 +50,63 @@ interface ConsentState {
84
50
  personalization?: boolean;
85
51
  }
86
52
  type EventType = 'page_view' | 'button_click' | 'form_view' | 'form_submit' | 'form_interaction' | 'scroll_depth' | 'engagement' | 'download' | 'exit_intent' | 'error' | 'performance' | 'time_on_page' | 'custom';
53
+ interface TrackingEvent {
54
+ /** Workspace/project ID */
55
+ workspaceId: string;
56
+ /** Anonymous visitor identifier */
57
+ visitorId: string;
58
+ /** Session identifier */
59
+ sessionId: string;
60
+ /** Event type category */
61
+ eventType: EventType;
62
+ /** Human-readable event name */
63
+ eventName: string;
64
+ /** Current page URL */
65
+ url: string;
66
+ /** Referrer URL */
67
+ referrer?: string;
68
+ /** Event properties/metadata */
69
+ properties: Record<string, unknown>;
70
+ /** Device information */
71
+ device: DeviceInfo;
72
+ /** UTM parameters */
73
+ utm?: UTMParams;
74
+ /** ISO timestamp */
75
+ timestamp: string;
76
+ /** SDK version */
77
+ sdkVersion: string;
78
+ }
79
+ interface DeviceInfo {
80
+ userAgent: string;
81
+ screen: string;
82
+ language: string;
83
+ timezone?: string;
84
+ }
85
+ interface UTMParams {
86
+ utmSource?: string;
87
+ utmMedium?: string;
88
+ utmCampaign?: string;
89
+ utmTerm?: string;
90
+ utmContent?: string;
91
+ }
92
+ interface GroupTraits {
93
+ /** Company/account name */
94
+ name?: string;
95
+ /** Industry */
96
+ industry?: string;
97
+ /** Company size */
98
+ employees?: number;
99
+ /** Annual revenue */
100
+ revenue?: number;
101
+ /** Company website */
102
+ website?: string;
103
+ /** Company plan/tier */
104
+ plan?: string;
105
+ /** Additional custom properties */
106
+ [key: string]: unknown;
107
+ }
108
+ /** Event middleware function — intercept or transform events before they are sent */
109
+ type MiddlewareFn = (event: TrackingEvent, next: () => void) => void;
87
110
  interface UserTraits {
88
111
  firstName?: string;
89
112
  lastName?: string;
@@ -119,24 +142,18 @@ interface TrackerCore {
119
142
  deleteData(): void;
120
143
  /** Get current consent state */
121
144
  getConsentState(): ConsentState;
122
- /** Get the current visitor's profile from the CRM */
123
- getVisitorProfile(): Promise<VisitorProfile | null>;
124
- /** Get the current visitor's recent activity */
125
- getVisitorActivity(options?: VisitorActivityOptions): Promise<{
126
- data: VisitorActivity[];
127
- pagination: {
128
- page: number;
129
- limit: number;
130
- total: number;
131
- pages: number;
132
- };
133
- } | null>;
134
- /** Get a summarized journey timeline for the current visitor */
135
- getVisitorTimeline(): Promise<VisitorTimeline | null>;
136
- /** Get engagement metrics for the current visitor */
137
- getVisitorEngagement(): Promise<EngagementMetrics | null>;
138
- /** Send a server-side inbound event (requires apiKey in config) */
139
- sendEvent(payload: InboundEventPayload): Promise<InboundEventResult>;
145
+ /** Associate the current visitor with a group (company/account) */
146
+ group(groupId: string, traits?: GroupTraits): void;
147
+ /** Merge two visitor identities (e.g., anonymous → logged-in) */
148
+ alias(newId: string, previousId?: string): Promise<boolean>;
149
+ /** Track a screen view (for mobile-first PWAs and SPAs) */
150
+ screen(name: string, properties?: Record<string, unknown>): void;
151
+ /** Register event middleware to intercept/transform events before sending */
152
+ use(middleware: MiddlewareFn): void;
153
+ /** Register a callback to be invoked when the SDK is fully initialized */
154
+ onReady(callback: () => void): void;
155
+ /** Check if the SDK is fully initialized and ready */
156
+ isReady(): boolean;
140
157
  /** Create or update a contact by email (upsert) */
141
158
  createContact(data: PublicContactData): Promise<PublicCrmResult>;
142
159
  /** Update an existing contact by ID (limited fields) */
@@ -148,76 +165,6 @@ interface TrackerCore {
148
165
  /** Create an opportunity (e.g., from "Request Demo" forms) */
149
166
  createOpportunity(data: PublicOpportunityData): Promise<PublicCrmResult>;
150
167
  }
151
- interface VisitorProfile {
152
- visitorId: string;
153
- contactId?: string;
154
- email?: string;
155
- firstName?: string;
156
- lastName?: string;
157
- company?: string;
158
- jobTitle?: string;
159
- phone?: string;
160
- status?: string;
161
- lifecycleStage?: string;
162
- tags?: string[];
163
- leadScore?: number;
164
- firstSeen?: string;
165
- lastSeen?: string;
166
- sessionCount?: number;
167
- pageViewCount?: number;
168
- totalTimeSpent?: number;
169
- customFields?: Record<string, unknown>;
170
- }
171
- interface VisitorActivity {
172
- _id?: string;
173
- eventType: string;
174
- eventName: string;
175
- url: string;
176
- properties?: Record<string, unknown>;
177
- timestamp: string;
178
- }
179
- interface VisitorTimeline {
180
- visitorId: string;
181
- contactId?: string;
182
- firstSeen: string;
183
- lastSeen: string;
184
- totalSessions: number;
185
- totalPageViews: number;
186
- totalEvents: number;
187
- totalTimeSpentSeconds: number;
188
- averageSessionDurationSeconds: number;
189
- topPages: Array<{
190
- url: string;
191
- views: number;
192
- avgTimeSeconds?: number;
193
- }>;
194
- recentActivities: VisitorActivity[];
195
- devices: Array<{
196
- userAgent: string;
197
- lastSeen: string;
198
- }>;
199
- }
200
- interface EngagementMetrics {
201
- visitorId: string;
202
- totalTimeOnSiteSeconds: number;
203
- averageSessionDurationSeconds: number;
204
- totalPageViews: number;
205
- totalSessions: number;
206
- engagementScore: number;
207
- bounceRate: number;
208
- lastActiveAt: string;
209
- topEvents: Array<{
210
- eventType: string;
211
- count: number;
212
- }>;
213
- }
214
- interface VisitorActivityOptions {
215
- page?: number;
216
- limit?: number;
217
- eventType?: string;
218
- startDate?: string;
219
- endDate?: string;
220
- }
221
168
  interface PublicContactData {
222
169
  email: string;
223
170
  firstName?: string;