@bota.dev/react-native-app-sdk 2.0.0-beta.0
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/BotaDeviceSDK.podspec +55 -0
- package/LICENSE +21 -0
- package/README.md +101 -0
- package/android/build.gradle +76 -0
- package/android/src/main/AndroidManifest.xml +1 -0
- package/android/src/main/java/dev/bota/sdk/reactnative/BotaDeviceSDKAndroidDevices.kt +172 -0
- package/android/src/main/java/dev/bota/sdk/reactnative/BotaDeviceSDKAndroidLifecycle.kt +100 -0
- package/android/src/main/java/dev/bota/sdk/reactnative/BotaDeviceSDKAndroidLogs.kt +82 -0
- package/android/src/main/java/dev/bota/sdk/reactnative/BotaDeviceSDKAndroidModels.kt +476 -0
- package/android/src/main/java/dev/bota/sdk/reactnative/BotaDeviceSDKAndroidOTA.kt +58 -0
- package/android/src/main/java/dev/bota/sdk/reactnative/BotaDeviceSDKAndroidRecordingUploads.kt +180 -0
- package/android/src/main/java/dev/bota/sdk/reactnative/BotaDeviceSDKAndroidRecordings.kt +751 -0
- package/android/src/main/java/dev/bota/sdk/reactnative/BotaDeviceSDKAndroidSecurity.kt +509 -0
- package/android/src/main/java/dev/bota/sdk/reactnative/BotaDeviceSDKAndroidWiFi.kt +125 -0
- package/android/src/main/java/dev/bota/sdk/reactnative/BotaDeviceSDKEncryptedUploadV2Materials.kt +46 -0
- package/android/src/main/java/dev/bota/sdk/reactnative/BotaDeviceSDKModule.kt +723 -0
- package/android/src/main/java/dev/bota/sdk/reactnative/BotaDeviceSDKPackage.kt +33 -0
- package/android/src/test/java/dev/bota/sdk/reactnative/BotaDeviceSDKAndroidDevicesTest.kt +211 -0
- package/android/src/test/java/dev/bota/sdk/reactnative/BotaDeviceSDKAndroidLifecycleTest.kt +132 -0
- package/android/src/test/java/dev/bota/sdk/reactnative/BotaDeviceSDKAndroidLogsTest.kt +57 -0
- package/android/src/test/java/dev/bota/sdk/reactnative/BotaDeviceSDKAndroidOTATest.kt +75 -0
- package/android/src/test/java/dev/bota/sdk/reactnative/BotaDeviceSDKAndroidRecordingUploadsTest.kt +147 -0
- package/android/src/test/java/dev/bota/sdk/reactnative/BotaDeviceSDKAndroidRecordingsTest.kt +355 -0
- package/android/src/test/java/dev/bota/sdk/reactnative/BotaDeviceSDKAndroidSecurityTest.kt +523 -0
- package/android/src/test/java/dev/bota/sdk/reactnative/BotaDeviceSDKAndroidWiFiTest.kt +100 -0
- package/generated/codegen-contract.json +3593 -0
- package/ios/BotaDeviceSDK.mm +1300 -0
- package/ios/BotaDeviceSDKAppleBridge.swift +2260 -0
- package/ios/BotaDeviceSDKAppleDevices.swift +191 -0
- package/ios/BotaDeviceSDKAppleLifecycle.swift +167 -0
- package/ios/BotaDeviceSDKAppleLogs.swift +79 -0
- package/ios/BotaDeviceSDKAppleOTA.swift +73 -0
- package/ios/BotaDeviceSDKAppleRecordingUploads.swift +178 -0
- package/ios/BotaDeviceSDKAppleRecordings.swift +670 -0
- package/ios/BotaDeviceSDKAppleSecurity.swift +586 -0
- package/ios/BotaDeviceSDKAppleWiFi.swift +128 -0
- package/ios/BotaDeviceSDKEncryptedUploadV2Materials.swift +99 -0
- package/lib/commonjs/BotaClient.js +194 -0
- package/lib/commonjs/BotaClient.js.map +1 -0
- package/lib/commonjs/ble/constants.js +10 -0
- package/lib/commonjs/ble/constants.js.map +1 -0
- package/lib/commonjs/ble/deviceLogs.js +50 -0
- package/lib/commonjs/ble/deviceLogs.js.map +1 -0
- package/lib/commonjs/cache/DeviceStateCache.js +6 -0
- package/lib/commonjs/cache/DeviceStateCache.js.map +1 -0
- package/lib/commonjs/client.js +746 -0
- package/lib/commonjs/client.js.map +1 -0
- package/lib/commonjs/compatibility/runtime.js +44 -0
- package/lib/commonjs/compatibility/runtime.js.map +1 -0
- package/lib/commonjs/index.js +123 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/managers/DeviceManager.js +647 -0
- package/lib/commonjs/managers/DeviceManager.js.map +1 -0
- package/lib/commonjs/managers/OTAManager.js +140 -0
- package/lib/commonjs/managers/OTAManager.js.map +1 -0
- package/lib/commonjs/managers/RecordingManager.js +444 -0
- package/lib/commonjs/managers/RecordingManager.js.map +1 -0
- package/lib/commonjs/managers/StreamingSession.js +175 -0
- package/lib/commonjs/managers/StreamingSession.js.map +1 -0
- package/lib/commonjs/managers/types.js +6 -0
- package/lib/commonjs/managers/types.js.map +1 -0
- package/lib/commonjs/models/Device.js +2 -0
- package/lib/commonjs/models/Device.js.map +1 -0
- package/lib/commonjs/models/Recording.js +2 -0
- package/lib/commonjs/models/Recording.js.map +1 -0
- package/lib/commonjs/models/Status.js +6 -0
- package/lib/commonjs/models/Status.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/specs/NativeBotaDeviceSDK.js +9 -0
- package/lib/commonjs/specs/NativeBotaDeviceSDK.js.map +1 -0
- package/lib/commonjs/sync/syncStatus.js +178 -0
- package/lib/commonjs/sync/syncStatus.js.map +1 -0
- package/lib/commonjs/utils/errors.js +194 -0
- package/lib/commonjs/utils/errors.js.map +1 -0
- package/lib/commonjs/utils/logger.js +84 -0
- package/lib/commonjs/utils/logger.js.map +1 -0
- package/lib/module/BotaClient.js +189 -0
- package/lib/module/BotaClient.js.map +1 -0
- package/lib/module/ble/constants.js +6 -0
- package/lib/module/ble/constants.js.map +1 -0
- package/lib/module/ble/deviceLogs.js +45 -0
- package/lib/module/ble/deviceLogs.js.map +1 -0
- package/lib/module/cache/DeviceStateCache.js +4 -0
- package/lib/module/cache/DeviceStateCache.js.map +1 -0
- package/lib/module/client.js +740 -0
- package/lib/module/client.js.map +1 -0
- package/lib/module/compatibility/runtime.js +35 -0
- package/lib/module/compatibility/runtime.js.map +1 -0
- package/lib/module/index.js +17 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/managers/DeviceManager.js +641 -0
- package/lib/module/managers/DeviceManager.js.map +1 -0
- package/lib/module/managers/OTAManager.js +134 -0
- package/lib/module/managers/OTAManager.js.map +1 -0
- package/lib/module/managers/RecordingManager.js +438 -0
- package/lib/module/managers/RecordingManager.js.map +1 -0
- package/lib/module/managers/StreamingSession.js +168 -0
- package/lib/module/managers/StreamingSession.js.map +1 -0
- package/lib/module/managers/types.js +4 -0
- package/lib/module/managers/types.js.map +1 -0
- package/lib/module/models/Device.js +2 -0
- package/lib/module/models/Device.js.map +1 -0
- package/lib/module/models/Recording.js +2 -0
- package/lib/module/models/Recording.js.map +1 -0
- package/lib/module/models/Status.js +4 -0
- package/lib/module/models/Status.js.map +1 -0
- package/lib/module/specs/NativeBotaDeviceSDK.js +5 -0
- package/lib/module/specs/NativeBotaDeviceSDK.js.map +1 -0
- package/lib/module/sync/syncStatus.js +174 -0
- package/lib/module/sync/syncStatus.js.map +1 -0
- package/lib/module/utils/errors.js +183 -0
- package/lib/module/utils/errors.js.map +1 -0
- package/lib/module/utils/logger.js +80 -0
- package/lib/module/utils/logger.js.map +1 -0
- package/lib/typescript/BotaClient.d.ts +40 -0
- package/lib/typescript/BotaClient.d.ts.map +1 -0
- package/lib/typescript/ble/constants.d.ts +4 -0
- package/lib/typescript/ble/constants.d.ts.map +1 -0
- package/lib/typescript/ble/deviceLogs.d.ts +10 -0
- package/lib/typescript/ble/deviceLogs.d.ts.map +1 -0
- package/lib/typescript/cache/DeviceStateCache.d.ts +14 -0
- package/lib/typescript/cache/DeviceStateCache.d.ts.map +1 -0
- package/lib/typescript/client.d.ts +208 -0
- package/lib/typescript/client.d.ts.map +1 -0
- package/lib/typescript/compatibility/runtime.d.ts +11 -0
- package/lib/typescript/compatibility/runtime.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +19 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/managers/DeviceManager.d.ts +117 -0
- package/lib/typescript/managers/DeviceManager.d.ts.map +1 -0
- package/lib/typescript/managers/OTAManager.d.ts +25 -0
- package/lib/typescript/managers/OTAManager.d.ts.map +1 -0
- package/lib/typescript/managers/RecordingManager.d.ts +54 -0
- package/lib/typescript/managers/RecordingManager.d.ts.map +1 -0
- package/lib/typescript/managers/StreamingSession.d.ts +35 -0
- package/lib/typescript/managers/StreamingSession.d.ts.map +1 -0
- package/lib/typescript/managers/types.d.ts +19 -0
- package/lib/typescript/managers/types.d.ts.map +1 -0
- package/lib/typescript/models/Device.d.ts +392 -0
- package/lib/typescript/models/Device.d.ts.map +1 -0
- package/lib/typescript/models/Recording.d.ts +259 -0
- package/lib/typescript/models/Recording.d.ts.map +1 -0
- package/lib/typescript/models/Status.d.ts +106 -0
- package/lib/typescript/models/Status.d.ts.map +1 -0
- package/lib/typescript/specs/NativeBotaDeviceSDK.d.ts +393 -0
- package/lib/typescript/specs/NativeBotaDeviceSDK.d.ts.map +1 -0
- package/lib/typescript/sync/syncStatus.d.ts +123 -0
- package/lib/typescript/sync/syncStatus.d.ts.map +1 -0
- package/lib/typescript/utils/errors.d.ts +83 -0
- package/lib/typescript/utils/errors.d.ts.map +1 -0
- package/lib/typescript/utils/logger.d.ts +36 -0
- package/lib/typescript/utils/logger.d.ts.map +1 -0
- package/package.json +100 -0
- package/scripts/bota_device_sdk_spm_workaround.rb +53 -0
- package/src/BotaClient.ts +231 -0
- package/src/ble/constants.ts +3 -0
- package/src/ble/deviceLogs.ts +61 -0
- package/src/cache/DeviceStateCache.ts +20 -0
- package/src/client.ts +1410 -0
- package/src/compatibility/runtime.ts +55 -0
- package/src/index.ts +146 -0
- package/src/managers/DeviceManager.ts +927 -0
- package/src/managers/OTAManager.ts +195 -0
- package/src/managers/RecordingManager.ts +578 -0
- package/src/managers/StreamingSession.ts +212 -0
- package/src/managers/types.ts +36 -0
- package/src/models/Device.ts +484 -0
- package/src/models/Recording.ts +281 -0
- package/src/models/Status.ts +128 -0
- package/src/specs/NativeBotaDeviceSDK.ts +542 -0
- package/src/sync/syncStatus.ts +243 -0
- package/src/utils/errors.ts +327 -0
- package/src/utils/logger.ts +122 -0
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.UploadError = exports.TransferError = exports.SdkError = exports.ProvisioningError = exports.DeviceError = exports.BotaError = exports.BluetoothError = void 0;
|
|
7
|
+
exports.isBotaError = isBotaError;
|
|
8
|
+
var _constants = require("../ble/constants");
|
|
9
|
+
/**
|
|
10
|
+
* Custom error types for the Bota SDK
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Base error class for all Bota SDK errors
|
|
15
|
+
*/
|
|
16
|
+
class BotaError extends Error {
|
|
17
|
+
constructor(message, code, cause) {
|
|
18
|
+
super(message);
|
|
19
|
+
this.code = code;
|
|
20
|
+
this.cause = cause;
|
|
21
|
+
this.name = 'BotaError';
|
|
22
|
+
Object.setPrototypeOf(this, BotaError.prototype);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Bluetooth-related errors
|
|
28
|
+
*/
|
|
29
|
+
exports.BotaError = BotaError;
|
|
30
|
+
class BluetoothError extends BotaError {
|
|
31
|
+
constructor(message, code, cause) {
|
|
32
|
+
super(message, code, cause);
|
|
33
|
+
this.name = 'BluetoothError';
|
|
34
|
+
Object.setPrototypeOf(this, BluetoothError.prototype);
|
|
35
|
+
}
|
|
36
|
+
static unavailable() {
|
|
37
|
+
return new BluetoothError('Bluetooth is not available on this device', 'BLUETOOTH_UNAVAILABLE');
|
|
38
|
+
}
|
|
39
|
+
static unauthorized() {
|
|
40
|
+
return new BluetoothError('Bluetooth permission not granted', 'BLUETOOTH_UNAUTHORIZED');
|
|
41
|
+
}
|
|
42
|
+
static poweredOff() {
|
|
43
|
+
return new BluetoothError('Bluetooth is powered off', 'BLUETOOTH_OFF');
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Device-related errors
|
|
49
|
+
*/
|
|
50
|
+
exports.BluetoothError = BluetoothError;
|
|
51
|
+
class DeviceError extends BotaError {
|
|
52
|
+
constructor(message, code, deviceId, cause) {
|
|
53
|
+
super(message, code, cause);
|
|
54
|
+
this.deviceId = deviceId;
|
|
55
|
+
this.name = 'DeviceError';
|
|
56
|
+
Object.setPrototypeOf(this, DeviceError.prototype);
|
|
57
|
+
}
|
|
58
|
+
static notFound(deviceId) {
|
|
59
|
+
return new DeviceError(`Device ${deviceId} not found`, 'DEVICE_NOT_FOUND', deviceId);
|
|
60
|
+
}
|
|
61
|
+
static connectionFailed(deviceId, cause) {
|
|
62
|
+
return new DeviceError(`Failed to connect to device ${deviceId}`, 'CONNECTION_FAILED', deviceId, cause);
|
|
63
|
+
}
|
|
64
|
+
static connectionLost(deviceId, during) {
|
|
65
|
+
const message = during ? `Connection to device ${deviceId} lost during ${during}` : `Connection to device ${deviceId} lost`;
|
|
66
|
+
return new DeviceError(message, 'CONNECTION_LOST', deviceId);
|
|
67
|
+
}
|
|
68
|
+
static bondingFailed(deviceId, cause) {
|
|
69
|
+
return new DeviceError(`Bonding failed for device ${deviceId}`, 'BONDING_FAILED', deviceId, cause);
|
|
70
|
+
}
|
|
71
|
+
static notConnected(deviceId) {
|
|
72
|
+
return new DeviceError(`Device ${deviceId} is not connected`, 'NOT_CONNECTED', deviceId);
|
|
73
|
+
}
|
|
74
|
+
static alreadyConnected(deviceId) {
|
|
75
|
+
return new DeviceError(`Device ${deviceId} is already connected`, 'ALREADY_CONNECTED', deviceId);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Provisioning-related errors
|
|
81
|
+
*/
|
|
82
|
+
exports.DeviceError = DeviceError;
|
|
83
|
+
class ProvisioningError extends BotaError {
|
|
84
|
+
constructor(message, code, deviceId, cause) {
|
|
85
|
+
super(message, code, cause);
|
|
86
|
+
this.deviceId = deviceId;
|
|
87
|
+
this.name = 'ProvisioningError';
|
|
88
|
+
Object.setPrototypeOf(this, ProvisioningError.prototype);
|
|
89
|
+
}
|
|
90
|
+
static invalidToken(deviceId) {
|
|
91
|
+
return new ProvisioningError('Device rejected the token as invalid', 'INVALID_TOKEN', deviceId);
|
|
92
|
+
}
|
|
93
|
+
static storageError(deviceId) {
|
|
94
|
+
return new ProvisioningError('Device failed to store the token', 'STORAGE_ERROR', deviceId);
|
|
95
|
+
}
|
|
96
|
+
static chunkError(deviceId) {
|
|
97
|
+
return new ProvisioningError('Token chunk transfer failed', 'CHUNK_ERROR', deviceId);
|
|
98
|
+
}
|
|
99
|
+
static alreadyProvisioned(deviceId) {
|
|
100
|
+
return new ProvisioningError('Device is already provisioned', 'ALREADY_PROVISIONED', deviceId);
|
|
101
|
+
}
|
|
102
|
+
static alreadyPaired(deviceId) {
|
|
103
|
+
return new ProvisioningError('Device is already paired with another credential. Factory reset the device before re-provisioning.', 'ALREADY_PAIRED', deviceId);
|
|
104
|
+
}
|
|
105
|
+
static timeout(deviceId) {
|
|
106
|
+
return new ProvisioningError('Provisioning timed out waiting for device response', 'PROVISIONING_TIMEOUT', deviceId);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Transfer-related errors
|
|
112
|
+
*/
|
|
113
|
+
exports.ProvisioningError = ProvisioningError;
|
|
114
|
+
class TransferError extends BotaError {
|
|
115
|
+
constructor(message, code, recordingUuid, cause) {
|
|
116
|
+
super(message, code, cause);
|
|
117
|
+
this.recordingUuid = recordingUuid;
|
|
118
|
+
this.name = 'TransferError';
|
|
119
|
+
Object.setPrototypeOf(this, TransferError.prototype);
|
|
120
|
+
}
|
|
121
|
+
static recordingNotFound(uuid) {
|
|
122
|
+
return new TransferError(`Recording ${uuid} not found on device`, 'RECORDING_NOT_FOUND', uuid);
|
|
123
|
+
}
|
|
124
|
+
static checksumMismatch(uuid) {
|
|
125
|
+
return new TransferError(`Checksum mismatch for recording ${uuid}`, 'CHECKSUM_MISMATCH', uuid);
|
|
126
|
+
}
|
|
127
|
+
static interrupted(uuid, cause) {
|
|
128
|
+
return new TransferError(`Transfer interrupted for recording ${uuid}`, 'TRANSFER_INTERRUPTED', uuid, cause);
|
|
129
|
+
}
|
|
130
|
+
static timeout(uuid) {
|
|
131
|
+
return new TransferError(`Transfer timed out for recording ${uuid}`, 'TRANSFER_TIMEOUT', uuid);
|
|
132
|
+
}
|
|
133
|
+
static deviceError(uuid, errorCode) {
|
|
134
|
+
if (errorCode === _constants.BLE_ERROR_STORAGE_KEY_UNAVAILABLE) {
|
|
135
|
+
return new TransferError(`Recording ${uuid} exists, but its device storage key is unavailable`, 'STORAGE_KEY_UNAVAILABLE', uuid);
|
|
136
|
+
}
|
|
137
|
+
return new TransferError(`Device error (code: ${errorCode}) during transfer of ${uuid}`, 'DEVICE_ERROR', uuid);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Upload-related errors
|
|
143
|
+
*/
|
|
144
|
+
exports.TransferError = TransferError;
|
|
145
|
+
class UploadError extends BotaError {
|
|
146
|
+
constructor(message, code, taskId, cause) {
|
|
147
|
+
super(message, code, cause);
|
|
148
|
+
this.taskId = taskId;
|
|
149
|
+
this.name = 'UploadError';
|
|
150
|
+
Object.setPrototypeOf(this, UploadError.prototype);
|
|
151
|
+
}
|
|
152
|
+
static urlExpired(taskId) {
|
|
153
|
+
return new UploadError('Upload URL has expired', 'URL_EXPIRED', taskId);
|
|
154
|
+
}
|
|
155
|
+
static networkUnavailable() {
|
|
156
|
+
return new UploadError('Network is not available', 'NETWORK_UNAVAILABLE');
|
|
157
|
+
}
|
|
158
|
+
static uploadFailed(taskId, cause) {
|
|
159
|
+
return new UploadError(`Upload failed for task ${taskId}`, 'UPLOAD_FAILED', taskId, cause);
|
|
160
|
+
}
|
|
161
|
+
static completionFailed(taskId, cause) {
|
|
162
|
+
return new UploadError(`Failed to notify completion for task ${taskId}`, 'COMPLETION_FAILED', taskId, cause);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* SDK state errors
|
|
168
|
+
*/
|
|
169
|
+
exports.UploadError = UploadError;
|
|
170
|
+
class SdkError extends BotaError {
|
|
171
|
+
constructor(message, code, cause) {
|
|
172
|
+
super(message, code, cause);
|
|
173
|
+
this.name = 'SdkError';
|
|
174
|
+
Object.setPrototypeOf(this, SdkError.prototype);
|
|
175
|
+
}
|
|
176
|
+
static notInitialized() {
|
|
177
|
+
return new SdkError('SDK has not been initialized. Call BotaClient.configure() first.', 'NOT_INITIALIZED');
|
|
178
|
+
}
|
|
179
|
+
static invalidState(expected, actual) {
|
|
180
|
+
return new SdkError(`Invalid state: expected ${expected}, got ${actual}`, 'INVALID_STATE');
|
|
181
|
+
}
|
|
182
|
+
static timeout(operation) {
|
|
183
|
+
return new SdkError(`Operation timed out: ${operation}`, 'TIMEOUT');
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Type guard to check if an error is a BotaError
|
|
189
|
+
*/
|
|
190
|
+
exports.SdkError = SdkError;
|
|
191
|
+
function isBotaError(error) {
|
|
192
|
+
return error instanceof BotaError;
|
|
193
|
+
}
|
|
194
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_constants","require","BotaError","Error","constructor","message","code","cause","name","Object","setPrototypeOf","prototype","exports","BluetoothError","unavailable","unauthorized","poweredOff","DeviceError","deviceId","notFound","connectionFailed","connectionLost","during","bondingFailed","notConnected","alreadyConnected","ProvisioningError","invalidToken","storageError","chunkError","alreadyProvisioned","alreadyPaired","timeout","TransferError","recordingUuid","recordingNotFound","uuid","checksumMismatch","interrupted","deviceError","errorCode","BLE_ERROR_STORAGE_KEY_UNAVAILABLE","UploadError","taskId","urlExpired","networkUnavailable","uploadFailed","completionFailed","SdkError","notInitialized","invalidState","expected","actual","operation","isBotaError","error"],"sourceRoot":"../../../src","sources":["ut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F,CAAC;EACH;EAEA,OAAOpB,OAAOA,CAACqB,SAAiB,EAAY;IAC1C,OAAO,IAAIL,QAAQ,CAAC,wBAAwBK,SAAS,EAAE,EAAE,SAAS,CAAC;EACrE;AACF;;AAEA;AACA;AACA;AAFAzC,OAAA,CAAAoC,QAAA,GAAAA,QAAA;AAGO,SAASM,WAAWA,CAACC,KAAc,EAAsB;EAC9D,OAAOA,KAAK,YAAYrD,SAAS;AACnC","ignoreList":[]}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.logger = void 0;
|
|
7
|
+
const LOG_LEVELS = {
|
|
8
|
+
debug: 0,
|
|
9
|
+
info: 1,
|
|
10
|
+
warn: 2,
|
|
11
|
+
error: 3,
|
|
12
|
+
none: 4
|
|
13
|
+
};
|
|
14
|
+
class Logger {
|
|
15
|
+
level = 'warn';
|
|
16
|
+
prefix = '[Bota SDK]';
|
|
17
|
+
handler = null;
|
|
18
|
+
setLevel(level) {
|
|
19
|
+
this.level = level;
|
|
20
|
+
}
|
|
21
|
+
getLevel() {
|
|
22
|
+
return this.level;
|
|
23
|
+
}
|
|
24
|
+
setHandler(handler) {
|
|
25
|
+
this.handler = handler;
|
|
26
|
+
}
|
|
27
|
+
debug(message, context) {
|
|
28
|
+
this.write('debug', message, context);
|
|
29
|
+
}
|
|
30
|
+
info(message, context) {
|
|
31
|
+
this.write('info', message, context);
|
|
32
|
+
}
|
|
33
|
+
warn(message, context) {
|
|
34
|
+
this.write('warn', message, context);
|
|
35
|
+
}
|
|
36
|
+
error(message, error, context) {
|
|
37
|
+
this.write('error', message, error ? {
|
|
38
|
+
...context,
|
|
39
|
+
error: error.message,
|
|
40
|
+
stack: error.stack
|
|
41
|
+
} : context);
|
|
42
|
+
}
|
|
43
|
+
tag(tag) {
|
|
44
|
+
return new TaggedLogger(this, tag);
|
|
45
|
+
}
|
|
46
|
+
write(level, message, context) {
|
|
47
|
+
if (LOG_LEVELS[level] < LOG_LEVELS[this.level]) return;
|
|
48
|
+
if (this.handler) {
|
|
49
|
+
this.handler({
|
|
50
|
+
level,
|
|
51
|
+
message,
|
|
52
|
+
context,
|
|
53
|
+
timestamp: new Date()
|
|
54
|
+
});
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const output = this.format(level, message, context);
|
|
58
|
+
console[level](output);
|
|
59
|
+
}
|
|
60
|
+
format(level, message, context) {
|
|
61
|
+
const contextValue = context ? ` ${JSON.stringify(context)}` : '';
|
|
62
|
+
return `${new Date().toISOString()} ${this.prefix} [${level.toUpperCase()}] ${message}${contextValue}`;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
class TaggedLogger {
|
|
66
|
+
constructor(parent, tagValue) {
|
|
67
|
+
this.parent = parent;
|
|
68
|
+
this.tagValue = tagValue;
|
|
69
|
+
}
|
|
70
|
+
debug(message, context) {
|
|
71
|
+
this.parent.debug(`[${this.tagValue}] ${message}`, context);
|
|
72
|
+
}
|
|
73
|
+
info(message, context) {
|
|
74
|
+
this.parent.info(`[${this.tagValue}] ${message}`, context);
|
|
75
|
+
}
|
|
76
|
+
warn(message, context) {
|
|
77
|
+
this.parent.warn(`[${this.tagValue}] ${message}`, context);
|
|
78
|
+
}
|
|
79
|
+
error(message, error, context) {
|
|
80
|
+
this.parent.error(`[${this.tagValue}] ${message}`, error, context);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
const logger = exports.logger = new Logger();
|
|
84
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["LOG_LEVELS","debug","info","warn","error","none","Logger","level","prefix","handler","setLevel","getLevel","setHandler","message","context","write","stack","tag","TaggedLogger","timestamp","Date","output","format","console","contextValue","JSON","stringify","toISOString","toUpperCase","constructor","parent","tagValue","logger","exports"],"sourceRoot":"../../../src","sources":["utils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AO,EAAE,EAAEC,OAAO,CAAC;EAC5D;EAEAX,IAAIA,CAACU,OAAe,EAAEC,OAAiC,EAAQ;IAC7D,IAAI,CAACgB,MAAM,CAAC3B,IAAI,CAAC,IAAI,IAAI,CAAC4B,QAAQ,KAAKlB,OAAO,EAAE,EAAEC,OAAO,CAAC;EAC5D;EAEAV,KAAKA,CACHS,OAAe,EACfT,KAAa,EACbU,OAAiC,EAC3B;IACN,IAAI,CAACgB,MAAM,CAAC1B,KAAK,CAAC,IAAI,IAAI,CAAC2B,QAAQ,KAAKlB,OAAO,EAAE,EAAET,KAAK,EAAEU,OAAO,CAAC;EACpE;AACF;AAEO,MAAMkB,MAAM,GAAAC,OAAA,CAAAD,MAAA,GAAG,IAAI1B,MAAM,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import EventEmitter from 'eventemitter3';
|
|
4
|
+
import { getCompatibilityClient } from './compatibility/runtime';
|
|
5
|
+
import { DeviceManager } from './managers/DeviceManager';
|
|
6
|
+
import { OTAManager } from './managers/OTAManager';
|
|
7
|
+
import { RecordingManager } from './managers/RecordingManager';
|
|
8
|
+
import { BluetoothError, SdkError } from './utils/errors';
|
|
9
|
+
import { logger } from './utils/logger';
|
|
10
|
+
const log = logger.tag('BotaClient');
|
|
11
|
+
const normalizeConfig = config => ({
|
|
12
|
+
environment: config.environment ?? 'production',
|
|
13
|
+
backgroundSyncEnabled: config.backgroundSyncEnabled ?? true,
|
|
14
|
+
wifiOnlyUpload: config.wifiOnlyUpload ?? false,
|
|
15
|
+
logLevel: config.logLevel ?? 'warn',
|
|
16
|
+
debug: config.debug ?? false
|
|
17
|
+
});
|
|
18
|
+
class BotaClientImpl extends EventEmitter {
|
|
19
|
+
_config = null;
|
|
20
|
+
_state = 'uninitialized';
|
|
21
|
+
_bluetoothState = 'unknown';
|
|
22
|
+
_client = null;
|
|
23
|
+
_deviceManager = null;
|
|
24
|
+
_recordingManager = null;
|
|
25
|
+
_otaManager = null;
|
|
26
|
+
_nativeOwned = false;
|
|
27
|
+
_operation = Promise.resolve();
|
|
28
|
+
_configurePromise = null;
|
|
29
|
+
_destroyPromise = null;
|
|
30
|
+
get state() {
|
|
31
|
+
return this._state;
|
|
32
|
+
}
|
|
33
|
+
get bluetoothState() {
|
|
34
|
+
return this._bluetoothState;
|
|
35
|
+
}
|
|
36
|
+
get isBluetoothReady() {
|
|
37
|
+
return this._bluetoothState === 'poweredOn';
|
|
38
|
+
}
|
|
39
|
+
get isInitialized() {
|
|
40
|
+
return this._state === 'ready';
|
|
41
|
+
}
|
|
42
|
+
get config() {
|
|
43
|
+
return this._config;
|
|
44
|
+
}
|
|
45
|
+
get devices() {
|
|
46
|
+
if (!this._deviceManager) throw SdkError.notInitialized();
|
|
47
|
+
return this._deviceManager;
|
|
48
|
+
}
|
|
49
|
+
get recordings() {
|
|
50
|
+
if (!this._recordingManager) throw SdkError.notInitialized();
|
|
51
|
+
return this._recordingManager;
|
|
52
|
+
}
|
|
53
|
+
get ota() {
|
|
54
|
+
if (!this._otaManager) throw SdkError.notInitialized();
|
|
55
|
+
return this._otaManager;
|
|
56
|
+
}
|
|
57
|
+
configure(config = {}) {
|
|
58
|
+
if (this._configurePromise && !this._destroyPromise) {
|
|
59
|
+
return this._configurePromise;
|
|
60
|
+
}
|
|
61
|
+
const normalized = normalizeConfig(config);
|
|
62
|
+
const operation = this.enqueue(() => this.performConfigure(normalized));
|
|
63
|
+
this._configurePromise = operation;
|
|
64
|
+
void operation.finally(() => {
|
|
65
|
+
if (this._configurePromise === operation) this._configurePromise = null;
|
|
66
|
+
}).catch(() => undefined);
|
|
67
|
+
return operation;
|
|
68
|
+
}
|
|
69
|
+
async waitForBluetooth(timeoutMs = 10000) {
|
|
70
|
+
if (!this._client || !this._nativeOwned) throw SdkError.notInitialized();
|
|
71
|
+
if (this._bluetoothState === 'poweredOn') return;
|
|
72
|
+
if (this._bluetoothState === 'unsupported') {
|
|
73
|
+
throw BluetoothError.unavailable();
|
|
74
|
+
}
|
|
75
|
+
const deadline = Date.now() + timeoutMs;
|
|
76
|
+
while (Date.now() < deadline) {
|
|
77
|
+
await new Promise(resolve => setTimeout(() => resolve(), 50));
|
|
78
|
+
const capabilities = await this._client.getCapabilities();
|
|
79
|
+
const state = capabilities.bluetooth ? 'poweredOn' : 'unsupported';
|
|
80
|
+
this.setBluetoothState(state);
|
|
81
|
+
if (state === 'poweredOn') return;
|
|
82
|
+
if (state === 'unsupported') {
|
|
83
|
+
throw BluetoothError.unavailable();
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
throw SdkError.timeout('Bluetooth ready');
|
|
87
|
+
}
|
|
88
|
+
setLogLevel(level) {
|
|
89
|
+
logger.setLevel(level);
|
|
90
|
+
if (this._config) this._config.logLevel = level;
|
|
91
|
+
}
|
|
92
|
+
setLogHandler(handler) {
|
|
93
|
+
logger.setHandler(handler);
|
|
94
|
+
}
|
|
95
|
+
destroy() {
|
|
96
|
+
if (this._destroyPromise) return this._destroyPromise;
|
|
97
|
+
const operation = this.enqueue(async () => {
|
|
98
|
+
await this.releaseOwnerGraph();
|
|
99
|
+
this.removeAllListeners();
|
|
100
|
+
});
|
|
101
|
+
this._destroyPromise = operation;
|
|
102
|
+
void operation.finally(() => {
|
|
103
|
+
if (this._destroyPromise === operation) this._destroyPromise = null;
|
|
104
|
+
}).catch(() => undefined);
|
|
105
|
+
return operation;
|
|
106
|
+
}
|
|
107
|
+
enqueue(operation) {
|
|
108
|
+
const queued = this._operation.catch(() => undefined).then(operation);
|
|
109
|
+
this._operation = queued.catch(() => undefined);
|
|
110
|
+
return queued;
|
|
111
|
+
}
|
|
112
|
+
async performConfigure(config) {
|
|
113
|
+
if (this._state !== 'uninitialized' || this._nativeOwned) {
|
|
114
|
+
log.warn('SDK already configured, reconfiguring');
|
|
115
|
+
await this.releaseOwnerGraph();
|
|
116
|
+
}
|
|
117
|
+
this._config = config;
|
|
118
|
+
logger.setLevel(config.logLevel);
|
|
119
|
+
this.setState('initializing');
|
|
120
|
+
const client = getCompatibilityClient();
|
|
121
|
+
this._client = client;
|
|
122
|
+
this._nativeOwned = true;
|
|
123
|
+
let deviceManager = null;
|
|
124
|
+
let recordingManager = null;
|
|
125
|
+
let otaManager = null;
|
|
126
|
+
try {
|
|
127
|
+
await client.configure({
|
|
128
|
+
logLevel: config.logLevel
|
|
129
|
+
});
|
|
130
|
+
const nativeState = await client.getState();
|
|
131
|
+
if (nativeState !== 'ready') {
|
|
132
|
+
throw SdkError.invalidState('ready', nativeState);
|
|
133
|
+
}
|
|
134
|
+
const capabilities = await client.getCapabilities();
|
|
135
|
+
this.setBluetoothState(capabilities.bluetooth ? 'poweredOn' : 'unsupported');
|
|
136
|
+
deviceManager = new DeviceManager();
|
|
137
|
+
await deviceManager.initialize();
|
|
138
|
+
recordingManager = new RecordingManager();
|
|
139
|
+
await recordingManager.initialize();
|
|
140
|
+
otaManager = new OTAManager(deviceManager);
|
|
141
|
+
this._deviceManager = deviceManager;
|
|
142
|
+
this._recordingManager = recordingManager;
|
|
143
|
+
this._otaManager = otaManager;
|
|
144
|
+
this.setState(nativeState);
|
|
145
|
+
log.info('SDK configured successfully', {
|
|
146
|
+
environment: config.environment,
|
|
147
|
+
bluetoothState: this._bluetoothState
|
|
148
|
+
});
|
|
149
|
+
} catch (error) {
|
|
150
|
+
deviceManager?.destroy();
|
|
151
|
+
recordingManager?.destroy();
|
|
152
|
+
otaManager?.destroy();
|
|
153
|
+
await client.destroy().catch(() => undefined);
|
|
154
|
+
this._nativeOwned = false;
|
|
155
|
+
this._client = null;
|
|
156
|
+
this.setState('error');
|
|
157
|
+
const failure = error instanceof Error ? error : new Error(String(error));
|
|
158
|
+
log.error('Failed to configure SDK', failure);
|
|
159
|
+
this.emit('error', failure);
|
|
160
|
+
throw error;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
async releaseOwnerGraph() {
|
|
164
|
+
this._deviceManager?.destroy();
|
|
165
|
+
this._recordingManager?.destroy();
|
|
166
|
+
this._otaManager?.destroy();
|
|
167
|
+
this._deviceManager = null;
|
|
168
|
+
this._recordingManager = null;
|
|
169
|
+
this._otaManager = null;
|
|
170
|
+
const client = this._client;
|
|
171
|
+
this._client = null;
|
|
172
|
+
if (client && this._nativeOwned) await client.destroy();
|
|
173
|
+
this._nativeOwned = false;
|
|
174
|
+
this._config = null;
|
|
175
|
+
this.setState('uninitialized');
|
|
176
|
+
}
|
|
177
|
+
setState(state) {
|
|
178
|
+
if (state === this._state) return;
|
|
179
|
+
this._state = state;
|
|
180
|
+
this.emit('stateChanged', state);
|
|
181
|
+
}
|
|
182
|
+
setBluetoothState(state) {
|
|
183
|
+
if (state === this._bluetoothState) return;
|
|
184
|
+
this._bluetoothState = state;
|
|
185
|
+
this.emit('bluetoothStateChanged', state);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
export const BotaClient = new BotaClientImpl();
|
|
189
|
+
//# sourceMappingURL=BotaClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["EventEmitter","getCompatibilityClient","DeviceManager","OTAManager","RecordingManager","BluetoothError","SdkError","logger","log","tag","normalizeConfig","config","environment","backgroundSyncEnabled","wifiOnlyUpload","logLevel","debug","BotaClientImpl","_config","_state","_bluetoothState","_client","_deviceManager","_recordingManager","_otaManager","_nativeOwned","_operation","Promise","resolve","_configurePromise","_destroyPromise","state","bluetoothState","isBluetoothReady","isInitialized","devices","notInitialized","recordings","ota","configure","normalized","operation","enqueue","performConfigure","finally","catch","undefined","waitForBluetooth","timeoutMs","unavailable","deadline","Date","now","setTimeout","capabilities","getCapabilities","bluetooth","setBluetoothState","timeout","setLogLevel","level","setLevel","setLogHandler","handler","setHandler","destroy","releaseOwnerGraph","removeAllListeners","queued","then","warn","setState","client","deviceManager","recordingManager","otaManager","nativeState","getState","invalidState","initialize","info","error","failure","Error","String","emit","BotaClient"],"sourceRoot":"../../src","sources":["BotaClient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C;EAClC;EAEQ0B,iBAAiBA,CAAC1B,KAAqB,EAAQ;IACrD,IAAIA,KAAK,KAAK,IAAI,CAACX,eAAe,EAAE;IACpC,IAAI,CAACA,eAAe,GAAGW,KAAK;IAC5B,IAAI,CAACsD,IAAI,CAAC,uBAAuB,EAAEtD,KAAK,CAAC;EAC3C;AACF;AAEA,OAAO,MAAMuD,UAAU,GAAG,IAAIrE,cAAc,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["DEVICE_LOG_FLAG_BACKLOG","DEVICE_LOG_FLAG_DROPPED","BLE_ERROR_STORAGE_KEY_UNAVAILABLE"],"sourceRoot":"../../../src","sources":["ble/constants.ts"],"mappings":";;AAAA,OAAO,MAAMA,uBAAuB,GAAG,IAAI;AAC3C,OAAO,MAAMC,uBAAuB,GAAG,IAAI;AAC3C,OAAO,MAAMC,iCAAiC,GAAG,IAAI","ignoreList":[]}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { Buffer } from 'buffer';
|
|
4
|
+
import { DEVICE_LOG_FLAG_BACKLOG, DEVICE_LOG_FLAG_DROPPED } from './constants';
|
|
5
|
+
const PACKET_HEADER_SIZE = 3;
|
|
6
|
+
export class DeviceLogDecoder {
|
|
7
|
+
lineBuffer = Buffer.alloc(0);
|
|
8
|
+
expectedSequence = null;
|
|
9
|
+
push(packet) {
|
|
10
|
+
if (packet.length < PACKET_HEADER_SIZE) {
|
|
11
|
+
return [];
|
|
12
|
+
}
|
|
13
|
+
const sequence = packet.readUInt16LE(0);
|
|
14
|
+
const flags = packet[2];
|
|
15
|
+
const hasSequenceGap = this.expectedSequence !== null && sequence !== this.expectedSequence;
|
|
16
|
+
const hasDroppedBytes = (flags & DEVICE_LOG_FLAG_DROPPED) !== 0;
|
|
17
|
+
const events = [];
|
|
18
|
+
if (hasSequenceGap || hasDroppedBytes) {
|
|
19
|
+
this.lineBuffer = Buffer.alloc(0);
|
|
20
|
+
}
|
|
21
|
+
this.expectedSequence = sequence + 1 & 0xffff;
|
|
22
|
+
this.lineBuffer = Buffer.concat([this.lineBuffer, packet.subarray(PACKET_HEADER_SIZE)]);
|
|
23
|
+
const isBacklog = (flags & DEVICE_LOG_FLAG_BACKLOG) !== 0;
|
|
24
|
+
let newlineIndex = this.lineBuffer.indexOf(0x0a);
|
|
25
|
+
while (newlineIndex !== -1) {
|
|
26
|
+
let line = this.lineBuffer.subarray(0, newlineIndex);
|
|
27
|
+
if (line.length > 0 && line[line.length - 1] === 0x0d) {
|
|
28
|
+
line = line.subarray(0, line.length - 1);
|
|
29
|
+
}
|
|
30
|
+
events.push({
|
|
31
|
+
level: 'debug',
|
|
32
|
+
message: Buffer.from(line).toString('utf8'),
|
|
33
|
+
isBacklog
|
|
34
|
+
});
|
|
35
|
+
this.lineBuffer = Buffer.from(this.lineBuffer.subarray(newlineIndex + 1));
|
|
36
|
+
newlineIndex = this.lineBuffer.indexOf(0x0a);
|
|
37
|
+
}
|
|
38
|
+
return events;
|
|
39
|
+
}
|
|
40
|
+
reset() {
|
|
41
|
+
this.lineBuffer = Buffer.alloc(0);
|
|
42
|
+
this.expectedSequence = null;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=deviceLogs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Buffer","DEVICE_LOG_FLAG_BACKLOG","DEVICE_LOG_FLAG_DROPPED","PACKET_HEADER_SIZE","DeviceLogDecoder","lineBuffer","alloc","expectedSequence","push","packet","length","sequence","readUInt16LE","flags","hasSequenceGap","hasDroppedBytes","events","concat","subarray","isBacklog","newlineIndex","indexOf","line","level","message","from","toString","reset"],"sourceRoot":"../../../src","sources":["ble/deviceLogs.ts"],"mappings":";;AAAA,SAASA,MAAM,QAAQ,QAAQ;AAE/B,SACEC,uBAAuB,EACvBC,uBAAuB,QAClB,aAAa;AAKpB,MAAMC,kBAAkB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