baraqex 1.0.68 → 1.0.70

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/dist/index.js CHANGED
@@ -633,22 +633,30 @@ var init_api_router = __esm({
633
633
  ApiRouter = class {
634
634
  constructor(apiDir, auth = null) {
635
635
  this.router = null;
636
+ this.initialized = false;
636
637
  this.apiDir = path.resolve(process.cwd(), apiDir);
637
638
  this.auth = auth;
638
- this.initializeRouter();
639
639
  }
640
- async initializeRouter() {
640
+ async initialize() {
641
+ if (this.initialized && this.router)
642
+ return;
641
643
  try {
642
644
  const express = await import("express");
643
645
  this.router = express.default.Router();
644
646
  this.setupRoutes();
647
+ this.initialized = true;
648
+ console.log("\u2705 API Router initialized successfully");
645
649
  } catch (error) {
650
+ console.error("\u274C Failed to initialize API Router:", error);
646
651
  if (error.code === "MODULE_NOT_FOUND") {
647
652
  throw new Error("Express not installed. Run: npm install express @types/express");
648
653
  }
649
654
  throw error;
650
655
  }
651
656
  }
657
+ isInitialized() {
658
+ return this.initialized && this.router !== null;
659
+ }
652
660
  setupRoutes() {
653
661
  if (!fs.existsSync(this.apiDir)) {
654
662
  console.log(`API directory not found: ${this.apiDir}`);
@@ -686,46 +694,24 @@ var init_api_router = __esm({
686
694
  try {
687
695
  const absolutePath = path.isAbsolute(filePath) ? filePath : path.resolve(filePath);
688
696
  const fileUrl = pathToFileURL(absolutePath).href;
689
- if (process.platform === "win32") {
690
- const urlWithTimestamp = `${fileUrl}?t=${Date.now()}`;
691
- const routeModule = await import(urlWithTimestamp);
692
- if (!this.isValidRouteModule(routeModule)) {
693
- console.warn(`Invalid route module: ${filePath}`);
694
- return;
695
- }
696
- console.log(`Registering API route: ${routePath}`);
697
- const middleware = routeModule.middleware || [];
698
- for (const method of ["get", "post", "put", "delete", "patch", "options"]) {
699
- const handler = routeModule[method];
700
- if (typeof handler === "function") {
701
- const routerMethod = this.router[method];
702
- routerMethod.call(
703
- this.router,
704
- routePath,
705
- ...middleware,
706
- this.wrapHandler(handler)
707
- );
708
- }
709
- }
710
- } else {
711
- const routeModule = await import(fileUrl);
712
- if (!this.isValidRouteModule(routeModule)) {
713
- console.warn(`Invalid route module: ${filePath}`);
714
- return;
715
- }
716
- console.log(`Registering API route: ${routePath}`);
717
- const middleware = routeModule.middleware || [];
718
- for (const method of ["get", "post", "put", "delete", "patch", "options"]) {
719
- const handler = routeModule[method];
720
- if (typeof handler === "function") {
721
- const routerMethod = this.router[method];
722
- routerMethod.call(
723
- this.router,
724
- routePath,
725
- ...middleware,
726
- this.wrapHandler(handler)
727
- );
728
- }
697
+ const urlWithTimestamp = `${fileUrl}?t=${Date.now()}`;
698
+ const routeModule = await import(urlWithTimestamp);
699
+ if (!this.isValidRouteModule(routeModule)) {
700
+ console.warn(`Invalid route module: ${filePath}`);
701
+ return;
702
+ }
703
+ console.log(`Registering API route: ${routePath}`);
704
+ const middleware = routeModule.middleware || [];
705
+ for (const method of ["get", "post", "put", "delete", "patch", "options"]) {
706
+ const handler = routeModule[method];
707
+ if (typeof handler === "function") {
708
+ const routerMethod = this.router[method];
709
+ routerMethod.call(
710
+ this.router,
711
+ routePath,
712
+ ...middleware,
713
+ this.wrapHandler(handler)
714
+ );
729
715
  }
730
716
  }
731
717
  } catch (error) {
@@ -1440,8 +1426,14 @@ var init_server = __esm({
1440
1426
  throw error;
1441
1427
  }
1442
1428
  }
1443
- setupApiRoutes() {
1429
+ async setupApiRoutes() {
1444
1430
  const apiRouter = new ApiRouter(this.config.apiDir, this.auth);
1431
+ await apiRouter.initialize();
1432
+ if (!apiRouter.isInitialized() || !apiRouter.router) {
1433
+ console.warn("\u26A0\uFE0F API router not initialized properly - skipping API routes");
1434
+ return;
1435
+ }
1436
+ console.log("\u2705 Setting up API routes...");
1445
1437
  this.app.use("/api", requestLogger, apiRouter.router);
1446
1438
  this.app.get("/api-docs", (req, res) => {
1447
1439
  const apiDocs = this.generateApiDocs();