pinggy 0.3.7 → 0.3.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.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { PinggyOptions, TunnelUsageType, TunnelInstance, TunnelType } from '@pinggy/pinggy';
2
+ import { TunnelConfigurationV1, TunnelUsageType, TunnelInstance, TunnelType, RemoteManagementConfig } from '@pinggy/pinggy';
3
3
  import { Worker } from 'node:worker_threads';
4
4
  import { z } from 'zod';
5
5
  import winston from 'winston';
@@ -14,7 +14,7 @@ interface AdditionalForwarding {
14
14
  interface TunnelStatus {
15
15
  tunnelid: string;
16
16
  remoteurls: string[];
17
- tunnelconfig: PinggyOptions;
17
+ tunnelconfig: TunnelConfigurationV1;
18
18
  status: Status;
19
19
  stats: TunnelUsageType;
20
20
  }
@@ -50,19 +50,9 @@ interface Status {
50
50
  endtimestamp: string;
51
51
  warnings: Warning[];
52
52
  }
53
- type FinalConfig = (PinggyOptions & {
54
- configid: string;
55
- }) & {
56
- tunnelType: string[];
53
+ type FinalConfig = (TunnelConfigurationV1) & {
57
54
  conf?: string;
58
55
  saveconf?: string;
59
- serve?: string;
60
- remoteManagement?: string;
61
- additionalForwarding?: AdditionalForwarding[];
62
- manage?: string;
63
- version?: boolean;
64
- NoTUI?: boolean;
65
- qrCode?: boolean;
66
56
  };
67
57
  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";
68
58
  interface ErrorResponse {
@@ -93,12 +83,10 @@ interface RemoteManagementState {
93
83
 
94
84
  interface ManagedTunnel {
95
85
  tunnelid: string;
96
- configid: string;
86
+ configId: string;
97
87
  tunnelName?: string;
98
88
  instance: TunnelInstance;
99
- tunnelConfig?: PinggyOptions;
100
- configWithForwarding?: PinggyOptions;
101
- additionalForwarding?: AdditionalForwarding[];
89
+ tunnelConfig?: TunnelConfigurationV1;
102
90
  serveWorker?: Worker | null;
103
91
  warnings?: Warning[];
104
92
  serve?: string;
@@ -110,15 +98,24 @@ interface ManagedTunnel {
110
98
  }
111
99
  interface TunnelList {
112
100
  tunnelid: string;
113
- configid: string;
101
+ configId: string;
114
102
  tunnelName?: string;
115
- tunnelConfig: PinggyOptions;
103
+ tunnelConfig: TunnelConfigurationV1;
116
104
  remoteurls: string[];
117
- additionalForwarding?: AdditionalForwarding[];
105
+ serve?: string;
106
+ }
107
+ interface TunnelCreationConfig extends TunnelConfigurationV1 {
108
+ tunnelid?: string;
109
+ tunnelName?: string;
110
+ serve?: string;
111
+ }
112
+ interface TunnelUpdateConfig extends TunnelConfigurationV1 {
113
+ tunnelName?: string;
118
114
  serve?: string;
119
115
  }
120
116
  type StatsListener = (tunnelId: string, stats: TunnelUsageType) => void;
121
117
  type ErrorListener = (tunnelId: string, errorMsg: string, isFatal: boolean) => void;
118
+ type PollingErrorListener = (tunnelId: string, errorMsg: string) => void;
122
119
  type DisconnectListener = (tunnelId: string, error: string, messages: string[]) => void;
123
120
  type TunnelWorkerErrorListner = (tunnelid: string, error: Error) => void;
124
121
  type StartListener = (tunnelId: string, urls: string[]) => void;
@@ -127,16 +124,10 @@ type ReconnectingListener = (tunnelId: string, retryCnt: number) => void;
127
124
  type ReconnectionCompletedListener = (tunnelId: string, urls: string[]) => void;
128
125
  type ReconnectionFailedListener = (tunnelId: string, retryCnt: number) => void;
129
126
  interface ITunnelManager {
130
- createTunnel(config: (PinggyOptions & {
131
- configid: string;
132
- tunnelid?: string;
133
- tunnelName?: string;
134
- }) & {
135
- additionalForwarding?: AdditionalForwarding[];
136
- }): Promise<ManagedTunnel>;
127
+ createTunnel(config: TunnelCreationConfig, buildConfig?: boolean): Promise<ManagedTunnel>;
137
128
  startTunnel(tunnelId: string): Promise<string[]>;
138
129
  stopTunnel(tunnelId: string): {
139
- configid: string;
130
+ configId: string;
140
131
  tunnelid: string;
141
132
  };
142
133
  stopAllTunnels(): void;
@@ -144,22 +135,20 @@ interface ITunnelManager {
144
135
  getAllTunnels(): Promise<TunnelList[]>;
145
136
  getTunnelStatus(tunnelId: string): Promise<string>;
146
137
  getTunnelInstance(configId?: string, tunnelId?: string): TunnelInstance;
147
- getTunnelConfig(configId?: string, tunnelId?: string): Promise<PinggyOptions>;
138
+ getTunnelConfig(configId?: string, tunnelId?: string): Promise<TunnelConfigurationV1>;
148
139
  restartTunnel(tunnelId: string): Promise<void>;
149
- updateConfig(newConfig: PinggyOptions & {
150
- configid: string;
151
- additionalForwarding?: AdditionalForwarding[];
152
- tunnelName?: string;
153
- }): Promise<ManagedTunnel>;
140
+ updateConfig(newConfig: TunnelUpdateConfig, buildConfig: boolean): Promise<ManagedTunnel>;
154
141
  getManagedTunnel(configId?: string, tunnelId?: string): ManagedTunnel;
155
142
  getTunnelGreetMessage(tunnelId: string): Promise<string | null>;
156
143
  getTunnelStats(tunnelId: string): TunnelUsageType[] | null;
157
144
  getLatestTunnelStats(tunnelId: string): TunnelUsageType | null;
158
145
  registerStatsListener(tunnelId: string, listener: StatsListener): Promise<[string, string]>;
159
146
  registerErrorListener(tunnelId: string, listener: ErrorListener): Promise<string>;
147
+ registerPollingErrorListener(tunnelId: string, listener: PollingErrorListener): Promise<string>;
160
148
  registerWorkerErrorListner(tunnelId: string, listener: TunnelWorkerErrorListner): void;
161
149
  registerStartListener(tunnelId: string, listener: StartListener): Promise<string>;
162
150
  deregisterErrorListener(tunnelId: string, listenerId: string): void;
151
+ deregisterPollingErrorListener(tunnelId: string, listenerId: string): void;
163
152
  registerDisconnectListener(tunnelId: string, listener: DisconnectListener): Promise<string>;
164
153
  deregisterDisconnectListener(tunnelId: string, listenerId: string): void;
165
154
  deregisterStatsListener(tunnelId: string, listenerId: string): void;
@@ -182,6 +171,7 @@ declare class TunnelManager implements ITunnelManager {
182
171
  private tunnelStats;
183
172
  private tunnelStatsListeners;
184
173
  private tunnelErrorListeners;
174
+ private tunnelPollingErrorListeners;
185
175
  private tunnelDisconnectListeners;
186
176
  private tunnelWorkerErrorListeners;
187
177
  private tunnelStartListeners;
@@ -193,12 +183,9 @@ declare class TunnelManager implements ITunnelManager {
193
183
  static getInstance(): TunnelManager;
194
184
  /**
195
185
  * Creates a new managed tunnel instance with the given configuration.
196
- * Builds the config with forwarding rules and creates the tunnel instance.
186
+ * Optionally builds the config with forwarding rules based on buildConfig flag.
197
187
  *
198
188
  * @param config - The tunnel configuration options
199
- * @param config.configid - Unique identifier for the tunnel configuration
200
- * @param config.tunnelid - Optional custom tunnel identifier. If not provided, a random UUID will be generated
201
- * @param config.additionalForwarding - Optional array of additional forwarding configurations
202
189
  *
203
190
  * @throws {Error} When configId is invalid or empty
204
191
  * @throws {Error} When a tunnel with the given configId already exists
@@ -206,17 +193,7 @@ declare class TunnelManager implements ITunnelManager {
206
193
  * @returns {ManagedTunnel} A new managed tunnel instance containing the tunnel details,
207
194
  * status information, and statistics
208
195
  */
209
- createTunnel(config: (PinggyOptions & {
210
- tunnelType: string[] | undefined;
211
- } & {
212
- configid: string;
213
- tunnelid?: string;
214
- tunnelName?: string;
215
- }) & {
216
- additionalForwarding?: AdditionalForwarding[];
217
- } & {
218
- serve?: string;
219
- }): Promise<ManagedTunnel>;
196
+ createTunnel(config: TunnelCreationConfig): Promise<ManagedTunnel>;
220
197
  /**
221
198
  * Internal method to create a tunnel with an already-processed configuration.
222
199
  * This is used by createTunnel, restartTunnel, and updateConfig to avoid config processing.
@@ -226,15 +203,6 @@ declare class TunnelManager implements ITunnelManager {
226
203
  * @private
227
204
  */
228
205
  private _createTunnelWithProcessedConfig;
229
- /**
230
- * Builds the Pinggy configuration by merging the default forwarding rule
231
- * with additional forwarding rules from additionalForwarding array.
232
- *
233
- * @param config - The base Pinggy configuration
234
- * @param additionalForwarding - Optional array of additional forwarding rules
235
- * @returns Modified PinggyOptions
236
- */
237
- private buildPinggyConfig;
238
206
  /**
239
207
  * Start a tunnel that was created but not yet started
240
208
  */
@@ -250,7 +218,7 @@ declare class TunnelManager implements ITunnelManager {
250
218
  * - Logs the stop operation with tunnelId and configId
251
219
  */
252
220
  stopTunnel(tunnelId: string): {
253
- configid: string;
221
+ configId: string;
254
222
  tunnelid: string;
255
223
  };
256
224
  /**
@@ -300,7 +268,7 @@ declare class TunnelManager implements ITunnelManager {
300
268
  * @returns The tunnel config
301
269
  * @throws Error if neither configId nor tunnelId is provided, or if tunnel is not found
302
270
  */
303
- getTunnelConfig(configId?: string, tunnelId?: string): Promise<PinggyOptions>;
271
+ getTunnelConfig(configId?: string, tunnelId?: string): Promise<TunnelConfigurationV1>;
304
272
  /**
305
273
  * Restarts a tunnel with its current configuration.
306
274
  * This function will stop the tunnel if it's running and start it again.
@@ -319,14 +287,7 @@ declare class TunnelManager implements ITunnelManager {
319
287
  * @returns Promise resolving to the updated ManagedTunnel
320
288
  * @throws Error if the tunnel is not found or if the update process fails
321
289
  */
322
- updateConfig(newConfig: PinggyOptions & {
323
- tunnelType: string[] | undefined;
324
- } & {
325
- configid: string;
326
- additionalForwarding?: AdditionalForwarding[];
327
- tunnelName?: string;
328
- serve?: string;
329
- }): Promise<ManagedTunnel>;
290
+ updateConfig(newConfig: TunnelUpdateConfig): Promise<ManagedTunnel>;
330
291
  /**
331
292
  * Retrieve the ManagedTunnel object by either configId or tunnelId.
332
293
  * Throws an error if neither id is provided or the tunnel is not found.
@@ -347,6 +308,7 @@ declare class TunnelManager implements ITunnelManager {
347
308
  */
348
309
  registerStatsListener(tunnelId: string, listener: StatsListener): Promise<[string, string]>;
349
310
  registerErrorListener(tunnelId: string, listener: ErrorListener): Promise<string>;
311
+ registerPollingErrorListener(tunnelId: string, listener: PollingErrorListener): Promise<string>;
350
312
  registerDisconnectListener(tunnelId: string, listener: DisconnectListener): Promise<string>;
351
313
  registerWorkerErrorListner(tunnelId: string, listener: TunnelWorkerErrorListner): Promise<void>;
352
314
  registerStartListener(tunnelId: string, listener: StartListener): Promise<string>;
@@ -362,6 +324,7 @@ declare class TunnelManager implements ITunnelManager {
362
324
  */
363
325
  deregisterStatsListener(tunnelId: string, listenerId: string): void;
364
326
  deregisterErrorListener(tunnelId: string, listenerId: string): void;
327
+ deregisterPollingErrorListener(tunnelId: string, listenerId: string): void;
365
328
  deregisterDisconnectListener(tunnelId: string, listenerId: string): void;
366
329
  deregisterWillReconnectListener(tunnelId: string, listenerId: string): void;
367
330
  deregisterReconnectingListener(tunnelId: string, listenerId: string): void;
@@ -373,6 +336,8 @@ declare class TunnelManager implements ITunnelManager {
373
336
  * This callback will update stored stats and notify all registered listeners.
374
337
  */
375
338
  private setupStatsCallback;
339
+ private setupTunnelPollingErrorCallback;
340
+ private notifyPollingErrorListeners;
376
341
  private notifyErrorListeners;
377
342
  private setupErrorCallback;
378
343
  private setupDisconnectCallback;
@@ -417,7 +382,7 @@ declare const TunnelConfigSchema: z.ZodPipe<z.ZodObject<{
417
382
  username: z.ZodString;
418
383
  password: z.ZodString;
419
384
  }, z.core.$strip>>>;
420
- bearerauth: z.ZodNullable<z.ZodString>;
385
+ bearerauth: z.ZodNullable<z.ZodArray<z.ZodString>>;
421
386
  configid: z.ZodString;
422
387
  configname: z.ZodString;
423
388
  greetmsg: z.ZodOptional<z.ZodString>;
@@ -426,7 +391,7 @@ declare const TunnelConfigSchema: z.ZodPipe<z.ZodObject<{
426
391
  fullRequestUrl: z.ZodBoolean;
427
392
  headermodification: z.ZodArray<z.ZodObject<{
428
393
  key: z.ZodString;
429
- value: z.ZodOptional<z.ZodArray<z.ZodString>>;
394
+ value: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString>>>;
430
395
  type: z.ZodEnum<{
431
396
  add: "add";
432
397
  remove: "remove";
@@ -470,7 +435,7 @@ declare const TunnelConfigSchema: z.ZodPipe<z.ZodObject<{
470
435
  username: string;
471
436
  password: string;
472
437
  }[] | null;
473
- bearerauth: string | null;
438
+ bearerauth: string[] | null;
474
439
  configid: string;
475
440
  configname: string;
476
441
  force: boolean;
@@ -479,7 +444,7 @@ declare const TunnelConfigSchema: z.ZodPipe<z.ZodObject<{
479
444
  headermodification: {
480
445
  key: string;
481
446
  type: "add" | "remove" | "update";
482
- value?: string[] | undefined;
447
+ value?: string[] | null | undefined;
483
448
  }[];
484
449
  httpsOnly: boolean;
485
450
  internalwebdebuggerport: number;
@@ -511,7 +476,7 @@ declare const TunnelConfigSchema: z.ZodPipe<z.ZodObject<{
511
476
  username: string;
512
477
  password: string;
513
478
  }[] | null;
514
- bearerauth: string | null;
479
+ bearerauth: string[] | null;
515
480
  configid: string;
516
481
  configname: string;
517
482
  force: boolean;
@@ -520,7 +485,7 @@ declare const TunnelConfigSchema: z.ZodPipe<z.ZodObject<{
520
485
  headermodification: {
521
486
  key: string;
522
487
  type: "add" | "remove" | "update";
523
- value?: string[] | undefined;
488
+ value?: string[] | null | undefined;
524
489
  }[];
525
490
  httpsOnly: boolean;
526
491
  internalwebdebuggerport: number;
@@ -550,6 +515,56 @@ declare const TunnelConfigSchema: z.ZodPipe<z.ZodObject<{
550
515
  serve?: string | undefined;
551
516
  }>>;
552
517
  type TunnelConfig = z.infer<typeof TunnelConfigSchema>;
518
+ /**
519
+ * V1 Tunnel Config Schema
520
+ */
521
+ declare const TunnelConfigV1Schema: z.ZodObject<{
522
+ version: z.ZodString;
523
+ name: z.ZodString;
524
+ configId: z.ZodString;
525
+ serverAddress: z.ZodOptional<z.ZodString>;
526
+ token: z.ZodOptional<z.ZodString>;
527
+ autoReconnect: z.ZodOptional<z.ZodBoolean>;
528
+ reconnectInterval: z.ZodOptional<z.ZodNumber>;
529
+ maxReconnectAttempts: z.ZodOptional<z.ZodNumber>;
530
+ force: z.ZodBoolean;
531
+ keepAliveInterval: z.ZodOptional<z.ZodNumber>;
532
+ webDebugger: z.ZodString;
533
+ forwarding: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodObject<{
534
+ listenAddress: z.ZodOptional<z.ZodString>;
535
+ address: z.ZodString;
536
+ type: z.ZodOptional<z.ZodEnum<{
537
+ http: TunnelType.Http;
538
+ tcp: TunnelType.Tcp;
539
+ tls: TunnelType.Tls;
540
+ udp: TunnelType.Udp;
541
+ tlstcp: TunnelType.TlsTcp;
542
+ }>>;
543
+ }, z.core.$strip>>]>;
544
+ ipWhitelist: z.ZodOptional<z.ZodArray<z.ZodString>>;
545
+ basicAuth: z.ZodOptional<z.ZodArray<z.ZodObject<{
546
+ username: z.ZodString;
547
+ password: z.ZodString;
548
+ }, z.core.$strip>>>;
549
+ bearerTokenAuth: z.ZodOptional<z.ZodArray<z.ZodString>>;
550
+ headerModification: z.ZodOptional<z.ZodArray<z.ZodObject<{
551
+ key: z.ZodString;
552
+ value: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString>>>;
553
+ type: z.ZodEnum<{
554
+ add: "add";
555
+ remove: "remove";
556
+ update: "update";
557
+ }>;
558
+ }, z.core.$strip>>>;
559
+ reverseProxy: z.ZodOptional<z.ZodBoolean>;
560
+ xForwardedFor: z.ZodOptional<z.ZodBoolean>;
561
+ httpsOnly: z.ZodOptional<z.ZodBoolean>;
562
+ originalRequestUrl: z.ZodOptional<z.ZodBoolean>;
563
+ allowPreflight: z.ZodOptional<z.ZodBoolean>;
564
+ serve: z.ZodOptional<z.ZodString>;
565
+ optional: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
566
+ }, z.core.$strip>;
567
+ type TunnelConfigV1 = z.infer<typeof TunnelConfigV1Schema>;
553
568
 
554
569
  interface TunnelResponse {
555
570
  tunnelid: string;
@@ -558,10 +573,21 @@ interface TunnelResponse {
558
573
  status: Status;
559
574
  stats: TunnelUsageType;
560
575
  }
576
+ interface TunnelResponseV2 {
577
+ tunnelid: string;
578
+ remoteurls: string[];
579
+ tunnelconfig: TunnelConfigV1;
580
+ status: Status;
581
+ stats: TunnelUsageType;
582
+ greetmsg?: string;
583
+ }
561
584
  interface TunnelHandler {
562
585
  handleStart(config: TunnelConfig): Promise<TunnelResponse | ErrorResponse>;
586
+ handleStartV2(config: TunnelConfigV1): Promise<TunnelResponseV2 | ErrorResponse>;
563
587
  handleUpdateConfig(config: TunnelConfig): Promise<TunnelResponse | ErrorResponse>;
588
+ handleUpdateConfigV2(config: TunnelConfigV1): Promise<TunnelResponseV2 | ErrorResponse>;
564
589
  handleList(): Promise<TunnelResponse[] | ErrorResponse>;
590
+ handleListV2(): Promise<TunnelResponseV2[] | ErrorResponse>;
565
591
  handleStop(tunnelid: string): Promise<TunnelResponse | ErrorResponse>;
566
592
  handleGet(tunnelid: string): Promise<TunnelResponse | ErrorResponse>;
567
593
  handleRestart(tunnelid: string): Promise<TunnelResponse | ErrorResponse>;
@@ -577,9 +603,13 @@ declare class TunnelOperations implements TunnelHandler {
577
603
  constructor();
578
604
  private buildStatus;
579
605
  private buildTunnelResponse;
606
+ private buildTunnelResponseV2;
580
607
  private error;
581
608
  handleStart(config: TunnelConfig): Promise<TunnelResponse | ErrorResponse>;
609
+ handleStartV2(config: TunnelConfigV1): Promise<TunnelResponseV2 | ErrorResponse>;
582
610
  handleUpdateConfig(config: TunnelConfig): Promise<TunnelResponse | ErrorResponse>;
611
+ handleUpdateConfigV2(config: TunnelConfigV1): Promise<TunnelResponseV2 | ErrorResponse>;
612
+ handleListV2(): Promise<TunnelResponseV2[] | ErrorResponse>;
583
613
  handleList(): Promise<TunnelResponse[] | ErrorResponse>;
584
614
  handleStop(tunnelid: string): Promise<TunnelResponse | ErrorResponse>;
585
615
  handleGet(tunnelid: string): Promise<TunnelResponse | ErrorResponse>;
@@ -610,7 +640,7 @@ declare function enablePackageLogging(opts?: BaseLogConfigType): winston.Logger;
610
640
  * - On other failures: retry every 15 seconds
611
641
  * - Keep running until closed or SIGINT
612
642
  */
613
- declare function initiateRemoteManagement(token: string, manage?: string): Promise<RemoteManagementState>;
643
+ declare function initiateRemoteManagement(remoteManagementConfig: RemoteManagementConfig): Promise<RemoteManagementState>;
614
644
  declare function closeRemoteManagement(timeoutMs?: number): Promise<RemoteManagementState>;
615
645
  declare function getRemoteManagementState(): RemoteManagementState;
616
646