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