@catbee/utils 2.0.0 → 2.0.1

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/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
  A modular, production-grade utility toolkit for Node.js and TypeScript, designed for robust, scalable applications. All utilities are tree-shakable and can be imported independently.
7
7
 
8
8
  <div style="display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 1rem 0;">
9
- <img src="https://img.shields.io/badge/build-passing-brightgreen" alt="Build Status" />
9
+ <img src="https://github.com/catbee-technologies/catbee-utils/actions/workflows/ci.yml/badge.svg?label=Build" alt="Build Status" />
10
10
  <img src="https://codecov.io/gh/catbee-technologies/catbee-utils/graph/badge.svg?token=XAJHK6R1OQ" alt="Coverage" />
11
11
  <img src="https://img.shields.io/node/v/@catbee/utils" alt="Node Version" />
12
12
  <img src="https://img.shields.io/npm/v/@catbee/utils" alt="NPM Version" />
@@ -65,7 +65,10 @@ const config = new ServerConfigBuilder()
65
65
 
66
66
  const server = new ExpressServer(config, {
67
67
  beforeInit: srv => console.log('Initializing server...'),
68
+ beforeRoutes: app => console.log('Setting up routes...'),
69
+ afterRoutes: app => console.log('Routes initialized.'),
68
70
  afterInit: srv => console.log('Server initialized'),
71
+ onServerCreated: srv => console.log('HTTP/HTTPS server instance created.'),
69
72
  beforeStart: app => console.log('Starting server...'),
70
73
  afterStart: srv => console.log('Server started!'),
71
74
  beforeStop: srv => console.log('Stopping server...'),
@@ -173,4 +176,4 @@ Both import styles are fully supported and tree-shakable. Use whichever fits you
173
176
 
174
177
  ## 📜 License
175
178
 
176
- MIT © Catbee Technologies (see the [LICENSE](https://catbee.in/license/) file for the full text)
179
+ MIT © Catbee Technologies (see the [LICENSE](https://catbee.in/license) file for the full text)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@catbee/utils",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "A modular, production-grade utility toolkit for Node.js and TypeScript, designed for robust, scalable applications (including Express-based services). All utilities are tree-shakable and can be imported independently.",
5
5
  "publishConfig": {
6
6
  "access": "public"
package/server/index.cjs CHANGED
@@ -860,6 +860,7 @@ var ExpressServer = class {
860
860
  async initialize() {
861
861
  await this.runHook("beforeInit", this);
862
862
  await this.setupMiddleware();
863
+ await this.runHook("beforeRoutes", this.app);
863
864
  await this.setupRoutes();
864
865
  await this.runHook("afterInit", this);
865
866
  }
@@ -1208,6 +1209,7 @@ var ExpressServer = class {
1208
1209
  }
1209
1210
  const routerToUse = this.externalRouter || this.rootRouter;
1210
1211
  this.app.use(this.globalPrefix, routerToUse);
1212
+ await this.runHook("afterRoutes", this.app);
1211
1213
  this.app.use((req, res) => {
1212
1214
  const status = httpStatusCodes.HttpStatusCodes.NOT_FOUND;
1213
1215
  const response$1 = response.createFinalErrorResponse(req, status, `Route ${req.method.toUpperCase()} ${req.path} not found`);
@@ -1361,6 +1363,7 @@ var ExpressServer = class {
1361
1363
  resolve(this.server);
1362
1364
  }, "onListening");
1363
1365
  this.server = this.createServerInstance(onListening);
1366
+ this.runHook("onServerCreated", this.server);
1364
1367
  this.setupConnectionTracking();
1365
1368
  this.setupServerErrorHandling(reject);
1366
1369
  } catch (error) {
package/server/index.mjs CHANGED
@@ -853,6 +853,7 @@ var ExpressServer = class {
853
853
  async initialize() {
854
854
  await this.runHook("beforeInit", this);
855
855
  await this.setupMiddleware();
856
+ await this.runHook("beforeRoutes", this.app);
856
857
  await this.setupRoutes();
857
858
  await this.runHook("afterInit", this);
858
859
  }
@@ -1201,6 +1202,7 @@ var ExpressServer = class {
1201
1202
  }
1202
1203
  const routerToUse = this.externalRouter || this.rootRouter;
1203
1204
  this.app.use(this.globalPrefix, routerToUse);
1205
+ await this.runHook("afterRoutes", this.app);
1204
1206
  this.app.use((req, res) => {
1205
1207
  const status = HttpStatusCodes.NOT_FOUND;
1206
1208
  const response = createFinalErrorResponse(req, status, `Route ${req.method.toUpperCase()} ${req.path} not found`);
@@ -1354,6 +1356,7 @@ var ExpressServer = class {
1354
1356
  resolve(this.server);
1355
1357
  }, "onListening");
1356
1358
  this.server = this.createServerInstance(onListening);
1359
+ this.runHook("onServerCreated", this.server);
1357
1360
  this.setupConnectionTracking();
1358
1361
  this.setupServerErrorHandling(reject);
1359
1362
  } catch (error) {
package/types/index.d.ts CHANGED
@@ -24,6 +24,7 @@
24
24
 
25
25
  import { json, urlencoded, Request, Response, Express, NextFunction } from 'express';
26
26
  import http from 'node:http';
27
+ import https from 'node:https';
27
28
  import { ExpressServer } from '@catbee/utils/server';
28
29
  import { HelmetOptions } from 'helmet';
29
30
  import { CompressionOptions } from 'compression';
@@ -554,8 +555,14 @@ interface CatbeeServerConfig {
554
555
  interface CatbeeServerHooks {
555
556
  /** Called before middleware & routes initialize */
556
557
  beforeInit?: (server: ExpressServer) => Promise<void> | void;
558
+ /** Called before any routes are registered */
559
+ beforeRoutes?: (app: Express) => Promise<void> | void;
560
+ /** Called after all routes are registered, before error handling middleware */
561
+ afterRoutes?: (app: Express) => Promise<void> | void;
557
562
  /** Called after middleware & routes initialize */
558
563
  afterInit?: (server: ExpressServer) => Promise<void> | void;
564
+ /** Called when the underlying HTTP/HTTPS server instance is created */
565
+ onServerCreated?: (server: http.Server | https.Server) => Promise<void> | void;
559
566
  /** Called before server starts listening */
560
567
  beforeStart?: (app: Express) => Promise<void> | void;
561
568
  /** Called after server is ready */