etherproxy-lite 0.2.0 → 0.4.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.
Files changed (2) hide show
  1. package/dist/index.js +10 -14
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -3,22 +3,18 @@
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  const cafe_utility_1 = require("cafe-utility");
5
5
  const http_1 = require("http");
6
- const config = {
7
- telegram: {
8
- token: cafe_utility_1.Arrays.requireStringArgument(process.argv, 'telegram-token', process.env, 'TELEGRAM_TOKEN'),
9
- chatId: cafe_utility_1.Arrays.requireStringArgument(process.argv, 'telegram-chat-id', process.env, 'TELEGRAM_CHAT_ID')
10
- }
11
- };
12
- const TTL = 4;
13
- const TIMEOUT = 12;
14
6
  let lastErrorReport = 0;
15
7
  const sequence = cafe_utility_1.Numbers.createSequence();
16
8
  const hostname = cafe_utility_1.Arrays.requireStringArgument(process.argv, 'hostname');
17
9
  const port = cafe_utility_1.Arrays.requireNumberArgument(process.argv, 'port');
18
10
  const target = cafe_utility_1.Arrays.requireStringArgument(process.argv, 'target');
11
+ const ttl = cafe_utility_1.Arrays.requireNumberArgument(process.argv, 'ttl');
12
+ const timeout = cafe_utility_1.Arrays.requireNumberArgument(process.argv, 'timeout');
13
+ const telegramToken = cafe_utility_1.Arrays.requireStringArgument(process.argv, 'telegram-token', process.env, 'TELEGRAM_TOKEN');
14
+ const telegramChatId = cafe_utility_1.Arrays.requireStringArgument(process.argv, 'telegram-chat-id', process.env, 'TELEGRAM_CHAT_ID');
19
15
  cafe_utility_1.System.forever(async () => {
20
16
  cafe_utility_1.Cache.deleteExpired();
21
- }, cafe_utility_1.Dates.seconds(TTL));
17
+ }, cafe_utility_1.Dates.seconds(ttl));
22
18
  const server = (0, http_1.createServer)(async (request, response) => {
23
19
  request.on('error', error => {
24
20
  console.error(error);
@@ -36,10 +32,10 @@ const server = (0, http_1.createServer)(async (request, response) => {
36
32
  const id = body.id;
37
33
  delete body.id;
38
34
  const key = JSON.stringify(body);
39
- const promise = await cafe_utility_1.Cache.get(key, cafe_utility_1.Dates.seconds(TTL), async () => {
35
+ const promise = await cafe_utility_1.Cache.get(key, cafe_utility_1.Dates.seconds(ttl), async () => {
40
36
  const init = {
41
37
  method: 'POST',
42
- signal: AbortSignal.timeout(cafe_utility_1.Dates.seconds(TIMEOUT)),
38
+ signal: AbortSignal.timeout(cafe_utility_1.Dates.seconds(timeout)),
43
39
  headers: { 'Content-Type': 'application/json' },
44
40
  body: JSON.stringify({ ...body, id: sequence.next() })
45
41
  };
@@ -66,13 +62,13 @@ const server = (0, http_1.createServer)(async (request, response) => {
66
62
  server.listen(port, hostname);
67
63
  console.log(`Etherproxy-Lite is running on port ${hostname}:${port}`);
68
64
  async function sendTelegramAlert(text) {
69
- await fetch(`https://api.telegram.org/bot${config.telegram.token}/sendMessage`, {
65
+ await fetch(`https://api.telegram.org/bot${telegramToken}/sendMessage`, {
70
66
  method: 'POST',
71
67
  headers: {
72
68
  'Content-Type': 'application/json'
73
69
  },
74
- body: JSON.stringify({ chat_id: config.telegram.chatId, text }),
75
- signal: AbortSignal.timeout(cafe_utility_1.Dates.seconds(TIMEOUT))
70
+ body: JSON.stringify({ chat_id: telegramChatId, text }),
71
+ signal: AbortSignal.timeout(cafe_utility_1.Dates.seconds(timeout))
76
72
  }).catch(error => {
77
73
  console.error('Failed to send Telegram alert:', error);
78
74
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "etherproxy-lite",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "bin": {
5
5
  "etherproxy-lite": "./dist/index.js"
6
6
  },