capacitor-pica-network-logger 0.2.5 → 0.2.7
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/README.md +2 -0
- package/android/src/main/java/com/linakis/capacitorpicanetworklogger/LoggerConfigProvider.kt +1 -0
- package/android/src/main/java/com/linakis/capacitorpicanetworklogger/PicaNetworkLoggerPlugin.kt +18 -1
- package/ios/Plugin/LoggerConfigProvider.swift +23 -9
- package/ios/Plugin/PicaNetworkLoggerPlugin.swift +18 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -46,6 +46,7 @@ Add to your app's `capacitor.config.ts`:
|
|
|
46
46
|
```ts
|
|
47
47
|
plugins: {
|
|
48
48
|
PicaNetworkLogger: {
|
|
49
|
+
enabled: true, // enable the plugin (default: true)
|
|
49
50
|
maxBodySize: 131072, // max chars per body (default: 128 KB)
|
|
50
51
|
notify: true, // show notifications per request (default: true)
|
|
51
52
|
redactHeaders: ["authorization", "cookie"], // header names to redact (default: none)
|
|
@@ -56,6 +57,7 @@ plugins: {
|
|
|
56
57
|
|
|
57
58
|
| Option | Type | Default | Description |
|
|
58
59
|
|---|---|---|---|
|
|
60
|
+
| `enabled` | `boolean` | `true` | Enable the plugin. When `false`, all methods are no-ops and no notifications are requested. |
|
|
59
61
|
| `maxBodySize` | `number` | `131072` | Maximum characters stored per request/response body. Truncated beyond this. |
|
|
60
62
|
| `notify` | `boolean` | `true` | Post a local notification for each completed request. On Android 13+ requests `POST_NOTIFICATIONS` permission. |
|
|
61
63
|
| `redactHeaders` | `string[]` | `[]` | Header names (case-insensitive) whose values are replaced with `[REDACTED]`. |
|
package/android/src/main/java/com/linakis/capacitorpicanetworklogger/LoggerConfigProvider.kt
CHANGED
|
@@ -7,6 +7,7 @@ class LoggerConfigProvider {
|
|
|
7
7
|
fun getConfig(plugin: Plugin): JSObject {
|
|
8
8
|
val config = plugin.bridge.config.getPluginConfiguration("PicaNetworkLogger")
|
|
9
9
|
val output = JSObject()
|
|
10
|
+
output.put("enabled", config.getBoolean("enabled", true))
|
|
10
11
|
output.put("maxBodySize", config.getInt("maxBodySize", 131072))
|
|
11
12
|
output.put("redactHeaders", config.getArray("redactHeaders"))
|
|
12
13
|
output.put("redactJsonFields", config.getArray("redactJsonFields"))
|
package/android/src/main/java/com/linakis/capacitorpicanetworklogger/PicaNetworkLoggerPlugin.kt
CHANGED
|
@@ -14,11 +14,14 @@ import org.json.JSONObject
|
|
|
14
14
|
class PicaNetworkLoggerPlugin : Plugin() {
|
|
15
15
|
private val repository = LogRepository()
|
|
16
16
|
private val configProvider = LoggerConfigProvider()
|
|
17
|
+
private var enabled = true
|
|
17
18
|
|
|
18
19
|
override fun load() {
|
|
19
20
|
super.load()
|
|
20
|
-
repository.attach(bridge.context)
|
|
21
21
|
val config = configProvider.getConfig(this)
|
|
22
|
+
enabled = config.optBoolean("enabled", true)
|
|
23
|
+
if (!enabled) return
|
|
24
|
+
repository.attach(bridge.context)
|
|
22
25
|
LogRepositoryStore.attach(bridge.context, repository, config.getInt("maxBodySize"))
|
|
23
26
|
val redactHeaders = config.get("redactHeaders")?.let { value ->
|
|
24
27
|
when (value) {
|
|
@@ -54,6 +57,12 @@ class PicaNetworkLoggerPlugin : Plugin() {
|
|
|
54
57
|
|
|
55
58
|
@PluginMethod
|
|
56
59
|
fun startRequest(call: PluginCall) {
|
|
60
|
+
if (!enabled) {
|
|
61
|
+
val ret = JSObject()
|
|
62
|
+
ret.put("id", "")
|
|
63
|
+
call.resolve(ret)
|
|
64
|
+
return
|
|
65
|
+
}
|
|
57
66
|
val method = call.getString("method") ?: "GET"
|
|
58
67
|
val url = call.getString("url") ?: ""
|
|
59
68
|
val headers = call.getObject("headers")?.let { obj ->
|
|
@@ -69,6 +78,10 @@ class PicaNetworkLoggerPlugin : Plugin() {
|
|
|
69
78
|
|
|
70
79
|
@PluginMethod
|
|
71
80
|
fun finishRequest(call: PluginCall) {
|
|
81
|
+
if (!enabled) {
|
|
82
|
+
call.resolve()
|
|
83
|
+
return
|
|
84
|
+
}
|
|
72
85
|
val id = call.getString("id") ?: return call.reject("Missing id")
|
|
73
86
|
val status = call.getInt("status")
|
|
74
87
|
val headers = call.getObject("headers")?.let { obj ->
|
|
@@ -82,6 +95,10 @@ class PicaNetworkLoggerPlugin : Plugin() {
|
|
|
82
95
|
|
|
83
96
|
@PluginMethod
|
|
84
97
|
fun openInspector(call: PluginCall) {
|
|
98
|
+
if (!enabled) {
|
|
99
|
+
call.resolve()
|
|
100
|
+
return
|
|
101
|
+
}
|
|
85
102
|
val context = bridge.context
|
|
86
103
|
val intent = android.content.Intent(context, InspectorActivity::class.java)
|
|
87
104
|
intent.addFlags(android.content.Intent.FLAG_ACTIVITY_NEW_TASK)
|
|
@@ -4,17 +4,31 @@ import Capacitor
|
|
|
4
4
|
|
|
5
5
|
class LoggerConfigProvider {
|
|
6
6
|
func getConfig(_ plugin: CAPPlugin) -> [String: Any] {
|
|
7
|
-
let
|
|
8
|
-
|
|
9
|
-
if let key = item.key as? String {
|
|
10
|
-
dict[key] = item.value
|
|
11
|
-
}
|
|
7
|
+
guard let bridgeConfig = plugin.bridge?.config else {
|
|
8
|
+
return defaults()
|
|
12
9
|
}
|
|
10
|
+
let pluginConfig = bridgeConfig.getPluginConfig("PicaNetworkLogger")
|
|
11
|
+
let enabled = pluginConfig.getBoolean("enabled", true)
|
|
12
|
+
let notify = pluginConfig.getBoolean("notify", true)
|
|
13
|
+
let maxBodySize = pluginConfig.getInt("maxBodySize", 131072)
|
|
14
|
+
let redactHeaders = bridgeConfig.getPluginConfigValue("PicaNetworkLogger", "redactHeaders") as? [String] ?? []
|
|
15
|
+
let redactJsonFields = bridgeConfig.getPluginConfigValue("PicaNetworkLogger", "redactJsonFields") as? [String] ?? []
|
|
13
16
|
return [
|
|
14
|
-
"enabled":
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
17
|
+
"enabled": enabled,
|
|
18
|
+
"notify": notify,
|
|
19
|
+
"maxBodySize": maxBodySize,
|
|
20
|
+
"redactHeaders": redactHeaders,
|
|
21
|
+
"redactJsonFields": redactJsonFields
|
|
22
|
+
]
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
private func defaults() -> [String: Any] {
|
|
26
|
+
return [
|
|
27
|
+
"enabled": true,
|
|
28
|
+
"notify": true,
|
|
29
|
+
"maxBodySize": 131072,
|
|
30
|
+
"redactHeaders": [] as [String],
|
|
31
|
+
"redactJsonFields": [] as [String]
|
|
18
32
|
]
|
|
19
33
|
}
|
|
20
34
|
}
|
|
@@ -14,8 +14,13 @@ public class PicaNetworkLoggerPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
14
14
|
CAPPluginMethod(name: "openInspector", returnType: CAPPluginReturnPromise)
|
|
15
15
|
]
|
|
16
16
|
private let configProvider = LoggerConfigProvider()
|
|
17
|
+
private var enabled = true
|
|
17
18
|
|
|
18
19
|
@objc func startRequest(_ call: CAPPluginCall) {
|
|
20
|
+
guard enabled else {
|
|
21
|
+
call.resolve(["id": ""])
|
|
22
|
+
return
|
|
23
|
+
}
|
|
19
24
|
let id = UUID().uuidString
|
|
20
25
|
let method = call.getString("method") ?? "GET"
|
|
21
26
|
let url = call.getString("url") ?? ""
|
|
@@ -32,6 +37,10 @@ public class PicaNetworkLoggerPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
32
37
|
}
|
|
33
38
|
|
|
34
39
|
@objc func finishRequest(_ call: CAPPluginCall) {
|
|
40
|
+
guard enabled else {
|
|
41
|
+
call.resolve()
|
|
42
|
+
return
|
|
43
|
+
}
|
|
35
44
|
guard let id = call.getString("id") else {
|
|
36
45
|
call.reject("Missing id")
|
|
37
46
|
return
|
|
@@ -55,15 +64,17 @@ public class PicaNetworkLoggerPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
55
64
|
public override func load() {
|
|
56
65
|
super.load()
|
|
57
66
|
let config = configProvider.getConfig(self)
|
|
67
|
+
enabled = config["enabled"] as? Bool ?? true
|
|
68
|
+
let notify = config["notify"] as? Bool ?? true
|
|
69
|
+
InspectorLogger.shared.setNotify(enabled: notify && enabled)
|
|
70
|
+
requestNotificationPermissionIfNeeded(enabled: notify && enabled)
|
|
71
|
+
guard enabled else { return }
|
|
58
72
|
if let size = config["maxBodySize"] as? Int {
|
|
59
73
|
InspectorLogger.shared.setMaxBodySize(size)
|
|
60
74
|
}
|
|
61
75
|
let headers = config["redactHeaders"] as? [String] ?? []
|
|
62
76
|
let jsonFields = config["redactJsonFields"] as? [String] ?? []
|
|
63
77
|
InspectorLogger.shared.setRedaction(headers: headers, jsonFields: jsonFields)
|
|
64
|
-
let notify = config["notify"] as? Bool ?? true
|
|
65
|
-
InspectorLogger.shared.setNotify(enabled: notify)
|
|
66
|
-
requestNotificationPermissionIfNeeded(enabled: notify)
|
|
67
78
|
}
|
|
68
79
|
|
|
69
80
|
private func requestNotificationPermissionIfNeeded(enabled: Bool) {
|
|
@@ -74,6 +85,10 @@ public class PicaNetworkLoggerPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
74
85
|
}
|
|
75
86
|
|
|
76
87
|
@objc func openInspector(_ call: CAPPluginCall) {
|
|
88
|
+
guard enabled else {
|
|
89
|
+
call.resolve()
|
|
90
|
+
return
|
|
91
|
+
}
|
|
77
92
|
#if canImport(UIKit)
|
|
78
93
|
DispatchQueue.main.async { [weak self] in
|
|
79
94
|
let inspector = UINavigationController(rootViewController: InspectorViewController())
|