@nagoorkani/session-capture-expo 0.1.3 → 0.1.5

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
@@ -33,6 +33,10 @@ init({
33
33
  projectId: 'project_...',
34
34
  endpoint: 'https://ingest.example.com',
35
35
  appVersion: '1.4.0',
36
+ // Optional: your signed-in user, recorded on every session. Leave out for
37
+ // anonymous users; call identify() after a later login.
38
+ appUserId: currentUser?.id,
39
+ appUserEmail: currentUser?.email,
36
40
  })
37
41
  ```
38
42
 
@@ -41,6 +45,25 @@ foreground/background transitions are tracked, and errors — including unhandle
41
45
  rejections — are captured without further wiring. Uncaught errors still reach
42
46
  your own handlers: the SDK chains rather than replaces them.
43
47
 
48
+ ### More device detail (optional)
49
+
50
+ Brand, model, screen, locale, timezone, OS and React Native version, and disk
51
+ space are sent with every session at no cost. Battery, memory, CPU
52
+ architectures, OS build, simulator flag, iOS model names and connection type
53
+ need Expo modules. Install whichever you want and pass them in:
54
+
55
+ ```ts
56
+ import * as Device from 'expo-device'
57
+ import * as Battery from 'expo-battery'
58
+ import * as Network from 'expo-network'
59
+
60
+ init({ /* ... */, modules: { device: Device, battery: Battery, network: Network } })
61
+ ```
62
+
63
+ They are passed rather than detected, so the SDK depends on none of them.
64
+ Battery and connection are read after the session opens, and arrive as a
65
+ `device_context` event a moment later.
66
+
44
67
  ## Capturing
45
68
 
46
69
  ```ts
@@ -48,7 +71,7 @@ import { track, screen, identify } from '@nagoorkani/session-capture-expo'
48
71
 
49
72
  screen('Checkout')
50
73
  track('checkout_started', { cartValue: 4200 })
51
- identify('user_123', { plan: 'pro' })
74
+ identify('user_123', { email: 'ana@example.com', plan: 'pro' })
52
75
  ```
53
76
 
54
77
  ```ts
package/dist/device.d.ts CHANGED
@@ -15,9 +15,61 @@
15
15
  * This module is therefore device-only. Nothing importable by tests may import
16
16
  * it: `core.ts` receives the context through a provider instead.
17
17
  */
18
+ type Fields = Record<string, string | number | boolean>;
18
19
  export interface DeviceContext {
19
20
  platform?: 'ios' | 'android';
20
21
  osVersion?: string;
21
22
  appVersion?: string;
23
+ deviceModel?: string;
24
+ /** Grouped detail the dashboard's Info tab renders as one card each. */
25
+ device?: Fields;
26
+ os?: Fields;
27
+ app?: Fields;
22
28
  }
23
- export declare function readDeviceContext(appVersion?: string): DeviceContext;
29
+ /**
30
+ * Expo modules the host app passes in, if it has them installed:
31
+ *
32
+ * import * as Device from 'expo-device'
33
+ * import * as Battery from 'expo-battery'
34
+ * import * as Network from 'expo-network'
35
+ * init({ ..., modules: { device: Device, battery: Battery, network: Network } })
36
+ *
37
+ * Passed in rather than required by name. The SDK ships prebuilt, and an
38
+ * optional `require` of an uninstalled module is a bundler-dependent guess —
39
+ * the same class of silent-on-device failure `device.ts` already hit once.
40
+ * Typed structurally so none of the three is a dependency of the SDK.
41
+ */
42
+ export interface DeviceModules {
43
+ device?: {
44
+ modelName?: string | null;
45
+ totalMemory?: number | null;
46
+ osBuildId?: string | null;
47
+ isDevice?: boolean;
48
+ supportedCpuArchitectures?: string[] | null;
49
+ deviceYearClass?: number | null;
50
+ };
51
+ battery?: {
52
+ getBatteryLevelAsync(): Promise<number>;
53
+ getBatteryStateAsync(): Promise<number>;
54
+ isLowPowerModeEnabledAsync?(): Promise<boolean>;
55
+ };
56
+ network?: {
57
+ getNetworkStateAsync(): Promise<{
58
+ type?: string;
59
+ isConnected?: boolean;
60
+ isInternetReachable?: boolean | null;
61
+ }>;
62
+ };
63
+ }
64
+ /**
65
+ * Battery and connection, which only have async APIs — so they cannot ride on
66
+ * `session_start`, which is captured synchronously the moment a session opens.
67
+ * They go out as a `device_context` event a moment later, and the dashboard
68
+ * merges it into the same cards.
69
+ */
70
+ export declare function readDeviceState(modules: DeviceModules): Promise<DeviceContext | null>;
71
+ export declare function readDeviceContext(appVersion?: string, modules?: DeviceModules, storage?: {
72
+ freeBytes?: number;
73
+ totalBytes?: number;
74
+ }): DeviceContext;
75
+ export {};
package/dist/index.d.ts CHANGED
@@ -6,6 +6,7 @@
6
6
  * installed here and unwound by `shutdown()`.
7
7
  */
8
8
  import { type InitOptions, type RemoteConfig } from '@nagoorkani/session-capture-core';
9
+ import { type DeviceModules } from './device.ts';
9
10
  export type { CaptureEvent, EventBatch, EventType, InitOptions, RemoteConfig, } from '@nagoorkani/session-capture-core';
10
11
  export { SCHEMA_VERSION, DEFAULT_CONFIG } from '@nagoorkani/session-capture-core';
11
12
  export { isSelfDisabled, safe, safeAsync } from '@nagoorkani/session-capture-core';
@@ -30,6 +31,11 @@ export { MemoryStore, type FileStore } from '@nagoorkani/session-capture-core';
30
31
  export { isSampled } from '@nagoorkani/session-capture-core';
31
32
  export { createPersistentStore } from './store-expo.ts';
32
33
  export { SDK_VERSION } from '@nagoorkani/session-capture-core';
34
+ export type { DeviceModules } from './device.ts';
35
+ export interface ExpoInitOptions extends InitOptions {
36
+ /** Optional Expo modules for battery, memory, connection and more in the Info tab. */
37
+ modules?: DeviceModules;
38
+ }
33
39
  export type { Breadcrumb } from '@nagoorkani/session-capture-core';
34
40
  export type { CapturedError } from '@nagoorkani/session-capture-core';
35
41
  export type { NetworkEvent } from '@nagoorkani/session-capture-core';
@@ -39,7 +45,7 @@ export type { NetworkEvent } from '@nagoorkani/session-capture-core';
39
45
  * Pass `enabled: false` to initialize without capturing, then `setEnabled(true)`
40
46
  * once the user consents. Nothing is captured *or* buffered while disabled.
41
47
  */
42
- export declare const init: (options: InitOptions) => void | undefined;
48
+ export declare const init: (options: ExpoInitOptions) => void | undefined;
43
49
  /** Enable or disable capture at runtime. The consent gate. */
44
50
  export declare const setEnabled: (enabled: boolean) => void | undefined;
45
51
  /** Whether the SDK is currently capturing. */
package/dist/index.js CHANGED
@@ -574,7 +574,7 @@ var SessionManager = class {
574
574
  };
575
575
 
576
576
  // ../core/src/core.ts
577
- var SDK_VERSION = "0.1.2";
577
+ var SDK_VERSION = "0.1.4";
578
578
  var SESSION_TIMEOUT_MS = 30 * 60 * 1e3;
579
579
  var ALWAYS_CAPTURED = /* @__PURE__ */ new Set([
580
580
  "error"
@@ -605,6 +605,12 @@ var SdkCore = class {
605
605
  this.sessionListeners = /* @__PURE__ */ new Set();
606
606
  /** Events discarded because remote config disabled capture. Diagnostics. */
607
607
  this.dropOnKill = 0;
608
+ /**
609
+ * Who `identify` last named, repeated on every later `session_start` so a
610
+ * rotated session is not anonymous. Memory only: a relaunch or reload
611
+ * forgets it, and the host calls `identify` again once it knows the user.
612
+ */
613
+ this.user = null;
608
614
  this.now = deps.now ?? Date.now;
609
615
  this.onFlush = deps.onFlush ?? (() => {
610
616
  });
@@ -628,6 +634,9 @@ var SdkCore = class {
628
634
  this.options = options;
629
635
  this.enabled = options.enabled ?? true;
630
636
  this.started = true;
637
+ if (options.appUserId) {
638
+ this.user = options.appUserEmail ? { userId: options.appUserId, email: options.appUserEmail } : { userId: options.appUserId };
639
+ }
631
640
  this.sessions = new SessionManager({
632
641
  timeoutMs: SESSION_TIMEOUT_MS,
633
642
  initial: this.restoreSession(),
@@ -644,6 +653,9 @@ var SdkCore = class {
644
653
  onFlush: (events) => this.deliver(events)
645
654
  });
646
655
  this.startSessionIfNeeded();
656
+ if (this.user) {
657
+ this.capture("user_action", { action: "identify", ...this.user });
658
+ }
647
659
  }
648
660
  /**
649
661
  * Whether capture is currently active.
@@ -824,6 +836,12 @@ var SdkCore = class {
824
836
  markReady() {
825
837
  this.capture("performance", { ...timeToReady(this.now()) });
826
838
  }
839
+ /** Attach an end user to this session and every later one in this run. */
840
+ identify(userId, traits) {
841
+ const email = typeof traits?.email === "string" ? traits.email : void 0;
842
+ this.user = email ? { userId, email } : { userId };
843
+ this.capture("user_action", { action: "identify", userId, ...traits });
844
+ }
827
845
  screen(name) {
828
846
  if (!this.isEnabled() || !this.sessions) return;
829
847
  this.sessions.setScreen(name);
@@ -869,7 +887,7 @@ var SdkCore = class {
869
887
  * rotation takes 1.
870
888
  */
871
889
  announce(sessionId) {
872
- this.capture("session_start", { ...this.deviceContext() });
890
+ this.capture("session_start", { ...this.deviceContext(), ...this.user });
873
891
  for (const listener of this.sessionListeners) {
874
892
  try {
875
893
  listener(sessionId);
@@ -1553,7 +1571,71 @@ var MemoryStore = class {
1553
1571
 
1554
1572
  // src/device.ts
1555
1573
  var import_react_native = require("react-native");
1556
- function readDeviceContext(appVersion) {
1574
+ function compact(fields) {
1575
+ const out = {};
1576
+ for (const [name, value] of Object.entries(fields)) {
1577
+ if (typeof value === "string" ? value : typeof value === "number" || typeof value === "boolean") {
1578
+ out[name] = value;
1579
+ }
1580
+ }
1581
+ return out;
1582
+ }
1583
+ function readDetail(context) {
1584
+ const constants = import_react_native.Platform.constants ?? {};
1585
+ const screen2 = import_react_native.Dimensions.get("screen");
1586
+ const rn = constants.reactNativeVersion;
1587
+ const intl = Intl.DateTimeFormat().resolvedOptions();
1588
+ if (typeof constants.Model === "string") context.deviceModel = constants.Model.slice(0, 64);
1589
+ context.device = compact({
1590
+ brand: constants.Brand,
1591
+ manufacturer: constants.Manufacturer,
1592
+ model: constants.Model,
1593
+ family: constants.interfaceIdiom,
1594
+ screenWidthPixels: Math.round(screen2.width * screen2.scale),
1595
+ screenHeightPixels: Math.round(screen2.height * screen2.scale),
1596
+ screenDensity: screen2.scale,
1597
+ fontScale: screen2.fontScale,
1598
+ orientation: screen2.width > screen2.height ? "landscape" : "portrait",
1599
+ colorScheme: import_react_native.Appearance.getColorScheme() ?? void 0,
1600
+ locale: intl.locale,
1601
+ timezone: intl.timeZone
1602
+ });
1603
+ context.os = compact({
1604
+ name: constants.systemName ?? (import_react_native.Platform.OS === "android" ? "Android" : void 0),
1605
+ version: constants.Release ?? constants.osVersion,
1606
+ apiLevel: import_react_native.Platform.OS === "android" ? import_react_native.Platform.Version : void 0
1607
+ });
1608
+ context.app = compact({
1609
+ version: context.appVersion,
1610
+ reactNative: rn ? `${rn.major}.${rn.minor}.${rn.patch}` : void 0,
1611
+ jsEngine: "HermesInternal" in globalThis ? "hermes" : "jsc"
1612
+ });
1613
+ }
1614
+ var PLUGGED_IN = [2, 3];
1615
+ async function readDeviceState(modules) {
1616
+ const device = {};
1617
+ const { battery, network } = modules;
1618
+ if (battery) {
1619
+ const [level, state, lowPower] = await Promise.all([
1620
+ battery.getBatteryLevelAsync().catch(() => -1),
1621
+ battery.getBatteryStateAsync().catch(() => 0),
1622
+ battery.isLowPowerModeEnabledAsync?.().catch(() => void 0)
1623
+ ]);
1624
+ if (level >= 0) device.batteryPercent = Math.round(level * 100);
1625
+ if (state) device.charging = PLUGGED_IN.includes(state);
1626
+ device.lowPowerMode = lowPower;
1627
+ }
1628
+ if (network) {
1629
+ const net = await network.getNetworkStateAsync().catch(() => null);
1630
+ if (net) {
1631
+ device.connectionType = net.type?.toLowerCase();
1632
+ device.online = net.isInternetReachable ?? net.isConnected;
1633
+ }
1634
+ }
1635
+ const fields = compact(device);
1636
+ return Object.keys(fields).length ? { device: fields } : null;
1637
+ }
1638
+ function readDeviceContext(appVersion, modules = {}, storage) {
1557
1639
  const context = {};
1558
1640
  if (appVersion) {
1559
1641
  context.appVersion = appVersion;
@@ -1564,6 +1646,28 @@ function readDeviceContext(appVersion) {
1564
1646
  if (import_react_native.Platform.Version !== void 0 && import_react_native.Platform.Version !== null) {
1565
1647
  context.osVersion = String(import_react_native.Platform.Version);
1566
1648
  }
1649
+ try {
1650
+ readDetail(context);
1651
+ const d = modules.device;
1652
+ if (d) {
1653
+ Object.assign(context.device, compact({
1654
+ // iOS has no model name in React Native; expo-device maps it ("iPhone 15").
1655
+ model: d.modelName ?? context.device.model,
1656
+ simulator: d.isDevice === void 0 ? void 0 : !d.isDevice,
1657
+ memorySizeBytes: d.totalMemory,
1658
+ architectures: d.supportedCpuArchitectures?.join(", "),
1659
+ yearClass: d.deviceYearClass
1660
+ }));
1661
+ Object.assign(context.os, compact({ build: d.osBuildId }));
1662
+ }
1663
+ if (storage) {
1664
+ Object.assign(context.device, compact({
1665
+ storageSizeBytes: storage.totalBytes,
1666
+ freeStorageBytes: storage.freeBytes
1667
+ }));
1668
+ }
1669
+ } catch {
1670
+ }
1567
1671
  return context;
1568
1672
  }
1569
1673
 
@@ -1610,6 +1714,13 @@ function createPersistentStore(directory = QUEUE_DIR) {
1610
1714
  return null;
1611
1715
  }
1612
1716
  }
1717
+ function readStorage() {
1718
+ try {
1719
+ return { freeBytes: import_expo_file_system.Paths.availableDiskSpace, totalBytes: import_expo_file_system.Paths.totalDiskSpace };
1720
+ } catch {
1721
+ return void 0;
1722
+ }
1723
+ }
1613
1724
 
1614
1725
  // src/lifecycle.ts
1615
1726
  var import_react_native2 = require("react-native");
@@ -1707,8 +1818,15 @@ var init = safe((options) => {
1707
1818
  await queue?.enqueue(batch);
1708
1819
  void dispatcher?.drain();
1709
1820
  },
1710
- deviceContext: () => ({ ...readDeviceContext(options.appVersion) })
1821
+ deviceContext: () => ({ ...readDeviceContext(options.appVersion, options.modules, readStorage()) })
1711
1822
  });
1823
+ const modules = options.modules;
1824
+ if (modules?.battery || modules?.network) {
1825
+ core.onSession(() => {
1826
+ void readDeviceState(modules).then((state) => state && core?.capture("device_context", { ...state })).catch(() => {
1827
+ });
1828
+ });
1829
+ }
1712
1830
  core.init(options);
1713
1831
  void bootstrapConfig(options).catch(() => {
1714
1832
  });
@@ -1773,7 +1891,7 @@ var screen = safe((name) => {
1773
1891
  }, void 0, "screen");
1774
1892
  var identify = safe(
1775
1893
  (userId, traits) => {
1776
- core?.capture("user_action", { action: "identify", userId, ...traits });
1894
+ core?.identify(userId, traits);
1777
1895
  },
1778
1896
  void 0,
1779
1897
  "identify"
package/dist/index.mjs CHANGED
@@ -522,7 +522,7 @@ var SessionManager = class {
522
522
  };
523
523
 
524
524
  // ../core/src/core.ts
525
- var SDK_VERSION = "0.1.2";
525
+ var SDK_VERSION = "0.1.4";
526
526
  var SESSION_TIMEOUT_MS = 30 * 60 * 1e3;
527
527
  var ALWAYS_CAPTURED = /* @__PURE__ */ new Set([
528
528
  "error"
@@ -553,6 +553,12 @@ var SdkCore = class {
553
553
  this.sessionListeners = /* @__PURE__ */ new Set();
554
554
  /** Events discarded because remote config disabled capture. Diagnostics. */
555
555
  this.dropOnKill = 0;
556
+ /**
557
+ * Who `identify` last named, repeated on every later `session_start` so a
558
+ * rotated session is not anonymous. Memory only: a relaunch or reload
559
+ * forgets it, and the host calls `identify` again once it knows the user.
560
+ */
561
+ this.user = null;
556
562
  this.now = deps.now ?? Date.now;
557
563
  this.onFlush = deps.onFlush ?? (() => {
558
564
  });
@@ -576,6 +582,9 @@ var SdkCore = class {
576
582
  this.options = options;
577
583
  this.enabled = options.enabled ?? true;
578
584
  this.started = true;
585
+ if (options.appUserId) {
586
+ this.user = options.appUserEmail ? { userId: options.appUserId, email: options.appUserEmail } : { userId: options.appUserId };
587
+ }
579
588
  this.sessions = new SessionManager({
580
589
  timeoutMs: SESSION_TIMEOUT_MS,
581
590
  initial: this.restoreSession(),
@@ -592,6 +601,9 @@ var SdkCore = class {
592
601
  onFlush: (events) => this.deliver(events)
593
602
  });
594
603
  this.startSessionIfNeeded();
604
+ if (this.user) {
605
+ this.capture("user_action", { action: "identify", ...this.user });
606
+ }
595
607
  }
596
608
  /**
597
609
  * Whether capture is currently active.
@@ -772,6 +784,12 @@ var SdkCore = class {
772
784
  markReady() {
773
785
  this.capture("performance", { ...timeToReady(this.now()) });
774
786
  }
787
+ /** Attach an end user to this session and every later one in this run. */
788
+ identify(userId, traits) {
789
+ const email = typeof traits?.email === "string" ? traits.email : void 0;
790
+ this.user = email ? { userId, email } : { userId };
791
+ this.capture("user_action", { action: "identify", userId, ...traits });
792
+ }
775
793
  screen(name) {
776
794
  if (!this.isEnabled() || !this.sessions) return;
777
795
  this.sessions.setScreen(name);
@@ -817,7 +835,7 @@ var SdkCore = class {
817
835
  * rotation takes 1.
818
836
  */
819
837
  announce(sessionId) {
820
- this.capture("session_start", { ...this.deviceContext() });
838
+ this.capture("session_start", { ...this.deviceContext(), ...this.user });
821
839
  for (const listener of this.sessionListeners) {
822
840
  try {
823
841
  listener(sessionId);
@@ -1500,8 +1518,72 @@ var MemoryStore = class {
1500
1518
  };
1501
1519
 
1502
1520
  // src/device.ts
1503
- import { Platform } from "react-native";
1504
- function readDeviceContext(appVersion) {
1521
+ import { Appearance, Dimensions, Platform } from "react-native";
1522
+ function compact(fields) {
1523
+ const out = {};
1524
+ for (const [name, value] of Object.entries(fields)) {
1525
+ if (typeof value === "string" ? value : typeof value === "number" || typeof value === "boolean") {
1526
+ out[name] = value;
1527
+ }
1528
+ }
1529
+ return out;
1530
+ }
1531
+ function readDetail(context) {
1532
+ const constants = Platform.constants ?? {};
1533
+ const screen2 = Dimensions.get("screen");
1534
+ const rn = constants.reactNativeVersion;
1535
+ const intl = Intl.DateTimeFormat().resolvedOptions();
1536
+ if (typeof constants.Model === "string") context.deviceModel = constants.Model.slice(0, 64);
1537
+ context.device = compact({
1538
+ brand: constants.Brand,
1539
+ manufacturer: constants.Manufacturer,
1540
+ model: constants.Model,
1541
+ family: constants.interfaceIdiom,
1542
+ screenWidthPixels: Math.round(screen2.width * screen2.scale),
1543
+ screenHeightPixels: Math.round(screen2.height * screen2.scale),
1544
+ screenDensity: screen2.scale,
1545
+ fontScale: screen2.fontScale,
1546
+ orientation: screen2.width > screen2.height ? "landscape" : "portrait",
1547
+ colorScheme: Appearance.getColorScheme() ?? void 0,
1548
+ locale: intl.locale,
1549
+ timezone: intl.timeZone
1550
+ });
1551
+ context.os = compact({
1552
+ name: constants.systemName ?? (Platform.OS === "android" ? "Android" : void 0),
1553
+ version: constants.Release ?? constants.osVersion,
1554
+ apiLevel: Platform.OS === "android" ? Platform.Version : void 0
1555
+ });
1556
+ context.app = compact({
1557
+ version: context.appVersion,
1558
+ reactNative: rn ? `${rn.major}.${rn.minor}.${rn.patch}` : void 0,
1559
+ jsEngine: "HermesInternal" in globalThis ? "hermes" : "jsc"
1560
+ });
1561
+ }
1562
+ var PLUGGED_IN = [2, 3];
1563
+ async function readDeviceState(modules) {
1564
+ const device = {};
1565
+ const { battery, network } = modules;
1566
+ if (battery) {
1567
+ const [level, state, lowPower] = await Promise.all([
1568
+ battery.getBatteryLevelAsync().catch(() => -1),
1569
+ battery.getBatteryStateAsync().catch(() => 0),
1570
+ battery.isLowPowerModeEnabledAsync?.().catch(() => void 0)
1571
+ ]);
1572
+ if (level >= 0) device.batteryPercent = Math.round(level * 100);
1573
+ if (state) device.charging = PLUGGED_IN.includes(state);
1574
+ device.lowPowerMode = lowPower;
1575
+ }
1576
+ if (network) {
1577
+ const net = await network.getNetworkStateAsync().catch(() => null);
1578
+ if (net) {
1579
+ device.connectionType = net.type?.toLowerCase();
1580
+ device.online = net.isInternetReachable ?? net.isConnected;
1581
+ }
1582
+ }
1583
+ const fields = compact(device);
1584
+ return Object.keys(fields).length ? { device: fields } : null;
1585
+ }
1586
+ function readDeviceContext(appVersion, modules = {}, storage) {
1505
1587
  const context = {};
1506
1588
  if (appVersion) {
1507
1589
  context.appVersion = appVersion;
@@ -1512,6 +1594,28 @@ function readDeviceContext(appVersion) {
1512
1594
  if (Platform.Version !== void 0 && Platform.Version !== null) {
1513
1595
  context.osVersion = String(Platform.Version);
1514
1596
  }
1597
+ try {
1598
+ readDetail(context);
1599
+ const d = modules.device;
1600
+ if (d) {
1601
+ Object.assign(context.device, compact({
1602
+ // iOS has no model name in React Native; expo-device maps it ("iPhone 15").
1603
+ model: d.modelName ?? context.device.model,
1604
+ simulator: d.isDevice === void 0 ? void 0 : !d.isDevice,
1605
+ memorySizeBytes: d.totalMemory,
1606
+ architectures: d.supportedCpuArchitectures?.join(", "),
1607
+ yearClass: d.deviceYearClass
1608
+ }));
1609
+ Object.assign(context.os, compact({ build: d.osBuildId }));
1610
+ }
1611
+ if (storage) {
1612
+ Object.assign(context.device, compact({
1613
+ storageSizeBytes: storage.totalBytes,
1614
+ freeStorageBytes: storage.freeBytes
1615
+ }));
1616
+ }
1617
+ } catch {
1618
+ }
1515
1619
  return context;
1516
1620
  }
1517
1621
 
@@ -1558,6 +1662,13 @@ function createPersistentStore(directory = QUEUE_DIR) {
1558
1662
  return null;
1559
1663
  }
1560
1664
  }
1665
+ function readStorage() {
1666
+ try {
1667
+ return { freeBytes: Paths.availableDiskSpace, totalBytes: Paths.totalDiskSpace };
1668
+ } catch {
1669
+ return void 0;
1670
+ }
1671
+ }
1561
1672
 
1562
1673
  // src/lifecycle.ts
1563
1674
  import { AppState } from "react-native";
@@ -1655,8 +1766,15 @@ var init = safe((options) => {
1655
1766
  await queue?.enqueue(batch);
1656
1767
  void dispatcher?.drain();
1657
1768
  },
1658
- deviceContext: () => ({ ...readDeviceContext(options.appVersion) })
1769
+ deviceContext: () => ({ ...readDeviceContext(options.appVersion, options.modules, readStorage()) })
1659
1770
  });
1771
+ const modules = options.modules;
1772
+ if (modules?.battery || modules?.network) {
1773
+ core.onSession(() => {
1774
+ void readDeviceState(modules).then((state) => state && core?.capture("device_context", { ...state })).catch(() => {
1775
+ });
1776
+ });
1777
+ }
1660
1778
  core.init(options);
1661
1779
  void bootstrapConfig(options).catch(() => {
1662
1780
  });
@@ -1721,7 +1839,7 @@ var screen = safe((name) => {
1721
1839
  }, void 0, "screen");
1722
1840
  var identify = safe(
1723
1841
  (userId, traits) => {
1724
- core?.capture("user_action", { action: "identify", userId, ...traits });
1842
+ core?.identify(userId, traits);
1725
1843
  },
1726
1844
  void 0,
1727
1845
  "identify"
@@ -33,3 +33,8 @@ export declare class ExpoFileStore implements FileStore {
33
33
  * bad as refusing to run inside someone else's application.
34
34
  */
35
35
  export declare function createPersistentStore(directory?: string): FileStore | null;
36
+ /** Disk capacity for the Info tab. Sync in the current file-system API. */
37
+ export declare function readStorage(): {
38
+ freeBytes?: number;
39
+ totalBytes?: number;
40
+ } | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nagoorkani/session-capture-expo",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "Lightweight session capture and observability for Expo / React Native",
5
5
  "license": "UNLICENSED",
6
6
  "main": "./dist/index.js",
@@ -20,7 +20,7 @@
20
20
  "analytics"
21
21
  ],
22
22
  "dependencies": {
23
- "@nagoorkani/session-capture-core": "^0.1.2"
23
+ "@nagoorkani/session-capture-core": "^0.1.4"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "expo": ">=50",