catalyst-core-internal 0.1.3 → 0.1.5

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 (41) hide show
  1. package/bin/catalyst.js +1 -8
  2. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/BridgeMessageValidator.kt +1 -1
  3. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/CustomWebview.kt +1 -12
  4. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/MainActivity.kt +3 -18
  5. package/dist/native/buildAppAndroid.js +2 -2
  6. package/dist/native/buildAppIos.js +17 -10
  7. package/dist/native/iosnativeWebView/Sources/Core/WebView/NativeBridge.swift +2 -13
  8. package/dist/native/iosnativeWebView/Sources/Core/WebView/WebView.swift +0 -6
  9. package/dist/native/iosnativeWebView/iosnativeWebView.xcodeproj/project.pbxproj +0 -4
  10. package/mcp_v2/conversion-tasks.json +326 -0
  11. package/mcp_v2/knowledge-base.json +1068 -0
  12. package/mcp_v2/lib/helpers.js +159 -0
  13. package/mcp_v2/mcp.js +562 -0
  14. package/mcp_v2/package.json +13 -0
  15. package/mcp_v2/schema.sql +88 -0
  16. package/mcp_v2/setup.js +276 -0
  17. package/mcp_v2/tools/build.js +686 -0
  18. package/mcp_v2/tools/config.js +453 -0
  19. package/mcp_v2/tools/conversion.js +799 -0
  20. package/mcp_v2/tools/debug.js +113 -0
  21. package/mcp_v2/tools/knowledge.js +219 -0
  22. package/mcp_v2/tools/sync.js +23 -0
  23. package/mcp_v2/tools/tasks.js +945 -0
  24. package/package.json +2 -3
  25. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/plugins/CatalystPlugin.kt +0 -5
  26. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/plugins/GeneratedPluginIndex.kt +0 -6
  27. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/plugins/PluginBridge.kt +0 -240
  28. package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/plugins/PluginBridgeTest.kt +0 -121
  29. package/dist/native/internal-plugins/device-info-plugin/android/DeviceInfoPlugin.kt +0 -43
  30. package/dist/native/internal-plugins/device-info-plugin/ios/DeviceInfoPlugin.swift +0 -28
  31. package/dist/native/internal-plugins/device-info-plugin/manifest.json +0 -19
  32. package/dist/native/internalPluginUtils.js +0 -1
  33. package/dist/native/iosnativeWebView/Sources/Core/Plugins/CatalystPlugin.swift +0 -5
  34. package/dist/native/iosnativeWebView/Sources/Core/Plugins/GeneratedPluginIndex.swift +0 -6
  35. package/dist/native/iosnativeWebView/Sources/Core/Plugins/PluginBridge.swift +0 -364
  36. package/dist/native/iosnativeWebView/Sources/Core/WebView/WeakScriptMessageHandler.swift +0 -14
  37. package/dist/native/iosnativeWebView/iosnativeWebViewTests/PluginBridgeTests.swift +0 -160
  38. package/dist/native/plugin-bridge/PluginBridge.js +0 -1
  39. package/dist/native/pluginComposerAndroid.js +0 -9
  40. package/dist/native/pluginComposerIos.js +0 -7
  41. package/dist/scripts/plugins.js +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "catalyst-core-internal",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "main": "index.js",
5
5
  "description": "Web framework that provides great performance out of the box",
6
6
  "bin": {
@@ -31,7 +31,6 @@
31
31
  "./caching": "./dist/caching.js",
32
32
  "./router/ClientRouter": "./dist/router/ClientRouter.js",
33
33
  "./WebBridge": "./dist/native/bridge/WebBridge.js",
34
- "./PluginBridge": "./dist/native/plugin-bridge/PluginBridge.js",
35
34
  "./hooks": "./dist/native/bridge/hooks.js",
36
35
  "./sentry": "./dist/sentry.js",
37
36
  "./otel": "./dist/otel.js"
@@ -40,7 +39,7 @@
40
39
  "lint": "eslint .",
41
40
  "lint-staged": "lint-staged",
42
41
  "prettify": "prettier . --write",
43
- "prepare": "babel src --out-dir ./dist --ignore '**/.build/**' && mkdir -p dist/native && cp -r src/native/androidProject src/native/build.swift src/native/assets src/native/internal-plugins dist/native/ && mkdir -p dist/native/iosnativeWebView && tar -C src/native/iosnativeWebView --exclude='.build' --exclude='.package-config-hash' -cf - . | tar -C dist/native/iosnativeWebView -xf -",
42
+ "prepare": "babel src --out-dir ./dist --ignore '**/.build/**' && mkdir -p dist/native && cp -r src/native/androidProject src/native/build.swift src/native/assets dist/native/ && mkdir -p dist/native/iosnativeWebView && tar -C src/native/iosnativeWebView --exclude='.build' --exclude='.package-config-hash' -cf - . | tar -C dist/native/iosnativeWebView -xf -",
44
43
  "prepublishOnly": "npm i && npm run prepare"
45
44
  },
46
45
  "license": "MIT",
@@ -1,5 +0,0 @@
1
- package io.yourname.androidproject.plugins
2
-
3
- interface CatalystPlugin {
4
- fun handle(command: String, data: Any?, bridge: PluginBridgeContext)
5
- }
@@ -1,6 +0,0 @@
1
- package io.yourname.androidproject.plugins
2
-
3
- object GeneratedPluginIndex {
4
- val pluginIdToClassName: Map<String, String> = emptyMap()
5
- val pluginToCommands: Map<String, Set<String>> = emptyMap()
6
- }
@@ -1,240 +0,0 @@
1
- package io.yourname.androidproject.plugins
2
-
3
- import android.app.Activity
4
- import android.content.Context
5
- import android.util.Log
6
- import android.webkit.JavascriptInterface
7
- import android.webkit.WebView
8
- import io.yourname.androidproject.CatalystConstants
9
- import org.json.JSONArray
10
- import org.json.JSONException
11
- import org.json.JSONObject
12
- import java.util.Properties
13
-
14
- internal data class PluginRequest(
15
- val pluginId: String,
16
- val command: String,
17
- val data: Any?,
18
- val requestId: String?
19
- )
20
-
21
- private class PluginBridgeRuntimeError(
22
- override val message: String,
23
- val code: String,
24
- cause: Throwable? = null
25
- ) : Exception(message, cause)
26
-
27
- class PluginBridge(
28
- private val activity: Activity,
29
- private val webView: WebView,
30
- private val properties: Properties
31
- ) {
32
- companion object {
33
- private const val TAG = "PluginBridge"
34
- private const val ERROR_EVENT = "PLUGIN_BRIDGE_ERROR"
35
- private const val SYSTEM_PLUGIN_ID = "__bridge__"
36
- private const val ERROR_CODE_INVALID_PAYLOAD = "INVALID_PAYLOAD"
37
- private const val ERROR_CODE_PLUGIN_NOT_FOUND = "PLUGIN_NOT_FOUND"
38
- private const val ERROR_CODE_COMMAND_NOT_SUPPORTED = "COMMAND_NOT_SUPPORTED"
39
- private const val ERROR_CODE_PLUGIN_NOT_REGISTERED = "PLUGIN_NOT_REGISTERED"
40
- private const val ERROR_CODE_PLUGIN_INSTANTIATION_FAILED = "PLUGIN_INSTANTIATION_FAILED"
41
- private const val ERROR_CODE_PLUGIN_EXECUTION_FAILED = "PLUGIN_EXECUTION_FAILED"
42
-
43
- private fun readRequiredString(body: JSONObject, key: String): String {
44
- if (!body.has(key) || body.isNull(key)) {
45
- return ""
46
- }
47
-
48
- val rawValue = body.get(key)
49
- if (rawValue !is String) {
50
- throw IllegalArgumentException("$key must be a string")
51
- }
52
-
53
- return rawValue.trim()
54
- }
55
-
56
- private fun readOptionalString(body: JSONObject, key: String): String? {
57
- if (!body.has(key) || body.isNull(key)) {
58
- return null
59
- }
60
-
61
- val rawValue = body.get(key)
62
- if (rawValue !is String) {
63
- throw IllegalArgumentException("$key must be a string when provided")
64
- }
65
-
66
- return rawValue.trim().ifEmpty { null }
67
- }
68
-
69
- internal fun parseRequest(payload: String?): PluginRequest {
70
- if (payload.isNullOrBlank()) {
71
- throw IllegalArgumentException("Payload is required")
72
- }
73
- val messageSize = payload.toByteArray(Charsets.UTF_8).size
74
- if (messageSize > CatalystConstants.Bridge.MAX_MESSAGE_SIZE) {
75
- throw IllegalArgumentException("Payload exceeds maximum size")
76
- }
77
-
78
- val body = JSONObject(payload)
79
- return PluginRequest(
80
- pluginId = readRequiredString(body, "pluginId"),
81
- command = readRequiredString(body, "command"),
82
- data = if (body.has("data") && !body.isNull("data")) body.get("data") else null,
83
- requestId = readOptionalString(body, "requestId")
84
- )
85
- }
86
- }
87
-
88
- private val pluginIdToClassName = GeneratedPluginIndex.pluginIdToClassName
89
- private val pluginToCommands = GeneratedPluginIndex.pluginToCommands
90
-
91
- @JavascriptInterface
92
- fun emit(payload: String?) {
93
- var request: PluginRequest? = null
94
-
95
- try {
96
- request = parseRequest(payload)
97
-
98
- if (request.pluginId.isEmpty()) {
99
- sendBridgeError("pluginId is required", ERROR_CODE_INVALID_PAYLOAD, request)
100
- return
101
- }
102
- if (request.command.isEmpty()) {
103
- sendBridgeError("command is required", ERROR_CODE_INVALID_PAYLOAD, request)
104
- return
105
- }
106
-
107
- if (!hasPlugin(request.pluginId)) {
108
- sendBridgeError("Unsupported plugin: ${request.pluginId}", ERROR_CODE_PLUGIN_NOT_FOUND, request)
109
- return
110
- }
111
-
112
- if (!hasCommand(request.pluginId, request.command)) {
113
- sendBridgeError(
114
- "Unsupported command '${request.command}' for plugin '${request.pluginId}'",
115
- ERROR_CODE_COMMAND_NOT_SUPPORTED,
116
- request
117
- )
118
- return
119
- }
120
-
121
- val plugin = try {
122
- getPluginForId(request.pluginId)
123
- } catch (error: PluginBridgeRuntimeError) {
124
- sendBridgeError(error.message, error.code, request)
125
- return
126
- }
127
-
128
- val callbackContext = PluginBridgeContext(
129
- activity = activity,
130
- webView = webView,
131
- properties = properties,
132
- pluginId = request.pluginId,
133
- command = request.command,
134
- requestId = request.requestId
135
- )
136
-
137
- plugin.handle(request.command, request.data, callbackContext)
138
- } catch (error: IllegalArgumentException) {
139
- sendBridgeError(error.message ?: "Invalid payload", ERROR_CODE_INVALID_PAYLOAD, request)
140
- } catch (error: JSONException) {
141
- sendBridgeError("Invalid JSON payload: ${error.message}", ERROR_CODE_INVALID_PAYLOAD, request)
142
- } catch (error: Exception) {
143
- Log.e(TAG, "Plugin command failed for ${request?.pluginId ?: "<unknown>"}.${request?.command ?: "<unknown>"}", error)
144
- sendBridgeError("Plugin execution failed: ${error.message}", ERROR_CODE_PLUGIN_EXECUTION_FAILED, request)
145
- }
146
- }
147
-
148
- private fun sendBridgeError(message: String, code: String, request: PluginRequest?) {
149
- PluginBridgeContext(
150
- activity = activity,
151
- webView = webView,
152
- properties = properties,
153
- pluginId = SYSTEM_PLUGIN_ID,
154
- command = request?.command,
155
- requestId = request?.requestId
156
- ).callback(
157
- ERROR_EVENT,
158
- JSONObject().apply {
159
- put("message", message)
160
- put("code", code)
161
- put("pluginId", request?.pluginId ?: SYSTEM_PLUGIN_ID)
162
- request?.command?.takeIf { it.isNotEmpty() }?.let { put("command", it) }
163
- }
164
- )
165
- }
166
-
167
- private fun hasPlugin(pluginId: String): Boolean {
168
- return pluginIdToClassName.containsKey(pluginId)
169
- }
170
-
171
- private fun hasCommand(pluginId: String, command: String): Boolean {
172
- return pluginToCommands[pluginId]?.contains(command) ?: false
173
- }
174
-
175
- private fun getPluginForId(pluginId: String): CatalystPlugin {
176
- val className = pluginIdToClassName[pluginId]
177
- ?: throw PluginBridgeRuntimeError(
178
- "No plugin registered for id: $pluginId",
179
- ERROR_CODE_PLUGIN_NOT_REGISTERED
180
- )
181
-
182
- return try {
183
- val clazz = Class.forName(className)
184
- val instance = clazz.getDeclaredConstructor().newInstance()
185
- instance as? CatalystPlugin
186
- ?: throw IllegalStateException("Plugin class '$className' must implement CatalystPlugin")
187
- } catch (error: Exception) {
188
- Log.e(TAG, "Failed to instantiate plugin class $className for plugin $pluginId", error)
189
- throw PluginBridgeRuntimeError(
190
- "Failed to instantiate plugin class '$className' for plugin '$pluginId': ${error.message ?: error.javaClass.simpleName}",
191
- ERROR_CODE_PLUGIN_INSTANTIATION_FAILED,
192
- error
193
- )
194
- }
195
- }
196
- }
197
-
198
- class PluginBridgeContext(
199
- val activity: Activity,
200
- val webView: WebView,
201
- val properties: Properties,
202
- val pluginId: String,
203
- val command: String?,
204
- val requestId: String?
205
- ) {
206
- val context: Context
207
- get() = activity
208
-
209
- fun callback(
210
- eventName: String,
211
- data: Any?,
212
- command: String? = this.command
213
- ) {
214
- require(eventName.isNotBlank()) { "Callback eventName is required" }
215
-
216
- val pluginLiteral = JSONObject.quote(pluginId)
217
- val eventLiteral = JSONObject.quote(eventName)
218
- val dataLiteral = toJavaScriptLiteral(data)
219
- val requestLiteral = requestId?.let(JSONObject::quote) ?: "null"
220
- val commandLiteral = command?.takeIf { it.isNotBlank() }?.let(JSONObject::quote) ?: "null"
221
-
222
- webView.post {
223
- webView.evaluateJavascript(
224
- "window.PluginBridgeWeb && window.PluginBridgeWeb.callback($pluginLiteral, $eventLiteral, $dataLiteral, $requestLiteral, $commandLiteral);",
225
- null
226
- )
227
- }
228
- }
229
-
230
- private fun toJavaScriptLiteral(value: Any?): String {
231
- return when (value) {
232
- null -> "null"
233
- is JSONObject -> value.toString()
234
- is JSONArray -> value.toString()
235
- is Number, is Boolean -> value.toString()
236
- is String -> JSONObject.quote(value)
237
- else -> JSONObject.wrap(value)?.toString() ?: "null"
238
- }
239
- }
240
- }
@@ -1,121 +0,0 @@
1
- package io.yourname.androidproject.plugins
2
-
3
- import io.yourname.androidproject.CatalystConstants
4
- import org.json.JSONException
5
- import org.json.JSONObject
6
- import org.junit.Assert.assertEquals
7
- import org.junit.Assert.assertNull
8
- import org.junit.Assert.assertTrue
9
- import org.junit.Assert.fail
10
- import org.junit.Test
11
-
12
- class PluginBridgeTest {
13
-
14
- @Test
15
- fun `parseRequest accepts valid payload and trims string fields`() {
16
- val request = PluginBridge.parseRequest(
17
- """
18
- {
19
- "pluginId": " device-info-plugin ",
20
- "command": " getDeviceInfo ",
21
- "data": { "includeSecurity": true },
22
- "requestId": " req-123 "
23
- }
24
- """.trimIndent()
25
- )
26
-
27
- assertEquals("device-info-plugin", request.pluginId)
28
- assertEquals("getDeviceInfo", request.command)
29
- assertEquals("req-123", request.requestId)
30
- assertEquals(true, (request.data as JSONObject).getBoolean("includeSecurity"))
31
- }
32
-
33
- @Test
34
- fun `parseRequest treats blank requestId as null`() {
35
- val request = PluginBridge.parseRequest(
36
- """
37
- {
38
- "pluginId": "device-info-plugin",
39
- "command": "getDeviceInfo",
40
- "requestId": " "
41
- }
42
- """.trimIndent()
43
- )
44
-
45
- assertNull(request.requestId)
46
- }
47
-
48
- @Test
49
- fun `parseRequest rejects blank payload`() {
50
- try {
51
- PluginBridge.parseRequest(" ")
52
- fail("Expected invalid blank payload to throw")
53
- } catch (error: IllegalArgumentException) {
54
- assertEquals("Payload is required", error.message)
55
- }
56
- }
57
-
58
- @Test
59
- fun `parseRequest rejects oversized payload`() {
60
- val oversizedData = "x".repeat(CatalystConstants.Bridge.MAX_MESSAGE_SIZE + 256)
61
- val payload = """
62
- {
63
- "pluginId": "device-info-plugin",
64
- "command": "getDeviceInfo",
65
- "data": "$oversizedData"
66
- }
67
- """.trimIndent()
68
-
69
- try {
70
- PluginBridge.parseRequest(payload)
71
- fail("Expected oversized payload to throw")
72
- } catch (error: IllegalArgumentException) {
73
- assertEquals("Payload exceeds maximum size", error.message)
74
- }
75
- }
76
-
77
- @Test
78
- fun `parseRequest rejects non string pluginId`() {
79
- try {
80
- PluginBridge.parseRequest(
81
- """
82
- {
83
- "pluginId": 42,
84
- "command": "getDeviceInfo"
85
- }
86
- """.trimIndent()
87
- )
88
- fail("Expected non-string pluginId to throw")
89
- } catch (error: IllegalArgumentException) {
90
- assertEquals("pluginId must be a string", error.message)
91
- }
92
- }
93
-
94
- @Test
95
- fun `parseRequest rejects non string requestId`() {
96
- try {
97
- PluginBridge.parseRequest(
98
- """
99
- {
100
- "pluginId": "device-info-plugin",
101
- "command": "getDeviceInfo",
102
- "requestId": 42
103
- }
104
- """.trimIndent()
105
- )
106
- fail("Expected non-string requestId to throw")
107
- } catch (error: IllegalArgumentException) {
108
- assertEquals("requestId must be a string when provided", error.message)
109
- }
110
- }
111
-
112
- @Test
113
- fun `parseRequest rejects invalid JSON`() {
114
- try {
115
- PluginBridge.parseRequest("{")
116
- fail("Expected invalid JSON to throw")
117
- } catch (error: JSONException) {
118
- assertTrue(error.message?.isNotBlank() == true)
119
- }
120
- }
121
- }
@@ -1,43 +0,0 @@
1
- package io.yourname.androidproject.plugins.internal.deviceinfo
2
-
3
- import android.util.Log
4
- import io.yourname.androidproject.plugins.CatalystPlugin
5
- import io.yourname.androidproject.plugins.PluginBridgeContext
6
- import io.yourname.androidproject.utils.DeviceInfoUtils
7
- import org.json.JSONObject
8
-
9
- class DeviceInfoPlugin : CatalystPlugin {
10
- companion object {
11
- private const val TAG = "DeviceInfoPlugin"
12
- private const val COMMAND_GET_DEVICE_INFO = "getDeviceInfo"
13
- private const val CALLBACK_SUCCESS = "onSuccess"
14
- private const val CALLBACK_ERROR = "onError"
15
- }
16
-
17
- override fun handle(command: String, data: Any?, bridge: PluginBridgeContext) {
18
- if (command != COMMAND_GET_DEVICE_INFO) {
19
- bridge.callback(
20
- CALLBACK_ERROR,
21
- JSONObject().apply {
22
- put("message", "Unsupported command: $command")
23
- put("code", "UNSUPPORTED_COMMAND")
24
- }
25
- )
26
- return
27
- }
28
-
29
- try {
30
- val deviceInfo = DeviceInfoUtils.getDeviceInfo(bridge.context, bridge.properties)
31
- bridge.callback(CALLBACK_SUCCESS, deviceInfo)
32
- } catch (error: Exception) {
33
- Log.e(TAG, "Failed to resolve device info", error)
34
- bridge.callback(
35
- CALLBACK_ERROR,
36
- JSONObject().apply {
37
- put("message", error.message ?: "Failed to get device info")
38
- put("code", "DEVICE_INFO_ERROR")
39
- }
40
- )
41
- }
42
- }
43
- }
@@ -1,28 +0,0 @@
1
- import Foundation
2
-
3
- final class DeviceInfoPlugin: CatalystPlugin {
4
- private let commandGetDeviceInfo = "getDeviceInfo"
5
- private let successCallback = "onSuccess"
6
- private let errorCallback = "onError"
7
-
8
- func handle(command: String, data: Any?, bridge: PluginBridgeContext) {
9
- guard command == commandGetDeviceInfo else {
10
- bridge.callback(eventName: errorCallback, data: [
11
- "message": "Unsupported command: \(command)",
12
- "code": "UNSUPPORTED_COMMAND",
13
- ])
14
- return
15
- }
16
-
17
- let deviceInfo = DeviceInfoUtils.getDeviceInfo()
18
- if let error = deviceInfo["error"] as? String {
19
- bridge.callback(eventName: errorCallback, data: [
20
- "message": error,
21
- "code": "DEVICE_INFO_ERROR",
22
- ])
23
- return
24
- }
25
-
26
- bridge.callback(eventName: successCallback, data: deviceInfo)
27
- }
28
- }
@@ -1,19 +0,0 @@
1
- {
2
- "id": "io.catalyst.device_info",
3
- "configKey": "deviceInfo",
4
- "version": "1.0.0",
5
- "displayName": "Device Info",
6
- "description": "Provides device metadata, screen metrics, app info, and platform-specific diagnostics.",
7
- "category": "device",
8
- "platforms": ["android", "ios"],
9
- "commands": ["getDeviceInfo"],
10
- "android": {
11
- "className": "io.yourname.androidproject.plugins.internal.deviceinfo.DeviceInfoPlugin",
12
- "permissions": [],
13
- "dependencies": []
14
- },
15
- "ios": {
16
- "className": "DeviceInfoPlugin",
17
- "dependencies": []
18
- }
19
- }
@@ -1 +0,0 @@
1
- "use strict";const fs=require("fs");const path=require("path");function isDir(dirPath){return fs.existsSync(dirPath)&&fs.statSync(dirPath).isDirectory();}function mustBeNonEmptyString(value,fieldName,sourcePath){if(typeof value!=="string"||!value.trim()){throw new Error(`Invalid '${fieldName}' in ${sourcePath}`);}return value.trim();}function readStringArray(value,fieldName,sourcePath,{required=false,nonEmpty=false}={}){if(!Array.isArray(value)){if(required){throw new Error(`'${fieldName}' is required and must be an array in ${sourcePath}`);}return[];}const result=value.map(entry=>mustBeNonEmptyString(entry,`${fieldName}[]`,sourcePath));if(nonEmpty&&result.length===0){throw new Error(`'${fieldName}' is required and must be non-empty in ${sourcePath}`);}return result;}function readPlainObject(value,fieldName,sourcePath){if(value==null){return{};}if(!value||typeof value!=="object"||Array.isArray(value)){throw new Error(`'${fieldName}' must be an object in ${sourcePath}`);}return value;}function cloneJsonValue(value,fieldName,sourcePath){try{return JSON.parse(JSON.stringify(value));}catch(error){throw new Error(`'${fieldName}' must be JSON-serializable in ${sourcePath}`);}}function readIosUrlSchemes(value,fieldName,sourcePath){if(value==null){return[];}if(!Array.isArray(value)){throw new Error(`'${fieldName}' must be an array in ${sourcePath}`);}return value.map((entry,index)=>{const entryField=`${fieldName}[${index}]`;if(!entry||typeof entry!=="object"||Array.isArray(entry)){throw new Error(`'${entryField}' must be an object in ${sourcePath}`);}return{name:entry.name==null?null:mustBeNonEmptyString(entry.name,`${entryField}.name`,sourcePath),schemes:readStringArray(entry.schemes,`${entryField}.schemes`,sourcePath,{required:true,nonEmpty:true})};});}function readIosDependencies(value,fieldName,sourcePath){if(value==null){return[];}if(!Array.isArray(value)){throw new Error(`'${fieldName}' must be an array in ${sourcePath}`);}return value.map((entry,index)=>{const entryField=`${fieldName}[${index}]`;if(!entry||typeof entry!=="object"||Array.isArray(entry)){throw new Error(`'${entryField}' must be an object in ${sourcePath}`);}const url=mustBeNonEmptyString(entry.url,`${entryField}.url`,sourcePath);const packageIdentity=entry.package==null?derivePackageIdentityFromUrl(url,`${entryField}.url`,sourcePath):mustBeNonEmptyString(entry.package,`${entryField}.package`,sourcePath);const products=readStringArray(entry.products,`${entryField}.products`,sourcePath,{required:true,nonEmpty:true});if(new Set(products).size!==products.length){throw new Error(`Duplicate product(s) found in '${entryField}.products' in ${sourcePath}`);}const hasFrom=entry.from!=null;const hasExact=entry.exact!=null;if(hasFrom===hasExact){throw new Error(`'${entryField}' must define exactly one version requirement: 'from' or 'exact' in ${sourcePath}`);}return{url,package:packageIdentity,products,requirement:hasFrom?{type:"from",version:mustBeNonEmptyString(entry.from,`${entryField}.from`,sourcePath)}:{type:"exact",version:mustBeNonEmptyString(entry.exact,`${entryField}.exact`,sourcePath)}};});}function derivePackageIdentityFromUrl(url,fieldName,sourcePath){const sanitizedUrl=url.replace(/\/+$/,"");const packageIdentity=sanitizedUrl.split("/").pop()?.replace(/\.git$/,"");if(!packageIdentity){throw new Error(`Unable to derive package identity from '${fieldName}' in ${sourcePath}`);}return packageIdentity;}function parsePluginManifest(pluginDir){const manifestPath=path.join(pluginDir,"manifest.json");if(!fs.existsSync(manifestPath)){return null;}let manifestContent;try{manifestContent=fs.readFileSync(manifestPath,"utf8");}catch(error){throw new Error(`Failed to read plugin manifest at ${manifestPath}: ${error.message}`);}let manifest;try{manifest=JSON.parse(manifestContent);}catch(error){throw new Error(`Invalid JSON in plugin manifest ${manifestPath}: ${error.message}`);}const id=mustBeNonEmptyString(manifest.id,"id",manifestPath);const configKey=mustBeNonEmptyString(manifest.configKey,"configKey",manifestPath);const platforms=readStringArray(manifest.platforms,"platforms",manifestPath,{required:true,nonEmpty:true});const androidConfig=platforms.includes("android")?manifest.android:null;const iosConfig=platforms.includes("ios")?manifest.ios:null;if(platforms.includes("android")&&(!androidConfig||typeof androidConfig!=="object")){throw new Error(`'android' config is required for plugin '${id}' in ${manifestPath}`);}if(platforms.includes("ios")&&(!iosConfig||typeof iosConfig!=="object")){throw new Error(`'ios' config is required for plugin '${id}' in ${manifestPath}`);}return{pluginDir,manifestPath,id,configKey,version:mustBeNonEmptyString(manifest.version,"version",manifestPath),displayName:mustBeNonEmptyString(manifest.displayName,"displayName",manifestPath),description:mustBeNonEmptyString(manifest.description,"description",manifestPath),category:mustBeNonEmptyString(manifest.category,"category",manifestPath),platforms,commands:readStringArray(manifest.commands,"commands",manifestPath,{required:true,nonEmpty:true}),android:androidConfig?{sourceDir:path.join(pluginDir,"android"),permissions:readStringArray(androidConfig.permissions,"android.permissions",manifestPath),dependencies:readStringArray(androidConfig.dependencies,"android.dependencies",manifestPath),className:mustBeNonEmptyString(androidConfig.className,"android.className",manifestPath)}:null,ios:iosConfig?{sourceDir:path.join(pluginDir,"ios"),dependencies:readIosDependencies(iosConfig.dependencies,"ios.dependencies",manifestPath),className:mustBeNonEmptyString(iosConfig.className,"ios.className",manifestPath),infoPlist:cloneJsonValue(readPlainObject(iosConfig.infoPlist,"ios.infoPlist",manifestPath),"ios.infoPlist",manifestPath),urlSchemes:readIosUrlSchemes(iosConfig.urlSchemes,"ios.urlSchemes",manifestPath),querySchemes:readStringArray(iosConfig.querySchemes,"ios.querySchemes",manifestPath),entitlements:cloneJsonValue(readPlainObject(iosConfig.entitlements,"ios.entitlements",manifestPath),"ios.entitlements",manifestPath),resources:readStringArray(iosConfig.resources,"ios.resources",manifestPath)}:null};}function discoverInternalPlugins(corePluginsRoot,log=()=>{}){if(!corePluginsRoot||!isDir(corePluginsRoot)){log(`No internal plugin directory found at ${corePluginsRoot||"<empty>"}`,"info");return[];}const plugins=[];const entries=fs.readdirSync(corePluginsRoot,{withFileTypes:true}).sort((left,right)=>left.name.localeCompare(right.name));for(const entry of entries){if(!entry.isDirectory()){continue;}const pluginDir=path.join(corePluginsRoot,entry.name);const parsed=parsePluginManifest(pluginDir);if(parsed){plugins.push(parsed);}}log(`Discovered ${plugins.length} internal plugin manifest(s)`,"info");return plugins;}function resolveInternalPluginsRoot(packageRoot){const distPluginsPath=path.join(packageRoot,"dist","native","internal-plugins");const srcPluginsPath=path.join(packageRoot,"src","native","internal-plugins");return fs.existsSync(distPluginsPath)?distPluginsPath:srcPluginsPath;}function resolvePluginConfig(WEBVIEW_CONFIG){const pluginConfig={};if(WEBVIEW_CONFIG.plugins!=null){if(typeof WEBVIEW_CONFIG.plugins!=="object"||Array.isArray(WEBVIEW_CONFIG.plugins)){throw new Error("'WEBVIEW_CONFIG.plugins' must be an object with boolean values");}for(const[key,value]of Object.entries(WEBVIEW_CONFIG.plugins)){if(typeof value!=="boolean"){throw new Error(`'WEBVIEW_CONFIG.plugins.${key}' must be boolean`);}pluginConfig[key]=value;}}return pluginConfig;}module.exports={discoverInternalPlugins,parsePluginManifest,resolvePluginConfig,resolveInternalPluginsRoot};
@@ -1,5 +0,0 @@
1
- import Foundation
2
-
3
- protocol CatalystPlugin {
4
- func handle(command: String, data: Any?, bridge: PluginBridgeContext)
5
- }
@@ -1,6 +0,0 @@
1
- import Foundation
2
-
3
- enum GeneratedPluginIndex {
4
- static let pluginFactories: [String: () -> CatalystPlugin] = [:]
5
- static let pluginToCommands: [String: Set<String>] = [:]
6
- }