@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.cjs.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
|
*/
|
|
@@ -14,15 +14,22 @@ var react = require('react');
|
|
|
14
14
|
*/
|
|
15
15
|
/** SDK Version */
|
|
16
16
|
const SDK_VERSION = '1.4.0';
|
|
17
|
-
/** Default API endpoint
|
|
17
|
+
/** Default API endpoint — reads from env or falls back to localhost */
|
|
18
18
|
const getDefaultApiEndpoint = () => {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
// Build-time env var (works with Next.js, Vite, CRA, etc.)
|
|
20
|
+
if (typeof process !== 'undefined' && process.env?.NEXT_PUBLIC_CLIANTA_API_ENDPOINT) {
|
|
21
|
+
return process.env.NEXT_PUBLIC_CLIANTA_API_ENDPOINT;
|
|
22
|
+
}
|
|
23
|
+
if (typeof process !== 'undefined' && process.env?.VITE_CLIANTA_API_ENDPOINT) {
|
|
24
|
+
return process.env.VITE_CLIANTA_API_ENDPOINT;
|
|
25
|
+
}
|
|
26
|
+
if (typeof process !== 'undefined' && process.env?.REACT_APP_CLIANTA_API_ENDPOINT) {
|
|
27
|
+
return process.env.REACT_APP_CLIANTA_API_ENDPOINT;
|
|
24
28
|
}
|
|
25
|
-
|
|
29
|
+
if (typeof process !== 'undefined' && process.env?.CLIANTA_API_ENDPOINT) {
|
|
30
|
+
return process.env.CLIANTA_API_ENDPOINT;
|
|
31
|
+
}
|
|
32
|
+
return 'http://localhost:5000';
|
|
26
33
|
};
|
|
27
34
|
/** Core plugins enabled by default */
|
|
28
35
|
const DEFAULT_PLUGINS = [
|
|
@@ -1784,7 +1791,7 @@ class PopupFormsPlugin extends BasePlugin {
|
|
|
1784
1791
|
return;
|
|
1785
1792
|
const config = this.tracker.getConfig();
|
|
1786
1793
|
const workspaceId = this.tracker.getWorkspaceId();
|
|
1787
|
-
const apiEndpoint = config.apiEndpoint || '
|
|
1794
|
+
const apiEndpoint = config.apiEndpoint || 'http://localhost:5000';
|
|
1788
1795
|
try {
|
|
1789
1796
|
const url = encodeURIComponent(window.location.href);
|
|
1790
1797
|
const response = await fetch(`${apiEndpoint}/api/public/lead-forms/${workspaceId}?url=${url}`);
|
|
@@ -1889,7 +1896,7 @@ class PopupFormsPlugin extends BasePlugin {
|
|
|
1889
1896
|
if (!this.tracker)
|
|
1890
1897
|
return;
|
|
1891
1898
|
const config = this.tracker.getConfig();
|
|
1892
|
-
const apiEndpoint = config.apiEndpoint || '
|
|
1899
|
+
const apiEndpoint = config.apiEndpoint || 'http://localhost:5000';
|
|
1893
1900
|
try {
|
|
1894
1901
|
await fetch(`${apiEndpoint}/api/public/lead-forms/${formId}/view`, {
|
|
1895
1902
|
method: 'POST',
|
|
@@ -2136,7 +2143,7 @@ class PopupFormsPlugin extends BasePlugin {
|
|
|
2136
2143
|
if (!this.tracker)
|
|
2137
2144
|
return;
|
|
2138
2145
|
const config = this.tracker.getConfig();
|
|
2139
|
-
const apiEndpoint = config.apiEndpoint || '
|
|
2146
|
+
const apiEndpoint = config.apiEndpoint || 'http://localhost:5000';
|
|
2140
2147
|
const visitorId = this.tracker.getVisitorId();
|
|
2141
2148
|
// Collect form data
|
|
2142
2149
|
const formData = new FormData(formElement);
|
|
@@ -3031,7 +3038,7 @@ class CRMClient {
|
|
|
3031
3038
|
* The contact is upserted in the CRM and matching workflow automations fire automatically.
|
|
3032
3039
|
*
|
|
3033
3040
|
* @example
|
|
3034
|
-
* const crm = new CRMClient('
|
|
3041
|
+
* const crm = new CRMClient('http://localhost:5000', 'WORKSPACE_ID');
|
|
3035
3042
|
* crm.setApiKey('mm_live_...');
|
|
3036
3043
|
*
|
|
3037
3044
|
* await crm.sendEvent({
|
|
@@ -4171,6 +4178,86 @@ class Tracker {
|
|
|
4171
4178
|
this.sessionId = this.createSessionId();
|
|
4172
4179
|
logger.info('All user data deleted');
|
|
4173
4180
|
}
|
|
4181
|
+
// ============================================
|
|
4182
|
+
// PUBLIC CRM METHODS (no API key required)
|
|
4183
|
+
// ============================================
|
|
4184
|
+
/**
|
|
4185
|
+
* Create or update a contact by email (upsert).
|
|
4186
|
+
* Secured by domain whitelist — no API key needed.
|
|
4187
|
+
*/
|
|
4188
|
+
async createContact(data) {
|
|
4189
|
+
return this.publicCrmRequest('/api/public/crm/contacts', 'POST', {
|
|
4190
|
+
workspaceId: this.workspaceId,
|
|
4191
|
+
...data,
|
|
4192
|
+
});
|
|
4193
|
+
}
|
|
4194
|
+
/**
|
|
4195
|
+
* Update an existing contact by ID (limited fields only).
|
|
4196
|
+
*/
|
|
4197
|
+
async updateContact(contactId, data) {
|
|
4198
|
+
return this.publicCrmRequest(`/api/public/crm/contacts/${contactId}`, 'PUT', {
|
|
4199
|
+
workspaceId: this.workspaceId,
|
|
4200
|
+
...data,
|
|
4201
|
+
});
|
|
4202
|
+
}
|
|
4203
|
+
/**
|
|
4204
|
+
* Submit a form — creates/updates contact from form data.
|
|
4205
|
+
*/
|
|
4206
|
+
async submitForm(formId, data) {
|
|
4207
|
+
const payload = {
|
|
4208
|
+
...data,
|
|
4209
|
+
metadata: {
|
|
4210
|
+
...data.metadata,
|
|
4211
|
+
visitorId: this.visitorId,
|
|
4212
|
+
sessionId: this.sessionId,
|
|
4213
|
+
pageUrl: typeof window !== 'undefined' ? window.location.href : undefined,
|
|
4214
|
+
referrer: typeof document !== 'undefined' ? document.referrer || undefined : undefined,
|
|
4215
|
+
},
|
|
4216
|
+
};
|
|
4217
|
+
return this.publicCrmRequest(`/api/public/crm/forms/${formId}/submit`, 'POST', payload);
|
|
4218
|
+
}
|
|
4219
|
+
/**
|
|
4220
|
+
* Log an activity linked to a contact (append-only).
|
|
4221
|
+
*/
|
|
4222
|
+
async logActivity(data) {
|
|
4223
|
+
return this.publicCrmRequest('/api/public/crm/activities', 'POST', {
|
|
4224
|
+
workspaceId: this.workspaceId,
|
|
4225
|
+
...data,
|
|
4226
|
+
});
|
|
4227
|
+
}
|
|
4228
|
+
/**
|
|
4229
|
+
* Create an opportunity (e.g., from "Request Demo" forms).
|
|
4230
|
+
*/
|
|
4231
|
+
async createOpportunity(data) {
|
|
4232
|
+
return this.publicCrmRequest('/api/public/crm/opportunities', 'POST', {
|
|
4233
|
+
workspaceId: this.workspaceId,
|
|
4234
|
+
...data,
|
|
4235
|
+
});
|
|
4236
|
+
}
|
|
4237
|
+
/**
|
|
4238
|
+
* Internal helper for public CRM API calls.
|
|
4239
|
+
*/
|
|
4240
|
+
async publicCrmRequest(path, method, body) {
|
|
4241
|
+
const url = `${this.config.apiEndpoint}${path}`;
|
|
4242
|
+
try {
|
|
4243
|
+
const response = await fetch(url, {
|
|
4244
|
+
method,
|
|
4245
|
+
headers: { 'Content-Type': 'application/json' },
|
|
4246
|
+
body: JSON.stringify(body),
|
|
4247
|
+
});
|
|
4248
|
+
const data = await response.json().catch(() => ({}));
|
|
4249
|
+
if (response.ok) {
|
|
4250
|
+
logger.debug(`Public CRM ${method} ${path} succeeded`);
|
|
4251
|
+
return { success: true, data: data.data ?? data, status: response.status };
|
|
4252
|
+
}
|
|
4253
|
+
logger.error(`Public CRM ${method} ${path} failed (${response.status}):`, data.message);
|
|
4254
|
+
return { success: false, error: data.message, status: response.status };
|
|
4255
|
+
}
|
|
4256
|
+
catch (error) {
|
|
4257
|
+
logger.error(`Public CRM ${method} ${path} error:`, error);
|
|
4258
|
+
return { success: false, error: error.message };
|
|
4259
|
+
}
|
|
4260
|
+
}
|
|
4174
4261
|
/**
|
|
4175
4262
|
* Destroy tracker and cleanup
|
|
4176
4263
|
*/
|
|
@@ -4264,7 +4351,7 @@ const CliantaContext = react.createContext(null);
|
|
|
4264
4351
|
*
|
|
4265
4352
|
* const config: CliantaConfig = {
|
|
4266
4353
|
* projectId: 'your-project-id',
|
|
4267
|
-
* apiEndpoint:
|
|
4354
|
+
* apiEndpoint: process.env.NEXT_PUBLIC_CLIANTA_API_ENDPOINT || 'http://localhost:5000',
|
|
4268
4355
|
* debug: process.env.NODE_ENV === 'development',
|
|
4269
4356
|
* };
|
|
4270
4357
|
*
|