@andrey4emk/npm-app-back-b24 0.9.3 → 0.9.5
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/bitrix24/b24.js +4 -1
- package/index.js +1 -0
- package/logs/logs.js +75 -0
- package/package.json +3 -2
package/bitrix24/b24.js
CHANGED
|
@@ -90,7 +90,8 @@ export class B24Prepared {
|
|
|
90
90
|
try {
|
|
91
91
|
const { access_token, refresh_token, domain, expires_in, member_id } = req.body;
|
|
92
92
|
if (!access_token || !refresh_token || !domain || !expires_in || !member_id) {
|
|
93
|
-
|
|
93
|
+
res.status(400).json({ status: "error", message: "Не заполнены обязательные поля." });
|
|
94
|
+
return { error: true, message: "Не заполнены обязательные поля." }; // <-- ДОБАВИТЬ
|
|
94
95
|
}
|
|
95
96
|
// Если домен начинается с https:// или http:// убираем эту часть
|
|
96
97
|
let domainClean = domain.replace("https://", "").replace("http://", "");
|
|
@@ -102,8 +103,10 @@ export class B24Prepared {
|
|
|
102
103
|
member_id,
|
|
103
104
|
});
|
|
104
105
|
res.status(201).json({ status: "ok", message: "Сохранили токены. Перезапустите сервер для применения." });
|
|
106
|
+
return { error: false, message: "Токены сохранены из фронта." }; // <-- ДОБАВИТЬ
|
|
105
107
|
} catch (error) {
|
|
106
108
|
res.status(500).json({ status: "error", message: "Не удалось сохранить токен." });
|
|
109
|
+
return { error: true, message: `Не удалось сохранить токен: ${error.message}` }; // <-- ДОБАВИТЬ
|
|
107
110
|
}
|
|
108
111
|
}
|
|
109
112
|
} catch (error) {
|
package/index.js
CHANGED
|
@@ -5,3 +5,4 @@ export * from "./sendMessage/chatApp.js"; // и из chatApp.js
|
|
|
5
5
|
export * from "./sendMessage/smsgold.js"; // и из smsGold.js
|
|
6
6
|
export * from "./sendMessage/email.js"; // и из email.js
|
|
7
7
|
export * from "./sendMessage/wappi.js"; // и из wappi.js
|
|
8
|
+
export * from "./logs/logs.js"; // и из logs.js
|
package/logs/logs.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import Conf from "conf";
|
|
3
|
+
import dotEnv from "dotenv";
|
|
4
|
+
dotEnv.config();
|
|
5
|
+
|
|
6
|
+
let configDir = process.env.CONFIG_DIR || "../config";
|
|
7
|
+
let confLog = new Conf({
|
|
8
|
+
cwd: path.resolve(configDir),
|
|
9
|
+
configName: "log",
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
class LogsAPI {
|
|
13
|
+
// Дефолтные настройки логирования
|
|
14
|
+
#defaultConfig = {
|
|
15
|
+
debug: {
|
|
16
|
+
enabled: false,
|
|
17
|
+
color: "\x1b[37m",
|
|
18
|
+
json: true,
|
|
19
|
+
},
|
|
20
|
+
info: {
|
|
21
|
+
enabled: true,
|
|
22
|
+
color: "\x1b[32m",
|
|
23
|
+
json: true,
|
|
24
|
+
},
|
|
25
|
+
error: {
|
|
26
|
+
enabled: true,
|
|
27
|
+
color: "\x1b[31m",
|
|
28
|
+
json: true,
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
constructor() {
|
|
33
|
+
this.#initConfig();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Проверяем и заполняем конфиг дефолтными значениями если данных нет
|
|
37
|
+
#initConfig() {
|
|
38
|
+
for (const level of Object.keys(this.#defaultConfig)) {
|
|
39
|
+
if (!confLog.has(level)) {
|
|
40
|
+
confLog.set(level, this.#defaultConfig[level]);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
add(message, level, jsonData) {
|
|
46
|
+
const levelStr = level || "info";
|
|
47
|
+
|
|
48
|
+
// Проверяем конфиг, и если стоит что логирование отключено, то выходим
|
|
49
|
+
const isLoggingEnabled = confLog.get(`${levelStr}.enabled`);
|
|
50
|
+
if (!isLoggingEnabled) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const messageText = typeof message === "string" ? message : JSON.stringify(message);
|
|
55
|
+
|
|
56
|
+
// Цвета для разных уровней
|
|
57
|
+
const colors = {
|
|
58
|
+
info: confLog.get("info.color"), // Зеленый
|
|
59
|
+
debug: confLog.get("debug.color"), // Серый
|
|
60
|
+
error: confLog.get("error.color"), // Красный
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const resetColor = "\x1b[0m"; // Сброс цвета
|
|
64
|
+
|
|
65
|
+
// Логирование с цветом в консоль
|
|
66
|
+
const color = colors[levelStr] || "\x1b[37m"; // По умолчанию серый
|
|
67
|
+
console.log(`${color}${levelStr}: ${messageText}${resetColor}`);
|
|
68
|
+
|
|
69
|
+
if (jsonData) {
|
|
70
|
+
console.dir(jsonData, { depth: null, colors: true });
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export const logs = new LogsAPI();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@andrey4emk/npm-app-back-b24",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.5",
|
|
4
4
|
"description": "Bitrix24 OAuth helpers for Node.js projects",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -26,7 +26,8 @@
|
|
|
26
26
|
"sendMessage/chatApp.js",
|
|
27
27
|
"sendMessage/smsgold.js",
|
|
28
28
|
"sendMessage/email.js",
|
|
29
|
-
"sendMessage/wappi.js"
|
|
29
|
+
"sendMessage/wappi.js",
|
|
30
|
+
"logs/logs.js"
|
|
30
31
|
],
|
|
31
32
|
"dependencies": {
|
|
32
33
|
"luxon": "^3.4.4",
|