@metarouter/react-native-sdk 0.1.23 → 0.1.24

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 (43) hide show
  1. package/lib/MetaRouter.d.ts +11 -0
  2. package/lib/MetaRouter.d.ts.map +1 -1
  3. package/lib/MetaRouter.js +11 -0
  4. package/lib/analytics/IdentityManager.d.ts +40 -0
  5. package/lib/analytics/IdentityManager.d.ts.map +1 -1
  6. package/lib/analytics/IdentityManager.js +40 -0
  7. package/lib/analytics/MetaRouterAnalyticsClient.d.ts +72 -0
  8. package/lib/analytics/MetaRouterAnalyticsClient.d.ts.map +1 -1
  9. package/lib/analytics/MetaRouterAnalyticsClient.js +74 -11
  10. package/lib/analytics/init.d.ts +17 -0
  11. package/lib/analytics/init.d.ts.map +1 -1
  12. package/lib/analytics/init.js +17 -0
  13. package/lib/analytics/proxy/proxyClient.d.ts +13 -0
  14. package/lib/analytics/proxy/proxyClient.d.ts.map +1 -1
  15. package/lib/analytics/proxy/proxyClient.js +13 -0
  16. package/lib/analytics/utils/anonymousId.d.ts +6 -0
  17. package/lib/analytics/utils/anonymousId.d.ts.map +1 -1
  18. package/lib/analytics/utils/anonymousId.js +6 -0
  19. package/lib/analytics/utils/contextInfo.d.ts +12 -1
  20. package/lib/analytics/utils/contextInfo.d.ts.map +1 -1
  21. package/lib/analytics/utils/contextInfo.js +10 -0
  22. package/lib/analytics/utils/enrichEvent.d.ts +15 -0
  23. package/lib/analytics/utils/enrichEvent.d.ts.map +1 -0
  24. package/lib/analytics/utils/enrichEvent.js +22 -0
  25. package/lib/analytics/utils/logger.d.ts +23 -0
  26. package/lib/analytics/utils/logger.d.ts.map +1 -1
  27. package/lib/analytics/utils/logger.js +23 -2
  28. package/lib/analytics/utils/retry.d.ts +14 -0
  29. package/lib/analytics/utils/retry.d.ts.map +1 -1
  30. package/lib/analytics/utils/retry.js +14 -0
  31. package/lib/analytics/utils/timezone.d.ts +5 -0
  32. package/lib/analytics/utils/timezone.d.ts.map +1 -1
  33. package/lib/analytics/utils/timezone.js +5 -0
  34. package/lib/react/context.d.ts +9 -0
  35. package/lib/react/context.d.ts.map +1 -1
  36. package/lib/react/context.js +9 -0
  37. package/lib/react/useMetaRouter.d.ts +4 -0
  38. package/lib/react/useMetaRouter.d.ts.map +1 -1
  39. package/lib/react/useMetaRouter.js +4 -0
  40. package/package.json +2 -2
  41. package/lib/analytics/enrichEvent.d.ts +0 -3
  42. package/lib/analytics/enrichEvent.d.ts.map +0 -1
  43. package/lib/analytics/enrichEvent.js +0 -10
@@ -1,4 +1,15 @@
1
1
  import type { MetaRouterInterface } from './types';
2
2
  import 'react-native-get-random-values';
3
+ /**
4
+ * Top-level MetaRouter SDK interface.
5
+ *
6
+ * Provides access to analytics methods for initialization, client retrieval, and reset.
7
+ * Designed for use in React Native applications.
8
+ *
9
+ * Usage:
10
+ * import MetaRouter from '@metarouter/react-native-sdk';
11
+ * await MetaRouter.analytics.init({ ... });
12
+ * MetaRouter.analytics.track(...);
13
+ */
3
14
  export declare const MetaRouter: MetaRouterInterface;
4
15
  //# sourceMappingURL=MetaRouter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"MetaRouter.d.ts","sourceRoot":"","sources":["../src/MetaRouter.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,gCAAgC,CAAC;AAExC,eAAO,MAAM,UAAU,EAAE,mBAMxB,CAAC"}
1
+ {"version":3,"file":"MetaRouter.d.ts","sourceRoot":"","sources":["../src/MetaRouter.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,gCAAgC,CAAC;AAExC;;;;;;;;;;GAUG;AACH,eAAO,MAAM,UAAU,EAAE,mBAMxB,CAAC"}
package/lib/MetaRouter.js CHANGED
@@ -1,5 +1,16 @@
1
1
  import { initAnalytics, getAnalyticsClient, resetAnalytics } from './analytics/init';
2
2
  import 'react-native-get-random-values';
3
+ /**
4
+ * Top-level MetaRouter SDK interface.
5
+ *
6
+ * Provides access to analytics methods for initialization, client retrieval, and reset.
7
+ * Designed for use in React Native applications.
8
+ *
9
+ * Usage:
10
+ * import MetaRouter from '@metarouter/react-native-sdk';
11
+ * await MetaRouter.analytics.init({ ... });
12
+ * MetaRouter.analytics.track(...);
13
+ */
3
14
  export const MetaRouter = {
4
15
  analytics: {
5
16
  init: (opts) => initAnalytics(opts),
@@ -1,15 +1,55 @@
1
1
  import { EventPayload, EventWithIdentity } from "./types";
2
+ /**
3
+ * Manages user, group, and anonymous identity for analytics events.
4
+ * - Loads or generates a persistent anonymous ID.
5
+ * - Tracks current user and group IDs.
6
+ * - Can enrich events with identity information.
7
+ * - Supports reset for logout/testing scenarios.
8
+ */
2
9
  export declare class IdentityManager {
3
10
  private anonymousId;
4
11
  private userId?;
5
12
  private groupId?;
13
+ /**
14
+ * Initializes the manager by loading or generating an anonymous ID.
15
+ * Should be called before using other methods.
16
+ */
6
17
  init(): Promise<void>;
18
+ /**
19
+ * Retrieves the current anonymous ID.
20
+ * @returns The anonymous ID or null if not initialized.
21
+ */
7
22
  getAnonymousId(): string | null;
23
+ /**
24
+ * Sets the user ID for the current session.
25
+ * @param userId - The user ID to set.
26
+ */
8
27
  identify(userId: string): void;
28
+ /**
29
+ * Sets the group ID for the current session.
30
+ * @param groupId - The group ID to set.
31
+ */
9
32
  group(groupId: string): void;
33
+ /**
34
+ * Retrieves the current user ID.
35
+ * @returns The user ID or undefined if not set.
36
+ */
10
37
  getUserId(): string | undefined;
38
+ /**
39
+ * Retrieves the current group ID.
40
+ * @returns The group ID or undefined if not set.
41
+ */
11
42
  getGroupId(): string | undefined;
43
+ /**
44
+ * Adds identity information to an event payload.
45
+ * @param event - The event payload to enrich.
46
+ * @returns The enriched event payload with identity information.
47
+ */
12
48
  addIdentityInfo<T extends EventPayload>(event: T): EventWithIdentity;
49
+ /**
50
+ * Resets the identity manager to its initial state.
51
+ * Clears all user and group IDs, and sets the anonymous ID to null.
52
+ */
13
53
  reset(): void;
14
54
  }
15
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,qBAAa,eAAe;IACxB,OAAO,CAAC,WAAW,CAAuB;IAC1C,OAAO,CAAC,MAAM,CAAC,CAAS;IACxB,OAAO,CAAC,OAAO,CAAC,CAAS;IAGnB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAY3B,cAAc,IAAI,MAAM,GAAG,IAAI;IAI/B,QAAQ,CAAC,MAAM,EAAE,MAAM;IAKvB,KAAK,CAAC,OAAO,EAAE,MAAM;IAKrB,SAAS,IAAI,MAAM,GAAG,SAAS;IAI/B,UAAU,IAAI,MAAM,GAAG,SAAS;IAIhC,eAAe,CAAC,CAAC,SAAS,YAAY,EAAE,KAAK,EAAE,CAAC,GAAG,iBAAiB;IASpE,KAAK;CAMN"}
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,9 +1,20 @@
1
1
  import { getAnonymousId } from "./utils/anonymousId";
2
2
  import { log, warn } from "./utils/logger";
3
+ /**
4
+ * Manages user, group, and anonymous identity for analytics events.
5
+ * - Loads or generates a persistent anonymous ID.
6
+ * - Tracks current user and group IDs.
7
+ * - Can enrich events with identity information.
8
+ * - Supports reset for logout/testing scenarios.
9
+ */
3
10
  export class IdentityManager {
4
11
  constructor() {
5
12
  this.anonymousId = null;
6
13
  }
14
+ /**
15
+ * Initializes the manager by loading or generating an anonymous ID.
16
+ * Should be called before using other methods.
17
+ */
7
18
  async init() {
8
19
  try {
9
20
  this.anonymousId = await getAnonymousId(); // load or generate
@@ -16,23 +27,48 @@ export class IdentityManager {
16
27
  log('Using fallback anonymous ID:', this.anonymousId);
17
28
  }
18
29
  }
30
+ /**
31
+ * Retrieves the current anonymous ID.
32
+ * @returns The anonymous ID or null if not initialized.
33
+ */
19
34
  getAnonymousId() {
20
35
  return this.anonymousId;
21
36
  }
37
+ /**
38
+ * Sets the user ID for the current session.
39
+ * @param userId - The user ID to set.
40
+ */
22
41
  identify(userId) {
23
42
  this.userId = userId;
24
43
  log('User identified:', userId);
25
44
  }
45
+ /**
46
+ * Sets the group ID for the current session.
47
+ * @param groupId - The group ID to set.
48
+ */
26
49
  group(groupId) {
27
50
  this.groupId = groupId;
28
51
  log('User grouped:', groupId);
29
52
  }
53
+ /**
54
+ * Retrieves the current user ID.
55
+ * @returns The user ID or undefined if not set.
56
+ */
30
57
  getUserId() {
31
58
  return this.userId;
32
59
  }
60
+ /**
61
+ * Retrieves the current group ID.
62
+ * @returns The group ID or undefined if not set.
63
+ */
33
64
  getGroupId() {
34
65
  return this.groupId;
35
66
  }
67
+ /**
68
+ * Adds identity information to an event payload.
69
+ * @param event - The event payload to enrich.
70
+ * @returns The enriched event payload with identity information.
71
+ */
36
72
  addIdentityInfo(event) {
37
73
  var _a, _b, _c;
38
74
  return {
@@ -42,6 +78,10 @@ export class IdentityManager {
42
78
  groupId: (_c = event.groupId) !== null && _c !== void 0 ? _c : this.groupId,
43
79
  };
44
80
  }
81
+ /**
82
+ * Resets the identity manager to its initial state.
83
+ * Clears all user and group IDs, and sets the anonymous ID to null.
84
+ */
45
85
  reset() {
46
86
  this.anonymousId = null;
47
87
  this.userId = undefined;
@@ -1,4 +1,11 @@
1
1
  import { InitOptions } from "./types";
2
+ /**
3
+ * Analytics client for MetaRouter.
4
+ * - Handles event queueing, batching, and delivery with retries.
5
+ * - Manages user, group, and anonymous identity.
6
+ * - Supports periodic and on-demand flushing.
7
+ * - Provides debug and cleanup utilities.
8
+ */
2
9
  export declare class MetaRouterAnalyticsClient {
3
10
  private initialized;
4
11
  private initPromise;
@@ -11,22 +18,78 @@ export declare class MetaRouterAnalyticsClient {
11
18
  private appState;
12
19
  private appStateSubscription;
13
20
  private identityManager;
21
+ /**
22
+ * Initializes the analytics client with the provided options.
23
+ * @param options - The initialization options.
24
+ */
14
25
  constructor(options: InitOptions);
26
+ /**
27
+ * Initializes the analytics client.
28
+ * @returns A promise that resolves when the client is initialized.
29
+ */
15
30
  private init;
31
+ /**
32
+ * Waits for the analytics client to be initialized.
33
+ * @returns A promise that resolves when the client is initialized.
34
+ */
16
35
  waitForInitialization(): Promise<void>;
36
+ /**
37
+ * Starts the flush loop.
38
+ */
17
39
  private startFlushLoop;
40
+ /**
41
+ * Returns the current timestamp in ISO format.
42
+ * @returns The current timestamp in ISO format.
43
+ */
18
44
  private now;
45
+ /**
46
+ * Enqueues an event for processing.
47
+ * @param event - The event to enqueue.
48
+ */
19
49
  private enqueue;
50
+ /**
51
+ * Sets up the app state listener.
52
+ */
20
53
  private setupAppStateListener;
54
+ /**
55
+ * Handles the app state change event.
56
+ * @param nextState - The new app state.
57
+ */
21
58
  private handleAppStateChange;
59
+ /**
60
+ * Tracks an event.
61
+ * @param event - The event to track.
62
+ * @param properties - The properties to track.
63
+ */
22
64
  track(event: string, properties?: Record<string, any>): void;
65
+ /**
66
+ * Identifies a user.
67
+ * @param userId - The user ID to identify.
68
+ * @param traits - The traits to identify the user with.
69
+ */
23
70
  identify(userId: string, traits?: Record<string, any>): void;
71
+ /**
72
+ * Tracks a page view.
73
+ * @param name - The name of the page.
74
+ * @param properties - The properties to track.
75
+ */
24
76
  page(name: string, properties?: Record<string, any>): void;
77
+ /**
78
+ * Groups a user.
79
+ * @param groupId - The group ID to group.
80
+ * @param traits - The traits to group the user with.
81
+ */
25
82
  group(groupId: string, traits?: Record<string, any>): void;
83
+ /**
84
+ * Tracks a screen view.
85
+ * @param name - The name of the screen.
86
+ * @param properties - The properties to track.
87
+ */
26
88
  screen(name: string, properties?: Record<string, any>): void;
27
89
  /**
28
90
  * Alias an anonymous user to a known user ID.
29
91
  * This updates internal identity state and enqueues an alias event.
92
+ * @param newUserId - The new user ID to alias to.
30
93
  */
31
94
  alias(newUserId: string): void;
32
95
  /**
@@ -46,6 +109,9 @@ export declare class MetaRouterAnalyticsClient {
46
109
  userId: string | undefined;
47
110
  groupId: string | undefined;
48
111
  };
112
+ /**
113
+ * Flushes the event queue to the ingestion endpoint.
114
+ */
49
115
  flush(): Promise<{
50
116
  sentAt: string;
51
117
  type: import("./types").EventType;
@@ -56,7 +122,13 @@ export declare class MetaRouterAnalyticsClient {
56
122
  properties?: Record<string, any>;
57
123
  timestamp?: string;
58
124
  }[] | undefined>;
125
+ /**
126
+ * Resets the analytics client.
127
+ */
59
128
  reset(): void;
129
+ /**
130
+ * Cleans up the analytics client.
131
+ */
60
132
  cleanup(): void;
61
133
  }
62
134
  //# sourceMappingURL=MetaRouterAnalyticsClient.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"MetaRouterAnalyticsClient.d.ts","sourceRoot":"","sources":["../../src/analytics/MetaRouterAnalyticsClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiD,WAAW,EAAE,MAAM,SAAS,CAAC;AASnF,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,QAAQ,CAAS;IACzB,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;gBAE7B,OAAO,EAAE,WAAW;YAalB,IAAI;IA8BZ,qBAAqB,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5C,OAAO,CAAC,cAAc;IAItB,OAAO,CAAC,GAAG;IAIX,OAAO,CAAC,OAAO;IAOf,OAAO,CAAC,qBAAqB;IAI7B,OAAO,CAAC,oBAAoB,CAK1B;IAGF,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAMrD,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAOrD,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAMnD,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAOnD,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAMrD;;;MAGE;IAEF,KAAK,CAAC,SAAS,EAAE,MAAM;IAOvB;;OAEG;IACH,kBAAkB;IAKlB;;OAEG;IACH,YAAY;;;;;;;;;;IAaN,KAAK;;;;;;;;;;IA2DX,KAAK;IAML,OAAO;CAQR"}
1
+ {"version":3,"file":"MetaRouterAnalyticsClient.d.ts","sourceRoot":"","sources":["../../src/analytics/MetaRouterAnalyticsClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiD,WAAW,EAAE,MAAM,SAAS,CAAC;AAQrF;;;;;;GAMG;AACD,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,QAAQ,CAAS;IACzB,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;IAahC;;;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;IAOf;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAI7B;;;OAGG;IACH,OAAO,CAAC,oBAAoB,CAK1B;IAGF;;;;OAIG;IACH,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAMrD;;;;OAIG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAOrD;;;;OAIG;IACH,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAMnD;;;;OAIG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAOnD;;;;OAIG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAMrD;;;;MAIE;IACF,KAAK,CAAC,SAAS,EAAE,MAAM;IAOvB;;OAEG;IACH,kBAAkB;IAKlB;;OAEG;IACH,YAAY;;;;;;;;;;IAaZ;;OAEG;IACG,KAAK;;;;;;;;;;IAkDX;;OAEG;IACH,KAAK;IAML;;OAEG;IACH,OAAO;CAQR"}
@@ -2,9 +2,20 @@ import { AppState } from 'react-native';
2
2
  import { retryWithBackoff } from "./utils/retry";
3
3
  import { error, log, setDebugLogging, warn } from "./utils/logger";
4
4
  import { IdentityManager } from "./IdentityManager";
5
- import { enrichEvent } from "./enrichEvent";
5
+ import { enrichEvent } from "./utils/enrichEvent";
6
6
  import { getContextInfo } from "./utils/contextInfo";
7
+ /**
8
+ * Analytics client for MetaRouter.
9
+ * - Handles event queueing, batching, and delivery with retries.
10
+ * - Manages user, group, and anonymous identity.
11
+ * - Supports periodic and on-demand flushing.
12
+ * - Provides debug and cleanup utilities.
13
+ */
7
14
  export class MetaRouterAnalyticsClient {
15
+ /**
16
+ * Initializes the analytics client with the provided options.
17
+ * @param options - The initialization options.
18
+ */
8
19
  constructor(options) {
9
20
  var _a;
10
21
  this.initialized = false;
@@ -13,6 +24,10 @@ export class MetaRouterAnalyticsClient {
13
24
  this.flushTimer = null;
14
25
  this.appState = AppState.currentState;
15
26
  this.appStateSubscription = null;
27
+ /**
28
+ * Handles the app state change event.
29
+ * @param nextState - The new app state.
30
+ */
16
31
  this.handleAppStateChange = (nextState) => {
17
32
  if (this.appState === 'active' && nextState.match(/inactive|background/)) {
18
33
  this.flush();
@@ -29,6 +44,10 @@ export class MetaRouterAnalyticsClient {
29
44
  this.initPromise = this.init();
30
45
  log('Analytics client constructor completed, initialization in progress...');
31
46
  }
47
+ /**
48
+ * Initializes the analytics client.
49
+ * @returns A promise that resolves when the client is initialized.
50
+ */
32
51
  async init() {
33
52
  if (this.initialized) {
34
53
  log('Analytics client already initialized');
@@ -53,46 +72,89 @@ export class MetaRouterAnalyticsClient {
53
72
  throw error;
54
73
  }
55
74
  }
75
+ /**
76
+ * Waits for the analytics client to be initialized.
77
+ * @returns A promise that resolves when the client is initialized.
78
+ */
56
79
  async waitForInitialization() {
57
80
  await this.initPromise;
58
81
  }
82
+ /**
83
+ * Starts the flush loop.
84
+ */
59
85
  startFlushLoop() {
60
86
  this.flushTimer = setInterval(() => this.flush(), this.flushIntervalMs);
61
87
  }
88
+ /**
89
+ * Returns the current timestamp in ISO format.
90
+ * @returns The current timestamp in ISO format.
91
+ */
62
92
  now() {
63
93
  return new Date().toISOString();
64
94
  }
95
+ /**
96
+ * Enqueues an event for processing.
97
+ * @param event - The event to enqueue.
98
+ */
65
99
  enqueue(event) {
66
100
  const eventWithIdentity = this.identityManager.addIdentityInfo(event);
67
101
  const enrichedEvent = enrichEvent(eventWithIdentity, this.writeKey, this.context);
68
102
  log('Enqueuing event', enrichedEvent);
69
103
  this.queue.push(enrichedEvent);
70
104
  }
105
+ /**
106
+ * Sets up the app state listener.
107
+ */
71
108
  setupAppStateListener() {
72
109
  this.appStateSubscription = AppState.addEventListener('change', this.handleAppStateChange);
73
110
  }
111
+ /**
112
+ * Tracks an event.
113
+ * @param event - The event to track.
114
+ * @param properties - The properties to track.
115
+ */
74
116
  track(event, properties) {
75
117
  log('Tracking event:', event, 'with properties:', properties);
76
118
  this.enqueue({ type: 'track', event, properties, timestamp: this.now() });
77
119
  log('Event enqueued, queue length:', this.queue.length);
78
120
  }
121
+ /**
122
+ * Identifies a user.
123
+ * @param userId - The user ID to identify.
124
+ * @param traits - The traits to identify the user with.
125
+ */
79
126
  identify(userId, traits) {
80
127
  log('Identifying user:', userId, 'with traits:', traits);
81
128
  this.identityManager.identify(userId);
82
129
  this.enqueue({ type: 'identify', userId, traits, timestamp: this.now() });
83
130
  log('Identify event enqueued, queue length:', this.queue.length);
84
131
  }
132
+ /**
133
+ * Tracks a page view.
134
+ * @param name - The name of the page.
135
+ * @param properties - The properties to track.
136
+ */
85
137
  page(name, properties) {
86
138
  log('Tracking page:', name, 'with properties:', properties);
87
139
  this.enqueue({ type: 'page', event: name, properties, timestamp: this.now() });
88
140
  log('Page event enqueued, queue length:', this.queue.length);
89
141
  }
142
+ /**
143
+ * Groups a user.
144
+ * @param groupId - The group ID to group.
145
+ * @param traits - The traits to group the user with.
146
+ */
90
147
  group(groupId, traits) {
91
148
  log('Grouping user:', groupId, 'with traits:', traits);
92
149
  this.identityManager.group(groupId);
93
150
  this.enqueue({ type: 'group', groupId, traits, timestamp: this.now() });
94
151
  log('Group event enqueued, queue length:', this.queue.length);
95
152
  }
153
+ /**
154
+ * Tracks a screen view.
155
+ * @param name - The name of the screen.
156
+ * @param properties - The properties to track.
157
+ */
96
158
  screen(name, properties) {
97
159
  log('Tracking screen:', name, 'with properties:', properties);
98
160
  this.enqueue({ type: 'screen', event: name, properties, timestamp: this.now() });
@@ -101,6 +163,7 @@ export class MetaRouterAnalyticsClient {
101
163
  /**
102
164
  * Alias an anonymous user to a known user ID.
103
165
  * This updates internal identity state and enqueues an alias event.
166
+ * @param newUserId - The new user ID to alias to.
104
167
  */
105
168
  alias(newUserId) {
106
169
  log('Aliasing user to:', newUserId);
@@ -130,6 +193,9 @@ export class MetaRouterAnalyticsClient {
130
193
  groupId: this.identityManager.getGroupId(),
131
194
  };
132
195
  }
196
+ /**
197
+ * Flushes the event queue to the ingestion endpoint.
198
+ */
133
199
  async flush() {
134
200
  const anonId = this.identityManager.getAnonymousId();
135
201
  if (!anonId) {
@@ -169,23 +235,20 @@ export class MetaRouterAnalyticsClient {
169
235
  }
170
236
  catch (err) {
171
237
  warn('Flush failed, re-queueing events', err);
172
- // Re-queue the original events (not the enriched ones)
173
- this.queue.unshift(...this.queue.splice(0, 0, ...batch.map(event => ({
174
- type: event.type,
175
- event: event.event,
176
- properties: event.properties,
177
- userId: event.userId,
178
- traits: event.traits,
179
- groupId: event.groupId,
180
- timestamp: event.timestamp,
181
- }))));
238
+ this.queue.unshift(...batch);
182
239
  }
183
240
  }
241
+ /**
242
+ * Resets the analytics client.
243
+ */
184
244
  reset() {
185
245
  this.identityManager.reset();
186
246
  this.queue = [];
187
247
  log('Analytics client reset');
188
248
  }
249
+ /**
250
+ * Cleans up the analytics client.
251
+ */
189
252
  cleanup() {
190
253
  var _a, _b;
191
254
  log('Cleaning up analytics client');
@@ -1,5 +1,22 @@
1
1
  import type { InitOptions, AnalyticsInterface } from './types';
2
+ /**
3
+ * Initializes the analytics client singleton.
4
+ * Waits for async setup (e.g., identity loading) before returning the interface.
5
+ * Returns the same instance on subsequent calls.
6
+ * @param options Analytics initialization options.
7
+ * @returns The analytics interface.
8
+ */
2
9
  export declare function initAnalytics(options: InitOptions): Promise<AnalyticsInterface>;
10
+ /**
11
+ * Retrieves the analytics client singleton.
12
+ * Returns the proxy client before initialization, and the real client after.
13
+ * @returns The analytics interface.
14
+ */
3
15
  export declare function getAnalyticsClient(): AnalyticsInterface;
16
+ /**
17
+ * Resets the analytics client singleton.
18
+ * Cleans up the client and sets it to null.
19
+ * @returns A promise that resolves when the client is reset.
20
+ */
4
21
  export declare function resetAnalytics(): Promise<void>;
5
22
  //# sourceMappingURL=init.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/analytics/init.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAM/D,wBAAsB,aAAa,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAuBrF;AAED,wBAAgB,kBAAkB,IAAI,kBAAkB,CAEvD;AAED,wBAAsB,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC,CAMpD"}
1
+ {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/analytics/init.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAM/D;;;;;;GAMG;AACH,wBAAsB,aAAa,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAuBrF;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,IAAI,kBAAkB,CAEvD;AAED;;;;GAIG;AACH,wBAAsB,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC,CAMpD"}
@@ -3,6 +3,13 @@ import { proxyClient, setRealClient } from './proxy/proxyClient';
3
3
  let initialized = false;
4
4
  let client = null;
5
5
  let analyticsInterface = null;
6
+ /**
7
+ * Initializes the analytics client singleton.
8
+ * Waits for async setup (e.g., identity loading) before returning the interface.
9
+ * Returns the same instance on subsequent calls.
10
+ * @param options Analytics initialization options.
11
+ * @returns The analytics interface.
12
+ */
6
13
  export async function initAnalytics(options) {
7
14
  if (initialized)
8
15
  return analyticsInterface;
@@ -24,9 +31,19 @@ export async function initAnalytics(options) {
24
31
  setRealClient(analyticsInterface);
25
32
  return analyticsInterface;
26
33
  }
34
+ /**
35
+ * Retrieves the analytics client singleton.
36
+ * Returns the proxy client before initialization, and the real client after.
37
+ * @returns The analytics interface.
38
+ */
27
39
  export function getAnalyticsClient() {
28
40
  return initialized ? analyticsInterface : proxyClient;
29
41
  }
42
+ /**
43
+ * Resets the analytics client singleton.
44
+ * Cleans up the client and sets it to null.
45
+ * @returns A promise that resolves when the client is reset.
46
+ */
30
47
  export async function resetAnalytics() {
31
48
  await (client === null || client === void 0 ? void 0 : client.cleanup());
32
49
  client = null;
@@ -1,4 +1,17 @@
1
1
  import type { AnalyticsInterface } from '../types';
2
+ /**
3
+ * proxyClient implements a proxy pattern for the AnalyticsInterface.
4
+ *
5
+ * It allows analytics method calls (track, identify, etc.) to be made before the real analytics client
6
+ * is fully initialized. Calls are queued and replayed once the real client is set via setRealClient.
7
+ * This ensures that analytics events are not lost if called early in the app lifecycle.
8
+ *
9
+ * The proxy also provides a fallback for getDebugInfo, returning proxy state if the real client is not ready.
10
+ *
11
+ * Usage:
12
+ * - Use proxyClient as the default analytics client before initialization.
13
+ * - Call setRealClient(realClientInstance) once the real client is ready.
14
+ */
2
15
  export declare const proxyClient: AnalyticsInterface;
3
16
  export declare function setRealClient(client: AnalyticsInterface | null): void;
4
17
  //# sourceMappingURL=proxyClient.d.ts.map
@@ -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,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;AAwBnD;;;;;;;;;;;;GAYG;AAEH,eAAO,MAAM,WAAW,EAAE,kBAWzB,CAAC;AAEF,wBAAgB,aAAa,CAAC,MAAM,EAAE,kBAAkB,GAAG,IAAI,QAO9D"}
@@ -13,6 +13,19 @@ function handleMethodCall(methodName, ...args) {
13
13
  }
14
14
  });
15
15
  }
16
+ /**
17
+ * proxyClient implements a proxy pattern for the AnalyticsInterface.
18
+ *
19
+ * It allows analytics method calls (track, identify, etc.) to be made before the real analytics client
20
+ * is fully initialized. Calls are queued and replayed once the real client is set via setRealClient.
21
+ * This ensures that analytics events are not lost if called early in the app lifecycle.
22
+ *
23
+ * The proxy also provides a fallback for getDebugInfo, returning proxy state if the real client is not ready.
24
+ *
25
+ * Usage:
26
+ * - Use proxyClient as the default analytics client before initialization.
27
+ * - Call setRealClient(realClientInstance) once the real client is ready.
28
+ */
16
29
  export const proxyClient = {
17
30
  track: (event, props) => handleMethodCall('track', event, props),
18
31
  identify: (userId, traits) => handleMethodCall('identify', userId, traits),
@@ -1,2 +1,8 @@
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
+ */
1
7
  export declare function getAnonymousId(): Promise<string>;
2
8
  //# sourceMappingURL=anonymousId.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"anonymousId.d.ts","sourceRoot":"","sources":["../../../src/analytics/utils/anonymousId.ts"],"names":[],"mappings":"AAMA,wBAAsB,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC,CAsBtD"}
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"}
@@ -2,6 +2,12 @@ import AsyncStorage from '@react-native-async-storage/async-storage';
2
2
  import { v4 as uuidv4 } from 'uuid';
3
3
  import { log, warn } from './logger';
4
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
+ */
5
11
  export async function getAnonymousId() {
6
12
  try {
7
13
  const existing = await AsyncStorage.getItem(STORAGE_KEY);
@@ -1,2 +1,13 @@
1
- export declare function getContextInfo(): Promise<any>;
1
+ import { EventContext } from '../types';
2
+ /**
3
+ * Gathers and caches device, app, and environment context information for analytics events.
4
+ *
5
+ * - Collects details such as app name/version, device model/type, OS, screen size, locale, timezone, and network status.
6
+ * - Uses `react-native-device-info` and the current environment to populate fields.
7
+ * - Caches the result for the lifetime of the app to avoid redundant async calls.
8
+ * - Returns a context object suitable for event enrichment.
9
+ *
10
+ * @returns {Promise<EventContext>} A promise that resolves to the context information object.
11
+ */
12
+ export declare function getContextInfo(): Promise<EventContext>;
2
13
  //# sourceMappingURL=contextInfo.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"contextInfo.d.ts","sourceRoot":"","sources":["../../../src/analytics/utils/contextInfo.ts"],"names":[],"mappings":"AAYA,wBAAsB,cAAc,IAAI,OAAO,CAAC,GAAG,CAAC,CA2CnD"}
1
+ {"version":3,"file":"contextInfo.d.ts","sourceRoot":"","sources":["../../../src/analytics/utils/contextInfo.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAWxC;;;;;;;;;GASG;AACH,wBAAsB,cAAc,IAAI,OAAO,CAAC,YAAY,CAAC,CA2C5D"}
@@ -8,6 +8,16 @@ try {
8
8
  catch {
9
9
  DeviceInfo = null;
10
10
  }
11
+ /**
12
+ * Gathers and caches device, app, and environment context information for analytics events.
13
+ *
14
+ * - Collects details such as app name/version, device model/type, OS, screen size, locale, timezone, and network status.
15
+ * - Uses `react-native-device-info` and the current environment to populate fields.
16
+ * - Caches the result for the lifetime of the app to avoid redundant async calls.
17
+ * - Returns a context object suitable for event enrichment.
18
+ *
19
+ * @returns {Promise<EventContext>} A promise that resolves to the context information object.
20
+ */
11
21
  export async function getContextInfo() {
12
22
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5;
13
23
  if (cachedContext)
@@ -0,0 +1,15 @@
1
+ import { EnrichedEventPayload, EventContext, EventWithIdentity } from "../types";
2
+ /**
3
+ * Enriches an analytics event with additional metadata required for ingestion.
4
+ *
5
+ * - Adds a unique messageId and the current sentAt timestamp.
6
+ * - Injects the provided writeKey and context information into the event.
7
+ * - Returns a new EnrichedEventPayload object, suitable for sending to the ingestion endpoint.
8
+ *
9
+ * @param event The base event with identity information.
10
+ * @param writeKey The write key for the analytics project.
11
+ * @param context The context information (device, app, environment, etc.).
12
+ * @returns The enriched event payload.
13
+ */
14
+ export declare function enrichEvent(event: EventWithIdentity, writeKey: string, context: EventContext): EnrichedEventPayload;
15
+ //# sourceMappingURL=enrichEvent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enrichEvent.d.ts","sourceRoot":"","sources":["../../../src/analytics/utils/enrichEvent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAI,oBAAoB,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAEnF;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,iBAAiB,EACxB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,YAAY,GACpB,oBAAoB,CAUtB"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Enriches an analytics event with additional metadata required for ingestion.
3
+ *
4
+ * - Adds a unique messageId and the current sentAt timestamp.
5
+ * - Injects the provided writeKey and context information into the event.
6
+ * - Returns a new EnrichedEventPayload object, suitable for sending to the ingestion endpoint.
7
+ *
8
+ * @param event The base event with identity information.
9
+ * @param writeKey The write key for the analytics project.
10
+ * @param context The context information (device, app, environment, etc.).
11
+ * @returns The enriched event payload.
12
+ */
13
+ export function enrichEvent(event, writeKey, context) {
14
+ const enriched = {
15
+ ...event,
16
+ writeKey,
17
+ messageId: `${Date.now()}-${Math.random().toString(36).slice(2, 10)}`,
18
+ sentAt: new Date().toISOString(),
19
+ context,
20
+ };
21
+ return enriched;
22
+ }
@@ -1,5 +1,28 @@
1
+ /**
2
+ * Simple logger utility for MetaRouter SDK.
3
+ *
4
+ * - Allows toggling debug logging for development and troubleshooting.
5
+ * - Always logs warnings and errors, regardless of debug setting.
6
+ * - Prepends all logs with a [MetaRouter] tag for easy identification.
7
+ */
8
+ /**
9
+ * Enables or disables debug logging.
10
+ * @param value If true, enables debug logging; if false, disables it.
11
+ */
1
12
  export declare function setDebugLogging(value: boolean): void;
13
+ /**
14
+ * Logs a message to the console if debug logging is enabled.
15
+ * @param args Arguments to log.
16
+ */
2
17
  export declare function log(...args: any[]): void;
18
+ /**
19
+ * Logs a warning to the console (always, regardless of debug setting).
20
+ * @param args Arguments to log as a warning.
21
+ */
3
22
  export declare function warn(...args: any[]): void;
23
+ /**
24
+ * Logs an error to the console (always, regardless of debug setting).
25
+ * @param args Arguments to log as an error.
26
+ */
4
27
  export declare function error(...args: any[]): void;
5
28
  //# sourceMappingURL=logger.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../../src/analytics/utils/logger.ts"],"names":[],"mappings":"AAEA,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,QAE7C;AAED,wBAAgB,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,QAEjC;AAED,wBAAgB,IAAI,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,QAGlC;AAED,wBAAgB,KAAK,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,QAGnC"}
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../../src/analytics/utils/logger.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH;;;GAGG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,QAE7C;AAED;;;GAGG;AACH,wBAAgB,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,QAEjC;AAED;;;GAGG;AACH,wBAAgB,IAAI,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,QAElC;AAED;;;GAGG;AACH,wBAAgB,KAAK,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,QAEnC"}
@@ -1,16 +1,37 @@
1
+ /**
2
+ * Simple logger utility for MetaRouter SDK.
3
+ *
4
+ * - Allows toggling debug logging for development and troubleshooting.
5
+ * - Always logs warnings and errors, regardless of debug setting.
6
+ * - Prepends all logs with a [MetaRouter] tag for easy identification.
7
+ */
1
8
  let enabled = false;
9
+ /**
10
+ * Enables or disables debug logging.
11
+ * @param value If true, enables debug logging; if false, disables it.
12
+ */
2
13
  export function setDebugLogging(value) {
3
14
  enabled = value;
4
15
  }
16
+ /**
17
+ * Logs a message to the console if debug logging is enabled.
18
+ * @param args Arguments to log.
19
+ */
5
20
  export function log(...args) {
6
21
  if (enabled)
7
22
  console.log('[MetaRouter]', ...args);
8
23
  }
24
+ /**
25
+ * Logs a warning to the console (always, regardless of debug setting).
26
+ * @param args Arguments to log as a warning.
27
+ */
9
28
  export function warn(...args) {
10
- // Always log warnings, even when debug is disabled
11
29
  console.warn('[MetaRouter]', ...args);
12
30
  }
31
+ /**
32
+ * Logs an error to the console (always, regardless of debug setting).
33
+ * @param args Arguments to log as an error.
34
+ */
13
35
  export function error(...args) {
14
- // Always log errors, even when debug is disabled
15
36
  console.error('[MetaRouter]', ...args);
16
37
  }
@@ -1,2 +1,16 @@
1
+ /**
2
+ * Retries an asynchronous operation with exponential backoff and optional jitter.
3
+ *
4
+ * - Attempts to execute the provided async function up to `retries` times.
5
+ * - Waits an exponentially increasing delay (with random jitter) between attempts.
6
+ * - If all attempts fail, the last error is thrown.
7
+ *
8
+ * @template T The return type of the async function.
9
+ * @param fn The asynchronous function to retry.
10
+ * @param retries The maximum number of attempts (default: 5).
11
+ * @param baseDelayMs The base delay in milliseconds for backoff (default: 1000).
12
+ * @param sleep Optional custom sleep function (default: setTimeout-based Promise).
13
+ * @returns A promise that resolves with the result of `fn`, or rejects after all retries fail.
14
+ */
1
15
  export declare function retryWithBackoff<T>(fn: () => Promise<T>, retries?: number, baseDelayMs?: number, sleep?: (ms: number) => Promise<unknown>): Promise<T>;
2
16
  //# sourceMappingURL=retry.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../../../src/analytics/utils/retry.ts"],"names":[],"mappings":"AAAA,wBAAsB,gBAAgB,CAAC,CAAC,EACpC,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACpB,OAAO,SAAI,EACX,WAAW,SAAO,EAClB,KAAK,IAAI,IAAI,MAAM,qBAA8C,GAChE,OAAO,CAAC,CAAC,CAAC,CAiBZ"}
1
+ {"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../../../src/analytics/utils/retry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,wBAAsB,gBAAgB,CAAC,CAAC,EACpC,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACpB,OAAO,SAAI,EACX,WAAW,SAAO,EAClB,KAAK,IAAI,IAAI,MAAM,qBAA8C,GAChE,OAAO,CAAC,CAAC,CAAC,CAiBZ"}
@@ -1,3 +1,17 @@
1
+ /**
2
+ * Retries an asynchronous operation with exponential backoff and optional jitter.
3
+ *
4
+ * - Attempts to execute the provided async function up to `retries` times.
5
+ * - Waits an exponentially increasing delay (with random jitter) between attempts.
6
+ * - If all attempts fail, the last error is thrown.
7
+ *
8
+ * @template T The return type of the async function.
9
+ * @param fn The asynchronous function to retry.
10
+ * @param retries The maximum number of attempts (default: 5).
11
+ * @param baseDelayMs The base delay in milliseconds for backoff (default: 1000).
12
+ * @param sleep Optional custom sleep function (default: setTimeout-based Promise).
13
+ * @returns A promise that resolves with the result of `fn`, or rejects after all retries fail.
14
+ */
1
15
  export async function retryWithBackoff(fn, retries = 5, baseDelayMs = 1000, sleep = (ms) => new Promise((res) => setTimeout(res, ms))) {
2
16
  let attempt = 0;
3
17
  while (attempt < retries) {
@@ -1,2 +1,7 @@
1
+ /**
2
+ * Returns the current IANA time zone string for the environment.
3
+ * Falls back to 'UTC' if unavailable.
4
+ * @returns {string} The IANA time zone (e.g., 'America/New_York') or 'UTC'.
5
+ */
1
6
  export declare function getTimeZone(): string;
2
7
  //# sourceMappingURL=timezone.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"timezone.d.ts","sourceRoot":"","sources":["../../../src/analytics/utils/timezone.ts"],"names":[],"mappings":"AAAA,wBAAgB,WAAW,IAAI,MAAM,CAMlC"}
1
+ {"version":3,"file":"timezone.d.ts","sourceRoot":"","sources":["../../../src/analytics/utils/timezone.ts"],"names":[],"mappings":"AAAG;;;;GAIG;AACN,wBAAgB,WAAW,IAAI,MAAM,CAMlC"}
@@ -1,3 +1,8 @@
1
+ /**
2
+ * Returns the current IANA time zone string for the environment.
3
+ * Falls back to 'UTC' if unavailable.
4
+ * @returns {string} The IANA time zone (e.g., 'America/New_York') or 'UTC'.
5
+ */
1
6
  export function getTimeZone() {
2
7
  try {
3
8
  return Intl.DateTimeFormat().resolvedOptions().timeZone;
@@ -1,6 +1,15 @@
1
1
  import React, { ReactNode } from "react";
2
2
  import type { MetaRouterInterface } from "../types";
3
+ /**
4
+ * Context for the MetaRouter analytics client.
5
+ * @param instance - The analytics client instance.
6
+ */
3
7
  export declare const MetaRouterContext: React.Context<MetaRouterInterface | null>;
8
+ /**
9
+ * Provider for the MetaRouter analytics client.
10
+ * @param children - The children to render.
11
+ * @param instance - The analytics client instance.
12
+ */
4
13
  export declare const MetaRouterProvider: ({ children, instance, }: {
5
14
  children: ReactNode;
6
15
  instance: MetaRouterInterface;
@@ -1 +1 @@
1
- {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/react/context.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAA6B,SAAS,EAAE,MAAM,OAAO,CAAC;AACpE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAEpD,eAAO,MAAM,iBAAiB,2CAE7B,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAAI,yBAGhC;IACD,QAAQ,EAAE,SAAS,CAAC;IACpB,QAAQ,EAAE,mBAAmB,CAAC;CAC/B,sBAMA,CAAC"}
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/react/context.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAA6B,SAAS,EAAE,MAAM,OAAO,CAAC;AACpE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAEpD;;;GAGG;AACH,eAAO,MAAM,iBAAiB,2CAE7B,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,GAAI,yBAGhC;IACD,QAAQ,EAAE,SAAS,CAAC;IACpB,QAAQ,EAAE,mBAAmB,CAAC;CAC/B,sBAMA,CAAC"}
@@ -1,5 +1,14 @@
1
1
  import React, { createContext } from "react";
2
+ /**
3
+ * Context for the MetaRouter analytics client.
4
+ * @param instance - The analytics client instance.
5
+ */
2
6
  export const MetaRouterContext = createContext(null);
7
+ /**
8
+ * Provider for the MetaRouter analytics client.
9
+ * @param children - The children to render.
10
+ * @param instance - The analytics client instance.
11
+ */
3
12
  export const MetaRouterProvider = ({ children, instance, }) => {
4
13
  return (React.createElement(MetaRouterContext.Provider, { value: instance }, children));
5
14
  };
@@ -1,4 +1,8 @@
1
1
  import type { AnalyticsInterface } from "../analytics/types";
2
+ /**
3
+ * Custom hook to access the MetaRouter analytics client.
4
+ * @returns The analytics client instance.
5
+ */
2
6
  export declare const useMetaRouter: () => {
3
7
  analytics: AnalyticsInterface;
4
8
  };
@@ -1 +1 @@
1
- {"version":3,"file":"useMetaRouter.d.ts","sourceRoot":"","sources":["../../src/react/useMetaRouter.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAE7D,eAAO,MAAM,aAAa,QAAO;IAAE,SAAS,EAAE,kBAAkB,CAAA;CAQ7D,CAAC"}
1
+ {"version":3,"file":"useMetaRouter.d.ts","sourceRoot":"","sources":["../../src/react/useMetaRouter.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAE7D;;;GAGG;AACH,eAAO,MAAM,aAAa,QAAO;IAAE,SAAS,EAAE,kBAAkB,CAAA;CAQ7D,CAAC"}
@@ -1,5 +1,9 @@
1
1
  import { useContext } from "react";
2
2
  import { MetaRouterContext } from "./context";
3
+ /**
4
+ * Custom hook to access the MetaRouter analytics client.
5
+ * @returns The analytics client instance.
6
+ */
3
7
  export const useMetaRouter = () => {
4
8
  const ctx = useContext(MetaRouterContext);
5
9
  if (!ctx)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metarouter/react-native-sdk",
3
- "version": "0.1.23",
3
+ "version": "0.1.24",
4
4
  "main": "./lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "exports": {
@@ -18,7 +18,7 @@
18
18
  "clean": "rm -rf lib",
19
19
  "build": "tsc --project tsconfig.build.json",
20
20
  "prepare": "npm run build",
21
- "prePublishOnly": "npm run clean && npm run build",
21
+ "prepublishOnly": "npm run clean && npm run build",
22
22
  "test": "jest"
23
23
  },
24
24
  "publishConfig": {
@@ -1,3 +0,0 @@
1
- import { EnrichedEventPayload, EventContext, EventWithIdentity } from "./types";
2
- export declare function enrichEvent(event: EventWithIdentity, writeKey: string, context: EventContext): EnrichedEventPayload;
3
- //# sourceMappingURL=enrichEvent.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"enrichEvent.d.ts","sourceRoot":"","sources":["../../src/analytics/enrichEvent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAI,oBAAoB,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAGlF,wBAAgB,WAAW,CACzB,KAAK,EAAE,iBAAiB,EACxB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,YAAY,GACpB,oBAAoB,CAUtB"}
@@ -1,10 +0,0 @@
1
- export function enrichEvent(event, writeKey, context) {
2
- const enriched = {
3
- ...event,
4
- writeKey,
5
- messageId: `${Date.now()}-${Math.random().toString(36).slice(2, 10)}`,
6
- sentAt: new Date().toISOString(),
7
- context,
8
- };
9
- return enriched;
10
- }