@ngrok/ngrok 0.7.0 → 0.8.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.
Files changed (75) hide show
  1. package/CHANGELOG.md +19 -10
  2. package/Cargo.toml +2 -2
  3. package/README.md +37 -21
  4. package/docs/assets/highlight.css +10 -10
  5. package/docs/assets/search.js +1 -1
  6. package/docs/classes/HttpListenerBuilder.html +594 -0
  7. package/docs/classes/LabeledListenerBuilder.html +206 -0
  8. package/docs/classes/Listener.html +241 -0
  9. package/docs/classes/Session.html +207 -0
  10. package/docs/classes/SessionBuilder.html +465 -0
  11. package/docs/classes/TcpListenerBuilder.html +281 -0
  12. package/docs/classes/TlsListenerBuilder.html +322 -0
  13. package/docs/classes/UpdateRequest.html +46 -43
  14. package/docs/functions/authtoken.html +30 -29
  15. package/docs/functions/connect.html +31 -30
  16. package/docs/functions/consoleLog.html +30 -29
  17. package/docs/functions/disconnect.html +31 -30
  18. package/docs/functions/getListener.html +89 -0
  19. package/docs/functions/getListenerByUrl.html +89 -0
  20. package/docs/functions/kill.html +31 -30
  21. package/docs/functions/listen.html +33 -32
  22. package/docs/functions/listenable.html +31 -30
  23. package/docs/functions/listeners.html +84 -0
  24. package/docs/functions/loggingCallback.html +30 -29
  25. package/docs/index.html +66 -58
  26. package/docs/interfaces/Config.html +445 -319
  27. package/docs/modules.html +48 -48
  28. package/examples/express/ngrok-express-quickstart.js +1 -1
  29. package/examples/express/ngrok-express.js +6 -6
  30. package/examples/fastify/ngrok-fastify.js +4 -4
  31. package/examples/hapi/ngrok-hapi.js +4 -4
  32. package/examples/koa/ngrok-koa.js +1 -1
  33. package/examples/nestjs/src/main.ts +5 -5
  34. package/examples/nextjs/README.md +3 -0
  35. package/examples/nextjs/ngrok.config.js +7 -7
  36. package/examples/ngrok-connect-full.js +7 -3
  37. package/examples/ngrok-http-full.js +9 -6
  38. package/examples/ngrok-http-minimum.js +6 -6
  39. package/examples/ngrok-labeled.js +7 -7
  40. package/examples/ngrok-listen.js +1 -1
  41. package/examples/ngrok-tcp.js +5 -5
  42. package/examples/ngrok-tls.js +5 -5
  43. package/examples/ngrok-typescript.ts +12 -12
  44. package/examples/ngrok-windows-pipe.js +4 -4
  45. package/examples/ngrok-winston.js +2 -2
  46. package/examples/remix/ngrok.config.js +4 -4
  47. package/examples/svelte/ngrok.config.cjs +4 -4
  48. package/examples/vue/ngrok.config.ts +4 -4
  49. package/index.d.ts +511 -266
  50. package/index.js +81 -75
  51. package/package.json +14 -14
  52. package/scripts/gc-node-drop.js +7 -7
  53. package/scripts/gc-rust-drop.js +9 -9
  54. package/src/config.rs +114 -11
  55. package/src/connect.rs +32 -28
  56. package/src/http.rs +89 -23
  57. package/src/lib.rs +2 -2
  58. package/src/{tunnel.rs → listener.rs} +134 -134
  59. package/src/{tunnel_builder.rs → listener_builder.rs} +63 -54
  60. package/src/session.rs +57 -49
  61. package/src/tcp.rs +6 -3
  62. package/src/tls.rs +17 -7
  63. package/trailer.d.ts +5 -5
  64. package/trailer.js +69 -63
  65. package/typedoc.json +1 -1
  66. package/docs/classes/NgrokHttpTunnelBuilder.html +0 -510
  67. package/docs/classes/NgrokLabeledTunnelBuilder.html +0 -199
  68. package/docs/classes/NgrokSession.html +0 -199
  69. package/docs/classes/NgrokSessionBuilder.html +0 -449
  70. package/docs/classes/NgrokTcpTunnelBuilder.html +0 -268
  71. package/docs/classes/NgrokTlsTunnelBuilder.html +0 -304
  72. package/docs/classes/NgrokTunnel.html +0 -231
  73. package/docs/functions/getTunnel.html +0 -88
  74. package/docs/functions/getTunnelByUrl.html +0 -88
  75. package/docs/functions/tunnels.html +0 -83
@@ -44,21 +44,21 @@ pub(crate) const UNIX_PREFIX: &str = "unix:";
44
44
  pub(crate) const TCP_PREFIX: &str = "tcp://";
45
45
 
46
46
  lazy_static! {
47
- // tunnel references to be kept until explicit close to prevent nodejs gc from dropping them.
48
- // the tunnel wrapper object, and the underlying tunnel, both have references to the Session
47
+ // listener references to be kept until explicit close to prevent nodejs gc from dropping them.
48
+ // the listener wrapper object, and the underlying listener, both have references to the Session
49
49
  // so the Session is safe from premature dropping.
50
- static ref GLOBAL_TUNNELS: Mutex<HashMap<String,Arc<Storage>>> = Mutex::new(HashMap::new());
50
+ static ref GLOBAL_LISTENERS: Mutex<HashMap<String,Arc<Storage>>> = Mutex::new(HashMap::new());
51
51
  }
52
52
 
53
- /// Stores the tunnel and session references to be kept until explicit close.
53
+ /// Stores the listener and session references to be kept until explicit close.
54
54
  struct Storage {
55
- tunnel: Option<Arc<Mutex<dyn ExtendedTunnel>>>,
55
+ listener: Option<Arc<Mutex<dyn ExtendedListener>>>,
56
56
  forwarder: Option<Arc<Mutex<dyn ExtendedForwarder>>>,
57
57
  session: Session,
58
- tun_meta: Arc<TunnelMetadata>,
58
+ tun_meta: Arc<ListenerMetadata>,
59
59
  }
60
60
 
61
- struct TunnelMetadata {
61
+ struct ListenerMetadata {
62
62
  id: String,
63
63
  forwards_to: String,
64
64
  metadata: String,
@@ -67,10 +67,10 @@ struct TunnelMetadata {
67
67
  labels: HashMap<String, String>,
68
68
  }
69
69
 
70
- /// The TunnelExt cannot be turned into an object since it contains generics, so implementing
70
+ /// The upstream cannot be turned into an object since it contains generics, so implementing
71
71
  /// a proxy trait without generics which can be the dyn type stored in the global map.
72
72
  #[async_trait]
73
- pub trait ExtendedTunnel: Send {
73
+ pub trait ExtendedListener: Send {
74
74
  async fn fwd(&mut self, url: Url) -> CoreResult<(), io::Error>;
75
75
  }
76
76
 
@@ -78,19 +78,19 @@ pub trait ExtendedForwarder: Send {
78
78
  fn get_join(&mut self) -> &mut JoinHandle<CoreResult<(), io::Error>>;
79
79
  }
80
80
 
81
- /// An ngrok tunnel.
81
+ /// An ngrok listener.
82
82
  ///
83
- /// @group Tunnel and Sessions
83
+ /// @group Listener and Sessions
84
84
  #[napi(custom_finalize)]
85
85
  #[allow(dead_code)]
86
- pub struct NgrokTunnel {
86
+ pub struct Listener {
87
87
  session: Session,
88
- tun_meta: Arc<TunnelMetadata>,
88
+ tun_meta: Arc<ListenerMetadata>,
89
89
  }
90
90
 
91
- macro_rules! make_tunnel_type {
91
+ macro_rules! make_listener_type {
92
92
  // the common (non-labeled) branch
93
- ($(#[$outer:meta])* $wrapper:ident, $tunnel:tt, common) => {
93
+ ($(#[$outer:meta])* $wrapper:ident, $listener:tt, common) => {
94
94
  $(#[$outer])*
95
95
  #[allow(dead_code)]
96
96
  pub(crate) struct $wrapper {
@@ -99,32 +99,32 @@ macro_rules! make_tunnel_type {
99
99
  #[napi]
100
100
  #[allow(dead_code)]
101
101
  impl $wrapper {
102
- pub(crate) async fn new_tunnel(session: Session, raw_tunnel: $tunnel) -> NgrokTunnel {
103
- let id = raw_tunnel.id().to_string();
104
- let tun_meta = Arc::new(TunnelMetadata {
102
+ pub(crate) async fn new_listener(session: Session, raw_listener: $listener) -> Listener {
103
+ let id = raw_listener.id().to_string();
104
+ let tun_meta = Arc::new(ListenerMetadata {
105
105
  id: id.clone(),
106
- forwards_to: raw_tunnel.forwards_to().to_string(),
107
- metadata: raw_tunnel.metadata().to_string(),
108
- url: Some(raw_tunnel.url().to_string()),
109
- proto: Some(raw_tunnel.proto().to_string()),
106
+ forwards_to: raw_listener.forwards_to().to_string(),
107
+ metadata: raw_listener.metadata().to_string(),
108
+ url: Some(raw_listener.url().to_string()),
109
+ proto: Some(raw_listener.proto().to_string()),
110
110
  labels: HashMap::new(),
111
111
  });
112
- info!("Created tunnel {id:?} with url {:?}", raw_tunnel.url());
113
- // keep a tunnel reference until an explicit call to close to prevent nodejs gc dropping it
112
+ info!("Created listener {id:?} with url {:?}", raw_listener.url());
113
+ // keep a listener reference until an explicit call to close to prevent nodejs gc dropping it
114
114
  let storage = Arc::new(Storage {
115
- tunnel: Some(Arc::new(Mutex::new(raw_tunnel))),
115
+ listener: Some(Arc::new(Mutex::new(raw_listener))),
116
116
  forwarder: None,
117
117
  session,
118
118
  tun_meta,
119
119
  });
120
- GLOBAL_TUNNELS.lock().await.insert(id, storage.clone());
120
+ GLOBAL_LISTENERS.lock().await.insert(id, storage.clone());
121
121
  // create the user-facing object
122
- NgrokTunnel::from_storage(&storage)
122
+ Listener::from_storage(&storage)
123
123
  }
124
124
 
125
- pub(crate) async fn new_forwarder(session: Session, forwarder: Forwarder<$tunnel>) -> NgrokTunnel {
125
+ pub(crate) async fn new_forwarder(session: Session, forwarder: Forwarder<$listener>) -> Listener {
126
126
  let id = forwarder.id().to_string();
127
- let tun_meta = Arc::new(TunnelMetadata {
127
+ let tun_meta = Arc::new(ListenerMetadata {
128
128
  id: id.clone(),
129
129
  forwards_to: forwarder.forwards_to().to_string(),
130
130
  metadata: forwarder.metadata().to_string(),
@@ -132,25 +132,25 @@ macro_rules! make_tunnel_type {
132
132
  proto: Some(forwarder.proto().to_string()),
133
133
  labels: HashMap::new(),
134
134
  });
135
- info!("Created tunnel {id:?} with url {:?}", forwarder.url());
136
- // keep a tunnel reference until an explicit call to close to prevent python gc dropping it
135
+ info!("Created listener {id:?} with url {:?}", forwarder.url());
136
+ // keep a listener reference until an explicit call to close to prevent python gc dropping it
137
137
  let storage = Arc::new(Storage {
138
- tunnel: None,
138
+ listener: None,
139
139
  forwarder: Some(Arc::new(Mutex::new(forwarder))),
140
140
  session,
141
141
  tun_meta,
142
142
  });
143
- GLOBAL_TUNNELS.lock().await.insert(id, storage.clone());
143
+ GLOBAL_LISTENERS.lock().await.insert(id, storage.clone());
144
144
  // create the user-facing object
145
- NgrokTunnel::from_storage(&storage)
145
+ Listener::from_storage(&storage)
146
146
  }
147
147
  }
148
148
 
149
- make_tunnel_type!($wrapper, $tunnel);
149
+ make_listener_type!($wrapper, $listener);
150
150
  };
151
151
 
152
152
  // the labeled branch
153
- ($(#[$outer:meta])* $wrapper:ident, $tunnel:tt, label) => {
153
+ ($(#[$outer:meta])* $wrapper:ident, $listener:tt, label) => {
154
154
  #[allow(dead_code)]
155
155
  pub(crate) struct $wrapper {
156
156
  }
@@ -158,32 +158,32 @@ macro_rules! make_tunnel_type {
158
158
  #[napi]
159
159
  #[allow(dead_code)]
160
160
  impl $wrapper {
161
- pub(crate) async fn new_tunnel(session: Session, raw_tunnel: $tunnel) -> NgrokTunnel {
162
- let id = raw_tunnel.id().to_string();
163
- let tun_meta = Arc::new(TunnelMetadata {
161
+ pub(crate) async fn new_listener(session: Session, raw_listener: $listener) -> Listener {
162
+ let id = raw_listener.id().to_string();
163
+ let tun_meta = Arc::new(ListenerMetadata {
164
164
  id: id.clone(),
165
- forwards_to: raw_tunnel.forwards_to().to_string(),
166
- metadata: raw_tunnel.metadata().to_string(),
165
+ forwards_to: raw_listener.forwards_to().to_string(),
166
+ metadata: raw_listener.metadata().to_string(),
167
167
  url: None,
168
168
  proto: None,
169
- labels: raw_tunnel.labels().clone(),
169
+ labels: raw_listener.labels().clone(),
170
170
  });
171
- info!("Created tunnel {id:?} with labels {:?}", tun_meta.labels);
172
- // keep a tunnel reference until an explicit call to close to prevent nodejs gc dropping it
171
+ info!("Created listener {id:?} with labels {:?}", tun_meta.labels);
172
+ // keep a listener reference until an explicit call to close to prevent nodejs gc dropping it
173
173
  let storage = Arc::new(Storage {
174
- tunnel: Some(Arc::new(Mutex::new(raw_tunnel))),
174
+ listener: Some(Arc::new(Mutex::new(raw_listener))),
175
175
  forwarder: None,
176
176
  session,
177
177
  tun_meta,
178
178
  });
179
- GLOBAL_TUNNELS.lock().await.insert(id, storage.clone());
179
+ GLOBAL_LISTENERS.lock().await.insert(id, storage.clone());
180
180
  // create the user-facing object
181
- NgrokTunnel::from_storage(&storage)
181
+ Listener::from_storage(&storage)
182
182
  }
183
183
 
184
- pub(crate) async fn new_forwarder(session: Session, forwarder: Forwarder<$tunnel>) -> NgrokTunnel {
184
+ pub(crate) async fn new_forwarder(session: Session, forwarder: Forwarder<$listener>) -> Listener {
185
185
  let id = forwarder.id().to_string();
186
- let tun_meta = Arc::new(TunnelMetadata {
186
+ let tun_meta = Arc::new(ListenerMetadata {
187
187
  id: id.clone(),
188
188
  forwards_to: forwarder.forwards_to().to_string(),
189
189
  metadata: forwarder.metadata().to_string(),
@@ -191,34 +191,34 @@ macro_rules! make_tunnel_type {
191
191
  proto: None,
192
192
  labels: forwarder.labels().clone(),
193
193
  });
194
- info!("Created tunnel {id:?} with labels {:?}", tun_meta.labels);
195
- // keep a tunnel reference until an explicit call to close to prevent python gc dropping it
194
+ info!("Created listener {id:?} with labels {:?}", tun_meta.labels);
195
+ // keep a listener reference until an explicit call to close to prevent python gc dropping it
196
196
  let storage = Arc::new(Storage {
197
- tunnel: None,
197
+ listener: None,
198
198
  forwarder: Some(Arc::new(Mutex::new(forwarder))),
199
199
  session,
200
200
  tun_meta,
201
201
  });
202
- GLOBAL_TUNNELS.lock().await.insert(id, storage.clone());
202
+ GLOBAL_LISTENERS.lock().await.insert(id, storage.clone());
203
203
  // create the user-facing object
204
- NgrokTunnel::from_storage(&storage)
204
+ Listener::from_storage(&storage)
205
205
  }
206
206
  }
207
207
 
208
- make_tunnel_type!($wrapper, $tunnel);
208
+ make_listener_type!($wrapper, $listener);
209
209
  };
210
210
 
211
- // all tunnels get these
212
- ($wrapper:ident, $tunnel:tt) => {
211
+ // all listeners get these
212
+ ($wrapper:ident, $listener:tt) => {
213
213
  #[async_trait]
214
- impl ExtendedTunnel for $tunnel {
214
+ impl ExtendedListener for $listener {
215
215
  #[allow(deprecated)]
216
216
  async fn fwd(&mut self, url: Url) -> CoreResult<(), io::Error> {
217
217
  ngrok::prelude::TunnelExt::forward(self, url).await
218
218
  }
219
219
  }
220
220
 
221
- impl ExtendedForwarder for Forwarder<$tunnel> {
221
+ impl ExtendedForwarder for Forwarder<$listener> {
222
222
  fn get_join(&mut self) -> &mut JoinHandle<CoreResult<(), io::Error>> {
223
223
  self.join()
224
224
  }
@@ -228,56 +228,56 @@ macro_rules! make_tunnel_type {
228
228
 
229
229
  #[napi]
230
230
  #[allow(dead_code)]
231
- impl NgrokTunnel {
232
- /// Create NgrokTunnel from Storage
233
- fn from_storage(storage: &Arc<Storage>) -> NgrokTunnel {
231
+ impl Listener {
232
+ /// Create Listener from Storage
233
+ fn from_storage(storage: &Arc<Storage>) -> Listener {
234
234
  // create the user-facing object
235
- NgrokTunnel {
235
+ Listener {
236
236
  session: storage.session.clone(),
237
237
  tun_meta: storage.tun_meta.clone(),
238
238
  }
239
239
  }
240
240
 
241
- /// The URL that this tunnel backs.
241
+ /// The URL that this listener backs.
242
242
  #[napi]
243
243
  pub fn url(&self) -> Option<String> {
244
244
  self.tun_meta.url.clone()
245
245
  }
246
246
 
247
- /// The protocol of the endpoint that this tunnel backs.
247
+ /// The protocol of the endpoint that this listener backs.
248
248
  #[napi]
249
249
  pub fn proto(&self) -> Option<String> {
250
250
  self.tun_meta.proto.clone()
251
251
  }
252
252
 
253
- /// The labels this tunnel was started with.
253
+ /// The labels this listener was started with.
254
254
  #[napi]
255
255
  pub fn labels(&self) -> HashMap<String, String> {
256
256
  self.tun_meta.labels.clone()
257
257
  }
258
258
 
259
- /// Returns a tunnel's unique ID.
259
+ /// Returns a listener's unique ID.
260
260
  #[napi]
261
261
  pub fn id(&self) -> String {
262
262
  self.tun_meta.id.clone()
263
263
  }
264
264
 
265
265
  /// Returns a human-readable string presented in the ngrok dashboard
266
- /// and the Tunnels API. Use the [HttpTunnelBuilder::forwards_to],
267
- /// [TcpTunnelBuilder::forwards_to], etc. to set this value
266
+ /// and the API. Use the [HttpListenerBuilder::forwards_to],
267
+ /// [TcpListenerBuilder::forwards_to], etc. to set this value
268
268
  /// explicitly.
269
269
  #[napi]
270
270
  pub fn forwards_to(&self) -> String {
271
271
  self.tun_meta.forwards_to.clone()
272
272
  }
273
273
 
274
- /// Returns the arbitrary metadata string for this tunnel.
274
+ /// Returns the arbitrary metadata string for this listener.
275
275
  #[napi]
276
276
  pub fn metadata(&self) -> String {
277
277
  self.tun_meta.metadata.clone()
278
278
  }
279
279
 
280
- /// Forward incoming tunnel connections. This can be either a TCP address or a file socket path.
280
+ /// Forward incoming listener connections. This can be either a TCP address or a file socket path.
281
281
  /// For file socket paths on Linux/Darwin, addr can be a unix domain socket path, e.g. "/tmp/ngrok.sock"
282
282
  /// On Windows, addr can be a named pipe, e.e. "\\\\.\\pipe\\an_ngrok_pipe
283
283
  #[napi]
@@ -300,69 +300,69 @@ impl NgrokTunnel {
300
300
  .map_err(|e| napi_err(format!("error on join: {e:?}")))?
301
301
  .map_err(|e| napi_err(format!("error on join: {e:?}")))
302
302
  } else {
303
- Err(napi_err("Tunnel is not joinable"))
303
+ Err(napi_err("Listener is not joinable"))
304
304
  }
305
305
  }
306
306
 
307
- /// Close the tunnel.
307
+ /// Close the listener.
308
308
  ///
309
309
  /// This is an RPC call that must be `.await`ed.
310
- /// It is equivalent to calling `Session::close_tunnel` with this
311
- /// tunnel's ID.
310
+ /// It is equivalent to calling `Session::close_listener` with this
311
+ /// listener's ID.
312
312
  #[napi]
313
313
  pub async fn close(&self) -> Result<()> {
314
- debug!("NgrokTunnel closing, id: {}", self.tun_meta.id);
314
+ debug!("Listener closing, id: {}", self.tun_meta.id);
315
315
 
316
- // we may not be able to lock our reference to the tunnel due to the forward_* calls which
317
- // continuously accept-loop while the tunnel is active, so calling close on the Session.
316
+ // we may not be able to lock our reference to the listener due to the forward_* calls which
317
+ // continuously accept-loop while the listener is active, so calling close on the Session.
318
318
  let res = self
319
319
  .session
320
320
  .close_tunnel(self.tun_meta.id.clone())
321
321
  .await
322
- .map_err(|e| napi_ngrok_err("error closing tunnel", &e));
322
+ .map_err(|e| napi_ngrok_err("error closing listener", &e));
323
323
 
324
- // drop our internal reference to the tunnel after awaiting close
325
- GLOBAL_TUNNELS.lock().await.remove(&self.tun_meta.id);
324
+ // drop our internal reference to the listener after awaiting close
325
+ GLOBAL_LISTENERS.lock().await.remove(&self.tun_meta.id);
326
326
 
327
327
  res
328
328
  }
329
329
  }
330
330
 
331
331
  #[allow(unused_mut)]
332
- impl ObjectFinalize for NgrokTunnel {
332
+ impl ObjectFinalize for Listener {
333
333
  fn finalize(mut self, _env: Env) -> Result<()> {
334
- debug!("NgrokTunnel finalize, id: {}", self.tun_meta.id);
334
+ debug!("Listener finalize, id: {}", self.tun_meta.id);
335
335
  Ok(())
336
336
  }
337
337
  }
338
338
 
339
- make_tunnel_type! {
340
- /// An ngrok tunnel backing an HTTP endpoint.
339
+ make_listener_type! {
340
+ /// An ngrok listener backing an HTTP endpoint.
341
341
  ///
342
- /// @group Tunnels
343
- NgrokHttpTunnel, HttpTunnel, common
342
+ /// @group Listeners
343
+ HttpListener, HttpTunnel, common
344
344
  }
345
- make_tunnel_type! {
346
- /// An ngrok tunnel backing a TCP endpoint.
345
+ make_listener_type! {
346
+ /// An ngrok listener backing a TCP endpoint.
347
347
  ///
348
- /// @group Tunnels
349
- NgrokTcpTunnel, TcpTunnel, common
348
+ /// @group Listeners
349
+ TcpListener, TcpTunnel, common
350
350
  }
351
- make_tunnel_type! {
352
- /// An ngrok tunnel bcking a TLS endpoint.
351
+ make_listener_type! {
352
+ /// An ngrok listener bcking a TLS endpoint.
353
353
  ///
354
- /// @group Tunnels
355
- NgrokTlsTunnel, TlsTunnel, common
354
+ /// @group Listeners
355
+ TlsListener, TlsTunnel, common
356
356
  }
357
- make_tunnel_type! {
358
- /// A labeled ngrok tunnel.
357
+ make_listener_type! {
358
+ /// A labeled ngrok listener.
359
359
  ///
360
- /// @group Tunnels
361
- NgrokLabeledTunnel, LabeledTunnel, label
360
+ /// @group Listeners
361
+ LabeledListener, LabeledTunnel, label
362
362
  }
363
363
 
364
364
  pub async fn forward(id: &String, mut addr: String) -> Result<()> {
365
- let tun_option = &get_storage_by_id(id).await?.tunnel;
365
+ let tun_option = &get_storage_by_id(id).await?.listener;
366
366
  if let Some(tun) = tun_option {
367
367
  // if addr is not a full url, choose a default protocol
368
368
  lazy_static! {
@@ -379,13 +379,13 @@ pub async fn forward(id: &String, mut addr: String) -> Result<()> {
379
379
  let url = Url::parse(addr.as_str())
380
380
  .map_err(|e| napi_err(format!("Cannot parse address: {addr}, error: {e}")))?;
381
381
 
382
- info!("Tunnel {id:?} forwarding to {:?}", url.to_string());
382
+ info!("Listener {id:?} forwarding to {:?}", url.to_string());
383
383
  let res = tun.lock().await.fwd(url).await;
384
384
 
385
385
  debug!("forward returning");
386
386
  canceled_is_ok(res)
387
387
  } else {
388
- Err(napi_err("tunnel is not forwardable"))
388
+ Err(napi_err("listener is not forwardable"))
389
389
  }
390
390
  }
391
391
 
@@ -410,52 +410,52 @@ fn canceled_is_ok(input: CoreResult<(), io::Error>) -> Result<()> {
410
410
 
411
411
  async fn get_storage_by_id(id: &String) -> Result<Arc<Storage>> {
412
412
  // we must clone the Arc before any locking so there is a local reference
413
- // to the mutex to unlock if the tunnel wrapper struct is dropped.
414
- Ok(GLOBAL_TUNNELS
413
+ // to the mutex to unlock if the listener wrapper struct is dropped.
414
+ Ok(GLOBAL_LISTENERS
415
415
  .lock()
416
416
  .await
417
417
  .get(id)
418
- .ok_or(napi_err("Tunnel is no longer running"))?
418
+ .ok_or(napi_err("Listener is no longer running"))?
419
419
  .clone()) // required clone
420
420
  }
421
421
 
422
- /// Delete any reference to the tunnel id
423
- pub(crate) async fn remove_global_tunnel(id: &String) {
424
- GLOBAL_TUNNELS.lock().await.remove(id);
422
+ /// Delete any reference to the listener id
423
+ pub(crate) async fn remove_global_listener(id: &String) {
424
+ GLOBAL_LISTENERS.lock().await.remove(id);
425
425
  }
426
426
 
427
- /// Close a tunnel with the given url, or all tunnels if no url is defined.
427
+ /// Close a listener with the given url, or all listeners if no url is defined.
428
428
  pub(crate) async fn close_url(url: Option<String>) -> Result<()> {
429
429
  let mut close_ids: Vec<String> = vec![];
430
- let tunnels = GLOBAL_TUNNELS.lock().await;
431
- for (id, storage) in tunnels.iter() {
432
- debug!("tunnel: {}", id);
430
+ let listeners = GLOBAL_LISTENERS.lock().await;
431
+ for (id, storage) in listeners.iter() {
432
+ debug!("listener: {}", id);
433
433
  if url.as_ref().is_none() || url == storage.tun_meta.url {
434
- debug!("closing tunnel: {}", id);
434
+ debug!("closing listener: {}", id);
435
435
  storage
436
436
  .session
437
437
  .close_tunnel(id)
438
438
  .await
439
- .map_err(|e| napi_ngrok_err("error closing tunnel", &e))?;
439
+ .map_err(|e| napi_ngrok_err("error closing listener", &e))?;
440
440
  close_ids.push(id.clone());
441
441
  }
442
442
  }
443
- drop(tunnels); // unlock GLOBAL_TUNNELS
443
+ drop(listeners); // unlock GLOBAL_LISTENERS
444
444
 
445
445
  // remove references entirely
446
446
  for id in close_ids {
447
- remove_global_tunnel(&id).await;
447
+ remove_global_listener(&id).await;
448
448
  }
449
449
  Ok(())
450
450
  }
451
451
 
452
- /// Make a list of all tunnels by iterating over the global tunnel map and creating an NgrokTunnel from each.
453
- pub(crate) async fn search_tunnels(
452
+ /// Make a list of all listeners by iterating over the global listener map and creating an Listener from each.
453
+ pub(crate) async fn search_listeners(
454
454
  session_id: Option<String>,
455
455
  url: Option<String>,
456
- ) -> Vec<NgrokTunnel> {
457
- let mut tunnels: Vec<NgrokTunnel> = vec![];
458
- for (_, storage) in GLOBAL_TUNNELS.lock().await.iter() {
456
+ ) -> Vec<Listener> {
457
+ let mut listeners: Vec<Listener> = vec![];
458
+ for (_, storage) in GLOBAL_LISTENERS.lock().await.iter() {
459
459
  // filter by session_id, if provided
460
460
  if let Some(session_id) = session_id.as_ref() {
461
461
  if session_id.ne(&storage.session.id()) {
@@ -466,30 +466,30 @@ pub(crate) async fn search_tunnels(
466
466
  if url.is_some() && url.ne(&storage.tun_meta.url) {
467
467
  continue;
468
468
  }
469
- // create a new NgrokTunnel from the storage
470
- tunnels.push(NgrokTunnel::from_storage(storage));
469
+ // create a new Listener from the storage
470
+ listeners.push(Listener::from_storage(storage));
471
471
  }
472
- tunnels
472
+ listeners
473
473
  }
474
474
 
475
- /// Retrieve a list of non-closed tunnels, in no particular order.
475
+ /// Retrieve a list of non-closed listeners, in no particular order.
476
476
  #[napi]
477
- pub async fn tunnels() -> Vec<NgrokTunnel> {
478
- search_tunnels(None, None).await
477
+ pub async fn listeners() -> Vec<Listener> {
478
+ search_listeners(None, None).await
479
479
  }
480
480
 
481
- /// Retrieve tunnel using the id
481
+ /// Retrieve listener using the id
482
482
  #[napi]
483
- pub async fn get_tunnel(id: String) -> Option<NgrokTunnel> {
484
- GLOBAL_TUNNELS
483
+ pub async fn get_listener(id: String) -> Option<Listener> {
484
+ GLOBAL_LISTENERS
485
485
  .lock()
486
486
  .await
487
487
  .get(&id)
488
- .map(NgrokTunnel::from_storage)
488
+ .map(Listener::from_storage)
489
489
  }
490
490
 
491
- /// Retrieve tunnel using the url
491
+ /// Retrieve listener using the url
492
492
  #[napi]
493
- pub async fn get_tunnel_by_url(url: String) -> Option<NgrokTunnel> {
494
- search_tunnels(None, Some(url)).await.into_iter().next()
493
+ pub async fn get_listener_by_url(url: String) -> Option<Listener> {
494
+ search_listeners(None, Some(url)).await.into_iter().next()
495
495
  }