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