@ngrok/ngrok 0.2.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 +10 -0
- package/Cargo.toml +1 -1
- package/README.md +17 -10
- package/docs/assets/highlight.css +13 -6
- package/docs/assets/main.js +3 -3
- package/docs/assets/search.js +1 -1
- package/docs/assets/style.css +450 -362
- package/docs/classes/NgrokHttpTunnelBuilder.html +232 -199
- package/docs/classes/NgrokLabeledTunnelBuilder.html +81 -49
- package/docs/classes/NgrokSession.html +96 -66
- package/docs/classes/NgrokSessionBuilder.html +168 -138
- package/docs/classes/NgrokTcpTunnelBuilder.html +112 -80
- package/docs/classes/NgrokTlsTunnelBuilder.html +130 -98
- package/docs/classes/NgrokTunnel.html +233 -0
- package/docs/classes/UpdateRequest.html +66 -33
- package/docs/functions/authtoken.html +85 -0
- package/docs/functions/connect.html +85 -0
- package/docs/functions/consoleLog.html +47 -34
- package/docs/functions/disconnect.html +85 -0
- package/docs/functions/kill.html +80 -0
- package/docs/functions/listen.html +51 -37
- package/docs/functions/listenable.html +49 -40
- package/docs/functions/loggingCallback.html +53 -40
- package/docs/index.html +91 -101
- package/docs/interfaces/Config.html +605 -0
- package/docs/modules.html +67 -46
- package/examples/ngrok-connect-full.js +64 -0
- package/examples/ngrok-connect-minimal.js +16 -0
- package/examples/ngrok-http-full.js +9 -11
- package/examples/ngrok-http-minimum.js +8 -12
- package/examples/ngrok-labeled.js +5 -5
- package/examples/ngrok-listen.js +2 -2
- package/examples/ngrok-tcp.js +5 -6
- package/examples/ngrok-tls.js +5 -5
- package/examples/ngrok-typescript.ts +3 -3
- package/examples/ngrok-windows-pipe.js +1 -1
- package/examples/ngrok-winston.js +2 -2
- package/index.d.ts +233 -124
- package/index.js +119 -7
- package/package.json +17 -16
- package/src/config.rs +182 -0
- package/src/connect.rs +328 -0
- package/src/http.rs +5 -4
- package/src/lib.rs +2 -0
- package/src/session.rs +59 -4
- package/src/tls.rs +1 -1
- package/src/tunnel.rs +210 -136
- package/src/tunnel_builder.rs +11 -2
- package/trailer.d.ts +11 -7
- package/trailer.js +113 -2
- package/typedoc.json +3 -0
- package/docs/classes/NgrokHttpTunnel.html +0 -191
- package/docs/classes/NgrokLabeledTunnel.html +0 -179
- package/docs/classes/NgrokTcpTunnel.html +0 -191
- package/docs/classes/NgrokTlsTunnel.html +0 -191
package/index.d.ts
CHANGED
|
@@ -3,13 +3,190 @@
|
|
|
3
3
|
|
|
4
4
|
/* auto-generated by NAPI-RS */
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Configuration object to pass to ngrok.connect()
|
|
8
|
+
*
|
|
9
|
+
* @group Functions
|
|
10
|
+
*/
|
|
11
|
+
export interface Config {
|
|
12
|
+
/**
|
|
13
|
+
* Port, network address, or named pipe. Defaults to 80.
|
|
14
|
+
* Examples: "80", "localhost:8080", "pipe:/tmp/my.sock"
|
|
15
|
+
*/
|
|
16
|
+
addr?: number|string
|
|
17
|
+
auth?: string|Array<string>
|
|
18
|
+
/**
|
|
19
|
+
* Configures the session to authenticate with the provided authtoken. You
|
|
20
|
+
* can [find your existing authtoken] or [create a new one] in the ngrok
|
|
21
|
+
* dashboard.
|
|
22
|
+
*
|
|
23
|
+
* See the [authtoken parameter in the ngrok docs] for additional details.
|
|
24
|
+
*
|
|
25
|
+
* [find your existing authtoken]: https://dashboard.ngrok.com/get-started/your-authtoken
|
|
26
|
+
* [create a new one]: https://dashboard.ngrok.com/tunnels/authtokens
|
|
27
|
+
* [authtoken parameter in the ngrok docs]: https://ngrok.com/docs/ngrok-agent/config#authtoken
|
|
28
|
+
*/
|
|
29
|
+
authtoken?: string
|
|
30
|
+
/**
|
|
31
|
+
* Shortcut for calling [SessionBuilder::authtoken] with the value of the
|
|
32
|
+
* NGROK_AUTHTOKEN environment variable.
|
|
33
|
+
*/
|
|
34
|
+
authtoken_from_env?: boolean
|
|
35
|
+
/** Credentials for basic authentication, with username and password colon separated. */
|
|
36
|
+
basic_auth?: string|Array<string>
|
|
37
|
+
/** Unused, will warn and be ignored */
|
|
38
|
+
binPath?: string
|
|
39
|
+
/**
|
|
40
|
+
* Reject requests when 5XX responses exceed this ratio.
|
|
41
|
+
* Disabled when 0.
|
|
42
|
+
*/
|
|
43
|
+
circuit_breaker?: number
|
|
44
|
+
/** Enable gzip compression for HTTP responses. */
|
|
45
|
+
compression?: boolean
|
|
46
|
+
/** Unused, will warn and be ignored */
|
|
47
|
+
configPath?: string
|
|
48
|
+
/**
|
|
49
|
+
* The certificate to use for TLS termination at the ngrok edge in PEM format.
|
|
50
|
+
* Only used if "proto" is "tls".
|
|
51
|
+
*/
|
|
52
|
+
crt?: string
|
|
53
|
+
/** The domain to request for this edge. */
|
|
54
|
+
domain?: string
|
|
55
|
+
/**
|
|
56
|
+
* Returns a human-readable string presented in the ngrok dashboard
|
|
57
|
+
* and the Tunnels API.
|
|
58
|
+
*/
|
|
59
|
+
forwards_to?: string
|
|
60
|
+
/** Unused, will warn and be ignored */
|
|
61
|
+
host_header?: string
|
|
62
|
+
/**
|
|
63
|
+
* The hostname for the tunnel to forward to.
|
|
64
|
+
* Only used if addr is not defined.
|
|
65
|
+
*/
|
|
66
|
+
host?: string
|
|
67
|
+
/** Synonym for domain */
|
|
68
|
+
hostname?: string
|
|
69
|
+
/** Unused, will warn and be ignored */
|
|
70
|
+
inspect?: string
|
|
71
|
+
/** Restriction placed on the origin of incoming connections to the edge to only allow these CIDR ranges. */
|
|
72
|
+
ip_restriction_allow_cidrs?: string|Array<string>
|
|
73
|
+
/** Restriction placed on the origin of incoming connections to the edge to deny these CIDR ranges. */
|
|
74
|
+
ip_restriction_deny_cidrs?: string|Array<string>
|
|
75
|
+
/**
|
|
76
|
+
* The certificate to use for TLS termination at the ngrok edge in PEM format.
|
|
77
|
+
* Only used if "proto" is "tls".
|
|
78
|
+
*/
|
|
79
|
+
key?: string
|
|
80
|
+
/** Add label, value pairs for this tunnel, colon separated. */
|
|
81
|
+
labels?: string|Array<string>
|
|
82
|
+
/** Tunnel-specific opaque metadata. Viewable via the API. */
|
|
83
|
+
metadata?: string
|
|
84
|
+
/**
|
|
85
|
+
* Certificates to use for client authentication at the ngrok edge.
|
|
86
|
+
* Only used if "proto" is "tls" or "http".
|
|
87
|
+
*/
|
|
88
|
+
mutual_tls_cas?: string|Array<string>
|
|
89
|
+
/** Unused, will warn and be ignored */
|
|
90
|
+
name?: string
|
|
91
|
+
/** OAuth configuration of domains to allow. */
|
|
92
|
+
oauth_allow_domains?: string|Array<string>
|
|
93
|
+
/** OAuth configuration of email addresses to allow. */
|
|
94
|
+
oauth_allow_emails?: string|Array<string>
|
|
95
|
+
/** OAuth configuration of scopes. */
|
|
96
|
+
oauth_scopes?: string|Array<string>
|
|
97
|
+
/**
|
|
98
|
+
* OAuth configuration of the provider, e.g. "google".
|
|
99
|
+
* https://ngrok.com/docs/cloud-edge/modules/oauth/
|
|
100
|
+
*/
|
|
101
|
+
oauth_provider?: string
|
|
102
|
+
/** OIDC configuration of client ID. */
|
|
103
|
+
oidc_client_id?: string
|
|
104
|
+
/** OIDC configuration of client secret. */
|
|
105
|
+
oidc_client_secret?: string
|
|
106
|
+
/** OIDC configuration of scopes. */
|
|
107
|
+
oidc_scopes?: string|Array<string>
|
|
108
|
+
/** OIDC configuration of the issuer URL. */
|
|
109
|
+
oidc_issuer_url?: string
|
|
110
|
+
/** OIDC configuration of domains to allow. */
|
|
111
|
+
oidc_allow_domains?: string|Array<string>
|
|
112
|
+
/** OIDC configuration of email addresses to allow. */
|
|
113
|
+
oidc_allow_emails?: string|Array<string>
|
|
114
|
+
/** Returns log messages from the ngrok library. */
|
|
115
|
+
onLogEvent?: (data: string) => void
|
|
116
|
+
/** 'closed' - connection is lost, 'connected' - reconnected */
|
|
117
|
+
onStatusChange?: (status: string) => void
|
|
118
|
+
/**
|
|
119
|
+
* The port for the tunnel to forward to.
|
|
120
|
+
* Only used if addr is not defined.
|
|
121
|
+
*/
|
|
122
|
+
port?: number
|
|
123
|
+
/** The type of tunnel to use, one of http|tcp|tls|labeled, defaults to http. */
|
|
124
|
+
proto?: string
|
|
125
|
+
/** The version of PROXY protocol to use with this tunnel "1", "2", or "" if not using. */
|
|
126
|
+
proxy_proto?: string
|
|
127
|
+
/** Adds a header to all requests to this edge. */
|
|
128
|
+
request_header_add?: string|Array<string>
|
|
129
|
+
/** Removes a header from requests to this edge. */
|
|
130
|
+
request_header_remove?: string|Array<string>
|
|
131
|
+
/** Adds a header to all responses coming from this edge. */
|
|
132
|
+
response_header_add?: string|Array<string>
|
|
133
|
+
/** Removes a header from responses from this edge. */
|
|
134
|
+
response_header_remove?: string|Array<string>
|
|
135
|
+
/** Unused, will warn and be ignored */
|
|
136
|
+
region?: string
|
|
137
|
+
/**
|
|
138
|
+
* The TCP address to request for this edge.
|
|
139
|
+
* Only used if proto is "tcp".
|
|
140
|
+
*/
|
|
141
|
+
remote_addr?: string
|
|
142
|
+
/**
|
|
143
|
+
* The scheme that this edge should use, defaults to "https".
|
|
144
|
+
* If multiple are given only the last one is used.
|
|
145
|
+
*/
|
|
146
|
+
schemes?: string|Array<string>
|
|
147
|
+
/**
|
|
148
|
+
* Configures the opaque, machine-readable metadata string for this session.
|
|
149
|
+
* Metadata is made available to you in the ngrok dashboard and the Agents API
|
|
150
|
+
* resource. It is a useful way to allow you to uniquely identify sessions. We
|
|
151
|
+
* suggest encoding the value in a structured format like JSON.
|
|
152
|
+
*
|
|
153
|
+
* See the [metdata parameter in the ngrok docs] for additional details.
|
|
154
|
+
*
|
|
155
|
+
* [metdata parameter in the ngrok docs]: https://ngrok.com/docs/ngrok-agent/config#metadata
|
|
156
|
+
*/
|
|
157
|
+
session_metadata?: string
|
|
158
|
+
/** Unused, use domain instead, will warn and be ignored */
|
|
159
|
+
subdomain?: string
|
|
160
|
+
/** Unused, will warn and be ignored */
|
|
161
|
+
terminate_at?: string
|
|
162
|
+
/** WebhookVerification configuration, the provider to use. */
|
|
163
|
+
verify_webhook_provider?: string
|
|
164
|
+
/** WebhookVerification configuration, the secret to use. */
|
|
165
|
+
verify_webhook_secret?: string
|
|
166
|
+
/** Unused, will warn and be ignored */
|
|
167
|
+
web_addr?: string
|
|
168
|
+
/** Convert incoming websocket connections to TCP-like streams. */
|
|
169
|
+
websocket_tcp_converter?: boolean
|
|
170
|
+
}
|
|
171
|
+
/** Transform a json object configuration into a tunnel */
|
|
172
|
+
export function connect(config: Config|string|number): Promise<string>
|
|
173
|
+
/** Close a tunnel with the given url, or all tunnels if no url is defined. */
|
|
174
|
+
export function disconnect(url?: string | undefined | null): Promise<void>
|
|
175
|
+
/** Close all tunnels. */
|
|
176
|
+
export function kill(): Promise<void>
|
|
6
177
|
/**
|
|
7
178
|
* Register a callback function that will receive logging event information.
|
|
8
179
|
* An absent callback will unregister an existing callback function.
|
|
9
180
|
* The log level defaults to INFO, it can be set to one of ERROR, WARN, INFO, DEBUG, or TRACE.
|
|
10
181
|
*/
|
|
11
182
|
export function loggingCallback(callback?: (level: string, target: string, message: string) => void, level?: string): void
|
|
12
|
-
/**
|
|
183
|
+
/** Set the default auth token to use for any future sessions. */
|
|
184
|
+
export function authtoken(authtoken: string): Promise<void>
|
|
185
|
+
/**
|
|
186
|
+
* The builder for an ngrok session.
|
|
187
|
+
*
|
|
188
|
+
* @group Tunnel and Sessions
|
|
189
|
+
*/
|
|
13
190
|
export class NgrokSessionBuilder {
|
|
14
191
|
/** Create a new session builder */
|
|
15
192
|
constructor()
|
|
@@ -143,7 +320,11 @@ export class NgrokSessionBuilder {
|
|
|
143
320
|
/** Attempt to establish an ngrok session using the current configuration. */
|
|
144
321
|
connect(): Promise<NgrokSession>
|
|
145
322
|
}
|
|
146
|
-
/**
|
|
323
|
+
/**
|
|
324
|
+
* An ngrok session.
|
|
325
|
+
*
|
|
326
|
+
* @group Tunnel and Sessions
|
|
327
|
+
*/
|
|
147
328
|
export class NgrokSession {
|
|
148
329
|
/** Start building a tunnel backing an HTTP endpoint. */
|
|
149
330
|
httpEndpoint(): NgrokHttpTunnelBuilder
|
|
@@ -158,116 +339,23 @@ export class NgrokSession {
|
|
|
158
339
|
/** Close the ngrok session. */
|
|
159
340
|
close(): Promise<void>
|
|
160
341
|
}
|
|
342
|
+
/** Container for UpdateRequest information. */
|
|
161
343
|
export class UpdateRequest {
|
|
162
344
|
/** The version that the agent is requested to update to. */
|
|
163
345
|
version: string
|
|
164
346
|
/** Whether or not updating to the same major version is sufficient. */
|
|
165
347
|
permitMajorVersion: boolean
|
|
166
348
|
}
|
|
167
|
-
/**
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
/** Returns a tunnel's unique ID. */
|
|
174
|
-
id(): string
|
|
175
|
-
/**
|
|
176
|
-
* Returns a human-readable string presented in the ngrok dashboard
|
|
177
|
-
* and the Tunnels API. Use the [HttpTunnelBuilder::forwards_to],
|
|
178
|
-
* [TcpTunnelBuilder::forwards_to], etc. to set this value
|
|
179
|
-
* explicitly.
|
|
180
|
-
*/
|
|
181
|
-
forwardsTo(): string
|
|
182
|
-
/** Returns the arbitrary metadata string for this tunnel. */
|
|
183
|
-
metadata(): string
|
|
184
|
-
/** Forward incoming tunnel connections to the provided TCP address. */
|
|
185
|
-
forwardTcp(addr: string): Promise<void>
|
|
186
|
-
/**
|
|
187
|
-
* Forward incoming tunnel connections to the provided file socket path.
|
|
188
|
-
* On Linux/Darwin addr can be a unix domain socket path, e.g. "/tmp/ngrok.sock"
|
|
189
|
-
* On Windows addr can be a named pipe, e.e. "\\.\pipe\an_ngrok_pipe"
|
|
190
|
-
*/
|
|
191
|
-
forwardPipe(addr: string): Promise<void>
|
|
192
|
-
/**
|
|
193
|
-
* Close the tunnel.
|
|
194
|
-
*
|
|
195
|
-
* This is an RPC call that must be `.await`ed.
|
|
196
|
-
* It is equivalent to calling `Session::close_tunnel` with this
|
|
197
|
-
* tunnel's ID.
|
|
198
|
-
*/
|
|
199
|
-
close(): Promise<void>
|
|
200
|
-
}
|
|
201
|
-
/**r" An ngrok tunnel backing a TCP endpoint. */
|
|
202
|
-
export class NgrokTcpTunnel {
|
|
203
|
-
/** The URL that this tunnel backs. */
|
|
204
|
-
url(): string
|
|
205
|
-
/** The protocol of the endpoint that this tunnel backs. */
|
|
206
|
-
proto(): string
|
|
207
|
-
/** Returns a tunnel's unique ID. */
|
|
208
|
-
id(): string
|
|
209
|
-
/**
|
|
210
|
-
* Returns a human-readable string presented in the ngrok dashboard
|
|
211
|
-
* and the Tunnels API. Use the [HttpTunnelBuilder::forwards_to],
|
|
212
|
-
* [TcpTunnelBuilder::forwards_to], etc. to set this value
|
|
213
|
-
* explicitly.
|
|
214
|
-
*/
|
|
215
|
-
forwardsTo(): string
|
|
216
|
-
/** Returns the arbitrary metadata string for this tunnel. */
|
|
217
|
-
metadata(): string
|
|
218
|
-
/** Forward incoming tunnel connections to the provided TCP address. */
|
|
219
|
-
forwardTcp(addr: string): Promise<void>
|
|
220
|
-
/**
|
|
221
|
-
* Forward incoming tunnel connections to the provided file socket path.
|
|
222
|
-
* On Linux/Darwin addr can be a unix domain socket path, e.g. "/tmp/ngrok.sock"
|
|
223
|
-
* On Windows addr can be a named pipe, e.e. "\\.\pipe\an_ngrok_pipe"
|
|
224
|
-
*/
|
|
225
|
-
forwardPipe(addr: string): Promise<void>
|
|
226
|
-
/**
|
|
227
|
-
* Close the tunnel.
|
|
228
|
-
*
|
|
229
|
-
* This is an RPC call that must be `.await`ed.
|
|
230
|
-
* It is equivalent to calling `Session::close_tunnel` with this
|
|
231
|
-
* tunnel's ID.
|
|
232
|
-
*/
|
|
233
|
-
close(): Promise<void>
|
|
234
|
-
}
|
|
235
|
-
/**r" An ngrok tunnel bcking a TLS endpoint. */
|
|
236
|
-
export class NgrokTlsTunnel {
|
|
349
|
+
/**
|
|
350
|
+
* An ngrok tunnel.
|
|
351
|
+
*
|
|
352
|
+
* @group Tunnel and Sessions
|
|
353
|
+
*/
|
|
354
|
+
export class NgrokTunnel {
|
|
237
355
|
/** The URL that this tunnel backs. */
|
|
238
|
-
url(): string
|
|
356
|
+
url(): string | null
|
|
239
357
|
/** The protocol of the endpoint that this tunnel backs. */
|
|
240
|
-
proto(): string
|
|
241
|
-
/** Returns a tunnel's unique ID. */
|
|
242
|
-
id(): string
|
|
243
|
-
/**
|
|
244
|
-
* Returns a human-readable string presented in the ngrok dashboard
|
|
245
|
-
* and the Tunnels API. Use the [HttpTunnelBuilder::forwards_to],
|
|
246
|
-
* [TcpTunnelBuilder::forwards_to], etc. to set this value
|
|
247
|
-
* explicitly.
|
|
248
|
-
*/
|
|
249
|
-
forwardsTo(): string
|
|
250
|
-
/** Returns the arbitrary metadata string for this tunnel. */
|
|
251
|
-
metadata(): string
|
|
252
|
-
/** Forward incoming tunnel connections to the provided TCP address. */
|
|
253
|
-
forwardTcp(addr: string): Promise<void>
|
|
254
|
-
/**
|
|
255
|
-
* Forward incoming tunnel connections to the provided file socket path.
|
|
256
|
-
* On Linux/Darwin addr can be a unix domain socket path, e.g. "/tmp/ngrok.sock"
|
|
257
|
-
* On Windows addr can be a named pipe, e.e. "\\.\pipe\an_ngrok_pipe"
|
|
258
|
-
*/
|
|
259
|
-
forwardPipe(addr: string): Promise<void>
|
|
260
|
-
/**
|
|
261
|
-
* Close the tunnel.
|
|
262
|
-
*
|
|
263
|
-
* This is an RPC call that must be `.await`ed.
|
|
264
|
-
* It is equivalent to calling `Session::close_tunnel` with this
|
|
265
|
-
* tunnel's ID.
|
|
266
|
-
*/
|
|
267
|
-
close(): Promise<void>
|
|
268
|
-
}
|
|
269
|
-
/**r" A labeled ngrok tunnel. */
|
|
270
|
-
export class NgrokLabeledTunnel {
|
|
358
|
+
proto(): string | null
|
|
271
359
|
/** The labels this tunnel was started with. */
|
|
272
360
|
labels(): Record<string, string>
|
|
273
361
|
/** Returns a tunnel's unique ID. */
|
|
@@ -298,7 +386,11 @@ export class NgrokLabeledTunnel {
|
|
|
298
386
|
*/
|
|
299
387
|
close(): Promise<void>
|
|
300
388
|
}
|
|
301
|
-
/**
|
|
389
|
+
/**
|
|
390
|
+
*r" An ngrok tunnel backing an HTTP endpoint.
|
|
391
|
+
*r"
|
|
392
|
+
*r" @group Tunnel Builders
|
|
393
|
+
*/
|
|
302
394
|
export class NgrokHttpTunnelBuilder {
|
|
303
395
|
/**
|
|
304
396
|
* The scheme that this edge should use.
|
|
@@ -318,13 +410,13 @@ export class NgrokHttpTunnelBuilder {
|
|
|
318
410
|
* Disabled when 0.
|
|
319
411
|
*/
|
|
320
412
|
circuitBreaker(circuitBreaker: number): this
|
|
321
|
-
/**
|
|
413
|
+
/** request_header adds a header to all requests to this edge. */
|
|
322
414
|
requestHeader(name: string, value: string): this
|
|
323
|
-
/**
|
|
415
|
+
/** response_header adds a header to all responses coming from this edge. */
|
|
324
416
|
responseHeader(name: string, value: string): this
|
|
325
|
-
/**
|
|
417
|
+
/** remove_request_header removes a header from requests to this edge. */
|
|
326
418
|
removeRequestHeader(name: string): this
|
|
327
|
-
/**
|
|
419
|
+
/** remove_response_header removes a header from responses from this edge. */
|
|
328
420
|
removeResponseHeader(name: string): this
|
|
329
421
|
/**
|
|
330
422
|
* Credentials for basic authentication.
|
|
@@ -334,6 +426,7 @@ export class NgrokHttpTunnelBuilder {
|
|
|
334
426
|
/**
|
|
335
427
|
* OAuth configuration.
|
|
336
428
|
* If not called, OAuth is disabled.
|
|
429
|
+
* https://ngrok.com/docs/cloud-edge/modules/oauth/
|
|
337
430
|
*/
|
|
338
431
|
oauth(provider: string, allowEmails?: Array<string> | undefined | null, allowDomains?: Array<string> | undefined | null, scopes?: Array<string> | undefined | null): this
|
|
339
432
|
/**
|
|
@@ -349,7 +442,7 @@ export class NgrokHttpTunnelBuilder {
|
|
|
349
442
|
/** Tunnel-specific opaque metadata. Viewable via the API. */
|
|
350
443
|
metadata(metadata: string): this
|
|
351
444
|
/** Begin listening for new connections on this tunnel. */
|
|
352
|
-
listen(bind?: boolean | undefined | null): Promise<
|
|
445
|
+
listen(bind?: boolean | undefined | null): Promise<NgrokTunnel>
|
|
353
446
|
/**
|
|
354
447
|
* Restriction placed on the origin of incoming connections to the edge to only allow these CIDR ranges.
|
|
355
448
|
* Call multiple times to add additional CIDR ranges.
|
|
@@ -368,14 +461,18 @@ export class NgrokHttpTunnelBuilder {
|
|
|
368
461
|
*/
|
|
369
462
|
forwardsTo(forwardsTo: string): this
|
|
370
463
|
}
|
|
371
|
-
/**
|
|
464
|
+
/**
|
|
465
|
+
*r" An ngrok tunnel backing a TCP endpoint.
|
|
466
|
+
*r"
|
|
467
|
+
*r" @group Tunnel Builders
|
|
468
|
+
*/
|
|
372
469
|
export class NgrokTcpTunnelBuilder {
|
|
373
470
|
/** The TCP address to request for this edge. */
|
|
374
471
|
remoteAddr(remoteAddr: string): this
|
|
375
472
|
/** Tunnel-specific opaque metadata. Viewable via the API. */
|
|
376
473
|
metadata(metadata: string): this
|
|
377
474
|
/** Begin listening for new connections on this tunnel. */
|
|
378
|
-
listen(bind?: boolean | undefined | null): Promise<
|
|
475
|
+
listen(bind?: boolean | undefined | null): Promise<NgrokTunnel>
|
|
379
476
|
/**
|
|
380
477
|
* Restriction placed on the origin of incoming connections to the edge to only allow these CIDR ranges.
|
|
381
478
|
* Call multiple times to add additional CIDR ranges.
|
|
@@ -394,18 +491,22 @@ export class NgrokTcpTunnelBuilder {
|
|
|
394
491
|
*/
|
|
395
492
|
forwardsTo(forwardsTo: string): this
|
|
396
493
|
}
|
|
397
|
-
/**
|
|
494
|
+
/**
|
|
495
|
+
*r" An ngrok tunnel backing a TLS endpoint.
|
|
496
|
+
*r"
|
|
497
|
+
*r" @group Tunnel Builders
|
|
498
|
+
*/
|
|
398
499
|
export class NgrokTlsTunnelBuilder {
|
|
399
500
|
/** The domain to request for this edge. */
|
|
400
501
|
domain(domain: string): this
|
|
401
502
|
/** Certificates to use for client authentication at the ngrok edge. */
|
|
402
503
|
mutualTlsca(mutualTlsca: Uint8Array): this
|
|
403
|
-
/** The key to use for TLS termination at the ngrok edge in PEM format. */
|
|
504
|
+
/** The certificate and key to use for TLS termination at the ngrok edge in PEM format. */
|
|
404
505
|
termination(certPem: Uint8Array, keyPem: Uint8Array): this
|
|
405
506
|
/** Tunnel-specific opaque metadata. Viewable via the API. */
|
|
406
507
|
metadata(metadata: string): this
|
|
407
508
|
/** Begin listening for new connections on this tunnel. */
|
|
408
|
-
listen(bind?: boolean | undefined | null): Promise<
|
|
509
|
+
listen(bind?: boolean | undefined | null): Promise<NgrokTunnel>
|
|
409
510
|
/**
|
|
410
511
|
* Restriction placed on the origin of incoming connections to the edge to only allow these CIDR ranges.
|
|
411
512
|
* Call multiple times to add additional CIDR ranges.
|
|
@@ -424,24 +525,32 @@ export class NgrokTlsTunnelBuilder {
|
|
|
424
525
|
*/
|
|
425
526
|
forwardsTo(forwardsTo: string): this
|
|
426
527
|
}
|
|
427
|
-
/**
|
|
528
|
+
/**
|
|
529
|
+
*r" A labeled ngrok tunnel.
|
|
530
|
+
*r"
|
|
531
|
+
*r" @group Tunnel Builders
|
|
532
|
+
*/
|
|
428
533
|
export class NgrokLabeledTunnelBuilder {
|
|
429
534
|
/** Tunnel-specific opaque metadata. Viewable via the API. */
|
|
430
535
|
metadata(metadata: string): this
|
|
431
536
|
/** Begin listening for new connections on this tunnel. */
|
|
432
|
-
listen(bind?: boolean | undefined | null): Promise<
|
|
537
|
+
listen(bind?: boolean | undefined | null): Promise<NgrokTunnel>
|
|
433
538
|
/** Add a label, value pair for this tunnel. */
|
|
434
539
|
label(label: string, value: string): this
|
|
435
540
|
}
|
|
436
|
-
/**
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
541
|
+
/**
|
|
542
|
+
* Get a listenable ngrok tunnel, suitable for passing to net.Server.listen().
|
|
543
|
+
* Uses the NGROK_AUTHTOKEN environment variable to authenticate.
|
|
544
|
+
*/
|
|
545
|
+
export function listenable(): NgrokTunnel;
|
|
546
|
+
/**
|
|
547
|
+
* Start the given net.Server listening to a generated, or passed in, tunnel.
|
|
548
|
+
* Uses the NGROK_AUTHTOKEN environment variable to authenticate if a new tunnel is created.
|
|
549
|
+
*/
|
|
441
550
|
export function listen(
|
|
442
551
|
server: import("net").Server,
|
|
443
|
-
tunnel?:
|
|
444
|
-
):
|
|
552
|
+
tunnel?: NgrokTunnel
|
|
553
|
+
): NgrokTunnel;
|
|
445
554
|
/**
|
|
446
555
|
* Register a console.log callback for ngrok INFO logging.
|
|
447
556
|
* Optionally set the logging level to one of ERROR, WARN, INFO, DEBUG, or TRACE.
|
package/index.js
CHANGED
|
@@ -252,16 +252,17 @@ if (!nativeBinding) {
|
|
|
252
252
|
throw new Error(`Failed to load native binding`)
|
|
253
253
|
}
|
|
254
254
|
|
|
255
|
-
const {
|
|
255
|
+
const { connect, disconnect, kill, loggingCallback, authtoken, NgrokSessionBuilder, NgrokSession, UpdateRequest, NgrokTunnel, NgrokHttpTunnelBuilder, NgrokTcpTunnelBuilder, NgrokTlsTunnelBuilder, NgrokLabeledTunnelBuilder } = nativeBinding
|
|
256
256
|
|
|
257
|
+
module.exports.connect = connect
|
|
258
|
+
module.exports.disconnect = disconnect
|
|
259
|
+
module.exports.kill = kill
|
|
257
260
|
module.exports.loggingCallback = loggingCallback
|
|
261
|
+
module.exports.authtoken = authtoken
|
|
258
262
|
module.exports.NgrokSessionBuilder = NgrokSessionBuilder
|
|
259
263
|
module.exports.NgrokSession = NgrokSession
|
|
260
264
|
module.exports.UpdateRequest = UpdateRequest
|
|
261
|
-
module.exports.
|
|
262
|
-
module.exports.NgrokTcpTunnel = NgrokTcpTunnel
|
|
263
|
-
module.exports.NgrokTlsTunnel = NgrokTlsTunnel
|
|
264
|
-
module.exports.NgrokLabeledTunnel = NgrokLabeledTunnel
|
|
265
|
+
module.exports.NgrokTunnel = NgrokTunnel
|
|
265
266
|
module.exports.NgrokHttpTunnelBuilder = NgrokHttpTunnelBuilder
|
|
266
267
|
module.exports.NgrokTcpTunnelBuilder = NgrokTcpTunnelBuilder
|
|
267
268
|
module.exports.NgrokTlsTunnelBuilder = NgrokTlsTunnelBuilder
|
|
@@ -451,6 +452,117 @@ function consoleLog(level) {
|
|
|
451
452
|
}, level);
|
|
452
453
|
}
|
|
453
454
|
|
|
454
|
-
|
|
455
|
-
|
|
455
|
+
// wrap connect with code to vectorize and split out functions
|
|
456
|
+
const _connect = connect;
|
|
457
|
+
async function ngrokConnect(config) {
|
|
458
|
+
if (Number.isInteger(config) || typeof config === "string" || config instanceof String) {
|
|
459
|
+
address = String(config);
|
|
460
|
+
if (!address.includes(":")) {
|
|
461
|
+
address = `localhost:${address}`;
|
|
462
|
+
}
|
|
463
|
+
config = { addr: address };
|
|
464
|
+
}
|
|
465
|
+
// Convert addr to string to allow for numeric port numbers
|
|
466
|
+
const addr = config["addr"];
|
|
467
|
+
if (Number.isInteger(addr)) config["addr"] = "localhost:" + String(config["addr"]);
|
|
468
|
+
// convert scalar values to arrays to meet what napi-rs expects
|
|
469
|
+
[
|
|
470
|
+
"auth",
|
|
471
|
+
"basic_auth",
|
|
472
|
+
"ip_restriction.allow_cidrs",
|
|
473
|
+
"ip_restriction.deny_cidrs",
|
|
474
|
+
"labels",
|
|
475
|
+
"oauth.allow_domains",
|
|
476
|
+
"oauth.allow_emails",
|
|
477
|
+
"oauth.scopes",
|
|
478
|
+
"oidc.scopes",
|
|
479
|
+
"oidc.allow_domains",
|
|
480
|
+
"oidc.allow_emails",
|
|
481
|
+
"request_header.add",
|
|
482
|
+
"request_header.remove",
|
|
483
|
+
"response_header.add",
|
|
484
|
+
"response_header.remove",
|
|
485
|
+
"schemes",
|
|
486
|
+
].forEach((key) => {
|
|
487
|
+
vectorize(config, key);
|
|
488
|
+
});
|
|
489
|
+
// convert dotted values to underscores for backwards compatibility
|
|
490
|
+
[
|
|
491
|
+
"ip_restriction.allow_cidrs",
|
|
492
|
+
"ip_restriction.deny_cidrs",
|
|
493
|
+
"oauth.allow_domains",
|
|
494
|
+
"oauth.allow_emails",
|
|
495
|
+
"oauth.scopes",
|
|
496
|
+
"oauth.provider",
|
|
497
|
+
"oidc.client_id",
|
|
498
|
+
"oidc.client_secret",
|
|
499
|
+
"oidc.scopes",
|
|
500
|
+
"oidc.issuer_url",
|
|
501
|
+
"oidc.allow_domains",
|
|
502
|
+
"oidc.allow_emails",
|
|
503
|
+
"request_header.add",
|
|
504
|
+
"request_header.remove",
|
|
505
|
+
"response_header.add",
|
|
506
|
+
"response_header.remove",
|
|
507
|
+
"verify_webhook.provider",
|
|
508
|
+
"verify_webhook.secret",
|
|
509
|
+
].forEach((key) => {
|
|
510
|
+
undot(config, key);
|
|
511
|
+
});
|
|
512
|
+
// break out the logging callback function to meet what napi-rs expects
|
|
513
|
+
var on_log_event;
|
|
514
|
+
if (config["onLogEvent"]) {
|
|
515
|
+
const onLogEvent = config.onLogEvent;
|
|
516
|
+
on_log_event = (level, target, message) => {
|
|
517
|
+
onLogEvent(`${level} ${target} - ${message}`);
|
|
518
|
+
};
|
|
519
|
+
config["onLogEvent"] = true;
|
|
520
|
+
}
|
|
521
|
+
// break out the status change callback functions to what napi-rs expects
|
|
522
|
+
var on_connection, on_disconnection;
|
|
523
|
+
if (config["onStatusChange"]) {
|
|
524
|
+
const onStatusChange = config.onStatusChange;
|
|
525
|
+
on_connection = (status, err) => {
|
|
526
|
+
onStatusChange(status);
|
|
527
|
+
};
|
|
528
|
+
on_disconnection = (addr, err) => {
|
|
529
|
+
onStatusChange("closed");
|
|
530
|
+
};
|
|
531
|
+
config["onStatusChange"] = true;
|
|
532
|
+
}
|
|
533
|
+
// call into rust
|
|
534
|
+
return await _connect(config, on_log_event, on_connection, on_disconnection);
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
function undot(config, dotKey) {
|
|
538
|
+
const noDotKey = dotKey.replace(".", "_");
|
|
539
|
+
if (config[dotKey] == null) return; // no dotKey value, done
|
|
540
|
+
if (config[noDotKey] == null) {
|
|
541
|
+
// nothing at destination, just set and be done
|
|
542
|
+
config[noDotKey] = config[dotKey];
|
|
543
|
+
return;
|
|
544
|
+
}
|
|
545
|
+
if (config[dotKey] instanceof Array && config[noDotKey] instanceof Array) {
|
|
546
|
+
// merge arrays
|
|
547
|
+
for (const obj of config[dotKey]) {
|
|
548
|
+
config[noDotKey].push(obj);
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
// destination exists and is not an array, do nothing so noDotKey can take precedence
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
function vectorize(config, key) {
|
|
555
|
+
// backwards compatible keys are passed in, check the new style as well
|
|
556
|
+
const noDotKey = key.replace(".", "_");
|
|
557
|
+
if (key != noDotKey) vectorize(config, noDotKey);
|
|
558
|
+
|
|
559
|
+
if (config[key] == null) return; // no value, done
|
|
560
|
+
if (!(config[key] instanceof Array)) {
|
|
561
|
+
config[key] = [config[key]];
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
module.exports.connect = ngrokConnect;
|
|
456
566
|
module.exports.consoleLog = consoleLog;
|
|
567
|
+
module.exports.listen = ngrokListen;
|
|
568
|
+
module.exports.listenable = listenable;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ngrok/ngrok",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"types": "index.d.ts",
|
|
6
6
|
"napi": {
|
|
@@ -27,9 +27,10 @@
|
|
|
27
27
|
"@types/node": "^18.13.0",
|
|
28
28
|
"ava": "^4.3.3",
|
|
29
29
|
"axios": "^1.3.3",
|
|
30
|
+
"axios-retry": "^3.4.0",
|
|
30
31
|
"express": "^4.18.2",
|
|
31
32
|
"prettier": "^2.8.7",
|
|
32
|
-
"typedoc": "^0.
|
|
33
|
+
"typedoc": "^0.24.7",
|
|
33
34
|
"typescript": "^4.9.5"
|
|
34
35
|
},
|
|
35
36
|
"ava": {
|
|
@@ -43,7 +44,7 @@
|
|
|
43
44
|
"build": "napi build --platform --release --js gen.js --dts gen.d.ts --pipe 'node post-build.js trailer index'",
|
|
44
45
|
"build:debug": "napi build --platform",
|
|
45
46
|
"clean": "rm -rf node_modules/ target/",
|
|
46
|
-
"docs": "mv trailer.d.ts trailer.d.hidden; mv examples .examples; npx typedoc index.d.ts; mv .examples examples; mv trailer.d.hidden trailer.d.ts",
|
|
47
|
+
"docs": "mv trailer.d.ts trailer.d.hidden; mv examples .examples; npx typedoc index.d.ts --navigation.includeGroups; mv .examples examples; mv trailer.d.hidden trailer.d.ts",
|
|
47
48
|
"prepublishOnly": "napi prepublish -t npm",
|
|
48
49
|
"prettier": "prettier --write .",
|
|
49
50
|
"test": "ava",
|
|
@@ -54,18 +55,18 @@
|
|
|
54
55
|
"description": "The ngrok agent in library form, suitable for integrating directly into your NodeJS application.",
|
|
55
56
|
"repository": "https://github.com/ngrok/ngrok-js",
|
|
56
57
|
"optionalDependencies": {
|
|
57
|
-
"@ngrok/ngrok-win32-x64-msvc": "0.
|
|
58
|
-
"@ngrok/ngrok-darwin-x64": "0.
|
|
59
|
-
"@ngrok/ngrok-linux-x64-gnu": "0.
|
|
60
|
-
"@ngrok/ngrok-darwin-arm64": "0.
|
|
61
|
-
"@ngrok/ngrok-android-arm64": "0.
|
|
62
|
-
"@ngrok/ngrok-linux-arm64-gnu": "0.
|
|
63
|
-
"@ngrok/ngrok-linux-arm64-musl": "0.
|
|
64
|
-
"@ngrok/ngrok-linux-arm-gnueabihf": "0.
|
|
65
|
-
"@ngrok/ngrok-linux-x64-musl": "0.
|
|
66
|
-
"@ngrok/ngrok-freebsd-x64": "0.
|
|
67
|
-
"@ngrok/ngrok-win32-ia32-msvc": "0.
|
|
68
|
-
"@ngrok/ngrok-android-arm-eabi": "0.
|
|
69
|
-
"@ngrok/ngrok-darwin-universal": "0.
|
|
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"
|
|
70
71
|
}
|
|
71
72
|
}
|