@mobana/react-native-sdk 0.2.10

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 (96) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +249 -0
  3. package/android/build.gradle +50 -0
  4. package/android/src/main/AndroidManifest.xml +6 -0
  5. package/android/src/main/java/ai/mobana/sdk/MobanaModule.kt +67 -0
  6. package/android/src/main/java/ai/mobana/sdk/MobanaPackage.kt +19 -0
  7. package/app.plugin.js +274 -0
  8. package/ios/Mobana.h +11 -0
  9. package/ios/Mobana.m +20 -0
  10. package/lib/commonjs/Mobana.js +676 -0
  11. package/lib/commonjs/Mobana.js.map +1 -0
  12. package/lib/commonjs/NativeMobana.js +53 -0
  13. package/lib/commonjs/NativeMobana.js.map +1 -0
  14. package/lib/commonjs/api.js +201 -0
  15. package/lib/commonjs/api.js.map +1 -0
  16. package/lib/commonjs/bridge/index.js +19 -0
  17. package/lib/commonjs/bridge/index.js.map +1 -0
  18. package/lib/commonjs/bridge/injectBridge.js +528 -0
  19. package/lib/commonjs/bridge/injectBridge.js.map +1 -0
  20. package/lib/commonjs/components/FlowWebView.js +676 -0
  21. package/lib/commonjs/components/FlowWebView.js.map +1 -0
  22. package/lib/commonjs/components/MobanaProvider.js +275 -0
  23. package/lib/commonjs/components/MobanaProvider.js.map +1 -0
  24. package/lib/commonjs/components/index.js +20 -0
  25. package/lib/commonjs/components/index.js.map +1 -0
  26. package/lib/commonjs/device.js +49 -0
  27. package/lib/commonjs/device.js.map +1 -0
  28. package/lib/commonjs/index.js +20 -0
  29. package/lib/commonjs/index.js.map +1 -0
  30. package/lib/commonjs/package.json +1 -0
  31. package/lib/commonjs/storage.js +277 -0
  32. package/lib/commonjs/storage.js.map +1 -0
  33. package/lib/commonjs/types.js +2 -0
  34. package/lib/commonjs/types.js.map +1 -0
  35. package/lib/module/Mobana.js +673 -0
  36. package/lib/module/Mobana.js.map +1 -0
  37. package/lib/module/NativeMobana.js +49 -0
  38. package/lib/module/NativeMobana.js.map +1 -0
  39. package/lib/module/api.js +194 -0
  40. package/lib/module/api.js.map +1 -0
  41. package/lib/module/bridge/index.js +4 -0
  42. package/lib/module/bridge/index.js.map +1 -0
  43. package/lib/module/bridge/injectBridge.js +523 -0
  44. package/lib/module/bridge/injectBridge.js.map +1 -0
  45. package/lib/module/components/FlowWebView.js +672 -0
  46. package/lib/module/components/FlowWebView.js.map +1 -0
  47. package/lib/module/components/MobanaProvider.js +270 -0
  48. package/lib/module/components/MobanaProvider.js.map +1 -0
  49. package/lib/module/components/index.js +5 -0
  50. package/lib/module/components/index.js.map +1 -0
  51. package/lib/module/device.js +45 -0
  52. package/lib/module/device.js.map +1 -0
  53. package/lib/module/index.js +53 -0
  54. package/lib/module/index.js.map +1 -0
  55. package/lib/module/storage.js +257 -0
  56. package/lib/module/storage.js.map +1 -0
  57. package/lib/module/types.js +2 -0
  58. package/lib/module/types.js.map +1 -0
  59. package/lib/typescript/Mobana.d.ts +209 -0
  60. package/lib/typescript/Mobana.d.ts.map +1 -0
  61. package/lib/typescript/NativeMobana.d.ts +11 -0
  62. package/lib/typescript/NativeMobana.d.ts.map +1 -0
  63. package/lib/typescript/api.d.ts +34 -0
  64. package/lib/typescript/api.d.ts.map +1 -0
  65. package/lib/typescript/bridge/index.d.ts +3 -0
  66. package/lib/typescript/bridge/index.d.ts.map +1 -0
  67. package/lib/typescript/bridge/injectBridge.d.ts +23 -0
  68. package/lib/typescript/bridge/injectBridge.d.ts.map +1 -0
  69. package/lib/typescript/components/FlowWebView.d.ts +38 -0
  70. package/lib/typescript/components/FlowWebView.d.ts.map +1 -0
  71. package/lib/typescript/components/MobanaProvider.d.ts +65 -0
  72. package/lib/typescript/components/MobanaProvider.d.ts.map +1 -0
  73. package/lib/typescript/components/index.d.ts +5 -0
  74. package/lib/typescript/components/index.d.ts.map +1 -0
  75. package/lib/typescript/device.d.ts +6 -0
  76. package/lib/typescript/device.d.ts.map +1 -0
  77. package/lib/typescript/index.d.ts +46 -0
  78. package/lib/typescript/index.d.ts.map +1 -0
  79. package/lib/typescript/storage.d.ts +68 -0
  80. package/lib/typescript/storage.d.ts.map +1 -0
  81. package/lib/typescript/types.d.ts +298 -0
  82. package/lib/typescript/types.d.ts.map +1 -0
  83. package/mobana.podspec +19 -0
  84. package/package.json +131 -0
  85. package/src/Mobana.ts +742 -0
  86. package/src/NativeMobana.ts +61 -0
  87. package/src/api.ts +259 -0
  88. package/src/bridge/index.ts +2 -0
  89. package/src/bridge/injectBridge.ts +542 -0
  90. package/src/components/FlowWebView.tsx +826 -0
  91. package/src/components/MobanaProvider.tsx +393 -0
  92. package/src/components/index.ts +4 -0
  93. package/src/device.ts +42 -0
  94. package/src/index.ts +66 -0
  95. package/src/storage.ts +262 -0
  96. package/src/types.ts +362 -0
@@ -0,0 +1,673 @@
1
+ "use strict";
2
+
3
+ import { getInstallId, getCachedResult, setCachedResult, clearAttribution, queueConversion, getConversionQueue, clearConversionQueue, getCachedFlow, setCachedFlow, clearAllCachedFlows, clearLocalData } from './storage';
4
+ import { findAttribution, trackConversionApi, fetchFlow } from './api';
5
+ import { getDeviceInfo } from './device';
6
+ import { getInstallReferrer } from './NativeMobana';
7
+ import { getGlobalFlowContext } from './components/MobanaProvider';
8
+ const DEFAULT_ENDPOINT = 'https://{appId}.mobana.ai';
9
+ const DEFAULT_TIMEOUT = 10000;
10
+
11
+ /**
12
+ * Mobana SDK for React Native
13
+ *
14
+ * Simple, privacy-focused mobile app attribution, conversions, and remote flows.
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * import { Mobana, MobanaProvider } from '@mobana/react-native-sdk';
19
+ *
20
+ * // Wrap your app with the provider (in App.tsx)
21
+ * function App() {
22
+ * return (
23
+ * <MobanaProvider>
24
+ * <YourApp />
25
+ * </MobanaProvider>
26
+ * );
27
+ * }
28
+ *
29
+ * // Initialize once on app start
30
+ * await Mobana.init({ appId: 'a1b2c3d4' });
31
+ *
32
+ * // Get attribution (handles caching, retries, Android Install Referrer)
33
+ * const attribution = await Mobana.getAttribution();
34
+ *
35
+ * // Track conversions
36
+ * Mobana.trackConversion('signup');
37
+ * Mobana.trackConversion('purchase', 49.99);
38
+ *
39
+ * // Show a flow
40
+ * const result = await Mobana.startFlow('onboarding');
41
+ * if (result.completed) {
42
+ * console.log('User completed onboarding!', result.data);
43
+ * }
44
+ * ```
45
+ */
46
+ class MobanaSDK {
47
+ config = null;
48
+ isConfigured = false;
49
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
50
+ attributionPromise = null;
51
+ // In-memory cache for attribution (faster than AsyncStorage)
52
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
53
+ cachedAttribution = null;
54
+ attributionChecked = false;
55
+
56
+ /**
57
+ * Initialize the SDK with your app settings
58
+ * Must be called before any other SDK methods
59
+ *
60
+ * @param config - Configuration options (appId is required)
61
+ *
62
+ * @example
63
+ * ```typescript
64
+ * // Basic initialization
65
+ * await Mobana.init({ appId: 'a1b2c3d4' });
66
+ *
67
+ * // With custom endpoint (for domain proxying)
68
+ * await Mobana.init({
69
+ * appId: 'a1b2c3d4',
70
+ * endpoint: 'https://myapp.com/d',
71
+ * });
72
+ *
73
+ * // With all options
74
+ * await Mobana.init({
75
+ * appId: 'a1b2c3d4',
76
+ * endpoint: 'https://myapp.com/d', // Optional
77
+ * enabled: userHasConsented, // Optional, default: true
78
+ * debug: __DEV__, // Optional, default: false
79
+ * });
80
+ * ```
81
+ */
82
+ async init(config) {
83
+ if (!config.appId) {
84
+ console.warn('[Mobana] appId is required');
85
+ return;
86
+ }
87
+ if (!config.appKey) {
88
+ console.warn('[Mobana] appKey is required');
89
+ return;
90
+ }
91
+ this.config = {
92
+ enabled: true,
93
+ debug: false,
94
+ ...config
95
+ };
96
+ this.isConfigured = true;
97
+
98
+ // Eagerly generate/retrieve the install ID so it's ready before
99
+ // the first attribution or conversion call.
100
+ const installId = await getInstallId();
101
+ if (this.config.debug) {
102
+ console.log('[Mobana] Initialized:', {
103
+ appId: this.config.appId,
104
+ endpoint: this.config.endpoint,
105
+ enabled: this.config.enabled,
106
+ installId
107
+ });
108
+ }
109
+
110
+ // Flush any queued conversions when SDK is initialized
111
+ await this.flushConversionQueue();
112
+ }
113
+
114
+ /**
115
+ * Enable or disable the SDK dynamically
116
+ * Useful for GDPR consent flows
117
+ *
118
+ * @param enabled - Whether the SDK should be enabled
119
+ */
120
+ setEnabled(enabled) {
121
+ if (!this.config) {
122
+ console.warn('[Mobana] SDK not configured. Call init() first.');
123
+ return;
124
+ }
125
+ this.config.enabled = enabled;
126
+ if (this.config.debug) {
127
+ console.log(`[Mobana] ${enabled ? 'Enabled' : 'Disabled'}`);
128
+ }
129
+ if (enabled) {
130
+ this.flushConversionQueue();
131
+ }
132
+ }
133
+
134
+ /**
135
+ * Get attribution data for this install
136
+ *
137
+ * Returns cached result if available, otherwise fetches from server.
138
+ * Never throws - returns null on error or no match.
139
+ *
140
+ * @param options - Optional settings for the attribution request
141
+ * @returns Attribution data or null if not available
142
+ *
143
+ * @example
144
+ * ```typescript
145
+ * const attribution = await Mobana.getAttribution();
146
+ *
147
+ * if (attribution) {
148
+ * YourAnalyticsProvider.track('App Installed', {
149
+ * source: attribution.utm_source,
150
+ * campaign: attribution.utm_campaign,
151
+ * });
152
+ *
153
+ * if (attribution.data?.promo) {
154
+ * applyPromoCode(attribution.data.promo);
155
+ * }
156
+ * }
157
+ * ```
158
+ *
159
+ * @example
160
+ * // With TypeScript generics for typed data
161
+ * interface MyDeeplinkData {
162
+ * promo?: string;
163
+ * referrer?: string;
164
+ * }
165
+ *
166
+ * const attribution = await Mobana.getAttribution<MyDeeplinkData>();
167
+ * // attribution.data is now typed as MyDeeplinkData
168
+ */
169
+ async getAttribution(options = {}) {
170
+ if (!this.isConfigured || !this.config) {
171
+ console.warn('[Mobana] SDK not configured. Call init() first.');
172
+ return null;
173
+ }
174
+ if (!this.config.enabled) {
175
+ if (this.config.debug) {
176
+ console.log('[Mobana] SDK disabled, returning null');
177
+ }
178
+ return null;
179
+ }
180
+
181
+ // Return in-memory cache if available (fastest)
182
+ if (this.attributionChecked) {
183
+ return this.cachedAttribution;
184
+ }
185
+
186
+ // Check AsyncStorage cache
187
+ const cached = await getCachedResult();
188
+ if (cached) {
189
+ if (this.config.debug) {
190
+ console.log('[Mobana] Returning cached result, matched:', cached.matched);
191
+ }
192
+ // Update in-memory cache
193
+ this.attributionChecked = true;
194
+ this.cachedAttribution = cached.matched ? cached.attribution ?? null : null;
195
+ return this.cachedAttribution;
196
+ }
197
+
198
+ // Prevent duplicate concurrent requests
199
+ if (this.attributionPromise) {
200
+ return this.attributionPromise;
201
+ }
202
+ this.attributionPromise = this.fetchAttribution(options);
203
+ const result = await this.attributionPromise;
204
+ this.attributionPromise = null;
205
+
206
+ // Update in-memory cache
207
+ this.attributionChecked = true;
208
+ this.cachedAttribution = result;
209
+ return result;
210
+ }
211
+
212
+ /**
213
+ * Track a conversion event
214
+ *
215
+ * Conversions are linked to the original attribution via installId.
216
+ * If offline, conversions are queued and sent when back online.
217
+ * Never throws - silently handles errors.
218
+ *
219
+ * @param name - Conversion name (must be configured in app settings)
220
+ * @param value - Optional monetary value
221
+ * @param flowSessionId - Optional flow session ID to link conversion to a specific flow presentation
222
+ *
223
+ * @example
224
+ * ```typescript
225
+ * // Simple conversion
226
+ * Mobana.trackConversion('signup');
227
+ *
228
+ * // Conversion with value
229
+ * Mobana.trackConversion('purchase', 49.99);
230
+ *
231
+ * // Conversion linked to a flow session
232
+ * const result = await Mobana.startFlow('pre-purchase');
233
+ * // ... user makes purchase via paywall ...
234
+ * await Mobana.trackConversion('purchase', 49.99, result.sessionId);
235
+ * ```
236
+ */
237
+ async trackConversion(name, value, flowSessionId) {
238
+ if (!this.isConfigured || !this.config) {
239
+ if (this.config?.debug) {
240
+ console.log('[Mobana] SDK not configured, skipping conversion');
241
+ }
242
+ return;
243
+ }
244
+ if (!this.config.enabled) {
245
+ if (this.config.debug) {
246
+ console.log('[Mobana] SDK disabled, skipping conversion');
247
+ }
248
+ return;
249
+ }
250
+ const installId = await getInstallId();
251
+ const event = {
252
+ installId,
253
+ name,
254
+ value,
255
+ timestamp: Date.now(),
256
+ flowSessionId
257
+ };
258
+
259
+ // Ensure Install record exists on server (created on first getAttribution call).
260
+ // This is fast after first call — returns from in-memory cache without network.
261
+ // We don't care about the result; conversions work for organic installs too.
262
+ await this.getAttribution();
263
+
264
+ // Try to send immediately
265
+ const success = await this.sendConversion(event);
266
+ if (!success) {
267
+ // Queue for later if failed (offline, etc.)
268
+ await queueConversion(event);
269
+ if (this.config.debug) {
270
+ console.log('[Mobana] Conversion queued for later');
271
+ }
272
+ }
273
+ }
274
+
275
+ /**
276
+ * Reset all stored attribution data
277
+ * Useful for testing or when user logs out
278
+ *
279
+ * Note: This generates a new installId, so subsequent attributions
280
+ * will be treated as a new install.
281
+ */
282
+ async reset() {
283
+ // Clear in-memory cache
284
+ this.cachedAttribution = null;
285
+ this.attributionChecked = false;
286
+ this.attributionPromise = null;
287
+
288
+ // Clear persistent storage
289
+ await clearAttribution();
290
+ await clearConversionQueue();
291
+ await clearAllCachedFlows();
292
+ await clearLocalData();
293
+ if (this.config?.debug) {
294
+ console.log('[Mobana] Reset complete');
295
+ }
296
+ }
297
+
298
+ // ============================================
299
+ // Flows
300
+ // ============================================
301
+
302
+ /**
303
+ * Start and display a flow
304
+ *
305
+ * Fetches the flow content (or uses cache) and presents it in a full-screen modal.
306
+ * The promise resolves when the user completes or dismisses the flow.
307
+ *
308
+ * Requires MobanaProvider to be mounted in your app.
309
+ *
310
+ * @param slug - Flow identifier (from dashboard)
311
+ * @param options - Optional flow configuration
312
+ * @returns Flow result with completion status and optional data
313
+ *
314
+ * @example
315
+ * ```typescript
316
+ * // Basic usage
317
+ * const result = await Mobana.startFlow('onboarding');
318
+ *
319
+ * if (result.completed) {
320
+ * console.log('Onboarding completed!', result.data);
321
+ * } else if (result.error) {
322
+ * console.log('Flow error:', result.error);
323
+ * }
324
+ *
325
+ * // With custom parameters
326
+ * const result = await Mobana.startFlow('welcome', {
327
+ * params: { userName: 'John', isPremium: true },
328
+ * onEvent: (name) => {
329
+ * analytics.track(name);
330
+ * },
331
+ * });
332
+ * ```
333
+ */
334
+ async startFlow(slug, options) {
335
+ // Check if SDK is configured
336
+ if (!this.isConfigured || !this.config) {
337
+ console.warn('[Mobana] SDK not configured. Call init() first.');
338
+ return {
339
+ completed: false,
340
+ dismissed: true,
341
+ error: 'SDK_NOT_CONFIGURED'
342
+ };
343
+ }
344
+
345
+ // Check if SDK is enabled
346
+ if (!this.config.enabled) {
347
+ if (this.config.debug) {
348
+ console.log('[Mobana] SDK disabled, cannot start flow');
349
+ }
350
+ return {
351
+ completed: false,
352
+ dismissed: true,
353
+ error: 'SDK_NOT_CONFIGURED'
354
+ };
355
+ }
356
+
357
+ // Check if provider is mounted
358
+ const flowContext = getGlobalFlowContext();
359
+ if (!flowContext?.isProviderMounted) {
360
+ console.warn('[Mobana] startFlow() called but MobanaProvider is not mounted. ' + 'Wrap your app with <MobanaProvider> to enable flows.');
361
+ return {
362
+ completed: false,
363
+ dismissed: true,
364
+ error: 'PROVIDER_NOT_MOUNTED'
365
+ };
366
+ }
367
+ try {
368
+ const endpoint = this.getEndpoint();
369
+ const installId = await getInstallId();
370
+
371
+ // Ensure attribution is loaded (for passing to flow context).
372
+ // Fast after first call — returns from in-memory cache without network.
373
+ // We don't fail if attribution isn't matched; flows work for organic installs too.
374
+ await this.getAttribution();
375
+
376
+ // Check cache for this flow
377
+ const cached = await getCachedFlow(slug);
378
+ if (this.config.debug) {
379
+ console.log(`[Mobana] Starting flow: ${slug}`, {
380
+ hasCached: !!cached,
381
+ cachedVersionId: cached?.versionId
382
+ });
383
+ }
384
+
385
+ // Fetch flow from server (with cache validation)
386
+ const response = await fetchFlow(endpoint, this.config.appKey, slug, installId, cached?.versionId, DEFAULT_TIMEOUT, this.config.debug);
387
+
388
+ // Handle network error
389
+ if (!response) {
390
+ // If we have a cached version, use it
391
+ if (cached) {
392
+ if (this.config.debug) {
393
+ console.log('[Mobana] Network error, using cached flow');
394
+ }
395
+ return this.presentFlowToUser(flowContext, {
396
+ slug,
397
+ config: cached,
398
+ installId,
399
+ endpoint,
400
+ appKey: this.config.appKey,
401
+ options
402
+ });
403
+ }
404
+ return {
405
+ completed: false,
406
+ dismissed: true,
407
+ error: 'NETWORK_ERROR'
408
+ };
409
+ }
410
+
411
+ // Handle server errors
412
+ if (response.error) {
413
+ if (this.config.debug) {
414
+ console.log(`[Mobana] Flow error: ${response.error}`);
415
+ }
416
+ return {
417
+ completed: false,
418
+ dismissed: true,
419
+ error: response.error
420
+ };
421
+ }
422
+
423
+ // Determine flow content to use
424
+ let flowConfig;
425
+ if (response.cached && cached) {
426
+ // Server confirmed our cached version is current
427
+ flowConfig = cached;
428
+ if (this.config.debug) {
429
+ console.log('[Mobana] Using cached flow (validated)');
430
+ }
431
+ } else if (response.versionId && response.html) {
432
+ // New content from server
433
+ flowConfig = {
434
+ versionId: response.versionId,
435
+ html: response.html,
436
+ css: response.css,
437
+ js: response.js
438
+ };
439
+ // Cache for next time
440
+ await setCachedFlow(slug, flowConfig);
441
+ if (this.config.debug) {
442
+ console.log('[Mobana] Using fresh flow, cached for next time');
443
+ }
444
+ } else {
445
+ // Unexpected response
446
+ if (this.config.debug) {
447
+ console.log('[Mobana] Unexpected flow response');
448
+ }
449
+ return {
450
+ completed: false,
451
+ dismissed: true,
452
+ error: 'SERVER_ERROR'
453
+ };
454
+ }
455
+
456
+ // Present the flow
457
+ return this.presentFlowToUser(flowContext, {
458
+ slug,
459
+ config: flowConfig,
460
+ installId,
461
+ endpoint,
462
+ appKey: this.config.appKey,
463
+ options
464
+ });
465
+ } catch (error) {
466
+ if (this.config.debug) {
467
+ console.log('[Mobana] Error starting flow:', error);
468
+ }
469
+ return {
470
+ completed: false,
471
+ dismissed: true,
472
+ error: 'SERVER_ERROR'
473
+ };
474
+ }
475
+ }
476
+
477
+ /**
478
+ * Prefetch a flow for faster display later
479
+ *
480
+ * Downloads and caches the flow content without displaying it.
481
+ * Call this ahead of time if you know a flow will be shown soon.
482
+ *
483
+ * @param slug - Flow identifier (from dashboard)
484
+ *
485
+ * @example
486
+ * ```typescript
487
+ * // Prefetch during app startup
488
+ * Mobana.prefetchFlow('onboarding');
489
+ *
490
+ * // Later, when ready to show (will be instant if prefetched)
491
+ * const result = await Mobana.startFlow('onboarding');
492
+ * ```
493
+ */
494
+ async prefetchFlow(slug) {
495
+ if (!this.isConfigured || !this.config) {
496
+ return;
497
+ }
498
+ if (!this.config.enabled) {
499
+ return;
500
+ }
501
+ try {
502
+ const endpoint = this.getEndpoint();
503
+ const installId = await getInstallId();
504
+ const cached = await getCachedFlow(slug);
505
+ if (this.config.debug) {
506
+ console.log(`[Mobana] Prefetching flow: ${slug}`);
507
+ }
508
+ const response = await fetchFlow(endpoint, this.config.appKey, slug, installId, cached?.versionId, DEFAULT_TIMEOUT, this.config.debug);
509
+ if (response && !response.error && !response.cached && response.versionId && response.html) {
510
+ // Cache the new content
511
+ await setCachedFlow(slug, {
512
+ versionId: response.versionId,
513
+ html: response.html,
514
+ css: response.css,
515
+ js: response.js
516
+ });
517
+ if (this.config.debug) {
518
+ console.log(`[Mobana] Flow "${slug}" prefetched and cached`);
519
+ }
520
+ } else if (response?.cached) {
521
+ if (this.config.debug) {
522
+ console.log(`[Mobana] Flow "${slug}" already cached and current`);
523
+ }
524
+ }
525
+ } catch (error) {
526
+ if (this.config.debug) {
527
+ console.log('[Mobana] Error prefetching flow:', error);
528
+ }
529
+ }
530
+ }
531
+
532
+ /**
533
+ * Present a flow to the user via the provider
534
+ */
535
+ presentFlowToUser(flowContext, params) {
536
+ return new Promise(resolve => {
537
+ flowContext.presentFlow({
538
+ slug: params.slug,
539
+ config: params.config,
540
+ installId: params.installId,
541
+ endpoint: params.endpoint,
542
+ appKey: params.appKey,
543
+ attribution: this.cachedAttribution,
544
+ options: params.options,
545
+ resolve,
546
+ debug: this.config?.debug
547
+ });
548
+ });
549
+ }
550
+
551
+ // ============================================
552
+ // Private methods
553
+ // ============================================
554
+
555
+ getEndpoint() {
556
+ if (this.config?.endpoint) {
557
+ // Remove trailing slash
558
+ return this.config.endpoint.replace(/\/$/, '');
559
+ }
560
+ if (this.config?.appId) {
561
+ return DEFAULT_ENDPOINT.replace('{appId}', this.config.appId);
562
+ }
563
+ throw new Error('No endpoint configured');
564
+ }
565
+ async fetchAttribution(options) {
566
+ const {
567
+ timeout = DEFAULT_TIMEOUT
568
+ } = options;
569
+ try {
570
+ const endpoint = this.getEndpoint();
571
+ const installId = await getInstallId();
572
+ const deviceInfo = getDeviceInfo();
573
+ if (this.config?.debug) {
574
+ console.log('[Mobana] Fetching attribution...');
575
+ console.log('[Mobana] Device info:', deviceInfo);
576
+ }
577
+
578
+ // Get Android Install Referrer for deterministic attribution
579
+ let dacid = null;
580
+ if (deviceInfo.platform === 'android') {
581
+ dacid = await getInstallReferrer();
582
+ if (this.config?.debug) {
583
+ console.log('[Mobana] Install Referrer dacid:', dacid || '(not available)');
584
+ }
585
+ }
586
+
587
+ // Make API request
588
+ const response = await findAttribution(endpoint, this.config.appKey, installId, deviceInfo, dacid, timeout, this.config?.debug ?? false);
589
+
590
+ // If no response (network error, timeout), don't cache - allow retry
591
+ if (!response) {
592
+ if (this.config?.debug) {
593
+ console.log('[Mobana] No response from server');
594
+ }
595
+ return null;
596
+ }
597
+
598
+ // Cache the response if server returned a valid response with matched key
599
+ // This prevents retrying on every startup
600
+ if (typeof response.matched === 'boolean') {
601
+ if (response.matched && response.attribution) {
602
+ // Build attribution object
603
+ const attribution = {
604
+ ...response.attribution,
605
+ confidence: response.confidence ?? 0
606
+ };
607
+
608
+ // Cache matched result
609
+ await setCachedResult(true, attribution);
610
+ if (this.config?.debug) {
611
+ console.log('[Mobana] Attribution matched:', attribution);
612
+ }
613
+ return attribution;
614
+ } else {
615
+ // Cache unmatched result - prevents retry on next startup
616
+ await setCachedResult(false);
617
+ if (this.config?.debug) {
618
+ console.log('[Mobana] No match found (cached)');
619
+ }
620
+ return null;
621
+ }
622
+ }
623
+
624
+ // Unexpected response format
625
+ if (this.config?.debug) {
626
+ console.log('[Mobana] Unexpected response format');
627
+ }
628
+ return null;
629
+ } catch (error) {
630
+ if (this.config?.debug) {
631
+ console.log('[Mobana] Error fetching attribution:', error);
632
+ }
633
+ return null;
634
+ }
635
+ }
636
+ async sendConversion(event) {
637
+ try {
638
+ const endpoint = this.getEndpoint();
639
+ return await trackConversionApi(endpoint, this.config.appKey, event, this.config?.debug ?? false);
640
+ } catch {
641
+ return false;
642
+ }
643
+ }
644
+ async flushConversionQueue() {
645
+ if (!this.config?.enabled) {
646
+ return;
647
+ }
648
+ const queue = await getConversionQueue();
649
+ if (queue.length === 0) {
650
+ return;
651
+ }
652
+ if (this.config?.debug) {
653
+ console.log(`[Mobana] Flushing ${queue.length} queued conversions`);
654
+ }
655
+
656
+ // Send all queued conversions
657
+ const results = await Promise.all(queue.map(event => this.sendConversion(event)));
658
+
659
+ // Clear the queue, then re-queue only the failures (avoids duplicate sends)
660
+ await clearConversionQueue();
661
+ const failed = queue.filter((_, i) => !results[i]);
662
+ for (const event of failed) {
663
+ await queueConversion(event);
664
+ }
665
+ }
666
+ }
667
+
668
+ // Export class for testing (create fresh instances without shared state)
669
+ export { MobanaSDK };
670
+
671
+ // Export singleton instance
672
+ export const Mobana = new MobanaSDK();
673
+ //# sourceMappingURL=Mobana.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["getInstallId","getCachedResult","setCachedResult","clearAttribution","queueConversion","getConversionQueue","clearConversionQueue","getCachedFlow","setCachedFlow","clearAllCachedFlows","clearLocalData","findAttribution","trackConversionApi","fetchFlow","getDeviceInfo","getInstallReferrer","getGlobalFlowContext","DEFAULT_ENDPOINT","DEFAULT_TIMEOUT","MobanaSDK","config","isConfigured","attributionPromise","cachedAttribution","attributionChecked","init","appId","console","warn","appKey","enabled","debug","installId","log","endpoint","flushConversionQueue","setEnabled","getAttribution","options","cached","matched","attribution","fetchAttribution","result","trackConversion","name","value","flowSessionId","event","timestamp","Date","now","success","sendConversion","reset","startFlow","slug","completed","dismissed","error","flowContext","isProviderMounted","getEndpoint","hasCached","cachedVersionId","versionId","response","presentFlowToUser","flowConfig","html","css","js","prefetchFlow","params","Promise","resolve","presentFlow","replace","Error","timeout","deviceInfo","dacid","platform","confidence","queue","length","results","all","map","failed","filter","_","i","Mobana"],"sourceRoot":"../../src","sources":["Mobana.ts"],"mappings":";;AASA,SACEA,YAAY,EACZC,eAAe,EACfC,eAAe,EACfC,gBAAgB,EAChBC,eAAe,EACfC,kBAAkB,EAClBC,oBAAoB,EACpBC,aAAa,EACbC,aAAa,EACbC,mBAAmB,EACnBC,cAAc,QACT,WAAW;AAClB,SAASC,eAAe,EAAEC,kBAAkB,EAAEC,SAAS,QAAQ,OAAO;AACtE,SAASC,aAAa,QAAQ,UAAU;AACxC,SAASC,kBAAkB,QAAQ,gBAAgB;AACnD,SAASC,oBAAoB,QAAQ,6BAA6B;AAElE,MAAMC,gBAAgB,GAAG,2BAA2B;AACpD,MAAMC,eAAe,GAAG,KAAK;;AAE7B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,SAAS,CAAC;EACNC,MAAM,GAAwB,IAAI;EAClCC,YAAY,GAAG,KAAK;EAC5B;EACQC,kBAAkB,GAA4C,IAAI;EAC1E;EACA;EACQC,iBAAiB,GAA4B,IAAI;EACjDC,kBAAkB,GAAG,KAAK;;EAElC;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACE,MAAMC,IAAIA,CAACL,MAAoB,EAAiB;IAC9C,IAAI,CAACA,MAAM,C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