@metarouter/react-native-sdk 0.1.22 → 0.1.23

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.
@@ -7,6 +7,7 @@ export declare class MetaRouterAnalyticsClient {
7
7
  private flushTimer;
8
8
  private endpoint;
9
9
  private writeKey;
10
+ private context;
10
11
  private appState;
11
12
  private appStateSubscription;
12
13
  private identityManager;
@@ -1 +1 @@
1
- {"version":3,"file":"MetaRouterAnalyticsClient.d.ts","sourceRoot":"","sources":["../../src/analytics/MetaRouterAnalyticsClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmC,WAAW,EAAE,MAAM,SAAS,CAAC;AAQrE,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,QAAQ,CAAyC;IACzD,OAAO,CAAC,oBAAoB,CAAwC;IACpE,OAAO,CAAC,eAAe,CAAkB;gBAE7B,OAAO,EAAE,WAAW;YAalB,IAAI;IA4BZ,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,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,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"}
@@ -3,6 +3,7 @@ import { retryWithBackoff } from "./utils/retry";
3
3
  import { error, log, setDebugLogging, warn } from "./utils/logger";
4
4
  import { IdentityManager } from "./IdentityManager";
5
5
  import { enrichEvent } from "./enrichEvent";
6
+ import { getContextInfo } from "./utils/contextInfo";
6
7
  export class MetaRouterAnalyticsClient {
7
8
  constructor(options) {
8
9
  var _a;
@@ -41,6 +42,7 @@ export class MetaRouterAnalyticsClient {
41
42
  log('Flush loop started with interval:', this.flushIntervalMs, 'ms');
42
43
  this.setupAppStateListener();
43
44
  log('App state listener setup completed');
45
+ this.context = await getContextInfo();
44
46
  this.initialized = true;
45
47
  log('Analytics client initialization completed successfully');
46
48
  }
@@ -62,7 +64,7 @@ export class MetaRouterAnalyticsClient {
62
64
  }
63
65
  enqueue(event) {
64
66
  const eventWithIdentity = this.identityManager.addIdentityInfo(event);
65
- const enrichedEvent = enrichEvent(eventWithIdentity, this.writeKey);
67
+ const enrichedEvent = enrichEvent(eventWithIdentity, this.writeKey, this.context);
66
68
  log('Enqueuing event', enrichedEvent);
67
69
  this.queue.push(enrichedEvent);
68
70
  }
@@ -1,3 +1,3 @@
1
- import { EnrichedEventPayload, EventWithIdentity } from "./types";
2
- export declare function enrichEvent(event: EventWithIdentity, writeKey: string): EnrichedEventPayload;
1
+ import { EnrichedEventPayload, EventContext, EventWithIdentity } from "./types";
2
+ export declare function enrichEvent(event: EventWithIdentity, writeKey: string, context: EventContext): EnrichedEventPayload;
3
3
  //# sourceMappingURL=enrichEvent.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"enrichEvent.d.ts","sourceRoot":"","sources":["../../src/analytics/enrichEvent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAI,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAIpE,wBAAgB,WAAW,CACzB,KAAK,EAAE,iBAAiB,EACxB,QAAQ,EAAE,MAAM,GACf,oBAAoB,CAUtB"}
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,11 +1,10 @@
1
- import { getContextInfo } from "./utils/contextInfo";
2
- export function enrichEvent(event, writeKey) {
1
+ export function enrichEvent(event, writeKey, context) {
3
2
  const enriched = {
4
3
  ...event,
5
4
  writeKey,
6
5
  messageId: `${Date.now()}-${Math.random().toString(36).slice(2, 10)}`,
7
6
  sentAt: new Date().toISOString(),
8
- context: getContextInfo(),
7
+ context,
9
8
  };
10
9
  return enriched;
11
10
  }
@@ -1,33 +1,2 @@
1
- export declare function getContextInfo(): {
2
- app: {
3
- name: any;
4
- version: any;
5
- build: any;
6
- namespace: any;
7
- };
8
- device: {
9
- manufacturer: any;
10
- model: any;
11
- name: any;
12
- type: string;
13
- };
14
- library: {
15
- name: string;
16
- version: string;
17
- };
18
- os: {
19
- name: any;
20
- version: any;
21
- };
22
- screen: {
23
- density: any;
24
- width: any;
25
- height: any;
26
- };
27
- network: {
28
- wifi: any;
29
- };
30
- locale: string;
31
- timezone: string;
32
- };
1
+ export declare function getContextInfo(): Promise<any>;
33
2
  //# sourceMappingURL=contextInfo.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"contextInfo.d.ts","sourceRoot":"","sources":["../../../src/analytics/utils/contextInfo.ts"],"names":[],"mappings":"AAUA,wBAAgB,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAwC7B"}
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,5 +1,6 @@
1
1
  import { getTimeZone } from './timezone';
2
2
  import pkg from '../../../package.json';
3
+ let cachedContext = null;
3
4
  let DeviceInfo = null;
4
5
  try {
5
6
  DeviceInfo = require('react-native-device-info');
@@ -7,43 +8,46 @@ try {
7
8
  catch {
8
9
  DeviceInfo = null;
9
10
  }
10
- export function getContextInfo() {
11
- 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, _6;
11
+ export async function getContextInfo() {
12
+ 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
+ if (cachedContext)
14
+ return cachedContext;
12
15
  let locale = 'en-US';
13
16
  if (typeof Intl !== 'undefined' && typeof Intl.DateTimeFormat === 'function') {
14
17
  const resolved = Intl.DateTimeFormat().resolvedOptions();
15
18
  locale = (_a = resolved.locale) !== null && _a !== void 0 ? _a : locale;
16
19
  }
17
- return {
18
- app: {
19
- name: (_c = (_b = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getApplicationName) === null || _b === void 0 ? void 0 : _b.call(DeviceInfo)) !== null && _c !== void 0 ? _c : 'metarouter-react-native',
20
- version: (_f = (_e = (_d = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getVersion) === null || _d === void 0 ? void 0 : _d.call(DeviceInfo)) !== null && _e !== void 0 ? _e : pkg.version) !== null && _f !== void 0 ? _f : 'unknown',
21
- build: (_h = (_g = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getBuildNumber) === null || _g === void 0 ? void 0 : _g.call(DeviceInfo)) !== null && _h !== void 0 ? _h : 'unknown',
22
- namespace: (_k = (_j = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getBundleId) === null || _j === void 0 ? void 0 : _j.call(DeviceInfo)) !== null && _k !== void 0 ? _k : 'unknown',
23
- },
24
- device: {
25
- manufacturer: (_m = (_l = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getManufacturer) === null || _l === void 0 ? void 0 : _l.call(DeviceInfo)) !== null && _m !== void 0 ? _m : 'unknown',
26
- model: (_p = (_o = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getModel) === null || _o === void 0 ? void 0 : _o.call(DeviceInfo)) !== null && _p !== void 0 ? _p : 'unknown',
27
- name: (_r = (_q = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getDeviceName) === null || _q === void 0 ? void 0 : _q.call(DeviceInfo)) !== null && _r !== void 0 ? _r : 'unknown',
28
- type: ((_t = (_s = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getSystemName) === null || _s === void 0 ? void 0 : _s.call(DeviceInfo)) === null || _t === void 0 ? void 0 : _t.toLowerCase()) === 'android' ? 'android' : 'ios',
29
- },
20
+ cachedContext = {
30
21
  library: {
31
22
  name: 'metarouter-react-native-sdk',
32
- version: (_u = pkg.version) !== null && _u !== void 0 ? _u : '0.0.0',
23
+ version: (_b = pkg.version) !== null && _b !== void 0 ? _b : '0.0.0',
24
+ },
25
+ locale,
26
+ timezone: getTimeZone(),
27
+ device: {
28
+ manufacturer: (_d = await ((_c = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getManufacturer) === null || _c === void 0 ? void 0 : _c.call(DeviceInfo))) !== null && _d !== void 0 ? _d : 'unknown',
29
+ model: (_f = (_e = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getModel) === null || _e === void 0 ? void 0 : _e.call(DeviceInfo)) !== null && _f !== void 0 ? _f : 'unknown',
30
+ name: (_h = await ((_g = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getDeviceName) === null || _g === void 0 ? void 0 : _g.call(DeviceInfo))) !== null && _h !== void 0 ? _h : 'unknown',
31
+ type: ((_j = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getSystemName) === null || _j === void 0 ? void 0 : _j.call(DeviceInfo)) === 'Android' ? 'android' : 'ios',
33
32
  },
34
33
  os: {
35
- name: (_w = (_v = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getSystemName) === null || _v === void 0 ? void 0 : _v.call(DeviceInfo)) !== null && _w !== void 0 ? _w : 'unknown',
36
- version: (_y = (_x = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getSystemVersion) === null || _x === void 0 ? void 0 : _x.call(DeviceInfo)) !== null && _y !== void 0 ? _y : 'unknown',
34
+ name: (_l = (_k = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getSystemName) === null || _k === void 0 ? void 0 : _k.call(DeviceInfo)) !== null && _l !== void 0 ? _l : 'unknown',
35
+ version: (_o = (_m = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getSystemVersion) === null || _m === void 0 ? void 0 : _m.call(DeviceInfo)) !== null && _o !== void 0 ? _o : 'unknown',
36
+ },
37
+ app: {
38
+ name: (_q = (_p = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getApplicationName) === null || _p === void 0 ? void 0 : _p.call(DeviceInfo)) !== null && _q !== void 0 ? _q : 'unknown',
39
+ version: (_t = (_s = (_r = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getVersion) === null || _r === void 0 ? void 0 : _r.call(DeviceInfo)) !== null && _s !== void 0 ? _s : pkg.version) !== null && _t !== void 0 ? _t : 'unknown',
40
+ build: (_v = (_u = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getBuildNumber) === null || _u === void 0 ? void 0 : _u.call(DeviceInfo)) !== null && _v !== void 0 ? _v : 'unknown',
41
+ namespace: (_x = (_w = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getBundleId) === null || _w === void 0 ? void 0 : _w.call(DeviceInfo)) !== null && _x !== void 0 ? _x : 'unknown',
37
42
  },
38
43
  screen: {
39
- density: (_0 = (_z = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getDensity) === null || _z === void 0 ? void 0 : _z.call(DeviceInfo)) !== null && _0 !== void 0 ? _0 : 2,
40
- width: (_2 = (_1 = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getScreenWidth) === null || _1 === void 0 ? void 0 : _1.call(DeviceInfo)) !== null && _2 !== void 0 ? _2 : 0,
41
- height: (_4 = (_3 = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getScreenHeight) === null || _3 === void 0 ? void 0 : _3.call(DeviceInfo)) !== null && _4 !== void 0 ? _4 : 0,
44
+ width: (_z = (_y = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getScreenWidth) === null || _y === void 0 ? void 0 : _y.call(DeviceInfo)) !== null && _z !== void 0 ? _z : 0,
45
+ height: (_1 = (_0 = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getScreenHeight) === null || _0 === void 0 ? void 0 : _0.call(DeviceInfo)) !== null && _1 !== void 0 ? _1 : 0,
46
+ density: (_3 = (_2 = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getDensity) === null || _2 === void 0 ? void 0 : _2.call(DeviceInfo)) !== null && _3 !== void 0 ? _3 : 1,
42
47
  },
43
48
  network: {
44
- wifi: (_6 = (_5 = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.isWifiEnabled) === null || _5 === void 0 ? void 0 : _5.call(DeviceInfo)) !== null && _6 !== void 0 ? _6 : true, // fallback to true if unknown
49
+ wifi: (_5 = await ((_4 = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.isWifiEnabled) === null || _4 === void 0 ? void 0 : _4.call(DeviceInfo))) !== null && _5 !== void 0 ? _5 : false,
45
50
  },
46
- locale,
47
- timezone: getTimeZone(),
48
51
  };
52
+ return cachedContext;
49
53
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metarouter/react-native-sdk",
3
- "version": "0.1.22",
3
+ "version": "0.1.23",
4
4
  "main": "./lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "exports": {