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

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 (110) hide show
  1. package/README.md +75 -3
  2. package/android/build.gradle +1 -0
  3. package/android/src/main/java/dev/bota/sdk/reactnative/BotaDeviceSDKAndroidDevices.kt +4 -0
  4. package/android/src/main/java/dev/bota/sdk/reactnative/BotaDeviceSDKAndroidDiagnostics.kt +53 -0
  5. package/android/src/main/java/dev/bota/sdk/reactnative/BotaDeviceSDKAndroidLogs.kt +16 -0
  6. package/android/src/main/java/dev/bota/sdk/reactnative/BotaDeviceSDKAndroidRecordingUploads.kt +144 -14
  7. package/android/src/main/java/dev/bota/sdk/reactnative/BotaDeviceSDKAndroidRecordings.kt +150 -29
  8. package/android/src/main/java/dev/bota/sdk/reactnative/BotaDeviceSDKEncryptedUploadV2Materials.kt +27 -0
  9. package/android/src/main/java/dev/bota/sdk/reactnative/BotaDeviceSDKModule.kt +83 -3
  10. package/android/src/test/java/dev/bota/sdk/reactnative/BotaDeviceSDKAndroidDevicesTest.kt +1 -0
  11. package/android/src/test/java/dev/bota/sdk/reactnative/BotaDeviceSDKAndroidLogsTest.kt +33 -0
  12. package/android/src/test/java/dev/bota/sdk/reactnative/BotaDeviceSDKAndroidRecordingUploadsTest.kt +135 -6
  13. package/android/src/test/java/dev/bota/sdk/reactnative/BotaDeviceSDKAndroidRecordingsTest.kt +236 -10
  14. package/generated/codegen-contract.json +568 -8
  15. package/ios/BotaDeviceSDK.mm +114 -0
  16. package/ios/BotaDeviceSDKAppleBridge.swift +141 -4
  17. package/ios/BotaDeviceSDKAppleDevices.swift +11 -0
  18. package/ios/BotaDeviceSDKAppleDiagnostics.swift +40 -0
  19. package/ios/BotaDeviceSDKAppleLogs.swift +18 -0
  20. package/ios/BotaDeviceSDKAppleRecordingUploads.swift +138 -6
  21. package/ios/BotaDeviceSDKAppleRecordings.swift +113 -5
  22. package/ios/BotaDeviceSDKEncryptedUploadV2Materials.swift +40 -0
  23. package/lib/commonjs/BotaClient.js +13 -2
  24. package/lib/commonjs/BotaClient.js.map +1 -1
  25. package/lib/commonjs/ble/constants.js +5 -1
  26. package/lib/commonjs/ble/constants.js.map +1 -1
  27. package/lib/commonjs/ble/deviceDiagnostics.js +240 -0
  28. package/lib/commonjs/ble/deviceDiagnostics.js.map +1 -0
  29. package/lib/commonjs/client.js +183 -28
  30. package/lib/commonjs/client.js.map +1 -1
  31. package/lib/commonjs/index.js +15 -0
  32. package/lib/commonjs/index.js.map +1 -1
  33. package/lib/commonjs/managers/DeviceManager.js +8 -0
  34. package/lib/commonjs/managers/DeviceManager.js.map +1 -1
  35. package/lib/commonjs/managers/NativeUploadQueue.js +386 -0
  36. package/lib/commonjs/managers/NativeUploadQueue.js.map +1 -0
  37. package/lib/commonjs/managers/RecordingManager.js +83 -102
  38. package/lib/commonjs/managers/RecordingManager.js.map +1 -1
  39. package/lib/commonjs/managers/uploadRecoveryMetadata.js +83 -0
  40. package/lib/commonjs/managers/uploadRecoveryMetadata.js.map +1 -0
  41. package/lib/commonjs/sdkIdentity.js +10 -0
  42. package/lib/commonjs/sdkIdentity.js.map +1 -0
  43. package/lib/commonjs/specs/NativeBotaDeviceSDK.js.map +1 -1
  44. package/lib/module/BotaClient.js +13 -2
  45. package/lib/module/BotaClient.js.map +1 -1
  46. package/lib/module/ble/constants.js +4 -0
  47. package/lib/module/ble/constants.js.map +1 -1
  48. package/lib/module/ble/deviceDiagnostics.js +234 -0
  49. package/lib/module/ble/deviceDiagnostics.js.map +1 -0
  50. package/lib/module/client.js +183 -28
  51. package/lib/module/client.js.map +1 -1
  52. package/lib/module/index.js +2 -0
  53. package/lib/module/index.js.map +1 -1
  54. package/lib/module/managers/DeviceManager.js +8 -0
  55. package/lib/module/managers/DeviceManager.js.map +1 -1
  56. package/lib/module/managers/NativeUploadQueue.js +380 -0
  57. package/lib/module/managers/NativeUploadQueue.js.map +1 -0
  58. package/lib/module/managers/RecordingManager.js +83 -102
  59. package/lib/module/managers/RecordingManager.js.map +1 -1
  60. package/lib/module/managers/uploadRecoveryMetadata.js +77 -0
  61. package/lib/module/managers/uploadRecoveryMetadata.js.map +1 -0
  62. package/lib/module/sdkIdentity.js +6 -0
  63. package/lib/module/sdkIdentity.js.map +1 -0
  64. package/lib/module/specs/NativeBotaDeviceSDK.js.map +1 -1
  65. package/lib/typescript/BotaClient.d.ts.map +1 -1
  66. package/lib/typescript/ble/constants.d.ts +4 -0
  67. package/lib/typescript/ble/constants.d.ts.map +1 -1
  68. package/lib/typescript/ble/deviceDiagnostics.d.ts +10 -0
  69. package/lib/typescript/ble/deviceDiagnostics.d.ts.map +1 -0
  70. package/lib/typescript/client.d.ts +24 -3
  71. package/lib/typescript/client.d.ts.map +1 -1
  72. package/lib/typescript/index.d.ts +6 -4
  73. package/lib/typescript/index.d.ts.map +1 -1
  74. package/lib/typescript/managers/DeviceManager.d.ts +3 -1
  75. package/lib/typescript/managers/DeviceManager.d.ts.map +1 -1
  76. package/lib/typescript/managers/NativeUploadQueue.d.ts +41 -0
  77. package/lib/typescript/managers/NativeUploadQueue.d.ts.map +1 -0
  78. package/lib/typescript/managers/RecordingManager.d.ts +3 -8
  79. package/lib/typescript/managers/RecordingManager.d.ts.map +1 -1
  80. package/lib/typescript/managers/types.d.ts +6 -1
  81. package/lib/typescript/managers/types.d.ts.map +1 -1
  82. package/lib/typescript/managers/uploadRecoveryMetadata.d.ts +6 -0
  83. package/lib/typescript/managers/uploadRecoveryMetadata.d.ts.map +1 -0
  84. package/lib/typescript/models/Device.d.ts +42 -0
  85. package/lib/typescript/models/Device.d.ts.map +1 -1
  86. package/lib/typescript/models/Recording.d.ts +47 -0
  87. package/lib/typescript/models/Recording.d.ts.map +1 -1
  88. package/lib/typescript/models/Status.d.ts +5 -1
  89. package/lib/typescript/models/Status.d.ts.map +1 -1
  90. package/lib/typescript/sdkIdentity.d.ts +3 -0
  91. package/lib/typescript/sdkIdentity.d.ts.map +1 -0
  92. package/lib/typescript/specs/NativeBotaDeviceSDK.d.ts +70 -0
  93. package/lib/typescript/specs/NativeBotaDeviceSDK.d.ts.map +1 -1
  94. package/package.json +1 -1
  95. package/scripts/bota_device_sdk_spm_workaround.rb +26 -15
  96. package/src/BotaClient.ts +13 -3
  97. package/src/ble/constants.ts +5 -0
  98. package/src/ble/deviceDiagnostics.ts +238 -0
  99. package/src/client.ts +189 -18
  100. package/src/index.ts +14 -0
  101. package/src/managers/DeviceManager.ts +11 -0
  102. package/src/managers/NativeUploadQueue.ts +330 -0
  103. package/src/managers/RecordingManager.ts +83 -116
  104. package/src/managers/types.ts +7 -1
  105. package/src/managers/uploadRecoveryMetadata.ts +59 -0
  106. package/src/models/Device.ts +43 -0
  107. package/src/models/Recording.ts +52 -0
  108. package/src/models/Status.ts +5 -1
  109. package/src/sdkIdentity.ts +3 -0
  110. package/src/specs/NativeBotaDeviceSDK.ts +66 -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) */
@@ -0,0 +1,3 @@
1
+ // Generated by cargo xtask client-identity generate. Do not edit.
2
+ export const SDK_PACKAGE = '@bota.dev/react-native-app-sdk'
3
+ export const SDK_VERSION = '2.0.0-beta.4'
@@ -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;
@@ -353,7 +403,17 @@ export type NativeDeviceWiFiScanResult = {
353
403
  currentSsid?: string;
354
404
  };
355
405
 
406
+ export type NativeClientContext = {
407
+ schemaVersion: number;
408
+ sessionId: string;
409
+ sequence: number;
410
+ platform: string;
411
+ sdkPackage: string;
412
+ sdkVersion: string;
413
+ };
414
+
356
415
  export interface Spec extends TurboModule {
416
+ nextClientPresence: (deviceId: string) => Promise<NativeClientContext | null>;
357
417
  readonly onDeviceDiscovered: EventEmitter<NativeDiscoveredDevice>;
358
418
  readonly onDeviceDisconnected: EventEmitter<NativeDeviceDisconnection>;
359
419
  readonly onDeviceStatusUpdated: EventEmitter<NativeDeviceStatus>;
@@ -480,6 +540,8 @@ export interface Spec extends TurboModule {
480
540
  startWiFiStatusUpdates: (device: NativeConnectedDevice) => Promise<void>;
481
541
  startDeviceLogs: (device: NativeConnectedDevice) => Promise<void>;
482
542
  stopDeviceLogs: () => Promise<void>;
543
+ readDiagnosticEvents: (device: NativeConnectedDevice) => Promise<NativeDiagnosticsBatch>;
544
+ acknowledgeDiagnosticEvents: (device: NativeConnectedDevice, acceptedEventIds: ReadonlyArray<string>) => Promise<void>;
483
545
  stopStatusUpdates: () => Promise<void>;
484
546
  stopWiFiStatusUpdates: () => Promise<void>;
485
547
  stopScan: () => Promise<void>;
@@ -493,6 +555,9 @@ export interface Spec extends TurboModule {
493
555
  recording: NativeEncryptedUploadV2Recording,
494
556
  operationId: string
495
557
  ) => Promise<void>;
558
+ listPendingRecordings: (device: NativeConnectedDevice) => Promise<ReadonlyArray<NativePendingRecording>>;
559
+ cancelEncryptedRecordingV2: (operationId: string) => Promise<void>;
560
+ releaseEncryptedUploadV2Material: (materialRegistrationId: string) => Promise<void>;
496
561
  resolveEncryptedUploadV2Profile: (
497
562
  requestId: string,
498
563
  decision: NativeEncryptedUploadV2ProfileDecision
@@ -507,6 +572,7 @@ export interface Spec extends TurboModule {
507
572
  ) => Promise<void>;
508
573
  uploadRecordingFile: (request: NativeRecordingUploadRequest) => Promise<void>;
509
574
  cancelRecordingUpload: (taskId: string) => Promise<void>;
575
+ releaseRecordingFile: (taskId: string, localPath: string) => Promise<void>;
510
576
  loadCompatibilityUploadQueue: () => Promise<string>;
511
577
  saveCompatibilityUploadQueue: (serializedTasks: string) => Promise<void>;
512
578
  stopAllRecordingOperations: () => Promise<void>;