omnikey-cli 1.5.7 → 1.6.0

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.
@@ -11,12 +11,11 @@ const crypto_1 = require("crypto");
11
11
  const winston_1 = __importDefault(require("winston"));
12
12
  const zod_1 = require("zod");
13
13
  const notifyTelegram_1 = require("./notifyTelegram");
14
- const db_1 = require("./db");
15
14
  exports.logger = winston_1.default.createLogger({
16
- level: process.env.LOG_LEVEL || "info",
15
+ level: process.env.LOG_LEVEL || 'info',
17
16
  defaultMeta: { conId: (0, crypto_1.randomUUID)() },
18
17
  format: winston_1.default.format.combine(winston_1.default.format.colorize(), winston_1.default.format.timestamp(), winston_1.default.format.printf(({ timestamp, level, message, ...meta }) => {
19
- const metaString = Object.keys(meta).length ? JSON.stringify(meta) : "";
18
+ const metaString = Object.keys(meta).length ? JSON.stringify(meta) : '';
20
19
  const date = new Date(timestamp).toLocaleString();
21
20
  return `[${date}] ${level}: ${message} ${metaString}`;
22
21
  })),
@@ -24,43 +23,37 @@ exports.logger = winston_1.default.createLogger({
24
23
  });
25
24
  const app = (0, express_1.default)();
26
25
  const port = process.env.PORT ? parseInt(process.env.PORT, 10) : 6666;
27
- try {
28
- (0, db_1.initDb)(exports.logger);
29
- }
30
- catch (e) {
31
- exports.logger.error("Failed to open omnikey SQLite database:", e);
32
- }
33
- const botToken = process.env.TELEGRAM_BOT_TOKEN ?? "";
26
+ const botToken = process.env.TELEGRAM_BOT_TOKEN ?? '';
34
27
  if (botToken) {
35
28
  try {
36
29
  const bot = (0, notifyTelegram_1.initTelegram)(botToken);
37
- exports.logger.info("Telegram bot initialized", {
30
+ exports.logger.info('Telegram bot initialized', {
38
31
  botTokenSet: !!botToken,
39
32
  bot: !!bot,
40
33
  });
41
34
  (0, notifyTelegram_1.setupMessageListener)(exports.logger, bot);
42
35
  }
43
36
  catch (e) {
44
- exports.logger.error("Failed to init telegram:", e);
37
+ exports.logger.error('Failed to init telegram:', e);
45
38
  }
46
39
  }
47
40
  app.use(express_1.default.json());
48
41
  const sendBodySchema = zod_1.z.object({
49
- message: zod_1.z.string().min(1, "message must not be empty"),
50
- parseMode: zod_1.z.enum(["Markdown", "MarkdownV2", "HTML"]).optional(),
42
+ message: zod_1.z.string().min(1, 'message must not be empty'),
43
+ parseMode: zod_1.z.enum(['Markdown', 'MarkdownV2', 'HTML']).optional(),
51
44
  });
52
- app.get("/", (req, res) => {
53
- res.send("Telegram bot service (TypeScript)");
45
+ app.get('/', (req, res) => {
46
+ res.send('Telegram bot service (TypeScript)');
54
47
  });
55
- app.post("/telegram/send", async (req, res) => {
56
- exports.logger.defaultMeta = { conId: "sending notification" };
48
+ app.post('/telegram/send', async (req, res) => {
49
+ exports.logger.defaultMeta = { conId: 'sending notification' };
57
50
  const parsed = sendBodySchema.safeParse(req.body);
58
51
  if (!parsed.success) {
59
- exports.logger.warn("Invalid /telegram/send body", {
52
+ exports.logger.warn('Invalid /telegram/send body', {
60
53
  issues: parsed.error.issues,
61
54
  });
62
55
  return res.status(400).json({
63
- message: "Invalid request body",
56
+ message: 'Invalid request body',
64
57
  issues: parsed.error.issues,
65
58
  });
66
59
  }
@@ -68,16 +61,16 @@ app.post("/telegram/send", async (req, res) => {
68
61
  try {
69
62
  await (0, notifyTelegram_1.notify)(exports.logger, message, { parseMode });
70
63
  return res.json({
71
- message: "Message sent",
72
- parseMode: parseMode ?? "Markdown",
64
+ message: 'Message sent',
65
+ parseMode: parseMode ?? 'Markdown',
73
66
  });
74
67
  }
75
68
  catch (e) {
76
- exports.logger.error("Failed to send message:", e);
77
- const description = e?.response?.body
78
- ?.description ?? e.message;
69
+ exports.logger.error('Failed to send message:', e);
70
+ const description = e?.response?.body?.description ??
71
+ e.message;
79
72
  return res.status(502).json({
80
- message: "Failed to deliver message to Telegram",
73
+ message: 'Failed to deliver message to Telegram',
81
74
  error: description,
82
75
  });
83
76
  }
@@ -85,13 +78,11 @@ app.post("/telegram/send", async (req, res) => {
85
78
  app.listen(port, () => {
86
79
  exports.logger.info(`Server listening on http://localhost:${port}`);
87
80
  });
88
- process.on("SIGINT", () => {
89
- exports.logger.info("Received SIGINT. Exiting...");
90
- (0, db_1.closeDb)(exports.logger);
81
+ process.on('SIGINT', () => {
82
+ exports.logger.info('Received SIGINT. Exiting...');
91
83
  process.exit(0);
92
84
  });
93
- process.on("SIGTERM", () => {
94
- exports.logger.info("Received SIGTERM. Exiting...");
95
- (0, db_1.closeDb)(exports.logger);
85
+ process.on('SIGTERM', () => {
86
+ exports.logger.info('Received SIGTERM. Exiting...');
96
87
  process.exit(0);
97
88
  });