@intranefr/superbackend 1.6.3 → 1.6.4

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/package.json +1 -1
  2. package/src/middleware.js +28 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intranefr/superbackend",
3
- "version": "1.6.3",
3
+ "version": "1.6.4",
4
4
  "description": "Node.js middleware that gives your project backend superpowers",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/src/middleware.js CHANGED
@@ -44,6 +44,7 @@ const {
44
44
  } = require("./middleware/errorCapture");
45
45
  const rateLimiter = require("./services/rateLimiter.service");
46
46
  const pluginsService = require("./services/plugins.service");
47
+ const telegramService = require("./services/telegram.service");
47
48
 
48
49
  let errorCaptureInitialized = false;
49
50
 
@@ -229,8 +230,6 @@ function createMiddleware(options = {}) {
229
230
  maxPoolSize: 10,
230
231
  };
231
232
 
232
- const telegramService = require("./services/telegram.service");
233
-
234
233
  // Return a promise that resolves when connection is established
235
234
  const connectionPromise = mongoose
236
235
  .connect(mongoUri, connectionOptions)
@@ -251,7 +250,19 @@ const telegramService = require("./services/telegram.service");
251
250
  // Initialize Telegram bots (check telegram config)
252
251
  const telegramEnabled = options.telegram?.enabled !== false;
253
252
  if (telegramEnabled) {
254
- await telegramService.init();
253
+ const telegramInitializer =
254
+ (telegramService && typeof telegramService.initialize === "function"
255
+ ? telegramService.initialize.bind(telegramService)
256
+ : null) ||
257
+ (telegramService && typeof telegramService.init === "function"
258
+ ? telegramService.init.bind(telegramService)
259
+ : null);
260
+
261
+ if (telegramInitializer) {
262
+ await telegramInitializer();
263
+ } else {
264
+ console.warn("⚠️ Telegram service has no initialize/init method; skipping startup");
265
+ }
255
266
  } else {
256
267
  console.log("🔍 Telegram bots disabled - telegram.enabled:", options.telegram?.enabled);
257
268
  }
@@ -396,9 +407,21 @@ const telegramService = require("./services/telegram.service");
396
407
  // Initialize Telegram bots for existing connection (check telegram config)
397
408
  const telegramEnabled = options.telegram?.enabled !== false;
398
409
  if (telegramEnabled) {
399
- telegramService.init().catch(err => {
410
+ const telegramInitializer =
411
+ (telegramService && typeof telegramService.initialize === "function"
412
+ ? telegramService.initialize.bind(telegramService)
413
+ : null) ||
414
+ (telegramService && typeof telegramService.init === "function"
415
+ ? telegramService.init.bind(telegramService)
416
+ : null);
417
+
418
+ if (!telegramInitializer) {
419
+ console.warn("⚠️ Telegram service has no initialize/init method; skipping startup (existing connection)");
420
+ } else {
421
+ telegramInitializer().catch(err => {
400
422
  console.error("Failed to initialize Telegram service (existing connection):", err);
401
- });
423
+ });
424
+ }
402
425
  } else {
403
426
  console.log("🔍 Telegram bots disabled - telegram.enabled:", options.telegram?.enabled, "(existing connection)");
404
427
  }