@strapi/utils 4.0.0-beta.12 → 4.0.0-beta.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/lib/content-types.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const _ = require('lodash');
|
|
4
|
+
const { has } = require('lodash/fp');
|
|
4
5
|
|
|
5
6
|
const SINGLE_TYPE = 'singleType';
|
|
6
7
|
const COLLECTION_TYPE = 'collectionType';
|
|
@@ -31,8 +32,18 @@ const constants = {
|
|
|
31
32
|
COLLECTION_TYPE,
|
|
32
33
|
};
|
|
33
34
|
|
|
34
|
-
const getTimestamps =
|
|
35
|
-
|
|
35
|
+
const getTimestamps = model => {
|
|
36
|
+
const attributes = [];
|
|
37
|
+
|
|
38
|
+
if (has(CREATED_AT_ATTRIBUTE, model.attributes)) {
|
|
39
|
+
attributes.push(CREATED_AT_ATTRIBUTE);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (has(UPDATED_AT_ATTRIBUTE, model.attributes)) {
|
|
43
|
+
attributes.push(UPDATED_AT_ATTRIBUTE);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return attributes;
|
|
36
47
|
};
|
|
37
48
|
|
|
38
49
|
const getNonWritableAttributes = (model = {}) => {
|
|
@@ -42,7 +53,7 @@ const getNonWritableAttributes = (model = {}) => {
|
|
|
42
53
|
[]
|
|
43
54
|
);
|
|
44
55
|
|
|
45
|
-
return _.uniq([ID_ATTRIBUTE, ...getTimestamps(), ...nonWritableAttributes]);
|
|
56
|
+
return _.uniq([ID_ATTRIBUTE, ...getTimestamps(model), ...nonWritableAttributes]);
|
|
46
57
|
};
|
|
47
58
|
|
|
48
59
|
const getWritableAttributes = (model = {}) => {
|
|
@@ -60,7 +71,7 @@ const getNonVisibleAttributes = model => {
|
|
|
60
71
|
[]
|
|
61
72
|
);
|
|
62
73
|
|
|
63
|
-
return _.uniq([ID_ATTRIBUTE, ...getTimestamps(), ...nonVisibleAttributes]);
|
|
74
|
+
return _.uniq([ID_ATTRIBUTE, ...getTimestamps(model), ...nonVisibleAttributes]);
|
|
64
75
|
};
|
|
65
76
|
|
|
66
77
|
const getVisibleAttributes = model => {
|
|
@@ -137,6 +148,7 @@ module.exports = {
|
|
|
137
148
|
isWritableAttribute,
|
|
138
149
|
getNonVisibleAttributes,
|
|
139
150
|
getVisibleAttributes,
|
|
151
|
+
getTimestamps,
|
|
140
152
|
isVisibleAttribute,
|
|
141
153
|
hasDraftAndPublish,
|
|
142
154
|
isDraft,
|
package/lib/index.js
CHANGED
|
@@ -33,6 +33,7 @@ const providerFactory = require('./provider-factory');
|
|
|
33
33
|
const pagination = require('./pagination');
|
|
34
34
|
const sanitize = require('./sanitize');
|
|
35
35
|
const traverseEntity = require('./traverse-entity');
|
|
36
|
+
const pipeAsync = require('./pipe-async');
|
|
36
37
|
|
|
37
38
|
module.exports = {
|
|
38
39
|
yup,
|
|
@@ -66,6 +67,7 @@ module.exports = {
|
|
|
66
67
|
hooks,
|
|
67
68
|
providerFactory,
|
|
68
69
|
pagination,
|
|
70
|
+
pipeAsync,
|
|
69
71
|
errors,
|
|
70
72
|
validateYupSchema,
|
|
71
73
|
validateYupSchemaSync,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
module.exports = (...methods) => async data => {
|
|
4
4
|
let res = data;
|
|
5
5
|
|
|
6
6
|
for (const method of methods) {
|
|
@@ -9,7 +9,3 @@ const pipeAsync = (...methods) => async data => {
|
|
|
9
9
|
|
|
10
10
|
return res;
|
|
11
11
|
};
|
|
12
|
-
|
|
13
|
-
module.exports = {
|
|
14
|
-
pipeAsync,
|
|
15
|
-
};
|
package/lib/sanitize/index.js
CHANGED
|
@@ -4,8 +4,10 @@ const { isArray } = require('lodash/fp');
|
|
|
4
4
|
|
|
5
5
|
const traverseEntity = require('../traverse-entity');
|
|
6
6
|
const { getNonWritableAttributes } = require('../content-types');
|
|
7
|
+
const pipeAsync = require('../pipe-async');
|
|
8
|
+
|
|
7
9
|
const visitors = require('./visitors');
|
|
8
|
-
const
|
|
10
|
+
const sanitizers = require('./sanitizers');
|
|
9
11
|
|
|
10
12
|
module.exports = {
|
|
11
13
|
contentAPI: {
|
|
@@ -26,7 +28,7 @@ module.exports = {
|
|
|
26
28
|
transforms.push(traverseEntity(visitors.removeRestrictedRelations(auth), { schema }));
|
|
27
29
|
}
|
|
28
30
|
|
|
29
|
-
return
|
|
31
|
+
return pipeAsync(...transforms)(data);
|
|
30
32
|
},
|
|
31
33
|
|
|
32
34
|
output(data, schema, { auth } = {}) {
|
|
@@ -34,30 +36,16 @@ module.exports = {
|
|
|
34
36
|
return Promise.all(data.map(entry => this.output(entry, schema, { auth })));
|
|
35
37
|
}
|
|
36
38
|
|
|
37
|
-
const transforms = [
|
|
38
|
-
traverseEntity(visitors.removePassword, { schema }),
|
|
39
|
-
traverseEntity(visitors.removePrivate, { schema }),
|
|
40
|
-
];
|
|
39
|
+
const transforms = [sanitizers.defaultSanitizeOutput(schema)];
|
|
41
40
|
|
|
42
41
|
if (auth) {
|
|
43
42
|
transforms.push(traverseEntity(visitors.removeRestrictedRelations(auth), { schema }));
|
|
44
43
|
}
|
|
45
44
|
|
|
46
|
-
return
|
|
45
|
+
return pipeAsync(...transforms)(data);
|
|
47
46
|
},
|
|
48
47
|
},
|
|
49
48
|
|
|
50
|
-
|
|
51
|
-
if (isArray(data)) {
|
|
52
|
-
return Promise.all(data.map(entry => this.eventHub(entry, schema)));
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return utils.pipeAsync(
|
|
56
|
-
traverseEntity(visitors.removePassword, { schema }),
|
|
57
|
-
traverseEntity(visitors.removePrivate, { schema })
|
|
58
|
-
)(data);
|
|
59
|
-
},
|
|
60
|
-
|
|
61
|
-
utils,
|
|
49
|
+
sanitizers,
|
|
62
50
|
visitors,
|
|
63
51
|
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { curry } = require('lodash/fp');
|
|
4
|
+
|
|
5
|
+
const pipeAsync = require('../pipe-async');
|
|
6
|
+
const traverseEntity = require('../traverse-entity');
|
|
7
|
+
|
|
8
|
+
const { removePassword, removePrivate } = require('./visitors');
|
|
9
|
+
|
|
10
|
+
const sanitizePasswords = curry((schema, entity) => {
|
|
11
|
+
return traverseEntity(removePassword, { schema }, entity);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
const sanitizePrivates = curry((schema, entity) => {
|
|
15
|
+
return traverseEntity(removePrivate, { schema }, entity);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
const defaultSanitizeOutput = curry((schema, entity) => {
|
|
19
|
+
return pipeAsync(sanitizePrivates(schema), sanitizePasswords(schema))(entity);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
module.exports = {
|
|
23
|
+
sanitizePasswords,
|
|
24
|
+
sanitizePrivates,
|
|
25
|
+
defaultSanitizeOutput,
|
|
26
|
+
};
|
|
@@ -16,7 +16,7 @@ module.exports = (allowedFields = null) => ({ key, path }, { remove }) => {
|
|
|
16
16
|
const containedPaths = getContainedPaths(path);
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
|
-
* Tells if the current path should be
|
|
19
|
+
* Tells if the current path should be kept or not based
|
|
20
20
|
* on the success of the check functions for any of the allowed paths.
|
|
21
21
|
*
|
|
22
22
|
* The check functions are defined as follow:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strapi/utils",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.16",
|
|
4
4
|
"description": "Shared utilities for the Strapi packages",
|
|
5
5
|
"homepage": "https://strapi.io",
|
|
6
6
|
"keywords": [
|
|
@@ -42,5 +42,5 @@
|
|
|
42
42
|
"npm": ">=6.0.0"
|
|
43
43
|
},
|
|
44
44
|
"license": "SEE LICENSE IN LICENSE",
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "71bdfa34637832e8e78a6cf1b57c8c6dbadf133d"
|
|
46
46
|
}
|