@metarouter/react-native-sdk 0.1.25 → 0.1.27

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.
@@ -24,12 +24,12 @@ export declare class IdentityManager {
24
24
  * Sets the user ID for the current session.
25
25
  * @param userId - The user ID to set.
26
26
  */
27
- identify(userId: string): void;
27
+ identify(userId: string): Promise<void>;
28
28
  /**
29
29
  * Sets the group ID for the current session.
30
30
  * @param groupId - The group ID to set.
31
31
  */
32
- group(groupId: string): void;
32
+ group(groupId: string): Promise<void>;
33
33
  /**
34
34
  * Retrieves the current user ID.
35
35
  * @returns The user ID or undefined if not set.
@@ -50,6 +50,6 @@ export declare class IdentityManager {
50
50
  * Resets the identity manager to its initial state.
51
51
  * Clears all user and group IDs, and sets the anonymous ID to null.
52
52
  */
53
- reset(): void;
53
+ reset(): Promise<void>;
54
54
  }
55
55
  //# sourceMappingURL=IdentityManager.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"IdentityManager.d.ts","sourceRoot":"","sources":["../../src/analytics/IdentityManager.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAE1D;;;;;;GAMG;AACH,qBAAa,eAAe;IACxB,OAAO,CAAC,WAAW,CAAuB;IAC1C,OAAO,CAAC,MAAM,CAAC,CAAS;IACxB,OAAO,CAAC,OAAO,CAAC,CAAS;IAEzB;;;KAGC;IACK,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAY3B;;;OAGG;IACH,cAAc,IAAI,MAAM,GAAG,IAAI;IAI/B;;;OAGG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM;IAKvB;;;OAGG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM;IAKrB;;;OAGG;IACH,SAAS,IAAI,MAAM,GAAG,SAAS;IAI/B;;;OAGG;IACH,UAAU,IAAI,MAAM,GAAG,SAAS;IAIhC;;;;OAIG;IACH,eAAe,CAAC,CAAC,SAAS,YAAY,EAAE,KAAK,EAAE,CAAC,GAAG,iBAAiB;IASpE;;;OAGG;IACH,KAAK;CAMN"}
1
+ {"version":3,"file":"IdentityManager.d.ts","sourceRoot":"","sources":["../../src/analytics/IdentityManager.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAG1D;;;;;;GAMG;AACH,qBAAa,eAAe;IACxB,OAAO,CAAC,WAAW,CAAuB;IAC1C,OAAO,CAAC,MAAM,CAAC,CAAS;IACxB,OAAO,CAAC,OAAO,CAAC,CAAS;IAEzB;;;KAGC;IACK,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAuB3B;;;OAGG;IACH,cAAc,IAAI,MAAM,GAAG,IAAI;IAI/B;;;OAGG;IACG,QAAQ,CAAC,MAAM,EAAE,MAAM;IAU7B;;;OAGG;IACG,KAAK,CAAC,OAAO,EAAE,MAAM;IAU3B;;;OAGG;IACH,SAAS,IAAI,MAAM,GAAG,SAAS;IAI/B;;;OAGG;IACH,UAAU,IAAI,MAAM,GAAG,SAAS;IAIhC;;;;OAIG;IACH,eAAe,CAAC,CAAC,SAAS,YAAY,EAAE,KAAK,EAAE,CAAC,GAAG,iBAAiB;IASpE;;;OAGG;IACG,KAAK;CAaZ"}
@@ -1,5 +1,5 @@
1
- import { getAnonymousId } from "./utils/anonymousId";
2
1
  import { log, warn } from "./utils/logger";
2
+ import { USER_ID_KEY, GROUP_ID_KEY, ANONYMOUS_ID_KEY, getIdentityField, setIdentityField, removeIdentityField } from './utils/identityStorage';
3
3
  /**
4
4
  * Manages user, group, and anonymous identity for analytics events.
5
5
  * - Loads or generates a persistent anonymous ID.
@@ -17,12 +17,23 @@ export class IdentityManager {
17
17
  */
18
18
  async init() {
19
19
  try {
20
- this.anonymousId = await getAnonymousId(); // load or generate
21
- log('IdentityManager initialized with anonymous ID:', this.anonymousId);
20
+ const storedAnonId = await getIdentityField(ANONYMOUS_ID_KEY);
21
+ if (!storedAnonId) {
22
+ const newId = `anon-${Date.now()}-${Math.random().toString(36).substring(2, 10)}`;
23
+ await setIdentityField(ANONYMOUS_ID_KEY, newId);
24
+ this.anonymousId = newId;
25
+ log('Generated and stored new anonymous ID:', newId);
26
+ }
27
+ else {
28
+ this.anonymousId = storedAnonId;
29
+ log('Loaded stored anonymous ID:', storedAnonId);
30
+ }
31
+ this.userId = await getIdentityField(USER_ID_KEY) || undefined;
32
+ this.groupId = await getIdentityField(GROUP_ID_KEY) || undefined;
33
+ log('IdentityManager initialized with anonymous ID:', this.anonymousId, 'userId:', this.userId, 'groupId:', this.groupId);
22
34
  }
23
35
  catch (error) {
24
36
  warn('Failed to initialize IdentityManager, using fallback anonymous ID', error);
25
- // Fallback: generate a temporary anonymous ID
26
37
  this.anonymousId = `fallback-${Date.now()}-${Math.random().toString(36).substring(2, 10)}`;
27
38
  log('Using fallback anonymous ID:', this.anonymousId);
28
39
  }
@@ -38,16 +49,28 @@ export class IdentityManager {
38
49
  * Sets the user ID for the current session.
39
50
  * @param userId - The user ID to set.
40
51
  */
41
- identify(userId) {
52
+ async identify(userId) {
42
53
  this.userId = userId;
54
+ try {
55
+ await setIdentityField(USER_ID_KEY, userId);
56
+ }
57
+ catch (error) {
58
+ warn('Failed to persist userId', error);
59
+ }
43
60
  log('User identified:', userId);
44
61
  }
45
62
  /**
46
63
  * Sets the group ID for the current session.
47
64
  * @param groupId - The group ID to set.
48
65
  */
49
- group(groupId) {
66
+ async group(groupId) {
50
67
  this.groupId = groupId;
68
+ try {
69
+ await setIdentityField(GROUP_ID_KEY, groupId);
70
+ }
71
+ catch (error) {
72
+ warn('Failed to persist groupId', error);
73
+ }
51
74
  log('User grouped:', groupId);
52
75
  }
53
76
  /**
@@ -82,10 +105,18 @@ export class IdentityManager {
82
105
  * Resets the identity manager to its initial state.
83
106
  * Clears all user and group IDs, and sets the anonymous ID to null.
84
107
  */
85
- reset() {
108
+ async reset() {
86
109
  this.anonymousId = null;
87
110
  this.userId = undefined;
88
111
  this.groupId = undefined;
112
+ try {
113
+ await removeIdentityField(ANONYMOUS_ID_KEY);
114
+ await removeIdentityField(USER_ID_KEY);
115
+ await removeIdentityField(GROUP_ID_KEY);
116
+ }
117
+ catch (error) {
118
+ warn('Failed to clear userId/groupId/anonymousId from storage', error);
119
+ }
89
120
  log('IdentityManager reset');
90
121
  }
91
122
  }
@@ -18,6 +18,7 @@ export declare class MetaRouterAnalyticsClient {
18
18
  private appState;
19
19
  private appStateSubscription;
20
20
  private identityManager;
21
+ private static readonly MAX_QUEUE_SIZE;
21
22
  /**
22
23
  * Initializes the analytics client with the provided options.
23
24
  * @param options - The initialization options.
@@ -1 +1 @@
1
- {"version":3,"file":"MetaRouterAnalyticsClient.d.ts","sourceRoot":"","sources":["../../src/analytics/MetaRouterAnalyticsClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,WAAW,EACZ,MAAM,SAAS,CAAC;AAQjB;;;;;;GAMG;AACH,qBAAa,yBAAyB;IACpC,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,WAAW,CAAgB;IACnC,OAAO,CAAC,KAAK,CAAsB;IACnC,OAAO,CAAC,eAAe,CAAS;IAChC,OAAO,CAAC,UAAU,CAA+B;IACjD,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,OAAO,CAAgB;IAC/B,OAAO,CAAC,QAAQ,CAAyC;IACzD,OAAO,CAAC,oBAAoB,CAAwC;IACpE,OAAO,CAAC,eAAe,CAAkB;IAEzC;;;OAGG;gBACS,OAAO,EAAE,WAAW;IAchC;;;OAGG;YACW,IAAI;IA8BlB;;;OAGG;IACG,qBAAqB,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5C;;OAEG;IACH,OAAO,CAAC,cAAc;IAItB;;;OAGG;IACH,OAAO,CAAC,GAAG;IAIX;;;OAGG;IACH,OAAO,CAAC,OAAO;IAWf;;OAEG;IACH,OAAO,CA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AEG;IACH,KAAK;IAML;;OAEG;IACH,OAAO;CAOR"}
@@ -97,6 +97,10 @@ export class MetaRouterAnalyticsClient {
97
97
  * @param event - The event to enqueue.
98
98
  */
99
99
  enqueue(event) {
100
+ if (this.queue.length >= MetaRouterAnalyticsClient.MAX_QUEUE_SIZE) {
101
+ log(`Event queue reached max size (${MetaRouterAnalyticsClient.MAX_QUEUE_SIZE}). Attempting to flush queued events before adding new.`);
102
+ this.flush();
103
+ }
100
104
  const eventWithIdentity = this.identityManager.addIdentityInfo(event);
101
105
  const enrichedEvent = enrichEvent(eventWithIdentity, this.writeKey, this.context);
102
106
  log("Enqueuing event", enrichedEvent);
@@ -269,3 +273,4 @@ export class MetaRouterAnalyticsClient {
269
273
  (_b = (_a = this.appStateSubscription) === null || _a === void 0 ? void 0 : _a.remove) === null || _b === void 0 ? void 0 : _b.call(_a);
270
274
  }
271
275
  }
276
+ MetaRouterAnalyticsClient.MAX_QUEUE_SIZE = 20;
@@ -2,7 +2,7 @@ import { MetaRouterAnalyticsClient } from './MetaRouterAnalyticsClient';
2
2
  import { proxyClient, setRealClient } from './proxy/proxyClient';
3
3
  let initialized = false;
4
4
  let client = null;
5
- let analyticsInterface = null;
5
+ let analyticsClient = null;
6
6
  /**
7
7
  * Initializes the analytics client singleton.
8
8
  * Waits for async setup (e.g., identity loading) before returning the interface.
@@ -12,11 +12,11 @@ let analyticsInterface = null;
12
12
  */
13
13
  export async function initAnalytics(options) {
14
14
  if (initialized)
15
- return analyticsInterface;
15
+ return analyticsClient;
16
16
  client = new MetaRouterAnalyticsClient(options);
17
17
  // Wait for the client to fully initialize (including anonymous ID loading)
18
18
  await client.waitForInitialization();
19
- analyticsInterface = {
19
+ analyticsClient = {
20
20
  track: (event, props) => client.track(event, props),
21
21
  identify: (userId, traits) => client.identify(userId, traits),
22
22
  group: (groupId, traits) => client.group(groupId, traits),
@@ -28,8 +28,8 @@ export async function initAnalytics(options) {
28
28
  getDebugInfo: () => client.getDebugInfo(),
29
29
  };
30
30
  initialized = true;
31
- setRealClient(analyticsInterface);
32
- return analyticsInterface;
31
+ setRealClient(analyticsClient);
32
+ return analyticsClient;
33
33
  }
34
34
  /**
35
35
  * Retrieves the analytics client singleton.
@@ -37,7 +37,7 @@ export async function initAnalytics(options) {
37
37
  * @returns The analytics interface.
38
38
  */
39
39
  export function getAnalyticsClient() {
40
- return initialized ? analyticsInterface : proxyClient;
40
+ return initialized ? analyticsClient : proxyClient;
41
41
  }
42
42
  /**
43
43
  * Resets the analytics client singleton.
@@ -47,7 +47,7 @@ export function getAnalyticsClient() {
47
47
  export async function resetAnalytics() {
48
48
  await (client === null || client === void 0 ? void 0 : client.cleanup());
49
49
  client = null;
50
- analyticsInterface = null;
50
+ analyticsClient = null;
51
51
  initialized = false;
52
52
  setRealClient(null);
53
53
  }
@@ -1 +1 @@
1
- {"version":3,"file":"proxyClient.d.ts","sourceRoot":"","sources":["../../../src/analytics/proxy/proxyClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAwBnD;;;;;;;;;;;;GAYG;AAEH,eAAO,MAAM,WAAW,EAAE,kBAWzB,CAAC;AAEF,wBAAgB,aAAa,CAAC,MAAM,EAAE,kBAAkB,GAAG,IAAI,QAO9D"}
1
+ {"version":3,"file":"proxyClient.d.ts","sourceRoot":"","sources":["../../../src/analytics/proxy/proxyClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AA2BnD;;;;;;;;;;;;GAYG;AAEH,eAAO,MAAM,WAAW,EAAE,kBAWzB,CAAC;AAEF,wBAAgB,aAAa,CAAC,MAAM,EAAE,kBAAkB,GAAG,IAAI,QAO9D"}
@@ -1,11 +1,14 @@
1
1
  const pendingCalls = [];
2
+ const MAX_PENDING_CALLS = 20;
2
3
  let realClient = null;
3
4
  function handleMethodCall(methodName, ...args) {
4
5
  if (realClient) {
5
6
  return realClient[methodName](...args);
6
7
  }
7
- if (pendingCalls.length > 100) {
8
- console.warn(`[MetaRouter] Proxy queue exceeds 100 pending calls: ${methodName}`);
8
+ if (pendingCalls.length >= MAX_PENDING_CALLS) {
9
+ // Drop the oldest call
10
+ pendingCalls.shift();
11
+ console.warn(`[MetaRouter] Proxy queue reached max size (${MAX_PENDING_CALLS}). Oldest call dropped.`);
9
12
  }
10
13
  pendingCalls.push(() => {
11
14
  if (realClient) {
@@ -0,0 +1,7 @@
1
+ export declare const ANONYMOUS_ID_KEY = "metarouter:anonymous_id";
2
+ export declare const USER_ID_KEY = "metarouter:user_id";
3
+ export declare const GROUP_ID_KEY = "metarouter:group_id";
4
+ export declare function getIdentityField(key: string): Promise<string | null>;
5
+ export declare function setIdentityField(key: string, value: string): Promise<void>;
6
+ export declare function removeIdentityField(key: string): Promise<void>;
7
+ //# sourceMappingURL=identityStorage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identityStorage.d.ts","sourceRoot":"","sources":["../../../src/analytics/utils/identityStorage.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,gBAAgB,4BAA4B,CAAC;AAC1D,eAAO,MAAM,WAAW,uBAAuB,CAAC;AAChD,eAAO,MAAM,YAAY,wBAAwB,CAAC;AAElD,wBAAsB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAM1E;AAED,wBAAsB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAMhF;AAED,wBAAsB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAMpE"}
@@ -0,0 +1,28 @@
1
+ import AsyncStorage from '@react-native-async-storage/async-storage';
2
+ export const ANONYMOUS_ID_KEY = 'metarouter:anonymous_id';
3
+ export const USER_ID_KEY = 'metarouter:user_id';
4
+ export const GROUP_ID_KEY = 'metarouter:group_id';
5
+ export async function getIdentityField(key) {
6
+ try {
7
+ return await AsyncStorage.getItem(key);
8
+ }
9
+ catch {
10
+ return null;
11
+ }
12
+ }
13
+ export async function setIdentityField(key, value) {
14
+ try {
15
+ await AsyncStorage.setItem(key, value);
16
+ }
17
+ catch {
18
+ // Optionally log error
19
+ }
20
+ }
21
+ export async function removeIdentityField(key) {
22
+ try {
23
+ await AsyncStorage.removeItem(key);
24
+ }
25
+ catch {
26
+ // Optionally log error
27
+ }
28
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metarouter/react-native-sdk",
3
- "version": "0.1.25",
3
+ "version": "0.1.27",
4
4
  "main": "./lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "exports": {
@@ -1,8 +0,0 @@
1
- /**
2
- * Retrieves or generates a persistent anonymous ID for the user/device.
3
- * - Attempts to load from AsyncStorage.
4
- * - If not found or storage fails, generates a new UUIDv4.
5
- * - Always returns a valid string.
6
- */
7
- export declare function getAnonymousId(): Promise<string>;
8
- //# sourceMappingURL=anonymousId.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"anonymousId.d.ts","sourceRoot":"","sources":["../../../src/analytics/utils/anonymousId.ts"],"names":[],"mappings":"AAMA;;;;;GAKG;AACH,wBAAsB,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC,CAsBtD"}
@@ -1,32 +0,0 @@
1
- import AsyncStorage from '@react-native-async-storage/async-storage';
2
- import { v4 as uuidv4 } from 'uuid';
3
- import { log, warn } from './logger';
4
- const STORAGE_KEY = 'metarouter:anonymous_id';
5
- /**
6
- * Retrieves or generates a persistent anonymous ID for the user/device.
7
- * - Attempts to load from AsyncStorage.
8
- * - If not found or storage fails, generates a new UUIDv4.
9
- * - Always returns a valid string.
10
- */
11
- export async function getAnonymousId() {
12
- try {
13
- const existing = await AsyncStorage.getItem(STORAGE_KEY);
14
- if (existing) {
15
- log('Retrieved existing anonymous ID from storage');
16
- return existing;
17
- }
18
- }
19
- catch (error) {
20
- warn('Failed to read anonymous ID from storage, generating new one', error);
21
- }
22
- const anonId = uuidv4();
23
- log('Generated new anonymous ID:', anonId);
24
- try {
25
- await AsyncStorage.setItem(STORAGE_KEY, anonId);
26
- log('Stored anonymous ID in storage');
27
- }
28
- catch (error) {
29
- warn('Failed to store anonymous ID in storage, but continuing with generated ID', error);
30
- }
31
- return anonId;
32
- }