@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/clianta.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
|
*/
|
|
@@ -9,15 +9,22 @@
|
|
|
9
9
|
*/
|
|
10
10
|
/** SDK Version */
|
|
11
11
|
const SDK_VERSION = '1.4.0';
|
|
12
|
-
/** Default API endpoint
|
|
12
|
+
/** Default API endpoint — reads from env or falls back to localhost */
|
|
13
13
|
const getDefaultApiEndpoint = () => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
// Build-time env var (works with Next.js, Vite, CRA, etc.)
|
|
15
|
+
if (typeof process !== 'undefined' && process.env?.NEXT_PUBLIC_CLIANTA_API_ENDPOINT) {
|
|
16
|
+
return process.env.NEXT_PUBLIC_CLIANTA_API_ENDPOINT;
|
|
17
|
+
}
|
|
18
|
+
if (typeof process !== 'undefined' && process.env?.VITE_CLIANTA_API_ENDPOINT) {
|
|
19
|
+
return process.env.VITE_CLIANTA_API_ENDPOINT;
|
|
20
|
+
}
|
|
21
|
+
if (typeof process !== 'undefined' && process.env?.REACT_APP_CLIANTA_API_ENDPOINT) {
|
|
22
|
+
return process.env.REACT_APP_CLIANTA_API_ENDPOINT;
|
|
19
23
|
}
|
|
20
|
-
|
|
24
|
+
if (typeof process !== 'undefined' && process.env?.CLIANTA_API_ENDPOINT) {
|
|
25
|
+
return process.env.CLIANTA_API_ENDPOINT;
|
|
26
|
+
}
|
|
27
|
+
return 'http://localhost:5000';
|
|
21
28
|
};
|
|
22
29
|
/** Core plugins enabled by default */
|
|
23
30
|
const DEFAULT_PLUGINS = [
|
|
@@ -1779,7 +1786,7 @@ class PopupFormsPlugin extends BasePlugin {
|
|
|
1779
1786
|
return;
|
|
1780
1787
|
const config = this.tracker.getConfig();
|
|
1781
1788
|
const workspaceId = this.tracker.getWorkspaceId();
|
|
1782
|
-
const apiEndpoint = config.apiEndpoint || '
|
|
1789
|
+
const apiEndpoint = config.apiEndpoint || 'http://localhost:5000';
|
|
1783
1790
|
try {
|
|
1784
1791
|
const url = encodeURIComponent(window.location.href);
|
|
1785
1792
|
const response = await fetch(`${apiEndpoint}/api/public/lead-forms/${workspaceId}?url=${url}`);
|
|
@@ -1884,7 +1891,7 @@ class PopupFormsPlugin extends BasePlugin {
|
|
|
1884
1891
|
if (!this.tracker)
|
|
1885
1892
|
return;
|
|
1886
1893
|
const config = this.tracker.getConfig();
|
|
1887
|
-
const apiEndpoint = config.apiEndpoint || '
|
|
1894
|
+
const apiEndpoint = config.apiEndpoint || 'http://localhost:5000';
|
|
1888
1895
|
try {
|
|
1889
1896
|
await fetch(`${apiEndpoint}/api/public/lead-forms/${formId}/view`, {
|
|
1890
1897
|
method: 'POST',
|
|
@@ -2131,7 +2138,7 @@ class PopupFormsPlugin extends BasePlugin {
|
|
|
2131
2138
|
if (!this.tracker)
|
|
2132
2139
|
return;
|
|
2133
2140
|
const config = this.tracker.getConfig();
|
|
2134
|
-
const apiEndpoint = config.apiEndpoint || '
|
|
2141
|
+
const apiEndpoint = config.apiEndpoint || 'http://localhost:5000';
|
|
2135
2142
|
const visitorId = this.tracker.getVisitorId();
|
|
2136
2143
|
// Collect form data
|
|
2137
2144
|
const formData = new FormData(formElement);
|
|
@@ -3026,7 +3033,7 @@ class CRMClient {
|
|
|
3026
3033
|
* The contact is upserted in the CRM and matching workflow automations fire automatically.
|
|
3027
3034
|
*
|
|
3028
3035
|
* @example
|
|
3029
|
-
* const crm = new CRMClient('
|
|
3036
|
+
* const crm = new CRMClient('http://localhost:5000', 'WORKSPACE_ID');
|
|
3030
3037
|
* crm.setApiKey('mm_live_...');
|
|
3031
3038
|
*
|
|
3032
3039
|
* await crm.sendEvent({
|
|
@@ -4166,6 +4173,86 @@ class Tracker {
|
|
|
4166
4173
|
this.sessionId = this.createSessionId();
|
|
4167
4174
|
logger.info('All user data deleted');
|
|
4168
4175
|
}
|
|
4176
|
+
// ============================================
|
|
4177
|
+
// PUBLIC CRM METHODS (no API key required)
|
|
4178
|
+
// ============================================
|
|
4179
|
+
/**
|
|
4180
|
+
* Create or update a contact by email (upsert).
|
|
4181
|
+
* Secured by domain whitelist — no API key needed.
|
|
4182
|
+
*/
|
|
4183
|
+
async createContact(data) {
|
|
4184
|
+
return this.publicCrmRequest('/api/public/crm/contacts', 'POST', {
|
|
4185
|
+
workspaceId: this.workspaceId,
|
|
4186
|
+
...data,
|
|
4187
|
+
});
|
|
4188
|
+
}
|
|
4189
|
+
/**
|
|
4190
|
+
* Update an existing contact by ID (limited fields only).
|
|
4191
|
+
*/
|
|
4192
|
+
async updateContact(contactId, data) {
|
|
4193
|
+
return this.publicCrmRequest(`/api/public/crm/contacts/${contactId}`, 'PUT', {
|
|
4194
|
+
workspaceId: this.workspaceId,
|
|
4195
|
+
...data,
|
|
4196
|
+
});
|
|
4197
|
+
}
|
|
4198
|
+
/**
|
|
4199
|
+
* Submit a form — creates/updates contact from form data.
|
|
4200
|
+
*/
|
|
4201
|
+
async submitForm(formId, data) {
|
|
4202
|
+
const payload = {
|
|
4203
|
+
...data,
|
|
4204
|
+
metadata: {
|
|
4205
|
+
...data.metadata,
|
|
4206
|
+
visitorId: this.visitorId,
|
|
4207
|
+
sessionId: this.sessionId,
|
|
4208
|
+
pageUrl: typeof window !== 'undefined' ? window.location.href : undefined,
|
|
4209
|
+
referrer: typeof document !== 'undefined' ? document.referrer || undefined : undefined,
|
|
4210
|
+
},
|
|
4211
|
+
};
|
|
4212
|
+
return this.publicCrmRequest(`/api/public/crm/forms/${formId}/submit`, 'POST', payload);
|
|
4213
|
+
}
|
|
4214
|
+
/**
|
|
4215
|
+
* Log an activity linked to a contact (append-only).
|
|
4216
|
+
*/
|
|
4217
|
+
async logActivity(data) {
|
|
4218
|
+
return this.publicCrmRequest('/api/public/crm/activities', 'POST', {
|
|
4219
|
+
workspaceId: this.workspaceId,
|
|
4220
|
+
...data,
|
|
4221
|
+
});
|
|
4222
|
+
}
|
|
4223
|
+
/**
|
|
4224
|
+
* Create an opportunity (e.g., from "Request Demo" forms).
|
|
4225
|
+
*/
|
|
4226
|
+
async createOpportunity(data) {
|
|
4227
|
+
return this.publicCrmRequest('/api/public/crm/opportunities', 'POST', {
|
|
4228
|
+
workspaceId: this.workspaceId,
|
|
4229
|
+
...data,
|
|
4230
|
+
});
|
|
4231
|
+
}
|
|
4232
|
+
/**
|
|
4233
|
+
* Internal helper for public CRM API calls.
|
|
4234
|
+
*/
|
|
4235
|
+
async publicCrmRequest(path, method, body) {
|
|
4236
|
+
const url = `${this.config.apiEndpoint}${path}`;
|
|
4237
|
+
try {
|
|
4238
|
+
const response = await fetch(url, {
|
|
4239
|
+
method,
|
|
4240
|
+
headers: { 'Content-Type': 'application/json' },
|
|
4241
|
+
body: JSON.stringify(body),
|
|
4242
|
+
});
|
|
4243
|
+
const data = await response.json().catch(() => ({}));
|
|
4244
|
+
if (response.ok) {
|
|
4245
|
+
logger.debug(`Public CRM ${method} ${path} succeeded`);
|
|
4246
|
+
return { success: true, data: data.data ?? data, status: response.status };
|
|
4247
|
+
}
|
|
4248
|
+
logger.error(`Public CRM ${method} ${path} failed (${response.status}):`, data.message);
|
|
4249
|
+
return { success: false, error: data.message, status: response.status };
|
|
4250
|
+
}
|
|
4251
|
+
catch (error) {
|
|
4252
|
+
logger.error(`Public CRM ${method} ${path} error:`, error);
|
|
4253
|
+
return { success: false, error: error.message };
|
|
4254
|
+
}
|
|
4255
|
+
}
|
|
4169
4256
|
/**
|
|
4170
4257
|
* Destroy tracker and cleanup
|
|
4171
4258
|
*/
|