@teardown/react-native 1.2.39 → 2.0.1

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.
Files changed (87) hide show
  1. package/README.md +89 -7
  2. package/docs/01-getting-started.mdx +147 -0
  3. package/docs/02-core-concepts.mdx +188 -0
  4. package/docs/03-identity.mdx +301 -0
  5. package/docs/04-force-updates.mdx +339 -0
  6. package/docs/05-device-info.mdx +324 -0
  7. package/docs/06-logging.mdx +345 -0
  8. package/docs/06-storage.mdx +349 -0
  9. package/docs/07-api-reference.mdx +472 -0
  10. package/docs/07-logging.mdx +345 -0
  11. package/docs/08-api-reference.mdx +472 -0
  12. package/docs/08-hooks-reference.mdx +476 -0
  13. package/docs/09-advanced.mdx +563 -0
  14. package/docs/09-hooks-reference.mdx +476 -0
  15. package/docs/10-advanced.mdx +563 -0
  16. package/package.json +65 -47
  17. package/src/clients/api/api.client.ts +80 -0
  18. package/src/clients/api/index.ts +1 -0
  19. package/src/clients/device/device.adpater-interface.ts +57 -0
  20. package/src/clients/device/device.client.test.ts +190 -0
  21. package/src/clients/device/device.client.ts +69 -0
  22. package/src/clients/device/expo-adapter.ts +90 -0
  23. package/src/clients/device/index.ts +4 -0
  24. package/src/clients/force-update/force-update.client.test.ts +295 -0
  25. package/src/clients/force-update/force-update.client.ts +224 -0
  26. package/src/clients/force-update/index.ts +1 -0
  27. package/src/clients/identity/identity.client.test.ts +454 -0
  28. package/src/clients/identity/identity.client.ts +255 -0
  29. package/src/clients/identity/index.ts +1 -0
  30. package/src/clients/logging/index.ts +1 -0
  31. package/src/clients/logging/logging.client.ts +92 -0
  32. package/src/clients/notifications/notifications.client.ts +10 -0
  33. package/src/clients/storage/index.ts +1 -0
  34. package/src/clients/storage/mmkv-adapter.ts +23 -0
  35. package/src/clients/storage/storage.client.ts +75 -0
  36. package/src/clients/utils/index.ts +1 -0
  37. package/src/clients/utils/utils.client.ts +75 -0
  38. package/src/components/ui/button.tsx +0 -0
  39. package/src/components/ui/input.tsx +0 -0
  40. package/src/contexts/index.ts +1 -0
  41. package/src/contexts/teardown.context.ts +17 -0
  42. package/src/exports/expo.ts +1 -0
  43. package/src/exports/index.ts +16 -0
  44. package/src/exports/mmkv.ts +1 -0
  45. package/src/hooks/use-force-update.ts +38 -0
  46. package/src/hooks/use-session.ts +26 -0
  47. package/src/providers/teardown.provider.tsx +28 -0
  48. package/src/teardown.core.ts +76 -0
  49. package/dist/components/index.d.ts +0 -1
  50. package/dist/components/index.js +0 -3
  51. package/dist/components/index.js.map +0 -1
  52. package/dist/components/teardown-logo.d.ts +0 -4
  53. package/dist/components/teardown-logo.js +0 -35
  54. package/dist/components/teardown-logo.js.map +0 -1
  55. package/dist/containers/index.d.ts +0 -1
  56. package/dist/containers/index.js +0 -18
  57. package/dist/containers/index.js.map +0 -1
  58. package/dist/containers/teardown.container.d.ts +0 -8
  59. package/dist/containers/teardown.container.js +0 -26
  60. package/dist/containers/teardown.container.js.map +0 -1
  61. package/dist/index.d.ts +0 -2
  62. package/dist/index.js +0 -22
  63. package/dist/index.js.map +0 -1
  64. package/dist/plugins/http.plugin.d.ts +0 -23
  65. package/dist/plugins/http.plugin.js +0 -145
  66. package/dist/plugins/http.plugin.js.map +0 -1
  67. package/dist/plugins/index.d.ts +0 -2
  68. package/dist/plugins/index.js +0 -20
  69. package/dist/plugins/index.js.map +0 -1
  70. package/dist/plugins/logging.plugin.d.ts +0 -9
  71. package/dist/plugins/logging.plugin.js +0 -36
  72. package/dist/plugins/logging.plugin.js.map +0 -1
  73. package/dist/plugins/websocket.plugin.d.ts +0 -1
  74. package/dist/plugins/websocket.plugin.js +0 -108
  75. package/dist/plugins/websocket.plugin.js.map +0 -1
  76. package/dist/services/index.d.ts +0 -1
  77. package/dist/services/index.js +0 -18
  78. package/dist/services/index.js.map +0 -1
  79. package/dist/services/teardown.service.d.ts +0 -10
  80. package/dist/services/teardown.service.js +0 -22
  81. package/dist/services/teardown.service.js.map +0 -1
  82. package/dist/teardown.client.d.ts +0 -41
  83. package/dist/teardown.client.js +0 -60
  84. package/dist/teardown.client.js.map +0 -1
  85. package/dist/utils/log.d.ts +0 -5
  86. package/dist/utils/log.js +0 -9
  87. package/dist/utils/log.js.map +0 -1
package/README.md CHANGED
@@ -1,20 +1,102 @@
1
+ # @teardown/react-native
1
2
 
3
+ Comprehensive SDK for managing device identity, force updates, logging, and analytics in React Native and Expo applications.
2
4
 
5
+ ## Features
3
6
 
7
+ - 🔐 **Device & User Identity** - Unique device fingerprinting and user session management
8
+ - 🔄 **Force Updates** - Automatic version checking with optional or required update flows
9
+ - 📱 **Device Information** - Comprehensive device, OS, and app information collection
10
+ - 💾 **Storage** - Namespaced persistent storage with platform adapters
11
+ - 📝 **Logging** - Structured logging system with debug modes
12
+ - ⚡ **Performance** - Optimized with caching, throttling, and efficient state management
13
+ - 🎯 **Type Safety** - Full TypeScript support with runtime validation
4
14
 
5
-
6
- To get started:
15
+ ## Installation
7
16
 
8
17
  ```bash
9
- yarn add react-native-gesture-handler @teardown/react-native
18
+ bun add @teardown/react-native
10
19
  ```
11
20
 
12
- If you're using CocoaPods you need to install pods:
21
+ ### Peer Dependencies
13
22
 
14
23
  ```bash
15
- cd ios && pod install
24
+ bun add react react-native zod
25
+ bun add expo-application expo-device expo-updates
26
+ bun add react-native-device-info
27
+ ```
28
+
29
+ ## Quick Start
16
30
 
17
- or
31
+ ### 1. Initialize the SDK
18
32
 
19
- npx pod-install
33
+ ```tsx
34
+ import { TeardownCore } from '@teardown/react-native';
35
+ import { ExpoDeviceAdapter } from '@teardown/react-native/expo';
36
+ import { createMMKVStorageFactory } from '@teardown/react-native/mmkv';
37
+
38
+ export const teardown = new TeardownCore({
39
+ org_id: 'your-org-id',
40
+ project_id: 'your-project-id',
41
+ api_key: 'your-api-key',
42
+ storageFactory: createMMKVStorageFactory(),
43
+ deviceAdapter: new ExpoDeviceAdapter(),
44
+ forceUpdate: {
45
+ throttleMs: 30_000, // 30 seconds
46
+ checkCooldownMs: 10_000, // 10 seconds
47
+ },
48
+ });
20
49
  ```
50
+
51
+ ### 2. Wrap your app with TeardownProvider
52
+
53
+ ```tsx
54
+ import { TeardownProvider } from '@teardown/react-native';
55
+ import { teardown } from './lib/teardown';
56
+
57
+ export default function RootLayout() {
58
+ return (
59
+ <TeardownProvider core={teardown}>
60
+ <YourApp />
61
+ </TeardownProvider>
62
+ );
63
+ }
64
+ ```
65
+
66
+ ### 3. Use in components
67
+
68
+ ```tsx
69
+ import { useTeardown } from '@teardown/react-native';
70
+
71
+ function YourComponent() {
72
+ const { core } = useTeardown();
73
+
74
+ const handleLogin = async () => {
75
+ await core.identity.identify({
76
+ user_id: 'user-123',
77
+ email: 'user@example.com',
78
+ });
79
+ };
80
+
81
+ return <Button onPress={handleLogin} />;
82
+ }
83
+ ```
84
+
85
+ ## Documentation
86
+
87
+ Complete documentation is available in the [docs](./docs) folder:
88
+
89
+ - [Getting Started](./docs/01-getting-started.mdx) - Installation and setup
90
+ - [Core Concepts](./docs/02-core-concepts.mdx) - Architecture overview
91
+ - [Identity & Authentication](./docs/03-identity.mdx) - User session management
92
+ - [Force Updates](./docs/04-force-updates.mdx) - Version management
93
+ - [Device Information](./docs/05-device-info.mdx) - Device data collection
94
+ - [Storage](./docs/06-storage.mdx) - Persistent storage
95
+ - [Logging](./docs/07-logging.mdx) - Structured logging
96
+ - [API Reference](./docs/08-api-reference.mdx) - Complete API docs
97
+ - [Hooks Reference](./docs/09-hooks-reference.mdx) - React hooks
98
+ - [Advanced Usage](./docs/10-advanced.mdx) - Advanced patterns
99
+
100
+ ## License
101
+
102
+ Proprietary - See LICENSE file for details
@@ -0,0 +1,147 @@
1
+ # Getting Started
2
+
3
+ This guide will walk you through installing and setting up the Teardown SDK in your React Native or Expo application.
4
+
5
+ ## Installation
6
+
7
+ Install the core package:
8
+
9
+ ```bash
10
+ bun add @teardown/react-native
11
+ ```
12
+
13
+ ### Peer Dependencies
14
+
15
+ Install required peer dependencies:
16
+
17
+ ```bash
18
+ bun add react react-native zod
19
+ ```
20
+
21
+ ### Platform Adapters
22
+
23
+ #### For Expo Projects
24
+
25
+ ```bash
26
+ bun add expo-application expo-device expo-updates
27
+ ```
28
+
29
+ #### For React Native CLI Projects
30
+
31
+ ```bash
32
+ bun add react-native-device-info
33
+ ```
34
+
35
+ ### Storage Adapter
36
+
37
+ Install MMKV for fast, encrypted storage:
38
+
39
+ ```bash
40
+ bun add react-native-mmkv
41
+ ```
42
+
43
+ ## Initial Setup
44
+
45
+ ### 1. Create SDK Configuration
46
+
47
+ Create a file to initialize the Teardown SDK (e.g., `lib/teardown.ts`):
48
+
49
+ ```typescript
50
+ import { TeardownCore } from '@teardown/react-native';
51
+ import { ExpoDeviceAdapter } from '@teardown/react-native/expo';
52
+ import { createMMKVStorageFactory } from '@teardown/react-native/mmkv';
53
+
54
+ export const teardown = new TeardownCore({
55
+ org_id: 'your-org-id',
56
+ project_id: 'your-project-id',
57
+ api_key: 'your-api-key',
58
+ storageFactory: createMMKVStorageFactory(),
59
+ deviceAdapter: new ExpoDeviceAdapter(),
60
+ forceUpdate: {
61
+ throttleMs: 30_000, // Check every 30 seconds when app returns to foreground
62
+ checkCooldownMs: 300_000, // Wait 5 minutes between checks
63
+ },
64
+ });
65
+ ```
66
+
67
+ ### 2. Wrap Your App with TeardownProvider
68
+
69
+ In your root layout file (e.g., `app/_layout.tsx` for Expo Router):
70
+
71
+ ```typescript
72
+ import { TeardownProvider } from '@teardown/react-native';
73
+ import { teardown } from '../lib/teardown';
74
+
75
+ export default function RootLayout() {
76
+ return (
77
+ <TeardownProvider core={teardown}>
78
+ <YourApp />
79
+ </TeardownProvider>
80
+ );
81
+ }
82
+ ```
83
+
84
+ For traditional React Native:
85
+
86
+ ```typescript
87
+ import { TeardownProvider } from '@teardown/react-native';
88
+ import { teardown } from './lib/teardown';
89
+
90
+ export default function App() {
91
+ return (
92
+ <TeardownProvider core={teardown}>
93
+ <YourNavigationStack />
94
+ </TeardownProvider>
95
+ );
96
+ }
97
+ ```
98
+
99
+ ### 3. Use the SDK in Your Components
100
+
101
+ ```typescript
102
+ import { useTeardown } from '@teardown/react-native';
103
+
104
+ function MyComponent() {
105
+ const { core } = useTeardown();
106
+
107
+ const handleLogin = async () => {
108
+ const result = await core.identity.identify({
109
+ user_id: 'user-123',
110
+ email: 'user@example.com',
111
+ name: 'John Doe',
112
+ });
113
+
114
+ if (result.success) {
115
+ console.log('User identified:', result.data);
116
+ }
117
+ };
118
+
119
+ return <Button onPress={handleLogin} title="Login" />;
120
+ }
121
+ ```
122
+
123
+ ## Configuration Options
124
+
125
+ ### TeardownCore Options
126
+
127
+ | Option | Type | Required | Description |
128
+ |--------|------|----------|-------------|
129
+ | `org_id` | string | Yes | Your organization ID from Teardown dashboard |
130
+ | `project_id` | string | Yes | Your project ID from Teardown dashboard |
131
+ | `api_key` | string | Yes | Your API key from Teardown dashboard |
132
+ | `storageFactory` | function | Yes | Storage adapter factory (e.g., MMKV) |
133
+ | `deviceAdapter` | object | Yes | Device info adapter (Expo or RN) |
134
+ | `forceUpdate` | object | No | Force update configuration |
135
+
136
+ ### Force Update Options
137
+
138
+ | Option | Type | Default | Description |
139
+ |--------|------|---------|-------------|
140
+ | `throttleMs` | number | 30000 | Minimum time between foreground checks (ms) |
141
+ | `checkCooldownMs` | number | 300000 | Minimum time since last successful check (ms) |
142
+
143
+ ## Next Steps
144
+
145
+ - [Core Concepts](./02-core-concepts.mdx) - Understand the architecture
146
+ - [Identity & Authentication](./03-identity.mdx) - Manage user sessions
147
+ - [Force Updates](./04-force-updates.mdx) - Handle version management
@@ -0,0 +1,188 @@
1
+ # Core Concepts
2
+
3
+ Understanding the architecture and design principles of the Teardown SDK.
4
+
5
+ ## Architecture Overview
6
+
7
+ The Teardown SDK is built around a central `TeardownCore` instance that manages several specialized clients:
8
+
9
+ ```
10
+ TeardownCore
11
+ ├── IdentityClient - User and device identity
12
+ ├── ForceUpdateClient - Version management
13
+ ├── DeviceClient - Device information
14
+ ├── StorageClient - Persistent storage
15
+ ├── LoggingClient - Structured logging
16
+ └── ApiClient - API communication
17
+ ```
18
+
19
+ ## Core Principles
20
+
21
+ ### 1. Single Source of Truth
22
+
23
+ The `TeardownCore` instance is your single entry point to all SDK functionality. It's initialized once and passed through your app via the `TeardownProvider`.
24
+
25
+ ```typescript
26
+ const teardown = new TeardownCore({...});
27
+
28
+ // Use throughout your app
29
+ <TeardownProvider core={teardown}>
30
+ <App />
31
+ </TeardownProvider>
32
+ ```
33
+
34
+ ### 2. Automatic Initialization
35
+
36
+ The SDK automatically initializes when the `TeardownProvider` mounts:
37
+
38
+ - Loads persisted session data
39
+ - Identifies the device
40
+ - Checks version status
41
+ - Subscribes to app lifecycle events
42
+
43
+ ### 3. Reactive State Management
44
+
45
+ All clients use event emitters to notify of state changes. React hooks automatically subscribe to these events:
46
+
47
+ ```typescript
48
+ // Hooks automatically subscribe and cleanup
49
+ const session = useSession();
50
+ const { versionStatus } = useForceUpdate();
51
+ ```
52
+
53
+ ### 4. Namespaced Storage
54
+
55
+ Each client gets its own namespaced storage to prevent key collisions:
56
+
57
+ ```typescript
58
+ // Storage is automatically namespaced
59
+ teardown:v1:identity:IDENTIFY_STATE
60
+ teardown:v1:device:deviceId
61
+ teardown:v1:version:VERSION_STATUS
62
+ ```
63
+
64
+ ## Client Responsibilities
65
+
66
+ ### IdentityClient
67
+
68
+ Manages device and user identity:
69
+
70
+ - Generates unique device IDs
71
+ - Tracks user sessions
72
+ - Persists authentication state
73
+ - Provides persona management (anonymous or identified users)
74
+
75
+ ### ForceUpdateClient
76
+
77
+ Handles version management:
78
+
79
+ - Checks app version against backend
80
+ - Monitors app state changes
81
+ - Throttles version checks
82
+ - Emits update status changes
83
+
84
+ ### DeviceClient
85
+
86
+ Collects device information:
87
+
88
+ - OS version and platform
89
+ - Device model and manufacturer
90
+ - App version and build number
91
+ - Uses platform adapters for consistency
92
+
93
+ ### StorageClient
94
+
95
+ Provides persistent storage:
96
+
97
+ - Namespaced key-value storage
98
+ - Platform-agnostic interface
99
+ - Support for multiple adapters (MMKV, AsyncStorage, etc.)
100
+ - Automatic cleanup on shutdown
101
+
102
+ ### LoggingClient
103
+
104
+ Structured logging system:
105
+
106
+ - Configurable log levels
107
+ - Named loggers for each client
108
+ - Console binding preservation
109
+ - Debug mode support
110
+
111
+ ### ApiClient
112
+
113
+ Handles API communication:
114
+
115
+ - Type-safe API client
116
+ - Automatic header injection
117
+ - Request/response logging
118
+ - Error handling
119
+
120
+ ## Lifecycle Management
121
+
122
+ ### Initialization
123
+
124
+ ```typescript
125
+ const teardown = new TeardownCore({...});
126
+ // Automatically initializes identity client
127
+ ```
128
+
129
+ ### Runtime
130
+
131
+ The SDK operates automatically:
132
+ - Listens for app state changes
133
+ - Checks version on foreground
134
+ - Persists state changes
135
+
136
+ ### Cleanup
137
+
138
+ ```typescript
139
+ // Automatic cleanup when provider unmounts
140
+ useEffect(() => {
141
+ return () => {
142
+ core.shutdown();
143
+ };
144
+ }, [core]);
145
+ ```
146
+
147
+ ## State Persistence
148
+
149
+ All critical state is automatically persisted:
150
+
151
+ ```typescript
152
+ // Identity state
153
+ { type: "identified", session: {...}, version_info: {...} }
154
+
155
+ // Version status
156
+ { type: "up_to_date" | "update_available" | "update_required" | ... }
157
+ ```
158
+
159
+ State is restored on app restart for seamless user experience.
160
+
161
+ ## Error Handling
162
+
163
+ The SDK uses `AsyncResult` pattern for predictable error handling:
164
+
165
+ ```typescript
166
+ const result = await core.identity.identify({...});
167
+
168
+ if (result.success) {
169
+ // Handle success
170
+ console.log(result.data);
171
+ } else {
172
+ // Handle error
173
+ console.error(result.error);
174
+ }
175
+ ```
176
+
177
+ ## Type Safety
178
+
179
+ Full TypeScript support with:
180
+ - Runtime validation using Zod schemas
181
+ - Discriminated unions for state types
182
+ - Exported types for all public APIs
183
+
184
+ ## Next Steps
185
+
186
+ - [Identity & Authentication](./03-identity.mdx)
187
+ - [Force Updates](./04-force-updates.mdx)
188
+ - [API Reference](./07-api-reference.mdx)