@clianta/sdk 1.5.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 +16 -0
- package/dist/angular.cjs.js +100 -13
- package/dist/angular.cjs.js.map +1 -1
- package/dist/angular.d.ts +67 -1
- package/dist/angular.esm.js +100 -13
- package/dist/angular.esm.js.map +1 -1
- package/dist/clianta.cjs.js +99 -12
- package/dist/clianta.cjs.js.map +1 -1
- package/dist/clianta.esm.js +99 -12
- package/dist/clianta.esm.js.map +1 -1
- package/dist/clianta.umd.js +99 -12
- 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 +93 -2
- package/dist/react.cjs.js +100 -13
- package/dist/react.cjs.js.map +1 -1
- package/dist/react.d.ts +67 -1
- package/dist/react.esm.js +100 -13
- package/dist/react.esm.js.map +1 -1
- package/dist/svelte.cjs.js +100 -13
- package/dist/svelte.cjs.js.map +1 -1
- package/dist/svelte.d.ts +67 -1
- package/dist/svelte.esm.js +100 -13
- package/dist/svelte.esm.js.map +1 -1
- package/dist/vue.cjs.js +100 -13
- package/dist/vue.cjs.js.map +1 -1
- package/dist/vue.d.ts +67 -1
- package/dist/vue.esm.js +100 -13
- package/dist/vue.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/react.d.ts
CHANGED
|
@@ -140,6 +140,16 @@ interface TrackerCore {
|
|
|
140
140
|
getVisitorEngagement(): Promise<EngagementMetrics | null>;
|
|
141
141
|
/** Send a server-side inbound event (requires apiKey in config) */
|
|
142
142
|
sendEvent(payload: InboundEventPayload): Promise<InboundEventResult>;
|
|
143
|
+
/** Create or update a contact by email (upsert) */
|
|
144
|
+
createContact(data: PublicContactData): Promise<PublicCrmResult>;
|
|
145
|
+
/** Update an existing contact by ID (limited fields) */
|
|
146
|
+
updateContact(contactId: string, data: PublicContactUpdate): Promise<PublicCrmResult>;
|
|
147
|
+
/** Submit a form — creates/updates contact from form data */
|
|
148
|
+
submitForm(formId: string, data: PublicFormSubmission): Promise<PublicCrmResult>;
|
|
149
|
+
/** Log an activity linked to a contact (append-only) */
|
|
150
|
+
logActivity(data: PublicActivityData): Promise<PublicCrmResult>;
|
|
151
|
+
/** Create an opportunity (e.g., from "Request Demo" forms) */
|
|
152
|
+
createOpportunity(data: PublicOpportunityData): Promise<PublicCrmResult>;
|
|
143
153
|
}
|
|
144
154
|
interface VisitorProfile {
|
|
145
155
|
visitorId: string;
|
|
@@ -211,6 +221,62 @@ interface VisitorActivityOptions {
|
|
|
211
221
|
startDate?: string;
|
|
212
222
|
endDate?: string;
|
|
213
223
|
}
|
|
224
|
+
interface PublicContactData {
|
|
225
|
+
email: string;
|
|
226
|
+
firstName?: string;
|
|
227
|
+
lastName?: string;
|
|
228
|
+
company?: string;
|
|
229
|
+
jobTitle?: string;
|
|
230
|
+
phone?: string;
|
|
231
|
+
source?: string;
|
|
232
|
+
tags?: string[];
|
|
233
|
+
customFields?: Record<string, unknown>;
|
|
234
|
+
}
|
|
235
|
+
interface PublicContactUpdate {
|
|
236
|
+
firstName?: string;
|
|
237
|
+
lastName?: string;
|
|
238
|
+
company?: string;
|
|
239
|
+
jobTitle?: string;
|
|
240
|
+
phone?: string;
|
|
241
|
+
tags?: string[];
|
|
242
|
+
customFields?: Record<string, unknown>;
|
|
243
|
+
}
|
|
244
|
+
interface PublicActivityData {
|
|
245
|
+
contactId: string;
|
|
246
|
+
type: 'call' | 'email' | 'meeting' | 'note' | 'other';
|
|
247
|
+
title: string;
|
|
248
|
+
description?: string;
|
|
249
|
+
direction?: 'inbound' | 'outbound';
|
|
250
|
+
duration?: number;
|
|
251
|
+
emailSubject?: string;
|
|
252
|
+
metadata?: Record<string, unknown>;
|
|
253
|
+
}
|
|
254
|
+
interface PublicOpportunityData {
|
|
255
|
+
title: string;
|
|
256
|
+
contactId: string;
|
|
257
|
+
pipelineId: string;
|
|
258
|
+
stageId: string;
|
|
259
|
+
value?: number;
|
|
260
|
+
currency?: string;
|
|
261
|
+
description?: string;
|
|
262
|
+
expectedCloseDate?: string;
|
|
263
|
+
customFields?: Record<string, unknown>;
|
|
264
|
+
}
|
|
265
|
+
interface PublicFormSubmission {
|
|
266
|
+
fields: Record<string, unknown>;
|
|
267
|
+
metadata?: {
|
|
268
|
+
visitorId?: string;
|
|
269
|
+
sessionId?: string;
|
|
270
|
+
pageUrl?: string;
|
|
271
|
+
referrer?: string;
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
interface PublicCrmResult {
|
|
275
|
+
success: boolean;
|
|
276
|
+
data?: Record<string, unknown>;
|
|
277
|
+
error?: string;
|
|
278
|
+
status?: number;
|
|
279
|
+
}
|
|
214
280
|
|
|
215
281
|
interface CliantaProviderProps {
|
|
216
282
|
/** Configuration object (from clianta.config.ts) */
|
|
@@ -227,7 +293,7 @@ interface CliantaProviderProps {
|
|
|
227
293
|
*
|
|
228
294
|
* const config: CliantaConfig = {
|
|
229
295
|
* projectId: 'your-project-id',
|
|
230
|
-
* apiEndpoint:
|
|
296
|
+
* apiEndpoint: process.env.NEXT_PUBLIC_CLIANTA_API_ENDPOINT || 'http://localhost:5000',
|
|
231
297
|
* debug: process.env.NODE_ENV === 'development',
|
|
232
298
|
* };
|
|
233
299
|
*
|
package/dist/react.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* Clianta SDK v1.5.
|
|
2
|
+
* Clianta SDK v1.5.1
|
|
3
3
|
* (c) 2026 Clianta
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -12,15 +12,22 @@ import { createContext, useState, useRef, useEffect, useContext } from 'react';
|
|
|
12
12
|
*/
|
|
13
13
|
/** SDK Version */
|
|
14
14
|
const SDK_VERSION = '1.4.0';
|
|
15
|
-
/** Default API endpoint
|
|
15
|
+
/** Default API endpoint — reads from env or falls back to localhost */
|
|
16
16
|
const getDefaultApiEndpoint = () => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
// Build-time env var (works with Next.js, Vite, CRA, etc.)
|
|
18
|
+
if (typeof process !== 'undefined' && process.env?.NEXT_PUBLIC_CLIANTA_API_ENDPOINT) {
|
|
19
|
+
return process.env.NEXT_PUBLIC_CLIANTA_API_ENDPOINT;
|
|
20
|
+
}
|
|
21
|
+
if (typeof process !== 'undefined' && process.env?.VITE_CLIANTA_API_ENDPOINT) {
|
|
22
|
+
return process.env.VITE_CLIANTA_API_ENDPOINT;
|
|
23
|
+
}
|
|
24
|
+
if (typeof process !== 'undefined' && process.env?.REACT_APP_CLIANTA_API_ENDPOINT) {
|
|
25
|
+
return process.env.REACT_APP_CLIANTA_API_ENDPOINT;
|
|
22
26
|
}
|
|
23
|
-
|
|
27
|
+
if (typeof process !== 'undefined' && process.env?.CLIANTA_API_ENDPOINT) {
|
|
28
|
+
return process.env.CLIANTA_API_ENDPOINT;
|
|
29
|
+
}
|
|
30
|
+
return 'http://localhost:5000';
|
|
24
31
|
};
|
|
25
32
|
/** Core plugins enabled by default */
|
|
26
33
|
const DEFAULT_PLUGINS = [
|
|
@@ -1782,7 +1789,7 @@ class PopupFormsPlugin extends BasePlugin {
|
|
|
1782
1789
|
return;
|
|
1783
1790
|
const config = this.tracker.getConfig();
|
|
1784
1791
|
const workspaceId = this.tracker.getWorkspaceId();
|
|
1785
|
-
const apiEndpoint = config.apiEndpoint || '
|
|
1792
|
+
const apiEndpoint = config.apiEndpoint || 'http://localhost:5000';
|
|
1786
1793
|
try {
|
|
1787
1794
|
const url = encodeURIComponent(window.location.href);
|
|
1788
1795
|
const response = await fetch(`${apiEndpoint}/api/public/lead-forms/${workspaceId}?url=${url}`);
|
|
@@ -1887,7 +1894,7 @@ class PopupFormsPlugin extends BasePlugin {
|
|
|
1887
1894
|
if (!this.tracker)
|
|
1888
1895
|
return;
|
|
1889
1896
|
const config = this.tracker.getConfig();
|
|
1890
|
-
const apiEndpoint = config.apiEndpoint || '
|
|
1897
|
+
const apiEndpoint = config.apiEndpoint || 'http://localhost:5000';
|
|
1891
1898
|
try {
|
|
1892
1899
|
await fetch(`${apiEndpoint}/api/public/lead-forms/${formId}/view`, {
|
|
1893
1900
|
method: 'POST',
|
|
@@ -2134,7 +2141,7 @@ class PopupFormsPlugin extends BasePlugin {
|
|
|
2134
2141
|
if (!this.tracker)
|
|
2135
2142
|
return;
|
|
2136
2143
|
const config = this.tracker.getConfig();
|
|
2137
|
-
const apiEndpoint = config.apiEndpoint || '
|
|
2144
|
+
const apiEndpoint = config.apiEndpoint || 'http://localhost:5000';
|
|
2138
2145
|
const visitorId = this.tracker.getVisitorId();
|
|
2139
2146
|
// Collect form data
|
|
2140
2147
|
const formData = new FormData(formElement);
|
|
@@ -3029,7 +3036,7 @@ class CRMClient {
|
|
|
3029
3036
|
* The contact is upserted in the CRM and matching workflow automations fire automatically.
|
|
3030
3037
|
*
|
|
3031
3038
|
* @example
|
|
3032
|
-
* const crm = new CRMClient('
|
|
3039
|
+
* const crm = new CRMClient('http://localhost:5000', 'WORKSPACE_ID');
|
|
3033
3040
|
* crm.setApiKey('mm_live_...');
|
|
3034
3041
|
*
|
|
3035
3042
|
* await crm.sendEvent({
|
|
@@ -4169,6 +4176,86 @@ class Tracker {
|
|
|
4169
4176
|
this.sessionId = this.createSessionId();
|
|
4170
4177
|
logger.info('All user data deleted');
|
|
4171
4178
|
}
|
|
4179
|
+
// ============================================
|
|
4180
|
+
// PUBLIC CRM METHODS (no API key required)
|
|
4181
|
+
// ============================================
|
|
4182
|
+
/**
|
|
4183
|
+
* Create or update a contact by email (upsert).
|
|
4184
|
+
* Secured by domain whitelist — no API key needed.
|
|
4185
|
+
*/
|
|
4186
|
+
async createContact(data) {
|
|
4187
|
+
return this.publicCrmRequest('/api/public/crm/contacts', 'POST', {
|
|
4188
|
+
workspaceId: this.workspaceId,
|
|
4189
|
+
...data,
|
|
4190
|
+
});
|
|
4191
|
+
}
|
|
4192
|
+
/**
|
|
4193
|
+
* Update an existing contact by ID (limited fields only).
|
|
4194
|
+
*/
|
|
4195
|
+
async updateContact(contactId, data) {
|
|
4196
|
+
return this.publicCrmRequest(`/api/public/crm/contacts/${contactId}`, 'PUT', {
|
|
4197
|
+
workspaceId: this.workspaceId,
|
|
4198
|
+
...data,
|
|
4199
|
+
});
|
|
4200
|
+
}
|
|
4201
|
+
/**
|
|
4202
|
+
* Submit a form — creates/updates contact from form data.
|
|
4203
|
+
*/
|
|
4204
|
+
async submitForm(formId, data) {
|
|
4205
|
+
const payload = {
|
|
4206
|
+
...data,
|
|
4207
|
+
metadata: {
|
|
4208
|
+
...data.metadata,
|
|
4209
|
+
visitorId: this.visitorId,
|
|
4210
|
+
sessionId: this.sessionId,
|
|
4211
|
+
pageUrl: typeof window !== 'undefined' ? window.location.href : undefined,
|
|
4212
|
+
referrer: typeof document !== 'undefined' ? document.referrer || undefined : undefined,
|
|
4213
|
+
},
|
|
4214
|
+
};
|
|
4215
|
+
return this.publicCrmRequest(`/api/public/crm/forms/${formId}/submit`, 'POST', payload);
|
|
4216
|
+
}
|
|
4217
|
+
/**
|
|
4218
|
+
* Log an activity linked to a contact (append-only).
|
|
4219
|
+
*/
|
|
4220
|
+
async logActivity(data) {
|
|
4221
|
+
return this.publicCrmRequest('/api/public/crm/activities', 'POST', {
|
|
4222
|
+
workspaceId: this.workspaceId,
|
|
4223
|
+
...data,
|
|
4224
|
+
});
|
|
4225
|
+
}
|
|
4226
|
+
/**
|
|
4227
|
+
* Create an opportunity (e.g., from "Request Demo" forms).
|
|
4228
|
+
*/
|
|
4229
|
+
async createOpportunity(data) {
|
|
4230
|
+
return this.publicCrmRequest('/api/public/crm/opportunities', 'POST', {
|
|
4231
|
+
workspaceId: this.workspaceId,
|
|
4232
|
+
...data,
|
|
4233
|
+
});
|
|
4234
|
+
}
|
|
4235
|
+
/**
|
|
4236
|
+
* Internal helper for public CRM API calls.
|
|
4237
|
+
*/
|
|
4238
|
+
async publicCrmRequest(path, method, body) {
|
|
4239
|
+
const url = `${this.config.apiEndpoint}${path}`;
|
|
4240
|
+
try {
|
|
4241
|
+
const response = await fetch(url, {
|
|
4242
|
+
method,
|
|
4243
|
+
headers: { 'Content-Type': 'application/json' },
|
|
4244
|
+
body: JSON.stringify(body),
|
|
4245
|
+
});
|
|
4246
|
+
const data = await response.json().catch(() => ({}));
|
|
4247
|
+
if (response.ok) {
|
|
4248
|
+
logger.debug(`Public CRM ${method} ${path} succeeded`);
|
|
4249
|
+
return { success: true, data: data.data ?? data, status: response.status };
|
|
4250
|
+
}
|
|
4251
|
+
logger.error(`Public CRM ${method} ${path} failed (${response.status}):`, data.message);
|
|
4252
|
+
return { success: false, error: data.message, status: response.status };
|
|
4253
|
+
}
|
|
4254
|
+
catch (error) {
|
|
4255
|
+
logger.error(`Public CRM ${method} ${path} error:`, error);
|
|
4256
|
+
return { success: false, error: error.message };
|
|
4257
|
+
}
|
|
4258
|
+
}
|
|
4172
4259
|
/**
|
|
4173
4260
|
* Destroy tracker and cleanup
|
|
4174
4261
|
*/
|
|
@@ -4262,7 +4349,7 @@ const CliantaContext = createContext(null);
|
|
|
4262
4349
|
*
|
|
4263
4350
|
* const config: CliantaConfig = {
|
|
4264
4351
|
* projectId: 'your-project-id',
|
|
4265
|
-
* apiEndpoint:
|
|
4352
|
+
* apiEndpoint: process.env.NEXT_PUBLIC_CLIANTA_API_ENDPOINT || 'http://localhost:5000',
|
|
4266
4353
|
* debug: process.env.NODE_ENV === 'development',
|
|
4267
4354
|
* };
|
|
4268
4355
|
*
|