express-sweet 1.0.17 → 1.0.20

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.
@@ -0,0 +1,96 @@
1
+ const UserModel = require('../models/UserModel');
2
+
3
+ /**
4
+ * User authentication configuration interface.
5
+ */
6
+ module.exports = {
7
+ /**
8
+ * Enable user authentication, defaults to disabled (false).
9
+ * @type {boolean}
10
+ */
11
+ enabled: true,
12
+
13
+ /**
14
+ * The session store instance, defaults to a new MemoryStore(memory) instance.
15
+ * @type {'memory|redis'}
16
+ */
17
+ session_store: 'memory',
18
+
19
+ /**
20
+ * If the session is stored in "redis", this field is required and should be set to the hostname of the Redis server.
21
+ * For example, to connect to redis on localhost on port 6379, set "redis://localhost:6379".
22
+ * To connect to a different host or port, use a connection string in the format "redis[s]://[[username][:password]@][host][:port][/db-number]".
23
+ * For example, "redis://alice:foobared@awesome.redis.server:6380".
24
+ * @type {string|undefined}
25
+ */
26
+ redis_host: undefined,
27
+
28
+ /**
29
+ * Authentication user ID field name, defaults to `username`.
30
+ * @type {string}
31
+ */
32
+ username: 'email',
33
+
34
+ /**
35
+ * Authentication password field name, defaults to `password`.
36
+ * @type {string}
37
+ */
38
+ password: 'password',
39
+
40
+ /**
41
+ * URL to redirect after successful authentication, defaults to `/`.
42
+ * @type {string}
43
+ */
44
+ success_redirect: '/',
45
+
46
+ /**
47
+ * URL to redirect after log off, defaults to `/login`.
48
+ * @type {string}
49
+ */
50
+ failure_redirect: '/login',
51
+
52
+ /**
53
+ * This hook is called when authenticating a user.
54
+ * Please find the user information that owns the credentials based on the user name and password you received and return it.
55
+ * If the user who owns the credentials cannot be found, return null.
56
+ *
57
+ * Note that the user information must include an ID value that can identify the user.
58
+ *
59
+ * @type {(username: string, password: string) => Promise<{[key: string]: any}|null>}
60
+ */
61
+ authenticate_user: async (username, password) => {
62
+ return UserModel.findOne({
63
+ where: {
64
+ email: username,
65
+ password: password
66
+ },
67
+ raw: true
68
+ });
69
+ },
70
+
71
+ /**
72
+ * This hook is called when user authentication is successful.
73
+ * Please search and return the authenticated user information to be set in the session based on the user ID of the parameter.
74
+ * The returned data will be set in the req.user property and the view's session variable.
75
+ *
76
+ * @type {(id: number|string) => Promise<{[key: string]: any}>}
77
+ */
78
+ subscribe_user: async (id) => {
79
+ return UserModel.findOne({
80
+ where: {id},
81
+ raw: true
82
+ });
83
+ },
84
+
85
+ /**
86
+ * URL without authentication. If the URL described in the access URL partially matches, authentication will not be performed, defaults to none.
87
+ * @type {(string|RegExp)[]}
88
+ */
89
+ allow_unauthenticated: ['/api'],
90
+
91
+ /**
92
+ * Authenticated user session expiration, defaults to 24 hours (24 * 3600000).
93
+ * @type {number}
94
+ */
95
+ expiration: 24 * 3600000
96
+ }
@@ -0,0 +1,78 @@
1
+ const path = require('path');
2
+
3
+ /**
4
+ * Express Sweet basic configuration interface.
5
+ */
6
+ module.exports = {
7
+ /**
8
+ * Environment variable file (.env) path, defaults to none (undefined).
9
+ * @type {string}
10
+ */
11
+ env_path: '.env',
12
+
13
+ /**
14
+ * CORS permission, defaults to invalid (false).
15
+ * @type {{enabled: boolean}}
16
+ */
17
+ cors_enabled: true,
18
+
19
+ /**
20
+ * Maximum body size you can request, defaults to `100kb`.
21
+ * @type {string|number}
22
+ */
23
+ max_body_size: '100kb',
24
+
25
+ /**
26
+ * Absolute path to the router directory, defaults to `<application root directory>/routes`.
27
+ * @type {string}
28
+ */
29
+ router_dir: path.join(process.cwd(), 'routes'),
30
+
31
+ /**
32
+ * The endpoint to run when the root URL is requested, defaults to none (undefined).
33
+ * @type {string}
34
+ */
35
+ default_router: '/home',
36
+
37
+ /**
38
+ * This is a hook that rewrites the base URL.
39
+ * 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.
40
+ * The default value is the referrer's origin (eg https://example.com).
41
+ *
42
+ * @example
43
+ * rewrite_base_url: baseUrl => {
44
+ * return `${baseUrl}/admin`;
45
+ * }
46
+ *
47
+ * @type {(baseUrl: string): string}
48
+ */
49
+ rewrite_base_url: baseUrl => {
50
+ return baseUrl;
51
+ },
52
+
53
+ /**
54
+ * This is a hook for error handling.
55
+ * For example, you can use it when you want to send an external notification of the error received by this hook.
56
+ *
57
+ * @example
58
+ * error_handler: async err => {
59
+ * // Notify system administrator of error.
60
+ * return new Promise((resolve, reject) => {
61
+ * const sendmail = require('sendmail')();
62
+ * sendmail({
63
+ * from: 'no-reply@example.com',
64
+ * to: 'administrator@example.com',
65
+ * subject: 'Error occurred',
66
+ * text: err.message
67
+ * }, err => {
68
+ * err ? reject(err) : resolve();
69
+ * });
70
+ * });
71
+ * }
72
+ *
73
+ * @type {(err: any): void|Promise<void>}
74
+ */
75
+ error_handler: err => {
76
+ console.error(`An error has occurred. Error message: ${err.message}`);
77
+ }
78
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Database configuration.
3
+ */
4
+ module.exports = {
5
+ development: {
6
+ username: 'root',
7
+ password: 'password',
8
+ database: 'mydb',
9
+ host: 'localhost',
10
+ port: undefined,
11
+ dialect: 'mariadb',
12
+ timezone: '+09:00',
13
+ logging: false
14
+ },
15
+ test: {
16
+ username: 'root',
17
+ password: 'password',
18
+ database: 'mydb',
19
+ host: 'localhost',
20
+ port: undefined,
21
+ dialect: 'mariadb',
22
+ timezone: '+09:00',
23
+ logging: false
24
+ },
25
+ production: {
26
+ username: 'root',
27
+ password: 'password',
28
+ database: 'mydb',
29
+ host: 'localhost',
30
+ port: undefined,
31
+ dialect: 'mariadb',
32
+ timezone: '+09:00',
33
+ logging: false
34
+ }
35
+ }
@@ -0,0 +1,36 @@
1
+ const path = require('path');
2
+
3
+ /**
4
+ * View's configuration interface.
5
+ */
6
+ module.exports = {
7
+ /**
8
+ * Absolute path to the directory where the view files are located, defaults to `<application root directory>/views`.
9
+ * @type {string}
10
+ */
11
+ views_dir: path.join(process.cwd(), 'views'),
12
+
13
+ /**
14
+ * Path to partials templates, one or several directories, defaults to `<application root directory>/views/partials`.
15
+ * @type {string|string[]}
16
+ */
17
+ partials_dir: path.join(process.cwd(), 'views/partials'),
18
+
19
+ /**
20
+ * Path to layout templates, defaults to `<application root directory>/views/layout`.
21
+ * @type {string}
22
+ */
23
+ layouts_dir: path.join(process.cwd(), 'views/layout'),
24
+
25
+ /**
26
+ * Absolute path to default layout template. defaults to `<application root directory>/views/layout/default.hbs`.
27
+ * @type {string}
28
+ */
29
+ default_layout: path.join(process.cwd(), 'views/layout/default.hbs'),
30
+
31
+ /**
32
+ * Extension for templates & partials, defaults to `.hbs`,
33
+ * @type {string}
34
+ */
35
+ extension: '.hbs'
36
+ }
@@ -0,0 +1,96 @@
1
+ import UserModel from '../models/UserModel';
2
+
3
+ /**
4
+ * User authentication configuration interface.
5
+ */
6
+ export default {
7
+ /**
8
+ * Enable user authentication, defaults to disabled (false).
9
+ * @type {boolean}
10
+ */
11
+ enabled: true,
12
+
13
+ /**
14
+ * The session store instance, defaults to a new MemoryStore(memory) instance.
15
+ * @type {'memory|redis'}
16
+ */
17
+ session_store: 'memory',
18
+
19
+ /**
20
+ * If the session is stored in "redis", this field is required and should be set to the hostname of the Redis server.
21
+ * For example, to connect to redis on localhost on port 6379, set "redis://localhost:6379".
22
+ * To connect to a different host or port, use a connection string in the format "redis[s]://[[username][:password]@][host][:port][/db-number]".
23
+ * For example, "redis://alice:foobared@awesome.redis.server:6380".
24
+ * @type {string|undefined}
25
+ */
26
+ redis_host: undefined,
27
+
28
+ /**
29
+ * Authentication user ID field name, defaults to `username`.
30
+ * @type {string}
31
+ */
32
+ username: 'email',
33
+
34
+ /**
35
+ * Authentication password field name, defaults to `password`.
36
+ * @type {string}
37
+ */
38
+ password: 'password',
39
+
40
+ /**
41
+ * URL to redirect after successful authentication, defaults to `/`.
42
+ * @type {string}
43
+ */
44
+ success_redirect: '/',
45
+
46
+ /**
47
+ * URL to redirect after log off, defaults to `/login`.
48
+ * @type {string}
49
+ */
50
+ failure_redirect: '/login',
51
+
52
+ /**
53
+ * This hook is called when authenticating a user.
54
+ * Please find the user information that owns the credentials based on the user name and password you received and return it.
55
+ * If the user who owns the credentials cannot be found, return null.
56
+ *
57
+ * Note that the user information must include an ID value that can identify the user.
58
+ *
59
+ * @type {(username: string, password: string) => Promise<{[key: string]: any}|null>}
60
+ */
61
+ authenticate_user: async (username, password) => {
62
+ return UserModel.findOne({
63
+ where: {
64
+ email: username,
65
+ password: password
66
+ },
67
+ raw: true
68
+ });
69
+ },
70
+
71
+ /**
72
+ * This hook is called when user authentication is successful.
73
+ * Please search and return the authenticated user information to be set in the session based on the user ID of the parameter.
74
+ * The returned data will be set in the req.user property and the view's session variable.
75
+ *
76
+ * @type {(id: number|string) => Promise<{[key: string]: any}>}
77
+ */
78
+ subscribe_user: async (id) => {
79
+ return UserModel.findOne({
80
+ where: {id},
81
+ raw: true
82
+ });
83
+ },
84
+
85
+ /**
86
+ * URL without authentication. If the URL described in the access URL partially matches, authentication will not be performed, defaults to none.
87
+ * @type {(string|RegExp)[]}
88
+ */
89
+ allow_unauthenticated: ['/api'],
90
+
91
+ /**
92
+ * Authenticated user session expiration, defaults to 24 hours (24 * 3600000).
93
+ * @type {number}
94
+ */
95
+ expiration: 24 * 3600000
96
+ }
@@ -0,0 +1,78 @@
1
+ import path from 'path';
2
+
3
+ /**
4
+ * Express Sweet basic configuration interface.
5
+ */
6
+ export default {
7
+ /**
8
+ * Environment variable file (.env) path, defaults to none (undefined).
9
+ * @type {string}
10
+ */
11
+ env_path: '.env',
12
+
13
+ /**
14
+ * CORS permission, defaults to invalid (false).
15
+ * @type {{enabled: boolean}}
16
+ */
17
+ cors_enabled: true,
18
+
19
+ /**
20
+ * Maximum body size you can request, defaults to `100kb`.
21
+ * @type {string|number}
22
+ */
23
+ max_body_size: '100kb',
24
+
25
+ /**
26
+ * Absolute path to the router directory, defaults to `<application root directory>/routes`.
27
+ * @type {string}
28
+ */
29
+ router_dir: path.join(process.cwd(), 'routes'),
30
+
31
+ /**
32
+ * The endpoint to run when the root URL is requested, defaults to none (undefined).
33
+ * @type {string}
34
+ */
35
+ default_router: '/home',
36
+
37
+ /**
38
+ * This is a hook that rewrites the base URL.
39
+ * 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.
40
+ * The default value is the referrer's origin (eg https://example.com).
41
+ *
42
+ * @example
43
+ * rewrite_base_url: baseUrl => {
44
+ * return `${baseUrl}/admin`;
45
+ * }
46
+ *
47
+ * @type {(baseUrl: string): string}
48
+ */
49
+ rewrite_base_url: baseUrl => {
50
+ return baseUrl;
51
+ },
52
+
53
+ /**
54
+ * This is a hook for error handling.
55
+ * For example, you can use it when you want to send an external notification of the error received by this hook.
56
+ *
57
+ * @example
58
+ * error_handler: async err => {
59
+ * // Notify system administrator of error.
60
+ * return new Promise((resolve, reject) => {
61
+ * const sendmail = require('sendmail')();
62
+ * sendmail({
63
+ * from: 'no-reply@example.com',
64
+ * to: 'administrator@example.com',
65
+ * subject: 'Error occurred',
66
+ * text: err.message
67
+ * }, err => {
68
+ * err ? reject(err) : resolve();
69
+ * });
70
+ * });
71
+ * }
72
+ *
73
+ * @type {(err: any): void|Promise<void>}
74
+ */
75
+ error_handler: err => {
76
+ console.error(`An error has occurred. Error message: ${err.message}`);
77
+ }
78
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Database configuration.
3
+ */
4
+ export default {
5
+ development: {
6
+ username: 'root',
7
+ password: 'password',
8
+ database: 'mydb',
9
+ host: 'localhost',
10
+ port: undefined,
11
+ dialect: 'mariadb',
12
+ timezone: '+09:00',
13
+ logging: false
14
+ },
15
+ test: {
16
+ username: 'root',
17
+ password: 'password',
18
+ database: 'mydb',
19
+ host: 'localhost',
20
+ port: undefined,
21
+ dialect: 'mariadb',
22
+ timezone: '+09:00',
23
+ logging: false
24
+ },
25
+ production: {
26
+ username: 'root',
27
+ password: 'password',
28
+ database: 'mydb',
29
+ host: 'localhost',
30
+ port: undefined,
31
+ dialect: 'mariadb',
32
+ timezone: '+09:00',
33
+ logging: false
34
+ }
35
+ }
@@ -0,0 +1,36 @@
1
+ import path from 'path';
2
+
3
+ /**
4
+ * View's configuration interface.
5
+ */
6
+ export default {
7
+ /**
8
+ * Absolute path to the directory where the view files are located, defaults to `<application root directory>/views`.
9
+ * @type {string}
10
+ */
11
+ views_dir: path.join(process.cwd(), 'views'),
12
+
13
+ /**
14
+ * Path to partials templates, one or several directories, defaults to `<application root directory>/views/partials`.
15
+ * @type {string|string[]}
16
+ */
17
+ partials_dir: path.join(process.cwd(), 'views/partials'),
18
+
19
+ /**
20
+ * Path to layout templates, defaults to `<application root directory>/views/layout`.
21
+ * @type {string}
22
+ */
23
+ layouts_dir: path.join(process.cwd(), 'views/layout'),
24
+
25
+ /**
26
+ * Absolute path to default layout template. defaults to `<application root directory>/views/layout/default.hbs`.
27
+ * @type {string}
28
+ */
29
+ default_layout: path.join(process.cwd(), 'views/layout/default.hbs'),
30
+
31
+ /**
32
+ * Extension for templates & partials, defaults to `.hbs`,
33
+ * @type {string}
34
+ */
35
+ extension: '.hbs'
36
+ }
package/package.json CHANGED
@@ -1,19 +1,19 @@
1
1
  {
2
2
  "name": "express-sweet",
3
- "version": "1.0.17",
3
+ "version": "1.0.20",
4
4
  "description": "Extend Express functionality with Express Sweet and start developing fast, minimal web applications.",
5
5
  "main": "dist/build.common.js",
6
6
  "module": "dist/build.esm.js",
7
7
  "types": "types/index.d.ts",
8
8
  "files": [
9
- "LICENSE",
10
- "README.md",
11
- "CHANGELOG.md",
12
9
  "dist/",
13
10
  "docs/",
14
- "example/",
15
11
  "types/",
16
- "package.json"
12
+ "CHANGELOG.md",
13
+ "INSTALL-Redis.md",
14
+ "LICENSE",
15
+ "package.json",
16
+ "README.md"
17
17
  ],
18
18
  "scripts": {
19
19
  "watch": "node --max-old-space-size=8192 node_modules/rollup/dist/bin/rollup -c rollup.config.js --watch",
@@ -64,10 +64,11 @@
64
64
  },
65
65
  "homepage": "https://github.com/takuya-motoshima/express-sweet#readme",
66
66
  "dependencies": {
67
- "aws-sdk": "^2.690.0",
67
+ "aws-sdk": "^2.1142.0",
68
68
  "body-parser": "^1.19.0",
69
69
  "class-transformer": "^0.2.3",
70
70
  "class-validator": "^0.12.2",
71
+ "connect-redis": "^6.1.3",
71
72
  "cookie-parser": "~1.4.4",
72
73
  "cors": "^2.8.5",
73
74
  "debug": "~2.6.9",
@@ -90,12 +91,14 @@
90
91
  "nodejs-shared": "^1.0.2",
91
92
  "passport": "^0.4.1",
92
93
  "passport-local": "^1.0.0",
94
+ "redis": "^4.1.0",
93
95
  "reflect-metadata": "^0.1.13",
94
96
  "sequelize": "^5.22.4",
95
97
  "uniqid": "^5.2.0"
96
98
  },
97
99
  "devDependencies": {
98
100
  "@types/aws-sdk": "^2.7.0",
101
+ "@types/connect-redis": "^0.0.18",
99
102
  "@types/cookie-parser": "^1.4.2",
100
103
  "@types/debug": "^4.1.5",
101
104
  "@types/express": "^4.17.11",
@@ -162,7 +162,7 @@ export default class Model extends sequelize.Model {
162
162
  * transaction = await BookModel.begin();
163
163
  * const book = await BookModel.create({title: 'When Im Gone'}, {transaction});
164
164
  * await transaction.commit();
165
- * } catch(error) {
165
+ * } catch {
166
166
  * if (transaction)
167
167
  * await transaction.rollback();
168
168
  * }
@@ -1,21 +1,14 @@
1
1
  /**
2
- * Stringify an object using JSON.stringify.
2
+ * Use moment to format the date.
3
3
  *
4
4
  * @example
5
- * {{json_stringify value}}
6
- *
7
- * @param {any} value The value to convert to a JSON string.
8
- * @param {number} indent The number of space characters to use as whitespace.
9
- * @return {string} A JSON string representing the given value, or undefined.
10
- */
11
- export declare function json_stringify(value: any, indent?: number | string): string | undefined;
12
- /**
13
- * Parses the given string using JSON.parse.
14
- *
15
- * @example
16
- * {{json_parse value}}
17
- *
18
- * @param {any} value Object to stringify.
19
- * @return {any} JavaScript value or object described by a string.
5
+ * {{format_date 'YYYY/MM/DD' "2021-10-24T02:13:06.610Z"}} => 2021/10/24
6
+ * {{format_date 'YYYY/MM/DD' "2021-10-24T02:13:06.610Z" 'jp'}} => 2021/10/24
7
+ * {{format_date 'YYYY/MM/DD' "2021-10-24T02:13:06.610Z" 'es'}} => 2021/10/24
8
+ *
9
+ * @param {string} format A format string based on moment.
10
+ * @param {string} date Date string to format.
11
+ * @param {string|string[]} locale Language or language-country locale string (or array of strings) available in https://github.com/moment/moment/tree/develop/locale .
12
+ * @returns {string} Returns formatted date.
20
13
  */
21
- export declare function json_parse(value: any): any;
14
+ export declare function format_date(format: string, date: string, locale: string | string[]): string;
@@ -2,4 +2,5 @@ import * as html from './html';
2
2
  import * as object from './object';
3
3
  import * as string from './string';
4
4
  import * as comparison from './comparison';
5
- export { html, object, string, comparison };
5
+ import * as date from './date';
6
+ export { html, object, string, comparison, date };
@@ -7,6 +7,19 @@ export default interface {
7
7
  * @type {boolean}
8
8
  */
9
9
  enabled: boolean;
10
+ /**
11
+ * The session store instance, defaults to a new MemoryStore(memory) instance.
12
+ * @type {'memory'|'redis'}
13
+ */
14
+ session_store: 'memory' | 'redis';
15
+ /**
16
+ * If the session is stored in "redis", this field is required and should be set to the hostname of the Redis server.
17
+ * For example, to connect to redis on localhost on port 6379, set "redis://localhost:6379".
18
+ * To connect to a different host or port, use a connection string in the format "redis[s]://[[username][:password]@][host][:port][/db-number]".
19
+ * For example, "redis://alice:foobared@awesome.redis.server:6380".
20
+ * @type {string|undefined}
21
+ */
22
+ redis_host?: string;
10
23
  /**
11
24
  * Authentication user ID field name, defaults to `username`.
12
25
  * @type {string}
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Bounding box interface for faces, labels, borders, etc.
2
+ * Bounding box of the face.
3
3
  */
4
4
  export default interface {
5
5
  /**
@@ -0,0 +1,40 @@
1
+ /**
2
+ * The emotions that appear to be expressed on the face, and the confidence level in the determination.
3
+ */
4
+ export default interface {
5
+ /**
6
+ * Confidence level of "disgusted" predicted from the face.
7
+ * @type {number}
8
+ */
9
+ disgusted: number;
10
+ /**
11
+ * Confidence level of "happy" predicted from the face.
12
+ * @type {number}
13
+ */
14
+ happy: number;
15
+ /**
16
+ * Confidence level of "surprised" predicted from the face.
17
+ * @type {number}
18
+ */
19
+ surprised: number;
20
+ /**
21
+ * Confidence level of "angry" predicted from the face.
22
+ * @type {number}
23
+ */
24
+ angry: number;
25
+ /**
26
+ * Confidence level of "confused" predicted from the face.
27
+ * @type {number}
28
+ */
29
+ confused: number;
30
+ /**
31
+ * Confidence level of "calm" predicted from the face.
32
+ * @type {number}
33
+ */
34
+ calm: number;
35
+ /**
36
+ * Confidence level of "sad" predicted from the face.
37
+ * @type {number}
38
+ */
39
+ sad: number;
40
+ }
@@ -6,7 +6,7 @@ export default class {
6
6
  /**
7
7
  * Mount on application.
8
8
  */
9
- static mount(app: express.Express): undefined;
9
+ static mount(app: express.Express): void;
10
10
  /**
11
11
  * Returns the option.
12
12
  *