express-sweet 2.0.1 → 2.0.3

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 (63) hide show
  1. package/CHANGELOG.md +66 -457
  2. package/README.md +2107 -23
  3. package/configuration_sample/cjs/authentication.js +103 -0
  4. package/configuration_sample/cjs/config.js +76 -0
  5. package/configuration_sample/cjs/database.js +35 -0
  6. package/configuration_sample/cjs/view.js +36 -0
  7. package/configuration_sample/esm/authentication.js +103 -0
  8. package/configuration_sample/esm/config.js +76 -0
  9. package/configuration_sample/esm/database.js +35 -0
  10. package/configuration_sample/esm/view.js +36 -0
  11. package/dist/build.cjs +151 -0
  12. package/dist/build.mjs +151 -0
  13. package/package.json +27 -29
  14. package/screencaps/belongs-to-many.png +0 -0
  15. package/screencaps/belongs-to.png +0 -0
  16. package/screencaps/demonstration.webp +0 -0
  17. package/screencaps/has-many.png +0 -0
  18. package/screencaps/has-one.png +0 -0
  19. package/types/database/Database.d.ts +3 -171
  20. package/types/database/Model.d.ts +9 -6
  21. package/types/database/loadModels.d.ts +3 -1
  22. package/types/handlebars_helpers/comparison.d.ts +58 -188
  23. package/types/handlebars_helpers/date.d.ts +1 -1
  24. package/types/handlebars_helpers/html.d.ts +1 -1
  25. package/types/handlebars_helpers/index.d.ts +1 -0
  26. package/types/handlebars_helpers/layouts.d.ts +21 -0
  27. package/types/handlebars_helpers/math.d.ts +7 -14
  28. package/types/handlebars_helpers/number.d.ts +1 -1
  29. package/types/handlebars_helpers/object.d.ts +4 -4
  30. package/types/handlebars_helpers/string.d.ts +4 -9
  31. package/types/index.d.ts +0 -1
  32. package/types/interfaces/AuthenticationConfig.d.ts +0 -5
  33. package/types/interfaces/BasicConfig.d.ts +1 -5
  34. package/types/interfaces/ViewConfig.d.ts +0 -2
  35. package/types/middlewares/Authentication.d.ts +3 -1
  36. package/types/middlewares/CORS.d.ts +3 -1
  37. package/types/middlewares/Environment.d.ts +3 -3
  38. package/types/middlewares/ErrorHandler.d.ts +3 -1
  39. package/types/middlewares/Http.d.ts +3 -1
  40. package/types/middlewares/Local.d.ts +3 -1
  41. package/types/middlewares/View.d.ts +6 -2
  42. package/types/mount.d.ts +4 -2
  43. package/types/routing/Router.d.ts +3 -1
  44. package/types/services/Authentication.d.ts +4 -3
  45. package/types/types/global.d.ts +17 -0
  46. package/types/utils/loadAuthenticationConfig.d.ts +2 -2
  47. package/types/utils/loadBasicConfig.d.ts +2 -2
  48. package/types/utils/loadDatabaseConfig.d.ts +2 -2
  49. package/types/utils/loadViewConfig.d.ts +2 -2
  50. package/INSTALL-Redis.md +0 -77
  51. package/QUICK_START.md +0 -149
  52. package/dist/build.common.js +0 -378
  53. package/dist/build.esm.js +0 -378
  54. package/screencaps/login.jpg +0 -0
  55. package/screencaps/personal.jpg +0 -0
  56. package/screencaps/user-editing.jpg +0 -0
  57. package/screencaps/users.jpg +0 -0
  58. package/types/exceptions/FaceCollectionCreateFailed.d.ts +0 -25
  59. package/types/exceptions/FaceCollectionDeleteFailed.d.ts +0 -25
  60. package/types/exceptions/FaceIndexFailed.d.ts +0 -20
  61. package/types/exceptions/FaceMissingInPhoto.d.ts +0 -11
  62. package/types/exceptions/FacesMultipleInPhoto.d.ts +0 -11
  63. package/types/exceptions/index.d.ts +0 -5
package/CHANGELOG.md CHANGED
@@ -1,13 +1,66 @@
1
1
  # Changelog
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ ## [2.0.3] - 2024/9/3
5
+ ### Changed
6
+ - Add `"type": "module"` to the `package.json` of the esm app generated by `express-sweet-generator`. It is fully esm compliant.
7
+ - `require` was changed to dynamic import.
8
+ - Template engine changed from `express-hbs` to `express-handlebars`.
9
+ However, the `block` and `contentFor` helpers are still available.
10
+ - `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.
11
+ - Return type of `mount()` changed from `void` to `Promise<void>`.
12
+ - Return type of `middlewares/CORS.mount()` changed from `void` to `Promise<void>`.
13
+ - Return type of `middlewares/Environment.mount()` changed from `void` to `Promise<void>`.
14
+ - Return type of `middlewares/ErrorHandler.mount()` changed from `void` to `Promise<void>`.
15
+ - Return type of `middlewares/Http.mount()` changed from `void` to `Promise<void>`.
16
+ - Return type of `middlewares/Local.mount()` changed from `void` to `Promise<void>`.
17
+ - Return type of `middlewares/Router.mount()` changed from `void` to `Promise<void>`.
18
+ - Return type of `middlewares/View.mount()` changed from `void` to `Promise<void>`.
19
+ - Return type of `middlewares/View.mountBeforeRender()` changed from `void` to `Promise<void>`.
20
+ - Return type of `middlewares/Authentication.mount()` changed from `void` to `Promise<void>`.
21
+ - Return type of `utils/loadAuthenticationConfig()` changed from `AuthenticationConfig` to `Promise<AuthenticationConfig>`.
22
+ - Return type of `utils/loadBasicConfig()` changed from `BasicConfig` to `Promise<BasicConfig>`.
23
+ - Return type of `utils/loadDatabaseConfig()` changed from `sequelize.Options` to `Promise<sequelize.Options>`.
24
+ - Return type of `utils/loadViewConfig()` changed from `ViewConfig` to `Promise<ViewConfig>`.
25
+ - Return type of `services/Authentication.successRedirect()` changed from `void` to `Promise<void>`.
26
+ - Return type of `services/Authentication.failureRedirect()` changed from `void` to `Promise<void>`.
27
+ - Return type of `database/Model.initialize()` changed from `typeof Model` to `Promise<typeof Model>`.
28
+ - Return type of `database/loadModels()` changed from `void` to `Promise<void>`.
29
+ - DB connection check method has been changed.
30
+ - After:
31
+ ```js
32
+ const expressExtension = require('express-sweet');
33
+
34
+ // Create Database instance.
35
+ const config = await expressExtension.utils.loadDatabaseConfig();
36
+ const database = new expressExtension.database.Database(config.database, config.username, config.password, config);
37
+
38
+ // Check database connection.
39
+ await database.isConnect();
40
+ ```
41
+ - Before:
42
+ ```js
43
+ const expressExtension = require('express-sweet');
44
+
45
+ // Check database connection.
46
+ await expressExtension.database.Database.isConnect();
47
+ ```
48
+ - Update passport from 0.4.1 to 0.7.0
49
+
50
+ ## [2.0.2] - 2024/9/1
51
+ ### Changed
52
+ - Update express from 4.18.3 to 4.19.2.
53
+ - Update rollup from 2.79.1 to 4.21.2.
54
+ - Rename build files (build.common.js => build.cjs, build.esm.js => build.mjs).
55
+ - The express package was excluded from the build file. Instead, users should install express on their own.
56
+
4
57
  ## [2.0.1] - 2024/4/5
5
58
  ### Changed
6
59
  - Removed [nodejs-shared](https://www.npmjs.com/package/nodejs-shared) package dependency.
7
60
 
8
61
  ## [2.0.0] - 2024/3/24
9
62
  ### Changed
10
- - Express Sweet version 2 no longer depends on the AWS SDK.
63
+ - EXPRESS SWEET version 2 no longer depends on the AWS SDK.
11
64
  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.
12
65
 
13
66
  ## [1.1.1] - 2024/3/23
@@ -19,53 +72,22 @@ All notable changes to this project will be documented in this file.
19
72
 
20
73
  ## [1.1.0] - 2024/3/6
21
74
  ### Changed
22
- - Updated Express Sweet's dependency packages.
75
+ - Updated EXPRESS SWEET's dependency packages.
23
76
  - [express](https://www.npmjs.com/package/express) from v4.18.2 to v4.18.3
24
77
  - [multer](https://www.npmjs.com/package/multer) from v1.4.4 to v1.4.5-lts.1
25
78
  - [express-session](https://www.npmjs.com/package/express-session) from v1.17.3 to v1.18.0
26
79
  - [sequelize](https://www.npmjs.com/package/sequelize) from v6.32.0 to v6.37.1
27
80
  - [mariadb](https://www.npmjs.com/package/mariadb) from v2.4.0 to v3.2.3
28
81
  - [moment](https://www.npmjs.com/package/moment) from v2.29.4 to v2.30.1
29
- - Update [metronic-extension](https://www.npmjs.com/package/metronic-extension) of the demo from v1.0.1 to v3.0.9.
30
-
31
- ### Added
32
- - Demo (./demo) Docker environment added. See [here](demo/README.md) for details.
33
82
 
34
83
  ## [1.0.44] - 2023/12/30
35
84
  ### Changed
36
85
  - The `Secure` and `HttpOnly` attributes of the session cookie can now be set from the authentication configuration file (`config/authentication.js`).
37
86
 
38
- config/authentication.js:
39
- ```js
40
- /**
41
- * Specifies the boolean value for the Secure Set-Cookie attribute.
42
- * The default is true, which sets the Secure attribute on the cookie.
43
- * @type {boolean|undefined}
44
- */
45
- cookie_secure: true,
46
-
47
- /**
48
- * Specifies the boolean value for the HttpOnly Set-Cookie attribute.
49
- * Defaults to true, which sets the HttpOnly attribute on the cookie.
50
- * @type {boolean|undefined}
51
- */
52
- cookie_httpOnly: true,
53
- ```
54
-
55
87
  ## [1.0.43] - 2023/12/30
56
88
  ### Changed
57
89
  - The cookie name for storing session IDs can now be set in the `cookie_name` field of the authentication configuration file (`config/authentication.js`).
58
90
 
59
- config/authentication.js:
60
- ```js
61
- /**
62
- * The name of the session ID cookie to set in the response (and read from in the request).
63
- * The default value is 'connect.sid'.
64
- * @type {string|undefined}
65
- */
66
- cookie_name: 'connect.sid'
67
- ```
68
-
69
91
  ## [1.0.42] - 2023/8/31
70
92
  ### Changed
71
93
  - Update TypeScript version from 4.8.4 to 5.2.2.
@@ -79,56 +101,6 @@ All notable changes to this project will be documented in this file.
79
101
  ## [1.0.41] - 2023/8/4
80
102
  ### Changed
81
103
  - Added an option to the method that searches for faces in the collection to throw an exception if a face is not found or if multiple faces are found.
82
- <table>
83
- <thead>
84
- <tr>
85
- <th>Option</th>
86
- <th>Type</th>
87
- <th>Description</th>
88
- </tr>
89
- </thead>
90
- <tbody>
91
- <tr>
92
- <td>throwNotFoundFaceException</td>
93
- <td>boolean</td>
94
- <td>If true, throws a <code>FaceMissingInPhoto</code> exception when a face is not found in the image; if false, returns null. Default is false.</td>
95
- </tr>
96
- <tr>
97
- <td>throwTooManyFaceException</td>
98
- <td>boolean</td>
99
- <td>If true, throws a <code>FacesMultipleInPhoto</code> exception when more than one face is found in the image. Default is false.</td>
100
- </tr>
101
- </tbody>
102
- </table>
103
-
104
- Example:
105
- ```js
106
- const {services: {AWSRekognitionClient}, exceptions: {FaceMissingInPhoto, FacesMultipleInPhoto}} = require('express-sweet');
107
-
108
- // Rekognition Client.
109
- const client = new AWSRekognitionClient({
110
- accessKeyId: 'your AWS access key ID',
111
- secretAccessKey: 'your AWS secret access key',
112
- region: 'the region to send service requests to',
113
- });
114
-
115
- // Find a face in the collection.
116
- const collectionId = 'MyCollection';
117
-
118
- try {
119
- await client.searchFaces(collectionId, 'face.jpg', {
120
- throwNotFoundFaceException: true,
121
- throwTooManyFaceException: true,
122
- });
123
- } catch (err) {
124
- if (err instanceof FaceMissingInPhoto)
125
- console.log('No face was found');
126
- else if (err instanceof FacesMultipleInPhoto)
127
- console.log('Multiple faces were found');
128
- else
129
- console.log('Other errors');
130
- }
131
- ```
132
104
 
133
105
  ## [1.0.40] - 2023/8/4
134
106
  ### Changed
@@ -215,76 +187,16 @@ All notable changes to this project will be documented in this file.
215
187
 
216
188
  ### Added
217
189
  - New Math-related view helpers have been added.
218
- |Helper|Description|
219
- |--|--|
220
- |add|Calculates the sum of two numbers.|
221
- |sub|Calculates the difference of the given values.|
222
- |multiply|Calculate the multiplication of the given values.|
223
- |divide|Compute the division of the given values.|
224
- |ceil|Round up the value.|
225
- |floor|Rounds down a number.|
226
- |abs|Returns an absolute value.|
227
190
 
228
191
  ## [1.0.36] - 2023/7/12
229
192
  ### Changed
230
193
  - Moved the Ajax determination option (is_ajax) in the authentication configuration (config/authentication.js) to the basic configuration (config/config.js).
231
-
232
- config/config.js:
233
- ```js
234
- is_ajax: req => {
235
- // If the request URL begins with /api, it is assumed to be Ajax.
236
- return /^\/api/.test(req.path);
237
- // return !!req.xhr;
238
- }
239
- ```
240
- - 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.
241
-
242
- config/config.js:
243
- ```js
244
- hook_handle_error: (err, req, res, next) => {
245
- if (err.status === 404)
246
- // If the URL cannot be found, a 404 error screen (views/error-404.hbs) is displayed.
247
- res.render('error-404');
248
- else
249
- // For other errors, unknown error screen (views/error-unknown.hbs) is displayed.
250
- res.render('error-unknown');
251
- }
252
- ```
194
+ - 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.
253
195
 
254
196
  ## [1.0.35] - 2023/7/11
255
197
  ### Changed
256
198
  - 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.
257
-
258
- config/authentication.js:
259
- ```js
260
- // Set the URL to redirect to in case of login failure as a string.
261
- failure_redirect: '/login',
262
-
263
- // Dynamically set the url to redirect to on login failure.
264
- failure_redirect: (req, res) => {
265
- // If the role stored in the cookie is admin, redirect to the admin login screen.
266
- return req.cookies.role === 'admin' ? '/adminlogin' : 'login';
267
- },
268
- ```
269
- - The arguments of the failureRedirect method of the authentication service class (services/Authentication) have changed.
270
- The argument to the Authentication.failureRedirect method used to be just express.Response, but now it requires express.Request and express.Response.
271
-
272
- Example of login routes:
273
- ```js
274
- import {Router} from 'express';
275
- import * as sweet from 'express-sweet';
276
- const router = Router();
277
- const Authentication = sweet.services.Authentication;
278
-
279
- router.post('/login', async (req, res, next) => {
280
- const isAuth = await Authentication.authenticate(req, res, next);
281
- if (isAuth)
282
- Authentication.successRedirect(res);
283
- else
284
- Authentication.failureRedirect(req, res);
285
- });
286
- export default router;
287
- ```
199
+ - 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.
288
200
 
289
201
  ## [1.0.34] - 2023/7/1
290
202
  ### Changed
@@ -293,27 +205,6 @@ All notable changes to this project will be documented in this file.
293
205
  ## [1.0.33] - 2023/7/1
294
206
  ### Added
295
207
  - Added regular expression comparison view helper.
296
- ```html
297
- {{!-- results in: true --}}
298
- {{regexMatch 'foobar' 'foo'}}
299
-
300
- {{!-- results in: false --}}
301
- {{regexMatch 'bar' 'foo'}}
302
-
303
- {{!-- results in: false --}}
304
- {{regexMatch 'foobar' '^foo$'}}
305
-
306
- {{!-- results in: true --}}
307
- {{regexMatch 'Visit Here' 'here' 'i'}}
308
-
309
- {{!-- results in: false --}}
310
- {{regexMatch 'Visit Here' 'here'}}
311
-
312
- {{!-- results in: Match --}}
313
- {{#if (regexMatch 'foobar' 'foo')}}
314
- Match
315
- {{/if}}
316
- ```
317
208
 
318
209
  ## [1.0.32] - 2023/7/1
319
210
  ### Fixed
@@ -333,14 +224,6 @@ All notable changes to this project will be documented in this file.
333
224
 
334
225
  ### Added
335
226
  - Added view helper to convert numeric values to strings with language-sensitive representations.
336
- ```html
337
- {{!-- results in: 123,456.789 --}}
338
- {{number2locale 123456.789}}
339
-
340
- {{!-- German uses comma as decimal separator and period for thousands. --}}
341
- {{!-- results in: 123.456,789 --}}
342
- {{number2locale 123456.789 'de-DE'}}
343
- ```
344
227
 
345
228
  ## [1.0.30] - 2023/6/26
346
229
  ### Changed
@@ -352,81 +235,15 @@ All notable changes to this project will be documented in this file.
352
235
 
353
236
  ### Added
354
237
  - Added AWS SES email sending client class.
355
- ```js
356
- const sweet = require('express-sweet');
357
-
358
- // SES Client.
359
- const client = new sweet.services.AWSSesClient({
360
- apiVersion: 'API Version ("YYYYY-MM-DD" or "latest")',
361
- region: 'the region to send service requests to',
362
- accessKeyId: 'your AWS access key ID',
363
- secretAccessKey: 'your AWS secret access key',
364
- });
365
-
366
- // Send an email from "test<from@example.com>" to "to@example.com".
367
- await client
368
- .from('from@example.com', 'Sender Name')
369
- .to('to@example.com')
370
- .subject('Test email')
371
- .body('Hi, this is a test email')
372
- .send();
373
-
374
- // Use variables in the body of the e-mail.
375
- // The body can use the handlebars and handlebars-extd syntax.
376
- await client
377
- .from('from@example.com', 'Sender Name')
378
- .to('to@example.com')
379
- .subject('Test email')
380
- .body('Hello {{name}}', {name: 'Mason'})
381
- .send();
382
- ```
383
238
 
384
239
  ## [1.0.28] - 2023/6/16
385
240
  ### Changed
386
241
  - Updated AWS SDK version from 2 to 3.
387
- Unit test results:
388
- ```sh
389
- npm run test
390
-
391
- > express-sweet@1.0.25 test
392
- > jest
393
-
394
- PASS __tests__/AWSRekognitionClient.test.js (8.773 s)
395
- ? Should detect one person from the image (448 ms)
396
- ? Should be able to get facial details (532 ms)
397
- ? Should detect three persons from the image (589 ms)
398
- ? The two faces should be the same person (131 ms)
399
- ? The two faces should be different people (213 ms)
400
- ? Should be able to create collections (98 ms)
401
- ? Should index faces in the collection (242 ms)
402
- ? Should return the details of the indexed face (346 ms)
403
- ? Should be able to find faces from the collection (153 ms)
404
- ? Should be able to find faces from the collection (132 ms)
405
- ? Should list indexed faces (27 ms)
406
- ? Should delete the face from the collection (53 ms)
407
- ? Collection should be deleted (62 ms)
408
-
409
- Test Suites: 1 passed, 1 total
410
- Tests: 13 passed, 13 total
411
- Snapshots: 0 total
412
- Time: 9.323 s
413
- Ran all test suites.
414
- ```
415
242
 
416
243
  ## [1.0.27] - 2023/6/12
417
244
  ### Changed
418
245
  - Request object has been added to the arguments of the beforeRender function in the view configuration (config/view.js).
419
246
 
420
- express-sweet v1.0.27 or later (current):
421
- ```js
422
- beforeRender: (req, res) => {}
423
- ```
424
-
425
- express-sweet v1.0.26 or earlier:
426
- ```js
427
- beforeRender: res => {}
428
- ```
429
-
430
247
  ## [1.0.26] - 2023/6/11
431
248
  ### Changed
432
249
  - Update Sequelize from v5 to v6.
@@ -435,189 +252,41 @@ All notable changes to this project will be documented in this file.
435
252
  ```
436
253
  EXPRESS_DEBUG=true
437
254
  ```
438
- - A demo application was added [here](./demo).
439
255
 
440
256
  ## [1.0.25] - 2022/11/24
441
257
  ### Added
442
258
  - Added formatBytes view helper to convert bytes to appropriate units.
443
- ```html
444
- {{!-- results in: 1 KB --}}
445
- {{formatBytes 1024}}
446
-
447
- {{!-- results in: 1.21 KB --}}
448
- {{formatBytes 1234 2}}
449
-
450
- {{!-- results in: 1.205 KB --}}
451
- {{formatBytes 1234 3}}
452
-
453
- {{!-- results in: 0 Bytes --}}
454
- {{formatBytes 0}}
455
- ```
456
259
 
457
260
  ## [1.0.24] - 2022/10/24
458
261
  ### Added
459
- - Added is_ajax option to user authentication.
460
-
461
- config/authentication.js:
462
- ```js
463
- is_ajax: req => {
464
- // If the request URL begins with /api, it is assumed to be Ajax.
465
- return /^\/api/.test(req.path);
466
- // return !!req.xhr;
467
- }
468
- ```
262
+ - Added is_ajax option to user authentication (config/authentication.js).
469
263
 
470
264
  ## [1.0.23] - 2022/10/20
471
265
  ### Added
472
266
  - A request body object has been added to the parameters of the callback function for user authentication.
473
267
 
474
- config/authentication.js:
475
- ```js
476
- authenticate_user: async (username, password, req) => {
477
- const UserModel = require('../models/UserModel');
478
- return UserModel.findOne({
479
- where: {
480
- email: username,
481
- password
482
- },
483
- raw: true
484
- });
485
- }
486
- ```
487
-
488
268
  ## [1.0.22] - 2022/7/27
489
269
  ### Added
490
- - You can now set hook functions that are called before the view is rendered.
491
- Hook functions can be used, for example, to set local variables that can be used in the view.
492
-
493
- To use, add the beforeRender hook function to "config/view.js" as follows.
494
- ```js
495
- beforeRender: res => {
496
- res.locals.extra = 'Extra';
497
- }
498
- ```
270
+ - You can now set hook functions that are called before the view is rendered. Hook functions can be used, for example, to set local variables that can be used in the view.
499
271
 
500
272
  ## [1.0.21] - 2022/526
501
273
  ### Added
502
274
  - Added an option to the face indexing method to retrieve details (gender, emotion, age group) of indexed faces.
503
- ```js
504
- const sweet = require('express-sweet');
505
-
506
- // Rekognition Client.
507
- const client = new sweet.services.AWSRekognitionClient({
508
- accessKeyId: 'your AWS access key ID',
509
- secretAccessKey: 'your AWS secret access key',
510
- region: 'the region to send service requests to'
511
- });
512
-
513
- // Collection ID for testing.
514
- const collectionId = 'MyCollection';
515
-
516
- // Create a face and get the ID of the created face.
517
- // results in: e65d66cb-e7bc-4bbf-966c-b1b49ddf29f8
518
- const faceId = await client.indexFace(collectionId, 'face4.jpg');
519
- console.log(faceId);
520
-
521
- // Create a face and get the details of the created face.
522
- // results in: {
523
- // faceId: '7f2dd321-f047-44ff-8856-864637e1d286',
524
- // ageRange: { high: 29, low: 21 },
525
- // gender: 'female',
526
- // emotions: {
527
- // angry: 77.1907958984375,
528
- // surprised: 9.944050788879395,
529
- // fear: 7.514361381530762,
530
- // confused: 4.780297756195068,
531
- // sad: 2.91914963722229,
532
- // happy: 2.5718722343444824,
533
- // disgusted: 1.933768391609192,
534
- // calm: 1.5354809761047363
535
- // }
536
- // }
537
- const faceDetails = await client.indexFace(collectionId, 'face5.jpg', {returnDetails: true});
538
- console.log(faceDetails);
539
- ```
540
275
 
541
276
  ## [1.0.20] - 2022/5/25
542
277
  ### Added
543
278
  - Added an option to get details (emotion, gender, age group) to the face detection method.
544
- ```js
545
- const sweet = require('express-sweet');
546
-
547
- // Rekognition Client.
548
- const client = new sweet.services.AWSRekognitionClient({
549
- accessKeyId: 'your AWS access key ID',
550
- secretAccessKey: 'your AWS secret access key',
551
- region: 'the region to send service requests to'
552
- });
553
-
554
- (async () => {
555
- // Detects bounding boxes on faces.
556
- // results in: [
557
- // {
558
- // width: 0.3099822998046875,
559
- // height: 0.661512017250061,
560
- // left: 0.5449195504188538,
561
- // top: 0.11531734466552734
562
- // }
563
- // ]
564
- let res = await client.detectFaces('face.jpg');
565
- console.log(res);
566
-
567
- // Detect facial details.
568
- // results in: [
569
- // {
570
- // boundingBox: {
571
- // width: 0.3099822998046875,
572
- // height: 0.661512017250061,
573
- // left: 0.5449195504188538,
574
- // top: 0.11531734466552734
575
- // },
576
- // ageRange: { high: 14, low: 6 },
577
- // gender: 'female',
578
- // emotions: {
579
- // happy: 99.78905487060547,
580
- // surprised: 6.306276321411133,
581
- // fear: 5.880091190338135,
582
- // sad: 2.152125835418701,
583
- // confused: 0.023256277665495872,
584
- // angry: 0.018351631239056587,
585
- // calm: 0.015775982290506363,
586
- // disgusted: 0.013914424926042557
587
- // }
588
- // }
589
- // ]
590
- const minConfidence = 90;
591
- const withDetails = true;
592
- res = await client.detectFaces('face.jpg', minConfidence, withDetails);
593
- console.log(res);
594
- })();
595
- ```
596
279
 
597
280
  ## [1.0.19] - 2022/5/20
598
281
  ### Added
599
282
  - Add date format helper to view.
600
- ```html
601
- {{!-- results in: 2021/10/24 --}}
602
- {{formatDate 'YYYY/MM/DD' "2021-10-24T02:13:06.610Z"}}
603
-
604
- {{!-- results in: 2021/10/24 --}}
605
- {{formatDate 'YYYY/MM/DD' "2021-10-24T02:13:06.610Z" 'jp'}}
606
-
607
- {{!-- results in: 2021/10/24 --}}
608
- {{formatDate 'YYYY/MM/DD' "2021-10-24T02:13:06.610Z" 'es'}}
609
- ```
610
283
 
611
284
  ## [1.0.18] - 2022/5/18
612
285
  ### Added
613
- - User authentication sessions can now be stored in redis.
614
- To use redis for session storage, simply add the following option to config/authentication.js.
615
- Please give it a try.
616
-
286
+ - User authentication sessions can now be stored in redis. To use redis for session storage, simply add the following option to config/authentication.js. Please give it a try.
617
287
  config/authentication.js:
618
288
  ```json
619
- session_store: 'memory',
620
- // session_store: 'redis',
289
+ session_store: 'redis',
621
290
  redis_host: 'redis://localhost:6379'
622
291
  ```
623
292
 
@@ -636,42 +305,6 @@ All notable changes to this project will be documented in this file.
636
305
  ## [1.0.14] - 2022/1/17
637
306
  ### Changed
638
307
  - empty view helper can now check any type. Previously I could only check arrays.
639
- ```html
640
- {{!-- results in: false --}}
641
- {{empty [5, 6]}}
642
-
643
- {{#if (empty 'foo')}}
644
- Hello
645
- {{/if}}
646
-
647
- {{!-- results in: false --}}
648
- {{empty 'Hello'}}
649
-
650
- {{!-- results in: true --}}
651
- {{empty ''}}
652
-
653
- {{!-- results in: true --}}
654
- {{empty value}}
655
- ```
656
-
657
- - Added notEmpty view helper.
658
- ```html
659
- {{!-- results in: true --}}
660
- {{notEmpty [5, 6]}}
661
-
662
- {{#if (notEmpty 'foo')}}
663
- Hello
664
- {{/if}}
665
-
666
- {{!-- results in: true --}}
667
- {{notEmpty 'Hello'}}
668
-
669
- {{!-- results in: false --}}
670
- {{notEmpty ''}}
671
-
672
- {{!-- results in: false --}}
673
- {{notEmpty ' '}}
674
- ```
675
308
 
676
309
  ## [1.0.13] - 2021/12/13
677
310
  ### Added
@@ -688,10 +321,8 @@ All notable changes to this project will be documented in this file.
688
321
  await book.save({transaction});
689
322
  await transaction.commit();
690
323
 
691
- // Check the update result.
692
- // results in: New title of book: When Im Gone
324
+ // Load updated data.
693
325
  await book.reload();
694
- console.log(`New title of book: ${book.title}`);
695
326
  } catch (err) {
696
327
  if (transaction)
697
328
  await transaction.rollback();
@@ -700,9 +331,7 @@ All notable changes to this project will be documented in this file.
700
331
 
701
332
  ## [1.0.12] - 2021/11/16
702
333
  ### Added
703
- - Added a method to the model that can execute raw SQL.
704
- As there are often use cases in which it is just easier to execute raw / already prepared SQL queries, you can use the Model.query method.
705
-
334
+ - Added a method to the model that can execute raw SQL. As there are often use cases in which it is just easier to execute raw / already prepared SQL queries, you can use the Model.query method.
706
335
  ```js
707
336
  // By default the function will return two arguments - a results array, and an object containing metadata (such as amount of affected rows, etc).
708
337
  // Note that since this is a raw query, the metadata are dialect specific.
@@ -721,27 +350,6 @@ All notable changes to this project will be documented in this file.
721
350
  ### Changed
722
351
  - Added face similarity found to face search results in collection.
723
352
 
724
- ```js
725
- import * as sweet from 'express-sweet';
726
-
727
- // Find a face from the collection.
728
- // results in: Face search results: [
729
- // {
730
- // faceId: '385e1b00-4ede-4219-a7b0-0b9cbe4953e5',
731
- // boundingBox: {
732
- // width: 0.3204210102558136,
733
- // height: 1.0046900510787964,
734
- // left: 0.39145898818969727,
735
- // top: 0.07936319708824158
736
- // },
737
- // similarity: 99.98941802978516
738
- // }
739
- // ]
740
- const collectionId = 'MyCollection';
741
- const res = await client.searchFaces(collectionId, 'face.jpg');
742
- console.log('Face search results:', res);
743
- ```
744
-
745
353
  ## [1.0.9] - 2021/10/13
746
354
  ### Changed
747
355
  - Updated dependent package'sharp'from 0.25.4 to 0.29.1.
@@ -771,7 +379,6 @@ All notable changes to this project will be documented in this file.
771
379
  ## [1.0.3] - 2021/6/13
772
380
  ### Changed
773
381
  - Change the current URL path of a local variable.app.locals.currentPath is a USVString containing an initial '/' followed by the path of the URL not including the query string or fragment.
774
-
775
382
  ```js
776
383
  // For example, when the current URL is "https://example.com/docs/api?q=value", "/docs/api" is set for "app.locals.currentPath".
777
384
  console.log(app.locals.currentPath);
@@ -836,4 +443,6 @@ All notable changes to this project will be documented in this file.
836
443
  [1.1.0]: https://github.com/takuya-motoshima/express-sweet/compare/v1.0.45...v1.1.0
837
444
  [1.1.1]: https://github.com/takuya-motoshima/express-sweet/compare/v1.1.0...v1.1.1
838
445
  [2.0.0]: https://github.com/takuya-motoshima/express-sweet/compare/v1.1.1...v2.0.0
839
- [2.0.1]: https://github.com/takuya-motoshima/express-sweet/compare/v2.0.0...v2.0.1
446
+ [2.0.1]: https://github.com/takuya-motoshima/express-sweet/compare/v2.0.0...v2.0.1
447
+ [2.0.2]: https://github.com/takuya-motoshima/express-sweet/compare/v2.0.1...v2.0.2
448
+ [2.0.3]: https://github.com/takuya-motoshima/express-sweet/compare/v2.0.2...v2.0.3