chore(): fix and run linter, bump node version to LTS

This commit is contained in:
Tiago Siebler
2024-12-11 16:40:54 +00:00
parent e92c083961
commit d363c51b2b
14 changed files with 330 additions and 287 deletions

View File

@@ -70,10 +70,15 @@ if (ENABLE_HTTP_TRACE) {
export default abstract class BaseRestClient {
private options: RestClientOptions;
private baseUrl: string;
private globalRequestOptions: AxiosRequestConfig;
private apiKey: string | undefined;
private apiSecret: string | undefined;
private apiPass: string | undefined;
/** Defines the client type (affecting how requests & signatures behave) */
@@ -292,6 +297,7 @@ export default abstract class BaseRestClient {
params?: TParams,
isPublicApi?: true,
): Promise<UnsignedRequest<TParams>>;
private async prepareSignParams<TParams extends object | undefined>(
method: Method,
endpoint: string,
@@ -299,6 +305,7 @@ export default abstract class BaseRestClient {
params?: TParams,
isPublicApi?: false | undefined,
): Promise<SignedRequest<TParams>>;
private async prepareSignParams<TParams extends object | undefined>(
method: Method,
endpoint: string,

View File

@@ -57,6 +57,7 @@ export abstract class BaseWebsocketClient<
private wsStore: WsStore<TWSKey, TWSTopicSubscribeEventArgs>;
protected logger: typeof DefaultLogger;
protected options: WebsocketClientOptions;
constructor(
@@ -87,7 +88,9 @@ export abstract class BaseWebsocketClient<
): boolean;
protected abstract shouldAuthOnConnect(wsKey: TWSKey): boolean;
protected abstract getWsUrl(wsKey: TWSKey): string;
protected abstract getMaxTopicsPerSubscribeEvent(
wsKey: TWSKey,
): number | null;
@@ -280,7 +283,7 @@ export abstract class BaseWebsocketClient<
recvWindow,
);
this.logger.info(`Sending auth request...`, {
this.logger.info('Sending auth request...', {
...LOGGER_CATEGORY,
wsKey,
});
@@ -441,7 +444,7 @@ export abstract class BaseWebsocketClient<
public tryWsSend(wsKey: TWSKey, wsMessage: string) {
try {
this.logger.silly(`Sending upstream ws message: `, {
this.logger.silly('Sending upstream ws message: ', {
...LOGGER_CATEGORY,
wsMessage,
wsKey,
@@ -459,7 +462,7 @@ export abstract class BaseWebsocketClient<
}
ws.send(wsMessage);
} catch (e) {
this.logger.error(`Failed to send WS message`, {
this.logger.error('Failed to send WS message', {
...LOGGER_CATEGORY,
wsMessage,
wsKey,
@@ -552,7 +555,7 @@ export abstract class BaseWebsocketClient<
if (typeof msg === 'object') {
if (typeof msg['code'] === 'number') {
if (msg.event === 'login' && msg.code === 0) {
this.logger.info(`Successfully authenticated WS client`, {
this.logger.info('Successfully authenticated WS client', {
...LOGGER_CATEGORY,
wsKey,
});
@@ -565,7 +568,7 @@ export abstract class BaseWebsocketClient<
if (msg['event']) {
if (msg.event === 'error') {
this.logger.error(`WS Error received`, {
this.logger.error('WS Error received', {
...LOGGER_CATEGORY,
wsKey,
message: msg || 'no message',

View File

@@ -18,6 +18,7 @@ export default class WsStore<
> {
private wsState: Record<string, WsStoredState<TWSTopicSubscribeEventArgs>> =
{};
private logger: typeof DefaultLogger;
constructor(logger: typeof DefaultLogger) {
@@ -29,10 +30,12 @@ export default class WsStore<
key: WsKey,
createIfMissing?: true,
): WsStoredState<TWSTopicSubscribeEventArgs>;
get(
key: WsKey,
createIfMissing?: false,
): WsStoredState<TWSTopicSubscribeEventArgs> | undefined;
get(
key: WsKey,
createIfMissing?: boolean,

View File

@@ -78,7 +78,7 @@ export function isWsFuturesPositionsSnapshotEvent(
*/
export function assertMarginType(marginType: string): marginType is MarginType {
if (marginType !== 'isolated' && marginType !== 'crossed') {
throw new Error(`MarginType should be one of: crossed | isolated`);
throw new Error('MarginType should be one of: crossed | isolated');
}
return true;
}

View File

@@ -138,7 +138,7 @@ export function getMaxTopicsPerSubscribeEvent(wsKey: WsKey): number | null {
return 15;
}
default: {
throw neverGuard(wsKey, `getWsKeyForTopic(): Unhandled wsKey`);
throw neverGuard(wsKey, 'getWsKeyForTopic(): Unhandled wsKey');
}
}
}
@@ -162,7 +162,7 @@ export async function getWsAuthSignature(
}> {
if (!apiKey || !apiSecret || !apiPass) {
throw new Error(
`Cannot auth - missing api key, secret or passcode in config`,
'Cannot auth - missing api key, secret or passcode in config',
);
}
const signatureExpiresAt = ((Date.now() + recvWindow) / 1000).toFixed(0);