@ngrok/ngrok 0.8.0 → 0.9.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.
@@ -20,7 +20,7 @@ const ngrok = require("@ngrok/ngrok");
20
20
  ngrok.consoleLog("INFO"); // turn on info logging
21
21
 
22
22
  (async function () {
23
- const url = await ngrok.connect({
23
+ const listener = await ngrok.connect({
24
24
  // session configuration
25
25
  addr: `unix:${UNIX_SOCKET}`,
26
26
  // addr: `localhost:8080`,
@@ -63,5 +63,5 @@ ngrok.consoleLog("INFO"); // turn on info logging
63
63
  // verify_webhook_secret: "asdf",
64
64
  // websocket_tcp_converter: true,
65
65
  });
66
- console.log(`Ingress established at: ${url}`);
66
+ console.log(`Ingress established at: ${listener.url()}`);
67
67
  })();
@@ -12,6 +12,6 @@ console.log(`Node.js web server at 8080 is running..`);
12
12
  // setup ngrok
13
13
  const ngrok = require("@ngrok/ngrok");
14
14
  (async function () {
15
- const url = await ngrok.connect({ addr: 8080, authtoken_from_env: true });
16
- console.log(`Ingress established at: ${url}`);
15
+ const listener = await ngrok.connect({ addr: 8080, authtoken_from_env: true });
16
+ console.log(`Ingress established at: ${listener.url()}`);
17
17
  })();
package/index.d.ts CHANGED
@@ -305,7 +305,7 @@ export interface Config {
305
305
  websocket_tcp_converter?: boolean
306
306
  }
307
307
  /** Transform a json object configuration into a listener */
308
- export function connect(config: Config|string|number): Promise<string>
308
+ export function connect(config: Config|string|number): Promise<Listener>
309
309
  /** Close a listener with the given url, or all listeners if no url is defined. */
310
310
  export function disconnect(url?: string | undefined | null): Promise<void>
311
311
  /** Close all listeners. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ngrok/ngrok",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "main": "index.js",
5
5
  "types": "index.d.ts",
6
6
  "napi": {
@@ -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.8.0",
59
- "@ngrok/ngrok-darwin-x64": "0.8.0",
60
- "@ngrok/ngrok-linux-x64-gnu": "0.8.0",
61
- "@ngrok/ngrok-darwin-arm64": "0.8.0",
62
- "@ngrok/ngrok-android-arm64": "0.8.0",
63
- "@ngrok/ngrok-linux-arm64-gnu": "0.8.0",
64
- "@ngrok/ngrok-linux-arm64-musl": "0.8.0",
65
- "@ngrok/ngrok-linux-arm-gnueabihf": "0.8.0",
66
- "@ngrok/ngrok-linux-x64-musl": "0.8.0",
67
- "@ngrok/ngrok-freebsd-x64": "0.8.0",
68
- "@ngrok/ngrok-win32-ia32-msvc": "0.8.0",
69
- "@ngrok/ngrok-android-arm-eabi": "0.8.0",
70
- "@ngrok/ngrok-darwin-universal": "0.8.0"
58
+ "@ngrok/ngrok-win32-x64-msvc": "0.9.0",
59
+ "@ngrok/ngrok-darwin-x64": "0.9.0",
60
+ "@ngrok/ngrok-linux-x64-gnu": "0.9.0",
61
+ "@ngrok/ngrok-darwin-arm64": "0.9.0",
62
+ "@ngrok/ngrok-android-arm64": "0.9.0",
63
+ "@ngrok/ngrok-linux-arm64-gnu": "0.9.0",
64
+ "@ngrok/ngrok-linux-arm64-musl": "0.9.0",
65
+ "@ngrok/ngrok-linux-arm-gnueabihf": "0.9.0",
66
+ "@ngrok/ngrok-linux-x64-musl": "0.9.0",
67
+ "@ngrok/ngrok-freebsd-x64": "0.9.0",
68
+ "@ngrok/ngrok-win32-ia32-msvc": "0.9.0",
69
+ "@ngrok/ngrok-android-arm-eabi": "0.9.0",
70
+ "@ngrok/ngrok-darwin-universal": "0.9.0"
71
71
  }
72
72
  }
package/src/connect.rs CHANGED
@@ -9,8 +9,11 @@ use tracing::warn;
9
9
 
10
10
  use crate::{
11
11
  config::Config,
12
- listener,
13
- listener::TCP_PREFIX,
12
+ listener::{
13
+ self,
14
+ Listener,
15
+ TCP_PREFIX,
16
+ },
14
17
  logging::logging_callback,
15
18
  napi_err,
16
19
  session::{
@@ -95,7 +98,7 @@ macro_rules! config_common {
95
98
  /// Transform a json object configuration into a listener
96
99
  #[napi(
97
100
  ts_args_type = "config: Config|string|number",
98
- ts_return_type = "Promise<string>"
101
+ ts_return_type = "Promise<Listener>"
99
102
  )]
100
103
  #[allow(dead_code)]
101
104
  pub fn connect(
@@ -129,7 +132,7 @@ pub fn connect(
129
132
  }
130
133
 
131
134
  /// Connect the session, configure and start the listener
132
- async fn async_connect(s_builder: SessionBuilder, config: Config) -> Result<String> {
135
+ async fn async_connect(s_builder: SessionBuilder, config: Config) -> Result<Listener> {
133
136
  // Using a singleton session for connect use cases
134
137
  let mut opt = SESSION.lock().await;
135
138
  if opt.is_none() {
@@ -147,17 +150,16 @@ async fn async_connect(s_builder: SessionBuilder, config: Config) -> Result<Stri
147
150
  _ => return Err(napi_err(format!("unhandled protocol {proto}"))),
148
151
  };
149
152
 
150
- let url = listener::get_listener(id.clone())
153
+ let listener = listener::get_listener(id.clone())
151
154
  .await
152
- .and_then(|t| t.url())
153
- .unwrap_or(id.clone());
155
+ .ok_or(napi_err("failed to start listener".to_string()))?;
154
156
 
155
157
  // move forwarding to another task
156
158
  if let Some(addr) = config.addr {
157
159
  tokio::spawn(async move { listener::forward(&id, addr).await });
158
160
  }
159
161
 
160
- Ok(url)
162
+ Ok(listener)
161
163
  }
162
164
 
163
165
  /// HTTP Listener configuration