@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/dist/angular.d.ts CHANGED
@@ -137,6 +137,16 @@ interface TrackerCore {
137
137
  getVisitorEngagement(): Promise<EngagementMetrics | null>;
138
138
  /** Send a server-side inbound event (requires apiKey in config) */
139
139
  sendEvent(payload: InboundEventPayload): Promise<InboundEventResult>;
140
+ /** Create or update a contact by email (upsert) */
141
+ createContact(data: PublicContactData): Promise<PublicCrmResult>;
142
+ /** Update an existing contact by ID (limited fields) */
143
+ updateContact(contactId: string, data: PublicContactUpdate): Promise<PublicCrmResult>;
144
+ /** Submit a form — creates/updates contact from form data */
145
+ submitForm(formId: string, data: PublicFormSubmission): Promise<PublicCrmResult>;
146
+ /** Log an activity linked to a contact (append-only) */
147
+ logActivity(data: PublicActivityData): Promise<PublicCrmResult>;
148
+ /** Create an opportunity (e.g., from "Request Demo" forms) */
149
+ createOpportunity(data: PublicOpportunityData): Promise<PublicCrmResult>;
140
150
  }
141
151
  interface VisitorProfile {
142
152
  visitorId: string;
@@ -208,6 +218,62 @@ interface VisitorActivityOptions {
208
218
  startDate?: string;
209
219
  endDate?: string;
210
220
  }
221
+ interface PublicContactData {
222
+ email: string;
223
+ firstName?: string;
224
+ lastName?: string;
225
+ company?: string;
226
+ jobTitle?: string;
227
+ phone?: string;
228
+ source?: string;
229
+ tags?: string[];
230
+ customFields?: Record<string, unknown>;
231
+ }
232
+ interface PublicContactUpdate {
233
+ firstName?: string;
234
+ lastName?: string;
235
+ company?: string;
236
+ jobTitle?: string;
237
+ phone?: string;
238
+ tags?: string[];
239
+ customFields?: Record<string, unknown>;
240
+ }
241
+ interface PublicActivityData {
242
+ contactId: string;
243
+ type: 'call' | 'email' | 'meeting' | 'note' | 'other';
244
+ title: string;
245
+ description?: string;
246
+ direction?: 'inbound' | 'outbound';
247
+ duration?: number;
248
+ emailSubject?: string;
249
+ metadata?: Record<string, unknown>;
250
+ }
251
+ interface PublicOpportunityData {
252
+ title: string;
253
+ contactId: string;
254
+ pipelineId: string;
255
+ stageId: string;
256
+ value?: number;
257
+ currency?: string;
258
+ description?: string;
259
+ expectedCloseDate?: string;
260
+ customFields?: Record<string, unknown>;
261
+ }
262
+ interface PublicFormSubmission {
263
+ fields: Record<string, unknown>;
264
+ metadata?: {
265
+ visitorId?: string;
266
+ sessionId?: string;
267
+ pageUrl?: string;
268
+ referrer?: string;
269
+ };
270
+ }
271
+ interface PublicCrmResult {
272
+ success: boolean;
273
+ data?: Record<string, unknown>;
274
+ error?: string;
275
+ status?: number;
276
+ }
211
277
 
212
278
  /**
213
279
  * Clianta SDK - Angular Integration
@@ -268,7 +334,7 @@ interface CliantaAngularConfig extends CliantaConfig {
268
334
  * @example
269
335
  * const instance = createCliantaTracker({
270
336
  * projectId: 'your-project-id',
271
- * apiEndpoint: 'https://api.clianta.online',
337
+ * apiEndpoint: environment.cliantaApiEndpoint || 'http://localhost:5000',
272
338
  * });
273
339
  *
274
340
  * instance.tracker?.track('page_view', 'Home Page');
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Clianta SDK v1.5.0
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 based on environment */
12
+ /** Default API endpoint reads from env or falls back to localhost */
13
13
  const getDefaultApiEndpoint = () => {
14
- if (typeof window === 'undefined')
15
- return 'https://api.clianta.online';
16
- const hostname = window.location.hostname;
17
- if (hostname.includes('localhost') || hostname.includes('127.0.0.1')) {
18
- return 'http://localhost:5000';
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
- return 'https://api.clianta.online';
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 || 'https://api.clianta.online';
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 || 'https://api.clianta.online';
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 || 'https://api.clianta.online';
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('https://api.clianta.online', 'WORKSPACE_ID');
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
  */
@@ -4290,7 +4377,7 @@ if (typeof window !== 'undefined') {
4290
4377
  * @example
4291
4378
  * const instance = createCliantaTracker({
4292
4379
  * projectId: 'your-project-id',
4293
- * apiEndpoint: 'https://api.clianta.online',
4380
+ * apiEndpoint: environment.cliantaApiEndpoint || 'http://localhost:5000',
4294
4381
  * });
4295
4382
  *
4296
4383
  * instance.tracker?.track('page_view', 'Home Page');