Skip to content

Commit e151eb8

Browse files
committed
wip
1 parent cc91f2e commit e151eb8

55 files changed

Lines changed: 315 additions & 248 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.eslintrc.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@ module.exports = {
33
parserOptions: {
44
sourceType: 'CommonJS',
55
},
6-
plugins: ['@typescript-eslint/eslint-plugin'],
6+
plugins: [
7+
'@typescript-eslint',
8+
'simple-import-sort',
9+
'import'
10+
],
711
extends: [
12+
'eslint:recommended',
813
'plugin:@typescript-eslint/recommended',
9-
'plugin:prettier/recommended',
1014
'plugin:prettier/recommended'
1115
],
1216
globals: {
@@ -27,6 +31,9 @@ module.exports = {
2731
'@typescript-eslint/no-empty-function': 'off',
2832
'@typescript-eslint/no-non-null-assertion': 'off',
2933
'@typescript-eslint/no-unused-vars': 'off',
34+
'import/first': 'error',
35+
'import/no-duplicates': 'error',
36+
'simple-import-sort/imports': 'error',
3037
'@typescript-eslint/ban-types': [
3138
'error',
3239
{

package.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"start": "ts-node --files --transpile-only ./src/main.ts",
99
"start:prod": "bash start.sh",
1010
"dev:server": "clear && tsnd --files --transpile-only --respawn --ignore-watch node_modules ./src/main.ts",
11-
"test": "clear && tsnd --files --transpile-only --respawn --ignore-watch node_modules ./test/all.test.ts"
11+
"test": "clear && tsnd --files --transpile-only --respawn --ignore-watch node_modules ./test/all.test.ts",
12+
"lint": "eslint --fix --ext .ts src"
1213
},
1314
"repository": {
1415
"type": "git",
@@ -84,12 +85,14 @@
8485
"@types/qrcode": "^1.5.0",
8586
"@types/qrcode-terminal": "^0.12.0",
8687
"@types/uuid": "^8.3.4",
87-
"@typescript-eslint/eslint-plugin": "^5.57.1",
88-
"@typescript-eslint/parser": "^5.57.1",
89-
"eslint": "^8.38.0",
88+
"@typescript-eslint/eslint-plugin": "^5.62.0",
89+
"@typescript-eslint/parser": "^5.62.0",
90+
"eslint": "^8.45.0",
9091
"eslint-config-prettier": "^8.8.0",
92+
"eslint-plugin-import": "^2.27.5",
9193
"eslint-plugin-prettier": "^4.2.1",
92-
"prettier": "^2.8.7",
94+
"eslint-plugin-simple-import-sort": "^10.0.0",
95+
"prettier": "^2.8.8",
9396
"ts-node-dev": "^2.0.0",
9497
"typescript": "^4.9.5"
9598
}

src/config/env.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import { isBooleanString } from 'class-validator';
12
import { readFileSync } from 'fs';
23
import { load } from 'js-yaml';
34
import { join } from 'path';
4-
import { isBooleanString } from 'class-validator';
55

66
export type HttpServer = { TYPE: 'http' | 'https'; PORT: number; URL: string };
77

src/config/logger.config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { configService, Log } from './env.config';
21
import dayjs from 'dayjs';
32

3+
import { configService, Log } from './env.config';
4+
45
const formatDateLog = (timestamp: number) =>
56
dayjs(timestamp)
67
.toDate()

src/db/db.connect.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import mongoose from 'mongoose';
2+
23
import { configService, Database } from '../config/env.config';
34
import { Logger } from '../config/logger.config';
45

src/db/redis.client.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { createClient, RedisClientType } from '@redis/client';
2-
import { Logger } from '../config/logger.config';
32
import { BufferJSON } from '@whiskeysockets/baileys';
3+
44
import { Redis } from '../config/env.config';
5+
import { Logger } from '../config/logger.config';
56

67
export class RedisCache {
78
constructor() {

src/main.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1+
import 'express-async-errors';
2+
3+
// import * as Sentry from '@sentry/node';
14
import compression from 'compression';
2-
import { configService, Cors, HttpServer } from './config/env.config';
35
import cors from 'cors';
46
import express, { json, NextFunction, Request, Response, urlencoded } from 'express';
57
import { join } from 'path';
8+
9+
import { configService, Cors, HttpServer } from './config/env.config';
610
import { onUnexpectedError } from './config/error.config';
711
import { Logger } from './config/logger.config';
812
import { ROOT_DIR } from './config/path.config';
9-
import { waMonitor } from './whatsapp/whatsapp.module';
10-
import { HttpStatus, router } from './whatsapp/routers/index.router';
11-
import 'express-async-errors';
1213
import { ServerUP } from './utils/server-up';
13-
import * as Sentry from '@sentry/node';
14+
import { HttpStatus, router } from './whatsapp/routers/index.router';
15+
import { waMonitor } from './whatsapp/whatsapp.module';
1416

1517
function initWA() {
1618
waMonitor.loadInstance();

src/utils/server-up.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { Express } from 'express';
22
import { readFileSync } from 'fs';
3-
import { configService, SslConf } from '../config/env.config';
4-
import * as https from 'https';
53
import * as http from 'http';
4+
import * as https from 'https';
5+
6+
import { configService, SslConf } from '../config/env.config';
67

78
export class ServerUP {
89
static #app: Express;

src/utils/use-multi-file-auth-state-db.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
proto,
77
SignalDataTypeMap,
88
} from '@whiskeysockets/baileys';
9+
910
import { configService, Database } from '../config/env.config';
1011
import { Logger } from '../config/logger.config';
1112
import { dbserver } from '../db/db.connect';
@@ -29,7 +30,9 @@ export async function useMultiFileAuthStateDb(
2930
JSON.parse(JSON.stringify(data, BufferJSON.replacer)),
3031
{ upsert: true },
3132
);
32-
} catch {}
33+
} catch (error) {
34+
logger.error(error);
35+
}
3336
};
3437

3538
const readData = async (key: string): Promise<any> => {
@@ -38,14 +41,18 @@ export async function useMultiFileAuthStateDb(
3841
const data = await collection.findOne({ _id: key });
3942
const creds = JSON.stringify(data);
4043
return JSON.parse(creds, BufferJSON.reviver);
41-
} catch {}
44+
} catch (error) {
45+
logger.error(error);
46+
}
4247
};
4348

4449
const removeData = async (key: string) => {
4550
try {
4651
await client.connect();
4752
return await collection.deleteOne({ _id: key });
48-
} catch {}
53+
} catch (error) {
54+
logger.error(error);
55+
}
4956
};
5057

5158
const creds: AuthenticationCreds = (await readData('creds')) || initAuthCreds();

src/utils/use-multi-file-auth-state-redis-db.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import {
55
proto,
66
SignalDataTypeMap,
77
} from '@whiskeysockets/baileys';
8-
import { RedisCache } from '../db/redis.client';
9-
import { Logger } from '../config/logger.config';
8+
109
import { Redis } from '../config/env.config';
10+
import { Logger } from '../config/logger.config';
11+
import { RedisCache } from '../db/redis.client';
1112

1213
export async function useMultiFileAuthStateRedisDb(cache: RedisCache): Promise<{
1314
state: AuthenticationState;

0 commit comments

Comments
 (0)