@kipicore/dbcore 1.1.707 → 1.1.709
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/commonValidator/joiSchemaBuilder.js +2 -14
- package/dist/helpers/apiError.d.ts +5 -0
- package/dist/helpers/apiError.js +15 -0
- package/dist/helpers/index.d.ts +2 -0
- package/dist/helpers/index.js +2 -0
- package/dist/helpers/telegramNotification.d.ts +1 -0
- package/dist/helpers/telegramNotification.js +48 -0
- package/dist/types/commonType.d.ts +88 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +1 -0
- package/package.json +3 -1
|
@@ -6,19 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.buildSchema = void 0;
|
|
7
7
|
const joi_1 = __importDefault(require("joi"));
|
|
8
8
|
const httpStatusCode_1 = require("../constants/httpStatusCode");
|
|
9
|
-
|
|
10
|
-
constructor(statusCode, message, isOperational = true, stack = '') {
|
|
11
|
-
super(message);
|
|
12
|
-
this.statusCode = statusCode;
|
|
13
|
-
this.isOperational = isOperational;
|
|
14
|
-
if (stack) {
|
|
15
|
-
this.stack = stack;
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
Error.captureStackTrace(this, this.constructor);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
9
|
+
const apiError_1 = __importDefault(require("../helpers/apiError"));
|
|
22
10
|
// GENERIC BUILDER
|
|
23
11
|
const buildSchema = (base, rules = {}) => {
|
|
24
12
|
let schema = base;
|
|
@@ -62,7 +50,7 @@ class BaseValidator {
|
|
|
62
50
|
const { error, value } = schema.validate({ ...req.body, ...req.query, ...req.params }, { ...defaultOptions, ...options });
|
|
63
51
|
if (error) {
|
|
64
52
|
const errorMessage = error.details.map(d => d.message).join(', ');
|
|
65
|
-
throw new
|
|
53
|
+
throw new apiError_1.default(httpStatusCode_1.HTTP_STATUS_CODE.BAD_REQUEST, errorMessage);
|
|
66
54
|
}
|
|
67
55
|
req.body = value;
|
|
68
56
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class ApiError extends Error {
|
|
4
|
+
constructor(statusCode, message, isOperational = true, stack = '') {
|
|
5
|
+
super(message);
|
|
6
|
+
this.statusCode = statusCode;
|
|
7
|
+
this.isOperational = isOperational;
|
|
8
|
+
if (stack !== '') {
|
|
9
|
+
this.stack = stack;
|
|
10
|
+
}
|
|
11
|
+
else
|
|
12
|
+
Error.captureStackTrace(this, this.constructor);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.default = ApiError;
|
package/dist/helpers/index.d.ts
CHANGED
package/dist/helpers/index.js
CHANGED
|
@@ -19,3 +19,5 @@ __exportStar(require("./utils"), exports);
|
|
|
19
19
|
__exportStar(require("./sendEmail"), exports);
|
|
20
20
|
__exportStar(require("./sendNotification"), exports);
|
|
21
21
|
__exportStar(require("./sendSMS"), exports);
|
|
22
|
+
__exportStar(require("./telegramNotification"), exports);
|
|
23
|
+
__exportStar(require("./apiError"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const sendErrorNotification: (errorType: string, errorMessage: string, endpoint: string, requestBody: any, headersData: any) => void;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.sendErrorNotification = void 0;
|
|
7
|
+
/* eslint-disable camelcase */
|
|
8
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
9
|
+
const node_telegram_bot_api_1 = __importDefault(require("node-telegram-bot-api"));
|
|
10
|
+
const dotenv_1 = __importDefault(require("dotenv"));
|
|
11
|
+
dotenv_1.default.config();
|
|
12
|
+
const BOT_TOKEN = process.env.BOT_TOKEN || '';
|
|
13
|
+
const ADMIN_CHAT_ID = process.env.ADMIN_CHAT_ID || '';
|
|
14
|
+
const bot = new node_telegram_bot_api_1.default(BOT_TOKEN, { polling: false });
|
|
15
|
+
const sendErrorNotification = (errorType, errorMessage, endpoint, requestBody, headersData) => {
|
|
16
|
+
const formattedMessage = `
|
|
17
|
+
⚠️ **ERROR NOTIFICATION** ⚠️
|
|
18
|
+
|
|
19
|
+
🕒 **Time:** \`${new Date().toLocaleString('en-IN', { timeZone: 'Asia/Kolkata' })}\`
|
|
20
|
+
|
|
21
|
+
❗ **Error Type:** \`${errorType.toUpperCase()}\`
|
|
22
|
+
📜 **Message:** \`${errorMessage}\`
|
|
23
|
+
|
|
24
|
+
🛠️ **Endpoint:** \`${endpoint}\`
|
|
25
|
+
|
|
26
|
+
📬 **Headers Data:**
|
|
27
|
+
\`\`\`json
|
|
28
|
+
${JSON.stringify(headersData, null, 2)}
|
|
29
|
+
\`\`\`
|
|
30
|
+
|
|
31
|
+
📩 **Request Body:**
|
|
32
|
+
\`\`\`json
|
|
33
|
+
${JSON.stringify(requestBody, null, 2)}
|
|
34
|
+
\`\`\`
|
|
35
|
+
|
|
36
|
+
📌 **Take Action ASAP!**
|
|
37
|
+
`;
|
|
38
|
+
bot.sendMessage(ADMIN_CHAT_ID, formattedMessage, {
|
|
39
|
+
parse_mode: 'Markdown',
|
|
40
|
+
})
|
|
41
|
+
.then(() => {
|
|
42
|
+
console.log('Error notification sent to Telegram successfully.');
|
|
43
|
+
})
|
|
44
|
+
.catch((err) => {
|
|
45
|
+
console.error(`Failed to send error notification: ${err}`);
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
exports.sendErrorNotification = sendErrorNotification;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Joi from 'joi';
|
|
2
|
-
import { APP_TYPE } from '../constants/app';
|
|
2
|
+
import { APP_TYPE, SOCKET_EVENTS } from '../constants/app';
|
|
3
3
|
export type TCustomHeaders = {
|
|
4
4
|
appType?: APP_TYPE;
|
|
5
5
|
token?: string;
|
|
@@ -35,3 +35,90 @@ export interface CrudValidatorRules<TField> {
|
|
|
35
35
|
getById?: SchemaRules<TField>;
|
|
36
36
|
delete?: SchemaRules<TField>;
|
|
37
37
|
}
|
|
38
|
+
export type TApiResponse = {
|
|
39
|
+
statusCode: number;
|
|
40
|
+
status: boolean;
|
|
41
|
+
message: string;
|
|
42
|
+
data?: [] | object | null;
|
|
43
|
+
dataDetails?: [] | object | null;
|
|
44
|
+
error?: string | [] | object;
|
|
45
|
+
};
|
|
46
|
+
export type TPaginastionOptions<T> = {
|
|
47
|
+
limit: number | undefined;
|
|
48
|
+
totalRecords: number;
|
|
49
|
+
totalPages: number;
|
|
50
|
+
hasPreviousPage: boolean;
|
|
51
|
+
hasNextPage: boolean;
|
|
52
|
+
currentPage: number;
|
|
53
|
+
recordList?: T[];
|
|
54
|
+
};
|
|
55
|
+
export type TPdfOption = {
|
|
56
|
+
data: any;
|
|
57
|
+
templateName: string;
|
|
58
|
+
customPath?: string;
|
|
59
|
+
customPdfOptions?: object;
|
|
60
|
+
customFileName?: string;
|
|
61
|
+
customstoragePath?: string;
|
|
62
|
+
isNotNeedToReadFile?: boolean;
|
|
63
|
+
};
|
|
64
|
+
export type TChangePassword = {
|
|
65
|
+
userId?: number;
|
|
66
|
+
oldPassword: string;
|
|
67
|
+
newPassword: string;
|
|
68
|
+
};
|
|
69
|
+
export type TWhereOptions<T> = {
|
|
70
|
+
[P in keyof T]?: {
|
|
71
|
+
eq?: T[P];
|
|
72
|
+
ne?: T[P];
|
|
73
|
+
gte?: T[P];
|
|
74
|
+
gt?: T[P];
|
|
75
|
+
lte?: T[P];
|
|
76
|
+
lt?: T[P];
|
|
77
|
+
is?: T[P];
|
|
78
|
+
notIn?: T[P][];
|
|
79
|
+
in?: T[P][];
|
|
80
|
+
like?: string;
|
|
81
|
+
notLike?: string;
|
|
82
|
+
iLike?: string;
|
|
83
|
+
notILike?: string;
|
|
84
|
+
startsWith?: string;
|
|
85
|
+
endsWith?: string;
|
|
86
|
+
substring?: string;
|
|
87
|
+
regexp?: string;
|
|
88
|
+
notRegexp?: string;
|
|
89
|
+
iRegexp?: string;
|
|
90
|
+
notIRegexp?: string;
|
|
91
|
+
between?: [T[P], T[P]];
|
|
92
|
+
notBetween?: [T[P], T[P]];
|
|
93
|
+
overlap?: T[P][];
|
|
94
|
+
contains?: T[P][];
|
|
95
|
+
contained?: T[P][];
|
|
96
|
+
adjacent?: T[P][];
|
|
97
|
+
strictLeft?: T[P][];
|
|
98
|
+
strictRight?: T[P][];
|
|
99
|
+
noExtendRight?: T[P][];
|
|
100
|
+
noExtendLeft?: T[P][];
|
|
101
|
+
and?: TWhereOptions<T>[];
|
|
102
|
+
or?: TWhereOptions<T>[];
|
|
103
|
+
not?: TWhereOptions<T>;
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
export type TSocketEventPayload = {
|
|
107
|
+
eventName?: SOCKET_EVENTS;
|
|
108
|
+
payload: {
|
|
109
|
+
event: SOCKET_EVENTS;
|
|
110
|
+
data: any;
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
export type socketPayload = {
|
|
114
|
+
event: SOCKET_EVENTS;
|
|
115
|
+
data: any;
|
|
116
|
+
};
|
|
117
|
+
export interface CrudValidatorRules<TField> {
|
|
118
|
+
create?: SchemaRules<TField>;
|
|
119
|
+
update?: SchemaRules<TField>;
|
|
120
|
+
getAll?: SchemaRules<TField>;
|
|
121
|
+
getAllWithPagination?: SchemaRules<TField>;
|
|
122
|
+
getById?: SchemaRules<TField>;
|
|
123
|
+
delete?: SchemaRules<TField>;
|
|
124
|
+
}
|
package/dist/types/index.d.ts
CHANGED
package/dist/types/index.js
CHANGED
|
@@ -279,3 +279,4 @@ __exportStar(require("./sportsAcademyType"), exports);
|
|
|
279
279
|
__exportStar(require("./userAmenityType"), exports);
|
|
280
280
|
__exportStar(require("./userAcademyMetaType"), exports);
|
|
281
281
|
__exportStar(require("./sportDataApproveType"), exports);
|
|
282
|
+
__exportStar(require("./commonType"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kipicore/dbcore",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.709",
|
|
4
4
|
"description": "Reusable DB core package with Postgres, MongoDB, models, services, interfaces, and types",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -52,6 +52,7 @@
|
|
|
52
52
|
"ioredis": "^5.11.1",
|
|
53
53
|
"joi": "^18.0.1",
|
|
54
54
|
"mongoose": "^8.5.2",
|
|
55
|
+
"node-telegram-bot-api": "^1.2.0",
|
|
55
56
|
"pg": "^8.12.0",
|
|
56
57
|
"sequelize": "^6.37.3",
|
|
57
58
|
"uuid": "^8.3.2",
|
|
@@ -64,6 +65,7 @@
|
|
|
64
65
|
"@types/express": "^5.0.6",
|
|
65
66
|
"@types/mongoose": "^5.11.97",
|
|
66
67
|
"@types/node": "^24.5.2",
|
|
68
|
+
"@types/node-telegram-bot-api": "^0.64.15",
|
|
67
69
|
"@types/sequelize": "^4.28.14",
|
|
68
70
|
"country-state-city": "^3.2.1",
|
|
69
71
|
"eslint": "^9.17.0",
|