@dwtechs/antity 0.9.1 → 0.10.0
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/README.md +32 -2
- package/dist/antity.d.ts +7 -6
- package/dist/antity.js +21 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -143,6 +143,7 @@ type Type =
|
|
|
143
143
|
"array" |
|
|
144
144
|
"jwt" |
|
|
145
145
|
"symbol" |
|
|
146
|
+
"password" |
|
|
146
147
|
"email" |
|
|
147
148
|
"regex" |
|
|
148
149
|
"json" |
|
|
@@ -203,7 +204,7 @@ class Entity {
|
|
|
203
204
|
* Normalizes an array of records by applying sanitization and normalization
|
|
204
205
|
* rules defined in the `properties` of the class.
|
|
205
206
|
*/
|
|
206
|
-
normalize(req: Request, _res: Response, next: NextFunction)
|
|
207
|
+
normalize: (req: Request, _res: Response, next: NextFunction) => void;
|
|
207
208
|
|
|
208
209
|
/**
|
|
209
210
|
* Validates a set of rows against the defined properties and operation/method.
|
|
@@ -211,7 +212,7 @@ class Entity {
|
|
|
211
212
|
* If a property is required and missing, or if it fails the control checks, the function returns an error message.
|
|
212
213
|
* Otherwise, it returns `null` indicating successful validation.
|
|
213
214
|
*/
|
|
214
|
-
validate(req: Request, _res: Response, next: NextFunction)
|
|
215
|
+
validate: (req: Request, _res: Response, next: NextFunction) => void;
|
|
215
216
|
}
|
|
216
217
|
|
|
217
218
|
```
|
|
@@ -219,6 +220,35 @@ normalize() and validate() methods are made to be used as Express.js middlewares
|
|
|
219
220
|
Each method will look for data to work on in the **req.body.rows** parameter.
|
|
220
221
|
|
|
221
222
|
|
|
223
|
+
### Password validation
|
|
224
|
+
|
|
225
|
+
Password validation will have the following options by default :
|
|
226
|
+
|
|
227
|
+
```javascript
|
|
228
|
+
const PWD_MIN_LENGTH = 9;
|
|
229
|
+
const PWD_MAX_LENGTH = 20;
|
|
230
|
+
const PWD_NUMBERS = true; // password must contain a number
|
|
231
|
+
const PWD_UPPERCASE = true; // password must contain an uppercase letter
|
|
232
|
+
const PWD_LOWERCASE = true; // password must contain a lowercase letter
|
|
233
|
+
const PWD_SYMBOLS = true; // password must contain at least one of the following symbol character : !@#%*_-+=:?><./()
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
#### Environment variables
|
|
237
|
+
|
|
238
|
+
You can update password default validator by setting the following environment variables :
|
|
239
|
+
|
|
240
|
+
```javascript
|
|
241
|
+
PWD_MIN_LENGTH_POLICY,
|
|
242
|
+
PWD_MAX_LENGTH_POLICY,
|
|
243
|
+
PWD_NUMBERS_POLICY,
|
|
244
|
+
PWD_UPPERCASE_POLICY,
|
|
245
|
+
PWD_LOWERCASE_POLICY,
|
|
246
|
+
PWD_SYMBOLS_POLICY
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
Properties **min** and **max** of the password properties will override default and environement variable if set.
|
|
250
|
+
|
|
251
|
+
|
|
222
252
|
### Available options for a property
|
|
223
253
|
|
|
224
254
|
Any of these can be passed into the options object for each function.
|
package/dist/antity.d.ts
CHANGED
|
@@ -42,6 +42,7 @@ type Type =
|
|
|
42
42
|
"array" |
|
|
43
43
|
"jwt" |
|
|
44
44
|
"symbol" |
|
|
45
|
+
"password" |
|
|
45
46
|
"email" |
|
|
46
47
|
"regex" |
|
|
47
48
|
"json" |
|
|
@@ -67,15 +68,15 @@ declare class Entity {
|
|
|
67
68
|
set name(name: string);
|
|
68
69
|
getProp(key: string): Property | undefined;
|
|
69
70
|
getPropsByMethod(method: Method): Property[];
|
|
70
|
-
normalize(req: Request, _res: Response, next: NextFunction)
|
|
71
|
-
validate(req: Request, _res: Response, next: NextFunction)
|
|
71
|
+
normalize: (req: Request, _res: Response, next: NextFunction) => void;
|
|
72
|
+
validate: (req: Request, _res: Response, next: NextFunction) => void;
|
|
72
73
|
}
|
|
73
74
|
|
|
74
75
|
declare class Property {
|
|
75
76
|
key: string;
|
|
76
77
|
type: Type;
|
|
77
|
-
min: number | Date;
|
|
78
|
-
max: number | Date;
|
|
78
|
+
min: number | Date | null;
|
|
79
|
+
max: number | Date | null;
|
|
79
80
|
required: boolean;
|
|
80
81
|
safe: boolean;
|
|
81
82
|
typeCheck: boolean;
|
|
@@ -89,8 +90,8 @@ declare class Property {
|
|
|
89
90
|
constructor(
|
|
90
91
|
key: string,
|
|
91
92
|
type: Type,
|
|
92
|
-
min: number | Date,
|
|
93
|
-
max: number | Date,
|
|
93
|
+
min: number | Date | null,
|
|
94
|
+
max: number | Date | null,
|
|
94
95
|
required: boolean,
|
|
95
96
|
safe: boolean,
|
|
96
97
|
typeCheck: boolean,
|
package/dist/antity.js
CHANGED
|
@@ -24,11 +24,18 @@ SOFTWARE.
|
|
|
24
24
|
https://github.com/DWTechs/Antity.js
|
|
25
25
|
*/
|
|
26
26
|
|
|
27
|
-
import { isBoolean, isStringOfLength, isValidNumber, isValidInteger, isValidFloat, isEven, isOdd, isPositive, isNegative, isPowerOfTwo, isAscii, isArrayOfLength, isEmail, isRegex, isJson, isJWT, isSymbol, isIpAddress, isSlug, isHexadecimal, isValidDate, isValidTimestamp, isFunction, isHtmlElement, isHtmlEventAttribute, isNode, isObject, isString, isProperty, isArray, isIn, isDate, isNumber, isInteger, isNil } from '@dwtechs/checkard';
|
|
27
|
+
import { isBoolean, isStringOfLength, isValidNumber, isValidInteger, isValidFloat, isEven, isOdd, isPositive, isNegative, isPowerOfTwo, isAscii, isArrayOfLength, isValidPassword, isEmail, isRegex, isJson, isJWT, isSymbol, isIpAddress, isSlug, isHexadecimal, isValidDate, isValidTimestamp, isFunction, isHtmlElement, isHtmlEventAttribute, isNode, isObject, isString, isProperty, isArray, isIn, isDate, isNumber, isInteger, isNil } from '@dwtechs/checkard';
|
|
28
28
|
import { log } from '@dwtechs/winstan';
|
|
29
29
|
|
|
30
30
|
const Methods = ["GET", "PATCH", "PUT", "POST", "DELETE"];
|
|
31
31
|
|
|
32
|
+
const { PWD_MIN_LENGTH_POLICY, PWD_MAX_LENGTH_POLICY, PWD_NUMBERS_POLICY, PWD_UPPERCASE_POLICY, PWD_LOWERCASE_POLICY, PWD_SYMBOLS_POLICY } = process.env;
|
|
33
|
+
const PWD_MIN_LENGTH = PWD_MIN_LENGTH_POLICY ? +PWD_MIN_LENGTH_POLICY : 9;
|
|
34
|
+
const PWD_MAX_LENGTH = PWD_MAX_LENGTH_POLICY ? +PWD_MAX_LENGTH_POLICY : 20;
|
|
35
|
+
const PWD_NUMBERS = PWD_NUMBERS_POLICY ? true : false;
|
|
36
|
+
const PWD_UPPERCASE = PWD_UPPERCASE_POLICY ? true : false;
|
|
37
|
+
const PWD_LOWERCASE = PWD_LOWERCASE_POLICY ? true : false;
|
|
38
|
+
const PWD_SYMBOLS = PWD_SYMBOLS_POLICY ? true : false;
|
|
32
39
|
const Types = {
|
|
33
40
|
boolean: {
|
|
34
41
|
validate: (v, _min, _max, _typeCheck) => isBoolean(v)
|
|
@@ -66,6 +73,19 @@ const Types = {
|
|
|
66
73
|
array: {
|
|
67
74
|
validate: (v, min, max, _typeCheck) => isArrayOfLength(v, min || undefined, max || undefined)
|
|
68
75
|
},
|
|
76
|
+
password: {
|
|
77
|
+
validate: (v, min, max, _typeCheck) => {
|
|
78
|
+
const o = {
|
|
79
|
+
minLength: min || PWD_MIN_LENGTH,
|
|
80
|
+
maxLength: max || PWD_MAX_LENGTH,
|
|
81
|
+
lowerCase: PWD_LOWERCASE,
|
|
82
|
+
upperCase: PWD_UPPERCASE,
|
|
83
|
+
number: PWD_NUMBERS,
|
|
84
|
+
specialCharacter: PWD_SYMBOLS,
|
|
85
|
+
};
|
|
86
|
+
return isValidPassword(v, o);
|
|
87
|
+
}
|
|
88
|
+
},
|
|
69
89
|
email: {
|
|
70
90
|
validate: (v, _min, _max, _typeCheck) => isEmail(v)
|
|
71
91
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dwtechs/antity",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "Open source library for easy entity management",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"entities"
|
|
@@ -53,6 +53,6 @@
|
|
|
53
53
|
"core-js": "3.33.0",
|
|
54
54
|
"jest": "29.7.0",
|
|
55
55
|
"rollup": "4.24.0",
|
|
56
|
-
"typescript": "5.
|
|
56
|
+
"typescript": "5.8.3"
|
|
57
57
|
}
|
|
58
58
|
}
|