express-sweet 4.0.0 → 5.1.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 (93) hide show
  1. package/CHANGELOG.md +221 -397
  2. package/LICENSE +1 -1
  3. package/README.md +210 -1174
  4. package/dist/build.cjs +32 -73
  5. package/dist/build.mjs +32 -73
  6. package/package.json +45 -61
  7. package/screenshots/avatar.png +0 -0
  8. package/screenshots/edit-profile.png +0 -0
  9. package/screenshots/hero-banner.png +0 -0
  10. package/screenshots/home.png +0 -0
  11. package/screenshots/mount-flow.mmd +11 -0
  12. package/screenshots/mount-flow.png +0 -0
  13. package/screenshots/new-person.png +0 -0
  14. package/screenshots/people.png +0 -0
  15. package/screenshots/sign-in.png +0 -0
  16. package/types/database/DatabaseManager.d.ts +15 -10
  17. package/types/database/Model.d.ts +29 -43
  18. package/types/database/index.d.ts +0 -1
  19. package/types/database/loadModels.d.ts +7 -13
  20. package/types/helpers/array.d.ts +21 -0
  21. package/types/helpers/comparison.d.ts +217 -0
  22. package/types/helpers/date.d.ts +20 -0
  23. package/types/helpers/html.d.ts +35 -0
  24. package/types/{handlebars_helpers → helpers}/index.d.ts +0 -2
  25. package/types/helpers/layouts.d.ts +29 -0
  26. package/types/helpers/math.d.ts +85 -0
  27. package/types/helpers/number.d.ts +19 -0
  28. package/types/helpers/object.d.ts +28 -0
  29. package/types/helpers/string.d.ts +45 -0
  30. package/types/index.d.ts +6 -9
  31. package/types/middleware/auth.d.ts +186 -0
  32. package/types/middleware/cors.d.ts +19 -0
  33. package/types/middleware/env.d.ts +40 -0
  34. package/types/middleware/error.d.ts +26 -0
  35. package/types/middleware/globals.d.ts +13 -0
  36. package/types/{middlewares → middleware}/index.d.ts +12 -13
  37. package/types/middleware/locals.d.ts +33 -0
  38. package/types/middleware/parser.d.ts +30 -0
  39. package/types/middleware/router.d.ts +31 -0
  40. package/types/middleware/views.d.ts +37 -0
  41. package/types/mount.d.ts +2 -3
  42. package/types/{interfaces → types}/AppConfig.d.ts +29 -18
  43. package/types/{interfaces → types}/AuthenticationConfig.d.ts +10 -11
  44. package/types/{interfaces → types}/DatabaseConfig.d.ts +0 -1
  45. package/types/{interfaces → types}/LoggingConfig.d.ts +0 -1
  46. package/types/{interfaces → types}/UploadConfig.d.ts +0 -1
  47. package/types/{interfaces → types}/ViewConfig.d.ts +1 -2
  48. package/types/{interfaces → types}/index.d.ts +1 -2
  49. package/types/utils/index.d.ts +0 -1
  50. package/types/utils/loadAppConfig.d.ts +1 -1
  51. package/types/utils/loadAuthenticationConfig.d.ts +1 -1
  52. package/types/utils/loadLoggingConfig.d.ts +1 -1
  53. package/types/utils/loadUploadConfig.d.ts +1 -1
  54. package/types/utils/loadViewConfig.d.ts +1 -1
  55. package/configuration_sample/cjs/authentication.js +0 -138
  56. package/configuration_sample/cjs/config.js +0 -92
  57. package/configuration_sample/cjs/database.js +0 -121
  58. package/configuration_sample/cjs/logging.js +0 -41
  59. package/configuration_sample/cjs/upload.js +0 -91
  60. package/configuration_sample/cjs/view.js +0 -54
  61. package/configuration_sample/esm/authentication.js +0 -136
  62. package/configuration_sample/esm/config.js +0 -92
  63. package/configuration_sample/esm/database.js +0 -121
  64. package/configuration_sample/esm/logging.js +0 -41
  65. package/configuration_sample/esm/upload.js +0 -91
  66. package/configuration_sample/esm/view.js +0 -54
  67. package/screencaps/belongs-to-many.png +0 -0
  68. package/screencaps/belongs-to.png +0 -0
  69. package/screencaps/demonstration.webp +0 -0
  70. package/screencaps/has-many.png +0 -0
  71. package/screencaps/has-one.png +0 -0
  72. package/types/handlebars_helpers/array.d.ts +0 -22
  73. package/types/handlebars_helpers/comparison.d.ts +0 -222
  74. package/types/handlebars_helpers/date.d.ts +0 -19
  75. package/types/handlebars_helpers/html.d.ts +0 -31
  76. package/types/handlebars_helpers/layouts.d.ts +0 -25
  77. package/types/handlebars_helpers/math.d.ts +0 -74
  78. package/types/handlebars_helpers/number.d.ts +0 -18
  79. package/types/handlebars_helpers/object.d.ts +0 -21
  80. package/types/handlebars_helpers/string.d.ts +0 -45
  81. package/types/middlewares/corsPolicy.d.ts +0 -28
  82. package/types/middlewares/envLoader.d.ts +0 -34
  83. package/types/middlewares/errorHandler.d.ts +0 -32
  84. package/types/middlewares/globalVars.d.ts +0 -25
  85. package/types/middlewares/localVars.d.ts +0 -44
  86. package/types/middlewares/passportAuth.d.ts +0 -15
  87. package/types/middlewares/requestParser.d.ts +0 -27
  88. package/types/middlewares/routeMapper.d.ts +0 -54
  89. package/types/middlewares/viewEngine.d.ts +0 -49
  90. package/types/services/Authentication.d.ts +0 -95
  91. package/types/services/index.d.ts +0 -33
  92. package/types/types/global.d.ts +0 -38
  93. package/types/utils/Types.d.ts +0 -29
@@ -1,54 +0,0 @@
1
- import express from 'express';
2
- /**
3
- * Set up URL routing based on file structure in the routes directory.
4
- * Automatically maps route files to URL endpoints using file-based routing.
5
- * Supports nested routing and default routes.
6
- *
7
- * @example
8
- * ```js
9
- * // Basic routing: routes/user.js responds to GET /user
10
- * import {Router} from 'express';
11
- *
12
- * const router = Router();
13
- * router.get('/', (req, res) => {
14
- * res.send('Hello World');
15
- * });
16
- *
17
- * export default router;
18
- * ```
19
- *
20
- * @example
21
- * ```js
22
- * // Nested routing: routes/api/users.js responds to GET /api/users
23
- * import {Router} from 'express';
24
- *
25
- * const router = Router();
26
- * router.get('/', (req, res) => {
27
- * res.send('Hello World');
28
- * });
29
- *
30
- * export default router;
31
- * ```
32
- *
33
- * @example
34
- * ```js
35
- * // Default routing configuration in config/config.js
36
- * export default {
37
- * default_router: '/blog' // routes/blog.js handles root URL "/"
38
- * };
39
- * ```
40
- */
41
- /**
42
- * Mount file-based routing on Express application.
43
- * Scans the routes directory and automatically maps files to URL endpoints.
44
- * @param {express.Express} app Express application instance
45
- * @returns {Promise<void>}
46
- * @example
47
- * ```js
48
- * // This method is called automatically by express-sweet.mount()
49
- * import routeMapper from './middlewares/routeMapper';
50
- *
51
- * await routeMapper(app);
52
- * ```
53
- */
54
- export default function routeMapper(app: express.Express): Promise<void>;
@@ -1,49 +0,0 @@
1
- import express from 'express';
2
- /**
3
- * Enable Handlebars template engine with custom helpers and configuration.
4
- * Sets up view engine, layouts, partials, and before-render hooks.
5
- *
6
- * @see {@link https://handlebarsjs.com/guide/ | Handlebars Guide}
7
- * @example
8
- * ```js
9
- * // View configuration in config/view.js
10
- * export default {
11
- * views_dir: 'views',
12
- * partials_dir: 'views/partials',
13
- * layouts_dir: 'views/layout',
14
- * default_layout: 'views/layout/default',
15
- * extension: '.hbs',
16
- * beforeRender: (req, res) => {
17
- * res.locals.extra = 'Extra';
18
- * }
19
- * };
20
- * ```
21
- */
22
- /**
23
- * Mount Handlebars view engine on Express application.
24
- * Configures template engine, helpers, layouts, and partials.
25
- * @param {express.Express} app Express application instance
26
- * @returns {Promise<void>}
27
- * @example
28
- * ```js
29
- * // This method is called automatically by express-sweet.mount()
30
- * import viewEngine from './middlewares/viewEngine';
31
- *
32
- * await viewEngine(app);
33
- * ```
34
- */
35
- export default function viewEngine(app: express.Express): Promise<void>;
36
- /**
37
- * Mount middleware to be executed just before rendering the view.
38
- * Allows setting view variables and executing beforeRender hooks from configuration.
39
- * @param {express.Express} app Express application instance
40
- * @returns {Promise<void>}
41
- * @example
42
- * ```js
43
- * // Called automatically after authentication middleware setup
44
- * import {mountBeforeRender} from './middlewares/viewEngine';
45
- *
46
- * await mountBeforeRender(app);
47
- * ```
48
- */
49
- export declare function mountBeforeRender(app: express.Express): Promise<void>;
@@ -1,95 +0,0 @@
1
- import express from 'express';
2
- /**
3
- * User authentication service using Passport.js.
4
- * Provides methods for user authentication, logout, and redirect handling.
5
- *
6
- * @see {@link https://www.passportjs.org/ | Passport.js}
7
- * @example
8
- * ```js
9
- * // Using in async request handler
10
- * import * as expx from 'express-sweet';
11
- *
12
- * router.post('/login', async (req, res, next) => {
13
- * const isAuthenticated = await expx.services.Authentication.authenticate(req, res, next);
14
- * res.json(isAuthenticated);
15
- * });
16
- * ```
17
- *
18
- * @example
19
- * ```js
20
- * // Using in sync request handler
21
- * router.post('/login', async (req, res, next) => {
22
- * const isAuthenticated = await expx.services.Authentication.authenticate(req, res, next);
23
- * if (isAuthenticated)
24
- * await expx.services.Authentication.successRedirect(res);
25
- * else
26
- * await expx.services.Authentication.failureRedirect(req, res);
27
- * });
28
- * ```
29
- */
30
- export default class Authentication {
31
- /**
32
- * Authenticate the user using username and password from request body.
33
- * Uses Passport.js local strategy for authentication.
34
- * @param {express.Request} req The HTTP request object containing user credentials
35
- * @param {express.Response} res The HTTP response object
36
- * @param {express.NextFunction} next The next middleware function
37
- * @returns {Promise<boolean>} Returns true if authentication is successful, false otherwise
38
- * @example
39
- * ```js
40
- * // For asynchronous requests
41
- * const router = Router();
42
- * router.post('/login', async (req, res, next) => {
43
- * const isAuthenticated = await Authentication.authenticate(req, res, next);
44
- * res.json(isAuthenticated);
45
- * });
46
- * ```
47
- */
48
- static authenticate(req: express.Request, res: express.Response, next: express.NextFunction): Promise<boolean>;
49
- /**
50
- * Log out the user by removing req.user property and clearing the login session.
51
- * @param {express.Request} req The HTTP request object
52
- * @example
53
- * ```js
54
- * import {Router} from 'express';
55
- * import * as expx from 'express-sweet';
56
- *
57
- * const router = Router();
58
- * router.get('/logout', (req, res) => {
59
- * expx.services.Authentication.logout(req);
60
- * res.redirect('/');
61
- * });
62
- * ```
63
- */
64
- static logout(req: express.Request): void;
65
- /**
66
- * Redirects to the success page after successful authentication.
67
- * Uses the URL specified in "success_redirect" of config/authentication.js.
68
- * @param {express.Response} res The HTTP response object
69
- * @returns {Promise<void>}
70
- * @example
71
- * ```js
72
- * // For synchronous login handling
73
- * const isAuthenticated = await Authentication.authenticate(req, res, next);
74
- * if (isAuthenticated)
75
- * await Authentication.successRedirect(res);
76
- * ```
77
- */
78
- static successRedirect(res: express.Response): Promise<void>;
79
- /**
80
- * Redirects to the failure page after authentication failure.
81
- * Uses the URL specified in "failure_redirect" of config/authentication.js.
82
- * Supports both static URLs and dynamic URL functions.
83
- * @param {express.Request} req The HTTP request object
84
- * @param {express.Response} res The HTTP response object
85
- * @returns {Promise<void>}
86
- * @example
87
- * ```js
88
- * // For synchronous login handling
89
- * const isAuthenticated = await Authentication.authenticate(req, res, next);
90
- * if (!isAuthenticated)
91
- * await Authentication.failureRedirect(req, res);
92
- * ```
93
- */
94
- static failureRedirect(req: express.Request, res: express.Response): Promise<void>;
95
- }
@@ -1,33 +0,0 @@
1
- /**
2
- * Business logic services for Express Sweet.
3
- *
4
- * Provides high-level service classes for common application functionality
5
- * such as user authentication, authorization, and other business operations.
6
- *
7
- * @module services
8
- * @example
9
- * ```js
10
- * // Using authentication service in routes
11
- * import * as expx from 'express-sweet';
12
- * import {Router} from 'express';
13
- *
14
- * const router = Router();
15
- *
16
- * router.post('/login', async (req, res, next) => {
17
- * const isAuthenticated = await expx.services.Authentication.authenticate(req, res, next);
18
- * if (isAuthenticated)
19
- * await expx.services.Authentication.successRedirect(res);
20
- * else
21
- * await expx.services.Authentication.failureRedirect(req, res);
22
- * });
23
- *
24
- * router.get('/logout', (req, res) => {
25
- * expx.services.Authentication.logout(req);
26
- * res.redirect('/');
27
- * });
28
- * ```
29
- */
30
- /**
31
- * User authentication service using Passport.js
32
- */
33
- export { default as Authentication } from './Authentication';
@@ -1,38 +0,0 @@
1
- /**
2
- * Global type declarations for Express Sweet.
3
- *
4
- * Extends the global namespace with Express Sweet specific variables
5
- * that are accessible throughout the application runtime.
6
- *
7
- * @module global
8
- * @example
9
- * // Accessing global variables anywhere in the application
10
- * console.log(global.APP_DIR); // "/path/to/your/app"
11
- * console.log(global.loadedEnv); // true or false
12
- */
13
- declare global {
14
- /**
15
- * Application root directory path.
16
- * Set by the Global middleware during application initialization.
17
- * Contains the absolute path to the directory where the main application file is located.
18
- * @type {string}
19
- * @example
20
- * // Access in routes or models
21
- * const configPath = `${global.APP_DIR}/config/custom.json`;
22
- * const publicPath = `${global.APP_DIR}/public/uploads`;
23
- */
24
- var APP_DIR: string;
25
- /**
26
- * Environment variables loading flag.
27
- * Set by the Environment middleware to prevent multiple loading of .env files.
28
- * True if environment variables have already been loaded from .env file.
29
- * @type {boolean}
30
- * @example
31
- * // Check if environment variables are loaded
32
- * if (global.loadedEnv) {
33
- * console.log('Environment variables already loaded');
34
- * }
35
- */
36
- var loadedEnv: boolean;
37
- }
38
- export {};
@@ -1,29 +0,0 @@
1
- /**
2
- * Type checking utility class.
3
- * Provides static methods for runtime type validation.
4
- */
5
- export default class Types {
6
- /**
7
- * Check if a function is async (returns a Promise).
8
- * @param {Function} value The function to check
9
- * @returns {boolean} True if async function, false otherwise
10
- * @example
11
- * ```js
12
- * Types.isAsyncFunction(async () => {}); // true
13
- * Types.isAsyncFunction(() => {}); // false
14
- * ```
15
- */
16
- static isAsyncFunction(value: Function): boolean;
17
- /**
18
- * Check if a value is a non-empty string.
19
- * @param {any} value The value to check
20
- * @returns {boolean} True if non-empty string, false otherwise
21
- * @example
22
- * ```js
23
- * Types.isString('hello'); // true
24
- * Types.isString(''); // false
25
- * Types.isString(123); // false
26
- * ```
27
- */
28
- static isString(value: any): boolean;
29
- }