riuve-rn 1.0.4 → 1.0.6

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
@@ -55,14 +55,24 @@ or
55
55
  yarn add riuve-rn
56
56
  ```
57
57
 
58
- ### 2. Install Required Dependencies
58
+ ### 2. Install a Storage Backend
59
59
 
60
- **AsyncStorage** is required for the SDK to function:
60
+ The SDK needs a storage backend for persisting events and user data. Choose **one** of the following:
61
+
62
+ **Option A: AsyncStorage (default)**
61
63
 
62
64
  ```bash
63
65
  npm install @react-native-async-storage/async-storage
64
66
  ```
65
67
 
68
+ **Option B: MMKV (recommended for performance)**
69
+
70
+ ```bash
71
+ npm install react-native-mmkv
72
+ ```
73
+
74
+ > MMKV is a high-performance synchronous storage library. If your project already uses MMKV, you can use it with the SDK — no need to install AsyncStorage. See [MMKV Storage](#6-mmkv-storage) for setup.
75
+
66
76
  ### 3. (Optional) Expo Modules
67
77
 
68
78
  If you're using Expo, install these for device info and network monitoring:
@@ -263,7 +273,27 @@ const token = await Notifications.getExpoPushTokenAsync();
263
273
  await Riuve.setFcmToken(token.data);
264
274
  ```
265
275
 
266
- ### 5. Locale / Language Override
276
+ ### 5. MMKV Storage
277
+
278
+ By default the SDK uses AsyncStorage. If your project uses `react-native-mmkv`, you can pass it as a custom storage adapter for better performance:
279
+
280
+ ```typescript
281
+ import { MMKV } from 'react-native-mmkv';
282
+ import Riuve, { MMKVStorageAdapter } from 'riuve-rn';
283
+
284
+ const mmkv = new MMKV({ id: 'riuve-storage' });
285
+
286
+ await Riuve.initialize('api_key', {
287
+ storage: new MMKVStorageAdapter(mmkv),
288
+ });
289
+ ```
290
+
291
+ **Why MMKV?**
292
+ - Synchronous reads/writes (no async overhead)
293
+ - ~30x faster than AsyncStorage
294
+ - No need to install AsyncStorage if you already use MMKV
295
+
296
+ ### 6. Locale / Language Override
267
297
 
268
298
  Override the device locale so the backend session uses your chosen language (e.g. for localized push notifications):
269
299
 
@@ -427,6 +457,10 @@ await Riuve.initialize('api_key', {
427
457
  maxQueueSize: 1000, // Maximum queue size (default: 1000)
428
458
  eventRetentionDays: 7, // Days to keep failed events (default: 7)
429
459
 
460
+ // Storage
461
+ storage: undefined, // Custom storage adapter (default: AsyncStorageAdapter)
462
+ // Use new MMKVStorageAdapter(mmkv) for MMKV
463
+
430
464
  // Automatic Operations
431
465
  autoFlushOnBackground: true, // Auto-flush on background (default: true)
432
466
  });
@@ -883,5 +917,5 @@ MIT
883
917
 
884
918
  ---
885
919
 
886
- **Last Updated:** 2026-02-07
887
- **SDK Version:** 1.0.2
920
+ **Last Updated:** 2026-02-25
921
+ **SDK Version:** 1.0.5
@@ -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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EG;IACH,YAAY,IAAI,MAAM;IAOtB;;OAEG;IACG,mBAAmB,IAAI,OAAO,CAAC,MAAM,CAAC;IAO5C;;OAEG;IACH,OAAO,IAAI,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,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');
@@ -101,6 +103,29 @@ class RiuveSDK {
101
103
  if (this.config.autoFlushOnBackground) {
102
104
  this.setupAppStateListener();
103
105
  }
106
+ // Process immediate events FIRST (e.g. app_opened) — before any pending events
107
+ const immediateEvents = this.config.immediateEvents;
108
+ if (immediateEvents && immediateEvents.length > 0) {
109
+ const anonymousId = this.identityManager.getAnonymousId();
110
+ const externalUserId = this.identityManager.getExternalUserId();
111
+ for (const ie of immediateEvents) {
112
+ try {
113
+ const event = {
114
+ id: (0, uuid_1.generateUUID)(),
115
+ name: ie.name,
116
+ properties: ie.properties,
117
+ timestamp: Date.now(),
118
+ anonymousId,
119
+ externalUserId: externalUserId || undefined,
120
+ };
121
+ await this.eventQueue.enqueue(event);
122
+ logger_1.logger.info(`Immediate event enqueued: ${ie.name}`);
123
+ }
124
+ catch (error) {
125
+ logger_1.logger.error(`Failed to enqueue immediate event '${ie.name}':`, error);
126
+ }
127
+ }
128
+ }
104
129
  // Process pending events (events that were tracked before initialization)
105
130
  if (this.pendingEvents.length > 0) {
106
131
  logger_1.logger.info(`Processing ${this.pendingEvents.length} pending events...`);
@@ -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;;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AAG,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,17 @@ 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;
32
+ /**
33
+ * Events to enqueue immediately during initialization, BEFORE any pending events.
34
+ * Use this for events like 'app_opened' that must appear first in the timeline,
35
+ * even when child components queue screen_viewed events before initialize() runs.
36
+ */
37
+ immediateEvents?: Array<{
38
+ name: string;
39
+ properties?: Record<string, any>;
40
+ }>;
29
41
  }
30
42
  /** Partial configuration that can be passed during initialization */
31
43
  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,o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,CAAC,EAAE,cAAc,CAAC;IAEzB;;;;OAIG;IACH,eAAe,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;KAAE,CAAC,CAAC;CAC7E;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.4",
3
+ "version": "1.0.6",
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
  },