sprint-es 0.0.21 → 0.0.23

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
@@ -12,7 +12,7 @@
12
12
  <hr />
13
13
  </div>
14
14
 
15
- ## Modules
15
+ ## Features
16
16
 
17
17
  **Sprint** provides different modules depending on the required use.
18
18
 
@@ -25,6 +25,7 @@
25
25
  | CORS, Morgan, and similar modules preinstalled | 🟢 Active |
26
26
  | Preconfigured health check and 404 error pages | 🟢 Active |
27
27
  | Anti-directory listing rate limiting system | 🟢 Active |
28
+ | Logger module included to reduce memory consumption | 🟢 Active |
28
29
 
29
30
  ```ts
30
31
  import Sprint from "sprint-es";
@@ -102,4 +103,58 @@ export default defineMiddleware({
102
103
  next();
103
104
  }
104
105
  });
105
- ```
106
+ ```
107
+
108
+ #### Define Rate Limit
109
+
110
+ ```ts
111
+ import { defineMiddleware } from "sprint-es";
112
+ import { createRateLimit } from "sprint-es/rate-limit";
113
+
114
+ const ratelimitIp = createRateLimit(3, "5s", "ip", {
115
+ blockDuration: "1m"
116
+ });
117
+
118
+ export default defineMiddleware({
119
+ name: "rate-limit",
120
+ priority: 7, // Runs after logger.
121
+ include: "/**",
122
+ handler: async (req, res, next) => {
123
+ const { success, limit, remaining, reset } = await ratelimitIp.limit(req.ip);
124
+
125
+ if (!success) return res.status(429).send("Too many requests. Try again later.");
126
+
127
+ console.log(`Request allowed. Remaining: ${remaining}/${limit}`);
128
+ next();
129
+ }
130
+ });
131
+ ```
132
+
133
+ More info: https://docs.tpeoficial.com/docs/toolkitify/rate-limit/introduction
134
+
135
+ #### Use Logger
136
+
137
+ Logger is designed to reduce memory consumption when using `console.logs`. Using it will improve the performance of your API.
138
+
139
+ ```ts
140
+ import { defineMiddleware } from "sprint-es";
141
+ import { logger } from "sprint-es/logger";
142
+
143
+ export default defineMiddleware({
144
+ name: "logger",
145
+ priority: 5, // Runs first.
146
+ include: "/**", // All routes.
147
+ handler: (req, res, next) => {
148
+ const start = Date.now();
149
+
150
+ res.on("finish", () => {
151
+ const duration = Date.now() - start;
152
+ logger.info(`${req.method} ${req.originalUrl} - ${res.statusCode} (${duration}ms)`);
153
+ });
154
+
155
+ next();
156
+ }
157
+ });
158
+ ```
159
+
160
+ More info: https://docs.tpeoficial.com/docs/toolkitify/logger/introduction
@@ -205,6 +205,7 @@ class Sprint {
205
205
  key,
206
206
  limit: 5,
207
207
  interval: "10s",
208
+ blockDuration: "1m",
208
209
  storage: "memory"
209
210
  }).then((result) => {
210
211
  if (!result.success) {
@@ -254,6 +255,7 @@ class Sprint {
254
255
  const healthRoute = this.prefix ? `${this.prefix}/healthcheck` : "/healthcheck";
255
256
  this.server.listen(port, () => {
256
257
  const prefixInfo = this.prefix ? ` (prefix: ${this.prefix})` : "";
258
+ console.log("\x1B[36m\x1B[1m%s\x1B[0m", `[Sprint] Need stronger route protection? Enhance your security by verifying User-Agent, IP and request patterns. Learn more at https://docs.tpeoficial.com/docs/dymo-api/private/request-verifier.`);
257
259
  console.log("\x1B[32m%s\x1B[0m", `[Sprint] Server running on http://localhost:${port}${prefixInfo}`);
258
260
  console.log("\x1B[32m%s\x1B[0m", `[Sprint] Healthcheck: http://localhost:${port}${healthRoute}`);
259
261
  });
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const logger = require("toolkitify/logger");
4
+ Object.defineProperty(exports, "Logger", {
5
+ enumerable: true,
6
+ get: () => logger.Logger
7
+ });
8
+ Object.defineProperty(exports, "logger", {
9
+ enumerable: true,
10
+ get: () => logger.logger
11
+ });
package/dist/esm/index.js CHANGED
@@ -202,6 +202,7 @@ class Sprint {
202
202
  key,
203
203
  limit: 5,
204
204
  interval: "10s",
205
+ blockDuration: "1m",
205
206
  storage: "memory"
206
207
  }).then((result) => {
207
208
  if (!result.success) {
@@ -251,6 +252,7 @@ class Sprint {
251
252
  const healthRoute = this.prefix ? `${this.prefix}/healthcheck` : "/healthcheck";
252
253
  this.server.listen(port, () => {
253
254
  const prefixInfo = this.prefix ? ` (prefix: ${this.prefix})` : "";
255
+ console.log("\x1B[36m\x1B[1m%s\x1B[0m", `[Sprint] Need stronger route protection? Enhance your security by verifying User-Agent, IP and request patterns. Learn more at https://docs.tpeoficial.com/docs/dymo-api/private/request-verifier.`);
254
256
  console.log("\x1B[32m%s\x1B[0m", `[Sprint] Server running on http://localhost:${port}${prefixInfo}`);
255
257
  console.log("\x1B[32m%s\x1B[0m", `[Sprint] Healthcheck: http://localhost:${port}${healthRoute}`);
256
258
  });
@@ -0,0 +1,5 @@
1
+ import { Logger, logger } from "toolkitify/logger";
2
+ export {
3
+ Logger,
4
+ logger
5
+ };
@@ -0,0 +1,3 @@
1
+ import { Logger, logger } from 'toolkitify/logger';
2
+ export { Logger, logger };
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/modules/logger/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEnD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"sprint.d.ts","sourceRoot":"","sources":["../../src/sprint.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,OAAO,EAAE,aAAa,EAAsC,MAAM,SAAS,CAAC;AACrF,OAAO,OAAO,EAAE,EAAE,WAAW,EAA2C,MAAM,SAAS,CAAC;AAQxF,qBAAa,MAAM;IACR,GAAG,EAAE,WAAW,CAAC;IACxB,OAAO,CAAC,IAAI,CAAqC;IACjD,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,eAAe,CAAS;IAChC,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,eAAe,CAAS;IAChC,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,YAAY,CAAgB;IACp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OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,YAAY,CAAgB;IACpC,OAAO,CAAC,MAAM,CAAc;IAC5B,OAAO,CAAC,iBAAiB,CAA0B;gBAEvC,EACR,IAAuB,EACvB,UAAuB,EACvB,eAAiC,EACjC,SAAkB,EAClB,eAAwB,EACxB,MAAW,EACd,GAAE,aAAkB;YAeP,IAAI;IAsBlB,OAAO,CAAC,YAAY;IAoBpB;;OAEG;IACH,OAAO,CAAC,sBAAsB;IA4B9B;;OAEG;YACW,eAAe;IAgC7B,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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sprint-es",
3
- "version": "0.0.21",
3
+ "version": "0.0.23",
4
4
  "description": "Sprint - Quickly API",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -12,6 +12,11 @@
12
12
  "require": "./dist/cjs/index.cjs",
13
13
  "import": "./dist/esm/index.js"
14
14
  },
15
+ "./logger": {
16
+ "types": "./dist/types/modules/logger/index.d.ts",
17
+ "require": "./dist/cjs/modules/logger/index.cjs",
18
+ "import": "./dist/esm/modules/logger/index.js"
19
+ },
15
20
  "./rate-limit": {
16
21
  "types": "./dist/types/modules/rate-limit/index.d.ts",
17
22
  "require": "./dist/cjs/modules/rate-limit/index.cjs",
@@ -53,7 +58,7 @@
53
58
  "morgan": "^1.10.1",
54
59
  "path": "^0.12.7",
55
60
  "serve-favicon": "^2.5.1",
56
- "toolkitify": "^0.0.20"
61
+ "toolkitify": "^0.0.26"
57
62
  },
58
63
  "contributors": [
59
64
  "TPEOficial (https://github.com/TPEOficial)",
@@ -79,4 +84,4 @@
79
84
  "tabWidth": 4,
80
85
  "useTabs": false
81
86
  }
82
- }
87
+ }