@clianta/sdk 1.4.0 → 1.5.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/CHANGELOG.md CHANGED
@@ -5,6 +5,52 @@ All notable changes to the Clianta SDK will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.5.1] - 2026-02-28
9
+
10
+ ### Added
11
+ - **Public CRM API** — Frontend-safe CRM methods that don't require an API key (secured by domain whitelist):
12
+ - `createContact()` — Create or upsert a contact by email
13
+ - `updateContact()` — Update an existing contact by ID
14
+ - `submitForm()` — Submit a form and auto-create/update contact
15
+ - `logActivity()` — Append an activity to a contact
16
+ - `createOpportunity()` — Create an opportunity (e.g., from "Request Demo" forms)
17
+ - **Public CRM types** — `PublicContactData`, `PublicContactUpdate`, `PublicFormSubmission`, `PublicActivityData`, `PublicOpportunityData`, `PublicCrmResult`
18
+ - **Updated docs** — API Reference and Getting Started guides updated with public CRM usage
19
+
20
+ ### Changed
21
+ - Config: improved `getDefaultApiEndpoint()` with env variable support
22
+ - Framework integrations: minor fixes for Angular, Svelte, Vue, React
23
+
24
+ ## [1.5.0] - 2026-02-28
25
+
26
+ ### Security
27
+ - **Cookie `Secure` flag** — Cookies now include `; Secure` on HTTPS connections, preventing visitor IDs from leaking over plaintext
28
+ - **Open redirect prevention** — `redirectUrl` in popup forms is validated before navigation; blocks `javascript:`, `data:`, and other dangerous protocols
29
+ - **API key browser warning** — Console warning when `apiKey` is used in client-side code (should be server-side only)
30
+ - **HTTPS endpoint warning** — Console warning when `apiEndpoint` uses HTTP in production
31
+ - **Email validation** — `identify()` validates email format before sending to server
32
+ - **Queue moved to sessionStorage** — Event queue no longer persists in localStorage by default (configurable via `persistMode`)
33
+ - **innerHTML → textContent** — Popup form submit button uses safe DOM API
34
+
35
+ ### Fixed
36
+ - **CRITICAL: Double `history.pushState` patching** — ScrollPlugin and PageViewPlugin were both monkey-patching the History API independently, causing double page view events on SPA navigation. ScrollPlugin now listens for a `clianta:navigation` custom event instead
37
+ - **CRITICAL: React `useEffect` re-initialization** — `CliantaProvider` was destroying and recreating the tracker on every render when config was defined inline (object ref changed). Now depends on `config.projectId` (stable string)
38
+ - **React context null on first render** — Switched from `useRef` to `useState` for tracker instance so context re-renders when ready
39
+ - **PopupForms cleanup** — Delay timers and click trigger listeners are now properly tracked and cleaned up on `destroy()`
40
+ - **`reset()` cleanup** — Now clears `contactId` and `pendingIdentify` alongside visitor/session IDs
41
+
42
+ ### Added
43
+ - **Visitor APIs** — `getVisitorProfile()`, `getVisitorActivity()`, `getVisitorTimeline()`, `getVisitorEngagement()` for fetching visitor data from the CRM
44
+ - **Event schema validation** — `registerEventSchema()` validates event properties in debug mode
45
+ - **`persistMode` config** — Choose `'session'` (default), `'local'` (cross-session), or `'none'` for queue persistence
46
+ - **`websiteDomain` property** — Automatically included on all tracked events
47
+ - **Angular integration** — `@clianta/sdk/angular` module
48
+ - **Svelte integration** — `@clianta/sdk/svelte` module
49
+
50
+ ### Changed
51
+ - `CliantaProvider` uses `useState` instead of `useRef` for tracker instance
52
+ - Queue persistence defaults to `sessionStorage` (was `localStorage`)
53
+
8
54
  ## [1.4.0] - 2026-02-27
9
55
 
10
56
  ### Fixed
package/README.md CHANGED
@@ -9,7 +9,8 @@ Professional CRM and tracking SDK for lead generation with **automated email tri
9
9
  - 🤖 **Event Triggers & Automation** - Automated emails, tasks, and webhooks (like Salesforce & HubSpot)
10
10
  - 📧 **Email Notifications** - Send automated emails based on CRM actions
11
11
  - 🔒 **GDPR Compliant** - Built-in consent management
12
- - **Framework Agnostic** - Works with React, Vue, Next.js, or vanilla JavaScript
12
+ - 🔍 **Read-Back APIs** - Fetch visitor profiles, activity, timeline, and engagement metrics
13
+ - ⚡ **Framework Support** - React, Vue, Angular, Svelte, Next.js, or vanilla JavaScript
13
14
 
14
15
  ## Installation
15
16
 
@@ -361,6 +362,60 @@ tracker.reset();
361
362
 
362
363
  ---
363
364
 
365
+ ## Read-Back APIs
366
+
367
+ ### Frontend (Own Visitor Data)
368
+
369
+ Fetch the current visitor's data directly from the SDK:
370
+
371
+ ```typescript
372
+ // Get visitor's CRM profile
373
+ const profile = await tracker.getVisitorProfile();
374
+ console.log(profile?.firstName, profile?.email, profile?.leadScore);
375
+
376
+ // Get recent activity (paginated)
377
+ const activity = await tracker.getVisitorActivity({ limit: 20 });
378
+ activity?.data.forEach(event => {
379
+ console.log(event.eventType, event.eventName, event.timestamp);
380
+ });
381
+
382
+ // Get visitor journey timeline
383
+ const timeline = await tracker.getVisitorTimeline();
384
+ console.log('Total sessions:', timeline?.totalSessions);
385
+ console.log('Time on site:', timeline?.totalTimeSpentSeconds, 'sec');
386
+
387
+ // Get engagement metrics
388
+ const engagement = await tracker.getVisitorEngagement();
389
+ console.log('Score:', engagement?.engagementScore);
390
+ ```
391
+
392
+ ### Server-Side (Full CRM Access via API Key)
393
+
394
+ ```typescript
395
+ import { CRMClient } from '@clianta/sdk';
396
+
397
+ const crm = new CRMClient('https://api.clianta.online', 'workspace-id');
398
+ crm.setApiKey('mm_live_xxxxx');
399
+
400
+ // Look up contact by email
401
+ const contact = await crm.getContactByEmail('user@example.com');
402
+
403
+ // Get contact's activity history
404
+ const activity = await crm.getContactActivity(contact.data._id, { limit: 50 });
405
+
406
+ // Get engagement metrics
407
+ const engagement = await crm.getContactEngagement(contact.data._id);
408
+
409
+ // Search contacts
410
+ const results = await crm.searchContacts('john', { status: 'lead' });
411
+
412
+ // Manage webhooks
413
+ const webhooks = await crm.listWebhooks();
414
+ await crm.createWebhook({ url: 'https://example.com/hook', events: ['contact.created'] });
415
+ ```
416
+
417
+ ---
418
+
364
419
  ## GDPR Compliance
365
420
 
366
421
  ### Wait for Consent