express-sweet 1.0.35 → 1.0.37

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 (33) hide show
  1. package/CHANGELOG.md +66 -1
  2. package/dist/build.common.js +11 -11
  3. package/dist/build.esm.js +12 -12
  4. package/docs/index.html +321 -38
  5. package/package.json +1 -1
  6. package/types/database/index.d.ts +3 -3
  7. package/types/exceptions/index.d.ts +5 -5
  8. package/types/handlebars_helpers/index.d.ts +8 -7
  9. package/types/handlebars_helpers/math.d.ts +81 -0
  10. package/types/index.d.ts +7 -7
  11. package/types/interfaces/{AuthenticationOptions.d.ts → AuthenticationConfig.d.ts} +0 -14
  12. package/types/interfaces/BasicConfig.d.ts +74 -0
  13. package/types/interfaces/FaceMatch.d.ts +1 -1
  14. package/types/interfaces/{ViewOptions.d.ts → ViewConfig.d.ts} +2 -2
  15. package/types/interfaces/index.d.ts +9 -9
  16. package/types/middlewares/CORS.d.ts +0 -1
  17. package/types/middlewares/Environment.d.ts +0 -1
  18. package/types/middlewares/{ErrorHandling.d.ts → ErrorHandler.d.ts} +0 -1
  19. package/types/middlewares/Http.d.ts +0 -1
  20. package/types/middlewares/Local.d.ts +0 -1
  21. package/types/middlewares/View.d.ts +0 -1
  22. package/types/middlewares/index.d.ts +8 -8
  23. package/types/routing/Router.d.ts +0 -1
  24. package/types/routing/index.d.ts +1 -1
  25. package/types/services/Authentication.d.ts +0 -1
  26. package/types/services/index.d.ts +3 -3
  27. package/types/utils/index.d.ts +4 -0
  28. package/types/utils/loadAuthenticationConfig.d.ts +8 -0
  29. package/types/utils/loadBasicConfig.d.ts +8 -0
  30. package/types/utils/loadDatabaseConfig.d.ts +8 -0
  31. package/types/utils/loadViewConfig.d.ts +8 -0
  32. package/types/interfaces/Config.d.ts +0 -66
  33. /package/types/interfaces/{DatabaseOptions.d.ts → DatabaseConfig.d.ts} +0 -0
@@ -0,0 +1,74 @@
1
+ import express from 'express';
2
+ /**
3
+ * Express Sweet basic configuration interface.
4
+ */
5
+ export default interface {
6
+ /**
7
+ * Environment variable file (.env) path, defaults to none (undefined).
8
+ * @type {string}
9
+ */
10
+ env_path?: string;
11
+ /**
12
+ * CORS permission, defaults to invalid (false).
13
+ * @type {{enabled: boolean}}
14
+ */
15
+ cors_enabled?: boolean;
16
+ /**
17
+ * Maximum body size you can request, defaults to `100kb`.
18
+ * @type {string|number}
19
+ */
20
+ max_body_size?: string | number;
21
+ /**
22
+ * Absolute path to the router directory, defaults to `<application root directory>/routes`.
23
+ * @type {string}
24
+ */
25
+ router_dir?: string;
26
+ /**
27
+ * The endpoint to run when the root URL is requested, defaults to none (undefined).
28
+ * @type {string}
29
+ */
30
+ default_router?: string;
31
+ /**
32
+ * This is a hook that rewrites the base URL.
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
+ * The default value is the referrer's origin (eg https://example.com).
35
+ *
36
+ * @example
37
+ * rewrite_base_url: baseUrl => {
38
+ * return `${baseUrl}/admin`;
39
+ * }
40
+ *
41
+ * @type {(baseUrl: string): string}
42
+ */
43
+ rewrite_base_url?: (baseUrl: string) => string;
44
+ /**
45
+ * How to determine if it is an ajax request.
46
+ * The default is that if there is an XMLHttpRequest in the request header (req.xhr) returns true.
47
+ * For example, if there is no XMLHttpRequest in req(express.Request) and the Ajax endpoint starts with /api, a custom Ajax decision can be made like "return /^\/api\//.test(req.path)".
48
+ *
49
+ * @type {(req: express.Request) => boolean}
50
+ * @example
51
+ * is_ajax: req => {
52
+ * // If the request URL begins with /api, it is assumed to be Ajax.
53
+ * return /^\/api/.test(req.path);
54
+ * // return !!req.xhr;
55
+ * }
56
+ */
57
+ is_ajax: (req: express.Request) => boolean;
58
+ /**
59
+ * Hooks the default behavior on request errors.
60
+ * If unset, simply returns an error HTTP status. (<code>res.status(err.status||500).end();</code>)
61
+ *
62
+ * @type {(err: any, req: express.Request, res: express.Response, next: express.NextFunction) => void}
63
+ * @example
64
+ * hook_handle_error: (err, req, res, next) => {
65
+ * if (err.status === 404)
66
+ * // If the URL cannot be found, a 404 error screen (views/error-404.hbs) is displayed.
67
+ * res.render('error-404');
68
+ * else
69
+ * // For other errors, unknown error screen (views/error-unknown.hbs) is displayed.
70
+ * res.render('error-unknown');
71
+ * },
72
+ */
73
+ hook_handle_error?: (err: any, req: express.Request, res: express.Response, next: express.NextFunction) => void;
74
+ }
@@ -1,4 +1,4 @@
1
- import BoundingBox from './BoundingBox';
1
+ import BoundingBox from '~/interfaces/BoundingBox';
2
2
  /**
3
3
  * This is the metadata structure of the bounding box coordinates, reliability (the bounding box contains a face), face ID, etc. returned by the searchFaces(), listFaces() methods, etc.
4
4
  */
@@ -38,7 +38,7 @@ export default interface {
38
38
  * res.locals.message = 'Hello World';
39
39
  * }
40
40
  *
41
- * @type {(res: express.Response) => void}
41
+ * @type {(res: express.Response) => Promise<void>|void}
42
42
  */
43
- beforeRender?: (req: express.Request, res: express.Response) => void;
43
+ beforeRender?: (req: express.Request, res: express.Response) => Promise<void> | void;
44
44
  }
@@ -1,9 +1,9 @@
1
- import AuthenticationOptions from './AuthenticationOptions';
2
- import Config from './Config';
3
- import DatabaseOptions from './DatabaseOptions';
4
- import FaceMatch from './FaceMatch';
5
- import BoundingBox from './BoundingBox';
6
- import RekognitionOptions from './RekognitionOptions';
7
- import SesOptions from './SesOptions';
8
- import ViewOptions from './ViewOptions';
9
- export { AuthenticationOptions, Config, DatabaseOptions, FaceMatch, BoundingBox, RekognitionOptions, SesOptions, ViewOptions };
1
+ import AuthenticationConfig from '~/interfaces/AuthenticationConfig';
2
+ import BasicConfig from '~/interfaces/BasicConfig';
3
+ import DatabaseConfig from '~/interfaces/DatabaseConfig';
4
+ import FaceMatch from '~/interfaces/FaceMatch';
5
+ import BoundingBox from '~/interfaces/BoundingBox';
6
+ import RekognitionOptions from '~/interfaces/RekognitionOptions';
7
+ import SesOptions from '~/interfaces/SesOptions';
8
+ import ViewConfig from '~/interfaces/ViewConfig';
9
+ export { AuthenticationConfig, BasicConfig, DatabaseConfig, FaceMatch, BoundingBox, RekognitionOptions, SesOptions, ViewConfig };
@@ -3,7 +3,6 @@ import express from 'express';
3
3
  * Enables the CORS.
4
4
  */
5
5
  export default class {
6
- #private;
7
6
  /**
8
7
  * Mount on application.
9
8
  */
@@ -3,7 +3,6 @@
3
3
  * Read the environment variable file in options.path and set it in "process.env".
4
4
  */
5
5
  export default class {
6
- #private;
7
6
  /**
8
7
  * Mount on application.
9
8
  */
@@ -3,7 +3,6 @@ import express from 'express';
3
3
  * Error handling.
4
4
  */
5
5
  export default class {
6
- #private;
7
6
  /**
8
7
  * Mount on application.
9
8
  */
@@ -3,7 +3,6 @@ import express from 'express';
3
3
  * Defines all the requisites in HTTP.
4
4
  */
5
5
  export default class {
6
- #private;
7
6
  /**
8
7
  * Mount on application.
9
8
  */
@@ -6,7 +6,6 @@ import express from 'express';
6
6
  * baseUrl: The base URL for this application.
7
7
  */
8
8
  export default class {
9
- #private;
10
9
  /**
11
10
  * Mount on application.
12
11
  */
@@ -3,7 +3,6 @@ import express from 'express';
3
3
  * Enable Handlebars template engine.
4
4
  */
5
5
  export default class {
6
- #private;
7
6
  /**
8
7
  * Mount on application.
9
8
  */
@@ -1,8 +1,8 @@
1
- import CORS from './CORS';
2
- import Environment from './Environment';
3
- import Global from './Global';
4
- import Http from './Http';
5
- import Local from './Local';
6
- import View from './View';
7
- import ErrorHandling from './ErrorHandling';
8
- export { CORS, Environment, Global, Http, Local, View, ErrorHandling };
1
+ import CORS from '~/middlewares/CORS';
2
+ import Environment from '~/middlewares/Environment';
3
+ import Global from '~/middlewares/Global';
4
+ import Http from '~/middlewares/Http';
5
+ import Local from '~/middlewares/Local';
6
+ import View from '~/middlewares/View';
7
+ import ErrorHandler from '~/middlewares/ErrorHandler';
8
+ export { CORS, Environment, Global, Http, Local, View, ErrorHandler, };
@@ -6,7 +6,6 @@ import express from 'express';
6
6
  * For example, if you have "routes/api/users.js", you can request the method in "user.js (ts)" with the base URL as "https:////api/users".
7
7
  */
8
8
  export default class {
9
- #private;
10
9
  /**
11
10
  * Mount on application.
12
11
  */
@@ -1,2 +1,2 @@
1
- import Router from './Router';
1
+ import Router from '~/routing/Router';
2
2
  export { Router };
@@ -3,7 +3,6 @@ import express from 'express';
3
3
  * User authentication service.
4
4
  */
5
5
  export default class {
6
- #private;
7
6
  /**
8
7
  * Authenticate the user.
9
8
  *
@@ -1,4 +1,4 @@
1
- import AWSRekognitionClient from './AWSRekognitionClient';
2
- import Authentication from './Authentication';
3
- import AWSSesClient from './AWSSesClient';
1
+ import AWSRekognitionClient from '~/services/AWSRekognitionClient';
2
+ import Authentication from '~/services/Authentication';
3
+ import AWSSesClient from '~/services/AWSSesClient';
4
4
  export { AWSRekognitionClient, Authentication, AWSSesClient, };
@@ -4,5 +4,9 @@ declare const _default: {
4
4
  isFunction: (value: any) => boolean;
5
5
  isObject: (value: any) => boolean;
6
6
  isString: (value: any) => boolean;
7
+ loadAuthenticationConfig: () => import("../interfaces").AuthenticationConfig;
8
+ loadBasicConfig: () => import("../interfaces").BasicConfig;
9
+ loadDatabaseConfig: () => import("sequelize").Options;
10
+ loadViewConfig: () => import("../interfaces").ViewConfig;
7
11
  };
8
12
  export default _default;
@@ -0,0 +1,8 @@
1
+ import AuthenticationConfig from '~/interfaces/AuthenticationConfig';
2
+ /**
3
+ * Get Authentication configuration (config/authentication).
4
+ *
5
+ * @return {AuthenticationConfig} Loaded configuration.
6
+ */
7
+ declare const _default: () => AuthenticationConfig;
8
+ export default _default;
@@ -0,0 +1,8 @@
1
+ import BasicConfig from '~/interfaces/BasicConfig';
2
+ /**
3
+ * Get basic configuration (config/config).
4
+ *
5
+ * @return {BasicConfig} Loaded configuration.
6
+ */
7
+ declare const _default: () => BasicConfig;
8
+ export default _default;
@@ -0,0 +1,8 @@
1
+ import sequelize from 'sequelize';
2
+ /**
3
+ * Get database configuration (config/database).
4
+ *
5
+ * @return {sequelize.Options} Loaded configuration.
6
+ */
7
+ declare const _default: () => sequelize.Options;
8
+ export default _default;
@@ -0,0 +1,8 @@
1
+ import ViewConfig from '~/interfaces/ViewConfig';
2
+ /**
3
+ * Get view configuration (config/view).
4
+ *
5
+ * @return {ViewConfig} Loaded configuration.
6
+ */
7
+ declare const _default: () => ViewConfig;
8
+ export default _default;
@@ -1,66 +0,0 @@
1
- /**
2
- * Express Sweet basic configuration interface.
3
- */
4
- export default interface {
5
- /**
6
- * Environment variable file (.env) path, defaults to none (undefined).
7
- * @type {string}
8
- */
9
- env_path?: string;
10
- /**
11
- * CORS permission, defaults to invalid (false).
12
- * @type {{enabled: boolean}}
13
- */
14
- cors_enabled?: boolean;
15
- /**
16
- * Maximum body size you can request, defaults to `100kb`.
17
- * @type {string|number}
18
- */
19
- max_body_size?: string | number;
20
- /**
21
- * Absolute path to the router directory, defaults to `<application root directory>/routes`.
22
- * @type {string}
23
- */
24
- router_dir?: string;
25
- /**
26
- * The endpoint to run when the root URL is requested, defaults to none (undefined).
27
- * @type {string}
28
- */
29
- default_router?: string;
30
- /**
31
- * This is a hook that rewrites the base URL.
32
- * 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.
33
- * The default value is the referrer's origin (eg https://example.com).
34
- *
35
- * @example
36
- * rewrite_base_url: baseUrl => {
37
- * return `${baseUrl}/admin`;
38
- * }
39
- *
40
- * @type {(baseUrl: string): string}
41
- */
42
- rewrite_base_url?: (baseUrl: string) => string;
43
- /**
44
- * This is a hook for error handling.
45
- * For example, you can use it when you want to send an external notification of the error received by this hook.
46
- *
47
- * @example
48
- * error_handler: async err => {
49
- * // Notify system administrator of error.
50
- * return new Promise((resolve, reject) => {
51
- * const sendmail = require('sendmail')();
52
- * sendmail({
53
- * from: 'no-reply@example.com',
54
- * to: 'administrator@example.com',
55
- * subject: 'Error occurred',
56
- * text: err.message
57
- * }, err => {
58
- * err ? reject(err) : resolve();
59
- * });
60
- * });
61
- * }
62
- *
63
- * @type {(err: any): void|Promise<void>}
64
- */
65
- error_handler?: (err: any) => void | Promise<void>;
66
- }