adapt-authoring-api 1.3.6 → 1.4.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/lib/AbstractApiModule.js +31 -0
- package/package.json +3 -6
package/lib/AbstractApiModule.js
CHANGED
|
@@ -410,6 +410,37 @@ class AbstractApiModule extends AbstractModule {
|
|
|
410
410
|
opts[key] = val
|
|
411
411
|
}
|
|
412
412
|
})
|
|
413
|
+
// handle search parameter
|
|
414
|
+
const search = req.apiData.query.search
|
|
415
|
+
if (search) {
|
|
416
|
+
delete req.apiData.query.search
|
|
417
|
+
try {
|
|
418
|
+
const schema = await this.getSchema(req.apiData.schemaName)
|
|
419
|
+
if (schema && schema.built && schema.built.properties) {
|
|
420
|
+
const searchableFields = Object.keys(schema.built.properties).filter(
|
|
421
|
+
field => schema.built.properties[field].isSearchable === true
|
|
422
|
+
)
|
|
423
|
+
if (searchableFields.length) {
|
|
424
|
+
// escape special regex characters to prevent ReDoS attacks
|
|
425
|
+
const escapedSearch = search.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
|
426
|
+
const regex = { $regex: escapedSearch, $options: 'i' }
|
|
427
|
+
const searchConditions = searchableFields.map(f => ({ [f]: regex }))
|
|
428
|
+
// merge with existing $or if present
|
|
429
|
+
if (req.apiData.query.$or) {
|
|
430
|
+
req.apiData.query.$and = [
|
|
431
|
+
{ $or: req.apiData.query.$or },
|
|
432
|
+
{ $or: searchConditions }
|
|
433
|
+
]
|
|
434
|
+
delete req.apiData.query.$or
|
|
435
|
+
} else {
|
|
436
|
+
req.apiData.query.$or = searchConditions
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
} catch (e) {
|
|
441
|
+
this.log('warn', `failed to process search parameter, ${e.message}`)
|
|
442
|
+
}
|
|
443
|
+
}
|
|
413
444
|
req.apiData.query = await this.parseQuery(req.apiData.schemaName, req.body, mongoOpts)
|
|
414
445
|
// remove any valid query keys from the options
|
|
415
446
|
Object.keys(req.apiData.query).forEach(key => delete opts[key])
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "adapt-authoring-api",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Abstract module for creating APIs",
|
|
5
5
|
"homepage": "https://github.com/adapt-security/adapt-authoring-api",
|
|
6
6
|
"license": "GPL-3.0",
|
|
@@ -8,11 +8,11 @@
|
|
|
8
8
|
"main": "index.js",
|
|
9
9
|
"repository": "github:adapt-security/adapt-authoring-api",
|
|
10
10
|
"dependencies": {
|
|
11
|
+
"adapt-authoring-core": "^1.7.0",
|
|
11
12
|
"lodash": "^4.17.21"
|
|
12
13
|
},
|
|
13
14
|
"peerDependencies": {
|
|
14
|
-
"adapt-authoring-auth": "^1.0.
|
|
15
|
-
"adapt-authoring-core": "^1.7.0",
|
|
15
|
+
"adapt-authoring-auth": "^1.0.6",
|
|
16
16
|
"adapt-authoring-jsonschema": "^1.2.0",
|
|
17
17
|
"adapt-authoring-mongodb": "^1.1.3",
|
|
18
18
|
"adapt-authoring-server": "^1.2.1"
|
|
@@ -21,9 +21,6 @@
|
|
|
21
21
|
"adapt-authoring-auth": {
|
|
22
22
|
"optional": true
|
|
23
23
|
},
|
|
24
|
-
"adapt-authoring-core": {
|
|
25
|
-
"optional": true
|
|
26
|
-
},
|
|
27
24
|
"adapt-authoring-jsonschema": {
|
|
28
25
|
"optional": true
|
|
29
26
|
},
|