@teardown/react-native 2.0.0 → 2.0.2

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 (41) hide show
  1. package/README.md +33 -19
  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 +46 -18
  17. package/src/clients/api/api.client.ts +29 -4
  18. package/src/clients/device/{expo-adapter.ts → adapters/basic.adapter.ts} +2 -40
  19. package/src/clients/device/{device.adpater-interface.ts → adapters/device.adpater-interface.ts} +1 -1
  20. package/src/clients/device/adapters/expo.adapter.ts +90 -0
  21. package/src/clients/device/device.client.test.ts +1 -6
  22. package/src/clients/device/device.client.ts +5 -1
  23. package/src/clients/device/index.ts +1 -1
  24. package/src/clients/force-update/force-update.client.test.ts +244 -13
  25. package/src/clients/force-update/force-update.client.ts +71 -11
  26. package/src/clients/identity/identity.client.test.ts +888 -223
  27. package/src/clients/identity/identity.client.ts +59 -14
  28. package/src/clients/storage/adapters/async-storage.adapter.ts +81 -0
  29. package/src/clients/storage/{mmkv-adapter.ts → adapters/mmkv.adapter.ts} +7 -10
  30. package/src/clients/storage/adapters/storage.adpater-interface.ts +30 -0
  31. package/src/clients/storage/index.ts +2 -1
  32. package/src/clients/storage/storage.client.ts +9 -20
  33. package/src/clients/utils/utils.client.ts +1 -57
  34. package/src/exports/adapters/async-storage.ts +1 -0
  35. package/src/exports/adapters/expo.ts +1 -0
  36. package/src/exports/adapters/mmkv.ts +1 -0
  37. package/src/hooks/use-force-update.ts +12 -3
  38. package/src/hooks/use-session.ts +7 -4
  39. package/src/teardown.core.ts +16 -6
  40. package/src/exports/expo.ts +0 -1
  41. package/src/exports/mmkv.ts +0 -1
@@ -0,0 +1,472 @@
1
+ # API Reference
2
+
3
+ Complete API documentation for the Teardown SDK.
4
+
5
+ ## TeardownCore
6
+
7
+ Main SDK class.
8
+
9
+ ### Constructor
10
+
11
+ ```typescript
12
+ new TeardownCore(options: TeardownCoreOptions)
13
+ ```
14
+
15
+ #### Options
16
+
17
+ ```typescript
18
+ type TeardownCoreOptions = {
19
+ org_id: string;
20
+ project_id: string;
21
+ api_key: string;
22
+ storageFactory: SupportedStorageFactory;
23
+ deviceAdapter: DeviceInfoAdapter;
24
+ forceUpdate?: ForceUpdateClientOptions;
25
+ }
26
+ ```
27
+
28
+ | Option | Type | Required | Description |
29
+ |--------|------|----------|-------------|
30
+ | `org_id` | string | Yes | Organization ID from dashboard |
31
+ | `project_id` | string | Yes | Project ID from dashboard |
32
+ | `api_key` | string | Yes | API key from dashboard |
33
+ | `storageFactory` | function | Yes | Storage adapter factory |
34
+ | `deviceAdapter` | object | Yes | Device info adapter |
35
+ | `forceUpdate` | object | No | Force update configuration |
36
+
37
+ ### Methods
38
+
39
+ #### `setLogLevel(level: LogLevel): void`
40
+
41
+ Set logging level.
42
+
43
+ ```typescript
44
+ teardown.setLogLevel('verbose');
45
+ ```
46
+
47
+ #### `shutdown(): void`
48
+
49
+ Clean up resources. Called automatically by provider.
50
+
51
+ ```typescript
52
+ teardown.shutdown();
53
+ ```
54
+
55
+ ### Properties
56
+
57
+ All properties are readonly and accessed via core instance:
58
+
59
+ ```typescript
60
+ const { core } = useTeardown();
61
+
62
+ core.identity // IdentityClient
63
+ core.forceUpdate // ForceUpdateClient
64
+ core.device // DeviceClient
65
+ core.api // ApiClient
66
+ ```
67
+
68
+ ---
69
+
70
+ ## IdentityClient
71
+
72
+ Manages user and device identity.
73
+
74
+ ### Methods
75
+
76
+ #### `identify(persona?: Persona): AsyncResult<IdentityUser>`
77
+
78
+ Identify device or user.
79
+
80
+ ```typescript
81
+ // Anonymous
82
+ const result = await core.identity.identify();
83
+
84
+ // With user info
85
+ const result = await core.identity.identify({
86
+ user_id: 'user-123',
87
+ email: 'user@example.com',
88
+ name: 'John Doe',
89
+ });
90
+
91
+ if (result.success) {
92
+ console.log(result.data.session_id);
93
+ } else {
94
+ console.error(result.error);
95
+ }
96
+ ```
97
+
98
+ **Parameters:**
99
+ - `persona` (optional): User information
100
+
101
+ **Returns:** `AsyncResult<IdentityUser>`
102
+
103
+ **Types:**
104
+ ```typescript
105
+ type Persona = {
106
+ user_id?: string;
107
+ email?: string;
108
+ name?: string;
109
+ }
110
+
111
+ type IdentityUser = {
112
+ session_id: string;
113
+ device_id: string;
114
+ persona_id: string;
115
+ token: string;
116
+ version_info: {
117
+ status: IdentifyVersionStatusEnum;
118
+ update: null;
119
+ }
120
+ }
121
+ ```
122
+
123
+ #### `refresh(): AsyncResult<IdentityUser>`
124
+
125
+ Re-identify current persona to refresh session.
126
+
127
+ ```typescript
128
+ const result = await core.identity.refresh();
129
+ ```
130
+
131
+ **Returns:** `AsyncResult<IdentityUser>` or error if not identified.
132
+
133
+ #### `reset(): void`
134
+
135
+ Reset identity to unidentified state.
136
+
137
+ ```typescript
138
+ core.identity.reset();
139
+ ```
140
+
141
+ #### `getIdentifyState(): IdentifyState`
142
+
143
+ Get current identity state.
144
+
145
+ ```typescript
146
+ const state = core.identity.getIdentifyState();
147
+
148
+ if (state.type === 'identified') {
149
+ console.log(state.session);
150
+ }
151
+ ```
152
+
153
+ **Returns:** `IdentifyState`
154
+
155
+ ```typescript
156
+ type IdentifyState =
157
+ | { type: "unidentified" }
158
+ | { type: "identifying" }
159
+ | { type: "identified", session: Session, version_info: {...} }
160
+ ```
161
+
162
+ #### `getSessionState(): Session | null`
163
+
164
+ Get current session or null.
165
+
166
+ ```typescript
167
+ const session = core.identity.getSessionState();
168
+
169
+ if (session) {
170
+ console.log(session.session_id);
171
+ }
172
+ ```
173
+
174
+ **Returns:** `Session | null`
175
+
176
+ #### `onIdentifyStateChange(listener: (state: IdentifyState) => void): () => void`
177
+
178
+ Subscribe to identity state changes.
179
+
180
+ ```typescript
181
+ const unsubscribe = core.identity.onIdentifyStateChange((state) => {
182
+ console.log('State changed:', state.type);
183
+ });
184
+
185
+ // Later
186
+ unsubscribe();
187
+ ```
188
+
189
+ **Returns:** Unsubscribe function
190
+
191
+ ---
192
+
193
+ ## ForceUpdateClient
194
+
195
+ Manages app version checking and updates.
196
+
197
+ ### Methods
198
+
199
+ #### `getVersionStatus(): VersionStatus`
200
+
201
+ Get current version status.
202
+
203
+ ```typescript
204
+ const status = core.forceUpdate.getVersionStatus();
205
+ console.log(status.type); // "up_to_date" | "update_available" | etc.
206
+ ```
207
+
208
+ **Returns:** `VersionStatus`
209
+
210
+ ```typescript
211
+ type VersionStatus =
212
+ | { type: "initializing" }
213
+ | { type: "checking" }
214
+ | { type: "up_to_date" }
215
+ | { type: "update_available" }
216
+ | { type: "update_recommended" }
217
+ | { type: "update_required" }
218
+ | { type: "disabled" }
219
+ ```
220
+
221
+ #### `onVersionStatusChange(listener: (status: VersionStatus) => void): () => void`
222
+
223
+ Subscribe to version status changes.
224
+
225
+ ```typescript
226
+ const unsubscribe = core.forceUpdate.onVersionStatusChange((status) => {
227
+ if (status.type === 'update_required') {
228
+ // Show update UI
229
+ }
230
+ });
231
+
232
+ // Later
233
+ unsubscribe();
234
+ ```
235
+
236
+ **Returns:** Unsubscribe function
237
+
238
+ ---
239
+
240
+ ## DeviceClient
241
+
242
+ Collects device information.
243
+
244
+ ### Methods
245
+
246
+ #### `getDeviceId(): Promise<string>`
247
+
248
+ Get unique device identifier.
249
+
250
+ ```typescript
251
+ const deviceId = await core.device.getDeviceId();
252
+ console.log(deviceId); // "uuid-v4-string"
253
+ ```
254
+
255
+ **Returns:** `Promise<string>`
256
+
257
+ #### `getDeviceInfo(): Promise<DeviceInfo>`
258
+
259
+ Get comprehensive device information.
260
+
261
+ ```typescript
262
+ const info = await core.device.getDeviceInfo();
263
+ console.log(info.device_platform); // "IOS" | "ANDROID" | etc.
264
+ console.log(info.app_version); // "1.0.0"
265
+ ```
266
+
267
+ **Returns:** `Promise<DeviceInfo>`
268
+
269
+ ```typescript
270
+ type DeviceInfo = {
271
+ app_version: string;
272
+ app_build: string;
273
+ app_bundle_id: string;
274
+ device_platform: DevicePlatformEnum;
275
+ device_os_version: string;
276
+ device_model: string;
277
+ device_manufacturer: string;
278
+ update?: {
279
+ update_id: string;
280
+ channel: string;
281
+ created_at: string;
282
+ runtime_version: string;
283
+ } | null;
284
+ }
285
+ ```
286
+
287
+ ---
288
+
289
+ ## ApiClient
290
+
291
+ Type-safe API client.
292
+
293
+ ### Properties
294
+
295
+ #### `client: Client`
296
+
297
+ Eden Treaty client for type-safe API calls.
298
+
299
+ ```typescript
300
+ const response = await core.api.client('/v1/identify', {
301
+ method: 'POST',
302
+ headers: {...},
303
+ body: {...},
304
+ });
305
+ ```
306
+
307
+ #### `orgId: string`
308
+
309
+ Current organization ID.
310
+
311
+ ```typescript
312
+ console.log(core.api.orgId);
313
+ ```
314
+
315
+ #### `projectId: string`
316
+
317
+ Current project ID.
318
+
319
+ ```typescript
320
+ console.log(core.api.projectId);
321
+ ```
322
+
323
+ #### `apiKey: string`
324
+
325
+ Current API key.
326
+
327
+ ```typescript
328
+ console.log(core.api.apiKey);
329
+ ```
330
+
331
+ #### `environmentSlug: string`
332
+
333
+ Current environment slug.
334
+
335
+ ```typescript
336
+ console.log(core.api.environmentSlug);
337
+ ```
338
+
339
+ ---
340
+
341
+ ## TeardownProvider
342
+
343
+ React provider component.
344
+
345
+ ### Props
346
+
347
+ ```typescript
348
+ type TeardownProviderProps = {
349
+ children: React.ReactNode;
350
+ core: TeardownCore;
351
+ }
352
+ ```
353
+
354
+ ### Usage
355
+
356
+ ```typescript
357
+ <TeardownProvider core={teardown}>
358
+ <App />
359
+ </TeardownProvider>
360
+ ```
361
+
362
+ ---
363
+
364
+ ## Types
365
+
366
+ ### AsyncResult
367
+
368
+ ```typescript
369
+ type AsyncResult<T> = Promise<
370
+ | { success: true; data: T }
371
+ | { success: false; error: string }
372
+ >
373
+ ```
374
+
375
+ ### Session
376
+
377
+ ```typescript
378
+ type Session = {
379
+ session_id: string;
380
+ device_id: string;
381
+ persona_id: string;
382
+ token: string;
383
+ }
384
+ ```
385
+
386
+ ### LogLevel
387
+
388
+ ```typescript
389
+ type LogLevel = "none" | "error" | "warn" | "info" | "verbose"
390
+ ```
391
+
392
+ ### SupportedStorage
393
+
394
+ ```typescript
395
+ type SupportedStorage = {
396
+ preload: () => void;
397
+ getItem: (key: string) => string | null;
398
+ setItem: (key: string, value: string) => void;
399
+ removeItem: (key: string) => void;
400
+ clear: () => void;
401
+ keys: () => string[];
402
+ }
403
+ ```
404
+
405
+ ### SupportedStorageFactory
406
+
407
+ ```typescript
408
+ type SupportedStorageFactory = (storageKey: string) => SupportedStorage
409
+ ```
410
+
411
+ ### DeviceInfoAdapter
412
+
413
+ ```typescript
414
+ interface DeviceInfoAdapter {
415
+ getDeviceInfo(): Promise<DeviceInfo>;
416
+ }
417
+ ```
418
+
419
+ ### ForceUpdateClientOptions
420
+
421
+ ```typescript
422
+ type ForceUpdateClientOptions = {
423
+ throttleMs?: number; // Default: 30000
424
+ checkCooldownMs?: number; // Default: 300000
425
+ }
426
+ ```
427
+
428
+ ---
429
+
430
+ ## Enums
431
+
432
+ ### DevicePlatformEnum
433
+
434
+ ```typescript
435
+ enum DevicePlatformEnum {
436
+ IOS = "IOS",
437
+ ANDROID = "ANDROID",
438
+ WEB = "WEB",
439
+ WINDOWS = "WINDOWS",
440
+ MACOS = "MACOS",
441
+ LINUX = "LINUX",
442
+ PHONE = "PHONE",
443
+ TABLET = "TABLET",
444
+ DESKTOP = "DESKTOP",
445
+ CONSOLE = "CONSOLE",
446
+ TV = "TV",
447
+ WEARABLE = "WEARABLE",
448
+ GAME_CONSOLE = "GAME_CONSOLE",
449
+ VR = "VR",
450
+ UNKNOWN = "UNKNOWN",
451
+ OTHER = "OTHER",
452
+ }
453
+ ```
454
+
455
+ ### IdentifyVersionStatusEnum
456
+
457
+ ```typescript
458
+ enum IdentifyVersionStatusEnum {
459
+ UPDATE_AVAILABLE = "UPDATE_AVAILABLE",
460
+ UPDATE_RECOMMENDED = "UPDATE_RECOMMENDED",
461
+ UPDATE_REQUIRED = "UPDATE_REQUIRED",
462
+ UP_TO_DATE = "UP_TO_DATE",
463
+ DISABLED = "DISABLED",
464
+ }
465
+ ```
466
+
467
+ ---
468
+
469
+ ## Next Steps
470
+
471
+ - [Hooks Reference](./08-hooks-reference.mdx)
472
+ - [Advanced Usage](./09-advanced.mdx)