cuoral-ionic 0.0.5 → 0.0.7
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/README.md +72 -1
- package/android/.gradle/8.9/checksums/checksums.lock +0 -0
- package/android/.gradle/8.9/checksums/sha1-checksums.bin +0 -0
- package/android/build/.transforms/bb54161301273cf9b5b94a21c0fb3f23/transformed/classes/classes_dex/classes.dex +0 -0
- package/android/build/.transforms/f1aabffcd8b03aa664e77a79b3e1de5d/transformed/debug/debug_dex/com/cuoral/ionic/CuoralPlugin$1.dex +0 -0
- package/android/build/.transforms/f1aabffcd8b03aa664e77a79b3e1de5d/transformed/debug/debug_dex/com/cuoral/ionic/CuoralPlugin$2.dex +0 -0
- package/android/build/.transforms/f1aabffcd8b03aa664e77a79b3e1de5d/transformed/debug/debug_dex/com/cuoral/ionic/CuoralPlugin$3.dex +0 -0
- package/android/build/.transforms/f1aabffcd8b03aa664e77a79b3e1de5d/transformed/debug/debug_dex/com/cuoral/ionic/CuoralPlugin$4.dex +0 -0
- package/android/build/.transforms/f1aabffcd8b03aa664e77a79b3e1de5d/transformed/debug/debug_dex/com/cuoral/ionic/CuoralPlugin$5.dex +0 -0
- package/android/build/.transforms/f1aabffcd8b03aa664e77a79b3e1de5d/transformed/debug/debug_dex/com/cuoral/ionic/CuoralPlugin$6.dex +0 -0
- package/android/build/.transforms/f1aabffcd8b03aa664e77a79b3e1de5d/transformed/debug/debug_dex/com/cuoral/ionic/CuoralPlugin$InitiateCallback.dex +0 -0
- package/android/build/.transforms/f1aabffcd8b03aa664e77a79b3e1de5d/transformed/debug/debug_dex/com/cuoral/ionic/CuoralPlugin$UploadCallback.dex +0 -0
- package/android/build/.transforms/f1aabffcd8b03aa664e77a79b3e1de5d/transformed/debug/debug_dex/com/cuoral/ionic/CuoralPlugin.dex +0 -0
- package/android/build/.transforms/f1aabffcd8b03aa664e77a79b3e1de5d/transformed/debug/desugar_graph.bin +0 -0
- package/android/build/intermediates/compile_library_classes_jar/debug/classes.jar +0 -0
- package/android/build/intermediates/javac/debug/classes/com/cuoral/ionic/CuoralPlugin$1.class +0 -0
- package/android/build/intermediates/javac/debug/classes/com/cuoral/ionic/CuoralPlugin$2.class +0 -0
- package/android/build/intermediates/javac/debug/classes/com/cuoral/ionic/CuoralPlugin$3.class +0 -0
- package/android/build/intermediates/javac/debug/classes/com/cuoral/ionic/CuoralPlugin$4.class +0 -0
- package/android/build/intermediates/javac/debug/classes/com/cuoral/ionic/CuoralPlugin$5.class +0 -0
- package/android/build/intermediates/javac/debug/classes/com/cuoral/ionic/CuoralPlugin$6.class +0 -0
- package/android/build/intermediates/javac/debug/classes/com/cuoral/ionic/CuoralPlugin$InitiateCallback.class +0 -0
- package/android/build/intermediates/javac/debug/classes/com/cuoral/ionic/CuoralPlugin$UploadCallback.class +0 -0
- package/android/build/intermediates/javac/debug/classes/com/cuoral/ionic/CuoralPlugin.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/com/cuoral/ionic/CuoralPlugin$1.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/com/cuoral/ionic/CuoralPlugin$2.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/com/cuoral/ionic/CuoralPlugin$3.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/com/cuoral/ionic/CuoralPlugin$4.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/com/cuoral/ionic/CuoralPlugin$5.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/com/cuoral/ionic/CuoralPlugin$6.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/com/cuoral/ionic/CuoralPlugin$InitiateCallback.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/com/cuoral/ionic/CuoralPlugin$UploadCallback.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/com/cuoral/ionic/CuoralPlugin.class +0 -0
- package/android/build/intermediates/runtime_library_classes_jar/debug/classes.jar +0 -0
- package/android/build/tmp/compileDebugJavaWithJavac/previous-compilation-data.bin +0 -0
- package/android/build.gradle +1 -0
- package/android/src/main/java/com/cuoral/ionic/CuoralPlugin.java +205 -5
- package/dist/cuoral.d.ts +27 -0
- package/dist/cuoral.d.ts.map +1 -1
- package/dist/cuoral.js +137 -7
- package/dist/index.esm.js +471 -17
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +490 -17
- package/dist/index.js.map +1 -1
- package/dist/intelligence.d.ts +51 -0
- package/dist/intelligence.d.ts.map +1 -1
- package/dist/intelligence.js +307 -0
- package/dist/plugin.d.ts +15 -2
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +23 -10
- package/dist/types.d.ts +4 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +4 -0
- package/ios/Plugin/CuoralPlugin.swift +249 -13
- package/package.json +4 -2
- package/src/cuoral.ts +151 -8
- package/src/intelligence.ts +375 -0
- package/src/plugin.ts +39 -11
- package/src/types.ts +4 -0
package/dist/cuoral.js
CHANGED
|
@@ -25,6 +25,11 @@ export class Cuoral {
|
|
|
25
25
|
key: options.publicKey,
|
|
26
26
|
_t: Date.now().toString(),
|
|
27
27
|
});
|
|
28
|
+
// Add session_id if available (for widget to use existing session)
|
|
29
|
+
const existingSessionId = localStorage.getItem('__x_loadID');
|
|
30
|
+
if (existingSessionId) {
|
|
31
|
+
params.set('cuoral_mobile_session_id', existingSessionId);
|
|
32
|
+
}
|
|
28
33
|
if (options.email)
|
|
29
34
|
params.set('email', options.email);
|
|
30
35
|
if (options.firstName)
|
|
@@ -49,18 +54,23 @@ export class Cuoral {
|
|
|
49
54
|
* Initialize Cuoral
|
|
50
55
|
*/
|
|
51
56
|
async initialize() {
|
|
57
|
+
// Fetch session configuration and initialize intelligence if enabled by backend
|
|
58
|
+
await this.initializeIntelligence();
|
|
59
|
+
console.log('[Cuoral] Initialize - Session ID:', localStorage.getItem('__x_loadID'));
|
|
60
|
+
// Setup localStorage listener to detect when widget changes session
|
|
61
|
+
this.setupStorageListener();
|
|
52
62
|
this.bridge.initialize();
|
|
53
63
|
// Recreate modal if it was destroyed (e.g., after clearSession)
|
|
54
64
|
if (this.options.useModal && !this.modal) {
|
|
55
65
|
const widgetUrl = this.getWidgetUrl();
|
|
56
66
|
this.modal = new CuoralModal(widgetUrl, this.options.showFloatingButton);
|
|
57
67
|
}
|
|
58
|
-
//
|
|
68
|
+
// Update modal URL with session ID
|
|
59
69
|
if (this.modal) {
|
|
70
|
+
const widgetUrl = this.getWidgetUrl();
|
|
71
|
+
this.modal.updateWidgetUrl(widgetUrl);
|
|
60
72
|
this.modal.initialize();
|
|
61
73
|
}
|
|
62
|
-
// Fetch session configuration and initialize intelligence if enabled by backend
|
|
63
|
-
await this.initializeIntelligence();
|
|
64
74
|
}
|
|
65
75
|
/**
|
|
66
76
|
* Initialize intelligence based on backend configuration
|
|
@@ -92,9 +102,13 @@ export class Cuoral {
|
|
|
92
102
|
}
|
|
93
103
|
// Only initialize intelligence if customer_intelligence is enabled in backend
|
|
94
104
|
if (config && config.customer_intelligence === true) {
|
|
105
|
+
console.log('[Cuoral] Initializing intelligence with session:', sessionId);
|
|
95
106
|
this.intelligence = new CuoralIntelligence(sessionId);
|
|
96
107
|
this.intelligence.init();
|
|
97
108
|
}
|
|
109
|
+
else {
|
|
110
|
+
console.log('[Cuoral] Intelligence not enabled or no config for session:', sessionId);
|
|
111
|
+
}
|
|
98
112
|
}
|
|
99
113
|
catch (error) {
|
|
100
114
|
console.warn('[Cuoral] Failed to initialize intelligence:', error);
|
|
@@ -151,6 +165,82 @@ export class Cuoral {
|
|
|
151
165
|
this.intelligence.trackError(message, stackTrace, metadata);
|
|
152
166
|
}
|
|
153
167
|
}
|
|
168
|
+
/**
|
|
169
|
+
* Update user profile for the current session
|
|
170
|
+
* Call this after user logs in to update the intelligence session with their profile
|
|
171
|
+
* @param email - User's email address
|
|
172
|
+
* @param name - User's full name
|
|
173
|
+
*/
|
|
174
|
+
async updateUserProfile(email, name) {
|
|
175
|
+
try {
|
|
176
|
+
const sessionId = localStorage.getItem('__x_loadID');
|
|
177
|
+
if (!sessionId) {
|
|
178
|
+
console.warn('[Cuoral] No session ID found, cannot update profile');
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
console.log('[Cuoral] Updating user profile for session:', sessionId);
|
|
182
|
+
const response = await fetch('https://api.cuoral.com/conversation/set-profile', {
|
|
183
|
+
method: 'POST',
|
|
184
|
+
headers: { 'Content-Type': 'application/json' },
|
|
185
|
+
body: JSON.stringify({
|
|
186
|
+
session_id: sessionId,
|
|
187
|
+
email: email,
|
|
188
|
+
name: name,
|
|
189
|
+
}),
|
|
190
|
+
});
|
|
191
|
+
if (!response.ok) {
|
|
192
|
+
console.error('[Cuoral] Failed to update profile:', response.statusText);
|
|
193
|
+
return false;
|
|
194
|
+
}
|
|
195
|
+
console.log('[Cuoral] ✓ User profile updated successfully for session:', sessionId);
|
|
196
|
+
// Store user info locally
|
|
197
|
+
this.options.email = email;
|
|
198
|
+
const nameParts = name.split(' ');
|
|
199
|
+
if (nameParts.length > 0) {
|
|
200
|
+
this.options.firstName = nameParts[0];
|
|
201
|
+
this.options.lastName = nameParts.slice(1).join(' ');
|
|
202
|
+
}
|
|
203
|
+
return true;
|
|
204
|
+
}
|
|
205
|
+
catch (error) {
|
|
206
|
+
console.error('[Cuoral] Error updating user profile:', error);
|
|
207
|
+
return false;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Start native screen recording programmatically
|
|
212
|
+
* @returns Promise<boolean> - true if recording started successfully
|
|
213
|
+
*/
|
|
214
|
+
async startRecording() {
|
|
215
|
+
try {
|
|
216
|
+
return await this.recorder.startRecording();
|
|
217
|
+
}
|
|
218
|
+
catch (error) {
|
|
219
|
+
console.error('[Cuoral] Failed to start recording:', error);
|
|
220
|
+
return false;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Stop native screen recording programmatically
|
|
225
|
+
* Recording will be automatically uploaded to the portal
|
|
226
|
+
* @returns Promise<{filePath?: string; duration?: number; uploaded?: boolean} | null> - Recording result or null if failed
|
|
227
|
+
*/
|
|
228
|
+
async stopRecording() {
|
|
229
|
+
try {
|
|
230
|
+
const sessionId = localStorage.getItem('__x_loadID');
|
|
231
|
+
const customerId = localStorage.getItem('cuoralCustomerId');
|
|
232
|
+
return await this.recorder.stopRecording({
|
|
233
|
+
autoUpload: true,
|
|
234
|
+
sessionId: sessionId || undefined,
|
|
235
|
+
publicKey: this.options.publicKey,
|
|
236
|
+
customerId: customerId || undefined,
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
catch (error) {
|
|
240
|
+
console.error('[Cuoral] Failed to stop recording:', error);
|
|
241
|
+
return null;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
154
244
|
/**
|
|
155
245
|
* Open the widget modal
|
|
156
246
|
*/
|
|
@@ -190,7 +280,7 @@ export class Cuoral {
|
|
|
190
280
|
// Add session_id if available
|
|
191
281
|
const sessionId = localStorage.getItem('__x_loadID');
|
|
192
282
|
if (sessionId) {
|
|
193
|
-
params.set('
|
|
283
|
+
params.set('cuoral_mobile_session_id', sessionId);
|
|
194
284
|
}
|
|
195
285
|
if (this.options.email)
|
|
196
286
|
params.set('email', this.options.email);
|
|
@@ -244,6 +334,28 @@ export class Cuoral {
|
|
|
244
334
|
}
|
|
245
335
|
}
|
|
246
336
|
}
|
|
337
|
+
/**
|
|
338
|
+
* Setup localStorage listener for session changes
|
|
339
|
+
* Widget updates localStorage when creating new session, SDK detects and syncs
|
|
340
|
+
*/
|
|
341
|
+
setupStorageListener() {
|
|
342
|
+
// Poll localStorage every 2 seconds to detect session changes
|
|
343
|
+
// (storage event doesn't fire for same-window changes)
|
|
344
|
+
let lastKnownSession = localStorage.getItem('__x_loadID');
|
|
345
|
+
setInterval(() => {
|
|
346
|
+
const currentSession = localStorage.getItem('__x_loadID');
|
|
347
|
+
if (currentSession && currentSession !== lastKnownSession) {
|
|
348
|
+
console.log('[Cuoral] 🔄 Session changed in localStorage');
|
|
349
|
+
console.log('[Cuoral] Old session:', lastKnownSession);
|
|
350
|
+
console.log('[Cuoral] New session:', currentSession);
|
|
351
|
+
lastKnownSession = currentSession;
|
|
352
|
+
// Update intelligence to use new session
|
|
353
|
+
if (this.intelligence) {
|
|
354
|
+
this.intelligence.updateSessionId(currentSession);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}, 2000);
|
|
358
|
+
}
|
|
247
359
|
/**
|
|
248
360
|
* Clean up resources
|
|
249
361
|
*/
|
|
@@ -338,9 +450,27 @@ export class Cuoral {
|
|
|
338
450
|
});
|
|
339
451
|
// Handle stop recording requests from widget
|
|
340
452
|
this.bridge.on(CuoralMessageType.STOP_RECORDING, async () => {
|
|
341
|
-
const
|
|
342
|
-
|
|
343
|
-
|
|
453
|
+
const sessionId = localStorage.getItem('__x_loadID');
|
|
454
|
+
const customerId = localStorage.getItem('cuoralCustomerId');
|
|
455
|
+
const result = await this.recorder.stopRecording({
|
|
456
|
+
autoUpload: true,
|
|
457
|
+
sessionId: sessionId || undefined,
|
|
458
|
+
publicKey: this.options.publicKey,
|
|
459
|
+
customerId: customerId || undefined,
|
|
460
|
+
});
|
|
461
|
+
if (result && result.uploaded) {
|
|
462
|
+
// Video was automatically uploaded, just notify widget
|
|
463
|
+
this.bridge.sendToWidget({
|
|
464
|
+
type: CuoralMessageType.RECORDING_UPLOADED,
|
|
465
|
+
payload: {
|
|
466
|
+
duration: result.duration,
|
|
467
|
+
uploaded: true,
|
|
468
|
+
timestamp: Date.now()
|
|
469
|
+
}
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
else if (result) {
|
|
473
|
+
// Upload failed or was disabled, send video data to widget (old behavior)
|
|
344
474
|
const capacitorUrl = result.filePath ? Capacitor.convertFileSrc(result.filePath) : '';
|
|
345
475
|
try {
|
|
346
476
|
// Fetch the video blob from the capacitor URL
|