@metarouter/react-native-sdk 1.1.4 → 1.1.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.
@@ -1,3 +1,3 @@
1
1
  import type { InitOptions, AnalyticsInterface } from "./types";
2
- export declare function createAnalyticsClient(options: InitOptions): Promise<AnalyticsInterface>;
2
+ export declare function createAnalyticsClient(options: InitOptions): AnalyticsInterface;
3
3
  //# 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;AAK/D,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,WAAW,GACnB,OAAO,CAAC,kBAAkB,CAAC,CAwC7B"}
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;AAK/D,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,WAAW,GACnB,kBAAkB,CAyBpB"}
@@ -1,41 +1,30 @@
1
1
  import { MetaRouterAnalyticsClient } from "./MetaRouterAnalyticsClient";
2
2
  import { proxyClient, setRealClient } from "./proxy/proxyClient";
3
- // Single-flight guard so concurrent callers don't double-init
4
- let inFlight = null;
5
- export async function createAnalyticsClient(options) {
6
- if (inFlight)
7
- return inFlight;
8
- inFlight = (async () => {
9
- // 1) Build the real client and fully initialize it
10
- const instance = new MetaRouterAnalyticsClient(options);
11
- await instance.init();
12
- // 2) Wrap the real instance with the public interface
13
- // Note: reset() also detaches the proxy so you’re "off" until you call createAnalyticsClient() again.
14
- const boundClient = {
15
- track: (event, props) => instance.track(event, props),
16
- identify: (userId, traits) => instance.identify(userId, traits),
17
- group: (groupId, traits) => instance.group(groupId, traits),
18
- screen: (name, props) => instance.screen(name, props),
19
- page: (name, props) => instance.page(name, props),
20
- alias: (newUserId) => instance.alias(newUserId),
21
- enableDebugLogging: () => instance.enableDebugLogging(),
22
- getDebugInfo: () => instance.getDebugInfo(),
23
- flush: () => instance.flush(),
24
- // Detach the proxy after a successful reset so nothing leaks out
25
- reset: async () => {
26
- await instance.reset();
27
- setRealClient(null, { dropPending: true }); // proxy goes idle; calls will queue or no-op
28
- },
29
- };
30
- // 3) Bind the proxy to this fully-initialized client
31
- setRealClient(boundClient);
32
- // 4) Return the proxy as the single public handle
33
- return proxyClient;
34
- })();
35
- try {
36
- return await inFlight;
37
- }
38
- finally {
39
- inFlight = null;
3
+ // Only one initialization in flight
4
+ let initPromise = null;
5
+ export function createAnalyticsClient(options) {
6
+ if (!initPromise) {
7
+ initPromise = (async () => {
8
+ const instance = new MetaRouterAnalyticsClient(options);
9
+ await instance.init();
10
+ const boundClient = {
11
+ track: (event, props) => instance.track(event, props),
12
+ identify: (userId, traits) => instance.identify(userId, traits),
13
+ group: (groupId, traits) => instance.group(groupId, traits),
14
+ screen: (name, props) => instance.screen(name, props),
15
+ page: (name, props) => instance.page(name, props),
16
+ alias: (newUserId) => instance.alias(newUserId),
17
+ enableDebugLogging: () => instance.enableDebugLogging(),
18
+ getDebugInfo: () => instance.getDebugInfo(),
19
+ flush: () => instance.flush(),
20
+ reset: async () => {
21
+ await instance.reset();
22
+ setRealClient(null, { dropPending: true });
23
+ initPromise = null;
24
+ },
25
+ };
26
+ setRealClient(boundClient);
27
+ })();
40
28
  }
29
+ return proxyClient;
41
30
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metarouter/react-native-sdk",
3
- "version": "1.1.4",
3
+ "version": "1.1.6",
4
4
  "main": "./lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "exports": {