@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,234 @@
1
+ "use strict";
2
+
3
+ import { Buffer } from 'buffer';
4
+ import { DEVICE_DIAGNOSTICS_EVT_END, DEVICE_DIAGNOSTICS_EVT_DETAIL, DEVICE_DIAGNOSTICS_EVT_META, DEVICE_DIAGNOSTICS_EVT_SIGNATURE } from './constants';
5
+ const EVENT_TYPES = {
6
+ 1: 'reset',
7
+ 2: 'watchdog',
8
+ 3: 'hard_fault',
9
+ 4: 'storage',
10
+ 5: 'power',
11
+ 6: 'radio',
12
+ 7: 'security'
13
+ };
14
+ const REASONS = {
15
+ 1: 'watchdog_timeout',
16
+ 2: 'cpu_illegal_instruction',
17
+ 3: 'cpu_misaligned_access',
18
+ 4: 'cpu_stack_overflow',
19
+ 5: 'cpu_usage_fault',
20
+ 6: 'memory_protection_fault',
21
+ 7: 'invalid_register_read',
22
+ 8: 'invalid_register_write',
23
+ 9: 'audio_subsystem_fault',
24
+ 10: 'wireless_subsystem_fault',
25
+ 11: 'flash_mmu_fault',
26
+ 12: 'low_voltage_reset',
27
+ 255: 'unknown_cpu_exception'
28
+ };
29
+ const SUBSYSTEMS = {
30
+ 0: 'system',
31
+ 1: 'audio',
32
+ 2: 'wireless',
33
+ 3: 'storage',
34
+ 4: 'power',
35
+ 5: 'security'
36
+ };
37
+ const STATES = {
38
+ 0: 'boot',
39
+ 1: 'deep_standby',
40
+ 2: 'recording',
41
+ 3: 'upload_preparing',
42
+ 4: 'uploading',
43
+ 5: 'error_recovery',
44
+ 6: 'full_sleep'
45
+ };
46
+ const BREADCRUMBS = {
47
+ 1: 'boot',
48
+ 2: 'standby_entered',
49
+ 3: 'recording_started',
50
+ 4: 'upload_preparing',
51
+ 5: 'upload_started',
52
+ 6: 'error_recovery',
53
+ 7: 'full_sleep'
54
+ };
55
+ const DETAIL_WIRE_SIZE = 176;
56
+ function u64LeHex(bytes) {
57
+ return Buffer.from(bytes).reverse().toString('hex').padStart(16, '0');
58
+ }
59
+ export function diagnosticEventIdCommand(eventId) {
60
+ if (!/^[0-9a-f]{16}$/.test(eventId)) {
61
+ throw new Error('Diagnostic event_id must be 16 lowercase hex characters');
62
+ }
63
+ return Buffer.concat([Buffer.from([0x11]), Buffer.from(eventId, 'hex').reverse()]);
64
+ }
65
+ function normalizedAddress(value) {
66
+ if (value === 0) return undefined;
67
+ const region = (value & 0x80000000) !== 0 ? 'sdram' : (value & 0x40000000) !== 0 ? 'ram' : 'rom';
68
+ const offset = (value & 0x3fffffff).toString(16).padStart(8, '0');
69
+ return `${region}:${offset}`;
70
+ }
71
+ function fixedHex32(value) {
72
+ return value.toString(16).padStart(8, '0');
73
+ }
74
+ function decodeDetail(bytes) {
75
+ if (bytes.length !== DETAIL_WIRE_SIZE || bytes[0] !== 1) {
76
+ throw new Error('Unsupported diagnostic detail payload');
77
+ }
78
+ const hasReport = (bytes[1] & 1) !== 0;
79
+ const firmwareBuildId = Buffer.from(bytes.subarray(2, 14)).toString('ascii');
80
+ if (!/^[0-9a-f]{12}$/.test(firmwareBuildId)) {
81
+ throw new Error('Invalid diagnostic firmware build id');
82
+ }
83
+ const common = {
84
+ firmware_build_id: firmwareBuildId,
85
+ subsystem: SUBSYSTEMS[bytes[14]] ?? 'system',
86
+ state_before_event: STATES[bytes[15]] ?? 'unknown'
87
+ };
88
+ if (!hasReport) return common;
89
+ const pcCount = Math.min(bytes[17], 6);
90
+ const breadcrumbCount = Math.min(bytes[18], 8);
91
+ const runtimeMask = bytes[19];
92
+ const pcTrace = [];
93
+ for (let index = 0; index < pcCount; index++) {
94
+ const address = normalizedAddress(bytes.readUInt32LE(48 + index * 4));
95
+ if (address) pcTrace.push(address);
96
+ }
97
+ const task = Buffer.from(bytes.subarray(80, 96)).toString('ascii').replace(/\0.*$/, '');
98
+ const breadcrumbs = [];
99
+ for (let index = 0; index < breadcrumbCount; index++) {
100
+ const offset = 96 + index * 10;
101
+ breadcrumbs.push({
102
+ delta_ms: bytes.readInt32LE(offset),
103
+ code: BREADCRUMBS[bytes.readUInt16LE(offset + 4)] ?? 'state_changed',
104
+ arg0: bytes.readInt32LE(offset + 6)
105
+ });
106
+ }
107
+ const reti = normalizedAddress(bytes.readUInt32LE(40));
108
+ const rets = normalizedAddress(bytes.readUInt32LE(44));
109
+ return {
110
+ ...common,
111
+ report: {
112
+ fault: {
113
+ cpu_id: bytes[16],
114
+ cpu_emu: fixedHex32(bytes.readUInt32LE(20)),
115
+ core_emu: fixedHex32(bytes.readUInt32LE(24)),
116
+ hsb_emu: fixedHex32(bytes.readUInt32LE(28)),
117
+ audio_emu: fixedHex32(bytes.readUInt32LE(32)),
118
+ wireless_emu: fixedHex32(bytes.readUInt32LE(36))
119
+ },
120
+ execution: {
121
+ ...(task ? {
122
+ task
123
+ } : {}),
124
+ ...(reti ? {
125
+ reti
126
+ } : {}),
127
+ ...(rets ? {
128
+ rets
129
+ } : {}),
130
+ pc_trace: pcTrace
131
+ },
132
+ ...((runtimeMask & 3) !== 0 ? {
133
+ runtime: {
134
+ ...((runtimeMask & 1) !== 0 ? {
135
+ heap_free_bytes: bytes.readUInt32LE(72)
136
+ } : {}),
137
+ ...((runtimeMask & 2) !== 0 ? {
138
+ task_stack_remaining_bytes: bytes.readUInt32LE(76)
139
+ } : {})
140
+ }
141
+ } : {}),
142
+ ...(breadcrumbs.length ? {
143
+ breadcrumbs
144
+ } : {})
145
+ }
146
+ };
147
+ }
148
+ export class DeviceDiagnosticsDecoder {
149
+ events = new Map();
150
+ details = new Map();
151
+ push(packet) {
152
+ if (packet.length === 17 && packet[0] === DEVICE_DIAGNOSTICS_EVT_META) {
153
+ const type = EVENT_TYPES[packet[2]];
154
+ if (!type) return null;
155
+ this.events.set(packet[1], {
156
+ event_id: u64LeHex(packet.subarray(9, 17)),
157
+ event_type: type,
158
+ reason_code: REASONS[packet.readUInt16LE(3)] ?? 'unknown_cpu_exception',
159
+ uptime_ms: packet.readUInt32LE(5)
160
+ });
161
+ return null;
162
+ }
163
+ if (packet.length === 10 && packet[0] === DEVICE_DIAGNOSTICS_EVT_SIGNATURE) {
164
+ const event = this.events.get(packet[1]);
165
+ if (event) event.signature = u64LeHex(packet.subarray(2, 10));
166
+ return null;
167
+ }
168
+ if (packet.length >= 6 && packet.length <= 20 && packet[0] === DEVICE_DIAGNOSTICS_EVT_DETAIL) {
169
+ const index = packet[1];
170
+ const offset = packet.readUInt16LE(2);
171
+ const total = packet.readUInt16LE(4);
172
+ if (total !== DETAIL_WIRE_SIZE || offset + packet.length - 6 > total) {
173
+ this.reset();
174
+ throw new Error('Invalid diagnostic detail chunk');
175
+ }
176
+ let detail = this.details.get(index);
177
+ if (offset === 0) {
178
+ if (detail) {
179
+ this.reset();
180
+ throw new Error(`Duplicate diagnostic detail at index ${index}`);
181
+ }
182
+ detail = {
183
+ buffer: Buffer.alloc(total),
184
+ received: 0
185
+ };
186
+ this.details.set(index, detail);
187
+ }
188
+ if (!detail || detail.received !== offset) {
189
+ this.reset();
190
+ throw new Error(`Out-of-order diagnostic detail at index ${index}`);
191
+ }
192
+ packet.copy(detail.buffer, offset, 6);
193
+ detail.received += packet.length - 6;
194
+ if (detail.received === total) {
195
+ const event = this.events.get(index);
196
+ if (!event) {
197
+ this.reset();
198
+ throw new Error(`Diagnostic detail without metadata at index ${index}`);
199
+ }
200
+ try {
201
+ Object.assign(event, decodeDetail(detail.buffer));
202
+ } catch (error) {
203
+ this.reset();
204
+ throw error;
205
+ }
206
+ }
207
+ return null;
208
+ }
209
+ if (packet.length === 2 && packet[0] === DEVICE_DIAGNOSTICS_EVT_END) {
210
+ const expected = packet[1];
211
+ const events = [];
212
+ for (let index = 0; index < expected; index++) {
213
+ const event = this.events.get(index);
214
+ if (!event?.signature || !event.firmware_build_id || !event.subsystem || !event.state_before_event || this.details.get(index)?.received !== DETAIL_WIRE_SIZE) {
215
+ this.reset();
216
+ throw new Error(`Incomplete diagnostic event at index ${index}`);
217
+ }
218
+ events.push(event);
219
+ }
220
+ const batch = {
221
+ schema_version: 1,
222
+ events
223
+ };
224
+ this.reset();
225
+ return batch;
226
+ }
227
+ return null;
228
+ }
229
+ reset() {
230
+ this.events.clear();
231
+ this.details.clear();
232
+ }
233
+ }
234
+ //# sourceMappingURL=deviceDiagnostics.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["Buffer","DEVICE_DIAGNOSTICS_EVT_END","DEVICE_DIAGNOSTICS_EVT_DETAIL","DEVICE_DIAGNOSTICS_EVT_META","DEVICE_DIAGNOSTICS_EVT_SIGNATURE","EVENT_TYPES","REASONS","SUBSYSTEMS","STATES","BREADCRUMBS","DETAIL_WIRE_SIZE","u64LeHex","bytes","from","reverse","toString","padStart","diagnosticEventIdCommand","eventId","test","Error","concat","normalizedAddress","value","undefined","region","offset","fixedHex32","decodeDetail","length","hasReport","firmwareBuildId","subarray","common","firmware_build_id","subsystem","state_before_event","pcCount","Math","min","breadcrumbCount","runtimeMask","pcTrace","index","address","readUInt32LE","push","task","replace","breadcrumbs","delta_ms","readInt32LE","code","readUInt16LE","arg0","reti","rets","report","fault","cpu_id","cpu_emu","core_emu","hsb_emu","audio_emu","wireless_emu","execution","pc_trace","runtime","heap_free_bytes","task_stack_remaining_bytes","DeviceDiagnosticsDecoder","events","Map","details","packet","type","set","event_id","event_type","reason_code","uptime_ms","event","get","signature","total","reset","detail","buffer","alloc","received","copy","Object","assign","error","expected","batch","schema_version","clear"],"sourceRoot":"../../../src","sources":["ble/deviceDiagnostics.ts"],"mappings":";;AAAA,SAASA,MAAM,QAAQ,QAAQ;AAE/B,SACEC,0BAA0B,EAC1BC,6BAA6B,EAC7BC,2BAA2B,EAC3BC,gCAAgC,QAC3B,aAAa;AAQpB,MAAMC,WAAsD,GAAG;EAC7D,CAAC,EAAE,OAAO;EAAE,CAAC,EAAE,UAAU;EAAE,CAAC,EAAE,YAAY;EAAE,CAAC,EAAE,SAAS;EACxD,CAAC,EAAE,OAAO;EAAE,CAAC,EAAE,OAAO;EAAE,CAAC,EAAE;AAC7B,CAAC;AACD,MAAMC,OAAmD,GAAG;EAC1D,CAAC,EAAE,kBAAkB;EAAE,CAAC,EAAE,yBAAyB;EACnD,CAAC,EAAE,uBAAuB;EAAE,CAAC,EAAE,oBAAoB;EACnD,CAAC,EAAE,iBAAiB;EAAE,CAAC,EAAE,yBAAyB;EAClD,CAAC,EAAE,uBAAuB;EAAE,CAAC,EAAE,wBAAwB;EACvD,CAAC,EAAE,uBAAuB;EAAE,EAAE,EAAE,0BAA0B;EAC1D,EAAE,EAAE,iBAAiB;EAAE,EAAE,EAAE,mBAAmB;EAC9C,GAAG,EAAE;AACP,CAAC;AACD,MAAMC,UAAkC,GAAG;EACzC,CAAC,EAAE,QAAQ;EAAE,CAAC,EAAE,OAAO;EAAE,CAAC,EAAE,UAAU;EAAE,CAAC,EAAE,SAAS;EACpD,CAAC,EAAE,OAAO;EAAE,CAAC,EAAE;AACjB,CAAC;AACD,MAAMC,MAA8B,GAAG;EACrC,CAAC,EAAE,MAAM;EAAE,CAAC,EAAE,cAAc;EAAE,CAAC,EAAE,WAAW;EAAE,CAAC,EAAE,kB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,OAAOU,KAAK;IACd;IACA,OAAO,IAAI;EACb;EAEAV,KAAKA,CAAA,EAAS;IACZ,IAAI,CAACd,MAAM,CAAC0B,KAAK,CAAC,CAAC;IACnB,IAAI,CAACxB,OAAO,CAACwB,KAAK,CAAC,CAAC;EACtB;AACF","ignoreList":[]}
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
 
3
+ import { SDK_PACKAGE, SDK_VERSION } from './sdkIdentity';
3
4
  import { reportCompatibilityDisconnection } from './compatibility/runtime';
4
5
  export class BotaNativeModuleError extends Error {
5
6
  code = 'native_module_unavailable';
@@ -8,12 +9,18 @@ export class BotaNativeModuleError extends Error {
8
9
  this.name = 'BotaNativeModuleError';
9
10
  }
10
11
  }
12
+ const formatAdvertisedMac = value => {
13
+ if (!value || !/^(?:[0-9a-f]{12}|(?:[0-9a-f]{2}:){5}[0-9a-f]{2})$/i.test(value)) {
14
+ return null;
15
+ }
16
+ return value.replace(/:/g, '').toUpperCase().match(/.{2}/g).join(':');
17
+ };
11
18
  const mapDiscoveredDevice = device => ({
12
19
  id: device.id,
13
20
  name: device.name ?? '',
14
21
  deviceType: device.deviceType ?? 'bota_pin',
15
22
  firmwareVersion: device.firmwareVersion ?? '',
16
- macAddress: device.macAddress ?? null,
23
+ macAddress: formatAdvertisedMac(device.macAddress),
17
24
  pairingState: device.pairingState ?? 'unpaired',
18
25
  rssi: device.rssi,
19
26
  discoveredAt: new Date(device.discoveredAtMs)
@@ -53,6 +60,41 @@ const createOpaqueId = () => 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy
53
60
  const nibble = value === 'x' ? random : random & 0x3 | 0x8;
54
61
  return nibble.toString(16);
55
62
  });
63
+ const catalogInteger = (value, maximum = BigInt(Number.MAX_SAFE_INTEGER)) => {
64
+ if (typeof value !== 'string' || !/^(0|[1-9][0-9]{0,19})$/.test(value) || BigInt(value) > maximum) {
65
+ throw new Error('invalid native recording catalog metadata');
66
+ }
67
+ return Number(value);
68
+ };
69
+ const mapPendingRecording = value => {
70
+ const uuidPattern = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
71
+ if (value.profile === 'legacy' && value.legacy && !value.encrypted) {
72
+ const recording = value.legacy;
73
+ if (typeof recording.uuid !== 'string' || !uuidPattern.test(recording.uuid) || !Number.isSafeInteger(recording.startedAtMs) || recording.startedAtMs < 0 || recording.startedAtMs > 8640000000000000 || !Number.isSafeInteger(recording.durationMs) || recording.durationMs < 0 || !Number.isSafeInteger(recording.fileSize) || recording.fileSize < 0 || typeof recording.codec !== 'string' || typeof recording.isEncrypted !== 'boolean') {
74
+ throw new Error('invalid native recording catalog metadata');
75
+ }
76
+ return mapRecording(recording);
77
+ }
78
+ if (value.profile !== 'encrypted_upload_v2' || !value.encrypted || value.legacy) {
79
+ throw new Error('invalid native recording catalog profile');
80
+ }
81
+ const recording = value.encrypted;
82
+ const plaintextLength = recording.plaintextLength;
83
+ if (typeof recording.uuid !== 'string' || !uuidPattern.test(recording.uuid) || recording.storageFormat !== 3 || typeof plaintextLength !== 'string' || !/^(0|[1-9][0-9]{0,19})$/.test(plaintextLength) || BigInt(plaintextLength) > 0xffffffffffffffffn || typeof recording.ciphertextLength !== 'string' || !/^[1-9][0-9]{0,19}$/.test(recording.ciphertextLength) || BigInt(recording.ciphertextLength) > 0xffffffffffffffffn || typeof recording.ciphertextSha256 !== 'string' || !/^[0-9a-f]{64}$/.test(recording.ciphertextSha256) || !Number.isInteger(recording.generation) || recording.generation < 0 || recording.generation > 0xffffffff) {
84
+ throw new Error('invalid native recording catalog identity');
85
+ }
86
+ return {
87
+ uuid: recording.uuid,
88
+ generation: recording.generation,
89
+ ciphertextLength: recording.ciphertextLength,
90
+ ciphertextSha256: recording.ciphertextSha256,
91
+ storageFormat: 3,
92
+ plaintextLength,
93
+ startedAtMs: recording.startedAtMs,
94
+ startedAt: new Date(catalogInteger(recording.startedAtMs, 8640000000000000n)),
95
+ durationMs: catalogInteger(recording.durationMs)
96
+ };
97
+ };
56
98
  const bytesToHex = value => Array.from(value, byte => byte.toString(16).padStart(2, '0')).join('');
57
99
  const toNativeConnectionSettings = settings => ({
58
100
  enabledConnections: settings.enabled_connections,
@@ -244,6 +286,9 @@ const toNativeRecordingUploadRequest = task => ({
244
286
  recordingId: task.recordingId,
245
287
  deviceId: task.deviceId,
246
288
  localPath: task.localPath,
289
+ ...(task.fileSizeBytes === undefined ? {} : {
290
+ fileSizeBytes: task.fileSizeBytes
291
+ }),
247
292
  uploadUrl: task.uploadUrl,
248
293
  ...(task.uploadToken ? {
249
294
  uploadToken: task.uploadToken
@@ -263,9 +308,12 @@ const toNativeRecordingUploadRequest = task => ({
263
308
  } : {})
264
309
  });
265
310
  const parseUploadQueue = serialized => {
266
- const value = JSON.parse(serialized || '[]');
267
- if (!Array.isArray(value)) return [];
311
+ const value = JSON.parse(serialized);
312
+ if (!Array.isArray(value)) throw new Error('Invalid upload recovery journal');
268
313
  return value.map(task => {
314
+ if (!task || typeof task !== 'object' || Array.isArray(task) || typeof task.createdAt !== 'string' || typeof task.updatedAt !== 'string') {
315
+ throw new Error('Invalid upload recovery journal');
316
+ }
269
317
  const candidate = task;
270
318
  return {
271
319
  ...candidate,
@@ -275,6 +323,8 @@ const parseUploadQueue = serialized => {
275
323
  });
276
324
  };
277
325
  export const createBotaDeviceSDK = nativeModule => {
326
+ let presenceStopped = false;
327
+ let presenceGeneration = 0;
278
328
  const requireNativeModule = () => {
279
329
  if (!nativeModule) throw new BotaNativeModuleError();
280
330
  return nativeModule;
@@ -494,6 +544,10 @@ export const createBotaDeviceSDK = nativeModule => {
494
544
  const values = await requireNativeModule().listRecordings(toNativeConnectedDevice(device));
495
545
  return values.map(mapRecording);
496
546
  },
547
+ async listPendingRecordings(device) {
548
+ const values = await requireNativeModule().listPendingRecordings(toNativeConnectedDevice(device));
549
+ return values.map(mapPendingRecording);
550
+ },
497
551
  async syncRecording(device, recording, onProgress, sinkId) {
498
552
  const module = requireNativeModule();
499
553
  const subscription = module.onRecordingTransferProgress(progress => {
@@ -505,38 +559,83 @@ export const createBotaDeviceSDK = nativeModule => {
505
559
  subscription.remove();
506
560
  }
507
561
  },
508
- async syncEncryptedRecordingV2(device, recording, provider, onProgress) {
562
+ async syncEncryptedRecordingV2(device, recording, provider, onProgress, options = {}) {
563
+ if (options.signal?.aborted) throw new Error('encrypted upload v2 cancelled');
509
564
  const module = requireNativeModule();
510
- const operationId = createOpaqueId();
511
- const profileSubscription = module.onEncryptedUploadV2ProfileRequested(request => {
512
- if (request.operationId !== operationId) return;
513
- void (async () => {
565
+ const operationId = options.operationId ?? createOpaqueId();
566
+ if (!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/.test(operationId)) {
567
+ throw new Error('invalid encrypted upload v2 operation ID');
568
+ }
569
+ let active = true;
570
+ let nativeStarted = false;
571
+ let cancellation;
572
+ let cancellationFailed = false;
573
+ const cancel = () => {
574
+ if (nativeStarted && !cancellation) {
514
575
  try {
515
- const decision = await provider({
516
- recording: request.recording,
517
- capability: request.capability,
518
- ...(request.checkpoint === undefined ? {} : {
519
- checkpoint: request.checkpoint
520
- })
576
+ cancellation = module.cancelEncryptedRecordingV2(operationId).catch(() => {
577
+ cancellationFailed = true;
521
578
  });
522
- if (decision.profile !== 'encrypted_upload_v2') {
523
- throw new Error('encrypted upload v2 requires an explicit v2 profile');
524
- }
525
- await module.resolveEncryptedUploadV2Profile(request.requestId, decision);
526
- } catch (error) {
527
- await module.rejectEncryptedUploadV2Profile(request.requestId, 'application_material_rejected');
579
+ } catch {
580
+ cancellationFailed = true;
528
581
  }
529
- })().catch(() => {});
530
- });
531
- const progressSubscription = module.onEncryptedUploadV2Progress(progress => {
532
- if (progress.operationId !== operationId) return;
533
- onProgress?.(mapEncryptedUploadV2Progress(progress));
534
- });
582
+ }
583
+ };
584
+ let profileSubscription;
585
+ let progressSubscription;
535
586
  try {
587
+ options.signal?.addEventListener('abort', cancel, {
588
+ once: true
589
+ });
590
+ profileSubscription = module.onEncryptedUploadV2ProfileRequested(request => {
591
+ if (!active || options.signal?.aborted || request.operationId !== operationId) return;
592
+ void (async () => {
593
+ let decision;
594
+ try {
595
+ decision = await provider({
596
+ operationId,
597
+ recording: request.recording,
598
+ capability: request.capability,
599
+ ...(request.checkpoint === undefined ? {} : {
600
+ checkpoint: request.checkpoint
601
+ })
602
+ });
603
+ if (!active || options.signal?.aborted) {
604
+ await module.releaseEncryptedUploadV2Material(decision.materialRegistrationId);
605
+ return;
606
+ }
607
+ if (decision.profile !== 'encrypted_upload_v2') {
608
+ throw new Error('encrypted upload v2 requires an explicit v2 profile');
609
+ }
610
+ await module.resolveEncryptedUploadV2Profile(request.requestId, decision);
611
+ } catch (error) {
612
+ if (decision) await module.releaseEncryptedUploadV2Material(decision.materialRegistrationId).catch(() => {});
613
+ if (active && !options.signal?.aborted) {
614
+ await module.rejectEncryptedUploadV2Profile(request.requestId, 'application_material_rejected');
615
+ }
616
+ }
617
+ })().catch(() => {});
618
+ });
619
+ progressSubscription = module.onEncryptedUploadV2Progress(progress => {
620
+ if (!active || options.signal?.aborted || progress.operationId !== operationId) return;
621
+ onProgress?.(mapEncryptedUploadV2Progress(progress));
622
+ });
623
+ if (options.signal?.aborted) throw new Error('encrypted upload v2 cancelled');
624
+ nativeStarted = true;
536
625
  await module.syncEncryptedRecordingV2(toNativeConnectedDevice(device), recording, operationId);
537
626
  } finally {
538
- profileSubscription.remove();
539
- progressSubscription.remove();
627
+ active = false;
628
+ let cleanupFailed = false;
629
+ for (const remove of [() => options.signal?.removeEventListener('abort', cancel), () => profileSubscription?.remove(), () => progressSubscription?.remove()]) {
630
+ try {
631
+ remove();
632
+ } catch {
633
+ cleanupFailed = true;
634
+ }
635
+ }
636
+ await cancellation;
637
+ if (cancellationFailed) throw new Error('encrypted upload v2 cancellation failed');
638
+ if (cleanupFailed) throw new Error('encrypted upload v2 listener cleanup failed');
540
639
  }
541
640
  },
542
641
  async uploadRecordingFile(task, onProgress) {
@@ -560,6 +659,9 @@ export const createBotaDeviceSDK = nativeModule => {
560
659
  async cancelRecordingUpload(taskId) {
561
660
  await requireNativeModule().cancelRecordingUpload(taskId);
562
661
  },
662
+ async releaseRecordingFile(taskId, localPath) {
663
+ await requireNativeModule().releaseRecordingFile(taskId, localPath);
664
+ },
563
665
  async loadUploadQueue() {
564
666
  return parseUploadQueue(await requireNativeModule().loadCompatibilityUploadQueue());
565
667
  },
@@ -642,6 +744,42 @@ export const createBotaDeviceSDK = nativeModule => {
642
744
  }
643
745
  };
644
746
  const logs = {
747
+ async readDiagnosticEvents(device) {
748
+ const batch = await requireNativeModule().readDiagnosticEvents(toNativeConnectedDevice(device));
749
+ if (batch.schema_version !== 1) throw new Error('Unsupported diagnostic batch schema');
750
+ return {
751
+ schema_version: 1,
752
+ events: batch.events.map(({
753
+ report,
754
+ ...event
755
+ }) => ({
756
+ ...event,
757
+ event_type: event.event_type,
758
+ reason_code: event.reason_code,
759
+ ...(report ? {
760
+ report: {
761
+ fault: report.fault,
762
+ execution: {
763
+ ...report.execution,
764
+ pc_trace: [...report.execution.pc_trace]
765
+ },
766
+ ...(report.runtime ? {
767
+ runtime: report.runtime
768
+ } : {}),
769
+ ...(report.breadcrumbs ? {
770
+ breadcrumbs: [...report.breadcrumbs]
771
+ } : {})
772
+ }
773
+ } : {})
774
+ }))
775
+ };
776
+ },
777
+ async acknowledgeDiagnosticEvents(device, acceptedEventIds) {
778
+ if (acceptedEventIds.some(id => !/^[0-9a-f]{16}$/.test(id))) {
779
+ throw new Error('Diagnostic event_id must be 16 lowercase hex characters');
780
+ }
781
+ await requireNativeModule().acknowledgeDiagnosticEvents(toNativeConnectedDevice(device), [...acceptedEventIds]);
782
+ },
645
783
  async subscribe(device, onLine) {
646
784
  const module = requireNativeModule();
647
785
  const eventSubscription = module.onDeviceLog(line => {
@@ -704,6 +842,19 @@ export const createBotaDeviceSDK = nativeModule => {
704
842
  }
705
843
  };
706
844
  const client = {
845
+ clientPresence: {
846
+ async nextReport(deviceId) {
847
+ if (presenceStopped) return null;
848
+ const generation = presenceGeneration;
849
+ const report = await requireNativeModule().nextClientPresence(deviceId);
850
+ if (presenceStopped || generation !== presenceGeneration) return null;
851
+ return report === null ? null : {
852
+ ...report,
853
+ sdkPackage: SDK_PACKAGE,
854
+ sdkVersion: SDK_VERSION
855
+ };
856
+ }
857
+ },
707
858
  controls,
708
859
  devices,
709
860
  factoryReset,
@@ -714,6 +865,7 @@ export const createBotaDeviceSDK = nativeModule => {
714
865
  streaming,
715
866
  wifi,
716
867
  async configure(configuration = {}) {
868
+ const generation = presenceGeneration;
717
869
  const nativeConfiguration = {
718
870
  logLevel: configuration.logLevel ?? 'warn',
719
871
  ...(configuration.applicationSupportDirectory ? {
@@ -721,8 +873,11 @@ export const createBotaDeviceSDK = nativeModule => {
721
873
  } : {})
722
874
  };
723
875
  await requireNativeModule().configure(nativeConfiguration);
876
+ if (generation === presenceGeneration) presenceStopped = false;
724
877
  },
725
878
  async destroy() {
879
+ presenceStopped = true;
880
+ presenceGeneration++;
726
881
  await requireNativeModule().destroy();
727
882
  },
728
883
  async getCapabilities() {