@bota.dev/react-native-app-sdk 2.0.0-beta.1 → 2.0.0-beta.3

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 (100) hide show
  1. package/README.md +66 -3
  2. package/android/build.gradle +1 -0
  3. package/android/src/main/java/dev/bota/sdk/reactnative/BotaDeviceSDKAndroidDiagnostics.kt +53 -0
  4. package/android/src/main/java/dev/bota/sdk/reactnative/BotaDeviceSDKAndroidLogs.kt +16 -0
  5. package/android/src/main/java/dev/bota/sdk/reactnative/BotaDeviceSDKAndroidRecordingUploads.kt +144 -14
  6. package/android/src/main/java/dev/bota/sdk/reactnative/BotaDeviceSDKAndroidRecordings.kt +150 -29
  7. package/android/src/main/java/dev/bota/sdk/reactnative/BotaDeviceSDKEncryptedUploadV2Materials.kt +27 -0
  8. package/android/src/main/java/dev/bota/sdk/reactnative/BotaDeviceSDKModule.kt +68 -3
  9. package/android/src/test/java/dev/bota/sdk/reactnative/BotaDeviceSDKAndroidLogsTest.kt +33 -0
  10. package/android/src/test/java/dev/bota/sdk/reactnative/BotaDeviceSDKAndroidRecordingUploadsTest.kt +135 -6
  11. package/android/src/test/java/dev/bota/sdk/reactnative/BotaDeviceSDKAndroidRecordingsTest.kt +236 -10
  12. package/generated/codegen-contract.json +495 -8
  13. package/ios/BotaDeviceSDK.mm +102 -0
  14. package/ios/BotaDeviceSDKAppleBridge.swift +126 -4
  15. package/ios/BotaDeviceSDKAppleDiagnostics.swift +40 -0
  16. package/ios/BotaDeviceSDKAppleLogs.swift +18 -0
  17. package/ios/BotaDeviceSDKAppleRecordingUploads.swift +138 -6
  18. package/ios/BotaDeviceSDKAppleRecordings.swift +113 -5
  19. package/ios/BotaDeviceSDKEncryptedUploadV2Materials.swift +40 -0
  20. package/lib/commonjs/BotaClient.js +13 -2
  21. package/lib/commonjs/BotaClient.js.map +1 -1
  22. package/lib/commonjs/ble/constants.js +5 -1
  23. package/lib/commonjs/ble/constants.js.map +1 -1
  24. package/lib/commonjs/ble/deviceDiagnostics.js +240 -0
  25. package/lib/commonjs/ble/deviceDiagnostics.js.map +1 -0
  26. package/lib/commonjs/client.js +163 -28
  27. package/lib/commonjs/client.js.map +1 -1
  28. package/lib/commonjs/index.js +15 -0
  29. package/lib/commonjs/index.js.map +1 -1
  30. package/lib/commonjs/managers/DeviceManager.js +8 -0
  31. package/lib/commonjs/managers/DeviceManager.js.map +1 -1
  32. package/lib/commonjs/managers/NativeUploadQueue.js +386 -0
  33. package/lib/commonjs/managers/NativeUploadQueue.js.map +1 -0
  34. package/lib/commonjs/managers/RecordingManager.js +83 -102
  35. package/lib/commonjs/managers/RecordingManager.js.map +1 -1
  36. package/lib/commonjs/managers/uploadRecoveryMetadata.js +83 -0
  37. package/lib/commonjs/managers/uploadRecoveryMetadata.js.map +1 -0
  38. package/lib/commonjs/specs/NativeBotaDeviceSDK.js.map +1 -1
  39. package/lib/module/BotaClient.js +13 -2
  40. package/lib/module/BotaClient.js.map +1 -1
  41. package/lib/module/ble/constants.js +4 -0
  42. package/lib/module/ble/constants.js.map +1 -1
  43. package/lib/module/ble/deviceDiagnostics.js +234 -0
  44. package/lib/module/ble/deviceDiagnostics.js.map +1 -0
  45. package/lib/module/client.js +163 -28
  46. package/lib/module/client.js.map +1 -1
  47. package/lib/module/index.js +2 -0
  48. package/lib/module/index.js.map +1 -1
  49. package/lib/module/managers/DeviceManager.js +8 -0
  50. package/lib/module/managers/DeviceManager.js.map +1 -1
  51. package/lib/module/managers/NativeUploadQueue.js +380 -0
  52. package/lib/module/managers/NativeUploadQueue.js.map +1 -0
  53. package/lib/module/managers/RecordingManager.js +83 -102
  54. package/lib/module/managers/RecordingManager.js.map +1 -1
  55. package/lib/module/managers/uploadRecoveryMetadata.js +77 -0
  56. package/lib/module/managers/uploadRecoveryMetadata.js.map +1 -0
  57. package/lib/module/specs/NativeBotaDeviceSDK.js.map +1 -1
  58. package/lib/typescript/BotaClient.d.ts.map +1 -1
  59. package/lib/typescript/ble/constants.d.ts +4 -0
  60. package/lib/typescript/ble/constants.d.ts.map +1 -1
  61. package/lib/typescript/ble/deviceDiagnostics.d.ts +10 -0
  62. package/lib/typescript/ble/deviceDiagnostics.d.ts.map +1 -0
  63. package/lib/typescript/client.d.ts +18 -2
  64. package/lib/typescript/client.d.ts.map +1 -1
  65. package/lib/typescript/index.d.ts +6 -4
  66. package/lib/typescript/index.d.ts.map +1 -1
  67. package/lib/typescript/managers/DeviceManager.d.ts +3 -1
  68. package/lib/typescript/managers/DeviceManager.d.ts.map +1 -1
  69. package/lib/typescript/managers/NativeUploadQueue.d.ts +41 -0
  70. package/lib/typescript/managers/NativeUploadQueue.d.ts.map +1 -0
  71. package/lib/typescript/managers/RecordingManager.d.ts +3 -8
  72. package/lib/typescript/managers/RecordingManager.d.ts.map +1 -1
  73. package/lib/typescript/managers/types.d.ts +6 -1
  74. package/lib/typescript/managers/types.d.ts.map +1 -1
  75. package/lib/typescript/managers/uploadRecoveryMetadata.d.ts +6 -0
  76. package/lib/typescript/managers/uploadRecoveryMetadata.d.ts.map +1 -0
  77. package/lib/typescript/models/Device.d.ts +42 -0
  78. package/lib/typescript/models/Device.d.ts.map +1 -1
  79. package/lib/typescript/models/Recording.d.ts +47 -0
  80. package/lib/typescript/models/Recording.d.ts.map +1 -1
  81. package/lib/typescript/models/Status.d.ts +5 -1
  82. package/lib/typescript/models/Status.d.ts.map +1 -1
  83. package/lib/typescript/specs/NativeBotaDeviceSDK.d.ts +61 -0
  84. package/lib/typescript/specs/NativeBotaDeviceSDK.d.ts.map +1 -1
  85. package/package.json +1 -1
  86. package/scripts/bota_device_sdk_spm_workaround.rb +26 -15
  87. package/src/BotaClient.ts +13 -3
  88. package/src/ble/constants.ts +5 -0
  89. package/src/ble/deviceDiagnostics.ts +238 -0
  90. package/src/client.ts +166 -18
  91. package/src/index.ts +12 -0
  92. package/src/managers/DeviceManager.ts +11 -0
  93. package/src/managers/NativeUploadQueue.ts +330 -0
  94. package/src/managers/RecordingManager.ts +83 -116
  95. package/src/managers/types.ts +7 -1
  96. package/src/managers/uploadRecoveryMetadata.ts +59 -0
  97. package/src/models/Device.ts +43 -0
  98. package/src/models/Recording.ts +52 -0
  99. package/src/models/Status.ts +5 -1
  100. package/src/specs/NativeBotaDeviceSDK.ts +56 -0
@@ -0,0 +1,59 @@
1
+ import type { UploadTask } from '../models/Recording';
2
+
3
+ const invalid = (): never => { throw new Error('Invalid upload recovery journal'); };
4
+
5
+ /** Whitelist, never spread a runtime object into persistent storage. */
6
+ export function persistedUploadQueue(tasks: UploadTask[]): UploadTask[] {
7
+ return tasks.map((task) => ({
8
+ id: task.id,
9
+ recordingId: task.recordingId,
10
+ deviceId: task.deviceId,
11
+ localPath: task.localPath,
12
+ uploadUrl: '',
13
+ status: task.status,
14
+ retryCount: task.retryCount,
15
+ createdAt: new Date(task.createdAt),
16
+ updatedAt: new Date(task.updatedAt),
17
+ ...(task.recordingUuid === undefined ? {} : { recordingUuid: task.recordingUuid }),
18
+ ...(task.recoveryScope === undefined ? {} : { recoveryScope: task.recoveryScope }),
19
+ ...(task.fileSizeBytes === undefined ? {} : { fileSizeBytes: task.fileSizeBytes }),
20
+ ...(task.nextAttemptAt === undefined ? {} : { nextAttemptAt: task.nextAttemptAt }),
21
+ ...(task.contentType === undefined ? {} : { contentType: task.contentType }),
22
+ ...(task.contentSha256 === undefined ? {} : { contentSha256: task.contentSha256 }),
23
+ relayUpload: task.relayUpload ?? !!task.relay,
24
+ }));
25
+ }
26
+
27
+ export function restoreUploadQueue(value: unknown): UploadTask[] {
28
+ if (!Array.isArray(value)) return invalid();
29
+ const ids = new Set<string>();
30
+ const validated = value.map((entry): UploadTask => {
31
+ if (!entry || typeof entry !== 'object') return invalid();
32
+ const task = entry as UploadTask;
33
+ for (const field of ['id', 'recordingId', 'deviceId'] as const) {
34
+ if (typeof task[field] !== 'string' || !task[field]) return invalid();
35
+ }
36
+ if (typeof task.localPath !== 'string' || ids.has(task.id)) return invalid();
37
+ ids.add(task.id);
38
+ if (!['pending', 'uploading', 'failed', 'completed'].includes(task.status)) return invalid();
39
+ if (!Number.isSafeInteger(task.retryCount) || task.retryCount < 0) return invalid();
40
+ for (const field of ['recordingUuid', 'recoveryScope', 'contentType', 'contentSha256'] as const) {
41
+ if (task[field] !== undefined && typeof task[field] !== 'string') return invalid();
42
+ }
43
+ for (const field of ['fileSizeBytes', 'nextAttemptAt'] as const) {
44
+ if (task[field] !== undefined && (!Number.isSafeInteger(task[field]) || task[field]! < 0)) return invalid();
45
+ }
46
+ if (task.relayUpload !== undefined && typeof task.relayUpload !== 'boolean') return invalid();
47
+ const createdAt = new Date(task.createdAt);
48
+ const updatedAt = new Date(task.updatedAt);
49
+ if (!Number.isFinite(createdAt.getTime()) || !Number.isFinite(updatedAt.getTime())) return invalid();
50
+ return { ...task, createdAt, updatedAt, status: task.status === 'uploading' ? 'pending' : task.status };
51
+ });
52
+ return persistedUploadQueue(validated);
53
+ }
54
+
55
+ export function rejectRecordingDataStore(value: unknown): void {
56
+ if (value !== undefined) {
57
+ throw new Error('RecordingDataStore byte callbacks are unsupported; recording files are native-owned');
58
+ }
59
+ }
@@ -199,6 +199,49 @@ export interface DeviceLogEvent {
199
199
  isBacklog: boolean;
200
200
  }
201
201
 
202
+ export type DeviceDiagnosticEventType =
203
+ | 'reset' | 'watchdog' | 'hard_fault' | 'storage'
204
+ | 'power' | 'radio' | 'security';
205
+
206
+ export type DeviceDiagnosticReasonCode =
207
+ | 'watchdog_timeout' | 'cpu_illegal_instruction'
208
+ | 'cpu_misaligned_access' | 'cpu_stack_overflow'
209
+ | 'cpu_usage_fault' | 'memory_protection_fault'
210
+ | 'invalid_register_read' | 'invalid_register_write'
211
+ | 'audio_subsystem_fault' | 'wireless_subsystem_fault'
212
+ | 'flash_mmu_fault' | 'low_voltage_reset'
213
+ | 'unknown_cpu_exception';
214
+
215
+ /** A retained device fault. Reading does not acknowledge or delete it. */
216
+ export interface DeviceDiagnosticEvent {
217
+ event_id: string;
218
+ event_type: DeviceDiagnosticEventType;
219
+ reason_code: DeviceDiagnosticReasonCode;
220
+ uptime_ms: number;
221
+ signature: string;
222
+ firmware_build_id: string;
223
+ subsystem: string;
224
+ state_before_event: string;
225
+ report?: {
226
+ fault: {
227
+ cpu_id: number;
228
+ cpu_emu: string;
229
+ core_emu: string;
230
+ hsb_emu: string;
231
+ audio_emu: string;
232
+ wireless_emu: string;
233
+ };
234
+ execution: { task?: string; reti?: string; rets?: string; pc_trace: string[] };
235
+ runtime?: { heap_free_bytes?: number; task_stack_remaining_bytes?: number };
236
+ breadcrumbs?: Array<{ delta_ms: number; code: string; arg0: number }>;
237
+ };
238
+ }
239
+
240
+ export interface DeviceDiagnosticsBatch {
241
+ schema_version: 1;
242
+ events: DeviceDiagnosticEvent[];
243
+ }
244
+
202
245
  /**
203
246
  * Storage information from device
204
247
  */
@@ -30,6 +30,20 @@ export interface DeviceRecording {
30
30
  * (obtained by calling customer's API, not Bota API directly)
31
31
  */
32
32
  export interface UploadInfo {
33
+ /** Non-secret account/project/environment identity. Must match during recovery. */
34
+ recoveryScope?: string;
35
+ /** Skip sending the object; complete must still acknowledge host durability. */
36
+ alreadyUploaded?: boolean;
37
+ /** Resolve only after the backend durably acknowledges this exact recording. */
38
+ complete?: (context: {
39
+ fileSizeBytes: number;
40
+ contentSha256?: string;
41
+ signal: AbortSignal;
42
+ }) => Promise<void>;
43
+ /** Aborted by the host when this authorization context becomes invalid. */
44
+ signal?: AbortSignal;
45
+ /** Releases host listeners/leases after the attempt, including cancellation. */
46
+ dispose?: () => void;
33
47
  /** Pre-signed S3 URL for upload */
34
48
  uploadUrl: string;
35
49
  /** Recording ID assigned by Bota API (rec_*) */
@@ -55,6 +69,37 @@ export interface UploadInfo {
55
69
  };
56
70
  }
57
71
 
72
+ /** Maintenance compatibility shape only. JS byte stores are unsupported by the
73
+ * native-owned facade; supplying one throws before native configuration. */
74
+ export interface RecordingDataStore {
75
+ saveRecordingData(input: {
76
+ deviceId: string;
77
+ recordingUuid: string;
78
+ data: Uint8Array;
79
+ }): Promise<string>;
80
+ loadRecordingData(localPath: string): Promise<Uint8Array>;
81
+ deleteRecordingData(localPath: string): Promise<void>;
82
+ }
83
+
84
+ /** Metadata only. The host must refresh credentials for this exact identity. */
85
+ export interface UploadRecoveryContext {
86
+ taskId: string;
87
+ recordingId: string;
88
+ deviceId: string;
89
+ recordingUuid: string;
90
+ recoveryScope?: string;
91
+ fileSizeBytes?: number;
92
+ relayUpload: boolean;
93
+ contentType?: string;
94
+ contentSha256?: string;
95
+ signal: AbortSignal;
96
+ }
97
+
98
+ /** Null parks an unavailable account without consuming the retry budget. */
99
+ export type UploadRecoveryProvider = (
100
+ context: UploadRecoveryContext
101
+ ) => Promise<UploadInfo | null>;
102
+
58
103
  /**
59
104
  * Sync progress stages
60
105
  */
@@ -102,6 +147,13 @@ export type UploadTaskStatus = 'pending' | 'uploading' | 'completed' | 'failed';
102
147
  * Upload task in the queue
103
148
  */
104
149
  export interface UploadTask {
150
+ recordingUuid?: string;
151
+ recoveryScope?: string;
152
+ fileSizeBytes?: number;
153
+ relayUpload?: boolean;
154
+ nextAttemptAt?: number;
155
+ /** Volatile compatibility field; never included in queue persistence. */
156
+ complete?: UploadInfo['complete'];
105
157
  /** Unique task identifier */
106
158
  id: string;
107
159
  /** Recording ID from Bota API */
@@ -3,7 +3,7 @@
3
3
  */
4
4
 
5
5
  import type { DeviceStatus, StorageInfo } from './Device';
6
- import type { SyncProgress, UploadTask } from './Recording';
6
+ import type { RecordingDataStore, SyncProgress, UploadRecoveryProvider, UploadTask } from './Recording';
7
7
 
8
8
  /**
9
9
  * SDK log level
@@ -14,6 +14,10 @@ export type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'none';
14
14
  * SDK configuration options
15
15
  */
16
16
  export interface BotaConfig {
17
+ /** Refreshes credentials for retained native recordings after restart. */
18
+ uploadRecoveryProvider?: UploadRecoveryProvider;
19
+ /** Unsupported compatibility option: byte callbacks cannot cross the bridge. */
20
+ recordingDataStore?: RecordingDataStore;
17
21
  /** Environment for API endpoint (development, gamma, or production) */
18
22
  environment?: 'development' | 'gamma' | 'production';
19
23
  /** Enable background sync (default: true) */
@@ -156,6 +156,16 @@ export type NativeEncryptedUploadV2Recording = {
156
156
  generation: number;
157
157
  ciphertextLength: string;
158
158
  ciphertextSha256: string;
159
+ startedAtMs?: string;
160
+ durationMs?: string;
161
+ plaintextLength?: string;
162
+ storageFormat?: number;
163
+ };
164
+
165
+ export type NativePendingRecording = {
166
+ profile: string;
167
+ legacy?: NativeDeviceRecording;
168
+ encrypted?: NativeEncryptedUploadV2Recording;
159
169
  };
160
170
 
161
171
  export type NativeEncryptedUploadV2Capability = {
@@ -223,6 +233,7 @@ export type NativeRecordingTransferResult = {
223
233
  localPath: string;
224
234
  e2eEncrypted: boolean;
225
235
  contentSha256?: string;
236
+ fileSizeBytes: number;
226
237
  };
227
238
 
228
239
  export type NativeRecordingUploadProgress = {
@@ -236,6 +247,7 @@ export type NativeRecordingUploadRequest = {
236
247
  recordingId: string;
237
248
  deviceId: string;
238
249
  localPath: string;
250
+ fileSizeBytes?: number;
239
251
  uploadUrl: string;
240
252
  uploadToken?: string;
241
253
  completeUrl?: string;
@@ -329,6 +341,44 @@ export type NativeDeviceLogLine = {
329
341
  isBacklog: boolean;
330
342
  };
331
343
 
344
+ export type NativeDiagnosticFault = {
345
+ cpu_id: number;
346
+ cpu_emu: string;
347
+ core_emu: string;
348
+ hsb_emu: string;
349
+ audio_emu: string;
350
+ wireless_emu: string;
351
+ };
352
+ export type NativeDiagnosticExecution = {
353
+ task?: string;
354
+ reti?: string;
355
+ rets?: string;
356
+ pc_trace: ReadonlyArray<string>;
357
+ };
358
+ export type NativeDiagnosticRuntime = {
359
+ heap_free_bytes?: number;
360
+ task_stack_remaining_bytes?: number;
361
+ };
362
+ export type NativeDiagnosticBreadcrumb = { delta_ms: number; code: string; arg0: number };
363
+ export type NativeDiagnosticReport = {
364
+ fault: NativeDiagnosticFault;
365
+ execution: NativeDiagnosticExecution;
366
+ runtime?: NativeDiagnosticRuntime;
367
+ breadcrumbs?: ReadonlyArray<NativeDiagnosticBreadcrumb>;
368
+ };
369
+ export type NativeDiagnosticEvent = {
370
+ event_id: string;
371
+ event_type: string;
372
+ reason_code: string;
373
+ uptime_ms: number;
374
+ signature: string;
375
+ firmware_build_id: string;
376
+ subsystem: string;
377
+ state_before_event: string;
378
+ report?: NativeDiagnosticReport;
379
+ };
380
+ export type NativeDiagnosticsBatch = { schema_version: number; events: ReadonlyArray<NativeDiagnosticEvent> };
381
+
332
382
  export type NativeWiFiConfigResult = {
333
383
  success: boolean;
334
384
  error?: string;
@@ -480,6 +530,8 @@ export interface Spec extends TurboModule {
480
530
  startWiFiStatusUpdates: (device: NativeConnectedDevice) => Promise<void>;
481
531
  startDeviceLogs: (device: NativeConnectedDevice) => Promise<void>;
482
532
  stopDeviceLogs: () => Promise<void>;
533
+ readDiagnosticEvents: (device: NativeConnectedDevice) => Promise<NativeDiagnosticsBatch>;
534
+ acknowledgeDiagnosticEvents: (device: NativeConnectedDevice, acceptedEventIds: ReadonlyArray<string>) => Promise<void>;
483
535
  stopStatusUpdates: () => Promise<void>;
484
536
  stopWiFiStatusUpdates: () => Promise<void>;
485
537
  stopScan: () => Promise<void>;
@@ -493,6 +545,9 @@ export interface Spec extends TurboModule {
493
545
  recording: NativeEncryptedUploadV2Recording,
494
546
  operationId: string
495
547
  ) => Promise<void>;
548
+ listPendingRecordings: (device: NativeConnectedDevice) => Promise<ReadonlyArray<NativePendingRecording>>;
549
+ cancelEncryptedRecordingV2: (operationId: string) => Promise<void>;
550
+ releaseEncryptedUploadV2Material: (materialRegistrationId: string) => Promise<void>;
496
551
  resolveEncryptedUploadV2Profile: (
497
552
  requestId: string,
498
553
  decision: NativeEncryptedUploadV2ProfileDecision
@@ -507,6 +562,7 @@ export interface Spec extends TurboModule {
507
562
  ) => Promise<void>;
508
563
  uploadRecordingFile: (request: NativeRecordingUploadRequest) => Promise<void>;
509
564
  cancelRecordingUpload: (taskId: string) => Promise<void>;
565
+ releaseRecordingFile: (taskId: string, localPath: string) => Promise<void>;
510
566
  loadCompatibilityUploadQueue: () => Promise<string>;
511
567
  saveCompatibilityUploadQueue: (serializedTasks: string) => Promise<void>;
512
568
  stopAllRecordingOperations: () => Promise<void>;