riuve-rn 1.0.3 → 1.0.5

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 CHANGED
@@ -263,6 +263,24 @@ const token = await Notifications.getExpoPushTokenAsync();
263
263
  await Riuve.setFcmToken(token.data);
264
264
  ```
265
265
 
266
+ ### 5. Locale / Language Override
267
+
268
+ Override the device locale so the backend session uses your chosen language (e.g. for localized push notifications):
269
+
270
+ ```typescript
271
+ // At initialization (e.g. from stored user preference)
272
+ await Riuve.initialize('api_key', {
273
+ localeOverride: 'tr', // 'tr' | 'en' | 'ar' | etc.
274
+ });
275
+
276
+ // Or change later (updates backend session locale)
277
+ await Riuve.setLocale('en');
278
+ ```
279
+
280
+ - **Persisted**: The override is stored and restored on next app launch.
281
+ - **Backend**: Session locale is updated via the initialize endpoint, so campaigns/notifications can use the selected language.
282
+ - **Format**: Use short language codes (`tr`, `en`, `ar`) to match backend notification content keys.
283
+
266
284
  ---
267
285
 
268
286
  ## Best Practices
@@ -390,6 +408,9 @@ await Riuve.initialize('api_key', {
390
408
  // Debugging
391
409
  debugMode: false, // Enable detailed logging (default: false)
392
410
 
411
+ // Locale (session language for backend / push notifications)
412
+ localeOverride: undefined, // e.g. 'tr' | 'en' | 'ar' (optional, persisted)
413
+
393
414
  // Batch Settings
394
415
  batchSize: 10, // Number of events per batch (default: 10)
395
416
  batchTimeout: 30000, // Auto-send timeout in ms (default: 30000)
@@ -655,6 +676,25 @@ const token = await Notifications.getExpoPushTokenAsync();
655
676
  await Riuve.setFcmToken(token.data);
656
677
  ```
657
678
 
679
+ ### Riuve.setLocale()
680
+
681
+ Sets the session locale override and syncs it to the backend (e.g. for localized push notifications). Call after SDK is initialized.
682
+
683
+ ```typescript
684
+ await Riuve.setLocale(locale: string): Promise<void>
685
+ ```
686
+
687
+ **Parameters:**
688
+ - `locale` (string, required): Language code (e.g. `'tr'`, `'en'`, `'ar'`)
689
+
690
+ **Example:**
691
+ ```typescript
692
+ // User changed app language in settings
693
+ await Riuve.setLocale('tr');
694
+ ```
695
+
696
+ **Note:** The value is persisted and used on next `initialize()`; the backend session is updated immediately so campaign/notification content can use the new locale.
697
+
658
698
  ### Riuve.isReady()
659
699
 
660
700
  Checks if SDK is initialized.
@@ -843,5 +883,5 @@ MIT
843
883
 
844
884
  ---
845
885
 
846
- **Last Updated:** 2025-01-29
847
- **SDK Version:** 1.1.1
886
+ **Last Updated:** 2026-02-07
887
+ **SDK Version:** 1.0.2
@@ -1 +1 @@
1
- {"version":3,"file":"Riuve.d.ts","sourceRoot":"","sources":["../src/Riuve.ts"],"names":[],"mappings":"AAAA;;GAEG;AAWH,OAAO,KAAK,EAAE,WAAW,EAAS,MAAM,SAAS,CAAC;AAWlD,cAAM,QAAQ;IACZ,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAyB;IAChD,OAAO,CAAC,MAAM,CAA4B;IAC1C,OAAO,CAAC,aAAa,CAAkB;IAEvC,OAAO,CAAC,UAAU,CAA2B;IAC7C,OAAO,CAAC,SAAS,CAA0B;IAC3C,OAAO,CAAC,eAAe,CAAgC;IACvD,OAAO,CAAC,cAAc,CAA+B;IACrD,OAAO,CAAC,YAAY,CAA6B;IAEjD,OAAO,CAAC,oBAAoB,CAAa;IACzC,OAAO,CAAC,aAAa,CAA4F;IAEjH;;OAEG;IACH,OAAO;IAEP;;OAEG;IACH,MAAM,CAAC,WAAW,IAAI,QAAQ;IAO9B;;OAEG;IACG,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAgI9F;;OAEG;IACG,QAAQ,CACZ,cAAc,EAAE,MAAM,EACtB,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GACnC,OAAO,CAAC,IAAI,CAAC;IAuChB;;OAEG;IACG,KAAK,CAAC,SAAS,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AAO;IAIlB;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAc7B;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAMzB;;OAEG;IACH,OAAO,CAAC,YAAY;IAOpB;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CA4B/B;AAGD,QAAA,MAAM,KAAK,UAAyB,CAAC;AAErC,eAAe,KAAK,CAAC"}
package/dist/Riuve.js CHANGED
@@ -51,6 +51,8 @@ class RiuveSDK {
51
51
  ...config,
52
52
  apiKey,
53
53
  };
54
+ // Initialize storage adapter (must happen before any storage operations)
55
+ Storage_1.storage.initialize(this.config.storage);
54
56
  // Restore persisted locale override if not passed in config
55
57
  if (this.config.localeOverride === undefined) {
56
58
  const storedLocale = await Storage_1.storage.get('LOCALE_OVERRIDE');
@@ -1 +1 @@
1
- {"version":3,"file":"NativeDeviceInfo.d.ts","sourceRoot":"","sources":["../../../src/adapters/deviceInfo/NativeDeviceInfo.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAEjE,qBAAa,gBAAiB,YAAW,iBAAiB;IACxD,OAAO,CAAC,UAAU,CAA+B;IAE3C,OAAO,IAAI,OAAO,CAAC,cAAc,CAAC;IAoDxC,SAAS,IAAI,cAAc,GAAG,IAAI;IAIlC;;OAEG;IACH,OAAO,CAAC,SAAS;CAiBlB"}
1
+ {"version":3,"file":"NativeDeviceInfo.d.ts","sourceRoot":"","sources":["../../../src/adapters/deviceInfo/NativeDeviceInfo.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAUjE,qBAAa,gBAAiB,YAAW,iBAAiB;IACxD,OAAO,CAAC,UAAU,CAA+B;IAE3C,OAAO,IAAI,OAAO,CAAC,cAAc,CAAC;IAoDxC,SAAS,IAAI,cAAc,GAAG,IAAI;IAIlC;;OAEG;IACH,OAAO,CAAC,SAAS;CAiBlB"}
@@ -5,13 +5,17 @@
5
5
  * Uses react-native-device-info for maximum device information.
6
6
  * This adapter provides the most comprehensive data but requires native modules.
7
7
  */
8
- var __importDefault = (this && this.__importDefault) || function (mod) {
9
- return (mod && mod.__esModule) ? mod : { "default": mod };
10
- };
11
8
  Object.defineProperty(exports, "__esModule", { value: true });
12
9
  exports.NativeDeviceInfo = void 0;
13
- const react_native_device_info_1 = __importDefault(require("react-native-device-info"));
14
10
  const react_native_1 = require("react-native");
11
+ // Dynamic require to avoid Metro bundling error when module is not installed
12
+ let DeviceInfo;
13
+ try {
14
+ DeviceInfo = require('react-native-device-info').default;
15
+ }
16
+ catch {
17
+ DeviceInfo = null;
18
+ }
15
19
  class NativeDeviceInfo {
16
20
  constructor() {
17
21
  this.cachedInfo = null;
@@ -22,11 +26,11 @@ class NativeDeviceInfo {
22
26
  }
23
27
  try {
24
28
  const [systemVersion, model, version, manufacturer, brand,] = await Promise.all([
25
- react_native_device_info_1.default.getSystemVersion(),
26
- react_native_device_info_1.default.getModel(),
27
- react_native_device_info_1.default.getVersion(),
28
- react_native_device_info_1.default.getManufacturer(),
29
- react_native_device_info_1.default.getBrand(),
29
+ DeviceInfo.getSystemVersion(),
30
+ DeviceInfo.getModel(),
31
+ DeviceInfo.getVersion(),
32
+ DeviceInfo.getManufacturer(),
33
+ DeviceInfo.getBrand(),
30
34
  ]);
31
35
  // Get locale
32
36
  const locale = this.getLocale();
@@ -1 +1 @@
1
- {"version":3,"file":"NativeNetworkManager.d.ts","sourceRoot":"","sources":["../../../src/adapters/network/NativeNetworkManager.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C,qBAAa,oBAAqB,YAAW,cAAc;IACzD,OAAO,CAAC,QAAQ,CAAiB;IACjC,OAAO,CAAC,SAAS,CAA0C;IAC3D,OAAO,CAAC,WAAW,CAA6B;IAE1C,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAWjC,WAAW,IAAI,OAAO;IAItB,cAAc,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE,OAAO,KAAK,IAAI,GAAG,IAAI;IAIrD,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAU9B,OAAO,IAAI,IAAI;IAQf,OAAO,CAAC,mBAAmB;IAS3B,OAAO,CAAC,eAAe;CASxB"}
1
+ {"version":3,"file":"NativeNetworkManager.d.ts","sourceRoot":"","sources":["../../../src/adapters/network/NativeNetworkManager.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAW9C,qBAAa,oBAAqB,YAAW,cAAc;IACzD,OAAO,CAAC,QAAQ,CAAiB;IACjC,OAAO,CAAC,SAAS,CAA0C;IAC3D,OAAO,CAAC,WAAW,CAA6B;IAE1C,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAWjC,WAAW,IAAI,OAAO;IAItB,cAAc,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE,OAAO,KAAK,IAAI,GAAG,IAAI;IAIrD,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAU9B,OAAO,IAAI,IAAI;IAQf,OAAO,CAAC,mBAAmB;IAS3B,OAAO,CAAC,eAAe;CASxB"}
@@ -5,12 +5,16 @@
5
5
  * Uses @react-native-community/netinfo for network monitoring.
6
6
  * This adapter provides real-time network status updates via event listeners.
7
7
  */
8
- var __importDefault = (this && this.__importDefault) || function (mod) {
9
- return (mod && mod.__esModule) ? mod : { "default": mod };
10
- };
11
8
  Object.defineProperty(exports, "__esModule", { value: true });
12
9
  exports.NativeNetworkManager = void 0;
13
- const netinfo_1 = __importDefault(require("@react-native-community/netinfo"));
10
+ // Dynamic require to avoid Metro bundling error when module is not installed
11
+ let NetInfo;
12
+ try {
13
+ NetInfo = require('@react-native-community/netinfo').default;
14
+ }
15
+ catch {
16
+ NetInfo = null;
17
+ }
14
18
  class NativeNetworkManager {
15
19
  constructor() {
16
20
  this.isOnline = true;
@@ -19,10 +23,10 @@ class NativeNetworkManager {
19
23
  }
20
24
  async initialize() {
21
25
  // Check initial network state
22
- const state = await netinfo_1.default.fetch();
26
+ const state = await NetInfo.fetch();
23
27
  this.isOnline = state.isConnected ?? true;
24
28
  // Subscribe to network state changes
25
- this.unsubscribe = netinfo_1.default.addEventListener((state) => {
29
+ this.unsubscribe = NetInfo.addEventListener((state) => {
26
30
  this.handleNetworkChange(state);
27
31
  });
28
32
  }
@@ -33,7 +37,7 @@ class NativeNetworkManager {
33
37
  this.listeners.push(callback);
34
38
  }
35
39
  async refresh() {
36
- const state = await netinfo_1.default.fetch();
40
+ const state = await NetInfo.fetch();
37
41
  const wasOnline = this.isOnline;
38
42
  this.isOnline = state.isConnected ?? true;
39
43
  if (wasOnline !== this.isOnline) {
@@ -0,0 +1,14 @@
1
+ /**
2
+ * AsyncStorage Adapter
3
+ *
4
+ * Default storage adapter using @react-native-async-storage/async-storage.
5
+ */
6
+ import type { StorageAdapter } from './types';
7
+ export declare class AsyncStorageAdapter implements StorageAdapter {
8
+ constructor();
9
+ getItem(key: string): Promise<string | null>;
10
+ setItem(key: string, value: string): Promise<void>;
11
+ removeItem(key: string): Promise<void>;
12
+ multiRemove(keys: string[]): Promise<void>;
13
+ }
14
+ //# sourceMappingURL=AsyncStorageAdapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AsyncStorageAdapter.d.ts","sourceRoot":"","sources":["../../../src/adapters/storage/AsyncStorageAdapter.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAU9C,qBAAa,mBAAoB,YAAW,cAAc;;IAUlD,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAI5C,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIlD,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAItC,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAGjD"}
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ /**
3
+ * AsyncStorage Adapter
4
+ *
5
+ * Default storage adapter using @react-native-async-storage/async-storage.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.AsyncStorageAdapter = void 0;
9
+ // Dynamic require to avoid Metro bundling error when module is not installed
10
+ let AsyncStorage;
11
+ try {
12
+ AsyncStorage = require('@react-native-async-storage/async-storage').default;
13
+ }
14
+ catch {
15
+ AsyncStorage = null;
16
+ }
17
+ class AsyncStorageAdapter {
18
+ constructor() {
19
+ if (!AsyncStorage) {
20
+ throw new Error('AsyncStorage is not available. Install @react-native-async-storage/async-storage ' +
21
+ 'or provide a custom storage adapter (e.g., MMKVStorageAdapter).');
22
+ }
23
+ }
24
+ async getItem(key) {
25
+ return AsyncStorage.getItem(key);
26
+ }
27
+ async setItem(key, value) {
28
+ await AsyncStorage.setItem(key, value);
29
+ }
30
+ async removeItem(key) {
31
+ await AsyncStorage.removeItem(key);
32
+ }
33
+ async multiRemove(keys) {
34
+ await AsyncStorage.multiRemove(keys);
35
+ }
36
+ }
37
+ exports.AsyncStorageAdapter = AsyncStorageAdapter;
@@ -0,0 +1,34 @@
1
+ /**
2
+ * MMKV Storage Adapter
3
+ *
4
+ * Storage adapter using react-native-mmkv for high-performance synchronous storage.
5
+ * The user must create their own MMKV instance and pass it to this adapter.
6
+ *
7
+ * Usage:
8
+ * import { MMKV } from 'react-native-mmkv';
9
+ * import { MMKVStorageAdapter } from 'riuve-rn';
10
+ *
11
+ * const mmkv = new MMKV({ id: 'riuve-storage' });
12
+ * const storageAdapter = new MMKVStorageAdapter(mmkv);
13
+ *
14
+ * await Riuve.initialize('api_key', { storage: storageAdapter });
15
+ */
16
+ import type { StorageAdapter } from './types';
17
+ /**
18
+ * Minimal MMKV interface that the adapter depends on.
19
+ * This avoids importing react-native-mmkv as a dependency.
20
+ */
21
+ export interface MMKVInterface {
22
+ getString(key: string): string | undefined;
23
+ set(key: string, value: string): void;
24
+ delete(key: string): void;
25
+ }
26
+ export declare class MMKVStorageAdapter implements StorageAdapter {
27
+ private mmkv;
28
+ constructor(mmkv: MMKVInterface);
29
+ getItem(key: string): Promise<string | null>;
30
+ setItem(key: string, value: string): Promise<void>;
31
+ removeItem(key: string): Promise<void>;
32
+ multiRemove(keys: string[]): Promise<void>;
33
+ }
34
+ //# sourceMappingURL=MMKVStorageAdapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MMKVStorageAdapter.d.ts","sourceRoot":"","sources":["../../../src/adapters/storage/MMKVStorageAdapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IAC3C,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACtC,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B;AAED,qBAAa,kBAAmB,YAAW,cAAc;IACvD,OAAO,CAAC,IAAI,CAAgB;gBAEhB,IAAI,EAAE,aAAa;IASzB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAI5C,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIlD,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAItC,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAKjD"}
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ /**
3
+ * MMKV Storage Adapter
4
+ *
5
+ * Storage adapter using react-native-mmkv for high-performance synchronous storage.
6
+ * The user must create their own MMKV instance and pass it to this adapter.
7
+ *
8
+ * Usage:
9
+ * import { MMKV } from 'react-native-mmkv';
10
+ * import { MMKVStorageAdapter } from 'riuve-rn';
11
+ *
12
+ * const mmkv = new MMKV({ id: 'riuve-storage' });
13
+ * const storageAdapter = new MMKVStorageAdapter(mmkv);
14
+ *
15
+ * await Riuve.initialize('api_key', { storage: storageAdapter });
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.MMKVStorageAdapter = void 0;
19
+ class MMKVStorageAdapter {
20
+ constructor(mmkv) {
21
+ if (!mmkv) {
22
+ throw new Error('MMKV instance is required. Create one with: new MMKV({ id: "riuve-storage" })');
23
+ }
24
+ this.mmkv = mmkv;
25
+ }
26
+ async getItem(key) {
27
+ return this.mmkv.getString(key) ?? null;
28
+ }
29
+ async setItem(key, value) {
30
+ this.mmkv.set(key, value);
31
+ }
32
+ async removeItem(key) {
33
+ this.mmkv.delete(key);
34
+ }
35
+ async multiRemove(keys) {
36
+ for (const key of keys) {
37
+ this.mmkv.delete(key);
38
+ }
39
+ }
40
+ }
41
+ exports.MMKVStorageAdapter = MMKVStorageAdapter;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Storage Adapter Exports
3
+ *
4
+ * Unlike network and deviceInfo adapters, the storage adapter is user-configured
5
+ * rather than auto-detected. The default is AsyncStorageAdapter.
6
+ */
7
+ export type { StorageAdapter } from './types';
8
+ export { AsyncStorageAdapter } from './AsyncStorageAdapter';
9
+ export { MMKVStorageAdapter } from './MMKVStorageAdapter';
10
+ export type { MMKVInterface } from './MMKVStorageAdapter';
11
+ import type { StorageAdapter } from './types';
12
+ /**
13
+ * Creates the default storage adapter (AsyncStorage).
14
+ */
15
+ export declare function createDefaultStorageAdapter(): StorageAdapter;
16
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/adapters/storage/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAC9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,YAAY,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAG1D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C;;GAEG;AACH,wBAAgB,2BAA2B,IAAI,cAAc,CAE5D"}
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ /**
3
+ * Storage Adapter Exports
4
+ *
5
+ * Unlike network and deviceInfo adapters, the storage adapter is user-configured
6
+ * rather than auto-detected. The default is AsyncStorageAdapter.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.MMKVStorageAdapter = exports.AsyncStorageAdapter = void 0;
10
+ exports.createDefaultStorageAdapter = createDefaultStorageAdapter;
11
+ var AsyncStorageAdapter_1 = require("./AsyncStorageAdapter");
12
+ Object.defineProperty(exports, "AsyncStorageAdapter", { enumerable: true, get: function () { return AsyncStorageAdapter_1.AsyncStorageAdapter; } });
13
+ var MMKVStorageAdapter_1 = require("./MMKVStorageAdapter");
14
+ Object.defineProperty(exports, "MMKVStorageAdapter", { enumerable: true, get: function () { return MMKVStorageAdapter_1.MMKVStorageAdapter; } });
15
+ const AsyncStorageAdapter_2 = require("./AsyncStorageAdapter");
16
+ /**
17
+ * Creates the default storage adapter (AsyncStorage).
18
+ */
19
+ function createDefaultStorageAdapter() {
20
+ return new AsyncStorageAdapter_2.AsyncStorageAdapter();
21
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Storage Adapter Types
3
+ *
4
+ * Defines the interface that all storage adapters must implement.
5
+ * All methods are async since AsyncStorage requires it.
6
+ * Synchronous adapters (like MMKV) wrap their results in resolved promises.
7
+ */
8
+ export interface StorageAdapter {
9
+ /** Gets a string value by key. Returns null if the key does not exist. */
10
+ getItem(key: string): Promise<string | null>;
11
+ /** Sets a string value for a key. */
12
+ setItem(key: string, value: string): Promise<void>;
13
+ /** Removes a key from storage. */
14
+ removeItem(key: string): Promise<void>;
15
+ /** Removes multiple keys from storage. */
16
+ multiRemove(keys: string[]): Promise<void>;
17
+ }
18
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/adapters/storage/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,WAAW,cAAc;IAC7B,0EAA0E;IAC1E,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAE7C,qCAAqC;IACrC,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEnD,kCAAkC;IAClC,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEvC,0CAA0C;IAC1C,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5C"}
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ /**
3
+ * Storage Adapter Types
4
+ *
5
+ * Defines the interface that all storage adapters must implement.
6
+ * All methods are async since AsyncStorage requires it.
7
+ * Synchronous adapters (like MMKV) wrap their results in resolved promises.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,8 +1,19 @@
1
1
  /**
2
- * Storage Layer - AsyncStorage Wrapper
2
+ * Storage Layer - Adapter-based Storage Wrapper
3
3
  */
4
+ import type { StorageAdapter } from '../adapters/storage/types';
4
5
  import type { StorageKey, StorageValue } from '../types/storage';
5
6
  declare class Storage {
7
+ private adapter;
8
+ /**
9
+ * Initializes storage with the given adapter.
10
+ * If no adapter is provided, uses AsyncStorageAdapter as default.
11
+ */
12
+ initialize(adapter?: StorageAdapter): void;
13
+ /**
14
+ * Gets the active adapter, initializing with default if needed.
15
+ */
16
+ private getAdapter;
6
17
  /**
7
18
  * Sets a value in storage
8
19
  */
@@ -1 +1 @@
1
- {"version":3,"file":"Storage.d.ts","sourceRoot":"","sources":["../../src/core/Storage.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAGjE,cAAM,OAAO;IACX;;OAEG;IACG,GAAG,CAAC,CAAC,SAAS,UAAU,EAC5B,GAAG,EAAE,CAAC,EACN,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC,GACrB,OAAO,CAAC,IAAI,CAAC;IAYhB;;OAEG;IACG,GAAG,CAAC,CAAC,SAAS,UAAU,EAC5B,GAAG,EAAE,CAAC,GACL,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IAiBlC;;OAEG;IACG,MAAM,CAAC,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAW5C;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAW5B;;OAEG;IACG,GAAG,CAAC,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC;CAQ7C;AAED,eAAO,MAAM,OAAO,SAAgB,CAAC"}
1
+ {"version":3,"file":"Storage.d.ts","sourceRoot":"","sources":["../../src/core/Storage.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAGhE,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAGjE,cAAM,OAAO;IACX,OAAO,CAAC,OAAO,CAA+B;IAE9C;;;OAGG;IACH,UAAU,CAAC,OAAO,CAAC,EAAE,cAAc,GAAG,IAAI;IAI1C;;OAEG;IACH,OAAO,CAAC,UAAU;IAOlB;;OAEG;IACG,GAAG,CAAC,CAAC,SAAS,UAAU,EAC5B,GAAG,EAAE,CAAC,EACN,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC,GACrB,OAAO,CAAC,IAAI,CAAC;IAWhB;;OAEG;IACG,GAAG,CAAC,CAAC,SAAS,UAAU,EAC5B,GAAG,EAAE,CAAC,GACL,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IAiBlC;;OAEG;IACG,MAAM,CAAC,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAU5C;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAU5B;;OAEG;IACG,GAAG,CAAC,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC;CAQ7C;AAED,eAAO,MAAM,OAAO,SAAgB,CAAC"}
@@ -1,16 +1,32 @@
1
1
  "use strict";
2
2
  /**
3
- * Storage Layer - AsyncStorage Wrapper
3
+ * Storage Layer - Adapter-based Storage Wrapper
4
4
  */
5
- var __importDefault = (this && this.__importDefault) || function (mod) {
6
- return (mod && mod.__esModule) ? mod : { "default": mod };
7
- };
8
5
  Object.defineProperty(exports, "__esModule", { value: true });
9
6
  exports.storage = void 0;
10
- const async_storage_1 = __importDefault(require("@react-native-async-storage/async-storage"));
7
+ const storage_1 = require("../adapters/storage");
11
8
  const constants_1 = require("../constants");
12
9
  const logger_1 = require("../utils/logger");
13
10
  class Storage {
11
+ constructor() {
12
+ this.adapter = null;
13
+ }
14
+ /**
15
+ * Initializes storage with the given adapter.
16
+ * If no adapter is provided, uses AsyncStorageAdapter as default.
17
+ */
18
+ initialize(adapter) {
19
+ this.adapter = adapter ?? (0, storage_1.createDefaultStorageAdapter)();
20
+ }
21
+ /**
22
+ * Gets the active adapter, initializing with default if needed.
23
+ */
24
+ getAdapter() {
25
+ if (!this.adapter) {
26
+ this.adapter = (0, storage_1.createDefaultStorageAdapter)();
27
+ }
28
+ return this.adapter;
29
+ }
14
30
  /**
15
31
  * Sets a value in storage
16
32
  */
@@ -18,8 +34,7 @@ class Storage {
18
34
  try {
19
35
  const storageKey = constants_1.STORAGE_KEYS[key];
20
36
  const serialized = JSON.stringify(value);
21
- await async_storage_1.default.setItem(storageKey, serialized);
22
- // Removed verbose debug logging for production
37
+ await this.getAdapter().setItem(storageKey, serialized);
23
38
  }
24
39
  catch (error) {
25
40
  logger_1.logger.error(`Storage set failed for ${key}:`, error);
@@ -32,7 +47,7 @@ class Storage {
32
47
  async get(key) {
33
48
  try {
34
49
  const storageKey = constants_1.STORAGE_KEYS[key];
35
- const serialized = await async_storage_1.default.getItem(storageKey);
50
+ const serialized = await this.getAdapter().getItem(storageKey);
36
51
  if (serialized === null) {
37
52
  return null;
38
53
  }
@@ -50,8 +65,7 @@ class Storage {
50
65
  async remove(key) {
51
66
  try {
52
67
  const storageKey = constants_1.STORAGE_KEYS[key];
53
- await async_storage_1.default.removeItem(storageKey);
54
- // Removed verbose debug logging for production
68
+ await this.getAdapter().removeItem(storageKey);
55
69
  }
56
70
  catch (error) {
57
71
  logger_1.logger.error(`Storage remove failed for ${key}:`, error);
@@ -64,8 +78,7 @@ class Storage {
64
78
  async clear() {
65
79
  try {
66
80
  const keys = Object.values(constants_1.STORAGE_KEYS);
67
- await async_storage_1.default.multiRemove(keys);
68
- // Removed verbose info logging for production
81
+ await this.getAdapter().multiRemove(keys);
69
82
  }
70
83
  catch (error) {
71
84
  logger_1.logger.error('Storage clear failed:', error);
package/dist/index.d.ts CHANGED
@@ -5,5 +5,7 @@
5
5
  import Riuve from './Riuve';
6
6
  export default Riuve;
7
7
  export type { RiuveConfig, RiuveConfigInput, Event, DeviceInfo, EventBatch, FailedBatch, InitializeRequest, InitializeResponse, IdentifyRequest, IdentifyResponse, TrackRequest, TrackResponse, SetFcmTokenRequest, SetFcmTokenResponse, ApiError, ErrorType, } from './types';
8
+ export { AsyncStorageAdapter, MMKVStorageAdapter } from './adapters/storage';
9
+ export type { StorageAdapter, MMKVInterface } from './adapters/storage';
8
10
  export { DEFAULT_CONFIG, ERROR_MESSAGES } from './constants';
9
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,MAAM,SAAS,CAAC;AAG5B,eAAe,KAAK,CAAC;AAGrB,YAAY,EACV,WAAW,EACX,gBAAgB,EAChB,KAAK,EACL,UAAU,EACV,UAAU,EACV,WAAW,EACX,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,EACf,gBAAgB,EAChB,YAAY,EACZ,aAAa,EACb,kBAAkB,EAClB,mBAAmB,EACnB,QAAQ,EACR,SAAS,GACV,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,MAAM,SAAS,CAAC;AAG5B,eAAe,KAAK,CAAC;AAGrB,YAAY,EACV,WAAW,EACX,gBAAgB,EAChB,KAAK,EACL,UAAU,EACV,UAAU,EACV,WAAW,EACX,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,EACf,gBAAgB,EAChB,YAAY,EACZ,aAAa,EACb,kBAAkB,EAClB,mBAAmB,EACnB,QAAQ,EACR,SAAS,GACV,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAC7E,YAAY,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGxE,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC"}
package/dist/index.js CHANGED
@@ -7,10 +7,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
7
7
  return (mod && mod.__esModule) ? mod : { "default": mod };
8
8
  };
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.ERROR_MESSAGES = exports.DEFAULT_CONFIG = void 0;
10
+ exports.ERROR_MESSAGES = exports.DEFAULT_CONFIG = exports.MMKVStorageAdapter = exports.AsyncStorageAdapter = void 0;
11
11
  const Riuve_1 = __importDefault(require("./Riuve"));
12
12
  // Export the SDK instance as default
13
13
  exports.default = Riuve_1.default;
14
+ // Export storage adapters for custom storage configuration
15
+ var storage_1 = require("./adapters/storage");
16
+ Object.defineProperty(exports, "AsyncStorageAdapter", { enumerable: true, get: function () { return storage_1.AsyncStorageAdapter; } });
17
+ Object.defineProperty(exports, "MMKVStorageAdapter", { enumerable: true, get: function () { return storage_1.MMKVStorageAdapter; } });
14
18
  // Export constants for advanced users
15
19
  var constants_1 = require("./constants");
16
20
  Object.defineProperty(exports, "DEFAULT_CONFIG", { enumerable: true, get: function () { return constants_1.DEFAULT_CONFIG; } });
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * Configuration Types
3
3
  */
4
+ import type { StorageAdapter } from '../adapters/storage/types';
4
5
  export interface RiuveConfig {
5
6
  /** API key for authenticating with the backend */
6
7
  apiKey: string;
@@ -26,6 +27,8 @@ export interface RiuveConfig {
26
27
  debugMode: boolean;
27
28
  /** Override device locale for session (e.g. 'tr', 'en', 'ar'). Persisted and sent to backend. */
28
29
  localeOverride?: string;
30
+ /** Custom storage adapter (default: AsyncStorageAdapter). Use MMKVStorageAdapter for MMKV. */
31
+ storage?: StorageAdapter;
29
32
  }
30
33
  /** Partial configuration that can be passed during initialization */
31
34
  export type RiuveConfigInput = Partial<Omit<RiuveConfig, 'apiKey'>> & {
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/types/config.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,WAAW;IAC1B,kDAAkD;IAClD,MAAM,EAAE,MAAM,CAAC;IAEf,6DAA6D;IAC7D,SAAS,EAAE,MAAM,CAAC;IAElB,mFAAmF;IACnF,YAAY,EAAE,MAAM,CAAC;IAErB,wEAAwE;IACxE,UAAU,EAAE,MAAM,CAAC;IAEnB,oEAAoE;IACpE,UAAU,EAAE,MAAM,CAAC;IAEnB,oEAAoE;IACpE,aAAa,EAAE,OAAO,CAAC;IAEvB,6EAA6E;IAC7E,qBAAqB,EAAE,OAAO,CAAC;IAE/B,iEAAiE;IACjE,YAAY,EAAE,MAAM,CAAC;IAErB,0DAA0D;IAC1D,kBAAkB,EAAE,MAAM,CAAC;IAE3B,uDAAuD;IACvD,cAAc,EAAE,MAAM,CAAC;IAEvB,+DAA+D;IAC/D,SAAS,EAAE,OAAO,CAAC;IAEnB,iGAAiG;IACjG,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,qEAAqE;AACrE,MAAM,MAAM,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC,GAAG;IACpE,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/types/config.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAEhE,MAAM,WAAW,WAAW;IAC1B,kDAAkD;IAClD,MAAM,EAAE,MAAM,CAAC;IAEf,6DAA6D;IAC7D,SAAS,EAAE,MAAM,CAAC;IAElB,mFAAmF;IACnF,YAAY,EAAE,MAAM,CAAC;IAErB,wEAAwE;IACxE,UAAU,EAAE,MAAM,CAAC;IAEnB,oEAAoE;IACpE,UAAU,EAAE,MAAM,CAAC;IAEnB,oEAAoE;IACpE,aAAa,EAAE,OAAO,CAAC;IAEvB,6EAA6E;IAC7E,qBAAqB,EAAE,OAAO,CAAC;IAE/B,iEAAiE;IACjE,YAAY,EAAE,MAAM,CAAC;IAErB,0DAA0D;IAC1D,kBAAkB,EAAE,MAAM,CAAC;IAE3B,uDAAuD;IACvD,cAAc,EAAE,MAAM,CAAC;IAEvB,+DAA+D;IAC/D,SAAS,EAAE,OAAO,CAAC;IAEnB,iGAAiG;IACjG,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB,8FAA8F;IAC9F,OAAO,CAAC,EAAE,cAAc,CAAC;CAC1B;AAED,qEAAqE;AACrE,MAAM,MAAM,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC,GAAG;IACpE,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "riuve-rn",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "Behavioral event tracking SDK for React Native with offline support and intelligent batching",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -31,6 +31,12 @@
31
31
  "react-native": ">=0.70.0"
32
32
  },
33
33
  "peerDependenciesMeta": {
34
+ "@react-native-async-storage/async-storage": {
35
+ "optional": true
36
+ },
37
+ "react-native-mmkv": {
38
+ "optional": true
39
+ },
34
40
  "react-native-device-info": {
35
41
  "optional": true
36
42
  },
package/dist/Rive.d.ts DELETED
@@ -1,91 +0,0 @@
1
- /**
2
- * Rive SDK - Main SDK Class (Singleton)
3
- */
4
- import type { RiveConfig } from './types';
5
- declare class RiveSDK {
6
- private static instance;
7
- private config;
8
- private isInitialized;
9
- private eventQueue;
10
- private apiClient;
11
- private identityManager;
12
- private networkManager;
13
- private batchManager;
14
- private appStateSubscription;
15
- private pendingEvents;
16
- /**
17
- * Private constructor for singleton pattern
18
- */
19
- private constructor();
20
- /**
21
- * Gets the singleton instance
22
- */
23
- static getInstance(): RiveSDK;
24
- /**
25
- * Initializes the SDK
26
- */
27
- initialize(apiKey: string, config?: Partial<Omit<RiveConfig, 'apiKey'>>): Promise<void>;
28
- /**
29
- * Identifies a user
30
- */
31
- identify(externalUserId: string, userProperties?: Record<string, any>): Promise<void>;
32
- /**
33
- * Tracks an event
34
- */
35
- track(eventName: string, eventProperties?: Record<string, any>): Promise<void>;
36
- /**
37
- * Sets the FCM token for push notifications
38
- */
39
- setFcmToken(token: string): Promise<void>;
40
- /**
41
- * Manually flushes all pending events
42
- */
43
- flush(): Promise<void>;
44
- /**
45
- * Resets the SDK (new anonymous user)
46
- */
47
- reset(): Promise<void>;
48
- /**
49
- * Gets the anonymous ID
50
- */
51
- getAnonymousId(): string | null;
52
- /**
53
- * Gets the external user ID
54
- */
55
- getExternalUserId(): string | null;
56
- /**
57
- * Gets the current configuration
58
- */
59
- getConfig(): RiveConfig | null;
60
- /**
61
- * Gets the event queue size
62
- */
63
- getQueueSize(): number;
64
- /**
65
- * Gets the failed batch count
66
- */
67
- getFailedBatchCount(): Promise<number>;
68
- /**
69
- * Checks if the SDK is initialized
70
- */
71
- isReady(): boolean;
72
- /**
73
- * Sets up app state listener for background flush
74
- */
75
- private setupAppStateListener;
76
- /**
77
- * Ensures the SDK is initialized before operations
78
- */
79
- private ensureInitialized;
80
- /**
81
- * Truncates JSON string if too long
82
- */
83
- private truncateJson;
84
- /**
85
- * Cleanup method (for testing or app shutdown)
86
- */
87
- cleanup(): Promise<void>;
88
- }
89
- declare const Rive: RiveSDK;
90
- export default Rive;
91
- //# sourceMappingURL=Rive.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Rive.d.ts","sourceRoot":"","sources":["../src/Rive.ts"],"names":[],"mappings":"AAAA;;GAEG;AAWH,OAAO,KAAK,EAAE,UAAU,EAAS,MAAM,SAAS,CAAC;AAWjD,cAAM,OAAO;IACX,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAwB;IAC/C,OAAO,CAAC,MAAM,CAA2B;IACzC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AI,OAAO;IAIlB;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAc7B;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAMzB;;OAEG;IACH,OAAO,CAAC,YAAY;IAOpB;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CA4B/B;AAGD,QAAA,MAAM,IAAI,SAAwB,CAAC;AAEnC,eAAe,IAAI,CAAC"}
package/dist/Rive.js DELETED
@@ -1,402 +0,0 @@
1
- "use strict";
2
- /**
3
- * Rive SDK - Main SDK Class (Singleton)
4
- */
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const uuid_1 = require("./utils/uuid");
7
- const react_native_1 = require("react-native");
8
- const EventQueue_1 = require("./core/EventQueue");
9
- const ApiClient_1 = require("./core/ApiClient");
10
- const DeviceInfo_1 = require("./core/DeviceInfo");
11
- const Storage_1 = require("./core/Storage");
12
- const IdentityManager_1 = require("./managers/IdentityManager");
13
- const NetworkManager_1 = require("./managers/NetworkManager");
14
- const BatchManager_1 = require("./managers/BatchManager");
15
- const constants_1 = require("./constants");
16
- const logger_1 = require("./utils/logger");
17
- const validators_1 = require("./utils/validators");
18
- class RiveSDK {
19
- /**
20
- * Private constructor for singleton pattern
21
- */
22
- constructor() {
23
- this.config = null;
24
- this.isInitialized = false;
25
- this.eventQueue = null;
26
- this.apiClient = null;
27
- this.identityManager = null;
28
- this.networkManager = null;
29
- this.batchManager = null;
30
- this.appStateSubscription = null;
31
- this.pendingEvents = [];
32
- }
33
- /**
34
- * Gets the singleton instance
35
- */
36
- static getInstance() {
37
- if (!RiveSDK.instance) {
38
- RiveSDK.instance = new RiveSDK();
39
- }
40
- return RiveSDK.instance;
41
- }
42
- /**
43
- * Initializes the SDK
44
- */
45
- async initialize(apiKey, config) {
46
- // Validate API key
47
- (0, validators_1.validateApiKey)(apiKey);
48
- // Build full config
49
- this.config = {
50
- ...constants_1.DEFAULT_CONFIG,
51
- ...config,
52
- apiKey,
53
- };
54
- // Enable debug mode if configured
55
- logger_1.logger.setDebugMode(this.config.debugMode);
56
- logger_1.logger.info('Initializing Rive SDK...');
57
- logger_1.logger.debug('Config:', this.config);
58
- try {
59
- // Initialize managers
60
- this.identityManager = new IdentityManager_1.IdentityManager();
61
- const anonymousId = await this.identityManager.initialize();
62
- this.networkManager = new NetworkManager_1.NetworkManager();
63
- await this.networkManager.initialize();
64
- // Initialize API client with hardcoded base URL
65
- this.apiClient = new ApiClient_1.ApiClient(constants_1.API_BASE_URL, this.config.apiKey, this.config.maxRetries, this.config.retryDelay, this.config.requestTimeout);
66
- // Initialize event queue
67
- this.eventQueue = new EventQueue_1.EventQueue(this.config.batchSize, this.config.batchTimeout, this.config.maxQueueSize);
68
- // Load persisted events from storage
69
- await this.eventQueue.loadFromStorage();
70
- // Initialize batch manager
71
- this.batchManager = new BatchManager_1.BatchManager(this.eventQueue, this.apiClient, this.networkManager, this.identityManager, this.config.eventRetentionDays);
72
- // Collect device info
73
- const deviceInfo = await DeviceInfo_1.deviceInfoCollector.collect();
74
- // Call initialize endpoint
75
- if (this.networkManager.isConnected()) {
76
- try {
77
- await this.apiClient.initialize({
78
- anonymous_id: anonymousId,
79
- device_info: deviceInfo,
80
- });
81
- logger_1.logger.info('SDK initialized successfully on backend');
82
- }
83
- catch (error) {
84
- logger_1.logger.warn('Failed to initialize on backend (will retry):', error);
85
- }
86
- }
87
- else {
88
- logger_1.logger.warn('Offline - backend initialization will occur when online');
89
- }
90
- // Setup app state listener for background flush
91
- if (this.config.autoFlushOnBackground) {
92
- this.setupAppStateListener();
93
- }
94
- // Process pending events (events that were tracked before initialization)
95
- if (this.pendingEvents.length > 0) {
96
- logger_1.logger.info(`Processing ${this.pendingEvents.length} pending events...`);
97
- const anonymousId = this.identityManager.getAnonymousId();
98
- const externalUserId = this.identityManager.getExternalUserId();
99
- let processedCount = 0;
100
- for (const pendingEvent of this.pendingEvents) {
101
- try {
102
- const event = {
103
- id: (0, uuid_1.generateUUID)(),
104
- name: pendingEvent.eventName,
105
- properties: pendingEvent.eventProperties,
106
- timestamp: pendingEvent.timestamp, // Use original timestamp
107
- anonymousId,
108
- externalUserId: externalUserId || undefined,
109
- };
110
- await this.eventQueue.enqueue(event);
111
- processedCount++;
112
- logger_1.logger.info(` Processed pending event: ${pendingEvent.eventName} (id: ${event.id})`);
113
- }
114
- catch (error) {
115
- logger_1.logger.error(`Failed to process pending event '${pendingEvent.eventName}':`, error);
116
- }
117
- }
118
- logger_1.logger.info(`Successfully processed ${processedCount}/${this.pendingEvents.length} pending events`);
119
- this.pendingEvents = []; // Clear pending events
120
- }
121
- this.isInitialized = true;
122
- logger_1.logger.info('Rive SDK initialized successfully');
123
- // Flush any offline queue
124
- await this.batchManager.flushOfflineQueue();
125
- }
126
- catch (error) {
127
- logger_1.logger.error('Failed to initialize SDK:', error);
128
- throw error;
129
- }
130
- }
131
- /**
132
- * Identifies a user
133
- */
134
- async identify(externalUserId, userProperties) {
135
- this.ensureInitialized();
136
- // Validate inputs
137
- (0, validators_1.validateUserId)(externalUserId);
138
- if (userProperties) {
139
- (0, validators_1.validateUserProperties)(userProperties);
140
- }
141
- logger_1.logger.info(`Identifying user: ${externalUserId}`);
142
- try {
143
- // Update identity manager
144
- await this.identityManager.identify(externalUserId, userProperties);
145
- // Call identify endpoint if online
146
- if (this.networkManager.isConnected()) {
147
- try {
148
- const anonymousId = this.identityManager.getAnonymousId();
149
- await this.apiClient.identify({
150
- anonymous_id: anonymousId,
151
- external_user_id: externalUserId,
152
- user_properties: userProperties,
153
- });
154
- logger_1.logger.info('User identified on backend successfully');
155
- }
156
- catch (error) {
157
- logger_1.logger.warn('Failed to identify user on backend:', error);
158
- }
159
- }
160
- else {
161
- logger_1.logger.warn('Offline - user will be identified when online');
162
- }
163
- }
164
- catch (error) {
165
- logger_1.logger.error('Failed to identify user:', error);
166
- throw error;
167
- }
168
- }
169
- /**
170
- * Tracks an event
171
- */
172
- async track(eventName, eventProperties) {
173
- // Validate inputs
174
- (0, validators_1.validateEventName)(eventName);
175
- if (eventProperties) {
176
- (0, validators_1.validateEventProperties)(eventProperties);
177
- }
178
- // If SDK is not initialized yet, add to pending events queue
179
- if (!this.isInitialized) {
180
- const timestamp = Date.now();
181
- this.pendingEvents.push({
182
- eventName,
183
- eventProperties,
184
- timestamp,
185
- });
186
- const propsStr = eventProperties ? this.truncateJson(JSON.stringify(eventProperties), 150) : 'none';
187
- logger_1.logger.info(`Event tracked: ${eventName}`);
188
- logger_1.logger.info(` Properties: ${propsStr}`);
189
- logger_1.logger.info(` Timestamp: ${new Date(timestamp).toISOString()}`);
190
- logger_1.logger.info(` Status: Added to pending queue (SDK not initialized yet)`);
191
- logger_1.logger.info(` Pending queue size: ${this.pendingEvents.length}`);
192
- return;
193
- }
194
- // SDK is initialized, proceed with normal flow
195
- try {
196
- const event = {
197
- id: (0, uuid_1.generateUUID)(),
198
- name: eventName,
199
- properties: eventProperties,
200
- timestamp: Date.now(),
201
- anonymousId: this.identityManager.getAnonymousId(),
202
- externalUserId: this.identityManager.getExternalUserId() || undefined,
203
- };
204
- const queueSizeBefore = this.eventQueue.size();
205
- // Add to queue
206
- await this.eventQueue.enqueue(event);
207
- const queueSizeAfter = this.eventQueue.size();
208
- const propsStr = eventProperties ? this.truncateJson(JSON.stringify(eventProperties), 150) : 'none';
209
- logger_1.logger.info(`Event tracked: ${eventName}`);
210
- logger_1.logger.info(` Properties: ${propsStr}`);
211
- logger_1.logger.info(` Event ID: ${event.id.substring(0, 8)}...`);
212
- logger_1.logger.info(` Timestamp: ${new Date(event.timestamp).toISOString()}`);
213
- logger_1.logger.info(` Queue size: ${queueSizeBefore} -> ${queueSizeAfter}/${this.config.maxQueueSize}`);
214
- logger_1.logger.info(` Status: Added to queue`);
215
- }
216
- catch (error) {
217
- logger_1.logger.error(`Failed to track event '${eventName}':`, error);
218
- throw error;
219
- }
220
- }
221
- /**
222
- * Sets the FCM token for push notifications
223
- */
224
- async setFcmToken(token) {
225
- this.ensureInitialized();
226
- if (typeof token !== 'string' || token.trim().length === 0) {
227
- throw new Error('FCM token must be a non-empty string');
228
- }
229
- logger_1.logger.info('Setting FCM token...');
230
- try {
231
- // Store token
232
- await Storage_1.storage.set('FCM_TOKEN', token);
233
- // Send to backend if online
234
- if (this.networkManager.isConnected()) {
235
- try {
236
- const anonymousId = this.identityManager.getAnonymousId();
237
- const externalUserId = this.identityManager.getExternalUserId();
238
- await this.apiClient.setFcmToken({
239
- anonymous_id: anonymousId,
240
- external_user_id: externalUserId || undefined,
241
- fcm_token: token,
242
- });
243
- logger_1.logger.info('FCM token set successfully');
244
- }
245
- catch (error) {
246
- logger_1.logger.warn('Failed to set FCM token on backend:', error);
247
- }
248
- }
249
- else {
250
- logger_1.logger.warn('Offline - FCM token will be sent when online');
251
- }
252
- }
253
- catch (error) {
254
- logger_1.logger.error('Failed to set FCM token:', error);
255
- throw error;
256
- }
257
- }
258
- /**
259
- * Manually flushes all pending events
260
- */
261
- async flush() {
262
- this.ensureInitialized();
263
- logger_1.logger.info('Manually flushing events...');
264
- try {
265
- await this.eventQueue.flush();
266
- logger_1.logger.info('Flush completed');
267
- }
268
- catch (error) {
269
- logger_1.logger.error('Flush failed:', error);
270
- throw error;
271
- }
272
- }
273
- /**
274
- * Resets the SDK (new anonymous user)
275
- */
276
- async reset() {
277
- this.ensureInitialized();
278
- logger_1.logger.info('Resetting SDK...');
279
- try {
280
- // Flush pending events
281
- await this.flush();
282
- // Reset identity
283
- await this.identityManager.reset();
284
- // Clear FCM token
285
- await Storage_1.storage.remove('FCM_TOKEN');
286
- logger_1.logger.info('SDK reset successfully');
287
- }
288
- catch (error) {
289
- logger_1.logger.error('Failed to reset SDK:', error);
290
- throw error;
291
- }
292
- }
293
- /**
294
- * Gets the anonymous ID
295
- */
296
- getAnonymousId() {
297
- if (!this.isInitialized || !this.identityManager) {
298
- return null;
299
- }
300
- return this.identityManager.getAnonymousId();
301
- }
302
- /**
303
- * Gets the external user ID
304
- */
305
- getExternalUserId() {
306
- if (!this.isInitialized || !this.identityManager) {
307
- return null;
308
- }
309
- return this.identityManager.getExternalUserId();
310
- }
311
- /**
312
- * Gets the current configuration
313
- */
314
- getConfig() {
315
- return this.config ? { ...this.config } : null;
316
- }
317
- /**
318
- * Gets the event queue size
319
- */
320
- getQueueSize() {
321
- if (!this.isInitialized || !this.eventQueue) {
322
- return 0;
323
- }
324
- return this.eventQueue.size();
325
- }
326
- /**
327
- * Gets the failed batch count
328
- */
329
- async getFailedBatchCount() {
330
- if (!this.isInitialized || !this.batchManager) {
331
- return 0;
332
- }
333
- return this.batchManager.getFailedBatchCount();
334
- }
335
- /**
336
- * Checks if the SDK is initialized
337
- */
338
- isReady() {
339
- return this.isInitialized;
340
- }
341
- /**
342
- * Sets up app state listener for background flush
343
- */
344
- setupAppStateListener() {
345
- this.appStateSubscription = react_native_1.AppState.addEventListener('change', (nextAppState) => {
346
- if (nextAppState === 'background' || nextAppState === 'inactive') {
347
- logger_1.logger.info('App going to background, flushing events...');
348
- this.flush().catch((error) => {
349
- logger_1.logger.error('Background flush failed:', error);
350
- });
351
- }
352
- });
353
- }
354
- /**
355
- * Ensures the SDK is initialized before operations
356
- */
357
- ensureInitialized() {
358
- if (!this.isInitialized) {
359
- throw new Error(constants_1.ERROR_MESSAGES.NOT_INITIALIZED);
360
- }
361
- }
362
- /**
363
- * Truncates JSON string if too long
364
- */
365
- truncateJson(json, maxLength) {
366
- if (json.length <= maxLength) {
367
- return json;
368
- }
369
- return json.substring(0, maxLength) + '...';
370
- }
371
- /**
372
- * Cleanup method (for testing or app shutdown)
373
- */
374
- async cleanup() {
375
- logger_1.logger.info('Cleaning up SDK...');
376
- // Flush pending events
377
- if (this.eventQueue) {
378
- try {
379
- await this.eventQueue.flush();
380
- }
381
- catch (error) {
382
- logger_1.logger.warn('Failed to flush during cleanup:', error);
383
- }
384
- this.eventQueue.destroy();
385
- }
386
- // Cleanup network manager
387
- if (this.networkManager) {
388
- this.networkManager.cleanup();
389
- }
390
- // Remove app state listener
391
- if (this.appStateSubscription) {
392
- this.appStateSubscription.remove();
393
- this.appStateSubscription = null;
394
- }
395
- this.isInitialized = false;
396
- logger_1.logger.info('SDK cleanup completed');
397
- }
398
- }
399
- RiveSDK.instance = null;
400
- // Export singleton instance methods
401
- const Rive = RiveSDK.getInstance();
402
- exports.default = Rive;