capacitor-pica-network-logger 0.2.5 → 0.2.6

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.
@@ -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"))
@@ -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)
@@ -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,6 +64,8 @@ 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
+ guard enabled else { return }
58
69
  if let size = config["maxBodySize"] as? Int {
59
70
  InspectorLogger.shared.setMaxBodySize(size)
60
71
  }
@@ -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())
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "capacitor-pica-network-logger",
3
- "version": "0.2.5",
3
+ "version": "0.2.6",
4
4
  "description": "Capacitor HTTP network logger with debug-only native capture",
5
5
  "license": "MIT",
6
6
  "repository": {