@ngrok/ngrok 0.5.1 → 0.5.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ngrok/ngrok",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "main": "index.js",
5
5
  "types": "index.d.ts",
6
6
  "napi": {
@@ -47,7 +47,7 @@
47
47
  "docs": "mv trailer.d.ts trailer.d.hidden; mv examples .examples; npx typedoc index.d.ts --navigation.includeGroups; mv .examples examples; mv trailer.d.hidden trailer.d.ts",
48
48
  "prepublishOnly": "napi prepublish -t npm",
49
49
  "prettier": "prettier --write .",
50
- "test": "ava",
50
+ "test": "tsc --strict index.d.ts && ava",
51
51
  "universal": "napi universal",
52
52
  "version": "napi version"
53
53
  },
@@ -55,18 +55,18 @@
55
55
  "description": "The ngrok agent in library form, suitable for integrating directly into your NodeJS application.",
56
56
  "repository": "https://github.com/ngrok/ngrok-nodejs",
57
57
  "optionalDependencies": {
58
- "@ngrok/ngrok-win32-x64-msvc": "0.5.1",
59
- "@ngrok/ngrok-darwin-x64": "0.5.1",
60
- "@ngrok/ngrok-linux-x64-gnu": "0.5.1",
61
- "@ngrok/ngrok-darwin-arm64": "0.5.1",
62
- "@ngrok/ngrok-android-arm64": "0.5.1",
63
- "@ngrok/ngrok-linux-arm64-gnu": "0.5.1",
64
- "@ngrok/ngrok-linux-arm64-musl": "0.5.1",
65
- "@ngrok/ngrok-linux-arm-gnueabihf": "0.5.1",
66
- "@ngrok/ngrok-linux-x64-musl": "0.5.1",
67
- "@ngrok/ngrok-freebsd-x64": "0.5.1",
68
- "@ngrok/ngrok-win32-ia32-msvc": "0.5.1",
69
- "@ngrok/ngrok-android-arm-eabi": "0.5.1",
70
- "@ngrok/ngrok-darwin-universal": "0.5.1"
58
+ "@ngrok/ngrok-win32-x64-msvc": "0.5.2",
59
+ "@ngrok/ngrok-darwin-x64": "0.5.2",
60
+ "@ngrok/ngrok-linux-x64-gnu": "0.5.2",
61
+ "@ngrok/ngrok-darwin-arm64": "0.5.2",
62
+ "@ngrok/ngrok-android-arm64": "0.5.2",
63
+ "@ngrok/ngrok-linux-arm64-gnu": "0.5.2",
64
+ "@ngrok/ngrok-linux-arm64-musl": "0.5.2",
65
+ "@ngrok/ngrok-linux-arm-gnueabihf": "0.5.2",
66
+ "@ngrok/ngrok-linux-x64-musl": "0.5.2",
67
+ "@ngrok/ngrok-freebsd-x64": "0.5.2",
68
+ "@ngrok/ngrok-win32-ia32-msvc": "0.5.2",
69
+ "@ngrok/ngrok-android-arm-eabi": "0.5.2",
70
+ "@ngrok/ngrok-darwin-universal": "0.5.2"
71
71
  }
72
72
  }
package/src/connect.rs CHANGED
@@ -146,7 +146,7 @@ async fn async_connect(s_builder: NgrokSessionBuilder, config: Config) -> Result
146
146
  _ => return Err(napi_err(format!("unhandled protocol {proto}"))),
147
147
  };
148
148
 
149
- let url = tunnel::get_url(&id).await.expect("no url found");
149
+ let url = tunnel::get_url(&id).await.unwrap_or(id.clone());
150
150
 
151
151
  // move forwarding to another task
152
152
  if let Some(addr) = config.addr {
package/src/session.rs CHANGED
@@ -479,7 +479,7 @@ impl NgrokSession {
479
479
  session
480
480
  .close()
481
481
  .await
482
- .map_err(|e| napi_err(format!("failed to close tunnel, {e:?}")))
482
+ .map_err(|e| napi_err(format!("failed to close session, {e:?}")))
483
483
  }
484
484
  }
485
485
 
package/src/tunnel.rs CHANGED
@@ -1,5 +1,7 @@
1
+ use core::result::Result as CoreResult;
1
2
  use std::{
2
3
  collections::HashMap,
4
+ error::Error,
3
5
  io,
4
6
  sync::Arc,
5
7
  };
@@ -10,6 +12,7 @@ use napi::bindgen_prelude::*;
10
12
  use napi_derive::napi;
11
13
  use ngrok::{
12
14
  prelude::*,
15
+ session::ConnectError,
13
16
  tunnel::{
14
17
  HttpTunnel,
15
18
  LabeledTunnel,
@@ -46,8 +49,8 @@ struct Storage {
46
49
  /// a proxy trait without generics which can be the dyn type stored in the global map.
47
50
  #[async_trait]
48
51
  pub trait ExtendedTunnel: Tunnel {
49
- async fn fwd_tcp(&mut self, addr: String) -> core::result::Result<(), io::Error>;
50
- async fn fwd_pipe(&mut self, addr: String) -> core::result::Result<(), io::Error>;
52
+ async fn fwd_tcp(&mut self, addr: String) -> CoreResult<(), io::Error>;
53
+ async fn fwd_pipe(&mut self, addr: String) -> CoreResult<(), io::Error>;
51
54
  }
52
55
 
53
56
  /// An ngrok tunnel.
@@ -147,10 +150,10 @@ macro_rules! make_tunnel_type {
147
150
  ($wrapper:ident, $tunnel:tt) => {
148
151
  #[async_trait]
149
152
  impl ExtendedTunnel for $tunnel {
150
- async fn fwd_tcp(&mut self, addr: String) -> core::result::Result<(), io::Error> {
153
+ async fn fwd_tcp(&mut self, addr: String) -> CoreResult<(), io::Error> {
151
154
  self.forward_tcp(addr).await
152
155
  }
153
- async fn fwd_pipe(&mut self, addr: String) -> core::result::Result<(), io::Error> {
156
+ async fn fwd_pipe(&mut self, addr: String) -> CoreResult<(), io::Error> {
154
157
  self.forward_pipe(addr).await
155
158
  }
156
159
  }
@@ -278,10 +281,10 @@ pub async fn forward_tcp(id: &String, addr: String) -> Result<()> {
278
281
  .lock()
279
282
  .await
280
283
  .fwd_tcp(addr)
281
- .await
282
- .map_err(|e| napi_err(format!("cannot forward tcp: {e:?}")));
284
+ .await;
285
+
283
286
  debug!("forward_tcp returning");
284
- res
287
+ canceled_is_ok(res)
285
288
  }
286
289
 
287
290
  pub async fn forward_pipe(id: &String, addr: String) -> Result<()> {
@@ -292,10 +295,29 @@ pub async fn forward_pipe(id: &String, addr: String) -> Result<()> {
292
295
  .lock()
293
296
  .await
294
297
  .fwd_pipe(addr)
295
- .await
296
- .map_err(|e| napi_err(format!("cannot forward pipe: {e:?}")));
298
+ .await;
299
+
297
300
  debug!("forward_pipe returning");
298
- res
301
+ canceled_is_ok(res)
302
+ }
303
+
304
+ fn canceled_is_ok(input: CoreResult<(), io::Error>) -> Result<()> {
305
+ match input {
306
+ Ok(_) => Ok(()),
307
+ Err(e) => {
308
+ if let Some(source) = e
309
+ .source()
310
+ .and_then(|s| s.downcast_ref::<Arc<ConnectError>>())
311
+ {
312
+ if let ConnectError::Canceled = **source {
313
+ debug!("Reconnect was canceled, session is closing, returning Ok");
314
+ return Ok(());
315
+ }
316
+ }
317
+
318
+ Err(napi_err(format!("error forwarding: {e:?}")))
319
+ }
320
+ }
299
321
  }
300
322
 
301
323
  /// Get url using the tunnel id
package/tsconfig.json CHANGED
@@ -1,6 +1,8 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "target": "es5",
4
- "module": "commonjs"
3
+ "module": "commonjs",
4
+ "noImplicitAny": true,
5
+ "strict": true,
6
+ "target": "es5"
5
7
  }
6
8
  }