express-sweet 1.0.15 → 1.0.16
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 +186 -0
- package/dist/build.common.js +53 -0
- package/dist/build.esm.js +53 -0
- package/package.json +1 -1
- package/types/database/Database.d.ts +162 -0
- package/types/database/Model.d.ts +221 -0
- package/types/database/index.d.ts +4 -0
- package/types/database/loadModels.d.ts +6 -0
- package/types/exceptions/ApiError.d.ts +29 -0
- package/types/exceptions/index.d.ts +2 -0
- package/types/handlebars_helpers/comparison.d.ts +302 -0
- package/types/handlebars_helpers/html.d.ts +11 -0
- package/types/handlebars_helpers/index.d.ts +5 -0
- package/types/handlebars_helpers/object.d.ts +21 -0
- package/types/handlebars_helpers/string.d.ts +12 -0
- package/types/index.d.ts +9 -0
- package/types/interfaces/AuthenticationOptions.d.ts +84 -0
- package/types/interfaces/BoundingBox.d.ts +25 -0
- package/types/interfaces/Config.d.ts +66 -0
- package/types/interfaces/DatabaseOptions.d.ts +7 -0
- package/types/interfaces/FaceMatch.d.ts +31 -0
- package/types/interfaces/RekognitionOptions.d.ts +26 -0
- package/types/interfaces/ViewOptions.d.ts +30 -0
- package/types/interfaces/index.d.ts +8 -0
- package/types/middlewares/Authentication.d.ts +16 -0
- package/types/middlewares/CORS.d.ts +16 -0
- package/types/middlewares/Environment.d.ts +17 -0
- package/types/middlewares/ErrorHandling.d.ts +16 -0
- package/types/middlewares/Global.d.ts +13 -0
- package/types/middlewares/Http.d.ts +16 -0
- package/types/middlewares/Local.d.ts +20 -0
- package/types/middlewares/View.d.ts +16 -0
- package/types/middlewares/index.d.ts +8 -0
- package/types/mount.d.ts +7 -0
- package/types/package.d.ts +91 -0
- package/types/routing/Router.d.ts +19 -0
- package/types/routing/index.d.ts +2 -0
- package/types/services/AWSRekognitionClient.d.ts +359 -0
- package/types/services/Authentication.d.ts +39 -0
- package/types/services/RedisClient.d.ts +80 -0
- package/types/services/index.d.ts +3 -0
- package/types/utils/Types.d.ts +16 -0
- package/types/utils/index.d.ts +2 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Set environment variables.
|
|
3
|
+
*
|
|
4
|
+
* Read the environment variable file in options.path and set it in "process.env".
|
|
5
|
+
*/
|
|
6
|
+
export default class {
|
|
7
|
+
/**
|
|
8
|
+
* Mount on application.
|
|
9
|
+
*/
|
|
10
|
+
static mount(): undefined;
|
|
11
|
+
/**
|
|
12
|
+
* Returns the option.
|
|
13
|
+
*
|
|
14
|
+
* @return {Config} option.
|
|
15
|
+
*/
|
|
16
|
+
private static loadOptions;
|
|
17
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import express from 'express';
|
|
2
|
+
/**
|
|
3
|
+
* Error handling.
|
|
4
|
+
*/
|
|
5
|
+
export default class {
|
|
6
|
+
/**
|
|
7
|
+
* Mount on application.
|
|
8
|
+
*/
|
|
9
|
+
static mount(app: express.Express): void;
|
|
10
|
+
/**
|
|
11
|
+
* Returns the option.
|
|
12
|
+
*
|
|
13
|
+
* @return {Config} option.
|
|
14
|
+
*/
|
|
15
|
+
private static loadOptions;
|
|
16
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Set global variables.
|
|
3
|
+
* It can be accessed like "global.xxx" in all router and model classes.
|
|
4
|
+
*
|
|
5
|
+
* Below is a description of the variables.
|
|
6
|
+
* APP_DIR: The directory where app.js is located.
|
|
7
|
+
*/
|
|
8
|
+
export default class {
|
|
9
|
+
/**
|
|
10
|
+
* Mount on application.
|
|
11
|
+
*/
|
|
12
|
+
static mount(): void;
|
|
13
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import express from 'express';
|
|
2
|
+
/**
|
|
3
|
+
* Defines all the requisites in HTTP.
|
|
4
|
+
*/
|
|
5
|
+
export default class {
|
|
6
|
+
/**
|
|
7
|
+
* Mount on application.
|
|
8
|
+
*/
|
|
9
|
+
static mount(app: express.Express): void;
|
|
10
|
+
/**
|
|
11
|
+
* Returns the option.
|
|
12
|
+
*
|
|
13
|
+
* @return {Config} option.
|
|
14
|
+
*/
|
|
15
|
+
private static loadOptions;
|
|
16
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import express from 'express';
|
|
2
|
+
/**
|
|
3
|
+
* Set local variables.
|
|
4
|
+
* It can be accessed in all views as {{var}} or {{{var}}}.
|
|
5
|
+
*
|
|
6
|
+
* Below is a description of the variables.
|
|
7
|
+
* baseUrl: The base URL for this application.
|
|
8
|
+
*/
|
|
9
|
+
export default class {
|
|
10
|
+
/**
|
|
11
|
+
* Mount on application.
|
|
12
|
+
*/
|
|
13
|
+
static mount(app: express.Express): void;
|
|
14
|
+
/**
|
|
15
|
+
* Returns the option.
|
|
16
|
+
*
|
|
17
|
+
* @return {Config} option.
|
|
18
|
+
*/
|
|
19
|
+
private static loadOptions;
|
|
20
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import express from 'express';
|
|
2
|
+
/**
|
|
3
|
+
* Enable Handlebars template engine.
|
|
4
|
+
*/
|
|
5
|
+
export default class {
|
|
6
|
+
/**
|
|
7
|
+
* Mount on application.
|
|
8
|
+
*/
|
|
9
|
+
static mount(app: express.Express): void;
|
|
10
|
+
/**
|
|
11
|
+
* Returns the option.
|
|
12
|
+
*
|
|
13
|
+
* @return {ViewOptions} option.
|
|
14
|
+
*/
|
|
15
|
+
private static loadOptions;
|
|
16
|
+
}
|
|
@@ -0,0 +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 };
|
package/types/mount.d.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
export declare var name: string;
|
|
2
|
+
export declare var version: string;
|
|
3
|
+
export declare var description: string;
|
|
4
|
+
export declare var main: string;
|
|
5
|
+
export declare var module: string;
|
|
6
|
+
export declare var types: string;
|
|
7
|
+
export declare var files: string[];
|
|
8
|
+
export declare var scripts: {
|
|
9
|
+
watch: string;
|
|
10
|
+
prewatch: string;
|
|
11
|
+
build: string;
|
|
12
|
+
prebuild: string;
|
|
13
|
+
test: string;
|
|
14
|
+
start: string;
|
|
15
|
+
prestart: string;
|
|
16
|
+
};
|
|
17
|
+
export declare var _moduleAliases: {
|
|
18
|
+
"~": string;
|
|
19
|
+
};
|
|
20
|
+
export declare var repository: {
|
|
21
|
+
type: string;
|
|
22
|
+
url: string;
|
|
23
|
+
};
|
|
24
|
+
export declare var keywords: string[];
|
|
25
|
+
export declare var author: string;
|
|
26
|
+
export declare var license: string;
|
|
27
|
+
export declare var bugs: {
|
|
28
|
+
url: string;
|
|
29
|
+
email: string;
|
|
30
|
+
};
|
|
31
|
+
export declare var homepage: string;
|
|
32
|
+
export declare var dependencies: {
|
|
33
|
+
"aws-sdk": string;
|
|
34
|
+
"body-parser": string;
|
|
35
|
+
"class-transformer": string;
|
|
36
|
+
"class-validator": string;
|
|
37
|
+
"cookie-parser": string;
|
|
38
|
+
cors: string;
|
|
39
|
+
debug: string;
|
|
40
|
+
dotenv: string;
|
|
41
|
+
esm: string;
|
|
42
|
+
express: string;
|
|
43
|
+
"express-hbs": string;
|
|
44
|
+
"express-session": string;
|
|
45
|
+
"fs-extra": string;
|
|
46
|
+
glob: string;
|
|
47
|
+
hbs: string;
|
|
48
|
+
"http-errors": string;
|
|
49
|
+
ioredis: string;
|
|
50
|
+
mariadb: string;
|
|
51
|
+
"mime-types": string;
|
|
52
|
+
"module-alias": string;
|
|
53
|
+
moment: string;
|
|
54
|
+
morgan: string;
|
|
55
|
+
multer: string;
|
|
56
|
+
"nodejs-shared": string;
|
|
57
|
+
passport: string;
|
|
58
|
+
"passport-local": string;
|
|
59
|
+
"reflect-metadata": string;
|
|
60
|
+
sequelize: string;
|
|
61
|
+
uniqid: string;
|
|
62
|
+
};
|
|
63
|
+
export declare var devDependencies: {
|
|
64
|
+
"@types/aws-sdk": string;
|
|
65
|
+
"@types/cookie-parser": string;
|
|
66
|
+
"@types/debug": string;
|
|
67
|
+
"@types/express": string;
|
|
68
|
+
"@types/express-session": string;
|
|
69
|
+
"@types/http-errors": string;
|
|
70
|
+
"@types/ioredis": string;
|
|
71
|
+
"@types/jest": string;
|
|
72
|
+
"@types/multer": string;
|
|
73
|
+
"@types/node": string;
|
|
74
|
+
"@types/passport": string;
|
|
75
|
+
"@types/passport-local": string;
|
|
76
|
+
"@types/validator": string;
|
|
77
|
+
jest: string;
|
|
78
|
+
json2module: string;
|
|
79
|
+
rollup: string;
|
|
80
|
+
"rollup-plugin-commonjs": string;
|
|
81
|
+
"rollup-plugin-json": string;
|
|
82
|
+
"rollup-plugin-node-resolve": string;
|
|
83
|
+
"rollup-plugin-terser": string;
|
|
84
|
+
"rollup-plugin-typescript2": string;
|
|
85
|
+
"ts-loader": string;
|
|
86
|
+
"ts-node": string;
|
|
87
|
+
"tsc-alias": string;
|
|
88
|
+
"tsconfig-paths": string;
|
|
89
|
+
tslint: string;
|
|
90
|
+
typescript: string;
|
|
91
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import express from 'express';
|
|
2
|
+
/**
|
|
3
|
+
* Set up URL routing.
|
|
4
|
+
*
|
|
5
|
+
* Define URL routing based on the path of the file in the routes directory.
|
|
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
|
+
*/
|
|
8
|
+
export default class {
|
|
9
|
+
/**
|
|
10
|
+
* Mount on application.
|
|
11
|
+
*/
|
|
12
|
+
static mount(app: express.Express): void;
|
|
13
|
+
/**
|
|
14
|
+
* Returns the option.
|
|
15
|
+
*
|
|
16
|
+
* @return {Config} option.
|
|
17
|
+
*/
|
|
18
|
+
private static loadOptions;
|
|
19
|
+
}
|
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
import RekognitionOptions from '~/interfaces/RekognitionOptions';
|
|
2
|
+
import FaceMatch from '~/interfaces/FaceMatch';
|
|
3
|
+
import BoundingBox from '~/interfaces/BoundingBox';
|
|
4
|
+
/**
|
|
5
|
+
* AWS Rekognition Client.
|
|
6
|
+
*/
|
|
7
|
+
export default class {
|
|
8
|
+
/**
|
|
9
|
+
* Rekognition client instance.
|
|
10
|
+
* @type {AWS.Rekognition}
|
|
11
|
+
*/
|
|
12
|
+
private client;
|
|
13
|
+
/**
|
|
14
|
+
* Constructs a rekognition client object.
|
|
15
|
+
*/
|
|
16
|
+
constructor(opts: RekognitionOptions);
|
|
17
|
+
/**
|
|
18
|
+
* Detects faces within an image that is provided as input.
|
|
19
|
+
* For each face detected, the operation returns a bounding box of the face.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* const AWSRekognitionClient = require('express-sweet').services.AWSRekognitionClient;
|
|
23
|
+
* const fs = require('fs');
|
|
24
|
+
*
|
|
25
|
+
* // Instantiate Rekognition client.
|
|
26
|
+
* const client = new AWSRekognitionClient({
|
|
27
|
+
* accessKeyId: process.env.AWS_REKOGNITION_ACCESS_KEY_ID,
|
|
28
|
+
* secretAccessKey: process.env.AWS_REKOGNITION_SECRET_ACCESS_KEY,
|
|
29
|
+
* region: process.env.AWS_REKOGNITION_REGION
|
|
30
|
+
* });
|
|
31
|
+
*
|
|
32
|
+
* // Detect faces from path.
|
|
33
|
+
* // Output: [
|
|
34
|
+
* // {
|
|
35
|
+
* // width: 0.5004957914352417,
|
|
36
|
+
* // height: 0.6926820874214172,
|
|
37
|
+
* // left: 0.2928674817085266,
|
|
38
|
+
* // top: 0.09095800668001175
|
|
39
|
+
* // }
|
|
40
|
+
* // ]
|
|
41
|
+
* await client.detectFaces('img.jpg');
|
|
42
|
+
*
|
|
43
|
+
* // Detect faces from data URL.
|
|
44
|
+
* await client.detectFaces('data:image/png;base64,/9j/4...');
|
|
45
|
+
*
|
|
46
|
+
* // Detect faces from buffer.
|
|
47
|
+
* await client.detectFaces(fs.readFileSync('img.jpg'));
|
|
48
|
+
*
|
|
49
|
+
* @param {string} img Image path or Data Url or image buffer.
|
|
50
|
+
* @param {number} minConfidence The minimum confidence of the detected face.
|
|
51
|
+
* Faces with a confidence lower than this value will not be returned as a result.
|
|
52
|
+
* @return {Promise<BoundingBox[]>} Returns the bounding box of the detected face.
|
|
53
|
+
*/
|
|
54
|
+
detectFaces(img: string, minConfidence?: number): Promise<BoundingBox[]>;
|
|
55
|
+
/**
|
|
56
|
+
* Compare the similarity of two faces.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* const AWSRekognitionClient = require('express-sweet').services.AWSRekognitionClient;
|
|
60
|
+
* const fs = require('fs');
|
|
61
|
+
*
|
|
62
|
+
* // Instantiate Rekognition client.
|
|
63
|
+
* const client = new AWSRekognitionClient({
|
|
64
|
+
* accessKeyId: process.env.AWS_REKOGNITION_ACCESS_KEY_ID,
|
|
65
|
+
* secretAccessKey: process.env.AWS_REKOGNITION_SECRET_ACCESS_KEY,
|
|
66
|
+
* region: process.env.AWS_REKOGNITION_REGION
|
|
67
|
+
* });
|
|
68
|
+
*
|
|
69
|
+
* // Compare faces from path.
|
|
70
|
+
* await client.compareFaces('img1.jpg', 'img2.jpg');
|
|
71
|
+
*
|
|
72
|
+
* // Compare faces from data URL.
|
|
73
|
+
* await client.compareFaces('data:image/png;base64,/9j/4...', 'data:image/png;base64,/9j/4...');
|
|
74
|
+
*
|
|
75
|
+
* // Compare faces from buffer.
|
|
76
|
+
* await client.compareFaces(fs.readFileSync('img1.jpg'), fs.readFileSync('img1.jpg'));
|
|
77
|
+
*
|
|
78
|
+
* @param {string} img1 Image path or Data Url or image buffer.
|
|
79
|
+
* @param {string} img2 Image path or Data Url or image buffer.
|
|
80
|
+
* @return {Promise<number>} Level of confidence that the faces match.
|
|
81
|
+
*/
|
|
82
|
+
compareFaces(img1: string, img2: string): Promise<number>;
|
|
83
|
+
/**
|
|
84
|
+
* Add faces to the collection using the IndexFaces operation.
|
|
85
|
+
* For example, you might create collections, one for each of your application users.
|
|
86
|
+
* A user can then index faces using the IndexFaces operation and persist results in a specific collection.
|
|
87
|
+
* Then, a user can search the collection for faces in the user-specific container.
|
|
88
|
+
* Note that Collection names are case-sensitive.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* const AWSRekognitionClient = require('express-sweet').services.AWSRekognitionClient;
|
|
92
|
+
*
|
|
93
|
+
* // Instantiate Rekognition client.
|
|
94
|
+
* const client = new AWSRekognitionClient({
|
|
95
|
+
* accessKeyId: process.env.AWS_REKOGNITION_ACCESS_KEY_ID,
|
|
96
|
+
* secretAccessKey: process.env.AWS_REKOGNITION_SECRET_ACCESS_KEY,
|
|
97
|
+
* region: process.env.AWS_REKOGNITION_REGION
|
|
98
|
+
* });
|
|
99
|
+
*
|
|
100
|
+
* try {
|
|
101
|
+
* // Creates a collection.
|
|
102
|
+
* await client.createCollection('MyCollection');
|
|
103
|
+
* } catch(err) {
|
|
104
|
+
* // You can get the resulting HTTP status code from the exception.
|
|
105
|
+
* console.log(`name: ${err.name}`);
|
|
106
|
+
* console.log(`statusCode: ${err.statusCode}`);
|
|
107
|
+
* console.log(`message: ${err.message}`);
|
|
108
|
+
* }
|
|
109
|
+
*
|
|
110
|
+
* @param {string} collectionId ID for the collection that you are creating.
|
|
111
|
+
* The maximum length is 255, and the characters that can be used are "[a-zA-Z0-9_.\-]+".
|
|
112
|
+
*/
|
|
113
|
+
createCollection(collectionId: string): Promise<void>;
|
|
114
|
+
/**
|
|
115
|
+
* Returns list of collection IDs.
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* const AWSRekognitionClient = require('express-sweet').services.AWSRekognitionClient;
|
|
119
|
+
*
|
|
120
|
+
* // Instantiate Rekognition client.
|
|
121
|
+
* const client = new AWSRekognitionClient({
|
|
122
|
+
* accessKeyId: process.env.AWS_REKOGNITION_ACCESS_KEY_ID,
|
|
123
|
+
* secretAccessKey: process.env.AWS_REKOGNITION_SECRET_ACCESS_KEY,
|
|
124
|
+
* region: process.env.AWS_REKOGNITION_REGION
|
|
125
|
+
* });
|
|
126
|
+
*
|
|
127
|
+
* // Find the collection IDs.
|
|
128
|
+
* // Output: [
|
|
129
|
+
* // 'MyCollection',
|
|
130
|
+
* // 'AnotherCollection'
|
|
131
|
+
* // ]
|
|
132
|
+
* await client.listCollections();
|
|
133
|
+
*
|
|
134
|
+
* @return {Promise<string[]>} An array of collection IDs.
|
|
135
|
+
*/
|
|
136
|
+
listCollections(): Promise<string[]>;
|
|
137
|
+
/**
|
|
138
|
+
* Detects one face in the input image and adds it to the specified collection.
|
|
139
|
+
* This method doesn't save the actual faces that are detected.
|
|
140
|
+
* Instead, the underlying detection algorithm first detects the faces in the input image.
|
|
141
|
+
* The algorithm extracts facial features into a feature vector, and stores it in the backend database.
|
|
142
|
+
*
|
|
143
|
+
* Note that this method is used to index one face.
|
|
144
|
+
* Throws an exception if no face is found in the input image or multiple faces are found.
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* const AWSRekognitionClient = require('express-sweet').services.AWSRekognitionClient;
|
|
148
|
+
* const fs = require('fs');
|
|
149
|
+
*
|
|
150
|
+
* // Instantiate Rekognition client.
|
|
151
|
+
* const client = new AWSRekognitionClient({
|
|
152
|
+
* accessKeyId: process.env.AWS_REKOGNITION_ACCESS_KEY_ID,
|
|
153
|
+
* secretAccessKey: process.env.AWS_REKOGNITION_SECRET_ACCESS_KEY,
|
|
154
|
+
* region: process.env.AWS_REKOGNITION_REGION
|
|
155
|
+
* });
|
|
156
|
+
*
|
|
157
|
+
* // Add face to collection from path.
|
|
158
|
+
* // Output: df8adc94-e888-4442-a03d-42aacd4a6cee
|
|
159
|
+
* const faceId = await client.indexFace('MyCollection', 'img.jpg', 'img.jpg');
|
|
160
|
+
* console.log(faceId);
|
|
161
|
+
*
|
|
162
|
+
* // Add face to collection from data URL.
|
|
163
|
+
* // Output: df8adc94-e888-4442-a03d-42aacd4a6cee
|
|
164
|
+
* const faceId = await client.indexFace('MyCollection', 'data:image/png;base64,/9j/4...', 'img.jpg');
|
|
165
|
+
* console.log(faceId);
|
|
166
|
+
*
|
|
167
|
+
* // Add face to collection from buffer.
|
|
168
|
+
* // Output: df8adc94-e888-4442-a03d-42aacd4a6cee
|
|
169
|
+
* const faceId = await client.indexFace('MyCollection', fs.readFileSync('img.jpg'), 'img.jpg');
|
|
170
|
+
* console.log(faceId);
|
|
171
|
+
*
|
|
172
|
+
* // If the face is not found in the image, throw an error.
|
|
173
|
+
* // Output: name: IndexFaceFaceNotFound
|
|
174
|
+
* // statusCode: 400
|
|
175
|
+
* // message: No face was found in the image
|
|
176
|
+
* try {
|
|
177
|
+
* await client.indexFace('MyCollection', 'img.jpg');
|
|
178
|
+
* } catch(err) {
|
|
179
|
+
* // You can get the resulting HTTP status code from the exception.
|
|
180
|
+
* console.log(`name: ${err.name}`);
|
|
181
|
+
* console.log(`statusCode: ${err.statusCode}`);
|
|
182
|
+
* console.log(`message: ${err.message}`);
|
|
183
|
+
* }
|
|
184
|
+
*
|
|
185
|
+
* // If multiple faces are found in the image, throw an error.
|
|
186
|
+
* // Output: name: IndexFaceMultipleFacesFound
|
|
187
|
+
* // statusCode: 400
|
|
188
|
+
* // message: Multiple faces found in the image
|
|
189
|
+
* try {
|
|
190
|
+
* await client.indexFace('MyCollection', 'img.jpg');
|
|
191
|
+
* } catch(err) {
|
|
192
|
+
* // You can get the resulting HTTP status code from the exception.
|
|
193
|
+
* console.log(`name: ${err.name}`);
|
|
194
|
+
* console.log(`statusCode: ${err.statusCode}`);
|
|
195
|
+
* console.log(`message: ${err.message}`);
|
|
196
|
+
* }
|
|
197
|
+
*
|
|
198
|
+
* @param {string} collectionId The ID of an existing collection to which you want to add the faces that are detected in the input images.
|
|
199
|
+
* @param {string} img Image path or Data Url or image buffer.
|
|
200
|
+
* @param {string} externalImageId The ID you want to assign to the faces detected in the image.
|
|
201
|
+
* When you call the "listFaces" operation, the response returns the external ID.
|
|
202
|
+
* You can use this external image ID to create a client-side index to associate the faces with each image.
|
|
203
|
+
* You can then use the index to find all faces in an image.
|
|
204
|
+
* The maximum length is 255, and the characters that can be used are "[a-zA-Z0-9_.\-:]+".
|
|
205
|
+
* @return {Promise<string>} A unique identifier assigned to the face.
|
|
206
|
+
*/
|
|
207
|
+
indexFace(collectionId: string, img: string, externalImageId?: string): Promise<string>;
|
|
208
|
+
/**
|
|
209
|
+
* For a given input image, first detects the largest face in the image, and then searches the specified collection for matching faces.
|
|
210
|
+
* The operation compares the features of the input face with faces in the specified collection.
|
|
211
|
+
*
|
|
212
|
+
* @example
|
|
213
|
+
* const AWSRekognitionClient = require('express-sweet').services.AWSRekognitionClient;
|
|
214
|
+
* const fs = require('fs');
|
|
215
|
+
*
|
|
216
|
+
* // Instantiate Rekognition client.
|
|
217
|
+
* const client = new AWSRekognitionClient({
|
|
218
|
+
* accessKeyId: process.env.AWS_REKOGNITION_ACCESS_KEY_ID,
|
|
219
|
+
* secretAccessKey: process.env.AWS_REKOGNITION_SECRET_ACCESS_KEY,
|
|
220
|
+
* region: process.env.AWS_REKOGNITION_REGION
|
|
221
|
+
* });
|
|
222
|
+
*
|
|
223
|
+
* // If you want to search for one face, specify 1 for the maxFaces option.
|
|
224
|
+
* // In that case, the search result will return the face data for one person.
|
|
225
|
+
* // Output: {
|
|
226
|
+
* // faceId: '2ce7f471-9c4b-4f27-b5a4-bbd02a5e134d',
|
|
227
|
+
* // boundingBox: {
|
|
228
|
+
* // width: 0.500495970249176,
|
|
229
|
+
* // height: 0.6926820278167725,
|
|
230
|
+
* // left: 0.2928670048713684,
|
|
231
|
+
* // top: 0.09095799922943115
|
|
232
|
+
* // },
|
|
233
|
+
* // externalImageId: 'img.jpg'
|
|
234
|
+
* // }
|
|
235
|
+
* const match = await client.searchFaces('MyCollection', 'img.jpg', {minConfidence: 99, maxFaces: 1});
|
|
236
|
+
* console.log(match);
|
|
237
|
+
*
|
|
238
|
+
* // If you want to search for multiple faces, specify 2 or more for the maxFaces option.
|
|
239
|
+
* // In that case, the search results will return a list of the face data of multiple people found.
|
|
240
|
+
* // Output: [
|
|
241
|
+
* // {
|
|
242
|
+
* // faceId: '2ce7f471-9c4b-4f27-b5a4-bbd02a5e134d',
|
|
243
|
+
* // boundingBox: {
|
|
244
|
+
* // width: 0.500495970249176,
|
|
245
|
+
* // height: 0.6926820278167725,
|
|
246
|
+
* // left: 0.2928670048713684,
|
|
247
|
+
* // top: 0.09095799922943115
|
|
248
|
+
* // },
|
|
249
|
+
* // externalImageId: 'img.jpg'
|
|
250
|
+
* // }
|
|
251
|
+
* // ]
|
|
252
|
+
* const matches = await client.searchFaces('MyCollection', 'img.jpg', {minConfidence: 99, maxFaces: 5});
|
|
253
|
+
* console.log(matches);
|
|
254
|
+
*
|
|
255
|
+
* // The input image can specify a buffer or DataURL in addition to the image path.
|
|
256
|
+
* await client.searchFaces('MyCollection', 'data:image/png;base64,/9j/4...');
|
|
257
|
+
* await client.searchFaces('MyCollection', fs.readFileSync('img.jpg'));
|
|
258
|
+
*
|
|
259
|
+
* @param {string} collectionId ID of the collection to search.
|
|
260
|
+
* @param {string} img Image path or Data Url or image buffer.
|
|
261
|
+
* @param {object} options option.
|
|
262
|
+
* @param {number} options.minConfidence Specifies the minimum confidence in the face match to return.
|
|
263
|
+
* The default value is 80%.
|
|
264
|
+
* @param {number} options.maxFaces Maximum number of faces to return.
|
|
265
|
+
* The operation returns the maximum number of faces with the highest confidence in the match.
|
|
266
|
+
* The default value is 5.
|
|
267
|
+
* @return {Promise<FaceMatch[]|FaceMatch|null>} If options.maxFaces is 1, the face information found is returned.
|
|
268
|
+
* If options.maxFaces is 2 or more, the list of face information found is returned.
|
|
269
|
+
* Returns null if no face is found.
|
|
270
|
+
*/
|
|
271
|
+
searchFaces(collectionId: string, img: string, opts?: {
|
|
272
|
+
minConfidence?: number;
|
|
273
|
+
maxFaces?: number;
|
|
274
|
+
}): Promise<FaceMatch[] | FaceMatch | null>;
|
|
275
|
+
/**
|
|
276
|
+
* Returns metadata for faces in the specified collection.
|
|
277
|
+
* This metadata includes information such as the bounding box coordinates, and face ID.
|
|
278
|
+
*
|
|
279
|
+
* @example
|
|
280
|
+
* const AWSRekognitionClient = require('express-sweet').services.AWSRekognitionClient;
|
|
281
|
+
* const fs = require('fs');
|
|
282
|
+
*
|
|
283
|
+
* // Instantiate Rekognition client.
|
|
284
|
+
* const client = new AWSRekognitionClient({
|
|
285
|
+
* accessKeyId: process.env.AWS_REKOGNITION_ACCESS_KEY_ID,
|
|
286
|
+
* secretAccessKey: process.env.AWS_REKOGNITION_SECRET_ACCESS_KEY,
|
|
287
|
+
* region: process.env.AWS_REKOGNITION_REGION
|
|
288
|
+
* });
|
|
289
|
+
*
|
|
290
|
+
* // Find all face metadata in the collection.
|
|
291
|
+
* // Output: [
|
|
292
|
+
* // {
|
|
293
|
+
* // faceId: '2ce7f471-9c4b-4f27-b5a4-bbd02a5e134d',
|
|
294
|
+
* // boundingBox: {
|
|
295
|
+
* // width: 0.500495970249176,
|
|
296
|
+
* // height: 0.6926820278167725,
|
|
297
|
+
* // left: 0.2928670048713684,
|
|
298
|
+
* // top: 0.09095799922943115
|
|
299
|
+
* // },
|
|
300
|
+
* // externalImageId: 'img.jpg'
|
|
301
|
+
* // }
|
|
302
|
+
* // ]
|
|
303
|
+
* const result = await client.listFaces('MyCollection');
|
|
304
|
+
* console.log(result);
|
|
305
|
+
*
|
|
306
|
+
* @param {string} collectionId ID of the collection from which to list the faces.
|
|
307
|
+
* @param {number} maxResults Maximum number of faces to return.
|
|
308
|
+
* The default value is 1000.
|
|
309
|
+
* @return {Promise<FaceMatch[]>} Returns all face metadata in the collection.
|
|
310
|
+
*/
|
|
311
|
+
listFaces(collectionId: string, maxResults?: number): Promise<FaceMatch[]>;
|
|
312
|
+
/**
|
|
313
|
+
* Deletes faces from a collection.
|
|
314
|
+
* You specify a collection ID and an array of face IDs to remove from the collection.
|
|
315
|
+
*
|
|
316
|
+
* @example
|
|
317
|
+
* const AWSRekognitionClient = require('express-sweet').services.AWSRekognitionClient;
|
|
318
|
+
*
|
|
319
|
+
* // Instantiate Rekognition client.
|
|
320
|
+
* const client = new AWSRekognitionClient({
|
|
321
|
+
* accessKeyId: process.env.AWS_REKOGNITION_ACCESS_KEY_ID,
|
|
322
|
+
* secretAccessKey: process.env.AWS_REKOGNITION_SECRET_ACCESS_KEY,
|
|
323
|
+
* region: process.env.AWS_REKOGNITION_REGION
|
|
324
|
+
* });
|
|
325
|
+
*
|
|
326
|
+
* // Delete a face from the collection.
|
|
327
|
+
* await client.deleteFaces('MyCollection', ['f7befa24-3b83-43cc-b21f-7fac4b91f51d']);
|
|
328
|
+
*
|
|
329
|
+
* @param {string} collectionId Collection from which to remove the specific faces.
|
|
330
|
+
* @param {string[]} faceIds An array of face IDs to delete.
|
|
331
|
+
*/
|
|
332
|
+
deleteFaces(collectionId: string, faceIds: string[]): Promise<void>;
|
|
333
|
+
/**
|
|
334
|
+
* Deletes the specified collection.
|
|
335
|
+
* Note that this operation removes all faces in the collection.
|
|
336
|
+
*
|
|
337
|
+
* @example
|
|
338
|
+
* const AWSRekognitionClient = require('express-sweet').services.AWSRekognitionClient;
|
|
339
|
+
*
|
|
340
|
+
* // Instantiate Rekognition client.
|
|
341
|
+
* const client = new AWSRekognitionClient({
|
|
342
|
+
* accessKeyId: process.env.AWS_REKOGNITION_ACCESS_KEY_ID,
|
|
343
|
+
* secretAccessKey: process.env.AWS_REKOGNITION_SECRET_ACCESS_KEY,
|
|
344
|
+
* region: process.env.AWS_REKOGNITION_REGION
|
|
345
|
+
* });
|
|
346
|
+
*
|
|
347
|
+
* // Delete collection.
|
|
348
|
+
* await client.deleteCollection('MyCollection');
|
|
349
|
+
*
|
|
350
|
+
* @param {string} collectionId ID of the collection to delete.
|
|
351
|
+
*/
|
|
352
|
+
deleteCollection(collectionId: string): Promise<void>;
|
|
353
|
+
/**
|
|
354
|
+
* Returns a buffer of images..
|
|
355
|
+
* @param {string|Buffer} img Image path or Data Url or image buffer.
|
|
356
|
+
* @return {Buffer} Image buffer.
|
|
357
|
+
*/
|
|
358
|
+
private getImageBuffer;
|
|
359
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import express from 'express';
|
|
2
|
+
/**
|
|
3
|
+
* User authentication service.
|
|
4
|
+
*/
|
|
5
|
+
export default class {
|
|
6
|
+
/**
|
|
7
|
+
* Authenticate the user.
|
|
8
|
+
*
|
|
9
|
+
* @param {express.Request} req The req object represents the HTTP request and has properties for the request query string, parameters, body, HTTP headers, and so on.
|
|
10
|
+
* @param {express.Response} res The res object represents the HTTP response that an Express app sends when it gets an HTTP request.
|
|
11
|
+
* @param {express.NextFunction} next A function that can access the next middleware function in the application's request-response cycle.
|
|
12
|
+
* @return {Promise<boolean>} Returns true if authentication is successful, false otherwise.
|
|
13
|
+
*/
|
|
14
|
+
static authenticate(req: express.Request, res: express.Response, next: express.NextFunction): Promise<boolean>;
|
|
15
|
+
/**
|
|
16
|
+
* Log out the user.
|
|
17
|
+
*
|
|
18
|
+
* @param {express.Request} req The req object represents the HTTP request and has properties for the request query string, parameters, body, HTTP headers, and so on.
|
|
19
|
+
*/
|
|
20
|
+
static logout(req: express.Request): void;
|
|
21
|
+
/**
|
|
22
|
+
* Redirects to the page that responds immediately after successful authentication set in "success_redirect" of "config/authentication.js".
|
|
23
|
+
*
|
|
24
|
+
* @param {express.Response} res The res object represents the HTTP response that an Express app sends when it gets an HTTP request.
|
|
25
|
+
*/
|
|
26
|
+
static successRedirect(res: express.Response): void;
|
|
27
|
+
/**
|
|
28
|
+
* Redirects to the page that responds immediately after authentication failure set in "failure_redirect" of "config/authentication.js".
|
|
29
|
+
*
|
|
30
|
+
* @param {express.Response} res The res object represents the HTTP response that an Express app sends when it gets an HTTP request.
|
|
31
|
+
*/
|
|
32
|
+
static failureRedirect(res: express.Response): void;
|
|
33
|
+
/**
|
|
34
|
+
* Returns the option.
|
|
35
|
+
*
|
|
36
|
+
* @return {AuthenticationOptions} option.
|
|
37
|
+
*/
|
|
38
|
+
private static loadOptions;
|
|
39
|
+
}
|