sprint-es 0.0.29 → 0.0.30

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/bin/sprint-es ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { spawn } from "child_process";
4
+ import { fileURLToPath } from "url";
5
+ import { dirname, join } from "path";
6
+
7
+ const __filename = fileURLToPath(import.meta.url);
8
+ const __dirname = dirname(__filename);
9
+
10
+ const cliPath = join(__dirname, "../src/cli.ts");
11
+ const tsx = spawn("tsx", [cliPath, ...process.argv.slice(2)], {
12
+ stdio: "inherit",
13
+ shell: true
14
+ });
15
+
16
+ tsx.on("exit", (code) => {
17
+ process.exit(code || 0);
18
+ });
@@ -95,6 +95,25 @@ class Sprint {
95
95
  }
96
96
  loadDefaults() {
97
97
  this.app.disable("x-powered-by");
98
+ this.app.use((req, res, next) => {
99
+ const getAuthorization = (sources) => {
100
+ const sourceList = Array.isArray(sources) ? sources : [sources];
101
+ for (const source of sourceList) {
102
+ const [type, key] = source.split(":");
103
+ if (type === "query") {
104
+ const value = req.query[key];
105
+ if (typeof value === "string" && value.length > 0) return value;
106
+ } else if (type === "headers") {
107
+ const value = req.headers[key.toLowerCase()];
108
+ if (typeof value === "string" && value.length > 0) return value;
109
+ if (Array.isArray(value) && value.length > 0 && typeof value[0] === "string" && value[0].length > 0) return value[0];
110
+ }
111
+ }
112
+ return void 0;
113
+ };
114
+ req.sprint = { getAuthorization };
115
+ next();
116
+ });
98
117
  this.app.use((_, res, next) => {
99
118
  res.setHeader("Content-Security-Policy", "default-src 'self'");
100
119
  res.setHeader("X-Content-Type-Options", "nosniff");
@@ -25,10 +25,10 @@ function schemaMiddleware(options) {
25
25
  req.body = result.data;
26
26
  }
27
27
  }
28
- if (options.query && req.query) {
29
- const result = parseSchema(options.query, req.query);
28
+ if (options.queryParams && req.query) {
29
+ const result = parseSchema(options.queryParams, req.query);
30
30
  if (!result.success) {
31
- errors.push(...result.errors.map((e) => ({ location: "query", ...e })));
31
+ errors.push(...result.errors.map((e) => ({ location: "queryParams", ...e })));
32
32
  } else {
33
33
  req.query = result.data;
34
34
  }
package/dist/esm/index.js CHANGED
@@ -92,6 +92,25 @@ class Sprint {
92
92
  }
93
93
  loadDefaults() {
94
94
  this.app.disable("x-powered-by");
95
+ this.app.use((req, res, next) => {
96
+ const getAuthorization = (sources) => {
97
+ const sourceList = Array.isArray(sources) ? sources : [sources];
98
+ for (const source of sourceList) {
99
+ const [type, key] = source.split(":");
100
+ if (type === "query") {
101
+ const value = req.query[key];
102
+ if (typeof value === "string" && value.length > 0) return value;
103
+ } else if (type === "headers") {
104
+ const value = req.headers[key.toLowerCase()];
105
+ if (typeof value === "string" && value.length > 0) return value;
106
+ if (Array.isArray(value) && value.length > 0 && typeof value[0] === "string" && value[0].length > 0) return value[0];
107
+ }
108
+ }
109
+ return void 0;
110
+ };
111
+ req.sprint = { getAuthorization };
112
+ next();
113
+ });
95
114
  this.app.use((_, res, next) => {
96
115
  res.setHeader("Content-Security-Policy", "default-src 'self'");
97
116
  res.setHeader("X-Content-Type-Options", "nosniff");
@@ -23,10 +23,10 @@ function schemaMiddleware(options) {
23
23
  req.body = result.data;
24
24
  }
25
25
  }
26
- if (options.query && req.query) {
27
- const result = parseSchema(options.query, req.query);
26
+ if (options.queryParams && req.query) {
27
+ const result = parseSchema(options.queryParams, req.query);
28
28
  if (!result.success) {
29
- errors.push(...result.errors.map((e) => ({ location: "query", ...e })));
29
+ errors.push(...result.errors.map((e) => ({ location: "queryParams", ...e })));
30
30
  } else {
31
31
  req.query = result.data;
32
32
  }
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":""}
@@ -2,7 +2,7 @@ import { Sprint } from './sprint';
2
2
  export { Sprint, isDevelopment, isProduction } from './sprint';
3
3
  export { defineMiddleware } from './middleware';
4
4
  export { __filename, __dirname } from './utils';
5
- export type { Handler, MiddlewareConfig, SprintOptions, LoadedMiddleware } from './types';
5
+ export type { Handler, MiddlewareConfig, SprintOptions, LoadedMiddleware, AuthorizationSource, SprintRequest } from './types';
6
6
  export declare const Router: () => import('express-serve-static-core').Router;
7
7
  export default Sprint;
8
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAGhD,YAAY,EAAE,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAG1F,eAAO,MAAM,MAAM,kDAAwB,CAAC;AAG5C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,eAAe,MAAM,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAGhD,YAAY,EAAE,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAG9H,eAAO,MAAM,MAAM,kDAAwB,CAAC;AAG5C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,eAAe,MAAM,CAAC"}
@@ -2,9 +2,8 @@ import { z, ZodSchema as ZodSchemaType, ZodTypeDef } from 'zod';
2
2
  export { z };
3
3
  export interface RouteSchemaOptions {
4
4
  body?: ZodSchemaType<any, ZodTypeDef, any>;
5
- query?: ZodSchemaType<any, ZodTypeDef, any>;
5
+ queryParams?: ZodSchemaType<any, ZodTypeDef, any>;
6
6
  params?: ZodSchemaType<any, ZodTypeDef, any>;
7
- response?: ZodSchemaType<any, ZodTypeDef, any>;
8
7
  }
9
8
  export declare function defineRouteSchema<T extends RouteSchemaOptions>(schema: T): T;
10
9
  export { schemaMiddleware } from './middleware';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/modules/schemas/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,SAAS,IAAI,aAAa,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AAEhE,OAAO,EAAE,CAAC,EAAE,CAAC;AAEb,MAAM,WAAW,kBAAkB;IAC/B,IAAI,CAAC,EAAE,aAAa,CAAC,GAAG,EAAE,UAAU,EAAE,GAAG,CAAC,CAAC;IAC3C,KAAK,CAAC,EAAE,aAAa,CAAC,GAAG,EAAE,UAAU,EAAE,GAAG,CAAC,CAAC;IAC5C,MAAM,CAAC,EAAE,aAAa,CAAC,GAAG,EAAE,UAAU,EAAE,GAAG,CAAC,CAAC;IAC7C,QAAQ,CAAC,EAAE,aAAa,CAAC,GAAG,EAAE,UAAU,EAAE,GAAG,CAAC,CAAC;CAClD;AAED,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,kBAAkB,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC,CAE5E;AAED,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEhD,YAAY,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/modules/schemas/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,SAAS,IAAI,aAAa,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AAEhE,OAAO,EAAE,CAAC,EAAE,CAAC;AAEb,MAAM,WAAW,kBAAkB;IAC/B,IAAI,CAAC,EAAE,aAAa,CAAC,GAAG,EAAE,UAAU,EAAE,GAAG,CAAC,CAAC;IAC3C,WAAW,CAAC,EAAE,aAAa,CAAC,GAAG,EAAE,UAAU,EAAE,GAAG,CAAC,CAAC;IAClD,MAAM,CAAC,EAAE,aAAa,CAAC,GAAG,EAAE,UAAU,EAAE,GAAG,CAAC,CAAC;CAChD;AAED,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,kBAAkB,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC,CAE5E;AAED,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEhD,YAAY,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC"}
@@ -2,7 +2,7 @@ import { z } from 'zod';
2
2
  export type ZodSchema = z.ZodType<any>;
3
3
  export interface ZodMiddlewareOptions {
4
4
  body?: ZodSchema;
5
- query?: ZodSchema;
5
+ queryParams?: ZodSchema;
6
6
  params?: ZodSchema;
7
7
  }
8
8
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/modules/schemas/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;AAEvC,MAAM,WAAW,oBAAoB;IACjC,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,MAAM,CAAC,EAAE,SAAS,CAAC;CACtB"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/modules/schemas/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAA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C7B,OAAO,CAAC,eAAe;YAcT,UAAU;IAgDxB,OAAO,CAAC,YAAY;IAgCpB,+BAA+B;IAC/B,OAAO,CAAC,WAAW;IAMZ,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO;IAClC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO;IACnC,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO;IAClC,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO;IACrC,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO;IACpC,GAAG,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,EAAE,YAAY,CAAC,EAAE,OAAO;IAK3D,MAAM,CAAC,QAAQ,CAAC,EAAE,MAAM,IAAI,GAAG,IAAI;CAgB7C"}
@@ -1,5 +1,16 @@
1
1
  import { Request, Response, NextFunction, RequestHandler } from 'express';
2
2
  export type Handler = (req: Request, res: Response, next: NextFunction) => any;
3
+ export type AuthorizationSource = `query:${string}` | `headers:${string}`;
4
+ export interface SprintRequest {
5
+ getAuthorization: (sources: AuthorizationSource | AuthorizationSource[]) => string | undefined;
6
+ }
7
+ declare global {
8
+ namespace Express {
9
+ interface Request {
10
+ sprint: SprintRequest;
11
+ }
12
+ }
13
+ }
3
14
  /**
4
15
  * Configuration for a middleware defined in the middlewares folder.
5
16
  * Export this from your middleware file using `defineMiddleware()`.
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE1E,MAAM,MAAM,OAAO,GAAG,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,KAAK,GAAG,CAAC;AAE/E;;;GAGG;AACH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,CAAC,OAAO,EAAE,mBAAmB,GAAG,mBAAmB,EAAE,KAAK,MAAM,GAAG,SAAS,CAAC;CAClG;AAED,OAAO,CAAC,MAAM,CAAC;IACX,UAAU,OAAO,CAAC;QACd,UAAU,OAAO;YACb,MAAM,EAAE,aAAa,CAAC;SACzB;KACJ;CACJ;AAED;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC7B,4CAA4C;IAC5C,OAAO,EAAE,cAAc,GAAG,cAAc,EAAE,CAAC;IAC3C;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC5B;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC5B;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,yCAAyC;IACzC,IAAI,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,gBAAiB,SAAQ,gBAAgB;IACtD,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,aAAa;IAC1B,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IAC9B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,2DAA2D;IAC3D,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,iDAAiD;IACjD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,iDAAiD;IACjD,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,2CAA2C;IAC3C,UAAU,CAAC,EAAE,OAAO,CAAC;CACxB"}
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "sprint-es",
3
- "version": "0.0.29",
3
+ "version": "0.0.30",
4
4
  "description": "Sprint - Quickly API",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
7
7
  "types": "dist/types/index.d.ts",
8
8
  "type": "module",
9
+ "bin": "./bin/sprint-es",
9
10
  "exports": {
10
11
  ".": {
11
12
  "types": "./dist/types/index.d.ts",
@@ -62,7 +63,7 @@
62
63
  "url": "https://github.com/TPEOficial/sprint/issues"
63
64
  },
64
65
  "homepage": "https://dymo.tpeoficial.com",
65
- "dependencies": {
66
+ "dependencies": {
66
67
  "axios": "^1.13.2",
67
68
  "cors": "^2.8.5",
68
69
  "express": "^5.1.0",
@@ -71,6 +72,7 @@
71
72
  "path": "^0.12.7",
72
73
  "serve-favicon": "^2.5.1",
73
74
  "toolkitify": "^0.0.26",
75
+ "tsx": "^4.19.0",
74
76
  "zod": "^3.25.0"
75
77
  },
76
78
  "contributors": [
package/README.md DELETED
@@ -1,181 +0,0 @@
1
- <div align="center">
2
- <h1>Sprint — Edge Server</h1>
3
- <p>A next-generation backend framework that enables instant API development with a single command, enforcing clean structure by default and eliminating repetitive code while keeping projects fast, organized, and scalable.</p>
4
- <img src="https://img.shields.io/badge/TypeScript-purple?style=for-the-badge&logo=typescript&logoColor=white"/>
5
- <a href="https://github.com/TPEOficial"> <img alt="GitHub" src="https://img.shields.io/badge/GitHub-purple?style=for-the-badge&logo=github&logoColor=white"/></a>
6
- <a href="https://ko-fi.com/fjrg2007"> <img alt="Kofi" src="https://img.shields.io/badge/Ko--fi-purple?style=for-the-badge&logo=ko-fi&logoColor=white"></a>
7
- <br />
8
- <br />
9
- <a href="#quickstart">Quickstart</a>
10
- <span>&nbsp;&nbsp;•&nbsp;&nbsp;</span>
11
- <a href="https://tpe.li/dsc">Discord</a>
12
- <hr />
13
- </div>
14
-
15
- ## Quickstart
16
-
17
- ```bash
18
- npx create-sprint -y
19
- ```
20
-
21
- This will create a new Sprint project in the current directory with:
22
- - TypeScript configuration
23
- - Default routes and middlewares folders
24
- - Healthcheck endpoint
25
-
26
- ### Development
27
-
28
- ```bash
29
- npm run dev
30
- ```
31
-
32
- ### Production
33
-
34
- ```bash
35
- npm run build && npm start
36
- ```
37
-
38
- ## Features
39
-
40
- **Sprint** provides different modules depending on the required use.
41
-
42
- | Feature | Status |
43
- | ---------------------------------------------------------------------- | -------------- |
44
- | File-based dynamic routing system | 🟢 Active |
45
- | Advanced middleware system | 🟢 Active |
46
- | Pre-established security policies | 🟢 Active |
47
- | Native support for JSON, formatted and ready to use | 🟢 Active |
48
- | CORS, Morgan, and similar modules preinstalled | 🟢 Active |
49
- | Preconfigured health check and 404 error pages | 🟢 Active |
50
- | Anti-directory listing rate limiting system | 🟢 Active |
51
- | Logger module included to reduce memory consumption | 🟢 Active |
52
-
53
- ```ts
54
- import Sprint from "sprint-es";
55
-
56
- const app = new Sprint();
57
-
58
- app.get("/", (req, res) => res.send("Hello World!"));
59
- ```
60
-
61
- #### File-based dynamic routing system
62
-
63
- In this example, we generate a route called random with subroutes inside it.
64
- ```
65
- 📦example
66
- ┣ 📂middlewares
67
- ┃ ┗ 📜auth.js
68
- ┣ 📂routes
69
- ┃ ┗ 📜random.js
70
- ┗ 📜app.js
71
- ```
72
-
73
- #### Define route
74
-
75
- We define a `Router` as we would in **ExpressJS** and export it to a file with the desired route name within the `routes` folder. **Sprint** will recognize it automatically.
76
-
77
- ```ts
78
- import { Router } from "sprint-es";
79
-
80
- const router = Router();
81
-
82
- router.get("/", (req, res) => res.send("Hello World 2!"));
83
-
84
- export default router;
85
- ```
86
-
87
- #### Visual grouping of routes
88
-
89
- You can create folders with names in parentheses to group your routes more easily without affecting the path in the API URL.
90
-
91
- ```
92
- 📦routes
93
- ┣ 📂(auth)
94
- ┃ ┣ 📂(protected)
95
- ┃ ┃ ┣ 📂settings
96
- ┃ ┃ ┃ ┗ 📜index.js
97
- ┃ ┃ ┗ 📜profile.js
98
- ┃ ┗ 📜login.js
99
- ```
100
-
101
- #### Define middleware
102
-
103
- We export a `defineMiddleware` function in a file with the name of your choice in the `middlewares` folder. **Sprint** will recognize it automatically.
104
-
105
- ```ts
106
- import { defineMiddleware } from "sprint-es";
107
-
108
- export default defineMiddleware({
109
- name: "admin",
110
- priority: 20, // Runs after auth.
111
- include: "/admin/**",
112
- handler: (req, res, next) => {
113
- if (!req.user) return res.status(401).json({ error: "Not authenticated" });
114
-
115
- if (req.user.role !== "admin") {
116
- console.log(`[Sprint Example: Admin] Access denied for user: ${req.user.name} (role: ${req.user.role})`);
117
- return res.status(403).json({
118
- error: "Forbidden",
119
- message: "Admin access required"
120
- });
121
- }
122
-
123
- console.log(`[Sprint Example: Admin] Admin access granted for: ${req.user.name}`);
124
- next();
125
- }
126
- });
127
- ```
128
-
129
- #### Define Rate Limit
130
-
131
- ```ts
132
- import { defineMiddleware } from "sprint-es";
133
- import { createRateLimit } from "sprint-es/rate-limit";
134
-
135
- const ratelimitIp = createRateLimit(3, "5s", "ip", {
136
- blockDuration: "1m"
137
- });
138
-
139
- export default defineMiddleware({
140
- name: "rate-limit",
141
- priority: 7, // Runs after logger.
142
- include: "/**",
143
- handler: async (req, res, next) => {
144
- const { success, limit, remaining, reset } = await ratelimitIp.limit(req.ip);
145
-
146
- if (!success) return res.status(429).send("Too many requests. Try again later.");
147
-
148
- console.log(`Request allowed. Remaining: ${remaining}/${limit}`);
149
- next();
150
- }
151
- });
152
- ```
153
-
154
- More info: https://docs.tpeoficial.com/docs/toolkitify/rate-limit/introduction
155
-
156
- #### Use Logger
157
-
158
- Logger is designed to reduce memory consumption when using `console.logs`. Using it will improve the performance of your API.
159
-
160
- ```ts
161
- import { defineMiddleware } from "sprint-es";
162
- import { logger } from "sprint-es/logger";
163
-
164
- export default defineMiddleware({
165
- name: "logger",
166
- priority: 5, // Runs first.
167
- include: "/**", // All routes.
168
- handler: (req, res, next) => {
169
- const start = Date.now();
170
-
171
- res.on("finish", () => {
172
- const duration = Date.now() - start;
173
- logger.info(`${req.method} ${req.originalUrl} - ${res.statusCode} (${duration}ms)`);
174
- });
175
-
176
- next();
177
- }
178
- });
179
- ```
180
-
181
- More info: https://docs.tpeoficial.com/docs/toolkitify/logger/introduction