Skip to content

Commit

Permalink
2.7.0 - Bump dependencies & fix ts linter errors
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshGlazebrook committed Jul 17, 2022
1 parent ed272b1 commit e776150
Show file tree
Hide file tree
Showing 7 changed files with 214 additions and 187 deletions.
346 changes: 184 additions & 162 deletions package-lock.json

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "socks",
"private": false,
"version": "2.6.2",
"version": "2.7.0",
"description": "Fully featured SOCKS proxy client supporting SOCKSv4, SOCKSv4a, and SOCKSv5. Includes Bind and Associate functionality.",
"main": "build/index.js",
"typings": "typings/index.d.ts",
Expand Down Expand Up @@ -34,18 +34,18 @@
"readmeFilename": "README.md",
"devDependencies": {
"@types/ip": "1.1.0",
"@types/mocha": "^9.1.0",
"@types/node": "^17.0.15",
"@typescript-eslint/eslint-plugin": "^5.27.1",
"@typescript-eslint/parser": "^5.27.1",
"@types/mocha": "^9.1.1",
"@types/node": "^18.0.6",
"@typescript-eslint/eslint-plugin": "^5.30.6",
"@typescript-eslint/parser": "^5.30.6",
"coveralls": "^3.1.1",
"eslint": "^8.17.0",
"mocha": "^9.2.0",
"eslint": "^8.20.0",
"mocha": "^10.0.0",
"nyc": "15.1.0",
"prettier": "^2.5.1",
"prettier": "^2.7.1",
"socks5-server": "^0.1.1",
"ts-node": "^10.4.0",
"typescript": "^4.7.3"
"ts-node": "^10.9.1",
"typescript": "^4.7.4"
},
"dependencies": {
"ip": "^2.0.0",
Expand Down
17 changes: 12 additions & 5 deletions src/client/socksclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ declare interface SocksClient {
listener: (info: SocksClientEstablishedEvent) => void,
): this;

once(event: string, listener: (...args: any[]) => void): this;
once(event: string, listener: (...args: unknown[]) => void): this;
once(event: 'error', listener: (err: SocksClientError) => void): this;
once(event: 'bound', listener: (info: SocksClientBoundEvent) => void): this;
once(
event: 'established',
listener: (info: SocksClientEstablishedEvent) => void,
): this;

emit(event: string | symbol, ...args: any[]): boolean;
emit(event: string | symbol, ...args: unknown[]): boolean;
emit(event: 'error', err: SocksClientError): boolean;
emit(event: 'bound', info: SocksClientBoundEvent): boolean;
emit(event: 'established', info: SocksClientEstablishedEvent): boolean;
Expand Down Expand Up @@ -92,7 +92,7 @@ class SocksClient extends EventEmitter implements SocksClient {
static createConnection(
options: SocksClientOptions,
callback?: (
error: unknown | null,
error: Error | null,
info?: SocksClientEstablishedEvent,
) => void,
): Promise<SocksClientEstablishedEvent> {
Expand All @@ -103,6 +103,7 @@ class SocksClient extends EventEmitter implements SocksClient {
} catch (err) {
if (typeof callback === 'function') {
callback(err);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return resolve(err as any); // Resolves pending promise (prevents memory leaks).
} else {
return reject(err);
Expand All @@ -126,6 +127,7 @@ class SocksClient extends EventEmitter implements SocksClient {
client.removeAllListeners();
if (typeof callback === 'function') {
callback(err);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
resolve(err as any); // Resolves pending promise (prevents memory leaks).
} else {
reject(err);
Expand All @@ -145,7 +147,10 @@ class SocksClient extends EventEmitter implements SocksClient {
*/
static createConnectionChain(
options: SocksClientChainOptions,
callback?: (error: any, socket?: {socket: net.Socket}) => void,
callback?: (
error: Error | null,
socket?: SocksClientEstablishedEvent,
) => void,
): Promise<SocksClientEstablishedEvent> {
// eslint-disable-next-line no-async-promise-executor
return new Promise<SocksClientEstablishedEvent>(async (resolve, reject) => {
Expand All @@ -155,6 +160,7 @@ class SocksClient extends EventEmitter implements SocksClient {
} catch (err) {
if (typeof callback === 'function') {
callback(err);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return resolve(err as any); // Resolves pending promise (prevents memory leaks).
} else {
return reject(err);
Expand Down Expand Up @@ -206,6 +212,7 @@ class SocksClient extends EventEmitter implements SocksClient {
} catch (err) {
if (typeof callback === 'function') {
callback(err);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
resolve(err as any); // Resolves pending promise (prevents memory leaks).
} else {
reject(err);
Expand Down Expand Up @@ -703,7 +710,7 @@ class SocksClient extends EventEmitter implements SocksClient {
private async handleInitialSocks5AuthenticationHandshakeResponse() {
this.setState(SocksClientState.ReceivedAuthenticationResponse);

let authResult: boolean = false;
let authResult = false;

if (this.socks5ChosenAuthType === Socks5Auth.NoAuth) {
authResult = await this.handleSocks5AuthenticationNoAuthHandshakeResponse(
Expand Down
2 changes: 1 addition & 1 deletion src/common/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class SocksClientError extends Error {
* Shuffles a given array.
* @param array The array to shuffle.
*/
function shuffleArray(array: any[]) {
function shuffleArray(array: unknown[]) {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
Expand Down
12 changes: 4 additions & 8 deletions typings/client/socksclient.d.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
/// <reference types="node" />
/// <reference types="node" />
/// <reference types="node" />
/// <reference types="node" />
import { EventEmitter } from 'events';
import * as net from 'net';
import { SocksClientOptions, SocksClientChainOptions, SocksRemoteHost, SocksProxy, SocksClientBoundEvent, SocksClientEstablishedEvent, SocksUDPFrameDetails } from '../common/constants';
import { SocksClientError } from '../common/util';
import { Duplex } from 'stream';
declare interface SocksClient {
on(event: 'error', listener: (err: SocksClientError) => void): this;
on(event: 'bound', listener: (info: SocksClientBoundEvent) => void): this;
on(event: 'established', listener: (info: SocksClientEstablishedEvent) => void): this;
once(event: string, listener: (...args: any[]) => void): this;
once(event: string, listener: (...args: unknown[]) => void): this;
once(event: 'error', listener: (err: SocksClientError) => void): this;
once(event: 'bound', listener: (info: SocksClientBoundEvent) => void): this;
once(event: 'established', listener: (info: SocksClientEstablishedEvent) => void): this;
emit(event: string | symbol, ...args: any[]): boolean;
emit(event: string | symbol, ...args: unknown[]): boolean;
emit(event: 'error', err: SocksClientError): boolean;
emit(event: 'bound', info: SocksClientBoundEvent): boolean;
emit(event: 'established', info: SocksClientEstablishedEvent): boolean;
Expand All @@ -40,7 +38,7 @@ declare class SocksClient extends EventEmitter implements SocksClient {
* @param callback { Function } An optional callback function.
* @returns { Promise }
*/
static createConnection(options: SocksClientOptions, callback?: (error: unknown | null, info?: SocksClientEstablishedEvent) => void): Promise<SocksClientEstablishedEvent>;
static createConnection(options: SocksClientOptions, callback?: (error: Error | null, info?: SocksClientEstablishedEvent) => void): Promise<SocksClientEstablishedEvent>;
/**
* Creates a new SOCKS connection chain to a destination host through 2 or more SOCKS proxies.
*
Expand All @@ -50,9 +48,7 @@ declare class SocksClient extends EventEmitter implements SocksClient {
* @param callback { Function } An optional callback function.
* @returns { Promise }
*/
static createConnectionChain(options: SocksClientChainOptions, callback?: (error: any, socket?: {
socket: net.Socket;
}) => void): Promise<SocksClientEstablishedEvent>;
static createConnectionChain(options: SocksClientChainOptions, callback?: (error: Error | null, socket?: SocksClientEstablishedEvent) => void): Promise<SocksClientEstablishedEvent>;
/**
* Creates a SOCKS UDP Frame.
* @param options
Expand Down
2 changes: 2 additions & 0 deletions typings/common/constants.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/// <reference types="node" />
/// <reference types="node" />
/// <reference types="node" />
import { Duplex } from 'stream';
import { Socket, SocketConnectOpts } from 'net';
import { RequireOnlyOne } from './util';
Expand Down
2 changes: 1 addition & 1 deletion typings/common/util.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ declare class SocksClientError extends Error {
* Shuffles a given array.
* @param array The array to shuffle.
*/
declare function shuffleArray(array: any[]): void;
declare function shuffleArray(array: unknown[]): void;
declare type RequireOnlyOne<T, Keys extends keyof T = keyof T> = Pick<T, Exclude<keyof T, Keys>> & {
[K in Keys]?: Required<Pick<T, K>> & Partial<Record<Exclude<Keys, K>, undefined>>;
}[Keys];
Expand Down

0 comments on commit e776150

Please sign in to comment.