@seip/bluebird-js 0.0.1 → 0.1.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.
Files changed (81) hide show
  1. package/.env_example +53 -53
  2. package/AGENTS.md +426 -403
  3. package/LICENSE +1 -1
  4. package/README.md +292 -285
  5. package/app/routes/api.js +50 -50
  6. package/app/routes/web.js +55 -53
  7. package/app/views/about.js +63 -0
  8. package/app/views/dashboard.js +147 -0
  9. package/app/views/index.js +80 -0
  10. package/app/views/layouts/main/view.js +81 -0
  11. package/app/views/legal/terms.html +19 -0
  12. package/app/views/login.js +80 -0
  13. package/core/app.d.ts +18 -18
  14. package/core/app.js +684 -644
  15. package/core/auth.d.ts +13 -13
  16. package/core/auth.js +326 -326
  17. package/core/cache.d.ts +17 -17
  18. package/core/cache.js +475 -475
  19. package/core/cli/doctor.js +287 -287
  20. package/core/cli/ecosystem.js +162 -162
  21. package/core/cli/init.js +779 -779
  22. package/core/cli/migrate.js +541 -541
  23. package/core/cli/model.js +66 -66
  24. package/core/cli/nginx.js +199 -199
  25. package/core/cli/route.js +120 -120
  26. package/core/cli/view.js +55 -36
  27. package/core/config.d.ts +3 -3
  28. package/core/config.js +111 -111
  29. package/core/csrf.d.ts +3 -3
  30. package/core/csrf.js +114 -114
  31. package/core/database.d.ts +15 -15
  32. package/core/database.js +636 -636
  33. package/core/debug.d.ts +3 -3
  34. package/core/debug.js +249 -249
  35. package/core/hash.d.ts +3 -3
  36. package/core/hash.js +194 -194
  37. package/core/html.d.ts +42 -0
  38. package/core/html.js +217 -0
  39. package/core/index.d.ts +1176 -1071
  40. package/core/logger.d.ts +3 -3
  41. package/core/logger.js +127 -124
  42. package/core/middleware.d.ts +3 -3
  43. package/core/middleware.js +28 -28
  44. package/core/model.d.ts +19 -19
  45. package/core/model.js +600 -600
  46. package/core/queue.d.ts +13 -13
  47. package/core/queue.js +172 -172
  48. package/core/ratelimit.d.ts +3 -3
  49. package/core/ratelimit.js +145 -145
  50. package/core/redis.d.ts +21 -21
  51. package/core/redis.js +230 -230
  52. package/core/render-cache.js +212 -0
  53. package/core/render.d.ts +3 -3
  54. package/core/render.js +199 -555
  55. package/core/router.d.ts +3 -3
  56. package/core/router.js +171 -171
  57. package/core/seo.d.ts +3 -3
  58. package/core/seo.js +106 -106
  59. package/core/swagger.d.ts +3 -3
  60. package/core/swagger.js +60 -60
  61. package/core/upload.d.ts +13 -13
  62. package/core/upload.js +102 -102
  63. package/core/util/colors.js +82 -82
  64. package/core/validate.d.ts +15 -15
  65. package/core/validate.js +364 -364
  66. package/core/view-loader.js +162 -0
  67. package/core/vite.d.ts +3 -3
  68. package/core/vite.js +145 -145
  69. package/core/ws.d.ts +13 -13
  70. package/core/ws.js +245 -245
  71. package/index.js +18 -18
  72. package/jsconfig.json +15 -15
  73. package/package.json +85 -86
  74. package/production.md +273 -273
  75. package/public/css/bluebird.min.css +1 -1
  76. package/public/js/bluebird-client.js +1780 -1662
  77. package/public/js/bluebird.min.js +1072 -1072
  78. package/app/views/about.html +0 -161
  79. package/app/views/dashboard.html +0 -140
  80. package/app/views/index.html +0 -150
  81. package/app/views/login.html +0 -144
package/core/csrf.js CHANGED
@@ -1,114 +1,114 @@
1
- import { createHmac, randomBytes, timingSafeEqual } from "node:crypto";
2
- import Config from "./config.js";
3
-
4
- const propsConfig = Config.props();
5
- const defaultSecret = propsConfig.jwtSecret || "bluebird-csrf-secret-key-32-chars!";
6
-
7
- /**
8
- * Native CSRF protection module using HMAC-SHA256 signed tokens without external dependencies.
9
- */
10
- class Csrf {
11
- /**
12
- * Generates a signed CSRF token string.
13
- * @param {string} [secret] - Secret key used for signing.
14
- * @returns {string} Hex encoded token in format salt.timestamp.signature.
15
- */
16
- static generateToken(secret = process.env.JWT_SECRET || defaultSecret) {
17
- const salt = randomBytes(16).toString("hex");
18
- const timestamp = Date.now().toString(36);
19
- const signature = createHmac("sha256", secret)
20
- .update(`${salt}.${timestamp}`)
21
- .digest("hex");
22
-
23
- return `${salt}.${timestamp}.${signature}`;
24
- }
25
-
26
- /**
27
- * Verifies the authenticity and validity of a CSRF token.
28
- * @param {string} token - The CSRF token to verify.
29
- * @param {string} [secret] - Secret key used for verification.
30
- * @param {number} [maxAgeMs=86400000] - Maximum token age in milliseconds (default 24h).
31
- * @returns {boolean} True if the token is valid.
32
- */
33
- static verifyToken(token, secret = process.env.JWT_SECRET || defaultSecret, maxAgeMs = 86400000) {
34
- if (!token || typeof token !== "string") return false;
35
-
36
- const parts = token.split(".");
37
- if (parts.length !== 3) return false;
38
-
39
- const [salt, timestampStr, signature] = parts;
40
- const timestamp = parseInt(timestampStr, 36);
41
-
42
- if (isNaN(timestamp) || Date.now() - timestamp > maxAgeMs) {
43
- return false;
44
- }
45
-
46
- const expected = createHmac("sha256", secret)
47
- .update(`${salt}.${timestampStr}`)
48
- .digest("hex");
49
-
50
- const sigBuf = Buffer.from(signature);
51
- const expBuf = Buffer.from(expected);
52
-
53
- if (sigBuf.length !== expBuf.length) return false;
54
- return timingSafeEqual(sigBuf, expBuf);
55
- }
56
-
57
- /**
58
- * Express middleware that ensures valid CSRF tokens on mutating HTTP requests.
59
- * @param {Object} [options={}] - Configuration options.
60
- * @param {string} [options.cookieName="_csrf"] - Name of the cookie storing the CSRF token.
61
- * @param {string} [options.headerName="x-csrf-token"] - Name of the request header.
62
- * @param {string} [options.bodyKey="_csrf"] - Name of the body field.
63
- * @param {number} [options.maxAgeMs=86400000] - Token expiration in milliseconds.
64
- * @returns {Function} Express middleware.
65
- */
66
- static middleware(options = {}) {
67
- const cookieName = options.cookieName || "_csrf";
68
- const headerName = (options.headerName || "x-csrf-token").toLowerCase();
69
- const bodyKey = options.bodyKey || "_csrf";
70
- const maxAgeMs = options.maxAgeMs || 86400000;
71
- const secret = options.secret || process.env.JWT_SECRET || defaultSecret;
72
-
73
- return (req, res, next) => {
74
- let token = req.cookies?.[cookieName];
75
-
76
- if (!token || !Csrf.verifyToken(token, secret, maxAgeMs)) {
77
- token = Csrf.generateToken(secret);
78
- if (typeof res.cookie === "function") {
79
- res.cookie(cookieName, token, {
80
- httpOnly: false,
81
- sameSite: "lax",
82
- secure: Boolean(!propsConfig.debug),
83
- path: "/",
84
- });
85
- }
86
- }
87
-
88
- res.locals.csrfToken = token;
89
- req.csrfToken = () => token;
90
-
91
- const safeMethods = ["GET", "HEAD", "OPTIONS"];
92
- if (safeMethods.includes(req.method)) {
93
- return next();
94
- }
95
-
96
- const receivedToken =
97
- req.headers[headerName] ||
98
- req.body?.[bodyKey] ||
99
- req.query?.[bodyKey];
100
-
101
- if (!receivedToken || !Csrf.verifyToken(receivedToken, secret, maxAgeMs) || receivedToken !== token) {
102
- return res.status(403).json({
103
- status: "error",
104
- message: "Invalid or missing CSRF token.",
105
- });
106
- }
107
-
108
- next();
109
- };
110
- }
111
- }
112
-
113
- export { Csrf };
114
- export default Csrf;
1
+ import { createHmac, randomBytes, timingSafeEqual } from "node:crypto";
2
+ import Config from "./config.js";
3
+
4
+ const propsConfig = Config.props();
5
+ const defaultSecret = propsConfig.jwtSecret || "bluebird-csrf-secret-key-32-chars!";
6
+
7
+ /**
8
+ * Native CSRF protection module using HMAC-SHA256 signed tokens without external dependencies.
9
+ */
10
+ class Csrf {
11
+ /**
12
+ * Generates a signed CSRF token string.
13
+ * @param {string} [secret] - Secret key used for signing.
14
+ * @returns {string} Hex encoded token in format salt.timestamp.signature.
15
+ */
16
+ static generateToken(secret = process.env.JWT_SECRET || defaultSecret) {
17
+ const salt = randomBytes(16).toString("hex");
18
+ const timestamp = Date.now().toString(36);
19
+ const signature = createHmac("sha256", secret)
20
+ .update(`${salt}.${timestamp}`)
21
+ .digest("hex");
22
+
23
+ return `${salt}.${timestamp}.${signature}`;
24
+ }
25
+
26
+ /**
27
+ * Verifies the authenticity and validity of a CSRF token.
28
+ * @param {string} token - The CSRF token to verify.
29
+ * @param {string} [secret] - Secret key used for verification.
30
+ * @param {number} [maxAgeMs=86400000] - Maximum token age in milliseconds (default 24h).
31
+ * @returns {boolean} True if the token is valid.
32
+ */
33
+ static verifyToken(token, secret = process.env.JWT_SECRET || defaultSecret, maxAgeMs = 86400000) {
34
+ if (!token || typeof token !== "string") return false;
35
+
36
+ const parts = token.split(".");
37
+ if (parts.length !== 3) return false;
38
+
39
+ const [salt, timestampStr, signature] = parts;
40
+ const timestamp = parseInt(timestampStr, 36);
41
+
42
+ if (isNaN(timestamp) || Date.now() - timestamp > maxAgeMs) {
43
+ return false;
44
+ }
45
+
46
+ const expected = createHmac("sha256", secret)
47
+ .update(`${salt}.${timestampStr}`)
48
+ .digest("hex");
49
+
50
+ const sigBuf = Buffer.from(signature);
51
+ const expBuf = Buffer.from(expected);
52
+
53
+ if (sigBuf.length !== expBuf.length) return false;
54
+ return timingSafeEqual(sigBuf, expBuf);
55
+ }
56
+
57
+ /**
58
+ * Express middleware that ensures valid CSRF tokens on mutating HTTP requests.
59
+ * @param {Object} [options={}] - Configuration options.
60
+ * @param {string} [options.cookieName="_csrf"] - Name of the cookie storing the CSRF token.
61
+ * @param {string} [options.headerName="x-csrf-token"] - Name of the request header.
62
+ * @param {string} [options.bodyKey="_csrf"] - Name of the body field.
63
+ * @param {number} [options.maxAgeMs=86400000] - Token expiration in milliseconds.
64
+ * @returns {Function} Express middleware.
65
+ */
66
+ static middleware(options = {}) {
67
+ const cookieName = options.cookieName || "_csrf";
68
+ const headerName = (options.headerName || "x-csrf-token").toLowerCase();
69
+ const bodyKey = options.bodyKey || "_csrf";
70
+ const maxAgeMs = options.maxAgeMs || 86400000;
71
+ const secret = options.secret || process.env.JWT_SECRET || defaultSecret;
72
+
73
+ return (req, res, next) => {
74
+ let token = req.cookies?.[cookieName];
75
+
76
+ if (!token || !Csrf.verifyToken(token, secret, maxAgeMs)) {
77
+ token = Csrf.generateToken(secret);
78
+ if (typeof res.cookie === "function") {
79
+ res.cookie(cookieName, token, {
80
+ httpOnly: false,
81
+ sameSite: "lax",
82
+ secure: Boolean(!propsConfig.debug),
83
+ path: "/",
84
+ });
85
+ }
86
+ }
87
+
88
+ res.locals.csrfToken = token;
89
+ req.csrfToken = () => token;
90
+
91
+ const safeMethods = ["GET", "HEAD", "OPTIONS"];
92
+ if (safeMethods.includes(req.method)) {
93
+ return next();
94
+ }
95
+
96
+ const receivedToken =
97
+ req.headers[headerName] ||
98
+ req.body?.[bodyKey] ||
99
+ req.query?.[bodyKey];
100
+
101
+ if (!receivedToken || !Csrf.verifyToken(receivedToken, secret, maxAgeMs) || receivedToken !== token) {
102
+ return res.status(403).json({
103
+ status: "error",
104
+ message: "Invalid or missing CSRF token.",
105
+ });
106
+ }
107
+
108
+ next();
109
+ };
110
+ }
111
+ }
112
+
113
+ export { Csrf };
114
+ export default Csrf;
@@ -1,15 +1,15 @@
1
- import {
2
- Database,
3
- DB_TYPE,
4
- DatabaseQueryOptions,
5
- DatabaseTransactionClient,
6
- PaginatedResult,
7
- } from "./index.js";
8
- export default Database;
9
- export {
10
- Database,
11
- DB_TYPE,
12
- DatabaseQueryOptions,
13
- DatabaseTransactionClient,
14
- PaginatedResult,
15
- };
1
+ import {
2
+ Database,
3
+ DB_TYPE,
4
+ DatabaseQueryOptions,
5
+ DatabaseTransactionClient,
6
+ PaginatedResult,
7
+ } from "./index.js";
8
+ export default Database;
9
+ export {
10
+ Database,
11
+ DB_TYPE,
12
+ DatabaseQueryOptions,
13
+ DatabaseTransactionClient,
14
+ PaginatedResult,
15
+ };