@ngrok/ngrok 0.7.1 → 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.
Files changed (77) hide show
  1. package/CHANGELOG.md +19 -10
  2. package/Cargo.toml +2 -2
  3. package/README.md +48 -32
  4. package/RELEASE.md +1 -1
  5. package/docs/assets/highlight.css +19 -12
  6. package/docs/assets/search.js +1 -1
  7. package/docs/classes/HttpListenerBuilder.html +594 -0
  8. package/docs/classes/LabeledListenerBuilder.html +206 -0
  9. package/docs/classes/Listener.html +241 -0
  10. package/docs/classes/Session.html +207 -0
  11. package/docs/classes/SessionBuilder.html +465 -0
  12. package/docs/classes/TcpListenerBuilder.html +281 -0
  13. package/docs/classes/TlsListenerBuilder.html +322 -0
  14. package/docs/classes/UpdateRequest.html +46 -43
  15. package/docs/functions/authtoken.html +30 -29
  16. package/docs/functions/connect.html +31 -30
  17. package/docs/functions/consoleLog.html +30 -29
  18. package/docs/functions/disconnect.html +31 -30
  19. package/docs/functions/getListener.html +89 -0
  20. package/docs/functions/getListenerByUrl.html +89 -0
  21. package/docs/functions/kill.html +31 -30
  22. package/docs/functions/listen.html +33 -32
  23. package/docs/functions/listenable.html +31 -30
  24. package/docs/functions/listeners.html +84 -0
  25. package/docs/functions/loggingCallback.html +30 -29
  26. package/docs/index.html +66 -58
  27. package/docs/interfaces/Config.html +445 -319
  28. package/docs/modules.html +48 -48
  29. package/examples/express/ngrok-express-quickstart.js +1 -1
  30. package/examples/express/ngrok-express.js +6 -6
  31. package/examples/fastify/ngrok-fastify.js +4 -4
  32. package/examples/hapi/ngrok-hapi.js +4 -4
  33. package/examples/koa/ngrok-koa.js +1 -1
  34. package/examples/nestjs/src/main.ts +5 -5
  35. package/examples/nextjs/README.md +3 -0
  36. package/examples/nextjs/ngrok.config.js +7 -7
  37. package/examples/ngrok-connect-full.js +8 -4
  38. package/examples/ngrok-connect-minimal.js +2 -2
  39. package/examples/ngrok-http-full.js +9 -6
  40. package/examples/ngrok-http-minimum.js +6 -6
  41. package/examples/ngrok-labeled.js +6 -6
  42. package/examples/ngrok-listen.js +1 -1
  43. package/examples/ngrok-tcp.js +5 -5
  44. package/examples/ngrok-tls.js +5 -5
  45. package/examples/ngrok-typescript.ts +12 -12
  46. package/examples/ngrok-windows-pipe.js +4 -4
  47. package/examples/ngrok-winston.js +2 -2
  48. package/examples/remix/ngrok.config.js +4 -4
  49. package/examples/svelte/ngrok.config.cjs +4 -4
  50. package/examples/vue/ngrok.config.ts +4 -4
  51. package/index.d.ts +511 -266
  52. package/index.js +75 -73
  53. package/package.json +14 -14
  54. package/scripts/gc-node-drop.js +7 -7
  55. package/scripts/gc-rust-drop.js +9 -9
  56. package/src/config.rs +113 -10
  57. package/src/connect.rs +38 -32
  58. package/src/http.rs +89 -23
  59. package/src/lib.rs +2 -2
  60. package/src/{tunnel.rs → listener.rs} +134 -134
  61. package/src/{tunnel_builder.rs → listener_builder.rs} +63 -54
  62. package/src/session.rs +57 -49
  63. package/src/tcp.rs +6 -3
  64. package/src/tls.rs +17 -7
  65. package/trailer.d.ts +5 -5
  66. package/trailer.js +64 -62
  67. package/typedoc.json +1 -1
  68. package/docs/classes/NgrokHttpTunnelBuilder.html +0 -510
  69. package/docs/classes/NgrokLabeledTunnelBuilder.html +0 -199
  70. package/docs/classes/NgrokSession.html +0 -199
  71. package/docs/classes/NgrokSessionBuilder.html +0 -449
  72. package/docs/classes/NgrokTcpTunnelBuilder.html +0 -268
  73. package/docs/classes/NgrokTlsTunnelBuilder.html +0 -304
  74. package/docs/classes/NgrokTunnel.html +0 -231
  75. package/docs/functions/getTunnel.html +0 -88
  76. package/docs/functions/getTunnelByUrl.html +0 -88
  77. package/docs/functions/tunnels.html +0 -83
package/CHANGELOG.md CHANGED
@@ -1,23 +1,32 @@
1
+ ## 0.9.0:
2
+
3
+ - `ngrok.connect` now returns the full `Listener` object.
4
+
5
+ ## 0.8.0:
6
+
7
+ - Add `allowUserAgent` and `denyUserAgent` options to HTTP listeners.
8
+ - Add `clientId` and `clientSecret` options to OAuth.
9
+
1
10
  ## 0.7.1:
2
11
 
3
12
  - Fix for windows pipe pathing.
4
13
 
5
14
  ## 0.7.0:
6
15
 
7
- - Add `listen_and_forward` and `listen_and_serve` to tunnel builders.
16
+ - Add `listen_and_forward` and `listen_and_serve` to listener builders.
8
17
  - Update to latest version of underlying rust library, allowing TLS backends.
9
18
 
10
19
  ## 0.6.0:
11
20
 
12
- - Flattened `tunnel.forwardPipe()` and `tunnel.forwardTcp()` into `tunnel.forward()`. Determination will be made based on `addr` input.
13
- - Add `ngrok.tunnels()` and `session.tunnels()` to get a list of current non-closed tunnels for the process or session, respectively.
21
+ - Flattened `listener.forwardPipe()` and `listener.forwardTcp()` into `listener.forward()`. Determination will be made based on `addr` input.
22
+ - Add `ngrok.listeners()` and `session.listeners()` to get a list of current non-closed listeners for the process or session, respectively.
14
23
  - Add `errorCode` field to thrown errors, where possible.
15
24
  - More heuristics for automatic unix socket file placement.
16
25
  - Connect heuristic improved for strings parseable as numbers.
17
26
 
18
27
  ## 0.5.2:
19
28
 
20
- - Cleanly return from a tunnel forward call after a `session.close()`.
29
+ - Cleanly return from a listener forward call after a `session.close()`.
21
30
 
22
31
  ## 0.5.1:
23
32
 
@@ -25,7 +34,7 @@
25
34
 
26
35
  ## 0.5.0:
27
36
 
28
- - Add `NgrokSession.clientInfo()`.
37
+ - Add `Session.clientInfo()`.
29
38
  - Rename to `ngrok-nodejs`.
30
39
 
31
40
  ## 0.4.1:
@@ -35,7 +44,7 @@
35
44
 
36
45
  ## 0.4.0:
37
46
 
38
- - Move to a single tunnel type for simplicity.
47
+ - Move to a single listener type for simplicity.
39
48
  - Documentation updates.
40
49
 
41
50
  ## 0.3.0:
@@ -55,12 +64,12 @@
55
64
 
56
65
  ## 0.1.0:
57
66
 
58
- - Added `ca_cert`, `handle_heartbeat`, and `handle_disconnection` to NgrokSession.
67
+ - Added `ca_cert`, `handle_heartbeat`, and `handle_disconnection` to Session.
59
68
 
60
69
  ## 0.0.12:
61
70
 
62
- - Added NgrokSession.close().
63
- - Cleanly shutdown when listen is called with a pre-configured tunnel.
71
+ - Added Session.close().
72
+ - Cleanly shutdown when listen is called with a pre-configured listener.
64
73
 
65
74
  ## 0.0.11:
66
75
 
@@ -77,7 +86,7 @@
77
86
  ## 0.0.8:
78
87
 
79
88
  - Support callbacks for logging, include console.log and Winston handlers.
80
- - Can now pass tunnels directly to net.Server.listen().
89
+ - Can now pass listeners directly to net.Server.listen().
81
90
  - Clean shutdown on SIGINT after ngrok.listen(server).
82
91
  - Typedoc generation of documentation.
83
92
 
package/Cargo.toml CHANGED
@@ -1,7 +1,7 @@
1
1
  [package]
2
2
  edition = "2021"
3
3
  name = "ngrok-nodejs"
4
- version = "0.7.1"
4
+ version = "0.9.0"
5
5
 
6
6
  [lib]
7
7
  crate-type = ["cdylib"]
@@ -18,7 +18,7 @@ mio = { version = "=0.8.6" }
18
18
  # Default enable napi4 feature, see https://nodejs.org/api/n-api.html#node-api-version-matrix
19
19
  napi = { version = "2.12.1", default-features = false, features = ["napi4", "tokio_rt"] }
20
20
  napi-derive = "2.12.1"
21
- ngrok = { version = "0.14.0-pre.6" }
21
+ ngrok = { version = "0.14.0-pre.8" }
22
22
  parking_lot = "0.12.1"
23
23
  regex = "1.9.5"
24
24
  rustls-pemfile = "1.0.1"
package/README.md CHANGED
@@ -45,8 +45,8 @@ npm install @ngrok/ngrok
45
45
  ```jsx
46
46
  const ngrok = require("@ngrok/ngrok");
47
47
  (async function() {
48
- const url = await ngrok.connect({ addr: 8080, authtoken_from_env: true });
49
- console.log(`Ingress established at: ${url}`);
48
+ const listener = await ngrok.connect({ addr: 8080, authtoken_from_env: true });
49
+ console.log(`Ingress established at: ${listener.url()}`);
50
50
  })();
51
51
  ```
52
52
 
@@ -76,69 +76,71 @@ await ngrok.authtoken(token);
76
76
 
77
77
  ## Connection
78
78
 
79
- The [connect](https://ngrok.github.io/ngrok-nodejs/functions/connect.html) method is the easiest way to start an ngrok session and establish a tunnel to a specified address. The [connect](https://ngrok.github.io/ngrok-nodejs/functions/connect.html) method returns a promise that resolves to the public URL of the tunnel.
79
+ The [connect](https://ngrok.github.io/ngrok-nodejs/functions/connect.html) method is the easiest way to start an ngrok session and establish a listener to a specified address. The [connect](https://ngrok.github.io/ngrok-nodejs/functions/connect.html) method returns a promise that resolves to the public URL of the listener.
80
80
 
81
- With no arguments the [connect](https://ngrok.github.io/ngrok-nodejs/functions/connect.html) method will start an HTTP tunnel to `localhost` port `80`:
81
+ With no arguments the [connect](https://ngrok.github.io/ngrok-nodejs/functions/connect.html) method will start an HTTP listener to `localhost` port `80`:
82
82
 
83
83
  ```jsx
84
84
  const ngrok = require("@ngrok/ngrok");
85
85
  (async function() {
86
- console.log( await ngrok.connect() );
86
+ console.log( (await ngrok.connect()).url() );
87
87
  })();
88
88
  ```
89
89
 
90
90
  You can pass the port number to forward on `localhost`:
91
91
 
92
92
  ```jsx
93
- const url = await ngrok.connect(4242);
93
+ const listener = await ngrok.connect(4242);
94
94
  ```
95
95
 
96
96
  Or you can specify the host and port via a string:
97
97
 
98
98
  ```jsx
99
- const url = await ngrok.connect("localhost:4242");
99
+ const listener = await ngrok.connect("localhost:4242");
100
100
  ```
101
101
 
102
102
  More options can be passed to the `connect` method to customize the connection:
103
103
 
104
104
  ```jsx
105
- const url = await ngrok.connect({addr: 8080, basic_auth: "ngrok:online1line"});
106
- const url = await ngrok.connect({addr: 8080, oauth_provider: "google", oauth_allow_domains: "example.com"});
105
+ const listener = await ngrok.connect({addr: 8080, basic_auth: "ngrok:online1line"});
106
+ const listener = await ngrok.connect({addr: 8080, oauth_provider: "google", oauth_allow_domains: "example.com"});
107
107
  ```
108
108
 
109
- The (optional) `proto` parameter is the tunnel type, which defaults to `http`. To create a TCP tunnel:
109
+ The (optional) `proto` parameter is the listener type, which defaults to `http`. To create a TCP listener:
110
110
 
111
111
  ```jsx
112
- const url = await ngrok.connect({proto: 'tcp', addr: 25565});
112
+ const listener = await ngrok.connect({proto: 'tcp', addr: 25565});
113
113
  ```
114
114
 
115
+ See [Full Configuration](#full-configuration) for the list of possible configuration options.
116
+
115
117
  ## Disconnection
116
118
 
117
- To close a tunnel use the [disconnect](https://ngrok.github.io/ngrok-nodejs/functions/disconnect.html) method with the `url` of the tunnel to close:
119
+ The [close](https://ngrok.github.io/ngrok-nodejs/classes/Listener.html#close) method on a listener will shut it down, and also stop the ngrok session if it is no longer needed. This method returns a promise that resolves when the listener is closed.
118
120
 
119
121
  ```jsx
120
- await ngrok.disconnect(url);
122
+ const listener = await ngrok.getListenerByUrl(url);
123
+ await listener.close();
121
124
  ```
122
125
 
123
- Or omit the `url` to close all tunnels:
126
+ Or use the [disconnect](https://ngrok.github.io/ngrok-nodejs/functions/disconnect.html) method with the `url()` of the listener to close (or id() for a Labeled Listener):
124
127
 
125
128
  ```jsx
126
- await ngrok.disconnect();
129
+ await ngrok.disconnect(listener.url());
127
130
  ```
128
131
 
129
- The [close](https://ngrok.github.io/ngrok-nodejs/classes/NgrokTunnel.html#close) method on a tunnel will shut it down, and also stop the ngrok session if it is no longer needed. This method returns a promise that resolves when the tunnel is closed.
132
+ Or omit the `url()` to close all listeners:
130
133
 
131
134
  ```jsx
132
- const tunnel = await ngrok.getTunnelByUrl(url);
133
- await tunnel.close();
135
+ await ngrok.disconnect();
134
136
  ```
135
137
 
136
- ## Listing Tunnels
138
+ ## Listing Listeners
137
139
 
138
- To list all current non-closed tunnels use the [tunnels](https://ngrok.github.io/ngrok-nodejs/functions/tunnels.html) method:
140
+ To list all current non-closed listeners use the [listeners](https://ngrok.github.io/ngrok-nodejs/functions/listeners.html) method:
139
141
 
140
142
  ```jsx
141
- const tunnels = await ngrok.tunnels();
143
+ const listeners = await ngrok.listeners();
142
144
  ```
143
145
 
144
146
  # Full Configuration
@@ -146,7 +148,7 @@ const tunnels = await ngrok.tunnels();
146
148
  This example shows [all the possible configuration items of ngrok.connect](https://github.com/ngrok/ngrok-nodejs/blob/main/examples/ngrok-connect-full.js):
147
149
 
148
150
  ```jsx
149
- const url = await ngrok.connect({
151
+ const listener = await ngrok.connect({
150
152
  // session configuration
151
153
  addr: `localhost:8080`, // or `8080` or `unix:${UNIX_SOCKET}`
152
154
  authtoken: "<authtoken>",
@@ -155,19 +157,23 @@ const url = await ngrok.connect({
155
157
  console.log(`disconnected, addr ${addr} error: ${error}`);
156
158
  },
157
159
  session_metadata: "Online in One Line",
158
- // tunnel configuration
160
+ // listener configuration
161
+ allow_user_agent: "^mozilla.*",
159
162
  basic_auth: ["ngrok:online1line"],
160
163
  circuit_breaker: 0.1,
161
164
  compression: true,
165
+ deny_user_agent: "^curl.*",
162
166
  domain: "<domain>",
163
167
  ip_restriction_allow_cidrs: ["0.0.0.0/0"],
164
168
  ip_restriction_deny_cidrs: ["10.1.1.1/32"],
165
- metadata: "example tunnel metadata from nodejs",
169
+ metadata: "example listener metadata from nodejs",
166
170
  mutual_tls_cas: [fs.readFileSync('ca.crt', 'utf8')],
167
171
  oauth_provider: "google",
168
172
  oauth_allow_domains: ["<domain>"],
169
173
  oauth_allow_emails: ["<email>"],
170
174
  oauth_scopes: ["<scope>"],
175
+ oauth_client_id: "<id>",
176
+ oauth_client_secret: "<secret>",
171
177
  oidc_issuer_url: "<url>",
172
178
  oidc_client_id: "<id>",
173
179
  oidc_client_secret: "<secret>",
@@ -215,7 +221,7 @@ npx degit github:ngrok/ngrok-nodejs/examples/express express && cd express && np
215
221
  * [Vue](https://vuejs.org/) - [Example vite.config.ts](https://github.com/ngrok/ngrok-nodejs/blob/main/examples/vue/vite.config.ts) loading [ngrok.config.ts](https://github.com/ngrok/ngrok-nodejs/blob/main/examples/vue/ngrok.config.ts)
216
222
  * [Winston](https://github.com/winstonjs/winston#readme) Logging - [Example](https://github.com/ngrok/ngrok-nodejs/blob/main/examples/ngrok-winston.js)
217
223
 
218
- ## Tunnel Types
224
+ ## Listener Types
219
225
  * ngrok.connect - [ngrok.connect Minimal Example](https://github.com/ngrok/ngrok-nodejs/blob/main/examples/ngrok-connect-minimal.js), [Full ngrok.connect Example](https://github.com/ngrok/ngrok-nodejs/blob/main/examples/ngrok-connect-full.js)
220
226
  * HTTP - [ngrok.listen Example](https://github.com/ngrok/ngrok-nodejs/blob/main/examples/ngrok-listen.js), [Minimal Example](https://github.com/ngrok/ngrok-nodejs/blob/main/examples/ngrok-http-minimum.js), [Full Configuration Example](https://github.com/ngrok/ngrok-nodejs/blob/main/examples/ngrok-http-full.js)
221
227
  * Labeled - [Example](https://github.com/ngrok/ngrok-nodejs/blob/main/examples/ngrok-labeled.js)
@@ -225,21 +231,31 @@ npx degit github:ngrok/ngrok-nodejs/examples/express express && cd express && np
225
231
 
226
232
  # Builders
227
233
 
228
- For more control over Sessions and Tunnels, the builder classes can be used.
234
+ For more control over Sessions and Listeners, the builder classes can be used.
229
235
 
230
236
  A minimal example using the builder class looks like [the following](https://github.com/ngrok/ngrok-nodejs/blob/main/examples/ngrok-http-minimum.js):
231
237
 
232
238
  ```jsx
233
- async function create_tunnel() {
239
+ async function create_listener() {
234
240
  const session = await new ngrok.NgrokSessionBuilder().authtokenFromEnv().connect();
235
- const tunnel = await session.httpEndpoint().listen();
236
- console.log("Ingress established at:", tunnel.url());
237
- tunnel.forward("localhost:8081");
241
+ const listener = await session.httpEndpoint().listen();
242
+ console.log("Ingress established at:", listener.url());
243
+ listener.forward("localhost:8081");
238
244
  }
239
245
  ```
240
246
 
241
247
  See here for a [Full Configuration Example](https://github.com/ngrok/ngrok-nodejs/blob/main/examples/ngrok-http-full.js)
242
248
 
249
+ ## TLS Backends
250
+
251
+ As of version `0.7.0` there is backend TLS connection support, validated by a filepath specified in the `SSL_CERT_FILE` environment variable, or falling back to the host OS installed trusted certificate authorities. So it is now possible to do this to connect:
252
+
253
+ ```jsx
254
+ await ngrok.connect({ addr: "https://127.0.0.1:3000", authtoken_from_env: true });
255
+ ```
256
+
257
+ If the service is using certs not trusted by the OS, such as self-signed certificates, add an environment variable like this before running: `SSL_CERT_FILE=/path/to/ca.crt`.
258
+
243
259
  # Async Programming
244
260
 
245
261
  All methods return a `Promise` and are suitable for use in asynchronous
@@ -248,7 +264,7 @@ or the `await` keyword to wait for completion of an API call.
248
264
 
249
265
  ### Error Handling
250
266
 
251
- The asynchronous functions will throw an error on failure to set up a session or tunnel,
267
+ The asynchronous functions will throw an error on failure to set up a session or listener,
252
268
  which can be caught and dealt with using standard then/catch semantics.
253
269
 
254
270
  ```jsx
@@ -256,7 +272,7 @@ new ngrok.NgrokSessionBuilder().authtokenFromEnv().connect()
256
272
  .then((session) => {
257
273
  session.httpEndpoint().listen()
258
274
  .then((tun) => {})
259
- .catch(err => console.log('tunnel setup error: ' + err))
275
+ .catch(err => console.log('listener setup error: ' + err))
260
276
  })
261
277
  .catch(err => console.log('session setup error: ' + err))
262
278
  .await;
package/RELEASE.md CHANGED
@@ -19,7 +19,7 @@ Release
19
19
  1. `git add .`
20
20
  1. `git commit -m '<version>'`
21
21
  1. `git push origin <username>/<version>`
22
- - Or with graphite: `gt branch track` and `gt stack submit`
22
+ - Or with graphite: `gt track` and `gt submit`
23
23
  1. Create a pull request off this branch
24
24
  - Make sure the name of the pull request is also just the `<version>` so the workflow will know to do a release
25
25
  1. Merge the pull request
@@ -1,22 +1,24 @@
1
1
  :root {
2
- --light-hl-0: #000000;
3
- --dark-hl-0: #D4D4D4;
4
- --light-hl-1: #A31515;
5
- --dark-hl-1: #CE9178;
6
- --light-hl-2: #0000FF;
7
- --dark-hl-2: #569CD6;
8
- --light-hl-3: #0070C1;
9
- --dark-hl-3: #4FC1FF;
10
- --light-hl-4: #795E26;
11
- --dark-hl-4: #DCDCAA;
2
+ --light-hl-0: #795E26;
3
+ --dark-hl-0: #DCDCAA;
4
+ --light-hl-1: #000000;
5
+ --dark-hl-1: #D4D4D4;
6
+ --light-hl-2: #A31515;
7
+ --dark-hl-2: #CE9178;
8
+ --light-hl-3: #0000FF;
9
+ --dark-hl-3: #569CD6;
10
+ --light-hl-4: #0070C1;
11
+ --dark-hl-4: #4FC1FF;
12
12
  --light-hl-5: #AF00DB;
13
13
  --dark-hl-5: #C586C0;
14
14
  --light-hl-6: #001080;
15
15
  --dark-hl-6: #9CDCFE;
16
16
  --light-hl-7: #098658;
17
17
  --dark-hl-7: #B5CEA8;
18
- --light-hl-8: #008000;
19
- --dark-hl-8: #6A9955;
18
+ --light-hl-8: #000000FF;
19
+ --dark-hl-8: #D4D4D4;
20
+ --light-hl-9: #008000;
21
+ --dark-hl-9: #6A9955;
20
22
  --light-code-background: #FFFFFF;
21
23
  --dark-code-background: #1E1E1E;
22
24
  }
@@ -31,6 +33,7 @@
31
33
  --hl-6: var(--light-hl-6);
32
34
  --hl-7: var(--light-hl-7);
33
35
  --hl-8: var(--light-hl-8);
36
+ --hl-9: var(--light-hl-9);
34
37
  --code-background: var(--light-code-background);
35
38
  } }
36
39
 
@@ -44,6 +47,7 @@
44
47
  --hl-6: var(--dark-hl-6);
45
48
  --hl-7: var(--dark-hl-7);
46
49
  --hl-8: var(--dark-hl-8);
50
+ --hl-9: var(--dark-hl-9);
47
51
  --code-background: var(--dark-code-background);
48
52
  } }
49
53
 
@@ -57,6 +61,7 @@
57
61
  --hl-6: var(--light-hl-6);
58
62
  --hl-7: var(--light-hl-7);
59
63
  --hl-8: var(--light-hl-8);
64
+ --hl-9: var(--light-hl-9);
60
65
  --code-background: var(--light-code-background);
61
66
  }
62
67
 
@@ -70,6 +75,7 @@
70
75
  --hl-6: var(--dark-hl-6);
71
76
  --hl-7: var(--dark-hl-7);
72
77
  --hl-8: var(--dark-hl-8);
78
+ --hl-9: var(--dark-hl-9);
73
79
  --code-background: var(--dark-code-background);
74
80
  }
75
81
 
@@ -82,4 +88,5 @@
82
88
  .hl-6 { color: var(--hl-6); }
83
89
  .hl-7 { color: var(--hl-7); }
84
90
  .hl-8 { color: var(--hl-8); }
91
+ .hl-9 { color: var(--hl-9); }
85
92
  pre, code { background: var(--code-background); }