@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.
- package/CHANGELOG.md +5 -0
- package/Cargo.toml +1 -1
- package/README.md +1 -1
- package/docs/assets/main.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/assets/style.css +6 -4
- package/docs/classes/NgrokHttpTunnelBuilder.html +40 -43
- package/docs/classes/NgrokLabeledTunnelBuilder.html +23 -26
- package/docs/classes/NgrokSession.html +24 -27
- package/docs/classes/NgrokSessionBuilder.html +32 -35
- package/docs/classes/NgrokTcpTunnelBuilder.html +27 -30
- package/docs/classes/NgrokTlsTunnelBuilder.html +29 -32
- package/docs/classes/{NgrokTcpTunnel.html → NgrokTunnel.html} +54 -47
- package/docs/classes/UpdateRequest.html +20 -23
- package/docs/functions/authtoken.html +18 -21
- package/docs/functions/connect.html +18 -21
- package/docs/functions/consoleLog.html +18 -21
- package/docs/functions/disconnect.html +18 -21
- package/docs/functions/kill.html +18 -21
- package/docs/functions/listen.html +23 -25
- package/docs/functions/listenable.html +22 -29
- package/docs/functions/loggingCallback.html +18 -21
- package/docs/index.html +18 -21
- package/docs/interfaces/Config.html +70 -73
- package/docs/modules.html +32 -38
- package/index.d.ts +24 -134
- package/index.js +2 -5
- package/package.json +16 -15
- package/src/session.rs +2 -4
- package/src/tunnel.rs +108 -102
- package/src/tunnel_builder.rs +3 -2
- package/trailer.d.ts +11 -7
- package/typedoc.json +3 -0
- package/docs/classes/NgrokHttpTunnel.html +0 -226
- package/docs/classes/NgrokLabeledTunnel.html +0 -214
- 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
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
131
|
+
NgrokTunnel {
|
|
142
132
|
id,
|
|
143
133
|
forwards_to,
|
|
144
134
|
metadata,
|
|
145
|
-
|
|
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
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
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
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
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
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
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
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
181
|
+
/// Returns a tunnel's unique ID.
|
|
182
|
+
#[napi]
|
|
183
|
+
pub fn id(&self) -> String {
|
|
184
|
+
self.id.clone()
|
|
185
|
+
}
|
|
201
186
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
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
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
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
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
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
|
-
///
|
|
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()
|
package/src/tunnel_builder.rs
CHANGED
|
@@ -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
|
|
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::
|
|
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
|
-
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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?:
|
|
9
|
-
):
|
|
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