capacitor-gleap-plugin 19.0.0 → 19.1.0

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.
@@ -1981,6 +1981,7 @@ class WebViewLogCapture {
1981
1981
  // logs are enabled (like the JavaScript SDK), so nothing is held in memory before that.
1982
1982
  this.networkCapture.install();
1983
1983
  this.listenForConfig();
1984
+ this.listenForFlush();
1984
1985
  }
1985
1986
  /**
1986
1987
  * Android debug builds (Capacitor's loggingBehavior) write the WebView console to logcat, which the
@@ -2003,6 +2004,36 @@ class WebViewLogCapture {
2003
2004
  // The native side predates the event: network logs stay off.
2004
2005
  }
2005
2006
  }
2007
+ /**
2008
+ * Capture requests: right before the native SDK collects the logs for a request, it asks for what is still
2009
+ * buffered here (pushed at most every PUSH_DELAY_MS otherwise) and waits up to 500 ms for the answer.
2010
+ */
2011
+ listenForFlush() {
2012
+ try {
2013
+ const handle = this.target.addListener('flushLogs', (data) => {
2014
+ const flushId = data && typeof data.flushId === 'string' ? data.flushId : null;
2015
+ runOutsideZone(() => this.flushNow().then(() => {
2016
+ if (flushId) {
2017
+ this.answerFlush(flushId);
2018
+ }
2019
+ }));
2020
+ });
2021
+ if (handle && typeof handle.catch === 'function') {
2022
+ handle.catch(() => undefined);
2023
+ }
2024
+ }
2025
+ catch (e) {
2026
+ // The native side predates the event: nothing asks for flushes.
2027
+ }
2028
+ }
2029
+ answerFlush(flushId) {
2030
+ try {
2031
+ Promise.resolve(this.target.logsFlushed({ flushId })).catch(() => undefined);
2032
+ }
2033
+ catch (e) {
2034
+ // The native side gives up waiting after 500 ms.
2035
+ }
2036
+ }
2006
2037
  applyRemoteConfig(config) {
2007
2038
  try {
2008
2039
  if (!config || typeof config !== 'object') {
@@ -2045,15 +2076,20 @@ class WebViewLogCapture {
2045
2076
  this.markDirty(this.consoleChannel);
2046
2077
  this.markDirty(this.networkChannel);
2047
2078
  }
2048
- /** Pushes pending changes now (before a plugin call that can produce a report). */
2079
+ /**
2080
+ * Pushes pending changes now (before a plugin call that can produce a report, or when the native SDK collects the
2081
+ * logs for a capture request). Resolves once the native side took them; never rejects.
2082
+ */
2049
2083
  flushNow() {
2084
+ const pushes = [];
2050
2085
  try {
2051
- this.flushChannel(this.consoleChannel);
2052
- this.flushChannel(this.networkChannel);
2086
+ pushes.push(this.flushChannel(this.consoleChannel));
2087
+ pushes.push(this.flushChannel(this.networkChannel));
2053
2088
  }
2054
2089
  catch (e) {
2055
2090
  // Ignore.
2056
2091
  }
2092
+ return Promise.all(pushes).then(() => undefined, () => undefined);
2057
2093
  }
2058
2094
  updateRules() {
2059
2095
  this.rules = createRedactionRules([...this.remoteProps, ...this.localProps], [...this.remoteBlacklist, ...this.localBlacklist]);
@@ -2084,20 +2120,21 @@ class WebViewLogCapture {
2084
2120
  channel.timer = null;
2085
2121
  }
2086
2122
  }
2123
+ /** Resolves once the push it started (if any) was answered; never rejects. */
2087
2124
  flushChannel(channel) {
2088
2125
  if (channel.timer !== null) {
2089
2126
  clearTimeout(channel.timer);
2090
2127
  channel.timer = null;
2091
2128
  }
2092
2129
  if (!channel.isDirty || !this.canPush(channel)) {
2093
- return;
2130
+ return Promise.resolve();
2094
2131
  }
2095
2132
  channel.isDirty = false;
2096
2133
  let push;
2097
2134
  if (channel.name === 'console') {
2098
2135
  const logs = this.consoleCapture ? this.consoleCapture.getEntries() : [];
2099
2136
  if (logs.length === 0 && !channel.hasPushedLogs) {
2100
- return;
2137
+ return Promise.resolve();
2101
2138
  }
2102
2139
  channel.hasPushedLogs = logs.length > 0;
2103
2140
  push = runOutsideZone(() => this.target.attachConsoleLogs({ logs }));
@@ -2105,18 +2142,19 @@ class WebViewLogCapture {
2105
2142
  else {
2106
2143
  const logs = this.isNetworkEnabled ? this.buildNetworkLogs() : [];
2107
2144
  if (logs.length === 0 && !channel.hasPushedLogs) {
2108
- return;
2145
+ return Promise.resolve();
2109
2146
  }
2110
2147
  channel.hasPushedLogs = logs.length > 0;
2111
2148
  push = runOutsideZone(() => this.target.attachNetworkLogs({ logs }));
2112
2149
  }
2113
2150
  try {
2114
- Promise.resolve(push).then(() => {
2151
+ return Promise.resolve(push).then(() => {
2115
2152
  channel.failures = 0;
2116
2153
  }, () => this.onPushFailed(channel));
2117
2154
  }
2118
2155
  catch (e) {
2119
2156
  this.onPushFailed(channel);
2157
+ return Promise.resolve();
2120
2158
  }
2121
2159
  }
2122
2160
  onPushFailed(channel) {
@@ -2441,6 +2479,10 @@ class GleapWeb extends core.WebPlugin {
2441
2479
  Gleap$1.openConversations(options.showBackButton);
2442
2480
  return { conversationsOpened: true };
2443
2481
  }
2482
+ // The JavaScript SDK opens `?gleapFile=` links itself on page load.
2483
+ async openProtectedFileFromUrl(_options) {
2484
+ return { opened: false };
2485
+ }
2444
2486
  async showSurvey(options) {
2445
2487
  Gleap$1.showSurvey(options.surveyId, options.format);
2446
2488
  return { opened: true };
@@ -2469,6 +2511,28 @@ class GleapWeb extends core.WebPlugin {
2469
2511
  });
2470
2512
  return { colorScheme: options.colorScheme };
2471
2513
  }
2514
+ async setCaptureEnabled(options) {
2515
+ if (typeof (options === null || options === void 0 ? void 0 : options.enabled) !== 'boolean') {
2516
+ throw new Error('No enabled value provided');
2517
+ }
2518
+ // A JavaScript SDK older than capture requests has nothing to switch.
2519
+ const jsSdk = Gleap$1;
2520
+ if (typeof jsSdk.setCaptureEnabled === 'function') {
2521
+ jsSdk.setCaptureEnabled(options.enabled);
2522
+ }
2523
+ return { captureEnabled: options.enabled };
2524
+ }
2525
+ async setRemoteLogCollectionEnabled(options) {
2526
+ if (typeof (options === null || options === void 0 ? void 0 : options.enabled) !== 'boolean') {
2527
+ throw new Error('No enabled value provided');
2528
+ }
2529
+ // A JavaScript SDK older than capture requests has nothing to switch.
2530
+ const jsSdk = Gleap$1;
2531
+ if (typeof jsSdk.setRemoteLogCollectionEnabled === 'function') {
2532
+ jsSdk.setRemoteLogCollectionEnabled(options.enabled);
2533
+ }
2534
+ return { remoteLogCollectionEnabled: options.enabled };
2535
+ }
2472
2536
  async identify(options) {
2473
2537
  var userData = {
2474
2538
  name: options.name,
@@ -2506,6 +2570,9 @@ class GleapWeb extends core.WebPlugin {
2506
2570
  // The JavaScript SDK records the page's requests itself on web.
2507
2571
  return { networkLogsAttached: false };
2508
2572
  }
2573
+ async logsFlushed() {
2574
+ // The JavaScript SDK collects the logs on web itself: nothing is buffered here.
2575
+ }
2509
2576
  async attachConsoleLogs() {
2510
2577
  // The JavaScript SDK records the page's console itself on web.
2511
2578
  return { consoleLogsAttached: false };