@ngrok/ngrok 1.7.0 → 1.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 1.8.0
2
+
3
+ - Change how a session waits between reconnect attempts after it loses its connection, for every session: the wait starts at 50 ms and doubles up to 30 s, each wait scaled by a random factor in [0, 1). Before, the wait grew 50-fold per attempt with no cap and no random factor: about 2 minutes before the fourth attempt and 1 h 44 min before the fifth.
4
+ - Add `SessionBuilder.reconnectBackoff(initialMs, maxMs)`, which sets the first wait between reconnect attempts and the cap the doubling waits stop at, and `SessionBuilder.reconnectJitter(enabled)`, which turns off or on the random scaling of each wait. The defaults are 50 ms, 30 s and jitter on. `reconnectBackoff` refuses a value that is not a whole number of milliseconds, such as a fraction, NaN or Infinity, with an error naming the argument.
5
+ - Add `SessionBuilder.reconnectMaxAttempts(attempts)`, which stops a session reconnecting after that many failed attempts in one outage; every listener then stops forwarding, and its `forward()` and `join()` reject with the last attempt's error. `listenAndServe`, `ngrok.listen` and `net.Server.listen(listener)` log that error with `console.error` and leave the process running. It refuses anything but a whole number from 1 to 4294967295. By default a session never stops reconnecting on its own.
6
+
1
7
  ## 1.7.0
2
8
 
3
9
  - Add support for CEL filtering when listing resources.
package/README.md CHANGED
@@ -170,7 +170,7 @@ A minimal example using the builder class looks like [the following](https://git
170
170
 
171
171
  ```jsx
172
172
  async function create_listener() {
173
- const session = await new ngrok.NgrokSessionBuilder().authtokenFromEnv().connect();
173
+ const session = await new ngrok.SessionBuilder().authtokenFromEnv().connect();
174
174
  const listener = await session.httpEndpoint().listen();
175
175
  console.log("Ingress established at:", listener.url());
176
176
  listener.forward("localhost:8081");
@@ -201,14 +201,13 @@ All asynchronous functions will throw an error on failure to set up a session or
201
201
  which can be caught and dealt with using try/catch or then/catch statements:
202
202
 
203
203
  ```jsx
204
- new ngrok.NgrokSessionBuilder().authtokenFromEnv().connect()
204
+ await new ngrok.SessionBuilder().authtokenFromEnv().connect()
205
205
  .then((session) => {
206
206
  session.httpEndpoint().listen()
207
207
  .then((tun) => {})
208
208
  .catch(err => console.log('listener setup error: ' + err))
209
209
  })
210
- .catch(err => console.log('session setup error: ' + err))
211
- .await;
210
+ .catch(err => console.log('session setup error: ' + err));
212
211
  ```
213
212
 
214
213
  ### Full Configuration
@@ -221,8 +220,8 @@ const listener = await ngrok.forward({
221
220
  addr: `localhost:8080`, // or `8080` or `unix:${UNIX_SOCKET}`
222
221
  authtoken: "<authtoken>",
223
222
  authtoken_from_env: true,
224
- on_status_change: (addr, error) => {
225
- console.log(`disconnected, addr ${addr} error: ${error}`);
223
+ onStatusChange: (status) => {
224
+ console.log(`Ngrok status changed: ${status}`);
226
225
  },
227
226
  session_metadata: "Online in One Line",
228
227
  // advanced session connection configuration
@@ -260,7 +259,6 @@ const listener = await ngrok.forward({
260
259
  oidc_allow_domains: ["<domain>"],
261
260
  oidc_allow_emails: ["<email>"],
262
261
  oidc_scopes: ["<scope>"],
263
- pooling_enabled: false,
264
262
  traffic_policy: "<policy_json>",
265
263
  request_header_remove: ["X-Req-Nope"],
266
264
  response_header_remove: ["X-Res-Nope"],
@@ -347,7 +345,6 @@ Changes to `ngrok-javascript` are tracked under [CHANGELOG.md](https://github.co
347
345
  - Check out [our official docs](https://docs.ngrok.com)
348
346
  - Read about updates on [our blog](https://blog.ngrok.com)
349
347
  - Open an [issue](https://github.com/ngrok/ngrok-javascript/issues) or [pull request](https://github.com/ngrok/ngrok-javascript/pulls)
350
- - Join our [Slack community](https://ngrok.com/slack)
351
348
  - Follow us on [X / Twitter (@ngrokHQ)](https://twitter.com/ngrokhq)
352
349
  - Subscribe to our [Youtube channel (@ngrokHQ)](https://www.youtube.com/@ngrokhq)
353
350
 
package/index.d.ts CHANGED
@@ -843,6 +843,56 @@ export declare class SessionBuilder {
843
843
  * [heartbeat_tolerance parameter in the ngrok docs]: https://ngrok.com/docs/ngrok-agent/config#heartbeat_tolerance
844
844
  */
845
845
  heartbeatTolerance(heartbeatTolerance: number): this
846
+ /**
847
+ * Configures how long the session waits between attempts to reconnect
848
+ * after it loses its connection to the ngrok service, in milliseconds.
849
+ *
850
+ * The first attempt is immediate. After it, the session waits `initialMs`,
851
+ * then twice as long before each attempt, up to `maxMs`. Each wait is
852
+ * scaled by a random factor in [0, 1) unless
853
+ * [SessionBuilder::reconnectJitter] turns that off. The defaults are
854
+ * 50 ms and 30 s. For a fixed wait between every attempt, pass the same
855
+ * value for both and turn jitter off.
856
+ *
857
+ * These waits never stop the session from reconnecting on their own:
858
+ * [SessionBuilder::reconnectMaxAttempts], or closing the session, does.
859
+ *
860
+ * A value that is not a whole number of milliseconds of at least 0 (a
861
+ * fraction, a negative number, NaN or Infinity) is refused with an error
862
+ * naming the argument. The ngrok Rust SDK then checks the range: it
863
+ * rejects an `initialMs` below 1 or above `maxMs`, and a `maxMs` above one
864
+ * day (86400000), with an error that starts with the call and its
865
+ * arguments, as in "reconnectBackoff(initialMs: 2000, maxMs: 1000): ",
866
+ * and names the rule broken. A refused call leaves the builder unchanged.
867
+ */
868
+ reconnectBackoff(initialMs: number, maxMs: number): this
869
+ /**
870
+ * Configures whether each wait between reconnect attempts is scaled by a
871
+ * random factor in [0, 1). On by default, so that sessions that lose
872
+ * their connections together don't all reconnect at the same moment.
873
+ */
874
+ reconnectJitter(enabled: boolean): this
875
+ /**
876
+ * Configures the session to stop reconnecting after `attempts` failed
877
+ * attempts in one outage, counting the immediate first attempt. Each new
878
+ * outage starts the count again. By default the session never stops on
879
+ * its own.
880
+ *
881
+ * When the session stops, every listener stops forwarding with the last
882
+ * attempt's error: [Listener::forward] rejects with an error whose message
883
+ * starts "error forwarding:", and [Listener::join] with one that starts
884
+ * "error on join:". Nothing rejects for the forwarding that `ngrok.forward`
885
+ * starts. The forwarding that `listenAndServe`, `ngrok.listen` and
886
+ * `net.Server.listen(listener)` start logs the error with `console.error`
887
+ * and leaves the process running. The
888
+ * [SessionBuilder::handleDisconnection] handler is called before each
889
+ * attempt, and not again once the session stops.
890
+ *
891
+ * `attempts` must be a whole number from 1 to 4294967295; anything else,
892
+ * a fraction, NaN or Infinity included, is refused with an error naming
893
+ * the argument.
894
+ */
895
+ reconnectMaxAttempts(attempts: number): this
846
896
  /**
847
897
  * Configures the opaque, machine-readable metadata string for this session.
848
898
  * Metadata is made available to you in the ngrok dashboard and the Agents API
package/index.js CHANGED
@@ -411,7 +411,7 @@ function defineListenerHandle(listener, socket) {
411
411
  Object.defineProperty(listener, "handle", {
412
412
  get: function () {
413
413
  // turn on forwarding now that it has been requested
414
- listener.forward("localhost:" + socket.address().port);
414
+ forwardInBackground(listener, "localhost:" + socket.address().port);
415
415
  return socket._handle;
416
416
  },
417
417
  });
@@ -486,10 +486,19 @@ async function ngrokLinkTcp(listener, server) {
486
486
  // random local port
487
487
  const socket = await asyncListen(server, { host: "localhost", port: 0 });
488
488
  // forward to socket
489
- listener.forward("localhost:" + socket.address().port);
489
+ forwardInBackground(listener, "localhost:" + socket.address().port);
490
490
  return socket;
491
491
  }
492
492
 
493
+ // Start forwarding without waiting for it to end. Forwarding ends with an error
494
+ // when the session stops reconnecting (SessionBuilder.reconnectMaxAttempts);
495
+ // that error is logged, since a rejection left unhandled ends the process.
496
+ function forwardInBackground(listener, addr) {
497
+ listener.forward(addr).catch((err) => {
498
+ console.error(`ngrok listener stopped forwarding to ${addr}: ${err}`);
499
+ });
500
+ }
501
+
493
502
  function generatePipeFilename(listener, server) {
494
503
  var proposed = "tun-" + listener.id() + ".sock";
495
504
 
@@ -552,7 +561,7 @@ async function ngrokLinkPipe(listener, server) {
552
561
  // convert pipe path to url
553
562
  addr = "pipe:" + filename.replace("\\\\.\\pipe\\", "//./");
554
563
  }
555
- listener.forward(addr);
564
+ forwardInBackground(listener, addr);
556
565
  socket.path = filename; // surface to caller
557
566
 
558
567
  return socket;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ngrok/ngrok",
3
- "version": "1.7.0",
3
+ "version": "1.8.0",
4
4
  "main": "index.js",
5
5
  "types": "index.d.ts",
6
6
  "files": [
@@ -95,18 +95,18 @@
95
95
  }
96
96
  },
97
97
  "optionalDependencies": {
98
- "@ngrok/ngrok-win32-x64-msvc": "1.7.0",
99
- "@ngrok/ngrok-darwin-x64": "1.7.0",
100
- "@ngrok/ngrok-linux-x64-gnu": "1.7.0",
101
- "@ngrok/ngrok-darwin-arm64": "1.7.0",
102
- "@ngrok/ngrok-android-arm64": "1.7.0",
103
- "@ngrok/ngrok-win32-arm64-msvc": "1.7.0",
104
- "@ngrok/ngrok-linux-arm64-gnu": "1.7.0",
105
- "@ngrok/ngrok-linux-arm64-musl": "1.7.0",
106
- "@ngrok/ngrok-linux-arm-gnueabihf": "1.7.0",
107
- "@ngrok/ngrok-linux-x64-musl": "1.7.0",
108
- "@ngrok/ngrok-freebsd-x64": "1.7.0",
109
- "@ngrok/ngrok-win32-ia32-msvc": "1.7.0",
110
- "@ngrok/ngrok-darwin-universal": "1.7.0"
98
+ "@ngrok/ngrok-win32-x64-msvc": "1.8.0",
99
+ "@ngrok/ngrok-darwin-x64": "1.8.0",
100
+ "@ngrok/ngrok-linux-x64-gnu": "1.8.0",
101
+ "@ngrok/ngrok-darwin-arm64": "1.8.0",
102
+ "@ngrok/ngrok-android-arm64": "1.8.0",
103
+ "@ngrok/ngrok-win32-arm64-msvc": "1.8.0",
104
+ "@ngrok/ngrok-linux-arm64-gnu": "1.8.0",
105
+ "@ngrok/ngrok-linux-arm64-musl": "1.8.0",
106
+ "@ngrok/ngrok-linux-arm-gnueabihf": "1.8.0",
107
+ "@ngrok/ngrok-linux-x64-musl": "1.8.0",
108
+ "@ngrok/ngrok-freebsd-x64": "1.8.0",
109
+ "@ngrok/ngrok-win32-ia32-msvc": "1.8.0",
110
+ "@ngrok/ngrok-darwin-universal": "1.8.0"
111
111
  }
112
112
  }