@rn-bridge-tools/expo 0.0.9 → 0.0.11

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 +1 @@
1
- {"version":3,"file":"device.d.ts","sourceRoot":"","sources":["../../src/handlers/device.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAY7D,eAAO,MAAM,cAAc;iCAEb,eAAe,CAAC,gBAAgB,CAAC,CAAC,SAAS,CAAC,KACrD,OAAO,CAAC,eAAe,CAAC,gBAAgB,CAAC,CAAC,UAAU,CAAC,CAAC;oCAkB7C,eAAe,CAAC,mBAAmB,CAAC,CAAC,SAAS,CAAC,KACxD,OAAO,CAAC,eAAe,CAAC,mBAAmB,CAAC,CAAC,UAAU,CAAC,CAAC;oCAmBhD,eAAe,CAAC,mBAAmB,CAAC,CAAC,SAAS,CAAC,KACxD,OAAO,CAAC,eAAe,CAAC,mBAAmB,CAAC,CAAC,UAAU,CAAC,CAAC;CAgB7D,CAAC"}
1
+ {"version":3,"file":"device.d.ts","sourceRoot":"","sources":["../../src/handlers/device.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AA0B7D,eAAO,MAAM,cAAc;iCAEb,eAAe,CAAC,gBAAgB,CAAC,CAAC,SAAS,CAAC,KACrD,OAAO,CAAC,eAAe,CAAC,gBAAgB,CAAC,CAAC,UAAU,CAAC,CAAC;oCAsB7C,eAAe,CAAC,mBAAmB,CAAC,CAAC,SAAS,CAAC,KACxD,OAAO,CAAC,eAAe,CAAC,mBAAmB,CAAC,CAAC,UAAU,CAAC,CAAC;oCAkBhD,eAAe,CAAC,mBAAmB,CAAC,CAAC,SAAS,CAAC,KACxD,OAAO,CAAC,eAAe,CAAC,mBAAmB,CAAC,CAAC,UAAU,CAAC,CAAC;CAoB7D,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"location.d.ts","sourceRoot":"","sources":["../../src/handlers/location.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAgC/D,eAAO,MAAM,gBAAgB;qCAEhB,iBAAiB,CAAC,qBAAqB,CAAC,CAAC,SAAS,CAAC,KAC3D,OAAO,CAAC,iBAAiB,CAAC,qBAAqB,CAAC,CAAC,UAAU,CAAC,CAAC;qCA2BrD,iBAAiB,CAAC,qBAAqB,CAAC,CAAC,SAAS,CAAC,KAC3D,OAAO,CAAC,iBAAiB,CAAC,qBAAqB,CAAC,CAAC,UAAU,CAAC,CAAC;oCA8BrD,iBAAiB,CAAC,oBAAoB,CAAC,CAAC,SAAS,CAAC,KAC1D,OAAO,CAAC,iBAAiB,CAAC,oBAAoB,CAAC,CAAC,UAAU,CAAC,CAAC;CAShE,CAAC"}
1
+ {"version":3,"file":"location.d.ts","sourceRoot":"","sources":["../../src/handlers/location.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAiC/D,eAAO,MAAM,gBAAgB;qCAEhB,iBAAiB,CAAC,qBAAqB,CAAC,CAAC,SAAS,CAAC,KAC3D,OAAO,CAAC,iBAAiB,CAAC,qBAAqB,CAAC,CAAC,UAAU,CAAC,CAAC;qCAgCrD,iBAAiB,CAAC,qBAAqB,CAAC,CAAC,SAAS,CAAC,KAC3D,OAAO,CAAC,iBAAiB,CAAC,qBAAqB,CAAC,CAAC,UAAU,CAAC,CAAC;oCAmCrD,iBAAiB,CAAC,oBAAoB,CAAC,CAAC,SAAS,CAAC,KAC1D,OAAO,CAAC,iBAAiB,CAAC,oBAAoB,CAAC,CAAC,UAAU,CAAC,CAAC;CAShE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rn-bridge-tools/expo",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
4
4
  "description": "Expo/React Native WebView bridge component and handlers for bridge-tools",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./dist/index.d.ts",
@@ -15,11 +15,13 @@
15
15
  "dist"
16
16
  ],
17
17
  "dependencies": {
18
- "@rn-bridge-tools/core": "0.0.9"
18
+ "@rn-bridge-tools/core": "0.0.11"
19
19
  },
20
20
  "peerDependencies": {
21
21
  "@react-native-async-storage/async-storage": "*",
22
+ "expo-network": "*",
22
23
  "@webview-bridge/react-native": ">=1.0.0",
24
+ "expo-battery": "*",
23
25
  "expo-camera": "*",
24
26
  "expo-clipboard": "*",
25
27
  "expo-device": "*",
@@ -79,6 +81,12 @@
79
81
  },
80
82
  "@react-native-async-storage/async-storage": {
81
83
  "optional": true
84
+ },
85
+ "expo-network": {
86
+ "optional": true
87
+ },
88
+ "expo-battery": {
89
+ "optional": true
82
90
  }
83
91
  },
84
92
  "devDependencies": {
@@ -10,6 +10,20 @@ interface DeviceModule {
10
10
  DeviceType: { TABLET: number };
11
11
  }
12
12
 
13
+ interface BatteryModule {
14
+ getBatteryLevelAsync: () => Promise<number>;
15
+ getBatteryStateAsync: () => Promise<number>;
16
+ BatteryState: { CHARGING: number };
17
+ }
18
+
19
+ interface NetworkModule {
20
+ getNetworkStateAsync: () => Promise<{
21
+ type: string;
22
+ isConnected: boolean;
23
+ isInternetReachable: boolean;
24
+ }>;
25
+ }
26
+
13
27
  export const deviceHandlers = {
14
28
  'device.getInfo': async (
15
29
  _payload: DeviceNamespace['device.getInfo']['request'],
@@ -18,54 +32,61 @@ export const deviceHandlers = {
18
32
  try { Device = require('expo-device') as DeviceModule; } catch {}
19
33
  if (!Device) return { success: false, error: 'MODULE_NOT_INSTALLED: expo-device' } as never;
20
34
 
21
- return {
22
- os: Platform.OS as 'ios' | 'android',
23
- osVersion: Platform.Version?.toString() ?? '',
24
- model: Device.modelName ?? '',
25
- brand: Device.brand ?? '',
26
- isTablet: Device.deviceType === Device.DeviceType.TABLET,
27
- appVersion: '1.0.0',
28
- buildNumber: '1',
29
- bundleId: '',
30
- };
35
+ try {
36
+ return {
37
+ os: Platform.OS as 'ios' | 'android',
38
+ osVersion: Platform.Version?.toString() ?? '',
39
+ model: Device.modelName ?? '',
40
+ brand: Device.brand ?? '',
41
+ isTablet: Device.deviceType === Device.DeviceType.TABLET,
42
+ appVersion: '1.0.0',
43
+ buildNumber: '1',
44
+ bundleId: '',
45
+ };
46
+ } catch (e) {
47
+ return { success: false, error: String(e) } as never;
48
+ }
31
49
  },
32
50
 
33
51
  'device.getBattery': async (
34
52
  _payload: DeviceNamespace['device.getBattery']['request'],
35
53
  ): Promise<DeviceNamespace['device.getBattery']['response']> => {
54
+ let Battery: BatteryModule | null = null;
55
+ try { Battery = require('expo-battery') as BatteryModule; } catch {}
56
+ if (!Battery) return { success: false, error: 'MODULE_NOT_INSTALLED: expo-battery' } as never;
57
+
36
58
  try {
37
- let Battery: { getBatteryLevelAsync: () => Promise<number>; getBatteryStateAsync: () => Promise<number>; BatteryState: { CHARGING: number } } | null = null;
38
- try { Battery = require('expo-battery') as { getBatteryLevelAsync: () => Promise<number>; getBatteryStateAsync: () => Promise<number>; BatteryState: { CHARGING: number } }; } catch {}
39
- if (!Battery) {
40
- return { level: -1, isCharging: false };
41
- }
42
59
  const level = await Battery.getBatteryLevelAsync();
43
60
  const state = await Battery.getBatteryStateAsync();
44
61
  return {
45
62
  level,
46
63
  isCharging: state === Battery.BatteryState.CHARGING,
47
64
  };
48
- } catch {
49
- return { level: -1, isCharging: false };
65
+ } catch (e) {
66
+ return { success: false, error: String(e) } as never;
50
67
  }
51
68
  },
52
69
 
53
70
  'device.getNetwork': async (
54
71
  _payload: DeviceNamespace['device.getNetwork']['request'],
55
72
  ): Promise<DeviceNamespace['device.getNetwork']['response']> => {
73
+ let Network: NetworkModule | null = null;
74
+ try { Network = require('expo-network') as NetworkModule; } catch {}
75
+ if (!Network) return { success: false, error: 'MODULE_NOT_INSTALLED: expo-network' } as never;
76
+
56
77
  try {
57
- let NetInfo: { fetch: () => Promise<{ type: string; isConnected: boolean | null }> } | null = null;
58
- try { NetInfo = require('@react-native-community/netinfo') as { fetch: () => Promise<{ type: string; isConnected: boolean | null }> }; } catch {}
59
- if (!NetInfo) {
60
- return { type: 'unknown', isConnected: true };
61
- }
62
- const state = await NetInfo.fetch();
78
+ const state = await Network.getNetworkStateAsync();
79
+ const typeMap: Record<string, 'wifi' | 'cellular' | 'none' | 'unknown'> = {
80
+ WIFI: 'wifi',
81
+ CELLULAR: 'cellular',
82
+ NONE: 'none',
83
+ };
63
84
  return {
64
- type: (state.type as 'wifi' | 'cellular' | 'none' | 'unknown') ?? 'unknown',
85
+ type: typeMap[state.type] ?? 'unknown',
65
86
  isConnected: state.isConnected ?? false,
66
87
  };
67
- } catch {
68
- return { type: 'unknown', isConnected: true };
88
+ } catch (e) {
89
+ return { success: false, error: String(e) } as never;
69
90
  }
70
91
  },
71
92
  };
@@ -10,6 +10,7 @@ interface ExpoLocationModule {
10
10
  High: number;
11
11
  Highest: number;
12
12
  };
13
+ requestForegroundPermissionsAsync: () => Promise<{ status: string }>;
13
14
  getCurrentPositionAsync: (opts: {
14
15
  accuracy?: number;
15
16
  }) => Promise<{
@@ -38,6 +39,11 @@ export const locationHandlers = {
38
39
  try { Location = require('expo-location') as ExpoLocationModule; } catch {}
39
40
  if (!Location) return { success: false, error: 'MODULE_NOT_INSTALLED: expo-location' } as never;
40
41
 
42
+ const { status } = await Location.requestForegroundPermissionsAsync();
43
+ if (status !== 'granted') {
44
+ return { success: false, error: 'PERMISSION_DENIED: location' } as never;
45
+ }
46
+
41
47
  const accuracyMap: Record<string, number> = {
42
48
  lowest: Location.Accuracy.Lowest,
43
49
  low: Location.Accuracy.Low,
@@ -66,6 +72,11 @@ export const locationHandlers = {
66
72
  try { Location = require('expo-location') as ExpoLocationModule; } catch {}
67
73
  if (!Location) return { success: false, error: 'MODULE_NOT_INSTALLED: expo-location' } as never;
68
74
 
75
+ const { status } = await Location.requestForegroundPermissionsAsync();
76
+ if (status !== 'granted') {
77
+ return { success: false, error: 'PERMISSION_DENIED: location' } as never;
78
+ }
79
+
69
80
  watchCounter += 1;
70
81
  const watchId = `watch_${watchCounter}`;
71
82