@teardown/react-native 2.0.23 → 2.0.27

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 (61) hide show
  1. package/docs/adapters/device/basic.mdx +59 -0
  2. package/docs/adapters/device/device-info.mdx +76 -0
  3. package/docs/adapters/device/expo.mdx +61 -0
  4. package/docs/adapters/device/index.mdx +102 -0
  5. package/docs/adapters/device/meta.json +4 -0
  6. package/docs/adapters/index.mdx +96 -0
  7. package/docs/adapters/meta.json +4 -0
  8. package/docs/adapters/notifications/expo.mdx +127 -0
  9. package/docs/adapters/notifications/firebase.mdx +142 -0
  10. package/docs/adapters/notifications/index.mdx +100 -0
  11. package/docs/adapters/notifications/meta.json +4 -0
  12. package/docs/adapters/notifications/wix.mdx +140 -0
  13. package/docs/adapters/storage/async-storage.mdx +95 -0
  14. package/docs/adapters/storage/index.mdx +93 -0
  15. package/docs/adapters/storage/meta.json +4 -0
  16. package/docs/adapters/storage/mmkv.mdx +86 -0
  17. package/docs/advanced.mdx +280 -0
  18. package/docs/api-reference.mdx +241 -0
  19. package/docs/core-concepts.mdx +158 -0
  20. package/docs/force-updates.mdx +185 -0
  21. package/docs/getting-started.mdx +156 -0
  22. package/docs/hooks-reference.mdx +232 -0
  23. package/docs/identity.mdx +171 -0
  24. package/docs/index.mdx +61 -0
  25. package/docs/logging.mdx +144 -0
  26. package/docs/meta.json +14 -0
  27. package/package.json +49 -31
  28. package/src/clients/api/index.ts +1 -1
  29. package/src/clients/device/adapters/basic.adapter.ts +57 -66
  30. package/src/clients/device/adapters/device-info.adapter.ts +21 -28
  31. package/src/clients/device/adapters/device.adpater-interface.ts +1 -8
  32. package/src/clients/device/adapters/expo.adapter.ts +33 -40
  33. package/src/clients/device/device.client.test.ts +20 -35
  34. package/src/clients/device/device.client.ts +0 -3
  35. package/src/clients/force-update/force-update.client.test.ts +69 -23
  36. package/src/clients/force-update/force-update.client.ts +42 -59
  37. package/src/clients/identity/identity.client.test.ts +22 -14
  38. package/src/clients/identity/identity.client.ts +1 -1
  39. package/src/clients/identity/index.ts +1 -1
  40. package/src/clients/logging/index.ts +1 -1
  41. package/src/clients/notifications/adapters/expo-notifications.adapter.ts +105 -0
  42. package/src/clients/notifications/adapters/firebase-messaging.adapter.ts +87 -0
  43. package/src/clients/notifications/adapters/notifications.adapter-interface.ts +112 -0
  44. package/src/clients/notifications/adapters/wix-notifications.adapter.ts +183 -0
  45. package/src/clients/notifications/index.ts +2 -0
  46. package/src/clients/notifications/notifications.client.ts +214 -3
  47. package/src/clients/storage/adapters/async-storage.adapter.ts +2 -6
  48. package/src/clients/storage/adapters/storage-adapters.test.ts +2 -7
  49. package/src/clients/storage/adapters/storage.adpater-interface.ts +1 -5
  50. package/src/clients/utils/index.ts +1 -1
  51. package/src/clients/utils/utils.client.ts +1 -1
  52. package/src/exports/adapters/async-storage.ts +1 -1
  53. package/src/exports/adapters/expo.ts +1 -1
  54. package/src/exports/expo.ts +2 -0
  55. package/src/exports/firebase.ts +1 -0
  56. package/src/exports/index.ts +6 -9
  57. package/src/exports/wix.ts +1 -0
  58. package/src/hooks/use-force-update.ts +31 -34
  59. package/src/index.ts +1 -0
  60. package/src/teardown.core.ts +0 -2
  61. package/src/.DS_Store +0 -0
@@ -0,0 +1,100 @@
1
+ ---
2
+ title: Notification Adapters
3
+ description: Push notification adapters for token registration and management.
4
+ icon: Bell
5
+ ---
6
+
7
+ Notification adapters handle push notification token registration and management with your push notification provider.
8
+
9
+ ## Available Adapters
10
+
11
+ | Adapter | Package | Best For |
12
+ |---------|---------|----------|
13
+ | [`ExpoNotificationsAdapter`](/docs/react-native/adapters/notifications/expo) | `expo-notifications` | Expo projects |
14
+ | [`FirebaseMessagingAdapter`](/docs/react-native/adapters/notifications/firebase) | `@react-native-firebase/messaging` | Firebase Cloud Messaging |
15
+ | [`WixNotificationsAdapter`](/docs/react-native/adapters/notifications/wix) | `react-native-notifications` | Wix notifications library |
16
+
17
+ ## Usage
18
+
19
+ Notification adapters are optional and used separately from the core SDK:
20
+
21
+ ```typescript
22
+ import { ExpoNotificationsAdapter } from '@teardown/react-native/expo-notifications';
23
+
24
+ const notificationsAdapter = new ExpoNotificationsAdapter();
25
+
26
+ // Get push token
27
+ const token = await notificationsAdapter.getToken();
28
+
29
+ // Register token with your backend
30
+ await registerPushToken(token);
31
+ ```
32
+
33
+ ## Adapter Interface
34
+
35
+ All notification adapters implement:
36
+
37
+ ```typescript
38
+ interface NotificationsAdapter {
39
+ /** Get the push notification token */
40
+ getToken(): Promise<string | null>;
41
+
42
+ /** Request notification permissions */
43
+ requestPermissions(): Promise<boolean>;
44
+
45
+ /** Check if notifications are enabled */
46
+ isEnabled(): Promise<boolean>;
47
+
48
+ /** Subscribe to incoming notifications */
49
+ onNotification(handler: (notification: Notification) => void): () => void;
50
+
51
+ /** Subscribe to notification responses (user taps) */
52
+ onNotificationResponse(handler: (response: NotificationResponse) => void): () => void;
53
+ }
54
+ ```
55
+
56
+ ## Choosing an Adapter
57
+
58
+ | If you're using... | Use this adapter |
59
+ |-------------------|------------------|
60
+ | Expo with expo-notifications | `ExpoNotificationsAdapter` |
61
+ | Firebase Cloud Messaging | `FirebaseMessagingAdapter` |
62
+ | Wix react-native-notifications | `WixNotificationsAdapter` |
63
+ | Other push library | Implement custom adapter |
64
+
65
+ ## Custom Adapter
66
+
67
+ Implement the `NotificationsAdapter` interface:
68
+
69
+ ```typescript
70
+ import type { NotificationsAdapter, Notification, NotificationResponse } from '@teardown/react-native';
71
+
72
+ class CustomNotificationsAdapter implements NotificationsAdapter {
73
+ async getToken(): Promise<string | null> {
74
+ // Return push token from your notification library
75
+ return await myNotificationLib.getToken();
76
+ }
77
+
78
+ async requestPermissions(): Promise<boolean> {
79
+ // Request notification permissions
80
+ return await myNotificationLib.requestPermission();
81
+ }
82
+
83
+ async isEnabled(): Promise<boolean> {
84
+ // Check if notifications are enabled
85
+ return await myNotificationLib.areNotificationsEnabled();
86
+ }
87
+
88
+ onNotification(handler: (notification: Notification) => void): () => void {
89
+ // Subscribe to incoming notifications
90
+ const subscription = myNotificationLib.onNotification(handler);
91
+ return () => subscription.remove();
92
+ }
93
+
94
+ onNotificationResponse(handler: (response: NotificationResponse) => void): () => void {
95
+ // Subscribe to notification taps
96
+ const subscription = myNotificationLib.onNotificationOpened(handler);
97
+ return () => subscription.remove();
98
+ }
99
+ }
100
+ ```
@@ -0,0 +1,4 @@
1
+ {
2
+ "title": "Notifications",
3
+ "pages": ["expo", "firebase", "wix"]
4
+ }
@@ -0,0 +1,140 @@
1
+ ---
2
+ title: WixNotificationsAdapter
3
+ description: Notification adapter for Wix react-native-notifications library.
4
+ ---
5
+
6
+ The `WixNotificationsAdapter` integrates with Wix's react-native-notifications library.
7
+
8
+ ## Installation
9
+
10
+ ```bash
11
+ npm install react-native-notifications
12
+ # or
13
+ bun add react-native-notifications
14
+ ```
15
+
16
+ For iOS:
17
+ ```bash
18
+ cd ios && pod install
19
+ ```
20
+
21
+ ## Usage
22
+
23
+ ```typescript
24
+ import { WixNotificationsAdapter } from '@teardown/react-native/wix-notifications';
25
+
26
+ const notifications = new WixNotificationsAdapter();
27
+
28
+ // Request permissions
29
+ const granted = await notifications.requestPermissions();
30
+
31
+ if (granted) {
32
+ // Get push token
33
+ const token = await notifications.getToken();
34
+ console.log('Push token:', token);
35
+ }
36
+ ```
37
+
38
+ ## Import Path
39
+
40
+ ```typescript
41
+ import { WixNotificationsAdapter } from '@teardown/react-native/wix-notifications';
42
+ ```
43
+
44
+ ## API
45
+
46
+ ### getToken()
47
+
48
+ Get the device push token:
49
+
50
+ ```typescript
51
+ const token = await notifications.getToken();
52
+ // Returns: device token string or null
53
+ ```
54
+
55
+ ### requestPermissions()
56
+
57
+ Request notification permissions:
58
+
59
+ ```typescript
60
+ const granted = await notifications.requestPermissions();
61
+ // Returns: true if granted, false otherwise
62
+ ```
63
+
64
+ ### isEnabled()
65
+
66
+ Check if notifications are enabled:
67
+
68
+ ```typescript
69
+ const enabled = await notifications.isEnabled();
70
+ ```
71
+
72
+ ### onNotification()
73
+
74
+ Subscribe to incoming notifications:
75
+
76
+ ```typescript
77
+ const unsubscribe = notifications.onNotification((notification) => {
78
+ console.log('Received:', notification.title);
79
+ });
80
+
81
+ // Cleanup
82
+ unsubscribe();
83
+ ```
84
+
85
+ ### onNotificationResponse()
86
+
87
+ Subscribe to notification opens:
88
+
89
+ ```typescript
90
+ const unsubscribe = notifications.onNotificationResponse((response) => {
91
+ console.log('User tapped:', response.notification.title);
92
+ });
93
+
94
+ // Cleanup
95
+ unsubscribe();
96
+ ```
97
+
98
+ ## Configuration
99
+
100
+ ### iOS
101
+
102
+ 1. Enable Push Notifications capability in Xcode
103
+ 2. Add to `AppDelegate.m`:
104
+
105
+ ```objc
106
+ #import <RNNotifications.h>
107
+
108
+ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
109
+ [RNNotifications startMonitorNotifications];
110
+ return YES;
111
+ }
112
+
113
+ - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
114
+ [RNNotifications didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
115
+ }
116
+
117
+ - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
118
+ [RNNotifications didFailToRegisterForRemoteNotificationsWithError:error];
119
+ }
120
+ ```
121
+
122
+ ### Android
123
+
124
+ 1. Add Firebase configuration (google-services.json)
125
+ 2. Initialize in `MainApplication.java`:
126
+
127
+ ```java
128
+ import com.wix.reactnativenotifications.RNNotificationsPackage;
129
+ ```
130
+
131
+ ## When to Use
132
+
133
+ - Existing projects using react-native-notifications
134
+ - Projects requiring fine-grained notification control
135
+ - Cross-platform notification handling
136
+
137
+ ## Requirements
138
+
139
+ - `react-native-notifications` >= 4.0.0
140
+ - React Native >= 0.60
@@ -0,0 +1,95 @@
1
+ ---
2
+ title: AsyncStorageAdapter
3
+ description: Storage adapter using @react-native-async-storage/async-storage.
4
+ ---
5
+
6
+ The `AsyncStorageAdapter` uses the community AsyncStorage library for persistent storage with broad platform compatibility.
7
+
8
+ ## Installation
9
+
10
+ ```bash
11
+ npm install @react-native-async-storage/async-storage
12
+ # or
13
+ bun add @react-native-async-storage/async-storage
14
+ ```
15
+
16
+ For Expo:
17
+ ```bash
18
+ npx expo install @react-native-async-storage/async-storage
19
+ ```
20
+
21
+ ## Usage
22
+
23
+ ```typescript
24
+ import { TeardownCore } from '@teardown/react-native';
25
+ import { DeviceInfoAdapter } from '@teardown/react-native/adapters/device-info';
26
+ import { AsyncStorageAdapter } from '@teardown/react-native/adapters/async-storage';
27
+
28
+ export const teardown = new TeardownCore({
29
+ org_id: 'your-org-id',
30
+ project_id: 'your-project-id',
31
+ api_key: 'your-api-key',
32
+ storageAdapter: new AsyncStorageAdapter(),
33
+ deviceAdapter: new DeviceInfoAdapter(),
34
+ });
35
+ ```
36
+
37
+ ## Import Path
38
+
39
+ ```typescript
40
+ import { AsyncStorageAdapter } from '@teardown/react-native/adapters/async-storage';
41
+ ```
42
+
43
+ ## When to Use
44
+
45
+ - Web support needed
46
+ - Existing AsyncStorage setup in your app
47
+ - Simpler debugging (plain text storage)
48
+ - Expo Go compatibility (no dev build needed)
49
+
50
+ ## Trade-offs
51
+
52
+ ### Pros
53
+ - Broader platform support (iOS, Android, Web)
54
+ - Works in Expo Go without dev build
55
+ - Plain text storage (easier debugging)
56
+ - Well-established, stable API
57
+
58
+ ### Cons
59
+ - Asynchronous API (slightly slower)
60
+ - No built-in encryption
61
+ - Larger bundle size than MMKV
62
+
63
+ ## How It Works
64
+
65
+ AsyncStorage provides a key-value storage API:
66
+
67
+ 1. The adapter wraps AsyncStorage with a synchronous-like interface
68
+ 2. Uses `preload()` to hydrate data into memory at startup
69
+ 3. Writes are persisted asynchronously
70
+
71
+ ## Requirements
72
+
73
+ - `@react-native-async-storage/async-storage` >= 1.17.0
74
+ - React Native >= 0.60
75
+
76
+ ## Platform Notes
77
+
78
+ ### iOS
79
+ - Data stored in NSUserDefaults (small data) or files (large data)
80
+ - Not encrypted by default
81
+
82
+ ### Android
83
+ - Data stored in SQLite database
84
+ - Not encrypted by default
85
+
86
+ ### Web
87
+ - Uses localStorage
88
+ - Size limited (~5MB)
89
+
90
+ ## Encryption Note
91
+
92
+ AsyncStorage does not encrypt data by default. For sensitive data, consider:
93
+ - Using MMKV instead (encrypted by default)
94
+ - Encrypting values before storage
95
+ - Using a separate encrypted storage for secrets
@@ -0,0 +1,93 @@
1
+ ---
2
+ title: Storage Adapters
3
+ description: Persistent storage adapters for sessions, device IDs, and version status.
4
+ icon: Database
5
+ ---
6
+
7
+ Storage adapters handle persistent data storage for the SDK. You must provide a storage adapter when initializing `TeardownCore`.
8
+
9
+ ## Available Adapters
10
+
11
+ | Adapter | Package | Sync/Async | Best For |
12
+ |---------|---------|-----------|----------|
13
+ | [`MMKVStorageAdapter`](/docs/react-native/adapters/storage/mmkv) | `react-native-mmkv` | Sync | Performance (recommended) |
14
+ | [`AsyncStorageAdapter`](/docs/react-native/adapters/storage/async-storage) | `@react-native-async-storage/async-storage` | Async | Compatibility |
15
+
16
+ ## Storage Interface
17
+
18
+ All storage adapters implement:
19
+
20
+ ```typescript
21
+ interface SupportedStorage {
22
+ preload(): void;
23
+ getItem(key: string): string | null;
24
+ setItem(key: string, value: string): void;
25
+ removeItem(key: string): void;
26
+ clear(): void;
27
+ keys(): string[];
28
+ }
29
+ ```
30
+
31
+ ## What Gets Stored
32
+
33
+ The SDK stores:
34
+
35
+ | Data | Storage Key | Description |
36
+ |------|-------------|-------------|
37
+ | Identity State | `identity:IDENTIFY_STATE` | Session, user ID, token |
38
+ | Version Status | `version:version_status` | Last known update status |
39
+ | Device ID | `device:device_id` | Stable device UUID |
40
+
41
+ ## Namespacing
42
+
43
+ Keys are prefixed with org/project IDs to prevent conflicts:
44
+
45
+ ```
46
+ teardown:{org_id}:{project_id}:identity:IDENTIFY_STATE
47
+ teardown:{org_id}:{project_id}:version:version_status
48
+ teardown:{org_id}:{project_id}:device:device_id
49
+ ```
50
+
51
+ ## Custom Adapter
52
+
53
+ Extend `StorageAdapter` for custom implementations:
54
+
55
+ ```typescript
56
+ import { StorageAdapter, type SupportedStorage } from '@teardown/react-native';
57
+
58
+ class CustomStorageAdapter extends StorageAdapter {
59
+ createStorage(storageKey: string): SupportedStorage {
60
+ return {
61
+ preload: () => {
62
+ // Load data into memory (called on init)
63
+ },
64
+ getItem: (key: string) => {
65
+ return myStorage.get(`${storageKey}:${key}`);
66
+ },
67
+ setItem: (key: string, value: string) => {
68
+ myStorage.set(`${storageKey}:${key}`, value);
69
+ },
70
+ removeItem: (key: string) => {
71
+ myStorage.delete(`${storageKey}:${key}`);
72
+ },
73
+ clear: () => {
74
+ // Clear all keys for this namespace
75
+ },
76
+ keys: () => {
77
+ // Return all keys for this namespace
78
+ return [];
79
+ },
80
+ };
81
+ }
82
+ }
83
+ ```
84
+
85
+ ## Comparison
86
+
87
+ | Feature | MMKV | AsyncStorage |
88
+ |---------|------|--------------|
89
+ | Speed | Faster (sync) | Slower (async) |
90
+ | Encryption | Built-in | No |
91
+ | Bundle Size | Smaller | Larger |
92
+ | Debugging | Binary data | Plain text |
93
+ | Platform Support | iOS, Android | iOS, Android, Web |
@@ -0,0 +1,4 @@
1
+ {
2
+ "title": "Storage",
3
+ "pages": ["mmkv", "async-storage"]
4
+ }
@@ -0,0 +1,86 @@
1
+ ---
2
+ title: MMKVStorageAdapter
3
+ description: Fast, encrypted storage adapter using react-native-mmkv.
4
+ ---
5
+
6
+ The `MMKVStorageAdapter` uses MMKV for high-performance, encrypted storage. **Recommended for most apps.**
7
+
8
+ ## Installation
9
+
10
+ ```bash
11
+ npm install react-native-mmkv
12
+ # or
13
+ bun add react-native-mmkv
14
+ ```
15
+
16
+ For iOS, run pod install:
17
+ ```bash
18
+ cd ios && pod install
19
+ ```
20
+
21
+ ## Usage
22
+
23
+ ```typescript
24
+ import { TeardownCore } from '@teardown/react-native';
25
+ import { ExpoDeviceAdapter } from '@teardown/react-native/adapters/expo';
26
+ import { MMKVStorageAdapter } from '@teardown/react-native/adapters/mmkv';
27
+
28
+ export const teardown = new TeardownCore({
29
+ org_id: 'your-org-id',
30
+ project_id: 'your-project-id',
31
+ api_key: 'your-api-key',
32
+ storageAdapter: new MMKVStorageAdapter(),
33
+ deviceAdapter: new ExpoDeviceAdapter(),
34
+ });
35
+ ```
36
+
37
+ ## Import Path
38
+
39
+ ```typescript
40
+ import { MMKVStorageAdapter } from '@teardown/react-native/adapters/mmkv';
41
+ ```
42
+
43
+ ## Benefits
44
+
45
+ - **Synchronous** - No async/await needed for reads/writes
46
+ - **Encrypted** - Data encrypted by default
47
+ - **Fast** - Memory-mapped for optimal performance
48
+ - **Small** - Minimal bundle size impact
49
+ - **Reliable** - Used by WeChat with 1B+ users
50
+
51
+ ## How It Works
52
+
53
+ MMKV uses memory-mapped files for storage:
54
+
55
+ 1. Data is written to memory
56
+ 2. OS flushes to disk asynchronously
57
+ 3. Reads are instant (from memory)
58
+ 4. Crash-safe with journaling
59
+
60
+ ## Requirements
61
+
62
+ - `react-native-mmkv` >= 2.0.0
63
+ - React Native >= 0.71
64
+
65
+ ## Platform Notes
66
+
67
+ ### iOS
68
+ - Requires `pod install`
69
+ - Data stored in app's sandboxed Documents directory
70
+ - Encrypted with iOS Keychain
71
+
72
+ ### Android
73
+ - Works out of the box
74
+ - Data stored in app's private directory
75
+ - Encrypted with Android KeyStore
76
+
77
+ ## Expo Compatibility
78
+
79
+ For Expo managed workflow, you need a development build:
80
+
81
+ ```bash
82
+ npx expo install react-native-mmkv
83
+ npx expo prebuild
84
+ ```
85
+
86
+ Or use EAS Build for production.