capacitor-pica-network-logger 0.2.6 → 0.2.8
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
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]`. |
|
|
@@ -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
|
}
|
|
@@ -65,6 +65,9 @@ public class PicaNetworkLoggerPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
65
65
|
super.load()
|
|
66
66
|
let config = configProvider.getConfig(self)
|
|
67
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)
|
|
68
71
|
guard enabled else { return }
|
|
69
72
|
if let size = config["maxBodySize"] as? Int {
|
|
70
73
|
InspectorLogger.shared.setMaxBodySize(size)
|
|
@@ -72,9 +75,6 @@ public class PicaNetworkLoggerPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
72
75
|
let headers = config["redactHeaders"] as? [String] ?? []
|
|
73
76
|
let jsonFields = config["redactJsonFields"] as? [String] ?? []
|
|
74
77
|
InspectorLogger.shared.setRedaction(headers: headers, jsonFields: jsonFields)
|
|
75
|
-
let notify = config["notify"] as? Bool ?? true
|
|
76
|
-
InspectorLogger.shared.setNotify(enabled: notify)
|
|
77
|
-
requestNotificationPermissionIfNeeded(enabled: notify)
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
private func requestNotificationPermissionIfNeeded(enabled: Bool) {
|