@ngrok/ngrok 0.4.0 → 0.5.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 (46) hide show
  1. package/CHANGELOG.md +12 -2
  2. package/CONTRIBUTING.md +4 -4
  3. package/Cargo.toml +3 -3
  4. package/README.md +29 -29
  5. package/docs/assets/search.js +1 -1
  6. package/docs/classes/NgrokHttpTunnelBuilder.html +21 -21
  7. package/docs/classes/NgrokLabeledTunnelBuilder.html +4 -4
  8. package/docs/classes/NgrokSession.html +7 -7
  9. package/docs/classes/NgrokSessionBuilder.html +40 -15
  10. package/docs/classes/NgrokTcpTunnelBuilder.html +8 -8
  11. package/docs/classes/NgrokTlsTunnelBuilder.html +10 -10
  12. package/docs/classes/NgrokTunnel.html +10 -10
  13. package/docs/classes/UpdateRequest.html +3 -3
  14. package/docs/functions/authtoken.html +1 -1
  15. package/docs/functions/connect.html +1 -1
  16. package/docs/functions/consoleLog.html +1 -1
  17. package/docs/functions/disconnect.html +1 -1
  18. package/docs/functions/kill.html +1 -1
  19. package/docs/functions/listen.html +1 -1
  20. package/docs/functions/listenable.html +1 -1
  21. package/docs/functions/loggingCallback.html +1 -1
  22. package/docs/index.html +28 -28
  23. package/docs/interfaces/Config.html +53 -53
  24. package/examples/express/package.json +1 -1
  25. package/examples/fastify/package.json +1 -1
  26. package/examples/hapi/package.json +1 -1
  27. package/examples/koa/package.json +1 -1
  28. package/examples/nestjs/package.json +1 -1
  29. package/examples/nextjs/package.json +1 -1
  30. package/examples/ngrok-http-full.js +5 -2
  31. package/examples/ngrok-listen.js +1 -1
  32. package/examples/ngrok-windows-pipe.js +1 -1
  33. package/examples/package.json +6 -2
  34. package/examples/remix/package.json +1 -1
  35. package/examples/svelte/ngrok.config.cjs +3 -1
  36. package/examples/svelte/package.json +1 -1
  37. package/examples/vue/package.json +1 -1
  38. package/flake.nix +1 -1
  39. package/index.d.ts +13 -4
  40. package/index.js +9 -7
  41. package/package.json +15 -15
  42. package/src/session.rs +27 -4
  43. package/src/tunnel.rs +2 -2
  44. package/trailer.d.ts +1 -4
  45. package/trailer.js +9 -7
  46. package/examples/nestjs/package-lock.json +0 -12138
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "devDependencies": {
3
- "@ngrok/ngrok": "^0.2.0",
3
+ "@ngrok/ngrok": "^0.*",
4
4
  "@hapi/hapi": "21.3.1"
5
5
  },
6
6
  "packageManager": "yarn@3.3.1"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "devDependencies": {
3
- "@ngrok/ngrok": "^0.2.0",
3
+ "@ngrok/ngrok": "^0.*",
4
4
  "koa": "2.14.2"
5
5
  },
6
6
  "packageManager": "yarn@3.3.1"
@@ -23,7 +23,7 @@
23
23
  "@nestjs/common": "^9.0.0",
24
24
  "@nestjs/core": "^9.0.0",
25
25
  "@nestjs/platform-express": "^9.0.0",
26
- "@ngrok/ngrok": "^0.2.0",
26
+ "@ngrok/ngrok": "^0.*",
27
27
  "reflect-metadata": "^0.1.13",
28
28
  "rxjs": "^7.2.0"
29
29
  },
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "dependencies": {
3
- "@ngrok/ngrok": "^0.2.0",
3
+ "@ngrok/ngrok": "^0.*",
4
4
  "next": "13.3.0"
5
5
  }
6
6
  }
@@ -25,6 +25,7 @@ builder
25
25
  // .authtoken("<authtoken>")
26
26
  .authtokenFromEnv()
27
27
  .metadata("Online in One Line")
28
+ .clientInfo("ngrok-http-full", "1.2.3")
28
29
  // .caCert(fs.readFileSync('ca.crt'))
29
30
  // .serverAddr('192.168.1.1:443')
30
31
  .handleStopCommand(() => {
@@ -35,8 +36,10 @@ builder
35
36
  })
36
37
  .handleUpdateCommand((update) => {
37
38
  console.log(
38
- "update command, version:", update.version,
39
- "permitMajorVersion:", update.permitMajorVersion
39
+ "update command, version:",
40
+ update.version,
41
+ "permitMajorVersion:",
42
+ update.permitMajorVersion
40
43
  );
41
44
  })
42
45
  .handleHeartbeat((latency) => {
@@ -7,5 +7,5 @@ const server = require("http").createServer(function (req, res) {
7
7
  const ngrok = require("@ngrok/ngrok");
8
8
 
9
9
  ngrok.listen(server).then(() => {
10
- console.log("Ingress establised at:", server.tunnel.url());
10
+ console.log("Ingress established at:", server.tunnel.url());
11
11
  });
@@ -10,7 +10,7 @@ http
10
10
  .listen(PIPE);
11
11
 
12
12
  const ngrok = require("@ngrok/ngrok");
13
- ngrok.consoleLog(); // turn on debug logging
13
+ ngrok.consoleLog(); // turn on info logging
14
14
  new ngrok.NgrokSessionBuilder()
15
15
  .authtokenFromEnv()
16
16
  .connect()
@@ -1,11 +1,15 @@
1
1
  {
2
2
  "devDependencies": {
3
- "@ngrok/ngrok": "^0.2.0",
3
+ "@ngrok/ngrok": "^0.*",
4
4
  "create-remix": "1.15.0",
5
5
  "create-svelte": "3.3.0",
6
6
  "create-vue": "3.6.1",
7
7
  "ts-node": "^10.9.1",
8
8
  "winston": "^3.8.2"
9
9
  },
10
- "packageManager": "yarn@3.3.1"
10
+ "packageManager": "yarn@3.3.1",
11
+ "scripts": {
12
+ "start": "node ngrok-http-minimum.js",
13
+ "listen": "node ngrok-listen.js"
14
+ }
11
15
  }
@@ -8,7 +8,7 @@
8
8
  "typecheck": "tsc"
9
9
  },
10
10
  "dependencies": {
11
- "@ngrok/ngrok": "^0.2.0",
11
+ "@ngrok/ngrok": "^0.*",
12
12
  "@remix-run/node": "^1.15.0",
13
13
  "@remix-run/react": "^1.15.0",
14
14
  "@remix-run/serve": "^1.15.0",
@@ -3,7 +3,9 @@ const ngrok = require("@ngrok/ngrok");
3
3
  // setup ngrok ingress in the parent process
4
4
  var host = "localhost";
5
5
  var port = "5173";
6
+ var run = true;
6
7
  process.argv.forEach((item, index) => {
8
+ if (item.includes("postinstall")) run = false;
7
9
  if (item == "--host") host = process.argv[index + 1];
8
10
  if (item == "--port") port = process.argv[index + 1];
9
11
  });
@@ -15,4 +17,4 @@ async function setup() {
15
17
  tunnel.forwardTcp(`${host}:${port}`);
16
18
  }
17
19
 
18
- setup();
20
+ if (run) setup();
@@ -10,7 +10,7 @@
10
10
  "check:watch": "svelte-kit sync && svelte-check --tsconfig ./jsconfig.json --watch"
11
11
  },
12
12
  "devDependencies": {
13
- "@ngrok/ngrok": "^0.2.0",
13
+ "@ngrok/ngrok": "^0.*",
14
14
  "@sveltejs/adapter-auto": "^2.0.0",
15
15
  "@sveltejs/kit": "^1.5.0",
16
16
  "svelte": "^3.54.0",
@@ -10,7 +10,7 @@
10
10
  "type-check": "vue-tsc --noEmit"
11
11
  },
12
12
  "dependencies": {
13
- "@ngrok/ngrok": "^0.2.0",
13
+ "@ngrok/ngrok": "^0.*",
14
14
  "vue": "^3.2.47"
15
15
  },
16
16
  "devDependencies": {
package/flake.nix CHANGED
@@ -93,7 +93,7 @@
93
93
  OPENSSL_LIB_DIR = "${pkgs.openssl.out}/lib";
94
94
  OPENSSL_INCLUDE_DIR = "${pkgs.openssl.dev}/include";
95
95
  shellHook = ''
96
- export PATH="$PATH:node_modules/.bin:`pwd`/node_modules/.bin"
96
+ export PATH="$PATH:$(git rev-parse --show-toplevel)/node_modules/.bin:$(git rev-parse --show-toplevel)/examples/node_modules/.bin"
97
97
  '';
98
98
  buildInputs = with pkgs; [
99
99
  toolchain
package/index.d.ts CHANGED
@@ -207,6 +207,18 @@ export class NgrokSessionBuilder {
207
207
  * NGROK_AUTHTOKEN environment variable.
208
208
  */
209
209
  authtokenFromEnv(): this
210
+ /**
211
+ * Add client type and version information for a client application.
212
+ *
213
+ * This is a way for applications and library consumers of this crate
214
+ * identify themselves.
215
+ *
216
+ * This will add a new entry to the `User-Agent` field in the "most significant"
217
+ * (first) position. Comments must follow [RFC 7230] or a connection error may occur.
218
+ *
219
+ * [RFC 7230]: https://datatracker.ietf.org/doc/html/rfc7230#section-3.2.6
220
+ */
221
+ clientInfo(clientType: string, version: string, comments?: string | undefined | null): this
210
222
  /**
211
223
  * Configures how often the session will send heartbeat messages to the ngrok
212
224
  * service to check session liveness.
@@ -547,10 +559,7 @@ export function listenable(): NgrokTunnel;
547
559
  * Start the given net.Server listening to a generated, or passed in, tunnel.
548
560
  * Uses the NGROK_AUTHTOKEN environment variable to authenticate if a new tunnel is created.
549
561
  */
550
- export function listen(
551
- server: import("net").Server,
552
- tunnel?: NgrokTunnel
553
- ): NgrokTunnel;
562
+ export function listen(server: import("net").Server, tunnel?: NgrokTunnel): NgrokTunnel;
554
563
  /**
555
564
  * Register a console.log callback for ngrok INFO logging.
556
565
  * Optionally set the logging level to one of ERROR, WARN, INFO, DEBUG, or TRACE.
package/index.js CHANGED
@@ -423,24 +423,26 @@ async function ngrokLinkPipe(tunnel, server) {
423
423
  return socket;
424
424
  }
425
425
 
426
+ // protect against multiple calls, for instance from npm
427
+ var sigintRan = false;
428
+
426
429
  function registerCleanup(tunnel, socket) {
427
430
  process.on("SIGINT", function () {
431
+ if (sigintRan) return;
432
+ sigintRan = true;
433
+
428
434
  if (process.listenerCount("SIGINT") > 1) {
429
435
  // user has registered a handler, abort this one
430
436
  return;
431
437
  }
432
438
  // close tunnel
433
439
  if (tunnel) {
434
- tunnel.close().then(() => {
435
- console.debug("ngrok closed tunnel: " + tunnel.id());
440
+ tunnel.close().catch((err) => {
441
+ console.error(`Error closing tunnel: ${err}`);
436
442
  });
437
443
  }
438
444
  // close webserver's socket
439
- if (socket) {
440
- socket.close(function () {
441
- console.debug("ngrok closed socket");
442
- });
443
- }
445
+ if (socket) socket.close();
444
446
  // unregister any logging callback
445
447
  loggingCallback();
446
448
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ngrok/ngrok",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "main": "index.js",
5
5
  "types": "index.d.ts",
6
6
  "napi": {
@@ -53,20 +53,20 @@
53
53
  },
54
54
  "packageManager": "yarn@3.3.1",
55
55
  "description": "The ngrok agent in library form, suitable for integrating directly into your NodeJS application.",
56
- "repository": "https://github.com/ngrok/ngrok-js",
56
+ "repository": "https://github.com/ngrok/ngrok-nodejs",
57
57
  "optionalDependencies": {
58
- "@ngrok/ngrok-win32-x64-msvc": "0.4.0",
59
- "@ngrok/ngrok-darwin-x64": "0.4.0",
60
- "@ngrok/ngrok-linux-x64-gnu": "0.4.0",
61
- "@ngrok/ngrok-darwin-arm64": "0.4.0",
62
- "@ngrok/ngrok-android-arm64": "0.4.0",
63
- "@ngrok/ngrok-linux-arm64-gnu": "0.4.0",
64
- "@ngrok/ngrok-linux-arm64-musl": "0.4.0",
65
- "@ngrok/ngrok-linux-arm-gnueabihf": "0.4.0",
66
- "@ngrok/ngrok-linux-x64-musl": "0.4.0",
67
- "@ngrok/ngrok-freebsd-x64": "0.4.0",
68
- "@ngrok/ngrok-win32-ia32-msvc": "0.4.0",
69
- "@ngrok/ngrok-android-arm-eabi": "0.4.0",
70
- "@ngrok/ngrok-darwin-universal": "0.4.0"
58
+ "@ngrok/ngrok-win32-x64-msvc": "0.5.0",
59
+ "@ngrok/ngrok-darwin-x64": "0.5.0",
60
+ "@ngrok/ngrok-linux-x64-gnu": "0.5.0",
61
+ "@ngrok/ngrok-darwin-arm64": "0.5.0",
62
+ "@ngrok/ngrok-android-arm64": "0.5.0",
63
+ "@ngrok/ngrok-linux-arm64-gnu": "0.5.0",
64
+ "@ngrok/ngrok-linux-arm64-musl": "0.5.0",
65
+ "@ngrok/ngrok-linux-arm-gnueabihf": "0.5.0",
66
+ "@ngrok/ngrok-linux-x64-musl": "0.5.0",
67
+ "@ngrok/ngrok-freebsd-x64": "0.5.0",
68
+ "@ngrok/ngrok-win32-ia32-msvc": "0.5.0",
69
+ "@ngrok/ngrok-android-arm-eabi": "0.5.0",
70
+ "@ngrok/ngrok-darwin-universal": "0.5.0"
71
71
  }
72
72
  }
package/src/session.rs CHANGED
@@ -44,7 +44,7 @@ use crate::{
44
44
  },
45
45
  };
46
46
 
47
- const CLIENT_TYPE: &str = "library/official/nodejs";
47
+ const CLIENT_TYPE: &str = "ngrok-nodejs";
48
48
  const VERSION: &str = env!("CARGO_PKG_VERSION");
49
49
 
50
50
  // appease clippy
@@ -84,9 +84,11 @@ impl NgrokSessionBuilder {
84
84
  #[napi(constructor)]
85
85
  pub fn new() -> Self {
86
86
  NgrokSessionBuilder {
87
- raw_builder: Arc::new(SyncMutex::new(
88
- Session::builder().child_client(CLIENT_TYPE, VERSION),
89
- )),
87
+ raw_builder: Arc::new(SyncMutex::new(Session::builder().client_info(
88
+ CLIENT_TYPE,
89
+ VERSION,
90
+ None::<String>,
91
+ ))),
90
92
  ..Default::default()
91
93
  }
92
94
  }
@@ -118,6 +120,27 @@ impl NgrokSessionBuilder {
118
120
  self
119
121
  }
120
122
 
123
+ /// Add client type and version information for a client application.
124
+ ///
125
+ /// This is a way for applications and library consumers of this crate
126
+ /// identify themselves.
127
+ ///
128
+ /// This will add a new entry to the `User-Agent` field in the "most significant"
129
+ /// (first) position. Comments must follow [RFC 7230] or a connection error may occur.
130
+ ///
131
+ /// [RFC 7230]: https://datatracker.ietf.org/doc/html/rfc7230#section-3.2.6
132
+ #[napi]
133
+ pub fn client_info(
134
+ &mut self,
135
+ client_type: String,
136
+ version: String,
137
+ comments: Option<String>,
138
+ ) -> &Self {
139
+ let mut builder = self.raw_builder.lock();
140
+ *builder = builder.clone().client_info(client_type, version, comments);
141
+ self
142
+ }
143
+
121
144
  /// Configures how often the session will send heartbeat messages to the ngrok
122
145
  /// service to check session liveness.
123
146
  ///
package/src/tunnel.rs CHANGED
@@ -220,7 +220,7 @@ impl NgrokTunnel {
220
220
  /// tunnel's ID.
221
221
  #[napi]
222
222
  pub async fn close(&self) -> Result<()> {
223
- debug!("{} closing, id: {}", stringify!($wrapper), self.id);
223
+ debug!("NgrokTunnel closing, id: {}", self.id);
224
224
 
225
225
  // we may not be able to lock our reference to the tunnel due to the forward_* calls which
226
226
  // continuously accept-loop while the tunnel is active, so calling close on the Session.
@@ -240,7 +240,7 @@ impl NgrokTunnel {
240
240
  #[allow(unused_mut)]
241
241
  impl ObjectFinalize for NgrokTunnel {
242
242
  fn finalize(mut self, _env: Env) -> Result<()> {
243
- debug!("{} finalize, id: {}", stringify!($wrapper), self.id);
243
+ debug!("NgrokTunnel finalize, id: {}", self.id);
244
244
  Ok(())
245
245
  }
246
246
  }
package/trailer.d.ts CHANGED
@@ -7,10 +7,7 @@ export function listenable(): NgrokTunnel;
7
7
  * Start the given net.Server listening to a generated, or passed in, tunnel.
8
8
  * Uses the NGROK_AUTHTOKEN environment variable to authenticate if a new tunnel is created.
9
9
  */
10
- export function listen(
11
- server: import("net").Server,
12
- tunnel?: NgrokTunnel
13
- ): NgrokTunnel;
10
+ export function listen(server: import("net").Server, tunnel?: NgrokTunnel): NgrokTunnel;
14
11
  /**
15
12
  * Register a console.log callback for ngrok INFO logging.
16
13
  * Optionally set the logging level to one of ERROR, WARN, INFO, DEBUG, or TRACE.
package/trailer.js CHANGED
@@ -154,24 +154,26 @@ async function ngrokLinkPipe(tunnel, server) {
154
154
  return socket;
155
155
  }
156
156
 
157
+ // protect against multiple calls, for instance from npm
158
+ var sigintRan = false;
159
+
157
160
  function registerCleanup(tunnel, socket) {
158
161
  process.on("SIGINT", function () {
162
+ if (sigintRan) return;
163
+ sigintRan = true;
164
+
159
165
  if (process.listenerCount("SIGINT") > 1) {
160
166
  // user has registered a handler, abort this one
161
167
  return;
162
168
  }
163
169
  // close tunnel
164
170
  if (tunnel) {
165
- tunnel.close().then(() => {
166
- console.debug("ngrok closed tunnel: " + tunnel.id());
171
+ tunnel.close().catch((err) => {
172
+ console.error(`Error closing tunnel: ${err}`);
167
173
  });
168
174
  }
169
175
  // close webserver's socket
170
- if (socket) {
171
- socket.close(function () {
172
- console.debug("ngrok closed socket");
173
- });
174
- }
176
+ if (socket) socket.close();
175
177
  // unregister any logging callback
176
178
  loggingCallback();
177
179
  });