@cap-kit/test-plugin 1.0.0 → 1.0.2

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 (33) hide show
  1. package/{TestPlugin.podspec → CapKitTest.podspec} +1 -1
  2. package/Package.swift +8 -5
  3. package/README.md +63 -31
  4. package/android/src/main/java/io/capkit/test/TestConfig.kt +39 -4
  5. package/android/src/main/java/io/capkit/test/TestImpl.kt +61 -0
  6. package/android/src/main/java/io/capkit/test/TestPlugin.kt +66 -10
  7. package/android/src/main/java/io/capkit/test/utils/TestLogger.kt +85 -0
  8. package/android/src/main/java/io/capkit/test/utils/TestUtils.kt +14 -0
  9. package/dist/docs.json +57 -21
  10. package/dist/esm/definitions.d.ts +137 -35
  11. package/dist/esm/definitions.js +23 -1
  12. package/dist/esm/definitions.js.map +1 -1
  13. package/dist/esm/index.d.ts +4 -4
  14. package/dist/esm/index.js +4 -16
  15. package/dist/esm/index.js.map +1 -1
  16. package/dist/esm/web.d.ts +16 -27
  17. package/dist/esm/web.js +25 -28
  18. package/dist/esm/web.js.map +1 -1
  19. package/dist/plugin.cjs.js +54 -39
  20. package/dist/plugin.cjs.js.map +1 -1
  21. package/dist/plugin.js +54 -39
  22. package/dist/plugin.js.map +1 -1
  23. package/ios/Sources/TestPlugin/TestConfig.swift +52 -9
  24. package/ios/Sources/TestPlugin/TestImpl.swift +51 -0
  25. package/ios/Sources/TestPlugin/TestPlugin.swift +83 -34
  26. package/ios/Sources/TestPlugin/Utils/TestLogger.swift +57 -0
  27. package/ios/Sources/TestPlugin/Utils/TestUtils.swift +12 -0
  28. package/ios/Tests/TestPluginTests/TestPluginTests.swift +7 -1
  29. package/package.json +11 -11
  30. package/android/src/main/java/io/capkit/test/Logger.kt +0 -25
  31. package/android/src/main/java/io/capkit/test/Test.kt +0 -20
  32. package/ios/Sources/TestPlugin/Logging.swift +0 -32
  33. package/ios/Sources/TestPlugin/Test.swift +0 -19
@@ -3,7 +3,7 @@ require 'json'
3
3
  package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
4
4
 
5
5
  Pod::Spec.new do |s|
6
- s.name = 'TestPlugin'
6
+ s.name = 'CapKitTest'
7
7
  s.version = package['version']
8
8
  s.summary = package['description']
9
9
  s.license = package['license']
package/Package.swift CHANGED
@@ -2,12 +2,13 @@
2
2
  import PackageDescription
3
3
 
4
4
  let package = Package(
5
- name: "TestPlugin",
5
+ name: "CapKitTest",
6
6
  platforms: [.iOS(.v15)],
7
7
  products: [
8
8
  .library(
9
- name: "TestPlugin",
10
- targets: ["TestPlugin"])
9
+ name: "CapKitTest",
10
+ targets: ["TestPlugin"]
11
+ )
11
12
  ],
12
13
  dependencies: [
13
14
  .package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "8.0.0")
@@ -17,8 +18,10 @@ let package = Package(
17
18
  name: "TestPlugin",
18
19
  dependencies: [
19
20
  .product(name: "Capacitor", package: "capacitor-swift-pm"),
20
- .product(name: "Cordova", package: "capacitor-swift-pm") ],
21
- path: "ios/Sources/TestPlugin" ),
21
+ .product(name: "Cordova", package: "capacitor-swift-pm")
22
+ ],
23
+ path: "ios/Sources/TestPlugin"
24
+ ),
22
25
  .testTarget(
23
26
  name: "TestPluginTests",
24
27
  dependencies: ["TestPlugin"],
package/README.md CHANGED
@@ -45,9 +45,10 @@ npx cap sync
45
45
 
46
46
  Configuration options for the Test plugin.
47
47
 
48
- | Prop | Type | Description | Default | Since |
49
- | ------------------- | ------------------- | ----------------------------------------------------------------------------------------------------------------------------- | ----------------------------- | ----- |
50
- | **`customMessage`** | <code>string</code> | A custom message to append to the echo response. This demonstrates how to pass data from `capacitor.config.ts` to the plugin. | <code>" (from config)"</code> | 0.0.1 |
48
+ | Prop | Type | Description | Default | Since |
49
+ | -------------------- | -------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------- | ----- |
50
+ | **`customMessage`** | <code>string</code> | Custom message appended to the echoed value. This option exists mainly as an example showing how to pass static configuration data from JavaScript to native platforms. | <code>" (from config)"</code> | 0.0.1 |
51
+ | **`verboseLogging`** | <code>boolean</code> | Enables verbose native logging. When enabled, additional debug information is printed to the native console (Logcat on Android, Xcode on iOS). This option affects native logging behavior only and has no impact on the JavaScript API. | <code>false</code> | 1.0.0 |
51
52
 
52
53
  ### Examples
53
54
 
@@ -57,7 +58,8 @@ In `capacitor.config.json`:
57
58
  {
58
59
  "plugins": {
59
60
  "Test": {
60
- "customMessage": " - Hello from Config!"
61
+ "customMessage": " - Hello from Config!",
62
+ "verboseLogging": true
61
63
  }
62
64
  }
63
65
  }
@@ -74,6 +76,7 @@ const config: CapacitorConfig = {
74
76
  plugins: {
75
77
  Test: {
76
78
  customMessage: ' - Hello from Config!',
79
+ verboseLogging: true,
77
80
  },
78
81
  },
79
82
  };
@@ -88,6 +91,7 @@ export default config;
88
91
  <docgen-index>
89
92
 
90
93
  * [`echo(...)`](#echo)
94
+ * [`openAppSettings()`](#openappsettings)
91
95
  * [`getPluginVersion()`](#getpluginversion)
92
96
  * [Interfaces](#interfaces)
93
97
 
@@ -96,7 +100,10 @@ export default config;
96
100
  <docgen-api>
97
101
  <!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
98
102
 
99
- Capacitor Test plugin interface.
103
+ Public JavaScript API for the Test Capacitor plugin.
104
+
105
+ This interface defines a stable, platform-agnostic API.
106
+ All methods behave consistently across Android, iOS, and Web.
100
107
 
101
108
  ### echo(...)
102
109
 
@@ -106,12 +113,15 @@ echo(options: EchoOptions) => Promise<EchoResult>
106
113
 
107
114
  Echoes the provided value.
108
115
 
109
- If the plugin is configured with a `customMessage`, it will be appended
110
- to the response.
116
+ If the plugin is configured with a `customMessage`, that value
117
+ will be appended to the returned string.
118
+
119
+ This method is primarily intended as an example demonstrating
120
+ native ↔ JavaScript communication.
111
121
 
112
- | Param | Type | Description |
113
- | ------------- | --------------------------------------------------- | ------------------------------------------- |
114
- | **`options`** | <code><a href="#echooptions">EchoOptions</a></code> | - The options containing the value to echo. |
122
+ | Param | Type | Description |
123
+ | ------------- | --------------------------------------------------- | ------------------------------------ |
124
+ | **`options`** | <code><a href="#echooptions">EchoOptions</a></code> | Object containing the value to echo. |
115
125
 
116
126
  **Returns:** <code>Promise&lt;<a href="#echoresult">EchoResult</a>&gt;</code>
117
127
 
@@ -119,13 +129,29 @@ to the response.
119
129
 
120
130
  #### Example
121
131
 
122
- ```typescript
123
- import { Test } from '@cap-kit/test-plugin';
132
+ ```ts
133
+ const { value } = await Test.echo({ value: 'Hello' });
134
+ console.log(value);
135
+ ```
124
136
 
125
- const result = await Test.echo({ value: 'Hello, World!' });
126
- console.log(result.value); // Output: 'Hello, World!'
137
+ --------------------
138
+
139
+
140
+ ### openAppSettings()
141
+
142
+ ```typescript
143
+ openAppSettings() => Promise<void>
127
144
  ```
128
145
 
146
+ Opens the operating system's application settings page.
147
+
148
+ This is typically used when a permission has been permanently
149
+ denied and the user must enable it manually.
150
+
151
+ On Web, this method is not supported.
152
+
153
+ **Since:** 1.0.0
154
+
129
155
  --------------------
130
156
 
131
157
 
@@ -135,7 +161,10 @@ console.log(result.value); // Output: 'Hello, World!'
135
161
  getPluginVersion() => Promise<PluginVersionResult>
136
162
  ```
137
163
 
138
- Get the native Capacitor plugin version.
164
+ Returns the native plugin version.
165
+
166
+ The returned version corresponds to the native implementation
167
+ bundled with the application.
139
168
 
140
169
  **Returns:** <code>Promise&lt;<a href="#pluginversionresult">PluginVersionResult</a>&gt;</code>
141
170
 
@@ -143,11 +172,8 @@ Get the native Capacitor plugin version.
143
172
 
144
173
  #### Example
145
174
 
146
- ```typescript
147
- import { Test } from '@cap-kit/test-plugin';
148
-
175
+ ```ts
149
176
  const { version } = await Test.getPluginVersion();
150
- console.log('Plugin version:', version); // Output: Plugin version: 0.0.1
151
177
  ```
152
178
 
153
179
  --------------------
@@ -158,29 +184,35 @@ console.log('Plugin version:', version); // Output: Plugin version: 0.0.1
158
184
 
159
185
  #### EchoResult
160
186
 
161
- Result returned by the echo method.
187
+ Result object returned by the `echo` method.
162
188
 
163
- | Prop | Type | Description |
164
- | ----------- | ------------------- | ----------------- |
165
- | **`value`** | <code>string</code> | The echoed value. |
189
+ This object represents the resolved value of the echo operation
190
+ after native processing has completed.
191
+
192
+ | Prop | Type | Description |
193
+ | ----------- | ------------------- | ------------------------------------------------------------------------------------------------------------- |
194
+ | **`value`** | <code>string</code> | The echoed string value. If a `customMessage` is configured, it will be appended to the original input value. |
166
195
 
167
196
 
168
197
  #### EchoOptions
169
198
 
170
- Options for the echo method.
199
+ Options object for the `echo` method.
200
+
201
+ This object defines the input payload sent from JavaScript
202
+ to the native plugin implementation.
171
203
 
172
- | Prop | Type | Description |
173
- | ----------- | ------------------- | ----------------------- |
174
- | **`value`** | <code>string</code> | The value to be echoed. |
204
+ | Prop | Type | Description |
205
+ | ----------- | ------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
206
+ | **`value`** | <code>string</code> | The string value to be echoed back by the plugin. This value is passed to the native layer and returned unchanged, optionally with a configuration-based suffix. |
175
207
 
176
208
 
177
209
  #### PluginVersionResult
178
210
 
179
- Result returned by the getPluginVersion method.
211
+ Result object returned by the `getPluginVersion()` method.
180
212
 
181
- | Prop | Type | Description |
182
- | ------------- | ------------------- | ---------------------------------------- |
183
- | **`version`** | <code>string</code> | The native version string of the plugin. |
213
+ | Prop | Type | Description |
214
+ | ------------- | ------------------- | --------------------------------- |
215
+ | **`version`** | <code>string</code> | The native plugin version string. |
184
216
 
185
217
  </docgen-api>
186
218
 
@@ -1,16 +1,51 @@
1
1
  package io.capkit.test
2
2
 
3
+ import android.content.Context
3
4
  import com.getcapacitor.Plugin
4
5
 
5
6
  /**
6
- * Helper class to manage the plugin configuration.
7
- * It parses the values from capacitor.config.json
7
+ * Plugin configuration holder.
8
+ *
9
+ * This class is responsible for reading and parsing configuration values
10
+ * defined under the `Test` key in `capacitor.config.ts`.
11
+ *
12
+ * Configuration is read once during plugin initialization and treated as
13
+ * immutable runtime input.
8
14
  */
9
15
  class TestConfig(plugin: Plugin) {
16
+ /**
17
+ * Android application context.
18
+ * Exposed for native components that may require it.
19
+ */
20
+ val context: Context
21
+
22
+ /**
23
+ * Enables verbose / debug logging for the plugin.
24
+ *
25
+ * When enabled, additional logs are printed to Logcat via [Logger.debug].
26
+ *
27
+ * Default: false
28
+ */
29
+ val verboseLogging: Boolean
30
+
31
+ /**
32
+ * Optional custom message appended to echoed values.
33
+ *
34
+ * This value is provided for demonstration purposes and shows how to
35
+ * pass static configuration from JavaScript to native code.
36
+ */
10
37
  val customMessage: String
11
38
 
12
39
  init {
13
- // "customMessage" must match the key in capacitor.config.ts
14
- customMessage = plugin.getConfig().getString("customMessage") ?: " (from config)"
40
+ context = plugin.context
41
+
42
+ val config = plugin.getConfig()
43
+
44
+ // Parse verboseLogging (default: false)
45
+ verboseLogging = config.getBoolean("verboseLogging", false)
46
+
47
+ // Parse customMessage (default fallback applied)
48
+ val cm = config.getString("customMessage")
49
+ customMessage = if (cm.isNullOrBlank()) " (from config)" else cm
15
50
  }
16
51
  }
@@ -0,0 +1,61 @@
1
+ package io.capkit.test
2
+
3
+ import android.content.Context
4
+ import io.capkit.test.utils.TestLogger
5
+
6
+ /**
7
+ * Platform-specific native implementation for the Test plugin.
8
+ *
9
+ * This class contains pure Android logic and MUST NOT depend
10
+ * directly on Capacitor bridge APIs.
11
+ *
12
+ * The Capacitor plugin class is responsible for:
13
+ * - reading configuration
14
+ * - handling PluginCall objects
15
+ * - delegating logic to this implementation
16
+ */
17
+ class TestImpl(
18
+ private val context: Context,
19
+ ) {
20
+ /**
21
+ * Cached plugin configuration.
22
+ * Provided once during initialization.
23
+ */
24
+ private lateinit var config: TestConfig
25
+
26
+ /**
27
+ * Applies the plugin configuration.
28
+ *
29
+ * This method should be called exactly once during plugin load
30
+ * and is responsible for translating configuration values into
31
+ * runtime behavior (e.g. logging verbosity).
32
+ */
33
+ fun updateConfig(newConfig: TestConfig) {
34
+ this.config = newConfig
35
+ TestLogger.verbose = this.config.verboseLogging
36
+ TestLogger.debug("Configuration updated. Verbose logging: ${this.config.verboseLogging}")
37
+ }
38
+
39
+ /**
40
+ * Echoes the provided value.
41
+ *
42
+ * This method represents a simple synchronous native operation
43
+ * and is intentionally side-effect free.
44
+ */
45
+ fun echo(value: String): String {
46
+ TestLogger.debug(value)
47
+ return value
48
+ }
49
+
50
+ companion object {
51
+ /**
52
+ * Account type identifier (example constant).
53
+ */
54
+ const val ACCOUNT_TYPE = "io.capkit.test"
55
+
56
+ /**
57
+ * Human-readable account name (example constant).
58
+ */
59
+ const val ACCOUNT_NAME = "Test"
60
+ }
61
+ }
@@ -1,34 +1,57 @@
1
1
  package io.capkit.test
2
2
 
3
+ import android.content.Intent
4
+ import android.net.Uri
5
+ import android.provider.Settings
6
+ import androidx.activity.result.ActivityResult
3
7
  import com.getcapacitor.JSObject
4
8
  import com.getcapacitor.Plugin
5
9
  import com.getcapacitor.PluginCall
6
10
  import com.getcapacitor.PluginMethod
11
+ import com.getcapacitor.annotation.ActivityCallback
7
12
  import com.getcapacitor.annotation.CapacitorPlugin
13
+ import io.capkit.test.utils.TestLogger
8
14
 
9
15
  /**
10
16
  * Capacitor bridge for the Test plugin.
11
17
  *
12
- * This class exposes native Android functionality to JavaScript
13
- * and delegates all business logic to the implementation class.
18
+ * This class acts as the boundary between JavaScript and native Android code.
19
+ * It is responsible for:
20
+ * - reading configuration
21
+ * - validating PluginCall input
22
+ * - mapping JS calls to native logic
14
23
  */
15
24
  @CapacitorPlugin(
16
25
  name = "Test",
17
26
  )
18
27
  class TestPlugin : Plugin() {
28
+ /**
29
+ * Plugin configuration parsed from capacitor.config.ts.
30
+ */
19
31
  private lateinit var config: TestConfig
20
32
 
33
+ /**
34
+ * Native implementation containing platform logic.
35
+ */
36
+ private lateinit var implementation: TestImpl
37
+
38
+ /**
39
+ * Called once when the plugin is loaded by the Capacitor bridge.
40
+ *
41
+ * This is the correct place to:
42
+ * - read configuration
43
+ * - initialize native resources
44
+ * - inject dependencies into the implementation
45
+ */
21
46
  override fun load() {
22
47
  super.load()
23
- Logger.debug("Loading plugin")
48
+
24
49
  config = TestConfig(this)
50
+ implementation = TestImpl(context)
51
+ implementation.updateConfig(config)
25
52
  }
26
53
 
27
- /** Plugin version (injected by Gradle). */
28
- private val pluginVersion: String = BuildConfig.PLUGIN_VERSION
29
-
30
- /** Native implementation (business logic). */
31
- private val implementation = Test()
54
+ // --- ---
32
55
 
33
56
  /**
34
57
  * Echoes a string back to JavaScript.
@@ -38,7 +61,7 @@ class TestPlugin : Plugin() {
38
61
  @PluginMethod
39
62
  fun echo(call: PluginCall) {
40
63
  var value = call.getString("value") ?: ""
41
- Logger.debug("Echoing value: $value")
64
+ TestLogger.debug("Echoing value: $value")
42
65
 
43
66
  // Append the custom message from the configuration
44
67
  value += config.customMessage
@@ -48,13 +71,46 @@ class TestPlugin : Plugin() {
48
71
  call.resolve(ret)
49
72
  }
50
73
 
74
+ // --- Version ---
75
+
51
76
  /**
52
77
  * Returns the plugin version.
53
78
  */
54
79
  @PluginMethod
55
80
  fun getPluginVersion(call: PluginCall) {
56
81
  val ret = JSObject()
57
- ret.put("version", pluginVersion)
82
+ ret.put("version", BuildConfig.PLUGIN_VERSION)
58
83
  call.resolve(ret)
59
84
  }
85
+
86
+ // --- Settings ---
87
+
88
+ /**
89
+ * Opens the application details settings page.
90
+ * Allowing the user to manually enable permissions.
91
+ */
92
+ @PluginMethod
93
+ fun openAppSettings(call: PluginCall) {
94
+ try {
95
+ val intent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
96
+ val uri = Uri.fromParts("package", context.packageName, null)
97
+ intent.data = uri
98
+ startActivityForResult(call, intent, "openSettingsResult")
99
+ call.resolve()
100
+ } catch (e: Exception) {
101
+ call.reject(
102
+ "Failed to open settings",
103
+ "UNAVAILABLE",
104
+ )
105
+ }
106
+ }
107
+
108
+ @ActivityCallback
109
+ private fun openSettingsResult(
110
+ call: PluginCall,
111
+ result: ActivityResult,
112
+ ) {
113
+ // No-op, just to satisfy the callback requirement if needed
114
+ call.resolve()
115
+ }
60
116
  }
@@ -0,0 +1,85 @@
1
+ package io.capkit.test.utils
2
+
3
+ import android.util.Log
4
+
5
+ /**
6
+ * Centralized logging utility for the Test plugin.
7
+ *
8
+ * This logger provides a single entry point for all native logs
9
+ * and supports runtime-controlled verbose logging.
10
+ *
11
+ * The goal is to avoid scattering `if (verbose)` checks across
12
+ * business logic and keep logging behavior consistent.
13
+ */
14
+ object TestLogger {
15
+ /**
16
+ * Logcat tag used for all plugin logs.
17
+ * Helps filtering logs during debugging.
18
+ */
19
+ private const val TAG = "⚡️ Test"
20
+
21
+ /**
22
+ * Controls whether debug logs are printed.
23
+ *
24
+ * This flag should be set once during plugin initialization
25
+ * based on configuration values.
26
+ */
27
+ var verbose: Boolean = false
28
+
29
+ /**
30
+ * Prints a debug / verbose log message.
31
+ *
32
+ * This method should be used for development-time diagnostics
33
+ * and is automatically silenced when [verbose] is false.
34
+ *
35
+ * @param messages One or more message fragments to be concatenated.
36
+ */
37
+ fun debug(vararg messages: String) {
38
+ if (verbose) {
39
+ log(TAG, Log.DEBUG, *messages)
40
+ }
41
+ }
42
+
43
+ /**
44
+ * Prints an error log message.
45
+ *
46
+ * Error logs are always printed regardless of [verbose] state.
47
+ *
48
+ * @param message Human-readable error description.
49
+ * @param e Optional exception for stack trace logging.
50
+ */
51
+ fun error(
52
+ message: String,
53
+ e: Throwable? = null,
54
+ ) {
55
+ val sb = StringBuilder(message)
56
+ if (e != null) {
57
+ sb.append(" | Error: ").append(e.message)
58
+ }
59
+ Log.e(TAG, sb.toString(), e)
60
+ }
61
+
62
+ /**
63
+ * Internal low-level log dispatcher.
64
+ *
65
+ * Joins message fragments and forwards them to Android's Log API
66
+ * using the specified priority.
67
+ */
68
+ fun log(
69
+ tag: String,
70
+ level: Int,
71
+ vararg messages: String,
72
+ ) {
73
+ val sb = StringBuilder()
74
+ for (msg in messages) {
75
+ sb.append(msg).append(" ")
76
+ }
77
+ when (level) {
78
+ Log.DEBUG -> Log.d(tag, sb.toString())
79
+ Log.INFO -> Log.i(tag, sb.toString())
80
+ Log.WARN -> Log.w(tag, sb.toString())
81
+ Log.ERROR -> Log.e(tag, sb.toString())
82
+ else -> Log.v(tag, sb.toString())
83
+ }
84
+ }
85
+ }
@@ -0,0 +1,14 @@
1
+ package io.capkit.test.utils
2
+
3
+ /**
4
+ * Utility helpers for the Test plugin.
5
+ *
6
+ * This object is intentionally empty and serves as a placeholder
7
+ * for future shared utility functions.
8
+ *
9
+ * Keeping a dedicated utils package helps maintain a clean
10
+ * separation between core logic and helper code.
11
+ */
12
+ object TestUtils {
13
+ // Utilities will be added here as the plugin evolves
14
+ }