catalyst-core 0.0.3-canary.11 → 0.0.3-canary.13

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 (63) hide show
  1. package/changelog.md +14 -3
  2. package/dist/native/androidProject/.idea/misc.xml +3 -0
  3. package/dist/native/androidProject/app/proguard-rules.pro +46 -14
  4. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/BridgeMessageValidator.kt +560 -0
  5. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/CatalystConstants.kt +106 -0
  6. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/CustomWebview.kt +508 -96
  7. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/MainActivity.kt +29 -2
  8. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/MetricsMonitor.kt +341 -0
  9. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/NativeBridge.kt +346 -68
  10. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/Utils.kt +71 -8
  11. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/WebCacheManager.kt +69 -8
  12. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/BridgeUtils.kt +11 -10
  13. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/DownloadUtils.kt +35 -14
  14. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/FileUtils.kt +3 -2
  15. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/FrameworkServerUtils.kt +56 -7
  16. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/IntentUtils.kt +31 -6
  17. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/KeyboardUtil.kt +35 -2
  18. package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/BridgeMessageValidatorTest.kt +267 -0
  19. package/dist/native/assets/catalyst.png +0 -0
  20. package/dist/native/bridge/WebBridge.js +14 -2
  21. package/dist/native/bridge/constants/NativeInterfaces.js +13 -5
  22. package/dist/native/bridge/hooks.js +18 -13
  23. package/dist/native/bridge/standardizedHooks.js +23 -5
  24. package/dist/native/bridge/utils/CameraUtils.js +58 -0
  25. package/dist/native/bridge/utils/FileObjectConverter.js +40 -0
  26. package/dist/native/bridge/utils/NativeBridge.js +6 -4
  27. package/dist/native/buildAppAndroid.js +1 -12
  28. package/dist/native/buildAppIos.js +115 -22
  29. package/dist/native/iosnativeWebView/Configurations/Debug.xcconfig +18 -0
  30. package/dist/native/iosnativeWebView/Configurations/Release.xcconfig +21 -0
  31. package/dist/native/iosnativeWebView/iosnativeWebView/AppDelegate.swift +43 -0
  32. package/dist/native/iosnativeWebView/iosnativeWebView/BootTimingUtility.swift +26 -0
  33. package/dist/native/iosnativeWebView/iosnativeWebView/BridgeCommandHandler.swift +312 -0
  34. package/dist/native/iosnativeWebView/iosnativeWebView/BridgeDelegateHandler.swift +166 -0
  35. package/dist/native/iosnativeWebView/iosnativeWebView/BridgeFileHandler.swift +340 -0
  36. package/dist/native/iosnativeWebView/iosnativeWebView/BridgeJavaScriptInterface.swift +141 -0
  37. package/dist/native/iosnativeWebView/iosnativeWebView/BridgeMessageValidator.swift +509 -0
  38. package/dist/native/iosnativeWebView/iosnativeWebView/CacheManager.swift +48 -31
  39. package/dist/native/iosnativeWebView/iosnativeWebView/CameraTransportUtils.swift +363 -0
  40. package/dist/native/iosnativeWebView/iosnativeWebView/CatalystConstants.swift +91 -0
  41. package/dist/native/iosnativeWebView/iosnativeWebView/ConfigConstants.swift +7 -0
  42. package/dist/native/iosnativeWebView/iosnativeWebView/ContentView.swift +49 -5
  43. package/dist/native/iosnativeWebView/iosnativeWebView/DeviceInfoUtils.swift +72 -0
  44. package/dist/native/iosnativeWebView/iosnativeWebView/FilePickerHandler.swift +938 -0
  45. package/dist/native/iosnativeWebView/iosnativeWebView/FrameworkServerUtils.swift +821 -0
  46. package/dist/native/iosnativeWebView/iosnativeWebView/ImageHandler.swift +191 -18
  47. package/dist/native/iosnativeWebView/iosnativeWebView/Info-Release.plist +21 -0
  48. package/dist/native/iosnativeWebView/iosnativeWebView/Info.plist +2 -0
  49. package/dist/native/iosnativeWebView/iosnativeWebView/NativeBridge.swift +137 -169
  50. package/dist/native/iosnativeWebView/iosnativeWebView/ResourceURLProtocol.swift +44 -16
  51. package/dist/native/iosnativeWebView/iosnativeWebView/SplashView.swift +91 -0
  52. package/dist/native/iosnativeWebView/iosnativeWebView/SplashViewModel.swift +86 -0
  53. package/dist/native/iosnativeWebView/iosnativeWebView/URLWhitelistManager.swift +238 -0
  54. package/dist/native/iosnativeWebView/iosnativeWebView/WebView.swift +66 -11
  55. package/dist/native/iosnativeWebView/iosnativeWebView/WebViewNavigationDelegate.swift +106 -9
  56. package/dist/native/iosnativeWebView/iosnativeWebView/iosnativeWebViewApp.swift +14 -0
  57. package/dist/native/iosnativeWebView/iosnativeWebView.xcodeproj/project.pbxproj +111 -6
  58. package/dist/native/iosnativeWebView/iosnativeWebView.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +33 -0
  59. package/dist/native/terminalProgress.js +1 -1
  60. package/dist/sentry.js +4 -1
  61. package/package.json +2 -2
  62. package/dist/native/androidProject/app/src/main/assets/webview_config.properties +0 -13
  63. package/dist/native/iosnativeWebView/iosnativeWebView.xcodeproj/project.xcworkspace/xcuserdata/mayansharma.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
package/changelog.md CHANGED
@@ -1,10 +1,21 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.0.3-canary.13] - 2025-09-28
4
+
5
+ - Multi file support in useFilePicker hook
6
+ - Android multiple app icon support
7
+ - Android whitelisting toggle support
8
+
9
+ ## [0.0.3-canary.12] - 2025-09-26
10
+
11
+ - Universal App Context: Added comprehensive context support for building universal mobile applications
12
+ - OpenTelemetry SDK Integration: Built-in support for observability and performance monitoring with Otel SDK
13
+
3
14
  ## [0.0.3-canary.11] - 2025-09-26
4
15
 
5
- - **Build organization**: Store APKs and iOS builds organized by generation date and time for better tracking and management
6
- - **Enhanced Android native support**: Add support for native keyboard and webview resizing in Android
7
- - **Device info API web support**: Web support in device info API
16
+ - Build organization: Store APKs and iOS builds organized by generation date and time for better tracking and management
17
+ - Enhanced Android native support: Add support for native keyboard and webview resizing in Android
18
+ - Device info API web support: Web support in device info API
8
19
 
9
20
  ## [0.0.3-canary.10] - 2025-09-11
10
21
 
@@ -2,4 +2,7 @@
2
2
  <project version="4">
3
3
  <component name="ExternalStorageConfigurationManager" enabled="true" />
4
4
  <component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="jbr-21" project-jdk-type="JavaSDK" />
5
+ <component name="ProjectType">
6
+ <option name="id" value="Android" />
7
+ </component>
5
8
  </project>
@@ -5,17 +5,49 @@
5
5
  # For more details, see
6
6
  # http://developer.android.com/guide/developing/tools/proguard.html
7
7
 
8
- # If your project uses WebView with JS, uncomment the following
9
- # and specify the fully qualified class name to the JavaScript interface
10
- # class:
11
- #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12
- # public *;
13
- #}
14
-
15
- # Uncomment this to preserve the line number information for
16
- # debugging stack traces.
17
- #-keepattributes SourceFile,LineNumberTable
18
-
19
- # If you keep the line number information, uncomment this to
20
- # hide the original source file name.
21
- #-renamesourcefileattribute SourceFile
8
+ # Keep line numbers for debugging
9
+ -keepattributes SourceFile,LineNumberTable
10
+ -renamesourcefileattribute SourceFile
11
+
12
+ # Keep JavaScript interface for WebView
13
+ -keepclassmembers class * {
14
+ @android.webkit.JavascriptInterface <methods>;
15
+ }
16
+
17
+ # Keep NativeBridge class (JavaScript interface)
18
+ -keep class io.yourname.androidproject.NativeBridge {
19
+ public *;
20
+ }
21
+
22
+ # Keep Kotlin coroutines
23
+ -keepnames class kotlinx.coroutines.internal.MainDispatcherFactory {}
24
+ -keepnames class kotlinx.coroutines.CoroutineExceptionHandler {}
25
+ -dontwarn kotlinx.coroutines.**
26
+
27
+ # Keep Ktor
28
+ -keep class io.ktor.** { *; }
29
+ -keepclassmembers class io.ktor.** { volatile <fields>; }
30
+ -dontwarn io.ktor.**
31
+
32
+ # Keep WebViewClient overrides
33
+ -keepclassmembers class * extends android.webkit.WebViewClient {
34
+ public void *(android.webkit.WebView, java.lang.String);
35
+ public void *(android.webkit.WebView, java.lang.String, android.graphics.Bitmap);
36
+ public boolean *(android.webkit.WebView, java.lang.String);
37
+ }
38
+
39
+ # Keep WebChromeClient overrides
40
+ -keepclassmembers class * extends android.webkit.WebChromeClient {
41
+ public void *(android.webkit.WebView, java.lang.String);
42
+ }
43
+
44
+ # Keep data classes used for caching
45
+ -keep class io.yourname.androidproject.WebCacheManager$CacheEntry { *; }
46
+ -keep class io.yourname.androidproject.WebCacheManager$CacheMetadata { *; }
47
+
48
+ # Remove debug logging in release builds
49
+ -assumenosideeffects class android.util.Log {
50
+ public static *** d(...);
51
+ public static *** v(...);
52
+ public static *** i(...);
53
+ }
@@ -0,0 +1,560 @@
1
+ package io.yourname.androidproject
2
+
3
+ import android.util.Log
4
+ import io.yourname.androidproject.utils.BridgeUtils
5
+ import org.json.JSONObject
6
+ import org.json.JSONException
7
+
8
+ /**
9
+ * Bridge message validation using custom schema validation
10
+ * Mirrors iOS BridgeMessageValidator.swift for cross-platform consistency
11
+ * Zero external dependencies for minimal APK impact
12
+ */
13
+
14
+ // MARK: - Validation Result Data Classes
15
+
16
+ /**
17
+ * Result of bridge message validation
18
+ */
19
+ data class BridgeValidationResult(
20
+ val isValid: Boolean,
21
+ val command: String?,
22
+ val params: Any?,
23
+ val body: JSONObject?,
24
+ val error: BridgeValidationError?
25
+ )
26
+
27
+ /**
28
+ * Validation error details
29
+ */
30
+ data class BridgeValidationError(
31
+ val message: String,
32
+ val code: String,
33
+ val eventName: String
34
+ )
35
+
36
+ // MARK: - Schema Definition Classes
37
+
38
+ /**
39
+ * Property schema definition
40
+ */
41
+ data class PropertySchema(
42
+ val type: String,
43
+ val enum: List<String>? = null,
44
+ val minimum: Number? = null,
45
+ val maximum: Number? = null
46
+ )
47
+
48
+ /**
49
+ * Object schema definition
50
+ */
51
+ data class SchemaDefinition(
52
+ val type: String = "object",
53
+ val properties: Map<String, PropertySchema>,
54
+ val required: List<String> = emptyList(),
55
+ val additionalProperties: Boolean = true
56
+ )
57
+
58
+ // MARK: - Bridge Message Validator
59
+
60
+ object BridgeMessageValidator {
61
+
62
+ private const val TAG = "BridgeMessageValidator"
63
+ private const val MAX_MESSAGE_SIZE = 10 * 1024 * 1024 // 10MB (match iOS)
64
+
65
+ // Valid commands (should match iOS CatalystConstants.Bridge.validCommands)
66
+ private val validCommands = setOf(
67
+ "openCamera",
68
+ "requestCameraPermission",
69
+ "pickFile",
70
+ "requestHapticFeedback",
71
+ "openFileWithIntent",
72
+ "getDeviceInfo",
73
+ "logger"
74
+ )
75
+
76
+ // MARK: - Schema Definitions (mirror iOS schemas)
77
+
78
+ private val schemas = mapOf(
79
+ "openCamera" to SchemaDefinition(
80
+ properties = mapOf(
81
+ "quality" to PropertySchema(
82
+ type = "string",
83
+ enum = listOf("high", "medium", "low")
84
+ ),
85
+ "allowsEditing" to PropertySchema(type = "boolean"),
86
+ "preferredCameraType" to PropertySchema(
87
+ type = "string",
88
+ enum = listOf("front", "back")
89
+ ),
90
+ "flashMode" to PropertySchema(
91
+ type = "string",
92
+ enum = listOf("auto", "on", "off")
93
+ ),
94
+ "videoMaximumDuration" to PropertySchema(
95
+ type = "number",
96
+ minimum = 0,
97
+ maximum = 3600
98
+ )
99
+ ),
100
+ additionalProperties = false
101
+ ),
102
+
103
+ "requestCameraPermission" to SchemaDefinition(
104
+ properties = mapOf(
105
+ "showRationale" to PropertySchema(type = "boolean"),
106
+ "fallbackToSettings" to PropertySchema(type = "boolean"),
107
+ "includeDetails" to PropertySchema(type = "boolean")
108
+ ),
109
+ additionalProperties = false
110
+ ),
111
+
112
+ "pickFile" to SchemaDefinition(
113
+ properties = mapOf(
114
+ "mimeType" to PropertySchema(type = "string"),
115
+ "multiple" to PropertySchema(type = "boolean"),
116
+ "minFileSize" to PropertySchema(
117
+ type = "number",
118
+ minimum = 0
119
+ ),
120
+ "maxFileSize" to PropertySchema(
121
+ type = "number",
122
+ minimum = 0
123
+ ),
124
+ "minFiles" to PropertySchema(
125
+ type = "number",
126
+ minimum = 1
127
+ ),
128
+ "maxFiles" to PropertySchema(
129
+ type = "number",
130
+ minimum = 1
131
+ )
132
+ ),
133
+ additionalProperties = false
134
+ ),
135
+
136
+ "requestHapticFeedback" to SchemaDefinition(
137
+ properties = mapOf(
138
+ "type" to PropertySchema(
139
+ type = "string",
140
+ enum = listOf(
141
+ "light", "medium", "heavy", "selection",
142
+ "impact", "notification", "VIRTUAL_KEY",
143
+ "LONG_PRESS", "DEFAULT"
144
+ )
145
+ ),
146
+ "intensity" to PropertySchema(
147
+ type = "number",
148
+ minimum = 0,
149
+ maximum = 1
150
+ )
151
+ ),
152
+ required = listOf("type"),
153
+ additionalProperties = false
154
+ ),
155
+
156
+ "openFileWithIntent" to SchemaDefinition(
157
+ properties = mapOf(
158
+ "url" to PropertySchema(type = "string"),
159
+ "filename" to PropertySchema(type = "string"),
160
+ "mimeType" to PropertySchema(type = "string"),
161
+ "data" to PropertySchema(type = "string")
162
+ ),
163
+ additionalProperties = false
164
+ ),
165
+
166
+ "getDeviceInfo" to SchemaDefinition(
167
+ properties = emptyMap(),
168
+ additionalProperties = false
169
+ ),
170
+
171
+ "logger" to SchemaDefinition(
172
+ properties = emptyMap(),
173
+ additionalProperties = false
174
+ )
175
+ )
176
+
177
+ // Commands that support flexible parameter formats (string or object)
178
+ // Mirror iOS flexible commands for backward compatibility
179
+ private val flexibleCommands = setOf(
180
+ "openCamera",
181
+ "requestCameraPermission",
182
+ "pickFile",
183
+ "requestHapticFeedback",
184
+ "openFileWithIntent"
185
+ )
186
+
187
+ // MARK: - Public Validation Interface
188
+
189
+ /**
190
+ * Validate a bridge message
191
+ * @param body The message body as JSONObject
192
+ * @return BridgeValidationResult with validation status and error details
193
+ */
194
+ fun validate(body: JSONObject): BridgeValidationResult {
195
+ BridgeUtils.logDebug(TAG, "Starting validation for bridge message")
196
+
197
+ // Step 1: Validate message size
198
+ try {
199
+ val messageSize = body.toString().toByteArray(Charsets.UTF_8).size
200
+ if (messageSize > MAX_MESSAGE_SIZE) {
201
+ BridgeUtils.logError(TAG, "Message size exceeds limit: $messageSize > $MAX_MESSAGE_SIZE")
202
+ return BridgeValidationResult(
203
+ isValid = false,
204
+ command = null,
205
+ params = null,
206
+ body = body,
207
+ error = BridgeValidationError(
208
+ message = "Message too large",
209
+ code = "MESSAGE_TOO_LARGE",
210
+ eventName = "BRIDGE_ERROR"
211
+ )
212
+ )
213
+ }
214
+ } catch (e: Exception) {
215
+ BridgeUtils.logError(TAG, "Error checking message size", e)
216
+ }
217
+
218
+ // Step 2: Validate root message structure
219
+ val rootValidationResult = validateRootMessageStructure(body)
220
+ if (rootValidationResult == null) {
221
+ return BridgeValidationResult(
222
+ isValid = false,
223
+ command = null,
224
+ params = null,
225
+ body = body,
226
+ error = BridgeValidationError(
227
+ message = "Invalid root message structure",
228
+ code = "INVALID_ROOT_STRUCTURE",
229
+ eventName = "BRIDGE_ERROR"
230
+ )
231
+ )
232
+ }
233
+
234
+ val command = rootValidationResult.first
235
+ val params = rootValidationResult.second
236
+
237
+ // Step 3: Validate command is supported
238
+ if (!validCommands.contains(command)) {
239
+ BridgeUtils.logError(TAG, "Unsupported command: $command")
240
+ return BridgeValidationResult(
241
+ isValid = false,
242
+ command = command,
243
+ params = params,
244
+ body = body,
245
+ error = BridgeValidationError(
246
+ message = "Unsupported command: $command",
247
+ code = "UNSUPPORTED_COMMAND",
248
+ eventName = "BRIDGE_ERROR"
249
+ )
250
+ )
251
+ }
252
+
253
+ // Step 4: Validate command-specific parameters
254
+ if (params != null) {
255
+ val validationError = validateCommandParameters(command, params)
256
+ if (validationError != null) {
257
+ return BridgeValidationResult(
258
+ isValid = false,
259
+ command = command,
260
+ params = params,
261
+ body = body,
262
+ error = validationError
263
+ )
264
+ }
265
+ }
266
+
267
+ BridgeUtils.logDebug(TAG, "Message validation successful for command: $command")
268
+ return BridgeValidationResult(
269
+ isValid = true,
270
+ command = command,
271
+ params = params,
272
+ body = body,
273
+ error = null
274
+ )
275
+ }
276
+
277
+ // MARK: - Private Validation Helpers
278
+
279
+ /**
280
+ * Validate root message structure (command + data fields)
281
+ * @return Pair of (command, params) or null if invalid
282
+ */
283
+ private fun validateRootMessageStructure(body: JSONObject): Pair<String, Any?>? {
284
+ // Validate required command field
285
+ val command = body.optString("command", "")
286
+ if (command.isEmpty()) {
287
+ BridgeUtils.logError(TAG, "Root message missing 'command' field")
288
+ return null
289
+ }
290
+
291
+ // Optional: Validate timestamp if present
292
+ if (body.has("timestamp")) {
293
+ val timestamp = body.optString("timestamp")
294
+ if (timestamp.isNotEmpty()) {
295
+ // Basic ISO8601 format check (simplified)
296
+ if (!timestamp.matches(Regex("\\d{4}-\\d{2}-\\d{2}T.*"))) {
297
+ BridgeUtils.logWarning(TAG, "Invalid timestamp format in message: $timestamp")
298
+ }
299
+ }
300
+ }
301
+
302
+ // Optional: Validate requestId if present
303
+ if (body.has("requestId")) {
304
+ val requestId = body.optString("requestId")
305
+ if (requestId.isEmpty()) {
306
+ BridgeUtils.logWarning(TAG, "Empty requestId in message")
307
+ }
308
+ }
309
+
310
+ // Extract params from 'data' field
311
+ val params = if (body.has("data")) {
312
+ val data = body.get("data")
313
+ when (data) {
314
+ JSONObject.NULL -> null
315
+ is JSONObject -> data
316
+ is String -> data
317
+ else -> data
318
+ }
319
+ } else {
320
+ null
321
+ }
322
+
323
+ return Pair(command, params)
324
+ }
325
+
326
+ /**
327
+ * Validate command-specific parameters against schema
328
+ */
329
+ private fun validateCommandParameters(command: String, params: Any): BridgeValidationError? {
330
+ // Handle flexible commands (allow string, object, or null for legacy compatibility)
331
+ if (flexibleCommands.contains(command)) {
332
+ // Allow string or null parameters
333
+ if (params is String || params == null) {
334
+ BridgeUtils.logDebug(TAG, "Command '$command' received string/nil parameters - allowing for legacy compatibility")
335
+ return null
336
+ }
337
+
338
+ // If it's an object, validate against schema if available
339
+ if (params is JSONObject) {
340
+ val schema = schemas[command]
341
+ if (schema == null) {
342
+ BridgeUtils.logDebug(TAG, "No schema defined for command: $command, allowing object parameters")
343
+ return null
344
+ }
345
+
346
+ return validateObjectAgainstSchema(params, schema, command)
347
+ }
348
+
349
+ BridgeUtils.logWarning(TAG, "Command '$command' received unexpected parameter type: ${params.javaClass.simpleName}")
350
+ return null // Allow for backward compatibility
351
+ }
352
+
353
+ // For strict commands, require object parameters and validate against schema
354
+ val schema = schemas[command]
355
+ if (schema == null) {
356
+ BridgeUtils.logDebug(TAG, "No schema defined for command: $command, allowing all parameters")
357
+ return null
358
+ }
359
+
360
+ if (params !is JSONObject) {
361
+ BridgeUtils.logError(TAG, "Parameters for command '$command' must be an object")
362
+ return BridgeValidationError(
363
+ message = "Invalid parameters format for $command",
364
+ code = "INVALID_PARAMS",
365
+ eventName = "BRIDGE_ERROR"
366
+ )
367
+ }
368
+
369
+ return validateObjectAgainstSchema(params, schema, command)
370
+ }
371
+
372
+ /**
373
+ * Validate a JSON object against a schema definition
374
+ */
375
+ private fun validateObjectAgainstSchema(
376
+ obj: JSONObject,
377
+ schema: SchemaDefinition,
378
+ commandName: String
379
+ ): BridgeValidationError? {
380
+ // Validate schema type
381
+ if (schema.type != "object") {
382
+ BridgeUtils.logWarning(TAG, "Schema for $commandName is not of type 'object'")
383
+ }
384
+
385
+ // Validate required fields
386
+ for (requiredField in schema.required) {
387
+ if (!obj.has(requiredField) || obj.isNull(requiredField)) {
388
+ BridgeUtils.logError(TAG, "Required field '$requiredField' missing for command $commandName")
389
+ return BridgeValidationError(
390
+ message = "Missing required field: $requiredField",
391
+ code = "MISSING_REQUIRED_FIELD",
392
+ eventName = "BRIDGE_ERROR"
393
+ )
394
+ }
395
+ }
396
+
397
+ // Validate each property
398
+ val keys = obj.keys()
399
+ while (keys.hasNext()) {
400
+ val key = keys.next()
401
+ val value = obj.get(key)
402
+
403
+ if (value == JSONObject.NULL) {
404
+ continue // Skip null values
405
+ }
406
+
407
+ val propertySchema = schema.properties[key]
408
+ if (propertySchema != null) {
409
+ val error = validatePropertyAgainstSchema(value, propertySchema, key, commandName)
410
+ if (error != null) {
411
+ return error
412
+ }
413
+ } else if (!schema.additionalProperties) {
414
+ BridgeUtils.logError(TAG, "Additional property '$key' not allowed for command $commandName")
415
+ return BridgeValidationError(
416
+ message = "Additional property '$key' not allowed",
417
+ code = "ADDITIONAL_PROPERTY_NOT_ALLOWED",
418
+ eventName = "BRIDGE_ERROR"
419
+ )
420
+ }
421
+ }
422
+
423
+ if (commandName == "pickFile") {
424
+ val minFiles = if (obj.has("minFiles") && !obj.isNull("minFiles")) obj.optInt("minFiles") else null
425
+ val maxFiles = if (obj.has("maxFiles") && !obj.isNull("maxFiles")) obj.optInt("maxFiles") else null
426
+ if (minFiles != null && maxFiles != null && minFiles > maxFiles) {
427
+ BridgeUtils.logError(TAG, "minFiles cannot be greater than maxFiles for pickFile command")
428
+ return BridgeValidationError(
429
+ message = "minFiles cannot be greater than maxFiles",
430
+ code = "INVALID_FILE_PICKER_OPTIONS",
431
+ eventName = "ON_FILE_PICK_ERROR"
432
+ )
433
+ }
434
+
435
+ val minFileSize = if (obj.has("minFileSize") && !obj.isNull("minFileSize")) obj.optLong("minFileSize") else null
436
+ val maxFileSize = if (obj.has("maxFileSize") && !obj.isNull("maxFileSize")) obj.optLong("maxFileSize") else null
437
+ if (minFileSize != null && maxFileSize != null && minFileSize > maxFileSize) {
438
+ BridgeUtils.logError(TAG, "minFileSize cannot be greater than maxFileSize for pickFile command")
439
+ return BridgeValidationError(
440
+ message = "minFileSize cannot be greater than maxFileSize",
441
+ code = "INVALID_FILE_PICKER_OPTIONS",
442
+ eventName = "ON_FILE_PICK_ERROR"
443
+ )
444
+ }
445
+ }
446
+
447
+ return null
448
+ }
449
+
450
+ /**
451
+ * Validate a single property against its schema
452
+ */
453
+ private fun validatePropertyAgainstSchema(
454
+ value: Any,
455
+ schema: PropertySchema,
456
+ propertyName: String,
457
+ commandName: String
458
+ ): BridgeValidationError? {
459
+ when (schema.type) {
460
+ "string" -> {
461
+ if (value !is String) {
462
+ BridgeUtils.logError(TAG, "Property '$propertyName' must be a string for command $commandName")
463
+ return BridgeValidationError(
464
+ message = "Property '$propertyName' must be a string",
465
+ code = "INVALID_TYPE",
466
+ eventName = "BRIDGE_ERROR"
467
+ )
468
+ }
469
+
470
+ // Validate enum values
471
+ if (schema.enum != null && !schema.enum.contains(value)) {
472
+ BridgeUtils.logError(TAG, "Property '$propertyName' value '$value' not in allowed enum values")
473
+ return BridgeValidationError(
474
+ message = "Invalid value for $propertyName: $value",
475
+ code = "INVALID_ENUM_VALUE",
476
+ eventName = "BRIDGE_ERROR"
477
+ )
478
+ }
479
+ }
480
+
481
+ "number" -> {
482
+ val numberValue = when (value) {
483
+ is Number -> value.toDouble()
484
+ is String -> value.toDoubleOrNull()
485
+ else -> null
486
+ }
487
+
488
+ if (numberValue == null) {
489
+ BridgeUtils.logError(TAG, "Property '$propertyName' must be a number for command $commandName")
490
+ return BridgeValidationError(
491
+ message = "Property '$propertyName' must be a number",
492
+ code = "INVALID_TYPE",
493
+ eventName = "BRIDGE_ERROR"
494
+ )
495
+ }
496
+
497
+ // Validate minimum
498
+ if (schema.minimum != null && numberValue < schema.minimum.toDouble()) {
499
+ BridgeUtils.logError(TAG, "Property '$propertyName' value $numberValue is below minimum ${schema.minimum}")
500
+ return BridgeValidationError(
501
+ message = "Value for $propertyName below minimum",
502
+ code = "VALUE_BELOW_MINIMUM",
503
+ eventName = "BRIDGE_ERROR"
504
+ )
505
+ }
506
+
507
+ // Validate maximum
508
+ if (schema.maximum != null && numberValue > schema.maximum.toDouble()) {
509
+ BridgeUtils.logError(TAG, "Property '$propertyName' value $numberValue is above maximum ${schema.maximum}")
510
+ return BridgeValidationError(
511
+ message = "Value for $propertyName above maximum",
512
+ code = "VALUE_ABOVE_MAXIMUM",
513
+ eventName = "BRIDGE_ERROR"
514
+ )
515
+ }
516
+ }
517
+
518
+ "boolean" -> {
519
+ if (value !is Boolean) {
520
+ BridgeUtils.logError(TAG, "Property '$propertyName' must be a boolean for command $commandName")
521
+ return BridgeValidationError(
522
+ message = "Property '$propertyName' must be a boolean",
523
+ code = "INVALID_TYPE",
524
+ eventName = "BRIDGE_ERROR"
525
+ )
526
+ }
527
+ }
528
+
529
+ else -> {
530
+ BridgeUtils.logWarning(TAG, "Unknown schema type '${schema.type}' for property $propertyName")
531
+ }
532
+ }
533
+
534
+ return null
535
+ }
536
+
537
+ // MARK: - Schema Management
538
+
539
+ /**
540
+ * Add a custom schema for a command
541
+ */
542
+ fun addCustomSchema(command: String, schema: SchemaDefinition) {
543
+ // Note: Since schemas is immutable, we'd need to make it mutable if dynamic schemas are needed
544
+ BridgeUtils.logInfo(TAG, "Custom schema support not yet implemented for runtime additions")
545
+ }
546
+
547
+ /**
548
+ * Get all available commands that have schemas
549
+ */
550
+ fun getAvailableCommands(): Set<String> {
551
+ return schemas.keys
552
+ }
553
+
554
+ /**
555
+ * Check if a command has a schema defined
556
+ */
557
+ fun hasSchema(command: String): Boolean {
558
+ return schemas.containsKey(command)
559
+ }
560
+ }