express-sweet 3.0.2 → 4.0.0

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 (40) hide show
  1. package/CHANGELOG.md +112 -118
  2. package/README.md +206 -57
  3. package/configuration_sample/cjs/config.js +5 -4
  4. package/configuration_sample/cjs/upload.js +91 -0
  5. package/configuration_sample/esm/config.js +5 -4
  6. package/configuration_sample/esm/upload.js +91 -0
  7. package/dist/build.cjs +41 -35
  8. package/dist/build.mjs +41 -35
  9. package/package.json +6 -4
  10. package/types/database/Model.d.ts +2 -2
  11. package/types/handlebars_helpers/object.d.ts +2 -2
  12. package/types/index.d.ts +1 -43
  13. package/types/interfaces/{BasicConfig.d.ts → AppConfig.d.ts} +8 -7
  14. package/types/interfaces/DatabaseConfig.d.ts +1 -0
  15. package/types/interfaces/UploadConfig.d.ts +73 -0
  16. package/types/interfaces/index.d.ts +6 -2
  17. package/types/middlewares/corsPolicy.d.ts +28 -0
  18. package/types/middlewares/{Environment.d.ts → envLoader.d.ts} +13 -15
  19. package/types/middlewares/errorHandler.d.ts +32 -0
  20. package/types/middlewares/globalVars.d.ts +25 -0
  21. package/types/middlewares/index.d.ts +19 -11
  22. package/types/middlewares/localVars.d.ts +44 -0
  23. package/types/middlewares/passportAuth.d.ts +15 -0
  24. package/types/middlewares/requestParser.d.ts +27 -0
  25. package/types/{routing/Router.d.ts → middlewares/routeMapper.d.ts} +14 -16
  26. package/types/middlewares/viewEngine.d.ts +49 -0
  27. package/types/mount.d.ts +33 -1
  28. package/types/utils/Types.d.ts +17 -11
  29. package/types/utils/index.d.ts +7 -3
  30. package/types/utils/loadAppConfig.d.ts +17 -0
  31. package/types/utils/loadUploadConfig.d.ts +20 -0
  32. package/types/middlewares/Authentication.d.ts +0 -52
  33. package/types/middlewares/CORS.d.ts +0 -30
  34. package/types/middlewares/ErrorHandler.d.ts +0 -34
  35. package/types/middlewares/Global.d.ts +0 -27
  36. package/types/middlewares/Http.d.ts +0 -29
  37. package/types/middlewares/Local.d.ts +0 -42
  38. package/types/middlewares/View.d.ts +0 -49
  39. package/types/routing/index.d.ts +0 -37
  40. package/types/utils/loadBasicConfig.d.ts +0 -17
package/CHANGELOG.md CHANGED
@@ -2,6 +2,79 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
+ ## [Unreleased]
6
+
7
+ ### Breaking Changes
8
+
9
+ **Middleware Architecture Refactoring**
10
+ - All middleware components have been refactored from class-based to function-based architecture
11
+ - Middleware naming updated to follow Express.js conventions (2-word composition pattern)
12
+
13
+ **Middleware Name Changes:**
14
+ | Previous (Class-based) | Current (Function-based) |
15
+ |------------------------|--------------------------|
16
+ | `CORS` | `corsPolicy` |
17
+ | `Environment` | `envLoader` |
18
+ | `ErrorHandler` | `errorHandler` |
19
+ | `Http` | `requestParser` |
20
+ | `Local` | `localVars` |
21
+ | `Router` | `routeMapper` |
22
+ | `View` | `viewEngine` |
23
+ | `Authentication` | `passportAuth` |
24
+ | `Global` | `globalVars` |
25
+
26
+ **Migration Notes:**
27
+ - These are internal changes and do not affect the public API
28
+ - The `mount()` function handles all middleware automatically
29
+ - No changes required in application code for standard usage
30
+
31
+ **Express 5 Migration**
32
+ - **Requires Node.js 18.x or higher**
33
+ - Upgraded from Express 4.21.2 to Express 5.2.1
34
+ - Note: `express-handlebars` remains at v7.1.3 to maintain Node.js 18+ compatibility (v8 requires Node.js 20+)
35
+ - Route patterns with regex parameters no longer support `/:param(\\d+)` syntax
36
+ - Use RegExp with named capture groups instead: `/^\/(?<userId>\d+)$/`
37
+ - See migration example in Changed section below
38
+ - For more details on Express 5 changes, see:
39
+ - [Express 5 Migration Guide](https://expressjs.com/en/guide/migrating-5.html)
40
+ - [Express.js Release Notes](https://expressjs.com/en/changelog/)
41
+
42
+ ### Added
43
+
44
+ **File Upload Support (Multer)**
45
+ - Added dynamic file upload middleware using Multer
46
+ - New `config/upload.js` configuration file for flexible upload handling
47
+ - Support for single file, multiple files (array), and multiple field uploads
48
+ - Both memory storage and disk storage options
49
+ - Request-based middleware resolution for route-specific upload configurations
50
+ - Sample configurations added:
51
+ - [ESM Configuration](configuration_sample/esm/upload.js)
52
+ - [CJS Configuration](configuration_sample/cjs/upload.js)
53
+
54
+ ### Changed
55
+
56
+ **Express 5 Compatibility Updates**
57
+ - Added `query parser: 'extended'` setting in HTTP middleware to maintain Express 4 behavior for nested query objects
58
+ - Added `multer().none()` middleware to parse `multipart/form-data` requests without files
59
+
60
+ **Route Pattern Migration Example**
61
+ ```js
62
+ // Before (Express 4)
63
+ router.get('/:userId(\\d+)', (req, res) => {
64
+ const userId = req.params.userId; // Works
65
+ });
66
+
67
+ // After (Express 5)
68
+ router.get(/^\/(?<userId>\d+)$/, (req, res) => {
69
+ const userId = req.params.userId; // Works with named capture group
70
+ });
71
+ ```
72
+
73
+ ### Fixed
74
+
75
+ - Fixed `ERR_INVALID_URL` error when invalid Host header values are provided
76
+ - `baseUrl` is now set to `undefined` when URL construction fails, allowing graceful error handling via `rewrite_base_url` hook or template checks
77
+
5
78
  ## [3.0.2] - 2025-11-28
6
79
 
7
80
  ### Changed
@@ -14,12 +87,7 @@ All notable changes to this project will be documented in this file.
14
87
  - Added explicit handling for OPTIONS preflight requests
15
88
 
16
89
  **Demo Improvements**
17
- - Reorganized demo structure into separate `web-app` and `rest-api` directories
18
90
  - Added new REST API demo showcasing CORS functionality with simple CRUD endpoints
19
- - Improved web-app demo documentation and Docker configuration
20
- - Updated Docker configuration to use `utf8mb4` character set
21
- - Optimized Dockerfile with layer reduction and `npm ci` for reproducibility
22
- - Added SQL comments and ON DELETE CASCADE to foreign keys in schema
23
91
 
24
92
  ## [3.0.1] - 2025-09-02
25
93
 
@@ -118,7 +186,7 @@ const db = await expx.database.DatabaseManager.getInstance();
118
186
 
119
187
  ### Fixed
120
188
 
121
- - Fixed a bug that caused redirection to fail when a path with query parameters was set for the logout redirect URL (`failure_redirect` in `config/authentication.js`).
189
+ - Fixed a bug that caused logout redirection to fail when the redirect URL contained query parameters.
122
190
 
123
191
  ## [2.0.5] - 2025-02-04
124
192
 
@@ -168,31 +236,16 @@ const db = await expx.database.DatabaseManager.getInstance();
168
236
 
169
237
  ## [2.0.3] - 2024-09-03
170
238
 
171
- ### Changed
239
+ > **Note:** This version used class-based middleware with names like `CORS`, `Environment`, `ErrorHandler`, `Http`, `Local`, `Router`, `View`, and `Authentication`. In v3.x and later, these were refactored to function-based middleware with new names (`corsPolicy`, `envLoader`, `errorHandler`, `requestParser`, `localVars`, `routeMapper`, `viewEngine`, `passportAuth`). The items listed below reflect the naming and structure used in v2.0.3.
172
240
 
173
- - Added `"type": "module"` to the `package.json` of the ESM app generated by `express-sweet-generator`. It is now fully ESM compliant.
174
- - `require` was changed to dynamic import.
175
- - Template engine changed from `express-hbs` to `express-handlebars`.
176
- However, the `block` and `contentFor` helpers are still available.
241
+ ### Breaking Changes
242
+
243
+ **Template Engine Migration**
244
+ - Template engine changed from `express-hbs` to `express-handlebars`.
245
+ However, the `block` and `contentFor` helpers are still available for backward compatibility.
246
+
247
+ **Database Layer Changes**
177
248
  - `database/Database` has been changed from a `sequelize.Sequelize` instance to a `sequelize.Sequelize` class. If you use it in the future, you need to instantiate it.
178
- - Return type of `mount()` changed from `void` to `Promise<void>`.
179
- - Return type of `middlewares/CORS.mount()` changed from `void` to `Promise<void>`.
180
- - Return type of `middlewares/Environment.mount()` changed from `void` to `Promise<void>`.
181
- - Return type of `middlewares/ErrorHandler.mount()` changed from `void` to `Promise<void>`.
182
- - Return type of `middlewares/Http.mount()` changed from `void` to `Promise<void>`.
183
- - Return type of `middlewares/Local.mount()` changed from `void` to `Promise<void>`.
184
- - Return type of `middlewares/Router.mount()` changed from `void` to `Promise<void>`.
185
- - Return type of `middlewares/View.mount()` changed from `void` to `Promise<void>`.
186
- - Return type of `middlewares/View.mountBeforeRender()` changed from `void` to `Promise<void>`.
187
- - Return type of `middlewares/Authentication.mount()` changed from `void` to `Promise<void>`.
188
- - Return type of `utils/loadAuthenticationConfig()` changed from `AuthenticationConfig` to `Promise<AuthenticationConfig>`.
189
- - Return type of `utils/loadBasicConfig()` changed from `BasicConfig` to `Promise<BasicConfig>`.
190
- - Return type of `utils/loadDatabaseConfig()` changed from `sequelize.Options` to `Promise<sequelize.Options>`.
191
- - Return type of `utils/loadViewConfig()` changed from `ViewConfig` to `Promise<ViewConfig>`.
192
- - Return type of `services/Authentication.successRedirect()` changed from `void` to `Promise<void>`.
193
- - Return type of `services/Authentication.failureRedirect()` changed from `void` to `Promise<void>`.
194
- - Return type of `database/Model.initialize()` changed from `typeof Model` to `Promise<typeof Model>`.
195
- - Return type of `database/loadModels()` changed from `void` to `Promise<void>`.
196
249
  - DB connection check method has been changed.
197
250
  - After:
198
251
  ```js
@@ -212,6 +265,14 @@ const db = await expx.database.DatabaseManager.getInstance();
212
265
  // Check database connection.
213
266
  await expx.database.Database.isConnect();
214
267
  ```
268
+
269
+ **Async Function Signature Changes**
270
+ - All middleware mount methods, configuration loaders, authentication services, and database initialization functions now return `Promise` types instead of synchronous return types. This change enables asynchronous configuration loading and proper async/await usage throughout the framework.
271
+
272
+ ### Changed
273
+
274
+ - Added `"type": "module"` to the `package.json` of the ESM app generated by `express-sweet-generator`. It is now fully ESM compliant.
275
+ - `require` was changed to dynamic import.
215
276
  - Updated passport from 0.4.1 to 0.7.0
216
277
 
217
278
  ## [2.0.2] - 2024-09-01
@@ -231,19 +292,17 @@ const db = await expx.database.DatabaseManager.getInstance();
231
292
 
232
293
  ## [2.0.0] - 2024-03-24
233
294
 
234
- ### Changed
295
+ ### Breaking Changes
235
296
 
236
- - EXPRESS SWEET version 2 no longer depends on the AWS SDK.
297
+ **AWS SDK Removal**
298
+ - EXPRESS SWEET version 2 no longer depends on the AWS SDK.
237
299
  The `services.AWSRekognitionClient` and `services.AWSSesClient` have been migrated to the [AWS SDK Extension](https://www.npmjs.com/package/aws-sdk-extension) NPM package, so please install from there if needed.
238
300
 
239
301
  ## [1.1.1] - 2024-03-23
240
302
 
241
303
  ### Changed
242
304
 
243
- - When cookie security is enabled (`config/authentication.js#cookie_secure`) and the application is running on the HTTP protocol, the following warning message is output upon user authentication.
244
- ```bash
245
- Warning: Cookie security must be disabled for user authentication to work over the HTTP protocol (config/authentication.js#cookie_secure)
246
- ```
305
+ - When cookie security is enabled and the application runs over HTTP, a warning message is now displayed during user authentication to prevent authentication issues caused by secure cookie settings incompatible with the HTTP protocol.
247
306
 
248
307
  ## [1.1.0] - 2024-03-06
249
308
 
@@ -261,13 +320,13 @@ const db = await expx.database.DatabaseManager.getInstance();
261
320
 
262
321
  ### Changed
263
322
 
264
- - The `Secure` and `HttpOnly` attributes of the session cookie can now be set from the authentication configuration file (`config/authentication.js`).
323
+ - The `Secure` and `HttpOnly` attributes of session cookies can now be configured through the authentication configuration file.
265
324
 
266
325
  ## [1.0.43] - 2023-12-30
267
326
 
268
327
  ### Changed
269
328
 
270
- - The cookie name for storing session IDs can now be set in the `cookie_name` field of the authentication configuration file (`config/authentication.js`).
329
+ - Session cookie name is now configurable through the authentication configuration file.
271
330
 
272
331
  ## [1.0.42] - 2023-08-31
273
332
 
@@ -297,86 +356,19 @@ const db = await expx.database.DatabaseManager.getInstance();
297
356
 
298
357
  ### Changed
299
358
 
300
- - Changed exception class name.
301
- <table>
302
- <thead>
303
- <tr>
304
- <th>Before Class Name</th>
305
- <th>After class name</th>
306
- <th>Instance member</th>
307
- <th>Description</th>
308
- </tr>
309
- </thead>
310
- <tbody>
311
- <tr>
312
- <td>CollectionCreationError</td>
313
- <td>FaceCollectionCreateFailed</td>
314
- <td>
315
- <ul>
316
- <li>name: Error Name.</li>
317
- <li>collectionId: Collection ID.</li>
318
- <li>httpStatusCode: HTTP status code.</li>
319
- </ul>
320
- </td>
321
- <td>Thrown when face collection creation (<code>AWSRekognitionClient.createCollection()</code>) fails.</td>
322
- </tr>
323
- <tr>
324
- <td>CollectionDeletionError</td>
325
- <td>FaceCollectionDeleteFailed</td>
326
- <td>
327
- <ul>
328
- <li>name: Error Name.</li>
329
- <li>collectionId: Collection ID.</li>
330
- <li>httpStatusCode: HTTP status code.</li>
331
- </ul>
332
- </td>
333
- <td>Thrown when deleting a face collection (<code>AWSRekognitionClient.deleteCollection()</code>) fails.</td>
334
- </tr>
335
- <tr>
336
- <td>FaceIndexError</td>
337
- <td>FaceIndexFailed</td>
338
- <td>
339
- <ul>
340
- <li>name: Error Name.</li>
341
- <li>collectionId: Collection ID.</li>
342
- </ul>
343
- </td>
344
- <td>Thrown when face indexing (<code>AWSRekognitionClient.indexFace()</code>) fails.</td>
345
- </tr>
346
- <tr>
347
- <td>MissingFaceInImageError</td>
348
- <td>FaceMissingInPhoto</td>
349
- <td>
350
- <ul>
351
- <li>name: Error Name.</li>
352
- </ul>
353
- </td>
354
- <td>Thrown if the face to index (<code>AWSRekognitionClient.indexFace()</code>) is not in the photo.</td>
355
- </tr>
356
- <tr>
357
- <td>MultipleFacesInImageError</td>
358
- <td>FacesMultipleInPhoto</td>
359
- <td>
360
- <ul>
361
- <li>name: Error Name.</li>
362
- </ul>
363
- </td>
364
- <td>Thrown when there are multiple faces to index (<code>AWSRekognitionClient.indexFace()</code>) in a photo.</td>
365
- </tr>
366
- </tbody>
367
- </table>
359
+ - Renamed AWS Rekognition exception classes to more descriptive names. All face-related error classes now follow a consistent naming pattern with "Face" prefix and "Failed"/"Missing"/"Multiple" suffixes for better clarity and error handling.
368
360
 
369
361
  ## [1.0.38] - 2023-07-17
370
362
 
371
363
  ### Fixed
372
364
 
373
- - Fixed a bug that login user data (req.user) could not be referenced in the function called just before view rendering (config/view.js#beforeRender).
365
+ - Fixed a bug that prevented login user data from being referenced in the view rendering hook function.
374
366
 
375
367
  ## [1.0.37] - 2023-07-17
376
368
 
377
369
  ### Changed
378
370
 
379
- - The beforeRender option in the view configuration (config/view.js) can now specify asynchronous functions.
371
+ - The view rendering hook function now supports asynchronous functions for async operations before rendering.
380
372
 
381
373
  ### Added
382
374
 
@@ -386,15 +378,15 @@ const db = await expx.database.DatabaseManager.getInstance();
386
378
 
387
379
  ### Changed
388
380
 
389
- - Moved the Ajax determination option (is_ajax) in the authentication configuration (config/authentication.js) to the basic configuration (config/config.js).
390
- - The error handle option (error_handler) in the basic configuration (config/config.js) has been removed and an option to hook error handles (hook_handle_error) added instead.
381
+ - Moved the Ajax determination option (`is_ajax`) from authentication configuration to application configuration.
382
+ - The error handler option has been replaced with a hookable error handling mechanism (`hook_handle_error`) for more flexible error processing.
391
383
 
392
384
  ## [1.0.35] - 2023-07-11
393
385
 
394
386
  ### Changed
395
387
 
396
- - The URL to redirect to when login fails (failure_redirect) option in the authentication configuration (config/authentication.js) can now be defined with a function.
397
- - The arguments of the failureRedirect method of the authentication service class (services/Authentication) have changed. The argument to the Authentication.failureRedirect method used to be just express.Response, but now it requires express.Request and express.Response.
388
+ - The login failure redirect URL option can now be defined as a function for dynamic redirect behavior.
389
+ - Authentication service's `failureRedirect` method signature changed to accept both request and response objects instead of response only.
398
390
 
399
391
  ## [1.0.34] - 2023-07-01
400
392
 
@@ -412,7 +404,7 @@ const db = await expx.database.DatabaseManager.getInstance();
412
404
 
413
405
  ### Fixed
414
406
 
415
- - Fixed a bug that cookies (req.cookies) cannot be referenced in the hook function before view rendering (config/view.js#beforeRender).
407
+ - Fixed a bug that prevented cookies from being accessed in the view rendering hook function.
416
408
 
417
409
  ## [1.0.31] - 2023-06-29
418
410
 
@@ -458,17 +450,17 @@ const db = await expx.database.DatabaseManager.getInstance();
458
450
 
459
451
  ### Changed
460
452
 
461
- - Request object has been added to the arguments of the beforeRender function in the view configuration (config/view.js).
453
+ - The view rendering hook function now receives the request object as an argument for accessing request data during rendering.
462
454
 
463
455
  ## [1.0.26] - 2023-06-11
464
456
 
465
457
  ### Changed
466
458
 
467
459
  - Updated Sequelize from v5 to v6.
468
- - Changed the framework debug log to output only when the environment variable EXPRESS_DEBUG is defined.
460
+ - Changed the framework debug log to output only when the environment variable SWEET_DEBUG is defined.
469
461
  .env:
470
462
  ```
471
- EXPRESS_DEBUG=true
463
+ SWEET_DEBUG=true
472
464
  ```
473
465
 
474
466
  ## [1.0.25] - 2022-11-24
@@ -481,7 +473,7 @@ const db = await expx.database.DatabaseManager.getInstance();
481
473
 
482
474
  ### Added
483
475
 
484
- - Added is_ajax option to user authentication (config/authentication.js).
476
+ - Added Ajax request detection option to authentication configuration for custom XHR/fetch request handling.
485
477
 
486
478
  ## [1.0.23] - 2022-10-20
487
479
 
@@ -540,7 +532,7 @@ const db = await expx.database.DatabaseManager.getInstance();
540
532
 
541
533
  ### Changed
542
534
 
543
- - Changed the type of 'config/authentication.js#allow_unauthenticated' from'string[]' to'(string|RegExp)[]}'.
535
+ - The unauthenticated route pattern option now accepts both string and RegExp patterns for more flexible route matching.
544
536
 
545
537
  ## [1.0.14] - 2022-01-17
546
538
 
@@ -722,4 +714,6 @@ const db = await expx.database.DatabaseManager.getInstance();
722
714
  [2.0.8]: https://github.com/takuya-motoshima/express-sweet/compare/v2.0.7...v2.0.8
723
715
  [2.0.9]: https://github.com/takuya-motoshima/express-sweet/compare/v2.0.8...v2.0.9
724
716
  [3.0.0]: https://github.com/takuya-motoshima/express-sweet/compare/v2.0.9...v3.0.0
725
- [3.0.1]: https://github.com/takuya-motoshima/express-sweet/compare/v3.0.0...v3.0.1
717
+ [3.0.1]: https://github.com/takuya-motoshima/express-sweet/compare/v3.0.0...v3.0.1
718
+ [3.0.2]: https://github.com/takuya-motoshima/express-sweet/compare/v3.0.1...v3.0.2
719
+ [Unreleased]: https://github.com/takuya-motoshima/express-sweet/compare/v3.0.2...HEAD