express-sweet 5.0.0 → 5.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "express-sweet",
3
- "version": "5.0.0",
3
+ "version": "5.1.1",
4
4
  "description": "Express.js, supercharged. Auth, ORM, routing, views — everything snaps together so you can ship fast and stay sharp.",
5
5
  "type": "module",
6
6
  "main": "dist/build.cjs",
@@ -61,14 +61,14 @@
61
61
  "connect-redis": "^9.0.0",
62
62
  "cookie-parser": "^1.4.7",
63
63
  "dotenv": "^17.3.1",
64
- "express": "^5.2.1",
65
- "express-handlebars": "^8.0.6",
64
+ "express": "^5.3.0",
65
+ "express-handlebars": "^9.0.6",
66
66
  "express-session": "^1.19.0",
67
- "glob": "^13.0.6",
67
+ "glob": "^14.0.6",
68
68
  "http-errors": "~2.0.1",
69
- "moment": "^2.30.1",
70
- "morgan": "^1.10.1",
71
- "multer": "^2.1.1",
69
+ "moment": "^2.31.0",
70
+ "morgan": "^1.12.1",
71
+ "multer": "^2.5.0",
72
72
  "passport": "^0.7.0",
73
73
  "passport-local": "^1.0.0",
74
74
  "redis": "^5.11.0",
@@ -1,6 +1,6 @@
1
1
  flowchart TD
2
2
  A["expx.mount(app)"] --> B["Global variables"]
3
- B --> C[".env file loading\n.env"]
3
+ B --> C[".env file loading & hook_after_env_load\n.env, config/config.js"]
4
4
  C --> D["Sequelize model initialization\nconfig/database.js, models/"]
5
5
  D --> E["Body parser, cookies, static files, Morgan logging\nconfig/logging.js, public/"]
6
6
  E --> F["Handlebars view engine\nconfig/view.js, views/"]
Binary file
@@ -2,7 +2,12 @@
2
2
  * Loads environment variables from a `.env` file into `process.env`.
3
3
  *
4
4
  * Reads the file path specified by `env_path` in `config/config.js`, parses it with dotenv,
5
- * and populates `process.env`. A global flag prevents duplicate loading across multiple calls.
5
+ * and populates `process.env`. Then runs the `hook_after_env_load` hook from the same config
6
+ * file, giving the application a chance to post-process environment variables before database
7
+ * models and the rest of the middleware stack read them. The hook runs even when `env_path`
8
+ * is unset, so it can also be used to build `process.env` from a secret manager.
9
+ *
10
+ * A global flag prevents duplicate execution across multiple calls.
6
11
  *
7
12
  * @returns {Promise<void>}
8
13
  * @example
@@ -20,5 +25,16 @@
20
25
  * DATABASE_URL=mysql://localhost/mydb
21
26
  * SECRET_KEY=mysecret
22
27
  * ```
28
+ * @example
29
+ * ```js
30
+ * // Post-process environment variables in config/config.js
31
+ * export default {
32
+ * env_path: '.env',
33
+ * hook_after_env_load: () => {
34
+ * if (process.env.DB_PASSWORD_B64)
35
+ * process.env.DB_PASSWORD = Buffer.from(process.env.DB_PASSWORD_B64, 'base64').toString();
36
+ * }
37
+ * };
38
+ * ```
23
39
  */
24
40
  export default function env(): Promise<void>;
package/types/mount.d.ts CHANGED
@@ -5,7 +5,7 @@ import express from 'express';
5
5
  *
6
6
  * **Initialization Order:**
7
7
  * 1. Global variables
8
- * 2. Environment variables (.env)
8
+ * 2. Environment variables (.env) and the `hook_after_env_load` hook
9
9
  * 3. Database models
10
10
  * 4. HTTP middleware (body parsing, cookies, static files)
11
11
  * 5. View engine (Handlebars)
@@ -13,6 +13,10 @@ import express from 'express';
13
13
  * default_router: '/blog',
14
14
  * rewrite_base_url: baseUrl => `${baseUrl}/admin`,
15
15
  * is_ajax: req => /^\/api/.test(req.path),
16
+ * hook_after_env_load: () => {
17
+ * if (process.env.DB_PASSWORD_B64)
18
+ * process.env.DB_PASSWORD = Buffer.from(process.env.DB_PASSWORD_B64, 'base64').toString();
19
+ * },
16
20
  * hook_handle_error: (error, req, res, next) => {
17
21
  * if (error.status === 404) res.render('error/404');
18
22
  * else res.render('error/500');
@@ -70,6 +74,21 @@ export default interface AppConfig {
70
74
  * ```
71
75
  */
72
76
  is_ajax?: (req: express.Request) => boolean;
77
+ /**
78
+ * Hook executed right after environment variables are loaded and before database
79
+ * models are initialized. Runs once per process, even when `env_path` is unset.
80
+ * Use it to decrypt secrets, fetch values from a secret manager, or validate
81
+ * required variables before the database connection is established.
82
+ * @type {() => Promise<void>|void}
83
+ * @example
84
+ * ```js
85
+ * hook_after_env_load: () => {
86
+ * if (process.env.DB_PASSWORD_B64)
87
+ * process.env.DB_PASSWORD = Buffer.from(process.env.DB_PASSWORD_B64, 'base64').toString();
88
+ * }
89
+ * ```
90
+ */
91
+ hook_after_env_load?: () => Promise<void> | void;
73
92
  /**
74
93
  * Custom error handler hook. Overrides the default behavior of responding with
75
94
  * `res.status(error.status || 500).end()`.