pinggy 0.1.8 → 0.1.9
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/dist/index.cjs +72 -36
- package/dist/index.d.cts +17 -7
- package/dist/index.d.ts +17 -7
- package/dist/index.js +72 -36
- package/dist/workers/file_serve_worker.cjs +296 -0
- package/dist/workers/file_serve_worker.d.cts +2 -0
- package/dist/workers/file_serve_worker.d.ts +2 -0
- package/dist/workers/file_serve_worker.js +262 -0
- package/package.json +2 -2
- package/src/remote_management/handler.ts +43 -17
- package/src/remote_management/remote_schema.ts +20 -4
- package/src/tunnel_manager/TunnelManager.ts +29 -20
- package/src/types.ts +12 -12
- package/tsup.config.ts +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1040,11 +1040,11 @@ var TunnelManager = class _TunnelManager {
|
|
|
1040
1040
|
if (Array.isArray(managed.additionalForwarding) && managed.additionalForwarding.length > 0) {
|
|
1041
1041
|
for (const f of managed.additionalForwarding) {
|
|
1042
1042
|
try {
|
|
1043
|
-
if (!f || typeof f.
|
|
1043
|
+
if (!f || typeof f.remoteDomain !== "string" || !f.localDomain || typeof f.localPort !== "number") {
|
|
1044
1044
|
logger.warn(`Skipping invalid additional forwarding rule: ${JSON.stringify(f)}`);
|
|
1045
1045
|
continue;
|
|
1046
1046
|
}
|
|
1047
|
-
const hostname = f.remoteDomain
|
|
1047
|
+
const hostname = f.remoteDomain;
|
|
1048
1048
|
const target = `${f.localDomain}:${f.localPort}`;
|
|
1049
1049
|
await managed.instance.tunnelRequestAdditionalForwarding(hostname, target);
|
|
1050
1050
|
logger.info("Applied additional forwarding", { tunnelId, hostname, target });
|
|
@@ -1125,7 +1125,9 @@ var TunnelManager = class _TunnelManager {
|
|
|
1125
1125
|
configid: tunnel.configid,
|
|
1126
1126
|
tunnelName: tunnel.tunnelName,
|
|
1127
1127
|
tunnelConfig: tunnel.tunnelConfig,
|
|
1128
|
-
remoteurls: !tunnel.isStopped ? await this.getTunnelUrls(tunnel.tunnelid) : []
|
|
1128
|
+
remoteurls: !tunnel.isStopped ? await this.getTunnelUrls(tunnel.tunnelid) : [],
|
|
1129
|
+
additionalForwarding: tunnel.additionalForwarding,
|
|
1130
|
+
serve: tunnel.serve
|
|
1129
1131
|
};
|
|
1130
1132
|
}));
|
|
1131
1133
|
return tunnelList;
|
|
@@ -1279,36 +1281,41 @@ var TunnelManager = class _TunnelManager {
|
|
|
1279
1281
|
if (!existingTunnel) {
|
|
1280
1282
|
throw new Error(`Tunnel with config id "${configid}" not found`);
|
|
1281
1283
|
}
|
|
1282
|
-
const
|
|
1284
|
+
const isStopped = existingTunnel.isStopped;
|
|
1283
1285
|
const currentTunnelConfig = existingTunnel.tunnelConfig;
|
|
1284
1286
|
const currentTunnelId = existingTunnel.tunnelid;
|
|
1285
1287
|
const currentTunnelConfigId = existingTunnel.configid;
|
|
1286
1288
|
const currentAdditionalForwarding = existingTunnel.additionalForwarding;
|
|
1287
1289
|
const currentTunnelName = existingTunnel.tunnelName;
|
|
1290
|
+
const currentServe = existingTunnel.serve;
|
|
1288
1291
|
try {
|
|
1289
|
-
if (
|
|
1292
|
+
if (!isStopped) {
|
|
1290
1293
|
existingTunnel.instance.stop();
|
|
1291
1294
|
}
|
|
1292
1295
|
this.tunnelsByTunnelId.delete(currentTunnelId);
|
|
1293
1296
|
this.tunnelsByConfigId.delete(currentTunnelConfigId);
|
|
1294
1297
|
const mergedConfig = {
|
|
1295
|
-
...currentTunnelConfig,
|
|
1296
1298
|
...newConfig,
|
|
1297
1299
|
configid,
|
|
1298
1300
|
tunnelName: newTunnelName !== void 0 ? newTunnelName : currentTunnelName,
|
|
1299
|
-
additionalForwarding: additionalForwarding !== void 0 ? additionalForwarding : currentAdditionalForwarding
|
|
1301
|
+
additionalForwarding: additionalForwarding !== void 0 ? additionalForwarding : currentAdditionalForwarding,
|
|
1302
|
+
serve: newConfig.serve !== void 0 ? newConfig.serve : currentServe
|
|
1300
1303
|
};
|
|
1301
1304
|
const newTunnel = await this.createTunnel(mergedConfig);
|
|
1302
|
-
if (
|
|
1305
|
+
if (!isStopped) {
|
|
1303
1306
|
this.startTunnel(newTunnel.tunnelid);
|
|
1304
1307
|
}
|
|
1305
1308
|
logger.info("Tunnel configuration updated", {
|
|
1306
1309
|
tunnelId: newTunnel.tunnelid,
|
|
1307
1310
|
configId: newTunnel.configid,
|
|
1308
|
-
|
|
1311
|
+
isStopped
|
|
1309
1312
|
});
|
|
1310
1313
|
return newTunnel;
|
|
1311
1314
|
} catch (error) {
|
|
1315
|
+
logger.error("Error updating tunnel configuration", {
|
|
1316
|
+
configId: configid,
|
|
1317
|
+
error: error instanceof Error ? error.message : String(error)
|
|
1318
|
+
});
|
|
1312
1319
|
try {
|
|
1313
1320
|
const originalTunnel = await this.createTunnel({
|
|
1314
1321
|
...currentTunnelConfig,
|
|
@@ -1317,7 +1324,7 @@ var TunnelManager = class _TunnelManager {
|
|
|
1317
1324
|
tunnelName: currentTunnelName,
|
|
1318
1325
|
additionalForwarding: currentAdditionalForwarding
|
|
1319
1326
|
});
|
|
1320
|
-
if (
|
|
1327
|
+
if (!isStopped) {
|
|
1321
1328
|
await this.startTunnel(originalTunnel.tunnelid);
|
|
1322
1329
|
}
|
|
1323
1330
|
logger.warn("Restored original tunnel configuration after update failure", {
|
|
@@ -1358,7 +1365,6 @@ var TunnelManager = class _TunnelManager {
|
|
|
1358
1365
|
}
|
|
1359
1366
|
try {
|
|
1360
1367
|
if (managed.isStopped) {
|
|
1361
|
-
logger.debug(`Tunnel "${tunnelId}" is stopped. No greet message available.`);
|
|
1362
1368
|
return null;
|
|
1363
1369
|
}
|
|
1364
1370
|
const messages = await managed.instance.getGreetMessage();
|
|
@@ -1506,7 +1512,6 @@ var TunnelManager = class _TunnelManager {
|
|
|
1506
1512
|
}
|
|
1507
1513
|
try {
|
|
1508
1514
|
if (managed.isStopped) {
|
|
1509
|
-
logger.debug(`Tunnel "${tunnelId}" is stopped. Cannot fetch local server TLS info`);
|
|
1510
1515
|
return false;
|
|
1511
1516
|
}
|
|
1512
1517
|
const tlsInfo = await managed.instance.getLocalServerTls();
|
|
@@ -1628,7 +1633,7 @@ var TunnelManager = class _TunnelManager {
|
|
|
1628
1633
|
if (tunnelListeners) {
|
|
1629
1634
|
for (const [listenerId, listener] of tunnelListeners) {
|
|
1630
1635
|
try {
|
|
1631
|
-
listener(tunnelId,
|
|
1636
|
+
listener(tunnelId, normalizedStats);
|
|
1632
1637
|
} catch (error) {
|
|
1633
1638
|
logger.warn("Error in stats listener callback", { listenerId, tunnelId, error });
|
|
1634
1639
|
}
|
|
@@ -1667,7 +1672,9 @@ var TunnelManager = class _TunnelManager {
|
|
|
1667
1672
|
}
|
|
1668
1673
|
startStaticFileServer(managed) {
|
|
1669
1674
|
try {
|
|
1670
|
-
const
|
|
1675
|
+
const __filename3 = (0, import_node_url.fileURLToPath)(importMetaUrl);
|
|
1676
|
+
const __dirname2 = import_node_path.default.dirname(__filename3);
|
|
1677
|
+
const fileServerWorkerPath = import_node_path.default.join(__dirname2, "workers", "file_serve_worker.js");
|
|
1671
1678
|
const staticServerWorker = new import_node_worker_threads.Worker(fileServerWorkerPath, {
|
|
1672
1679
|
workerData: {
|
|
1673
1680
|
dir: managed.serve,
|
|
@@ -2312,29 +2319,30 @@ function newStatus(tunnelState, errorCode, errorMsg) {
|
|
|
2312
2319
|
if (tunnelState === "live" /* Live */) {
|
|
2313
2320
|
assignedState = "running" /* Running */;
|
|
2314
2321
|
} else if (tunnelState === "idle" /* New */) {
|
|
2315
|
-
assignedState = "
|
|
2322
|
+
assignedState = "idle" /* New */;
|
|
2316
2323
|
} else if (tunnelState === "closed" /* Closed */) {
|
|
2317
2324
|
assignedState = "exited" /* Exited */;
|
|
2318
2325
|
}
|
|
2326
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
2319
2327
|
return {
|
|
2320
2328
|
state: assignedState,
|
|
2321
2329
|
errorcode: errorCode,
|
|
2322
2330
|
errormsg: errorMsg,
|
|
2323
|
-
createdtimestamp:
|
|
2324
|
-
starttimestamp:
|
|
2325
|
-
endtimestamp:
|
|
2331
|
+
createdtimestamp: now,
|
|
2332
|
+
starttimestamp: now,
|
|
2333
|
+
endtimestamp: now,
|
|
2326
2334
|
warnings: []
|
|
2327
2335
|
};
|
|
2328
2336
|
}
|
|
2329
2337
|
function newStats() {
|
|
2330
|
-
return {
|
|
2338
|
+
return [{
|
|
2331
2339
|
numLiveConnections: 0,
|
|
2332
2340
|
numTotalConnections: 0,
|
|
2333
2341
|
numTotalReqBytes: 0,
|
|
2334
2342
|
numTotalResBytes: 0,
|
|
2335
2343
|
numTotalTxBytes: 0,
|
|
2336
2344
|
elapsedTime: 0
|
|
2337
|
-
};
|
|
2345
|
+
}];
|
|
2338
2346
|
}
|
|
2339
2347
|
|
|
2340
2348
|
// src/remote_management/handler.ts
|
|
@@ -2349,6 +2357,11 @@ var HeaderModificationSchema = import_zod.z.object({
|
|
|
2349
2357
|
value: import_zod.z.array(import_zod.z.string()).optional(),
|
|
2350
2358
|
type: import_zod.z.enum(["add", "remove", "update"])
|
|
2351
2359
|
});
|
|
2360
|
+
var AdditionalForwardingSchema = import_zod.z.object({
|
|
2361
|
+
remoteDomain: import_zod.z.string().optional(),
|
|
2362
|
+
localDomain: import_zod.z.string(),
|
|
2363
|
+
localPort: import_zod.z.number()
|
|
2364
|
+
});
|
|
2352
2365
|
var TunnelConfigSchema = import_zod.z.object({
|
|
2353
2366
|
allowPreflight: import_zod.z.boolean(),
|
|
2354
2367
|
autoreconnect: import_zod.z.boolean(),
|
|
@@ -2376,7 +2389,9 @@ var TunnelConfigSchema = import_zod.z.object({
|
|
|
2376
2389
|
tunnelTimeout: import_zod.z.number(),
|
|
2377
2390
|
type: import_zod.z.enum([import_pinggy5.TunnelType.Http, import_pinggy5.TunnelType.Tcp, import_pinggy5.TunnelType.Udp, import_pinggy5.TunnelType.Tls, import_pinggy5.TunnelType.TlsTcp]),
|
|
2378
2391
|
webdebuggerport: import_zod.z.number(),
|
|
2379
|
-
xff: import_zod.z.string()
|
|
2392
|
+
xff: import_zod.z.string(),
|
|
2393
|
+
additionalForwarding: import_zod.z.array(AdditionalForwardingSchema).optional(),
|
|
2394
|
+
serve: import_zod.z.string().optional()
|
|
2380
2395
|
});
|
|
2381
2396
|
var StartSchema = import_zod.z.object({
|
|
2382
2397
|
tunnelID: import_zod.z.string().uuid().nullable().optional(),
|
|
@@ -2412,8 +2427,10 @@ function tunnelConfigToPinggyOptions(config) {
|
|
|
2412
2427
|
}
|
|
2413
2428
|
};
|
|
2414
2429
|
}
|
|
2415
|
-
function pinggyOptionsToTunnelConfig(opts, configid, configName, localserverTls, greetMsg) {
|
|
2430
|
+
function pinggyOptionsToTunnelConfig(opts, configid, configName, localserverTls, greetMsg, additionalForwarding, serve) {
|
|
2416
2431
|
const forwarding = Array.isArray(opts.forwarding) ? String(opts.forwarding[0].address).replace("//", "").replace(/\/$/, "") : String(opts.forwarding).replace("//", "").replace(/\/$/, "");
|
|
2432
|
+
const parsedForwardedHost = forwarding.split(":").length == 3 ? forwarding.split(":")[1] : forwarding.split(":")[0];
|
|
2433
|
+
const parsedLocalPort = forwarding.split(":").length == 3 ? parseInt(forwarding.split(":")[2], 10) : parseInt(forwarding.split(":")[1], 10);
|
|
2417
2434
|
const tunnelType = Array.isArray(opts.tunnelType) ? opts.tunnelType[0] : opts.tunnelType ?? "http";
|
|
2418
2435
|
const parsedTokens = opts.bearerTokenAuth ? Array.isArray(opts.bearerTokenAuth) ? opts.bearerTokenAuth : JSON.parse(opts.bearerTokenAuth) : [];
|
|
2419
2436
|
return {
|
|
@@ -2425,14 +2442,14 @@ function pinggyOptionsToTunnelConfig(opts, configid, configName, localserverTls,
|
|
|
2425
2442
|
configname: configName,
|
|
2426
2443
|
greetmsg: greetMsg || "",
|
|
2427
2444
|
force: opts.force ?? false,
|
|
2428
|
-
forwardedhost:
|
|
2445
|
+
forwardedhost: parsedForwardedHost || "localhost",
|
|
2429
2446
|
fullRequestUrl: opts.originalRequestUrl ?? false,
|
|
2430
2447
|
headermodification: opts.headerModification || [],
|
|
2431
2448
|
//structured list
|
|
2432
2449
|
httpsOnly: opts.httpsOnly ?? false,
|
|
2433
2450
|
internalwebdebuggerport: 0,
|
|
2434
2451
|
ipwhitelist: opts.ipWhitelist ? Array.isArray(opts.ipWhitelist) ? opts.ipWhitelist : JSON.parse(opts.ipWhitelist) : null,
|
|
2435
|
-
localport:
|
|
2452
|
+
localport: parsedLocalPort || 0,
|
|
2436
2453
|
localservertlssni: null,
|
|
2437
2454
|
regioncode: "",
|
|
2438
2455
|
noReverseProxy: opts.reverseProxy ?? false,
|
|
@@ -2444,7 +2461,9 @@ function pinggyOptionsToTunnelConfig(opts, configid, configName, localserverTls,
|
|
|
2444
2461
|
type: tunnelType,
|
|
2445
2462
|
webdebuggerport: Number(opts.webDebugger?.split(":")[0]) || 0,
|
|
2446
2463
|
xff: opts.xForwardedFor ? "1" : "",
|
|
2447
|
-
localsservertls: localserverTls || false
|
|
2464
|
+
localsservertls: localserverTls || false,
|
|
2465
|
+
additionalForwarding: additionalForwarding || [],
|
|
2466
|
+
serve: serve || ""
|
|
2448
2467
|
};
|
|
2449
2468
|
}
|
|
2450
2469
|
|
|
@@ -2454,7 +2473,7 @@ var TunnelOperations = class {
|
|
|
2454
2473
|
this.tunnelManager = TunnelManager.getInstance();
|
|
2455
2474
|
}
|
|
2456
2475
|
// --- Helper to construct TunnelResponse ---
|
|
2457
|
-
async buildTunnelResponse(tunnelid, tunnelConfig, configid, tunnelName) {
|
|
2476
|
+
async buildTunnelResponse(tunnelid, tunnelConfig, configid, tunnelName, additionalForwarding, serve) {
|
|
2458
2477
|
const [status, stats, tlsInfo, greetMsg, remoteurls] = await Promise.all([
|
|
2459
2478
|
this.tunnelManager.getTunnelStatus(tunnelid),
|
|
2460
2479
|
this.tunnelManager.getTunnelStats(tunnelid),
|
|
@@ -2465,7 +2484,7 @@ var TunnelOperations = class {
|
|
|
2465
2484
|
return {
|
|
2466
2485
|
tunnelid,
|
|
2467
2486
|
remoteurls,
|
|
2468
|
-
tunnelconfig: pinggyOptionsToTunnelConfig(tunnelConfig, configid, tunnelName, tlsInfo, greetMsg),
|
|
2487
|
+
tunnelconfig: pinggyOptionsToTunnelConfig(tunnelConfig, configid, tunnelName, tlsInfo, greetMsg, additionalForwarding),
|
|
2469
2488
|
status: newStatus(status, "" /* NoError */, ""),
|
|
2470
2489
|
stats
|
|
2471
2490
|
};
|
|
@@ -2480,14 +2499,17 @@ var TunnelOperations = class {
|
|
|
2480
2499
|
async handleStart(config) {
|
|
2481
2500
|
try {
|
|
2482
2501
|
const opts = tunnelConfigToPinggyOptions(config);
|
|
2483
|
-
const
|
|
2502
|
+
const additionalForwardingParsed = config.additionalForwarding || [];
|
|
2503
|
+
const { tunnelid, instance, tunnelName, additionalForwarding, serve } = await this.tunnelManager.createTunnel({
|
|
2484
2504
|
...opts,
|
|
2485
2505
|
configid: config.configid,
|
|
2486
|
-
tunnelName: config.configname
|
|
2506
|
+
tunnelName: config.configname,
|
|
2507
|
+
additionalForwarding: additionalForwardingParsed,
|
|
2508
|
+
serve: config.serve
|
|
2487
2509
|
});
|
|
2488
2510
|
this.tunnelManager.startTunnel(tunnelid);
|
|
2489
2511
|
const tunnelPconfig = await this.tunnelManager.getTunnelConfig("", tunnelid);
|
|
2490
|
-
const resp = this.buildTunnelResponse(tunnelid, tunnelPconfig, config.configid, tunnelName);
|
|
2512
|
+
const resp = this.buildTunnelResponse(tunnelid, tunnelPconfig, config.configid, tunnelName, additionalForwarding, serve);
|
|
2491
2513
|
return resp;
|
|
2492
2514
|
} catch (err) {
|
|
2493
2515
|
return this.error(ErrorCode.ErrorStartingTunnel, err, "Unknown error occurred while starting tunnel");
|
|
@@ -2499,11 +2521,13 @@ var TunnelOperations = class {
|
|
|
2499
2521
|
const tunnel = await this.tunnelManager.updateConfig({
|
|
2500
2522
|
...opts,
|
|
2501
2523
|
configid: config.configid,
|
|
2502
|
-
tunnelName: config.configname
|
|
2524
|
+
tunnelName: config.configname,
|
|
2525
|
+
additionalForwarding: config.additionalForwarding || [],
|
|
2526
|
+
serve: config.serve
|
|
2503
2527
|
});
|
|
2504
2528
|
if (!tunnel.instance || !tunnel.tunnelConfig)
|
|
2505
2529
|
throw new Error("Invalid tunnel state after configuration update");
|
|
2506
|
-
return this.buildTunnelResponse(tunnel.tunnelid, tunnel.tunnelConfig, config.configid, tunnel.tunnelName);
|
|
2530
|
+
return this.buildTunnelResponse(tunnel.tunnelid, tunnel.tunnelConfig, config.configid, tunnel.tunnelName, tunnel.additionalForwarding, tunnel.serve);
|
|
2507
2531
|
} catch (err) {
|
|
2508
2532
|
return this.error(ErrorCode.InternalServerError, err, "Failed to update tunnel configuration");
|
|
2509
2533
|
}
|
|
@@ -2523,7 +2547,8 @@ var TunnelOperations = class {
|
|
|
2523
2547
|
this.tunnelManager.getLocalserverTlsInfo(t.tunnelid),
|
|
2524
2548
|
this.tunnelManager.getTunnelGreetMessage(t.tunnelid)
|
|
2525
2549
|
]);
|
|
2526
|
-
const
|
|
2550
|
+
const pinggyOptions = status !== "closed" /* Closed */ && status !== "exited" /* Exited */ ? await this.tunnelManager.getTunnelConfig("", t.tunnelid) : t.tunnelConfig;
|
|
2551
|
+
const tunnelConfig = pinggyOptionsToTunnelConfig(pinggyOptions, t.configid, t.tunnelName, tlsInfo, greetMsg, t.additionalForwarding, t.serve);
|
|
2527
2552
|
return {
|
|
2528
2553
|
tunnelid: t.tunnelid,
|
|
2529
2554
|
remoteurls: t.remoteurls,
|
|
@@ -2542,7 +2567,7 @@ var TunnelOperations = class {
|
|
|
2542
2567
|
const { configid } = this.tunnelManager.stopTunnel(tunnelid);
|
|
2543
2568
|
const managed = this.tunnelManager.getManagedTunnel("", tunnelid);
|
|
2544
2569
|
if (!managed?.tunnelConfig) throw new Error(`Tunnel config for ID "${tunnelid}" not found`);
|
|
2545
|
-
return this.buildTunnelResponse(tunnelid, managed.tunnelConfig, configid, managed.tunnelName);
|
|
2570
|
+
return this.buildTunnelResponse(tunnelid, managed.tunnelConfig, configid, managed.tunnelName, managed.additionalForwarding, managed.serve);
|
|
2546
2571
|
} catch (err) {
|
|
2547
2572
|
return this.error(ErrorCode.TunnelNotFound, err, "Failed to stop tunnel");
|
|
2548
2573
|
}
|
|
@@ -2551,7 +2576,7 @@ var TunnelOperations = class {
|
|
|
2551
2576
|
try {
|
|
2552
2577
|
const managed = this.tunnelManager.getManagedTunnel("", tunnelid);
|
|
2553
2578
|
if (!managed?.tunnelConfig) throw new Error(`Tunnel config for ID "${tunnelid}" not found`);
|
|
2554
|
-
return this.buildTunnelResponse(tunnelid, managed.tunnelConfig, managed.configid, managed.tunnelName);
|
|
2579
|
+
return this.buildTunnelResponse(tunnelid, managed.tunnelConfig, managed.configid, managed.tunnelName, managed.additionalForwarding, managed.serve);
|
|
2555
2580
|
} catch (err) {
|
|
2556
2581
|
return this.error(ErrorCode.TunnelNotFound, err, "Failed to get tunnel information");
|
|
2557
2582
|
}
|
|
@@ -2561,7 +2586,7 @@ var TunnelOperations = class {
|
|
|
2561
2586
|
await this.tunnelManager.restartTunnel(tunnelid);
|
|
2562
2587
|
const managed = this.tunnelManager.getManagedTunnel("", tunnelid);
|
|
2563
2588
|
if (!managed?.tunnelConfig) throw new Error(`Tunnel config for ID "${tunnelid}" not found`);
|
|
2564
|
-
return this.buildTunnelResponse(tunnelid, managed.tunnelConfig, managed.configid, managed.tunnelName);
|
|
2589
|
+
return this.buildTunnelResponse(tunnelid, managed.tunnelConfig, managed.configid, managed.tunnelName, managed.additionalForwarding, managed.serve);
|
|
2565
2590
|
} catch (err) {
|
|
2566
2591
|
return this.error(ErrorCode.TunnelNotFound, err, "Failed to restart tunnel");
|
|
2567
2592
|
}
|
|
@@ -2572,6 +2597,17 @@ var TunnelOperations = class {
|
|
|
2572
2597
|
handleUnregisterStatsListener(tunnelid, listnerId) {
|
|
2573
2598
|
this.tunnelManager.deregisterStatsListener(tunnelid, listnerId);
|
|
2574
2599
|
}
|
|
2600
|
+
handleGetTunnelStats(tunnelid) {
|
|
2601
|
+
try {
|
|
2602
|
+
const stats = this.tunnelManager.getTunnelStats(tunnelid);
|
|
2603
|
+
if (!stats) {
|
|
2604
|
+
return newStats();
|
|
2605
|
+
}
|
|
2606
|
+
return stats;
|
|
2607
|
+
} catch (err) {
|
|
2608
|
+
return this.error(ErrorCode.TunnelNotFound, err, "Failed to get tunnel stats");
|
|
2609
|
+
}
|
|
2610
|
+
}
|
|
2575
2611
|
};
|
|
2576
2612
|
|
|
2577
2613
|
// src/remote_management/websocket_handlers.ts
|
package/dist/index.d.cts
CHANGED
|
@@ -6,7 +6,6 @@ import winston from 'winston';
|
|
|
6
6
|
|
|
7
7
|
interface AdditionalForwarding {
|
|
8
8
|
remoteDomain?: string;
|
|
9
|
-
remotePort: number;
|
|
10
9
|
localDomain: string;
|
|
11
10
|
localPort: number;
|
|
12
11
|
}
|
|
@@ -37,9 +36,9 @@ interface Status {
|
|
|
37
36
|
state: TunnelStateType;
|
|
38
37
|
errorcode: TunnelErrorCodeType;
|
|
39
38
|
errormsg: string;
|
|
40
|
-
createdtimestamp:
|
|
41
|
-
starttimestamp:
|
|
42
|
-
endtimestamp:
|
|
39
|
+
createdtimestamp: string;
|
|
40
|
+
starttimestamp: string;
|
|
41
|
+
endtimestamp: string;
|
|
43
42
|
warnings: Warning[];
|
|
44
43
|
}
|
|
45
44
|
type ErrorCodeType = "INVALID_REQUEST_METHOD" | "COULD_NOT_READ_BODY" | "INTERNAL_SERVER_ERROR" | "INVALID_DATA_FORMAT" | "ERROR_STARTING_TUNNEL" | "TUNNEL_WITH_ID_OR_CONFIG_ID_NOT_FOUND" | "TUNNEL_WITH_ID_OR_CONFIG_ID_ALREADY_RUNNING" | "WEBSOCKET_UPGRADE_FAILED" | "REMOTE_MANAGEMENT_ALREADY_RUNNING" | "REMOTE_MANAGEMENT_NOT_RUNNING" | "REMOTE_MANAGEMENT_DESERIALIZATION_FAILED";
|
|
@@ -82,8 +81,10 @@ interface TunnelList {
|
|
|
82
81
|
tunnelName?: string;
|
|
83
82
|
tunnelConfig: PinggyOptions;
|
|
84
83
|
remoteurls: string[];
|
|
84
|
+
additionalForwarding?: AdditionalForwarding[];
|
|
85
|
+
serve?: string;
|
|
85
86
|
}
|
|
86
|
-
type StatsListener = (tunnelId: string, stats: TunnelUsageType
|
|
87
|
+
type StatsListener = (tunnelId: string, stats: TunnelUsageType) => void;
|
|
87
88
|
type ErrorListener = (tunnelId: string, errorMsg: string, isFatal: boolean) => void;
|
|
88
89
|
type DisconnectListener = (tunnelId: string, error: string, messages: string[]) => void;
|
|
89
90
|
type TunnelWorkerErrorListner = (tunnelid: string, error: Error) => void;
|
|
@@ -239,6 +240,7 @@ declare class TunnelManager implements ITunnelManager {
|
|
|
239
240
|
configid: string;
|
|
240
241
|
additionalForwarding?: AdditionalForwarding[];
|
|
241
242
|
tunnelName?: string;
|
|
243
|
+
serve?: string;
|
|
242
244
|
}): Promise<ManagedTunnel>;
|
|
243
245
|
/**
|
|
244
246
|
* Retrieve the ManagedTunnel object by either configId or tunnelId.
|
|
@@ -335,6 +337,12 @@ declare const TunnelConfigSchema: z.ZodObject<{
|
|
|
335
337
|
}>;
|
|
336
338
|
webdebuggerport: z.ZodNumber;
|
|
337
339
|
xff: z.ZodString;
|
|
340
|
+
additionalForwarding: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
341
|
+
remoteDomain: z.ZodOptional<z.ZodString>;
|
|
342
|
+
localDomain: z.ZodString;
|
|
343
|
+
localPort: z.ZodNumber;
|
|
344
|
+
}, z.core.$strip>>>;
|
|
345
|
+
serve: z.ZodOptional<z.ZodString>;
|
|
338
346
|
}, z.core.$strip>;
|
|
339
347
|
type TunnelConfig = z.infer<typeof TunnelConfigSchema>;
|
|
340
348
|
|
|
@@ -352,8 +360,9 @@ interface TunnelHandler {
|
|
|
352
360
|
handleStop(tunnelid: string): Promise<TunnelResponse | ErrorResponse>;
|
|
353
361
|
handleGet(tunnelid: string): Promise<TunnelResponse | ErrorResponse>;
|
|
354
362
|
handleRestart(tunnelid: string): Promise<TunnelResponse | ErrorResponse>;
|
|
355
|
-
handleRegisterStatsListener(tunnelid: string, listener: (tunnelId: string, stats: TunnelUsageType
|
|
363
|
+
handleRegisterStatsListener(tunnelid: string, listener: (tunnelId: string, stats: TunnelUsageType) => void): void;
|
|
356
364
|
handleUnregisterStatsListener(tunnelid: string, listnerId: string): void;
|
|
365
|
+
handleGetTunnelStats(tunnelid: string): TunnelUsageType[] | ErrorResponse;
|
|
357
366
|
}
|
|
358
367
|
declare class TunnelOperations implements TunnelHandler {
|
|
359
368
|
private tunnelManager;
|
|
@@ -366,8 +375,9 @@ declare class TunnelOperations implements TunnelHandler {
|
|
|
366
375
|
handleStop(tunnelid: string): Promise<TunnelResponse | ErrorResponse>;
|
|
367
376
|
handleGet(tunnelid: string): Promise<TunnelResponse | ErrorResponse>;
|
|
368
377
|
handleRestart(tunnelid: string): Promise<TunnelResponse | ErrorResponse>;
|
|
369
|
-
handleRegisterStatsListener(tunnelid: string, listener: (tunnelId: string, stats: TunnelUsageType
|
|
378
|
+
handleRegisterStatsListener(tunnelid: string, listener: (tunnelId: string, stats: TunnelUsageType) => void): void;
|
|
370
379
|
handleUnregisterStatsListener(tunnelid: string, listnerId: string): void;
|
|
380
|
+
handleGetTunnelStats(tunnelid: string): TunnelUsageType[] | ErrorResponse;
|
|
371
381
|
}
|
|
372
382
|
|
|
373
383
|
interface BaseLogConfig {
|
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,6 @@ import winston from 'winston';
|
|
|
6
6
|
|
|
7
7
|
interface AdditionalForwarding {
|
|
8
8
|
remoteDomain?: string;
|
|
9
|
-
remotePort: number;
|
|
10
9
|
localDomain: string;
|
|
11
10
|
localPort: number;
|
|
12
11
|
}
|
|
@@ -37,9 +36,9 @@ interface Status {
|
|
|
37
36
|
state: TunnelStateType;
|
|
38
37
|
errorcode: TunnelErrorCodeType;
|
|
39
38
|
errormsg: string;
|
|
40
|
-
createdtimestamp:
|
|
41
|
-
starttimestamp:
|
|
42
|
-
endtimestamp:
|
|
39
|
+
createdtimestamp: string;
|
|
40
|
+
starttimestamp: string;
|
|
41
|
+
endtimestamp: string;
|
|
43
42
|
warnings: Warning[];
|
|
44
43
|
}
|
|
45
44
|
type ErrorCodeType = "INVALID_REQUEST_METHOD" | "COULD_NOT_READ_BODY" | "INTERNAL_SERVER_ERROR" | "INVALID_DATA_FORMAT" | "ERROR_STARTING_TUNNEL" | "TUNNEL_WITH_ID_OR_CONFIG_ID_NOT_FOUND" | "TUNNEL_WITH_ID_OR_CONFIG_ID_ALREADY_RUNNING" | "WEBSOCKET_UPGRADE_FAILED" | "REMOTE_MANAGEMENT_ALREADY_RUNNING" | "REMOTE_MANAGEMENT_NOT_RUNNING" | "REMOTE_MANAGEMENT_DESERIALIZATION_FAILED";
|
|
@@ -82,8 +81,10 @@ interface TunnelList {
|
|
|
82
81
|
tunnelName?: string;
|
|
83
82
|
tunnelConfig: PinggyOptions;
|
|
84
83
|
remoteurls: string[];
|
|
84
|
+
additionalForwarding?: AdditionalForwarding[];
|
|
85
|
+
serve?: string;
|
|
85
86
|
}
|
|
86
|
-
type StatsListener = (tunnelId: string, stats: TunnelUsageType
|
|
87
|
+
type StatsListener = (tunnelId: string, stats: TunnelUsageType) => void;
|
|
87
88
|
type ErrorListener = (tunnelId: string, errorMsg: string, isFatal: boolean) => void;
|
|
88
89
|
type DisconnectListener = (tunnelId: string, error: string, messages: string[]) => void;
|
|
89
90
|
type TunnelWorkerErrorListner = (tunnelid: string, error: Error) => void;
|
|
@@ -239,6 +240,7 @@ declare class TunnelManager implements ITunnelManager {
|
|
|
239
240
|
configid: string;
|
|
240
241
|
additionalForwarding?: AdditionalForwarding[];
|
|
241
242
|
tunnelName?: string;
|
|
243
|
+
serve?: string;
|
|
242
244
|
}): Promise<ManagedTunnel>;
|
|
243
245
|
/**
|
|
244
246
|
* Retrieve the ManagedTunnel object by either configId or tunnelId.
|
|
@@ -335,6 +337,12 @@ declare const TunnelConfigSchema: z.ZodObject<{
|
|
|
335
337
|
}>;
|
|
336
338
|
webdebuggerport: z.ZodNumber;
|
|
337
339
|
xff: z.ZodString;
|
|
340
|
+
additionalForwarding: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
341
|
+
remoteDomain: z.ZodOptional<z.ZodString>;
|
|
342
|
+
localDomain: z.ZodString;
|
|
343
|
+
localPort: z.ZodNumber;
|
|
344
|
+
}, z.core.$strip>>>;
|
|
345
|
+
serve: z.ZodOptional<z.ZodString>;
|
|
338
346
|
}, z.core.$strip>;
|
|
339
347
|
type TunnelConfig = z.infer<typeof TunnelConfigSchema>;
|
|
340
348
|
|
|
@@ -352,8 +360,9 @@ interface TunnelHandler {
|
|
|
352
360
|
handleStop(tunnelid: string): Promise<TunnelResponse | ErrorResponse>;
|
|
353
361
|
handleGet(tunnelid: string): Promise<TunnelResponse | ErrorResponse>;
|
|
354
362
|
handleRestart(tunnelid: string): Promise<TunnelResponse | ErrorResponse>;
|
|
355
|
-
handleRegisterStatsListener(tunnelid: string, listener: (tunnelId: string, stats: TunnelUsageType
|
|
363
|
+
handleRegisterStatsListener(tunnelid: string, listener: (tunnelId: string, stats: TunnelUsageType) => void): void;
|
|
356
364
|
handleUnregisterStatsListener(tunnelid: string, listnerId: string): void;
|
|
365
|
+
handleGetTunnelStats(tunnelid: string): TunnelUsageType[] | ErrorResponse;
|
|
357
366
|
}
|
|
358
367
|
declare class TunnelOperations implements TunnelHandler {
|
|
359
368
|
private tunnelManager;
|
|
@@ -366,8 +375,9 @@ declare class TunnelOperations implements TunnelHandler {
|
|
|
366
375
|
handleStop(tunnelid: string): Promise<TunnelResponse | ErrorResponse>;
|
|
367
376
|
handleGet(tunnelid: string): Promise<TunnelResponse | ErrorResponse>;
|
|
368
377
|
handleRestart(tunnelid: string): Promise<TunnelResponse | ErrorResponse>;
|
|
369
|
-
handleRegisterStatsListener(tunnelid: string, listener: (tunnelId: string, stats: TunnelUsageType
|
|
378
|
+
handleRegisterStatsListener(tunnelid: string, listener: (tunnelId: string, stats: TunnelUsageType) => void): void;
|
|
370
379
|
handleUnregisterStatsListener(tunnelid: string, listnerId: string): void;
|
|
380
|
+
handleGetTunnelStats(tunnelid: string): TunnelUsageType[] | ErrorResponse;
|
|
371
381
|
}
|
|
372
382
|
|
|
373
383
|
interface BaseLogConfig {
|