@strapi/utils 4.6.0-beta.0 → 4.6.0-beta.2
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/errors.js +17 -7
- package/lib/index.js +4 -1
- package/lib/object-formatting.js +6 -0
- package/lib/template.js +28 -0
- package/package.json +3 -3
package/lib/errors.js
CHANGED
|
@@ -55,19 +55,28 @@ class ForbiddenError extends ApplicationError {
|
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
class
|
|
58
|
+
class UnauthorizedError extends ApplicationError {
|
|
59
59
|
constructor(message, details) {
|
|
60
60
|
super(message, details);
|
|
61
|
-
this.name = '
|
|
62
|
-
this.message = message || '
|
|
61
|
+
this.name = 'UnauthorizedError';
|
|
62
|
+
this.message = message || 'Unauthorized';
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
class
|
|
66
|
+
class RateLimitError extends ApplicationError {
|
|
67
67
|
constructor(message, details) {
|
|
68
68
|
super(message, details);
|
|
69
|
-
this.name = '
|
|
70
|
-
this.message = message || '
|
|
69
|
+
this.name = 'RateLimitError';
|
|
70
|
+
this.message = message || 'Too many requests, please try again later.';
|
|
71
|
+
this.details = details || {};
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
class PayloadTooLargeError extends ApplicationError {
|
|
76
|
+
constructor(message, details) {
|
|
77
|
+
super(message, details);
|
|
78
|
+
this.name = 'PayloadTooLargeError';
|
|
79
|
+
this.message = message || 'Entity too large';
|
|
71
80
|
}
|
|
72
81
|
}
|
|
73
82
|
|
|
@@ -88,7 +97,8 @@ module.exports = {
|
|
|
88
97
|
PaginationError,
|
|
89
98
|
NotFoundError,
|
|
90
99
|
ForbiddenError,
|
|
91
|
-
PayloadTooLargeError,
|
|
92
100
|
UnauthorizedError,
|
|
101
|
+
RateLimitError,
|
|
102
|
+
PayloadTooLargeError,
|
|
93
103
|
PolicyError,
|
|
94
104
|
};
|
package/lib/index.js
CHANGED
|
@@ -24,7 +24,7 @@ const {
|
|
|
24
24
|
joinBy,
|
|
25
25
|
toKebabCase,
|
|
26
26
|
} = require('./string-formatting');
|
|
27
|
-
const { removeUndefined } = require('./object-formatting');
|
|
27
|
+
const { removeUndefined, keysDeep } = require('./object-formatting');
|
|
28
28
|
const { getConfigUrls, getAbsoluteAdminUrl, getAbsoluteServerUrl } = require('./config');
|
|
29
29
|
const { generateTimestampCode } = require('./code-generator');
|
|
30
30
|
const contentTypes = require('./content-types');
|
|
@@ -40,6 +40,7 @@ const traverseEntity = require('./traverse-entity');
|
|
|
40
40
|
const pipeAsync = require('./pipe-async');
|
|
41
41
|
const convertQueryParams = require('./convert-query-params');
|
|
42
42
|
const importDefault = require('./import-default');
|
|
43
|
+
const template = require('./template');
|
|
43
44
|
|
|
44
45
|
module.exports = {
|
|
45
46
|
yup,
|
|
@@ -61,11 +62,13 @@ module.exports = {
|
|
|
61
62
|
getConfigUrls,
|
|
62
63
|
escapeQuery,
|
|
63
64
|
removeUndefined,
|
|
65
|
+
keysDeep,
|
|
64
66
|
getAbsoluteAdminUrl,
|
|
65
67
|
getAbsoluteServerUrl,
|
|
66
68
|
generateTimestampCode,
|
|
67
69
|
stringIncludes,
|
|
68
70
|
stringEquals,
|
|
71
|
+
template,
|
|
69
72
|
isKebabCase,
|
|
70
73
|
isCamelCase,
|
|
71
74
|
toKebabCase,
|
package/lib/object-formatting.js
CHANGED
|
@@ -4,6 +4,12 @@ const _ = require('lodash');
|
|
|
4
4
|
|
|
5
5
|
const removeUndefined = (obj) => _.pickBy(obj, (value) => typeof value !== 'undefined');
|
|
6
6
|
|
|
7
|
+
const keysDeep = (obj, path = []) =>
|
|
8
|
+
!_.isObject(obj)
|
|
9
|
+
? path.join('.')
|
|
10
|
+
: _.reduce(obj, (acc, next, key) => _.concat(acc, keysDeep(next, [...path, key])), []);
|
|
11
|
+
|
|
7
12
|
module.exports = {
|
|
8
13
|
removeUndefined,
|
|
14
|
+
keysDeep,
|
|
9
15
|
};
|
package/lib/template.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Create a strict interpolation RegExp based on the given variables' name
|
|
5
|
+
*
|
|
6
|
+
* @param {string[]} allowedVariableNames - The list of allowed variables
|
|
7
|
+
* @param {string} [flags] - The RegExp flags
|
|
8
|
+
*/
|
|
9
|
+
const createStrictInterpolationRegExp = (allowedVariableNames, flags) => {
|
|
10
|
+
const oneOfVariables = allowedVariableNames.join('|');
|
|
11
|
+
|
|
12
|
+
// 1. We need to match the delimiters: <%= ... %>
|
|
13
|
+
// 2. We accept any number of whitespaces characters before and/or after the variable name: \s* ... \s*
|
|
14
|
+
// 3. We only accept values from the variable list as interpolation variables' name: : (${oneOfVariables})
|
|
15
|
+
return new RegExp(`<%=\\s*(${oneOfVariables})\\s*%>`, flags);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Create a loose interpolation RegExp to match as many groups as possible
|
|
20
|
+
*
|
|
21
|
+
* @param {string} [flags] - The RegExp flags
|
|
22
|
+
*/
|
|
23
|
+
const createLooseInterpolationRegExp = (flags) => new RegExp(/<%=([\s\S]+?)%>/, flags);
|
|
24
|
+
|
|
25
|
+
module.exports = {
|
|
26
|
+
createStrictInterpolationRegExp,
|
|
27
|
+
createLooseInterpolationRegExp,
|
|
28
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strapi/utils",
|
|
3
|
-
"version": "4.6.0-beta.
|
|
3
|
+
"version": "4.6.0-beta.2",
|
|
4
4
|
"description": "Shared utilities for the Strapi packages",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"strapi",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@sindresorhus/slugify": "1.1.0",
|
|
39
|
-
"date-fns": "2.29.
|
|
39
|
+
"date-fns": "2.29.3",
|
|
40
40
|
"http-errors": "1.8.1",
|
|
41
41
|
"lodash": "4.17.21",
|
|
42
42
|
"yup": "0.32.9"
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
"node": ">=14.19.1 <=18.x.x",
|
|
46
46
|
"npm": ">=6.0.0"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "b852090f931cd21868c4016f24db2f9fdfc7a7ab"
|
|
49
49
|
}
|