express-sweet 2.0.3 → 2.0.5
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/CHANGELOG.md +46 -3
- package/LICENSE +1 -1
- package/README.md +168 -57
- package/configuration_sample/cjs/config.js +8 -10
- package/configuration_sample/esm/config.js +8 -10
- package/dist/build.cjs +5 -5
- package/dist/build.mjs +2 -2
- package/package.json +4 -3
- package/types/database/Model.d.ts +13 -13
- package/types/handlebars_helpers/array.d.ts +20 -0
- package/types/handlebars_helpers/comparison.d.ts +50 -50
- package/types/handlebars_helpers/date.d.ts +4 -4
- package/types/handlebars_helpers/html.d.ts +20 -3
- package/types/handlebars_helpers/index.d.ts +1 -0
- package/types/handlebars_helpers/layouts.d.ts +4 -4
- package/types/handlebars_helpers/math.d.ts +14 -14
- package/types/handlebars_helpers/number.d.ts +5 -5
- package/types/handlebars_helpers/object.d.ts +4 -4
- package/types/handlebars_helpers/string.d.ts +8 -8
- package/types/interfaces/AuthenticationConfig.d.ts +4 -7
- package/types/interfaces/BasicConfig.d.ts +10 -11
- package/types/interfaces/ViewConfig.d.ts +1 -2
- package/types/utils/Types.d.ts +2 -2
- package/types/utils/isAsyncFunction.d.ts +7 -7
- package/types/utils/isFunction.d.ts +8 -8
|
@@ -56,6 +56,7 @@ export default interface AuthenticationConfig {
|
|
|
56
56
|
success_redirect: string;
|
|
57
57
|
/**
|
|
58
58
|
* URL to redirect after log off, defaults to `/login`.
|
|
59
|
+
* @type {string|((req: express.Request, res: express.Response) => string)}
|
|
59
60
|
* @example
|
|
60
61
|
* // Set the URL to redirect to in case of login failure as a string.
|
|
61
62
|
* failure_redirect: '/login',
|
|
@@ -65,15 +66,14 @@ export default interface AuthenticationConfig {
|
|
|
65
66
|
* // If the role stored in the cookie is admin, redirect to the admin login screen.
|
|
66
67
|
* return req.cookies.role === 'admin' ? '/adminlogin' : 'login';
|
|
67
68
|
* },
|
|
68
|
-
|
|
69
|
-
* @type {string|((req: express.Request, res: express.Response) => string)}
|
|
70
|
-
*/
|
|
69
|
+
*/
|
|
71
70
|
failure_redirect: string | ((req: express.Request, res: express.Response) => string);
|
|
72
71
|
/**
|
|
73
72
|
* This hook is called when authenticating a user.
|
|
74
73
|
* Please find the user information that owns the credentials based on the user name and password you received and return it.
|
|
75
74
|
* If the user who owns the credentials cannot be found, return null.
|
|
76
75
|
* Note that the user information must include an ID value that can identify the user.
|
|
76
|
+
* @type {(username: string, password: string, req: express.Request) => Promise<{[key: string]: any}|null>}
|
|
77
77
|
* @example
|
|
78
78
|
* authenticate_user: async (username, password, req) => {
|
|
79
79
|
* const UserModel = require('../models/UserModel');
|
|
@@ -85,8 +85,6 @@ export default interface AuthenticationConfig {
|
|
|
85
85
|
* raw: true
|
|
86
86
|
* });
|
|
87
87
|
* }
|
|
88
|
-
*
|
|
89
|
-
* @type {(username: string, password: string, req: express.Request) => Promise<{[key: string]: any}|null>}
|
|
90
88
|
*/
|
|
91
89
|
authenticate_user: (username: string, password: string, req: express.Request) => Promise<{
|
|
92
90
|
[key: string]: any;
|
|
@@ -95,6 +93,7 @@ export default interface AuthenticationConfig {
|
|
|
95
93
|
* This hook is called when user authentication is successful.
|
|
96
94
|
* Please search and return the authenticated user information to be set in the session based on the user ID of the parameter.
|
|
97
95
|
* The returned data will be set in the req.user property and the view's session variable.
|
|
96
|
+
* @type {(id: number|string) => Promise<{[key: string]: any}>}
|
|
98
97
|
* @example
|
|
99
98
|
* subscribe_user: async (id) => {
|
|
100
99
|
* const UserModel = require('../models/UserModel');
|
|
@@ -103,8 +102,6 @@ export default interface AuthenticationConfig {
|
|
|
103
102
|
* raw: true
|
|
104
103
|
* });
|
|
105
104
|
* }
|
|
106
|
-
*
|
|
107
|
-
* @type {(id: number|string) => Promise<{[key: string]: any}>}
|
|
108
105
|
*/
|
|
109
106
|
subscribe_user: (id: number | string) => Promise<{
|
|
110
107
|
[key: string]: any;
|
|
@@ -32,12 +32,11 @@ export default interface BasicConfig {
|
|
|
32
32
|
* This is a hook that rewrites the base URL.
|
|
33
33
|
* If you want to rewrite the app.locals.baseUrl property and the view's baseUrl variable, use this hook to return a new base URL.
|
|
34
34
|
* The default value is the referrer's origin (eg https://example.com).
|
|
35
|
+
* @type {(baseUrl: string): string}
|
|
35
36
|
* @example
|
|
36
37
|
* rewrite_base_url: baseUrl => {
|
|
37
38
|
* return `${baseUrl}/admin`;
|
|
38
39
|
* }
|
|
39
|
-
*
|
|
40
|
-
* @type {(baseUrl: string): string}
|
|
41
40
|
*/
|
|
42
41
|
rewrite_base_url?: (baseUrl: string) => string;
|
|
43
42
|
/**
|
|
@@ -55,17 +54,17 @@ export default interface BasicConfig {
|
|
|
55
54
|
is_ajax: (req: express.Request) => boolean;
|
|
56
55
|
/**
|
|
57
56
|
* Hooks the default behavior on request errors.
|
|
58
|
-
* If unset, simply returns an error HTTP status. (<code>res.status(
|
|
59
|
-
* @type {(
|
|
57
|
+
* If unset, simply returns an error HTTP status. (<code>res.status(error.status||500).end();</code>)
|
|
58
|
+
* @type {(error: any, req: express.Request, res: express.Response, next: express.NextFunction) => void}
|
|
60
59
|
* @example
|
|
61
|
-
* hook_handle_error: (
|
|
62
|
-
* if (
|
|
63
|
-
* // If the URL cannot be found, a 404 error screen (views/
|
|
64
|
-
* res.render('
|
|
60
|
+
* hook_handle_error: (error, req, res, next) => {
|
|
61
|
+
* if (error.status === 404)
|
|
62
|
+
* // If the URL cannot be found, a 404 error screen (views/errors/404.hbs) is displayed.
|
|
63
|
+
* res.render('errors/404');
|
|
65
64
|
* else
|
|
66
|
-
* // For other errors, unknown error screen (views/error
|
|
67
|
-
* res.render('error
|
|
65
|
+
* // For other errors, unknown error screen (views/error/500.hbs) is displayed.
|
|
66
|
+
* res.render('error/500');
|
|
68
67
|
* },
|
|
69
68
|
*/
|
|
70
|
-
hook_handle_error?: (
|
|
69
|
+
hook_handle_error?: (error: any, req: express.Request, res: express.Response, next: express.NextFunction) => void;
|
|
71
70
|
}
|
|
@@ -31,13 +31,12 @@ export default interface SesOptions {
|
|
|
31
31
|
/**
|
|
32
32
|
* Hook function just before the view is rendered.
|
|
33
33
|
* For example, you can set your own local variables that can be used within the view.
|
|
34
|
+
* @type {(res: express.Response) => Promise<void>|void}
|
|
34
35
|
* @example
|
|
35
36
|
* // The message set here can be referenced in the view as {{message}}.
|
|
36
37
|
* beforeRender: (req, res) => {
|
|
37
38
|
* res.locals.extra = 'Extra';
|
|
38
39
|
* }
|
|
39
|
-
*
|
|
40
|
-
* @type {(res: express.Response) => Promise<void>|void}
|
|
41
40
|
*/
|
|
42
41
|
beforeRender?: (req: express.Request, res: express.Response) => Promise<void> | void;
|
|
43
42
|
}
|
package/types/utils/Types.d.ts
CHANGED
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
export default class {
|
|
5
5
|
/**
|
|
6
6
|
* Returns true for asynchronous functions, false otherwise.
|
|
7
|
+
* @param {Function} value.
|
|
8
|
+
* @return {boolean}
|
|
7
9
|
* @example
|
|
8
10
|
* Types.isAsyncFunction(async () => {});// true
|
|
9
11
|
* Types.isAsyncFunction(() => {});// false
|
|
10
|
-
* @param {Function} value.
|
|
11
|
-
* @return {boolean}
|
|
12
12
|
*/
|
|
13
13
|
static isAsyncFunction(value: Function): boolean;
|
|
14
14
|
/**
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
* Returns true for asynchronous functions, false otherwise.
|
|
3
|
+
* @param {any} value.
|
|
4
|
+
* @return {boolean}
|
|
5
|
+
* @example
|
|
6
|
+
* utils.isAsyncFunction(async () => {});// true
|
|
7
|
+
* utils.isAsyncFunction(() => {});// false
|
|
8
|
+
*/
|
|
9
9
|
declare const _default: (value: any) => boolean;
|
|
10
10
|
export default _default;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
* Returns true for functions, false otherwise.
|
|
3
|
+
* @param {any} value.
|
|
4
|
+
* @return {boolean}
|
|
5
|
+
* @example
|
|
6
|
+
* utils.isFunction(() => {});// true
|
|
7
|
+
* utils.isFunction(async () => {});// true
|
|
8
|
+
* utils.isFunction('');// false
|
|
9
|
+
*/
|
|
10
10
|
declare const _default: (value: any) => boolean;
|
|
11
11
|
export default _default;
|