@ngrok/ngrok 0.3.0 → 0.4.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 (36) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/Cargo.toml +1 -1
  3. package/README.md +1 -1
  4. package/docs/assets/main.js +1 -1
  5. package/docs/assets/search.js +1 -1
  6. package/docs/assets/style.css +6 -4
  7. package/docs/classes/NgrokHttpTunnelBuilder.html +40 -43
  8. package/docs/classes/NgrokLabeledTunnelBuilder.html +23 -26
  9. package/docs/classes/NgrokSession.html +24 -27
  10. package/docs/classes/NgrokSessionBuilder.html +32 -35
  11. package/docs/classes/NgrokTcpTunnelBuilder.html +27 -30
  12. package/docs/classes/NgrokTlsTunnelBuilder.html +29 -32
  13. package/docs/classes/{NgrokTcpTunnel.html → NgrokTunnel.html} +54 -47
  14. package/docs/classes/UpdateRequest.html +20 -23
  15. package/docs/functions/authtoken.html +18 -21
  16. package/docs/functions/connect.html +18 -21
  17. package/docs/functions/consoleLog.html +18 -21
  18. package/docs/functions/disconnect.html +18 -21
  19. package/docs/functions/kill.html +18 -21
  20. package/docs/functions/listen.html +23 -25
  21. package/docs/functions/listenable.html +22 -29
  22. package/docs/functions/loggingCallback.html +18 -21
  23. package/docs/index.html +18 -21
  24. package/docs/interfaces/Config.html +70 -73
  25. package/docs/modules.html +32 -38
  26. package/index.d.ts +24 -134
  27. package/index.js +2 -5
  28. package/package.json +16 -15
  29. package/src/session.rs +2 -4
  30. package/src/tunnel.rs +108 -102
  31. package/src/tunnel_builder.rs +3 -2
  32. package/trailer.d.ts +11 -7
  33. package/typedoc.json +3 -0
  34. package/docs/classes/NgrokHttpTunnel.html +0 -226
  35. package/docs/classes/NgrokLabeledTunnel.html +0 -214
  36. package/docs/classes/NgrokTlsTunnel.html +0 -226
package/src/tunnel.rs CHANGED
@@ -50,26 +50,34 @@ pub trait ExtendedTunnel: Tunnel {
50
50
  async fn fwd_pipe(&mut self, addr: String) -> core::result::Result<(), io::Error>;
51
51
  }
52
52
 
53
+ /// An ngrok tunnel.
54
+ ///
55
+ /// @group Tunnel and Sessions
56
+ #[napi(custom_finalize)]
57
+ #[allow(dead_code)]
58
+ pub(crate) struct NgrokTunnel {
59
+ id: String,
60
+ forwards_to: String,
61
+ metadata: String,
62
+ url: Option<String>,
63
+ proto: Option<String>,
64
+ session: Session,
65
+ labels: HashMap<String, String>,
66
+ }
67
+
53
68
  macro_rules! make_tunnel_type {
54
69
  // the common (non-labeled) branch
55
70
  ($(#[$outer:meta])* $wrapper:ident, $tunnel:tt, common) => {
56
71
 
57
72
  $(#[$outer])*
58
- #[napi(custom_finalize)]
59
73
  #[allow(dead_code)]
60
74
  pub(crate) struct $wrapper {
61
- id: String,
62
- forwards_to: String,
63
- metadata: String,
64
- url: String,
65
- proto: String,
66
- session: Session,
67
75
  }
68
76
 
69
77
  #[napi]
70
78
  #[allow(dead_code)]
71
79
  impl $wrapper {
72
- pub(crate) async fn new(session: Session, raw_tunnel: $tunnel) -> Self {
80
+ pub(crate) async fn new_tunnel(session: Session, raw_tunnel: $tunnel) -> NgrokTunnel {
73
81
  let id = raw_tunnel.id().to_string();
74
82
  let forwards_to = raw_tunnel.forwards_to().to_string();
75
83
  let metadata = raw_tunnel.metadata().to_string();
@@ -83,27 +91,16 @@ macro_rules! make_tunnel_type {
83
91
  url: Some(url.clone()),
84
92
  }));
85
93
  // create the user-facing object
86
- $wrapper {
94
+ NgrokTunnel {
87
95
  id,
88
96
  forwards_to,
89
97
  metadata,
90
- url,
91
- proto,
98
+ url: Some(url),
99
+ proto: Some(proto),
92
100
  session,
101
+ labels: HashMap::new(),
93
102
  }
94
103
  }
95
-
96
- /// The URL that this tunnel backs.
97
- #[napi]
98
- pub fn url(&self) -> String {
99
- self.url.clone()
100
- }
101
-
102
- /// The protocol of the endpoint that this tunnel backs.
103
- #[napi]
104
- pub fn proto(&self) -> String {
105
- self.proto.clone()
106
- }
107
104
  }
108
105
 
109
106
  make_tunnel_type!($wrapper, $tunnel);
@@ -111,21 +108,14 @@ macro_rules! make_tunnel_type {
111
108
 
112
109
  // the labeled branch
113
110
  ($(#[$outer:meta])* $wrapper:ident, $tunnel:tt, label) => {
114
- $(#[$outer])*
115
- #[napi(custom_finalize)]
116
111
  #[allow(dead_code)]
117
112
  pub(crate) struct $wrapper {
118
- id: String,
119
- forwards_to: String,
120
- metadata: String,
121
- labels: HashMap<String,String>,
122
- session: Session,
123
113
  }
124
114
 
125
115
  #[napi]
126
116
  #[allow(dead_code)]
127
117
  impl $wrapper {
128
- pub(crate) async fn new(session: Session, raw_tunnel: $tunnel) -> Self {
118
+ pub(crate) async fn new_tunnel(session: Session, raw_tunnel: $tunnel) -> NgrokTunnel {
129
119
  let id = raw_tunnel.id().to_string();
130
120
  let forwards_to = raw_tunnel.forwards_to().to_string();
131
121
  let metadata = raw_tunnel.metadata().to_string();
@@ -138,20 +128,16 @@ macro_rules! make_tunnel_type {
138
128
  url: None,
139
129
  }));
140
130
  // create the user-facing object
141
- $wrapper {
131
+ NgrokTunnel {
142
132
  id,
143
133
  forwards_to,
144
134
  metadata,
145
- labels,
135
+ url: None,
136
+ proto: None,
146
137
  session,
138
+ labels,
147
139
  }
148
140
  }
149
-
150
- /// The labels this tunnel was started with.
151
- #[napi]
152
- pub fn labels(&self) -> HashMap<String, String> {
153
- self.labels.clone()
154
- }
155
141
  }
156
142
 
157
143
  make_tunnel_type!($wrapper, $tunnel);
@@ -168,75 +154,95 @@ macro_rules! make_tunnel_type {
168
154
  self.forward_pipe(addr).await
169
155
  }
170
156
  }
157
+ };
158
+ }
171
159
 
172
- #[napi]
173
- #[allow(dead_code)]
174
- impl $wrapper {
175
- /// Returns a tunnel's unique ID.
176
- #[napi]
177
- pub fn id(&self) -> String {
178
- self.id.clone()
179
- }
160
+ #[napi]
161
+ #[allow(dead_code)]
162
+ impl NgrokTunnel {
163
+ /// The URL that this tunnel backs.
164
+ #[napi]
165
+ pub fn url(&self) -> Option<String> {
166
+ self.url.clone()
167
+ }
180
168
 
181
- /// Returns a human-readable string presented in the ngrok dashboard
182
- /// and the Tunnels API. Use the [HttpTunnelBuilder::forwards_to],
183
- /// [TcpTunnelBuilder::forwards_to], etc. to set this value
184
- /// explicitly.
185
- #[napi]
186
- pub fn forwards_to(&self) -> String {
187
- self.forwards_to.clone()
188
- }
169
+ /// The protocol of the endpoint that this tunnel backs.
170
+ #[napi]
171
+ pub fn proto(&self) -> Option<String> {
172
+ self.proto.clone()
173
+ }
189
174
 
190
- /// Returns the arbitrary metadata string for this tunnel.
191
- #[napi]
192
- pub fn metadata(&self) -> String {
193
- self.metadata.clone()
194
- }
175
+ /// The labels this tunnel was started with.
176
+ #[napi]
177
+ pub fn labels(&self) -> HashMap<String, String> {
178
+ self.labels.clone()
179
+ }
195
180
 
196
- /// Forward incoming tunnel connections to the provided TCP address.
197
- #[napi]
198
- pub async fn forward_tcp(&self, addr: String) -> Result<()> {
199
- forward_tcp(&self.id, addr).await
200
- }
181
+ /// Returns a tunnel's unique ID.
182
+ #[napi]
183
+ pub fn id(&self) -> String {
184
+ self.id.clone()
185
+ }
201
186
 
202
- /// Forward incoming tunnel connections to the provided file socket path.
203
- /// On Linux/Darwin addr can be a unix domain socket path, e.g. "/tmp/ngrok.sock"
204
- /// On Windows addr can be a named pipe, e.e. "\\.\pipe\an_ngrok_pipe"
205
- #[napi]
206
- pub async fn forward_pipe(&self, addr: String) -> Result<()> {
207
- forward_pipe(&self.id, addr).await
208
- }
187
+ /// Returns a human-readable string presented in the ngrok dashboard
188
+ /// and the Tunnels API. Use the [HttpTunnelBuilder::forwards_to],
189
+ /// [TcpTunnelBuilder::forwards_to], etc. to set this value
190
+ /// explicitly.
191
+ #[napi]
192
+ pub fn forwards_to(&self) -> String {
193
+ self.forwards_to.clone()
194
+ }
209
195
 
210
- /// Close the tunnel.
211
- ///
212
- /// This is an RPC call that must be `.await`ed.
213
- /// It is equivalent to calling `Session::close_tunnel` with this
214
- /// tunnel's ID.
215
- #[napi]
216
- pub async fn close(&self) -> Result<()> {
217
- debug!("{} closing, id: {}", stringify!($wrapper), self.id);
218
-
219
- // we may not be able to lock our reference to the tunnel due to the forward_* calls which
220
- // continuously accept-loop while the tunnel is active, so calling close on the Session.
221
- let res = self.session.close_tunnel(self.id.clone())
222
- .await
223
- .map_err(|e| napi_err(format!("error closing tunnel: {e:?}")));
224
-
225
- // drop our internal reference to the tunnel after awaiting close
226
- GLOBAL_TUNNELS.lock().await.remove(&self.id);
227
-
228
- res
229
- }
230
- }
196
+ /// Returns the arbitrary metadata string for this tunnel.
197
+ #[napi]
198
+ pub fn metadata(&self) -> String {
199
+ self.metadata.clone()
200
+ }
231
201
 
232
- #[allow(unused_mut)]
233
- impl ObjectFinalize for $wrapper {
234
- fn finalize(mut self, _env: Env) -> Result<()> {
235
- debug!("{} finalize, id: {}", stringify!($wrapper), self.id);
236
- Ok(())
237
- }
238
- }
239
- };
202
+ /// Forward incoming tunnel connections to the provided TCP address.
203
+ #[napi]
204
+ pub async fn forward_tcp(&self, addr: String) -> Result<()> {
205
+ forward_tcp(&self.id, addr).await
206
+ }
207
+
208
+ /// Forward incoming tunnel connections to the provided file socket path.
209
+ /// On Linux/Darwin addr can be a unix domain socket path, e.g. "/tmp/ngrok.sock"
210
+ /// On Windows addr can be a named pipe, e.e. "\\.\pipe\an_ngrok_pipe"
211
+ #[napi]
212
+ pub async fn forward_pipe(&self, addr: String) -> Result<()> {
213
+ forward_pipe(&self.id, addr).await
214
+ }
215
+
216
+ /// Close the tunnel.
217
+ ///
218
+ /// This is an RPC call that must be `.await`ed.
219
+ /// It is equivalent to calling `Session::close_tunnel` with this
220
+ /// tunnel's ID.
221
+ #[napi]
222
+ pub async fn close(&self) -> Result<()> {
223
+ debug!("{} closing, id: {}", stringify!($wrapper), self.id);
224
+
225
+ // we may not be able to lock our reference to the tunnel due to the forward_* calls which
226
+ // continuously accept-loop while the tunnel is active, so calling close on the Session.
227
+ let res = self
228
+ .session
229
+ .close_tunnel(self.id.clone())
230
+ .await
231
+ .map_err(|e| napi_err(format!("error closing tunnel: {e:?}")));
232
+
233
+ // drop our internal reference to the tunnel after awaiting close
234
+ GLOBAL_TUNNELS.lock().await.remove(&self.id);
235
+
236
+ res
237
+ }
238
+ }
239
+
240
+ #[allow(unused_mut)]
241
+ impl ObjectFinalize for NgrokTunnel {
242
+ fn finalize(mut self, _env: Env) -> Result<()> {
243
+ debug!("{} finalize, id: {}", stringify!($wrapper), self.id);
244
+ Ok(())
245
+ }
240
246
  }
241
247
 
242
248
  make_tunnel_type! {
@@ -292,7 +298,7 @@ pub async fn forward_pipe(id: &String, addr: String) -> Result<()> {
292
298
  res
293
299
  }
294
300
 
295
- /// Delete any reference to the tunnel id
301
+ /// Get url using the tunnel id
296
302
  pub(crate) async fn get_url(id: &String) -> Option<String> {
297
303
  GLOBAL_TUNNELS
298
304
  .lock()
@@ -26,6 +26,7 @@ use crate::{
26
26
  NgrokLabeledTunnel,
27
27
  NgrokTcpTunnel,
28
28
  NgrokTlsTunnel,
29
+ NgrokTunnel,
29
30
  },
30
31
  };
31
32
 
@@ -59,7 +60,7 @@ macro_rules! make_tunnel_builder {
59
60
 
60
61
  /// Begin listening for new connections on this tunnel.
61
62
  #[napi]
62
- pub async fn listen(&self, _bind: Option<bool>) -> Result<$tunnel> {
63
+ pub async fn listen(&self, _bind: Option<bool>) -> Result<NgrokTunnel> {
63
64
  let session = self.session.lock().clone();
64
65
  let tun = self.tunnel_builder.lock().clone();
65
66
  let result = tun
@@ -69,7 +70,7 @@ macro_rules! make_tunnel_builder {
69
70
 
70
71
  // create the wrapping tunnel object via its async new()
71
72
  match result {
72
- Ok(raw_tun) => Ok($tunnel::new(session, raw_tun).await),
73
+ Ok(raw_tun) => Ok($tunnel::new_tunnel(session, raw_tun).await),
73
74
  Err(val) => Err(val),
74
75
  }
75
76
  }
package/trailer.d.ts CHANGED
@@ -1,12 +1,16 @@
1
- /** Generate, or convert a given tunnel, into one that can be passed into net.Server.listen(). */
2
- export function listenable(
3
- tunnel?: NgrokHttpTunnel | NgrokTcpTunnel | NgrokTlsTunnel | NgrokLabeledTunnel
4
- ): NgrokHttpTunnel | NgrokTcpTunnel | NgrokTlsTunnel | NgrokLabeledTunnel;
5
- /** Start the given net.Server listening to a generated, or passed in, tunnel. */
1
+ /**
2
+ * Get a listenable ngrok tunnel, suitable for passing to net.Server.listen().
3
+ * Uses the NGROK_AUTHTOKEN environment variable to authenticate.
4
+ */
5
+ export function listenable(): NgrokTunnel;
6
+ /**
7
+ * Start the given net.Server listening to a generated, or passed in, tunnel.
8
+ * Uses the NGROK_AUTHTOKEN environment variable to authenticate if a new tunnel is created.
9
+ */
6
10
  export function listen(
7
11
  server: import("net").Server,
8
- tunnel?: NgrokHttpTunnel | NgrokTcpTunnel | NgrokTlsTunnel | NgrokLabeledTunnel
9
- ): NgrokHttpTunnel | NgrokTcpTunnel | NgrokTlsTunnel | NgrokLabeledTunnel;
12
+ tunnel?: NgrokTunnel
13
+ ): NgrokTunnel;
10
14
  /**
11
15
  * Register a console.log callback for ngrok INFO logging.
12
16
  * Optionally set the logging level to one of ERROR, WARN, INFO, DEBUG, or TRACE.
package/typedoc.json ADDED
@@ -0,0 +1,3 @@
1
+ {
2
+ "groupOrder": ["Tunnel and Sessions", "Tunnel Builders", "Functions"]
3
+ }