ac-sanitizer 5.1.2 → 5.2.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/CHANGELOG.md +23 -0
- package/README.md +1 -0
- package/index.js +6 -0
- package/package.json +5 -5
- package/test/tests/helper.js +4 -0
- package/test/tests/string.js +4 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,26 @@
|
|
|
1
|
+
|
|
2
|
+
# [5.2.0](https://github.com/mmpro/ac-sanitizer/compare/v5.1.3..v5.2.0) (2025-09-20 14:05:48)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Feature
|
|
6
|
+
|
|
7
|
+
* **App:** Add new option optional | MP | [1363c1fce0495baba599acd52409893d6484fa13](https://github.com/mmpro/ac-sanitizer/commit/1363c1fce0495baba599acd52409893d6484fa13)
|
|
8
|
+
With field property optional, fields are removed from payload if they are nil
|
|
9
|
+
Related issues:
|
|
10
|
+
### Chores
|
|
11
|
+
|
|
12
|
+
* **App:** Updated packages | MP | [b01e620c2d20b17155cfb29408dca292806a4969](https://github.com/mmpro/ac-sanitizer/commit/b01e620c2d20b17155cfb29408dca292806a4969)
|
|
13
|
+
Updated packages
|
|
14
|
+
Related issues:
|
|
15
|
+
|
|
16
|
+
## [5.1.3](https://github.com/mmpro/ac-sanitizer/compare/v5.1.2..v5.1.3) (2025-09-19 05:27:36)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### Bug Fix
|
|
20
|
+
|
|
21
|
+
* **Misc:** Package updates | MP | [e1bb82a004239df4207d8c11e7fd84e82d07172f](https://github.com/mmpro/ac-sanitizer/commit/e1bb82a004239df4207d8c11e7fd84e82d07172f)
|
|
22
|
+
Package updates
|
|
23
|
+
Related issues:
|
|
1
24
|
|
|
2
25
|
## [5.1.2](https://github.com/mmpro/ac-sanitizer/compare/v5.1.1..v5.1.2) (2025-09-19 05:13:36)
|
|
3
26
|
|
package/README.md
CHANGED
|
@@ -60,6 +60,7 @@ convert | [boolean OR string] | Some types can be automatically converted (e.g.
|
|
|
60
60
|
valueType | [string] | Use it to sanitize values of an array by defining the allowed type here
|
|
61
61
|
strict | [boolean] | For objects only - if true and payload contains a property not defined, an error will be returned.
|
|
62
62
|
nullAllowed | [boolean] | If true, sending NULL is allowed.
|
|
63
|
+
optional | [boolean] | If true and the value is nil, the property is removed/omitted from payload. Helpful to cleanup response payloads.
|
|
63
64
|
|
|
64
65
|
[^1]: The path must be set with the parent propery as root, e.g. the actual field is settings.video.width, in property video the condition is then just "width" not the full path.
|
|
65
66
|
|
package/index.js
CHANGED
|
@@ -180,6 +180,12 @@ const sanitizer = function() {
|
|
|
180
180
|
if (error) {
|
|
181
181
|
// do not process other conditions
|
|
182
182
|
}
|
|
183
|
+
else if (_.get(field, 'optional') && _.isNil(value)) {
|
|
184
|
+
// optional field can be removed from (response) payload if value is nil
|
|
185
|
+
fields = _.filter(fields, item => {
|
|
186
|
+
if (item.field !== fieldName) return item
|
|
187
|
+
})
|
|
188
|
+
}
|
|
183
189
|
else if (field.nullAllowed && _.isNull(_.get(paramsToCheck, fieldName))) {
|
|
184
190
|
// do nothing null is allowed and sent!
|
|
185
191
|
}
|
package/package.json
CHANGED
|
@@ -4,14 +4,14 @@
|
|
|
4
4
|
"author": "Mark Poepping (https://www.admiralcloud.com)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "admiralcloud/ac-sanitizer",
|
|
7
|
-
"version": "5.
|
|
7
|
+
"version": "5.2.0",
|
|
8
8
|
"homepage": "https://www.admiralcloud.com",
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"ac-countrylist": "^1.0.
|
|
10
|
+
"ac-countrylist": "^1.0.15",
|
|
11
11
|
"ac-file-extensions": "^2.0.13",
|
|
12
|
-
"ac-ip": "^4.1.
|
|
12
|
+
"ac-ip": "^4.1.6",
|
|
13
13
|
"chai": "^4.5.0",
|
|
14
|
-
"date-and-time": "^
|
|
14
|
+
"date-and-time": "^4.0.5",
|
|
15
15
|
"hashids": "^2.3.0",
|
|
16
16
|
"lodash": "^4.17.21",
|
|
17
17
|
"validator": "^13.15.15"
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"ac-semantic-release": "^0.4.8",
|
|
21
21
|
"c8": "^10.1.3",
|
|
22
|
-
"eslint": "^9.
|
|
22
|
+
"eslint": "^9.36.0",
|
|
23
23
|
"mocha": "^11.7.2"
|
|
24
24
|
},
|
|
25
25
|
"scripts": {
|
package/test/tests/helper.js
CHANGED
|
@@ -31,6 +31,10 @@ const runValidationTests = (tests, fieldName, { equalityCheck = 'equal', adminLe
|
|
|
31
31
|
expect(_.get(r, 'error.additionalInfo'))[equalityCheck](_.get(test, 'additionalInfo'))
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
|
+
else if (_.get(test, 'optional') && _.isNil(_.get(test, 'value'))) {
|
|
35
|
+
// if field is optional and value is nil, the field is removed from params
|
|
36
|
+
expect(_.get(r, `params.${fieldName}`)).to.be.undefined
|
|
37
|
+
}
|
|
34
38
|
else {
|
|
35
39
|
expect(_.get(r, `params.${fieldName}`))[equalityCheck](_.get(test, 'expected'))
|
|
36
40
|
}
|
package/test/tests/string.js
CHANGED
|
@@ -20,7 +20,10 @@ module.exports = {
|
|
|
20
20
|
{ name: 'Valid - uppercase vs lowercase', type: 'string', ignoreCase: true, value: 'ABC', enum: ['abc'], expected: 'ABC' },
|
|
21
21
|
{ name: 'Invalid - value too short', type: 'string', minLength: 5, value: 'ABC', error: 'string_stringTooShort_minLength5' },
|
|
22
22
|
{ name: 'Valid - value is longer than 5 chars', type: 'string', minLength: 5, value: 'ABCDEF', expected: 'ABCDEF' },
|
|
23
|
-
{ name: 'Valid - value is a URL encoded, space separated string', type: 'string', convert: 'splitSpaceSeparated', value: 'one%20two%20three', expected: ['one', 'two', 'three'] }
|
|
23
|
+
{ name: 'Valid - value is a URL encoded, space separated string', type: 'string', convert: 'splitSpaceSeparated', value: 'one%20two%20three', expected: ['one', 'two', 'three'] },
|
|
24
|
+
{ name: 'Valid - values is null and null allowed', type: 'string', nullAllowed: true, value: null, expected: null },
|
|
25
|
+
{ name: 'Valid - values is null and null allowed and field is optional', type: 'string', nullAllowed: true, optional: true, value: null },
|
|
26
|
+
|
|
24
27
|
]
|
|
25
28
|
|
|
26
29
|
runValidationTests(baseTests, 'string', { equalityCheck: 'eql' })
|