@teardown/react-native 2.0.28 → 2.0.30

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
@@ -112,7 +112,7 @@ import { useTeardown, useForceUpdate, useSession } from '@teardown/react-native'
112
112
  function YourComponent() {
113
113
  const { core } = useTeardown();
114
114
  const session = useSession();
115
- const { status, isUpdateRequired } = useForceUpdate();
115
+ const { versionStatus, isUpdateRequired } = useForceUpdate();
116
116
 
117
117
  const handleLogin = async () => {
118
118
  await core.identity.identify({
@@ -129,14 +129,18 @@ function YourComponent() {
129
129
 
130
130
  ```tsx
131
131
  new TeardownCore({
132
- org_id: string, // Your organization ID
133
- project_id: string, // Your project ID
134
- api_key: string, // Your API key
135
- storageAdapter: adapter, // Storage implementation
136
- deviceAdapter: adapter, // Device info source
137
- forceUpdate: {
138
- throttleMs: 30_000, // Min time between checks (default: 30s)
139
- checkCooldownMs: 10_000 // Cooldown after check (default: 10s)
132
+ org_id: string, // Your organization ID
133
+ project_id: string, // Your project ID
134
+ api_key: string, // Your API key
135
+ environment_slug?: string, // Environment slug (default: "production")
136
+ ingestUrl?: string, // Custom ingest API URL (optional)
137
+ storageAdapter: adapter, // Storage implementation
138
+ deviceAdapter: adapter, // Device info source
139
+ notificationAdapter?: adapter, // Push notification adapter (optional)
140
+ forceUpdate?: {
141
+ checkIntervalMs?: number, // Min time between checks (default: 300000ms/5min)
142
+ checkOnForeground?: boolean, // Check on app foreground (default: true)
143
+ identifyAnonymousDevice?: boolean, // Check even when not identified (default: false)
140
144
  },
141
145
  });
142
146
  ```
@@ -156,16 +160,15 @@ For detailed guides, visit **[teardown.dev/docs](https://teardown.dev/docs)**
156
160
 
157
161
  Local documentation is also available in the [docs](./docs) folder:
158
162
 
159
- - [Getting Started](./docs/01-getting-started.mdx)
160
- - [Core Concepts](./docs/02-core-concepts.mdx)
161
- - [Identity & Authentication](./docs/03-identity.mdx)
162
- - [Force Updates](./docs/04-force-updates.mdx)
163
- - [Device Information](./docs/05-device-info.mdx)
164
- - [Storage](./docs/06-storage.mdx)
165
- - [Logging](./docs/07-logging.mdx)
166
- - [API Reference](./docs/08-api-reference.mdx)
167
- - [Hooks Reference](./docs/09-hooks-reference.mdx)
168
- - [Advanced Usage](./docs/10-advanced.mdx)
163
+ - [Getting Started](./docs/getting-started.mdx)
164
+ - [Core Concepts](./docs/core-concepts.mdx)
165
+ - [Identity & Authentication](./docs/identity.mdx)
166
+ - [Force Updates](./docs/force-updates.mdx)
167
+ - [Logging](./docs/logging.mdx)
168
+ - [API Reference](./docs/api-reference.mdx)
169
+ - [Hooks Reference](./docs/hooks-reference.mdx)
170
+ - [Advanced Usage](./docs/advanced.mdx)
171
+ - [Adapters](./docs/adapters/index.mdx)
169
172
 
170
173
  ## License
171
174
 
@@ -33,17 +33,17 @@ The BasicAdapter returns static or minimal information:
33
33
 
34
34
  ### Application Info
35
35
  - `version` - Static value or from app.json
36
- - `buildNumber` - Static value
37
- - `bundleId` - Static value or from app.json
36
+ - `build_number` - Static value (as number)
38
37
 
39
38
  ### Hardware Info
40
- - `deviceName` - "Unknown Device"
41
- - `brand` - "Unknown"
42
- - `deviceType` - "unknown"
39
+ - `device_name` - "Unknown Device"
40
+ - `device_brand` - "Unknown"
41
+ - `device_type` - "unknown"
43
42
 
44
43
  ### OS Info
45
- - `osName` - From React Native Platform API
46
- - `osVersion` - From React Native Platform API
44
+ - `platform` - From React Native `Platform.OS` mapped to `DevicePlatformEnum`
45
+ - `name` - From React Native Platform API
46
+ - `version` - From React Native Platform API
47
47
 
48
48
  ## When to Use
49
49
 
@@ -44,17 +44,17 @@ import { DeviceInfoAdapter } from '@teardown/react-native/adapters/device-info';
44
44
 
45
45
  ### Application Info
46
46
  - `version` - From `getVersion()`
47
- - `buildNumber` - From `getBuildNumber()`
48
- - `bundleId` - From `getBundleId()`
47
+ - `build_number` - From `getBuildNumber()` (as number)
49
48
 
50
49
  ### Hardware Info
51
- - `deviceName` - From `getDeviceName()`
52
- - `brand` - From `getBrand()`
53
- - `deviceType` - From `getDeviceType()` (phone, tablet, desktop, tv, unknown)
50
+ - `device_name` - From `getDeviceName()`
51
+ - `device_brand` - From `getBrand()`
52
+ - `device_type` - From `getDeviceType()` (phone, tablet, desktop, tv, unknown)
54
53
 
55
54
  ### OS Info
56
- - `osName` - From `getSystemName()`
57
- - `osVersion` - From `getSystemVersion()`
55
+ - `platform` - Mapped from React Native `Platform.OS` to `DevicePlatformEnum`
56
+ - `name` - From `getSystemName()`
57
+ - `version` - From `getSystemVersion()`
58
58
 
59
59
  ## When to Use
60
60
 
@@ -64,7 +64,7 @@ import { DeviceInfoAdapter } from '@teardown/react-native/adapters/device-info';
64
64
 
65
65
  ## Requirements
66
66
 
67
- - `react-native-device-info` >= 10.0.0
67
+ - `react-native-device-info` >= 15.0.0
68
68
  - React Native >= 0.60 (autolinking)
69
69
 
70
70
  ## Platform Notes
@@ -37,25 +37,25 @@ import { ExpoDeviceAdapter } from '@teardown/react-native/adapters/expo';
37
37
 
38
38
  ### Application Info
39
39
  - `version` - From `expo-application` `nativeApplicationVersion`
40
- - `buildNumber` - From `expo-application` `nativeBuildVersion`
41
- - `bundleId` - From `expo-application` `applicationId`
40
+ - `build_number` - From `expo-application` `nativeBuildVersion` (as number)
42
41
 
43
42
  ### Hardware Info
44
- - `deviceName` - From `expo-device` `deviceName`
45
- - `brand` - From `expo-device` `brand`
46
- - `deviceType` - From `expo-device` `deviceType` (phone, tablet, desktop, tv, unknown)
43
+ - `device_name` - From `expo-device` `deviceName`
44
+ - `device_brand` - From `expo-device` `brand`
45
+ - `device_type` - From `expo-device` `deviceType` (phone, tablet, desktop, tv, unknown)
47
46
 
48
47
  ### OS Info
49
- - `osName` - From `expo-device` `osName`
50
- - `osVersion` - From `expo-device` `osVersion`
48
+ - `platform` - Mapped from React Native `Platform.OS` to `DevicePlatformEnum`
49
+ - `name` - From `expo-device` `osName`
50
+ - `version` - From `expo-device` `osVersion`
51
51
 
52
52
  ## When to Use
53
53
 
54
54
  - Expo managed workflow projects
55
55
  - Expo bare workflow projects using Expo modules
56
- - Projects using Expo SDK 44+
56
+ - Projects using Expo SDK 50+
57
57
 
58
58
  ## Requirements
59
59
 
60
- - `expo-device` >= 4.0.0
61
- - `expo-application` >= 4.0.0
60
+ - `expo-device` >= 8.0.0
61
+ - `expo-application` >= 7.0.0
@@ -22,9 +22,8 @@ All device adapters provide:
22
22
 
23
23
  ```typescript
24
24
  interface ApplicationInfo {
25
- version: string; // App version (e.g., "1.2.3")
26
- buildNumber: string; // Build number (e.g., "45")
27
- bundleId: string; // Bundle identifier (e.g., "com.example.app")
25
+ version: string; // App version (e.g., "1.2.3")
26
+ build_number: number; // Build number (e.g., 45)
28
27
  }
29
28
  ```
30
29
 
@@ -32,9 +31,9 @@ interface ApplicationInfo {
32
31
 
33
32
  ```typescript
34
33
  interface HardwareInfo {
35
- deviceName: string; // Device name (e.g., "iPhone 14 Pro")
36
- brand: string; // Manufacturer (e.g., "Apple")
37
- deviceType: string; // Device type (e.g., "phone", "tablet")
34
+ device_name: string; // Device name (e.g., "iPhone 14 Pro")
35
+ device_brand: string; // Manufacturer (e.g., "Apple")
36
+ device_type: string; // Device type (e.g., "phone", "tablet")
38
37
  }
39
38
  ```
40
39
 
@@ -42,8 +41,23 @@ interface HardwareInfo {
42
41
 
43
42
  ```typescript
44
43
  interface OSInfo {
45
- osName: string; // OS name (e.g., "iOS", "Android")
46
- osVersion: string; // OS version (e.g., "17.0")
44
+ platform: DevicePlatformEnum; // Platform enum (IOS, ANDROID, etc.)
45
+ name: string; // OS name (e.g., "iOS", "Android")
46
+ version: string; // OS version (e.g., "17.0")
47
+ }
48
+ ```
49
+
50
+ ### DevicePlatformEnum
51
+
52
+ ```typescript
53
+ enum DevicePlatformEnum {
54
+ IOS = "IOS",
55
+ ANDROID = "ANDROID",
56
+ WEB = "WEB",
57
+ WINDOWS = "WINDOWS",
58
+ MACOS = "MACOS",
59
+ LINUX = "LINUX",
60
+ UNKNOWN = "UNKNOWN",
47
61
  }
48
62
  ```
49
63
 
@@ -52,10 +66,14 @@ interface OSInfo {
52
66
  ```typescript
53
67
  import { TeardownCore } from '@teardown/react-native';
54
68
  import { ExpoDeviceAdapter } from '@teardown/react-native/adapters/expo';
69
+ import { MMKVStorageAdapter } from '@teardown/react-native/adapters/mmkv';
55
70
 
56
71
  const teardown = new TeardownCore({
72
+ org_id: 'your-org-id',
73
+ project_id: 'your-project-id',
74
+ api_key: 'your-api-key',
75
+ storageAdapter: new MMKVStorageAdapter(),
57
76
  deviceAdapter: new ExpoDeviceAdapter(),
58
- // ... other options
59
77
  });
60
78
  ```
61
79
 
@@ -68,34 +86,47 @@ const deviceId = await core.device.getDeviceId();
68
86
  // Returns a UUID that persists in storage
69
87
  ```
70
88
 
89
+ To reset the device ID (device will appear as new install):
90
+
91
+ ```typescript
92
+ core.device.reset();
93
+ // Next getDeviceId() call will generate a new ID
94
+ ```
95
+
71
96
  ## Custom Adapter
72
97
 
73
- Implement the `DeviceInfoAdapter` interface:
98
+ Extend the `DeviceInfoAdapter` abstract class:
74
99
 
75
100
  ```typescript
76
- import type { DeviceInfoAdapter, ApplicationInfo, HardwareInfo, OSInfo } from '@teardown/react-native';
77
-
78
- class CustomDeviceAdapter implements DeviceInfoAdapter {
101
+ import {
102
+ DeviceInfoAdapter,
103
+ DevicePlatformEnum,
104
+ type ApplicationInfo,
105
+ type HardwareInfo,
106
+ type OSInfo,
107
+ } from '@teardown/react-native';
108
+
109
+ class CustomDeviceAdapter extends DeviceInfoAdapter {
79
110
  get applicationInfo(): ApplicationInfo {
80
111
  return {
81
112
  version: '1.0.0',
82
- buildNumber: '1',
83
- bundleId: 'com.example.app',
113
+ build_number: 1,
84
114
  };
85
115
  }
86
116
 
87
117
  get hardwareInfo(): HardwareInfo {
88
118
  return {
89
- deviceName: 'Custom Device',
90
- brand: 'Custom',
91
- deviceType: 'phone',
119
+ device_name: 'Custom Device',
120
+ device_brand: 'Custom',
121
+ device_type: 'phone',
92
122
  };
93
123
  }
94
124
 
95
125
  get osInfo(): OSInfo {
96
126
  return {
97
- osName: 'iOS',
98
- osVersion: '17.0',
127
+ platform: DevicePlatformEnum.IOS,
128
+ name: 'iOS',
129
+ version: '17.0',
99
130
  };
100
131
  }
101
132
  }
@@ -14,74 +14,104 @@ npx expo install expo-notifications expo-device expo-constants
14
14
  ## Usage
15
15
 
16
16
  ```typescript
17
- import { ExpoNotificationsAdapter } from '@teardown/react-native/expo-notifications';
18
-
19
- const notifications = new ExpoNotificationsAdapter();
20
-
21
- // Request permissions
22
- const granted = await notifications.requestPermissions();
17
+ import { TeardownCore } from '@teardown/react-native';
18
+ import { ExpoNotificationsAdapter } from '@teardown/react-native/expo';
19
+ import { ExpoDeviceAdapter } from '@teardown/react-native/adapters/expo';
20
+ import { MMKVStorageAdapter } from '@teardown/react-native/adapters/mmkv';
21
+
22
+ const teardown = new TeardownCore({
23
+ org_id: 'your-org-id',
24
+ project_id: 'your-project-id',
25
+ api_key: 'your-api-key',
26
+ storageAdapter: new MMKVStorageAdapter(),
27
+ deviceAdapter: new ExpoDeviceAdapter(),
28
+ notificationAdapter: new ExpoNotificationsAdapter(),
29
+ });
23
30
 
24
- if (granted) {
25
- // Get push token
26
- const token = await notifications.getToken();
27
- console.log('Push token:', token);
31
+ // Access via NotificationsClient
32
+ if (teardown.notifications) {
33
+ const status = await teardown.notifications.requestPermissions();
34
+ if (status.granted) {
35
+ const token = await teardown.notifications.getToken();
36
+ console.log('Expo push token:', token);
37
+ }
28
38
  }
29
39
  ```
30
40
 
31
41
  ## Import Path
32
42
 
33
43
  ```typescript
34
- import { ExpoNotificationsAdapter } from '@teardown/react-native/expo-notifications';
44
+ import { ExpoNotificationsAdapter } from '@teardown/react-native/expo';
35
45
  ```
36
46
 
37
47
  ## API
38
48
 
49
+ All methods are accessed via `NotificationsClient`, not directly on the adapter.
50
+
51
+ ### requestPermissions()
52
+
53
+ Request notification permissions:
54
+
55
+ ```typescript
56
+ const status = await teardown.notifications.requestPermissions();
57
+ // Returns: { granted: boolean, canAskAgain: boolean }
58
+ ```
59
+
39
60
  ### getToken()
40
61
 
41
62
  Get the Expo push token:
42
63
 
43
64
  ```typescript
44
- const token = await notifications.getToken();
65
+ const token = await teardown.notifications.getToken();
45
66
  // Returns: "ExponentPushToken[xxxxxx]" or null
46
67
  ```
47
68
 
48
- ### requestPermissions()
69
+ ### onNotificationReceived()
49
70
 
50
- Request notification permissions:
71
+ Subscribe to foreground notifications:
51
72
 
52
73
  ```typescript
53
- const granted = await notifications.requestPermissions();
54
- // Returns: true if granted, false otherwise
74
+ const unsubscribe = teardown.notifications.onNotificationReceived((notification) => {
75
+ console.log('Received:', notification.title);
76
+ });
77
+
78
+ // Cleanup
79
+ unsubscribe();
55
80
  ```
56
81
 
57
- ### isEnabled()
82
+ ### onNotificationOpened()
58
83
 
59
- Check if notifications are enabled:
84
+ Subscribe to notification taps:
60
85
 
61
86
  ```typescript
62
- const enabled = await notifications.isEnabled();
87
+ const unsubscribe = teardown.notifications.onNotificationOpened((notification) => {
88
+ console.log('User tapped:', notification.title);
89
+ });
90
+
91
+ // Cleanup
92
+ unsubscribe();
63
93
  ```
64
94
 
65
- ### onNotification()
95
+ ### onTokenRefresh()
66
96
 
67
- Subscribe to incoming notifications while app is foregrounded:
97
+ Subscribe to token changes:
68
98
 
69
99
  ```typescript
70
- const unsubscribe = notifications.onNotification((notification) => {
71
- console.log('Received:', notification.title);
100
+ const unsubscribe = teardown.notifications.onTokenChange((token) => {
101
+ console.log('New token:', token);
72
102
  });
73
103
 
74
104
  // Cleanup
75
105
  unsubscribe();
76
106
  ```
77
107
 
78
- ### onNotificationResponse()
108
+ ### onDataMessage()
79
109
 
80
- Subscribe to notification responses (user taps):
110
+ Subscribe to data-only/silent messages:
81
111
 
82
112
  ```typescript
83
- const unsubscribe = notifications.onNotificationResponse((response) => {
84
- console.log('User tapped notification:', response.notification.title);
113
+ const unsubscribe = teardown.notifications.onDataMessage((message) => {
114
+ console.log('Data message:', message.data);
85
115
  });
86
116
 
87
117
  // Cleanup
@@ -119,9 +149,13 @@ Push notifications require:
119
149
  - Push notification capability
120
150
  - APNs certificate or key
121
151
 
152
+ ## Platform
153
+
154
+ Returns `NotificationPlatformEnum.EXPO`
155
+
122
156
  ## Requirements
123
157
 
124
- - `expo-notifications` >= 0.17.0
125
- - `expo-device` >= 4.0.0
126
- - `expo-constants` >= 13.0.0
158
+ - `expo-notifications` >= 0.32
159
+ - `expo-device` >= 8.0.0
160
+ - `expo-constants` >= 17.0.0
127
161
  - EAS Build or dev client (not Expo Go)
@@ -21,74 +21,104 @@ cd ios && pod install
21
21
  ## Usage
22
22
 
23
23
  ```typescript
24
- import { FirebaseMessagingAdapter } from '@teardown/react-native/firebase-messaging';
25
-
26
- const notifications = new FirebaseMessagingAdapter();
27
-
28
- // Request permissions (iOS)
29
- const granted = await notifications.requestPermissions();
24
+ import { TeardownCore } from '@teardown/react-native';
25
+ import { FirebaseMessagingAdapter } from '@teardown/react-native/firebase';
26
+ import { DeviceInfoAdapter } from '@teardown/react-native/adapters/device-info';
27
+ import { AsyncStorageAdapter } from '@teardown/react-native/adapters/async-storage';
28
+
29
+ const teardown = new TeardownCore({
30
+ org_id: 'your-org-id',
31
+ project_id: 'your-project-id',
32
+ api_key: 'your-api-key',
33
+ storageAdapter: new AsyncStorageAdapter(),
34
+ deviceAdapter: new DeviceInfoAdapter(),
35
+ notificationAdapter: new FirebaseMessagingAdapter(),
36
+ });
30
37
 
31
- if (granted) {
32
- // Get FCM token
33
- const token = await notifications.getToken();
34
- console.log('FCM token:', token);
38
+ // Access via NotificationsClient
39
+ if (teardown.notifications) {
40
+ const status = await teardown.notifications.requestPermissions();
41
+ if (status.granted) {
42
+ const token = await teardown.notifications.getToken();
43
+ console.log('FCM token:', token);
44
+ }
35
45
  }
36
46
  ```
37
47
 
38
48
  ## Import Path
39
49
 
40
50
  ```typescript
41
- import { FirebaseMessagingAdapter } from '@teardown/react-native/firebase-messaging';
51
+ import { FirebaseMessagingAdapter } from '@teardown/react-native/firebase';
42
52
  ```
43
53
 
44
54
  ## API
45
55
 
56
+ All methods are accessed via `NotificationsClient`, not directly on the adapter.
57
+
58
+ ### requestPermissions()
59
+
60
+ Request notification permissions (required on iOS):
61
+
62
+ ```typescript
63
+ const status = await teardown.notifications.requestPermissions();
64
+ // Returns: { granted: boolean, canAskAgain: boolean }
65
+ ```
66
+
46
67
  ### getToken()
47
68
 
48
69
  Get the FCM registration token:
49
70
 
50
71
  ```typescript
51
- const token = await notifications.getToken();
72
+ const token = await teardown.notifications.getToken();
52
73
  // Returns: FCM token string or null
53
74
  ```
54
75
 
55
- ### requestPermissions()
76
+ ### onNotificationReceived()
56
77
 
57
- Request notification permissions (required on iOS):
78
+ Subscribe to foreground notifications:
58
79
 
59
80
  ```typescript
60
- const granted = await notifications.requestPermissions();
61
- // Returns: true if granted, false otherwise
81
+ const unsubscribe = teardown.notifications.onNotificationReceived((notification) => {
82
+ console.log('Received:', notification.title);
83
+ });
84
+
85
+ // Cleanup
86
+ unsubscribe();
62
87
  ```
63
88
 
64
- ### isEnabled()
89
+ ### onNotificationOpened()
65
90
 
66
- Check if notifications are enabled:
91
+ Subscribe to notification taps:
67
92
 
68
93
  ```typescript
69
- const enabled = await notifications.isEnabled();
94
+ const unsubscribe = teardown.notifications.onNotificationOpened((notification) => {
95
+ console.log('User tapped:', notification.title);
96
+ });
97
+
98
+ // Cleanup
99
+ unsubscribe();
70
100
  ```
71
101
 
72
- ### onNotification()
102
+ ### onTokenRefresh()
73
103
 
74
- Subscribe to incoming notifications:
104
+ Subscribe to token changes:
75
105
 
76
106
  ```typescript
77
- const unsubscribe = notifications.onNotification((notification) => {
78
- console.log('Received:', notification.title);
107
+ const unsubscribe = teardown.notifications.onTokenChange((token) => {
108
+ console.log('New FCM token:', token);
79
109
  });
80
110
 
81
111
  // Cleanup
82
112
  unsubscribe();
83
113
  ```
84
114
 
85
- ### onNotificationResponse()
115
+ ### onDataMessage()
86
116
 
87
- Subscribe to notification opens:
117
+ Subscribe to data-only messages (silent push):
88
118
 
89
119
  ```typescript
90
- const unsubscribe = notifications.onNotificationResponse((response) => {
91
- console.log('User tapped:', response.notification.title);
120
+ const unsubscribe = teardown.notifications.onDataMessage((message) => {
121
+ console.log('Data message:', message.data);
92
122
  });
93
123
 
94
124
  // Cleanup
@@ -135,6 +165,10 @@ messaging().setBackgroundMessageHandler(async (remoteMessage) => {
135
165
  });
136
166
  ```
137
167
 
168
+ ## Platform
169
+
170
+ Returns `NotificationPlatformEnum.FCM`
171
+
138
172
  ## Requirements
139
173
 
140
174
  - `@react-native-firebase/app` >= 18.0.0