@teardown/react-native 2.0.4 → 2.0.10
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 +104 -34
- package/package.json +18 -9
- package/src/clients/api/api.client.ts +1 -1
- package/src/clients/device/adapters/device-info.adapter.ts +36 -0
- package/src/clients/device/adapters/device.adpater-interface.ts +23 -0
- package/src/clients/device/adapters/expo.adapter.ts +2 -36
- package/src/clients/force-update/force-update.client.test.ts +7 -7
- package/src/clients/force-update/force-update.client.ts +30 -6
- package/src/clients/identity/identity.client.test.ts +20 -20
- package/src/clients/identity/identity.client.ts +5 -6
- package/src/clients/storage/adapters/async-storage.adapter.ts +18 -20
- package/src/clients/storage/adapters/storage.adpater-interface.ts +1 -1
- package/src/clients/storage/storage.client.ts +17 -1
- package/src/exports/adapters/device-info.ts +1 -0
- package/src/teardown.core.ts +3 -1
- package/docs/01-getting-started.mdx +0 -147
- package/docs/02-core-concepts.mdx +0 -188
- package/docs/03-identity.mdx +0 -301
- package/docs/04-force-updates.mdx +0 -339
- package/docs/05-device-info.mdx +0 -324
- package/docs/06-logging.mdx +0 -345
- package/docs/06-storage.mdx +0 -349
- package/docs/07-api-reference.mdx +0 -472
- package/docs/07-logging.mdx +0 -345
- package/docs/08-api-reference.mdx +0 -472
- package/docs/08-hooks-reference.mdx +0 -476
- package/docs/09-advanced.mdx +0 -563
- package/docs/09-hooks-reference.mdx +0 -476
- package/docs/10-advanced.mdx +0 -563
package/docs/07-logging.mdx
DELETED
|
@@ -1,345 +0,0 @@
|
|
|
1
|
-
# Logging
|
|
2
|
-
|
|
3
|
-
Structured logging system with configurable log levels.
|
|
4
|
-
|
|
5
|
-
## Overview
|
|
6
|
-
|
|
7
|
-
The LoggingClient provides:
|
|
8
|
-
- Configurable log levels
|
|
9
|
-
- Named loggers for each client
|
|
10
|
-
- Console binding preservation
|
|
11
|
-
- Debug mode support
|
|
12
|
-
|
|
13
|
-
## Log Levels
|
|
14
|
-
|
|
15
|
-
```typescript
|
|
16
|
-
type LogLevel =
|
|
17
|
-
| "none" // No logging
|
|
18
|
-
| "error" // Only errors
|
|
19
|
-
| "warn" // Errors and warnings
|
|
20
|
-
| "info" // Errors, warnings, and info
|
|
21
|
-
| "verbose" // Everything including debug
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
### Level Priority
|
|
25
|
-
|
|
26
|
-
```
|
|
27
|
-
none < error < warn < info < verbose
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
When you set a level, all lower-priority levels are also shown:
|
|
31
|
-
- `error`: Shows only errors
|
|
32
|
-
- `warn`: Shows errors + warnings
|
|
33
|
-
- `info`: Shows errors + warnings + info
|
|
34
|
-
- `verbose`: Shows everything (errors + warnings + info + debug)
|
|
35
|
-
|
|
36
|
-
## Setting Log Level
|
|
37
|
-
|
|
38
|
-
### On Initialization
|
|
39
|
-
|
|
40
|
-
```typescript
|
|
41
|
-
const teardown = new TeardownCore({
|
|
42
|
-
// ... other options
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
// Set log level after initialization
|
|
46
|
-
teardown.setLogLevel('verbose');
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
### During Runtime
|
|
50
|
-
|
|
51
|
-
```typescript
|
|
52
|
-
import { useTeardown } from '@teardown/react-native';
|
|
53
|
-
|
|
54
|
-
function DebugPanel() {
|
|
55
|
-
const { core } = useTeardown();
|
|
56
|
-
|
|
57
|
-
const enableDebugMode = () => {
|
|
58
|
-
core.setLogLevel('verbose');
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
const disableLogging = () => {
|
|
62
|
-
core.setLogLevel('none');
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
return (
|
|
66
|
-
<View>
|
|
67
|
-
<Button title="Enable Debug" onPress={enableDebugMode} />
|
|
68
|
-
<Button title="Disable Logs" onPress={disableLogging} />
|
|
69
|
-
</View>
|
|
70
|
-
);
|
|
71
|
-
}
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
## Log Output Format
|
|
75
|
-
|
|
76
|
-
All logs are prefixed with the client name:
|
|
77
|
-
|
|
78
|
-
```
|
|
79
|
-
[Teardown:TeardownCore] Shutting down TeardownCore
|
|
80
|
-
[Teardown:IdentityClient] Identify state: unidentified -> identifying
|
|
81
|
-
[Teardown:IdentityClient] Identify state: identifying -> identified
|
|
82
|
-
[Teardown:ForceUpdateClient] Version status changing: initializing -> checking
|
|
83
|
-
[Teardown:ForceUpdateClient] Checking version status on foreground
|
|
84
|
-
[Teardown:DeviceClient] Getting device ID
|
|
85
|
-
[Teardown:StorageClient] Creating storage for teardown:v1:identity
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
## Logger Methods
|
|
89
|
-
|
|
90
|
-
Each client has a logger with these methods:
|
|
91
|
-
|
|
92
|
-
```typescript
|
|
93
|
-
logger.info(message, ...args) // Info level
|
|
94
|
-
logger.warn(message, ...args) // Warning level
|
|
95
|
-
logger.error(message, ...args) // Error level
|
|
96
|
-
logger.debug(message, ...args) // Debug level (verbose)
|
|
97
|
-
logger.trace(message, ...args) // Stack trace (verbose)
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
## Internal Logging
|
|
101
|
-
|
|
102
|
-
The SDK logs these events:
|
|
103
|
-
|
|
104
|
-
### TeardownCore
|
|
105
|
-
|
|
106
|
-
```typescript
|
|
107
|
-
[Teardown:TeardownCore] Error initializing TeardownCore { error }
|
|
108
|
-
[Teardown:TeardownCore] Shutting down TeardownCore
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
### IdentityClient
|
|
112
|
-
|
|
113
|
-
```typescript
|
|
114
|
-
[Teardown:IdentityClient] Identify state: unidentified -> identifying
|
|
115
|
-
[Teardown:IdentityClient] Identify state: identifying -> identified
|
|
116
|
-
[Teardown:IdentityClient] 422 Error identifying user { ... }
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
### ForceUpdateClient
|
|
120
|
-
|
|
121
|
-
```typescript
|
|
122
|
-
[Teardown:ForceUpdateClient] Version status changing: initializing -> up_to_date
|
|
123
|
-
[Teardown:ForceUpdateClient] Checking version status on foreground
|
|
124
|
-
[Teardown:ForceUpdateClient] Skipping version check - not identified
|
|
125
|
-
```
|
|
126
|
-
|
|
127
|
-
### DeviceClient
|
|
128
|
-
|
|
129
|
-
```typescript
|
|
130
|
-
[Teardown:DeviceClient] Getting device ID
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
### StorageClient
|
|
134
|
-
|
|
135
|
-
```typescript
|
|
136
|
-
[Teardown:StorageClient] Creating storage for teardown:v1:identity
|
|
137
|
-
[Teardown:StorageClient] Storage already exists for teardown:v1:identity
|
|
138
|
-
[Teardown:StorageClient] Returning existing storage for teardown:v1:identity
|
|
139
|
-
[Teardown:StorageClient] Clearing storage for teardown:v1:identity
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
## Console Binding
|
|
143
|
-
|
|
144
|
-
The logger preserves console call sites for better debugging:
|
|
145
|
-
|
|
146
|
-
```typescript
|
|
147
|
-
// Bound console methods preserve original call site
|
|
148
|
-
private boundConsole = {
|
|
149
|
-
log: console.log.bind(console),
|
|
150
|
-
error: console.error.bind(console),
|
|
151
|
-
debug: console.debug.bind(console),
|
|
152
|
-
warn: console.warn.bind(console),
|
|
153
|
-
trace: console.trace.bind(console),
|
|
154
|
-
};
|
|
155
|
-
```
|
|
156
|
-
|
|
157
|
-
This means clicking log messages in DevTools takes you to the original SDK code, not the logger wrapper.
|
|
158
|
-
|
|
159
|
-
## Creating Custom Loggers
|
|
160
|
-
|
|
161
|
-
While not typically needed, you can create custom loggers:
|
|
162
|
-
|
|
163
|
-
```typescript
|
|
164
|
-
import { LoggingClient } from '@teardown/react-native';
|
|
165
|
-
|
|
166
|
-
const logging = new LoggingClient({ logLevel: 'info' });
|
|
167
|
-
const logger = logging.createLogger({ name: 'MyFeature' });
|
|
168
|
-
|
|
169
|
-
logger.info('Feature initialized');
|
|
170
|
-
logger.error('Something went wrong');
|
|
171
|
-
```
|
|
172
|
-
|
|
173
|
-
## Conditional Logging
|
|
174
|
-
|
|
175
|
-
The SDK checks log level before logging:
|
|
176
|
-
|
|
177
|
-
```typescript
|
|
178
|
-
// Only logs if current level >= info
|
|
179
|
-
if (this.loggingClient.shouldLog('info')) {
|
|
180
|
-
logger.info('Message');
|
|
181
|
-
}
|
|
182
|
-
```
|
|
183
|
-
|
|
184
|
-
This prevents unnecessary string concatenation and formatting in production.
|
|
185
|
-
|
|
186
|
-
## Best Practices
|
|
187
|
-
|
|
188
|
-
### 1. Use 'none' in Production
|
|
189
|
-
|
|
190
|
-
```typescript
|
|
191
|
-
// ✅ Good - no logs in production
|
|
192
|
-
const logLevel = __DEV__ ? 'verbose' : 'none';
|
|
193
|
-
teardown.setLogLevel(logLevel);
|
|
194
|
-
```
|
|
195
|
-
|
|
196
|
-
### 2. Use 'verbose' for Debugging
|
|
197
|
-
|
|
198
|
-
```typescript
|
|
199
|
-
// ✅ Good - detailed logs during development
|
|
200
|
-
if (__DEV__) {
|
|
201
|
-
teardown.setLogLevel('verbose');
|
|
202
|
-
}
|
|
203
|
-
```
|
|
204
|
-
|
|
205
|
-
### 3. Enable Logging for Support
|
|
206
|
-
|
|
207
|
-
```typescript
|
|
208
|
-
// ✅ Good - user can enable logs for support
|
|
209
|
-
function Settings() {
|
|
210
|
-
const { core } = useTeardown();
|
|
211
|
-
const [debugMode, setDebugMode] = useState(false);
|
|
212
|
-
|
|
213
|
-
const toggleDebug = () => {
|
|
214
|
-
const newMode = !debugMode;
|
|
215
|
-
setDebugMode(newMode);
|
|
216
|
-
core.setLogLevel(newMode ? 'verbose' : 'none');
|
|
217
|
-
};
|
|
218
|
-
|
|
219
|
-
return <Switch value={debugMode} onValueChange={toggleDebug} />;
|
|
220
|
-
}
|
|
221
|
-
```
|
|
222
|
-
|
|
223
|
-
### 4. Don't Rely on Logs for Logic
|
|
224
|
-
|
|
225
|
-
```typescript
|
|
226
|
-
// ❌ Bad - logs may be disabled
|
|
227
|
-
logger.info('User identified');
|
|
228
|
-
// ... rely on this log
|
|
229
|
-
|
|
230
|
-
// ✅ Good - use state/events
|
|
231
|
-
const result = await identify();
|
|
232
|
-
if (result.success) {
|
|
233
|
-
// ... use result, not logs
|
|
234
|
-
}
|
|
235
|
-
```
|
|
236
|
-
|
|
237
|
-
## Log Level Examples
|
|
238
|
-
|
|
239
|
-
### Development
|
|
240
|
-
|
|
241
|
-
```typescript
|
|
242
|
-
// See everything
|
|
243
|
-
teardown.setLogLevel('verbose');
|
|
244
|
-
|
|
245
|
-
// Output:
|
|
246
|
-
// [Teardown:IdentityClient] Getting device ID
|
|
247
|
-
// [Teardown:IdentityClient] Identify state: unidentified -> identifying
|
|
248
|
-
// [Teardown:StorageClient] Creating storage for teardown:v1:identity
|
|
249
|
-
// etc.
|
|
250
|
-
```
|
|
251
|
-
|
|
252
|
-
### Debugging Issues
|
|
253
|
-
|
|
254
|
-
```typescript
|
|
255
|
-
// See important events
|
|
256
|
-
teardown.setLogLevel('info');
|
|
257
|
-
|
|
258
|
-
// Output:
|
|
259
|
-
// [Teardown:IdentityClient] Identify state: unidentified -> identifying
|
|
260
|
-
// [Teardown:ForceUpdateClient] Version status changing: initializing -> up_to_date
|
|
261
|
-
```
|
|
262
|
-
|
|
263
|
-
### Production
|
|
264
|
-
|
|
265
|
-
```typescript
|
|
266
|
-
// See only errors
|
|
267
|
-
teardown.setLogLevel('error');
|
|
268
|
-
|
|
269
|
-
// Output:
|
|
270
|
-
// [Teardown:TeardownCore] Error initializing TeardownCore { error }
|
|
271
|
-
// [Teardown:IdentityClient] 422 Error identifying user { ... }
|
|
272
|
-
```
|
|
273
|
-
|
|
274
|
-
### Disabled
|
|
275
|
-
|
|
276
|
-
```typescript
|
|
277
|
-
// No logs
|
|
278
|
-
teardown.setLogLevel('none');
|
|
279
|
-
|
|
280
|
-
// Output:
|
|
281
|
-
// (nothing)
|
|
282
|
-
```
|
|
283
|
-
|
|
284
|
-
## Environment-Based Configuration
|
|
285
|
-
|
|
286
|
-
```typescript
|
|
287
|
-
const LOG_LEVEL: LogLevel =
|
|
288
|
-
process.env.NODE_ENV === 'development' ? 'verbose' :
|
|
289
|
-
process.env.NODE_ENV === 'staging' ? 'info' :
|
|
290
|
-
'error';
|
|
291
|
-
|
|
292
|
-
teardown.setLogLevel(LOG_LEVEL);
|
|
293
|
-
```
|
|
294
|
-
|
|
295
|
-
## Debugging Tips
|
|
296
|
-
|
|
297
|
-
### 1. Enable Verbose Logging
|
|
298
|
-
|
|
299
|
-
```typescript
|
|
300
|
-
teardown.setLogLevel('verbose');
|
|
301
|
-
```
|
|
302
|
-
|
|
303
|
-
### 2. Filter by Client
|
|
304
|
-
|
|
305
|
-
Search DevTools console for specific client:
|
|
306
|
-
```
|
|
307
|
-
[Teardown:IdentityClient]
|
|
308
|
-
```
|
|
309
|
-
|
|
310
|
-
### 3. Track State Transitions
|
|
311
|
-
|
|
312
|
-
Look for state change logs:
|
|
313
|
-
```
|
|
314
|
-
Identify state: unidentified -> identifying
|
|
315
|
-
Version status changing: checking -> up_to_date
|
|
316
|
-
```
|
|
317
|
-
|
|
318
|
-
### 4. Check Error Details
|
|
319
|
-
|
|
320
|
-
Errors include full context:
|
|
321
|
-
```typescript
|
|
322
|
-
logger.error('Error initializing', { error, context });
|
|
323
|
-
```
|
|
324
|
-
|
|
325
|
-
## Performance
|
|
326
|
-
|
|
327
|
-
Logging is optimized for production:
|
|
328
|
-
|
|
329
|
-
```typescript
|
|
330
|
-
// ✅ Good - check happens before string operations
|
|
331
|
-
if (this.shouldLog('verbose')) {
|
|
332
|
-
logger.debug(`Expensive operation: ${JSON.stringify(bigObject)}`);
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
// ❌ Bad - string created even if logging disabled
|
|
336
|
-
logger.debug(`Expensive operation: ${JSON.stringify(bigObject)}`);
|
|
337
|
-
```
|
|
338
|
-
|
|
339
|
-
The SDK uses the first pattern internally.
|
|
340
|
-
|
|
341
|
-
## Next Steps
|
|
342
|
-
|
|
343
|
-
- [API Reference](./07-api-reference.mdx)
|
|
344
|
-
- [Hooks Reference](./08-hooks-reference.mdx)
|
|
345
|
-
- [Advanced Usage](./09-advanced.mdx)
|