cuoral-ionic 0.0.1 → 0.0.2

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.
Files changed (85) hide show
  1. package/README.md +40 -4
  2. package/android/.gradle/8.9/checksums/checksums.lock +0 -0
  3. package/android/.gradle/8.9/dependencies-accessors/gc.properties +0 -0
  4. package/android/.gradle/8.9/fileChanges/last-build.bin +0 -0
  5. package/android/.gradle/8.9/fileHashes/fileHashes.lock +0 -0
  6. package/android/.gradle/8.9/gc.properties +0 -0
  7. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  8. package/android/.gradle/buildOutputCleanup/cache.properties +2 -0
  9. package/android/.gradle/vcs-1/gc.properties +0 -0
  10. package/android/build/.transforms/2c48e1f34ca03014b78fcb3e0ab7197b/results.bin +1 -0
  11. package/android/build/.transforms/2c48e1f34ca03014b78fcb3e0ab7197b/transformed/classes/classes_dex/classes.dex +0 -0
  12. package/android/build/.transforms/980c51bd075f726f311ad662d5d20ba0/results.bin +1 -0
  13. package/android/build/.transforms/980c51bd075f726f311ad662d5d20ba0/transformed/classes/classes_dex/classes.dex +0 -0
  14. package/android/build/.transforms/bb54161301273cf9b5b94a21c0fb3f23/results.bin +1 -0
  15. package/android/build/.transforms/bb54161301273cf9b5b94a21c0fb3f23/transformed/classes/classes_dex/classes.dex +0 -0
  16. package/android/build/.transforms/f1aabffcd8b03aa664e77a79b3e1de5d/results.bin +1 -0
  17. package/android/build/.transforms/f1aabffcd8b03aa664e77a79b3e1de5d/transformed/debug/debug_dex/com/cuoral/ionic/CuoralPlugin$1.dex +0 -0
  18. package/android/build/.transforms/f1aabffcd8b03aa664e77a79b3e1de5d/transformed/debug/debug_dex/com/cuoral/ionic/CuoralPlugin$2.dex +0 -0
  19. package/android/build/.transforms/f1aabffcd8b03aa664e77a79b3e1de5d/transformed/debug/debug_dex/com/cuoral/ionic/CuoralPlugin.dex +0 -0
  20. package/android/build/.transforms/f1aabffcd8b03aa664e77a79b3e1de5d/transformed/debug/debug_dex/com/cuoral/ionic/ScreenRecordService.dex +0 -0
  21. package/android/build/.transforms/f1aabffcd8b03aa664e77a79b3e1de5d/transformed/debug/desugar_graph.bin +0 -0
  22. package/android/build/intermediates/aapt_friendly_merged_manifests/debug/aapt/AndroidManifest.xml +22 -0
  23. package/android/build/intermediates/aapt_friendly_merged_manifests/debug/aapt/output-metadata.json +18 -0
  24. package/android/build/intermediates/aar_main_jar/debug/classes.jar +0 -0
  25. package/android/build/intermediates/aar_metadata/debug/aar-metadata.properties +6 -0
  26. package/android/build/intermediates/annotation_processor_list/debug/annotationProcessors.json +1 -0
  27. package/android/build/intermediates/annotations_typedef_file/debug/typedefs.txt +0 -0
  28. package/android/build/intermediates/compile_library_classes_jar/debug/classes.jar +0 -0
  29. package/android/build/intermediates/compile_r_class_jar/debug/R.jar +0 -0
  30. package/android/build/intermediates/compile_symbol_list/debug/R.txt +0 -0
  31. package/android/build/intermediates/incremental/debug/packageDebugResources/compile-file-map.properties +1 -0
  32. package/android/build/intermediates/incremental/debug/packageDebugResources/merger.xml +2 -0
  33. package/android/build/intermediates/incremental/debug-mergeJavaRes/merge-state +0 -0
  34. package/android/build/intermediates/incremental/mergeDebugJniLibFolders/merger.xml +2 -0
  35. package/android/build/intermediates/incremental/mergeDebugShaders/merger.xml +2 -0
  36. package/android/build/intermediates/incremental/packageDebugAssets/merger.xml +2 -0
  37. package/android/build/intermediates/javac/debug/classes/com/cuoral/ionic/CuoralPlugin$1.class +0 -0
  38. package/android/build/intermediates/javac/debug/classes/com/cuoral/ionic/CuoralPlugin$2.class +0 -0
  39. package/android/build/intermediates/javac/debug/classes/com/cuoral/ionic/CuoralPlugin.class +0 -0
  40. package/android/build/intermediates/javac/debug/classes/com/cuoral/ionic/ScreenRecordService.class +0 -0
  41. package/android/build/intermediates/local_only_symbol_list/debug/R-def.txt +2 -0
  42. package/android/build/intermediates/manifest_merge_blame_file/debug/manifest-merger-blame-debug-report.txt +38 -0
  43. package/android/build/intermediates/merged_java_res/debug/feature-cuoral-ionic.jar +0 -0
  44. package/android/build/intermediates/merged_manifest/debug/AndroidManifest.xml +22 -0
  45. package/android/build/intermediates/navigation_json/debug/navigation.json +1 -0
  46. package/android/build/intermediates/runtime_library_classes_dir/debug/com/cuoral/ionic/CuoralPlugin$1.class +0 -0
  47. package/android/build/intermediates/runtime_library_classes_dir/debug/com/cuoral/ionic/CuoralPlugin$2.class +0 -0
  48. package/android/build/intermediates/runtime_library_classes_dir/debug/com/cuoral/ionic/CuoralPlugin.class +0 -0
  49. package/android/build/intermediates/runtime_library_classes_dir/debug/com/cuoral/ionic/ScreenRecordService.class +0 -0
  50. package/android/build/intermediates/runtime_library_classes_jar/debug/classes.jar +0 -0
  51. package/android/build/intermediates/symbol_list_with_package_name/debug/package-aware-r.txt +1 -0
  52. package/android/build/outputs/aar/cuoral-ionic-debug.aar +0 -0
  53. package/android/build/outputs/logs/manifest-merger-debug-report.txt +49 -0
  54. package/android/build/tmp/compileDebugJavaWithJavac/compileTransaction/stash-dir/CuoralPlugin$1.class.uniqueId1 +0 -0
  55. package/android/build/tmp/compileDebugJavaWithJavac/compileTransaction/stash-dir/CuoralPlugin$2.class.uniqueId2 +0 -0
  56. package/android/build/tmp/compileDebugJavaWithJavac/compileTransaction/stash-dir/CuoralPlugin.class.uniqueId0 +0 -0
  57. package/android/build/tmp/compileDebugJavaWithJavac/previous-compilation-data.bin +0 -0
  58. package/android/build.gradle +61 -0
  59. package/android/src/main/AndroidManifest.xml +9 -0
  60. package/android/src/main/java/com/cuoral/ionic/CuoralPlugin.java +290 -33
  61. package/android/src/main/java/com/cuoral/ionic/ScreenRecordService.java +59 -0
  62. package/dist/cuoral.d.ts +30 -1
  63. package/dist/cuoral.d.ts.map +1 -1
  64. package/dist/cuoral.js +168 -1
  65. package/dist/index.d.ts +1 -0
  66. package/dist/index.d.ts.map +1 -1
  67. package/dist/index.esm.js +706 -127
  68. package/dist/index.esm.js.map +1 -1
  69. package/dist/index.js +706 -126
  70. package/dist/index.js.map +1 -1
  71. package/dist/intelligence.d.ts +66 -0
  72. package/dist/intelligence.d.ts.map +1 -0
  73. package/dist/intelligence.js +508 -0
  74. package/dist/plugin.d.ts +1 -1
  75. package/dist/plugin.d.ts.map +1 -1
  76. package/dist/plugin.js +24 -6
  77. package/dist/web.d.ts.map +1 -1
  78. package/dist/web.js +0 -3
  79. package/ios/Plugin/CuoralPlugin.swift +78 -1
  80. package/package.json +1 -1
  81. package/src/cuoral.ts +205 -1
  82. package/src/index.ts +1 -0
  83. package/src/intelligence.ts +609 -0
  84. package/src/plugin.ts +26 -6
  85. package/src/web.ts +0 -6
package/dist/cuoral.js CHANGED
@@ -2,12 +2,17 @@ import { CuoralBridge } from './bridge';
2
2
  import { CuoralRecorder } from './plugin';
3
3
  import { CuoralMessageType } from './types';
4
4
  import { CuoralModal } from './modal';
5
+ import { CuoralIntelligence } from './intelligence';
5
6
  import { Capacitor } from '@capacitor/core';
6
7
  /**
7
8
  * Main Cuoral class - simple API for users
8
9
  */
9
10
  export class Cuoral {
10
11
  constructor(options) {
12
+ // Check if running on a mobile platform
13
+ if (!Capacitor.isNativePlatform()) {
14
+ throw new Error('Cuoral Ionic library only works on native mobile platforms (iOS/Android). Web is not supported.');
15
+ }
11
16
  this.options = {
12
17
  showFloatingButton: true,
13
18
  useModal: true,
@@ -43,12 +48,103 @@ export class Cuoral {
43
48
  /**
44
49
  * Initialize Cuoral
45
50
  */
46
- initialize() {
51
+ async initialize() {
47
52
  this.bridge.initialize();
48
53
  // Initialize modal if enabled
49
54
  if (this.modal) {
50
55
  this.modal.initialize();
51
56
  }
57
+ // Fetch session configuration and initialize intelligence if enabled by backend
58
+ await this.initializeIntelligence();
59
+ }
60
+ /**
61
+ * Initialize intelligence based on backend configuration
62
+ */
63
+ async initializeIntelligence() {
64
+ try {
65
+ let sessionId = localStorage.getItem('__x_loadID');
66
+ // If no session exists, initiate a new one
67
+ if (!sessionId) {
68
+ sessionId = await this.initiateSession();
69
+ if (!sessionId) {
70
+ console.warn('[Cuoral] Failed to create session, intelligence not initialized');
71
+ return;
72
+ }
73
+ }
74
+ // Fetch session configuration
75
+ const config = await this.fetchSessionConfiguration(sessionId);
76
+ // If session was invalid/expired, try to initiate a new one
77
+ if (!config && !localStorage.getItem('__x_loadID')) {
78
+ sessionId = await this.initiateSession();
79
+ if (sessionId) {
80
+ const newConfig = await this.fetchSessionConfiguration(sessionId);
81
+ if (newConfig && newConfig.customer_intelligence === true) {
82
+ this.intelligence = new CuoralIntelligence(sessionId);
83
+ this.intelligence.init();
84
+ }
85
+ }
86
+ return;
87
+ }
88
+ // Only initialize intelligence if customer_intelligence is enabled in backend
89
+ if (config && config.customer_intelligence === true) {
90
+ this.intelligence = new CuoralIntelligence(sessionId);
91
+ this.intelligence.init();
92
+ }
93
+ }
94
+ catch (error) {
95
+ console.warn('[Cuoral] Failed to initialize intelligence:', error);
96
+ // Silently fail - don't break the app if intelligence fails to initialize
97
+ }
98
+ }
99
+ /**
100
+ * Fetch session configuration from backend
101
+ */
102
+ async fetchSessionConfiguration(sessionId) {
103
+ try {
104
+ const response = await fetch('https://api.cuoral.com/conversation/session/get', {
105
+ method: 'POST',
106
+ headers: {
107
+ 'Content-Type': 'application/json',
108
+ 'x-org-id': this.options.publicKey,
109
+ },
110
+ body: JSON.stringify({ session_id: sessionId }),
111
+ });
112
+ if (response.status === 404 || response.status === 400) {
113
+ // Session not found, clear and return null
114
+ localStorage.removeItem('__x_loadID');
115
+ return null;
116
+ }
117
+ if (!response.ok) {
118
+ return null;
119
+ }
120
+ const data = await response.json();
121
+ // If session is expired, clear it
122
+ if (data.is_expired) {
123
+ localStorage.removeItem('__x_loadID');
124
+ return null;
125
+ }
126
+ return data.configuration || null;
127
+ }
128
+ catch (error) {
129
+ console.warn('[Cuoral] Failed to fetch session configuration:', error);
130
+ return null;
131
+ }
132
+ }
133
+ /**
134
+ * Track a page/screen view
135
+ */
136
+ trackPageView(screen, metadata) {
137
+ if (this.intelligence) {
138
+ this.intelligence.trackPageView(screen, metadata);
139
+ }
140
+ }
141
+ /**
142
+ * Track an error manually
143
+ */
144
+ trackError(message, stackTrace, metadata) {
145
+ if (this.intelligence) {
146
+ this.intelligence.trackError(message, stackTrace, metadata);
147
+ }
52
148
  }
53
149
  /**
54
150
  * Open the widget modal
@@ -99,6 +195,77 @@ export class Cuoral {
99
195
  if (this.modal) {
100
196
  this.modal.destroy();
101
197
  }
198
+ // Destroy intelligence if exists
199
+ if (this.intelligence) {
200
+ this.intelligence.destroy();
201
+ }
202
+ }
203
+ /**
204
+ * Get or create session ID
205
+ */
206
+ getOrCreateSessionId() {
207
+ const storageKey = '__x_loadID';
208
+ let sessionId = localStorage.getItem(storageKey);
209
+ if (!sessionId) {
210
+ // Session will be created by initiate-session API call
211
+ // For now, return a temporary ID that will be replaced
212
+ sessionId = `temp-${Date.now()}-${Math.random().toString(36).substring(2, 15)}`;
213
+ }
214
+ return sessionId;
215
+ }
216
+ /**
217
+ * Initiate a new session with backend (like inline.js does)
218
+ */
219
+ async initiateSession() {
220
+ try {
221
+ const response = await fetch('https://api.cuoral.com/conversation/initiate-session', {
222
+ method: 'POST',
223
+ headers: {
224
+ 'Content-Type': 'application/json',
225
+ 'x-org-id': this.options.publicKey,
226
+ },
227
+ body: JSON.stringify({ public_key: this.options.publicKey }),
228
+ });
229
+ if (!response.ok) {
230
+ return null;
231
+ }
232
+ const data = await response.json();
233
+ if (data.status && data.session_id) {
234
+ localStorage.setItem('__x_loadID', data.session_id);
235
+ // Set profile if email, firstName, lastName are provided
236
+ if (this.options.email && this.options.firstName && this.options.lastName) {
237
+ await this.setProfile(data.session_id);
238
+ }
239
+ return data.session_id;
240
+ }
241
+ return null;
242
+ }
243
+ catch (error) {
244
+ console.warn('[Cuoral] Failed to initiate session:', error);
245
+ return null;
246
+ }
247
+ }
248
+ /**
249
+ * Set user profile for the session
250
+ */
251
+ async setProfile(sessionId) {
252
+ try {
253
+ await fetch('https://api.cuoral.com/conversation/set-profile', {
254
+ method: 'POST',
255
+ headers: {
256
+ 'Content-Type': 'application/json',
257
+ 'x-org-id': this.options.publicKey,
258
+ },
259
+ body: JSON.stringify({
260
+ session_id: sessionId,
261
+ email: this.options.email,
262
+ name: `${this.options.firstName} ${this.options.lastName}`,
263
+ }),
264
+ });
265
+ }
266
+ catch (error) {
267
+ console.warn('[Cuoral] Failed to set profile:', error);
268
+ }
102
269
  }
103
270
  /**
104
271
  * Setup automatic message handlers
package/dist/index.d.ts CHANGED
@@ -3,4 +3,5 @@ export * from './bridge';
3
3
  export * from './types';
4
4
  export * from './cuoral';
5
5
  export * from './modal';
6
+ export * from './intelligence';
6
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,gBAAgB,CAAC"}