@strapi/utils 4.11.0-exp.9xg4-3qfm-9w8f.1 → 4.11.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/dist/async.d.ts +10 -0
- package/dist/async.js +33 -0
- package/dist/async.js.map +1 -0
- package/dist/code-generator.d.ts +2 -0
- package/dist/code-generator.js +11 -0
- package/dist/code-generator.js.map +1 -0
- package/dist/config.d.ts +8 -0
- package/dist/config.js +79 -0
- package/dist/config.js.map +1 -0
- package/dist/content-types.d.ts +60 -0
- package/dist/content-types.js +147 -0
- package/dist/content-types.js.map +1 -0
- package/dist/convert-query-params.d.ts +72 -0
- package/dist/convert-query-params.js +451 -0
- package/dist/convert-query-params.js.map +1 -0
- package/dist/env-helper.d.ts +18 -0
- package/dist/env-helper.js +84 -0
- package/dist/env-helper.js.map +1 -0
- package/dist/errors.d.ts +37 -0
- package/dist/errors.js +100 -0
- package/dist/errors.js.map +1 -0
- package/dist/file.d.ts +16 -0
- package/dist/file.js +54 -0
- package/dist/file.js.map +1 -0
- package/dist/format-yup-error.d.ts +10 -0
- package/dist/format-yup-error.js +17 -0
- package/dist/format-yup-error.js.map +1 -0
- package/dist/hooks.d.ts +92 -0
- package/dist/hooks.js +89 -0
- package/dist/hooks.js.map +1 -0
- package/dist/import-default.d.ts +1 -0
- package/dist/import-default.js +10 -0
- package/dist/import-default.js.map +1 -0
- package/dist/index.d.ts +200 -0
- package/dist/index.js +151 -0
- package/dist/index.js.map +1 -0
- package/dist/object-formatting.d.ts +3 -0
- package/dist/object-formatting.js +14 -0
- package/dist/object-formatting.js.map +1 -0
- package/dist/pagination.d.ts +14 -0
- package/dist/pagination.js +80 -0
- package/dist/pagination.js.map +1 -0
- package/dist/parse-multipart.d.ts +8 -0
- package/dist/parse-multipart.js +36 -0
- package/dist/parse-multipart.js.map +1 -0
- package/dist/parse-type.d.ts +21 -0
- package/dist/parse-type.js +97 -0
- package/dist/parse-type.js.map +1 -0
- package/dist/policy.d.ts +41 -0
- package/dist/policy.js +109 -0
- package/dist/policy.js.map +1 -0
- package/dist/print-value.d.ts +2 -0
- package/dist/print-value.js +50 -0
- package/dist/print-value.js.map +1 -0
- package/dist/provider-factory.d.ts +84 -0
- package/dist/provider-factory.js +88 -0
- package/dist/provider-factory.js.map +1 -0
- package/dist/relations.d.ts +10 -0
- package/dist/relations.js +23 -0
- package/dist/relations.js.map +1 -0
- package/dist/sanitize/index.d.ts +23 -0
- package/dist/sanitize/index.js +135 -0
- package/dist/sanitize/index.js.map +1 -0
- package/dist/sanitize/sanitizers.d.ts +10 -0
- package/dist/sanitize/sanitizers.js +106 -0
- package/dist/sanitize/sanitizers.js.map +1 -0
- package/dist/sanitize/visitors/allowed-fields.d.ts +3 -0
- package/dist/sanitize/visitors/allowed-fields.js +83 -0
- package/dist/sanitize/visitors/allowed-fields.js.map +1 -0
- package/dist/sanitize/visitors/index.d.ts +7 -0
- package/dist/sanitize/visitors/index.js +21 -0
- package/dist/sanitize/visitors/index.js.map +1 -0
- package/dist/sanitize/visitors/remove-dynamic-zones.d.ts +3 -0
- package/dist/sanitize/visitors/remove-dynamic-zones.js +10 -0
- package/dist/sanitize/visitors/remove-dynamic-zones.js.map +1 -0
- package/dist/sanitize/visitors/remove-morph-to-relations.d.ts +3 -0
- package/dist/sanitize/visitors/remove-morph-to-relations.js +10 -0
- package/dist/sanitize/visitors/remove-morph-to-relations.js.map +1 -0
- package/dist/sanitize/visitors/remove-password.d.ts +3 -0
- package/dist/sanitize/visitors/remove-password.js +9 -0
- package/dist/sanitize/visitors/remove-password.js.map +1 -0
- package/dist/sanitize/visitors/remove-private.d.ts +3 -0
- package/dist/sanitize/visitors/remove-private.js +14 -0
- package/dist/sanitize/visitors/remove-private.js.map +1 -0
- package/dist/sanitize/visitors/remove-restricted-relations.d.ts +3 -0
- package/dist/sanitize/visitors/remove-restricted-relations.js +88 -0
- package/dist/sanitize/visitors/remove-restricted-relations.js.map +1 -0
- package/dist/sanitize/visitors/restricted-fields.d.ts +3 -0
- package/dist/sanitize/visitors/restricted-fields.js +25 -0
- package/dist/sanitize/visitors/restricted-fields.js.map +1 -0
- package/dist/set-creator-fields.d.ts +9 -0
- package/dist/set-creator-fields.js +38 -0
- package/dist/set-creator-fields.js.map +1 -0
- package/dist/string-formatting.d.ts +16 -0
- package/dist/string-formatting.js +85 -0
- package/dist/string-formatting.js.map +1 -0
- package/dist/template-configuration.d.ts +5 -0
- package/dist/template-configuration.js +28 -0
- package/dist/template-configuration.js.map +1 -0
- package/dist/template.d.ts +9 -0
- package/dist/template.js +20 -0
- package/dist/template.js.map +1 -0
- package/dist/traverse/factory.d.ts +80 -0
- package/dist/traverse/factory.js +127 -0
- package/dist/traverse/factory.js.map +1 -0
- package/dist/traverse/index.d.ts +5 -0
- package/dist/traverse/index.js +17 -0
- package/dist/traverse/index.js.map +1 -0
- package/dist/traverse/query-fields.d.ts +3 -0
- package/dist/traverse/query-fields.js +35 -0
- package/dist/traverse/query-fields.js.map +1 -0
- package/dist/traverse/query-filters.d.ts +3 -0
- package/dist/traverse/query-filters.js +75 -0
- package/dist/traverse/query-filters.js.map +1 -0
- package/dist/traverse/query-populate.d.ts +3 -0
- package/dist/traverse/query-populate.js +144 -0
- package/dist/traverse/query-populate.js.map +1 -0
- package/dist/traverse/query-sort.d.ts +3 -0
- package/dist/traverse/query-sort.js +116 -0
- package/dist/traverse/query-sort.js.map +1 -0
- package/dist/traverse-entity.d.ts +33 -0
- package/dist/traverse-entity.js +134 -0
- package/dist/traverse-entity.js.map +1 -0
- package/dist/types.d.ts +66 -0
- package/dist/types.js +4 -0
- package/dist/types.js.map +1 -0
- package/dist/validators.d.ts +13 -0
- package/dist/validators.js +120 -0
- package/dist/validators.js.map +1 -0
- package/dist/webhook.d.ts +10 -0
- package/dist/webhook.js +14 -0
- package/dist/webhook.js.map +1 -0
- package/lib/content-types.js +5 -4
- package/package.json +2 -2
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const fp_1 = require("lodash/fp");
|
|
4
|
+
exports.default = (allowedFields = null) => ({ key, path: { attribute: path } }, { remove }) => {
|
|
5
|
+
// All fields are allowed
|
|
6
|
+
if (allowedFields === null) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
// Ignore invalid formats
|
|
10
|
+
if (!(0, fp_1.isArray)(allowedFields)) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
if ((0, fp_1.isNil)(path)) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const containedPaths = getContainedPaths(path);
|
|
17
|
+
/**
|
|
18
|
+
* Tells if the current path should be kept or not based
|
|
19
|
+
* on the success of the check functions for any of the allowed paths.
|
|
20
|
+
*
|
|
21
|
+
* The check functions are defined as follow:
|
|
22
|
+
*
|
|
23
|
+
* `containedPaths.includes(p)`
|
|
24
|
+
* @example
|
|
25
|
+
* ```js
|
|
26
|
+
* const path = 'foo.bar.field';
|
|
27
|
+
* const p = 'foo.bar';
|
|
28
|
+
* // it should match
|
|
29
|
+
*
|
|
30
|
+
* const path = 'foo.bar.field';
|
|
31
|
+
* const p = 'bar.foo';
|
|
32
|
+
* // it shouldn't match
|
|
33
|
+
*
|
|
34
|
+
* const path = 'foo.bar';
|
|
35
|
+
* const p = 'foo.bar.field';
|
|
36
|
+
* // it should match but isn't handled by this check
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* `p.startsWith(`${path}.`)`
|
|
40
|
+
* @example
|
|
41
|
+
* ```js
|
|
42
|
+
* const path = 'foo.bar';
|
|
43
|
+
* const p = 'foo.bar.field';
|
|
44
|
+
* // it should match
|
|
45
|
+
*
|
|
46
|
+
* const path = 'foo.bar.field';
|
|
47
|
+
* const p = 'bar.foo';
|
|
48
|
+
* // it shouldn't match
|
|
49
|
+
*
|
|
50
|
+
* const path = 'foo.bar.field';
|
|
51
|
+
* const p = 'foo.bar';
|
|
52
|
+
* // it should match but isn't handled by this check
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
const isPathAllowed = allowedFields.some((p) => containedPaths.includes(p) || p.startsWith(`${path}.`));
|
|
56
|
+
if (isPathAllowed) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
// Remove otherwise
|
|
60
|
+
remove(key);
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Retrieve the list of allowed paths based on the given path
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```js
|
|
67
|
+
* const containedPaths = getContainedPaths('foo');
|
|
68
|
+
* // ['foo']
|
|
69
|
+
*
|
|
70
|
+
* * const containedPaths = getContainedPaths('foo.bar');
|
|
71
|
+
* // ['foo', 'foo.bar']
|
|
72
|
+
*
|
|
73
|
+
* * const containedPaths = getContainedPaths('foo.bar.field');
|
|
74
|
+
* // ['foo', 'foo.bar', 'foo.bar.field']
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
const getContainedPaths = (path) => {
|
|
78
|
+
const parts = (0, fp_1.toPath)(path);
|
|
79
|
+
return parts.reduce((acc, value, index, list) => {
|
|
80
|
+
return [...acc, list.slice(0, index + 1).join('.')];
|
|
81
|
+
}, []);
|
|
82
|
+
};
|
|
83
|
+
//# sourceMappingURL=allowed-fields.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"allowed-fields.js","sourceRoot":"","sources":["../../../src/sanitize/visitors/allowed-fields.ts"],"names":[],"mappings":";;AAAA,kCAAmD;AAGnD,kBAAe,CAAC,gBAAiC,IAAI,EAAW,EAAE,CAChE,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;IACjD,yBAAyB;IACzB,IAAI,aAAa,KAAK,IAAI,EAAE;QAC1B,OAAO;KACR;IAED,yBAAyB;IACzB,IAAI,CAAC,IAAA,YAAO,EAAC,aAAa,CAAC,EAAE;QAC3B,OAAO;KACR;IAED,IAAI,IAAA,UAAK,EAAC,IAAI,CAAC,EAAE;QACf,OAAO;KACR;IAED,MAAM,cAAc,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAC;IAE/C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAqCG;IACH,MAAM,aAAa,GAAG,aAAa,CAAC,IAAI,CACtC,CAAC,CAAC,EAAE,EAAE,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,GAAG,IAAI,GAAG,CAAC,CAC9D,CAAC;IAEF,IAAI,aAAa,EAAE;QACjB,OAAO;KACR;IAED,mBAAmB;IACnB,MAAM,CAAC,GAAG,CAAC,CAAC;AACd,CAAC,CAAC;AAEJ;;;;;;;;;;;;;;GAcG;AACH,MAAM,iBAAiB,GAAG,CAAC,IAAY,EAAE,EAAE;IACzC,MAAM,KAAK,GAAG,IAAA,WAAM,EAAC,IAAI,CAAC,CAAC;IAE3B,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;QAC9C,OAAO,CAAC,GAAG,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IACtD,CAAC,EAAE,EAAc,CAAC,CAAC;AACrB,CAAC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { default as removePassword } from './remove-password';
|
|
2
|
+
export { default as removePrivate } from './remove-private';
|
|
3
|
+
export { default as removeRestrictedRelations } from './remove-restricted-relations';
|
|
4
|
+
export { default as removeMorphToRelations } from './remove-morph-to-relations';
|
|
5
|
+
export { default as removeDynamicZones } from './remove-dynamic-zones';
|
|
6
|
+
export { default as allowedFields } from './allowed-fields';
|
|
7
|
+
export { default as restrictedFields } from './restricted-fields';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.restrictedFields = exports.allowedFields = exports.removeDynamicZones = exports.removeMorphToRelations = exports.removeRestrictedRelations = exports.removePrivate = exports.removePassword = void 0;
|
|
7
|
+
var remove_password_1 = require("./remove-password");
|
|
8
|
+
Object.defineProperty(exports, "removePassword", { enumerable: true, get: function () { return __importDefault(remove_password_1).default; } });
|
|
9
|
+
var remove_private_1 = require("./remove-private");
|
|
10
|
+
Object.defineProperty(exports, "removePrivate", { enumerable: true, get: function () { return __importDefault(remove_private_1).default; } });
|
|
11
|
+
var remove_restricted_relations_1 = require("./remove-restricted-relations");
|
|
12
|
+
Object.defineProperty(exports, "removeRestrictedRelations", { enumerable: true, get: function () { return __importDefault(remove_restricted_relations_1).default; } });
|
|
13
|
+
var remove_morph_to_relations_1 = require("./remove-morph-to-relations");
|
|
14
|
+
Object.defineProperty(exports, "removeMorphToRelations", { enumerable: true, get: function () { return __importDefault(remove_morph_to_relations_1).default; } });
|
|
15
|
+
var remove_dynamic_zones_1 = require("./remove-dynamic-zones");
|
|
16
|
+
Object.defineProperty(exports, "removeDynamicZones", { enumerable: true, get: function () { return __importDefault(remove_dynamic_zones_1).default; } });
|
|
17
|
+
var allowed_fields_1 = require("./allowed-fields");
|
|
18
|
+
Object.defineProperty(exports, "allowedFields", { enumerable: true, get: function () { return __importDefault(allowed_fields_1).default; } });
|
|
19
|
+
var restricted_fields_1 = require("./restricted-fields");
|
|
20
|
+
Object.defineProperty(exports, "restrictedFields", { enumerable: true, get: function () { return __importDefault(restricted_fields_1).default; } });
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/sanitize/visitors/index.ts"],"names":[],"mappings":";;;;;;AAAA,qDAA8D;AAArD,kIAAA,OAAO,OAAkB;AAClC,mDAA4D;AAAnD,gIAAA,OAAO,OAAiB;AACjC,6EAAqF;AAA5E,yJAAA,OAAO,OAA6B;AAC7C,yEAAgF;AAAvE,oJAAA,OAAO,OAA0B;AAC1C,+DAAuE;AAA9D,2IAAA,OAAO,OAAsB;AACtC,mDAA4D;AAAnD,gIAAA,OAAO,OAAiB;AACjC,yDAAkE;AAAzD,sIAAA,OAAO,OAAoB"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const content_types_1 = require("../../content-types");
|
|
4
|
+
const visitor = ({ key, attribute }, { remove }) => {
|
|
5
|
+
if ((0, content_types_1.isDynamicZoneAttribute)(attribute)) {
|
|
6
|
+
remove(key);
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
exports.default = visitor;
|
|
10
|
+
//# sourceMappingURL=remove-dynamic-zones.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remove-dynamic-zones.js","sourceRoot":"","sources":["../../../src/sanitize/visitors/remove-dynamic-zones.ts"],"names":[],"mappings":";;AAAA,uDAA6D;AAG7D,MAAM,OAAO,GAAY,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;IAC1D,IAAI,IAAA,sCAAsB,EAAC,SAAS,CAAC,EAAE;QACrC,MAAM,CAAC,GAAG,CAAC,CAAC;KACb;AACH,CAAC,CAAC;AAEF,kBAAe,OAAO,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const content_types_1 = require("../../content-types");
|
|
4
|
+
const visitor = ({ key, attribute }, { remove }) => {
|
|
5
|
+
if ((0, content_types_1.isMorphToRelationalAttribute)(attribute)) {
|
|
6
|
+
remove(key);
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
exports.default = visitor;
|
|
10
|
+
//# sourceMappingURL=remove-morph-to-relations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remove-morph-to-relations.js","sourceRoot":"","sources":["../../../src/sanitize/visitors/remove-morph-to-relations.ts"],"names":[],"mappings":";;AAAA,uDAAmE;AAGnE,MAAM,OAAO,GAAY,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;IAC1D,IAAI,IAAA,4CAA4B,EAAC,SAAS,CAAC,EAAE;QAC3C,MAAM,CAAC,GAAG,CAAC,CAAC;KACb;AACH,CAAC,CAAC;AAEF,kBAAe,OAAO,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const visitor = ({ key, attribute }, { remove }) => {
|
|
4
|
+
if (attribute?.type === 'password') {
|
|
5
|
+
remove(key);
|
|
6
|
+
}
|
|
7
|
+
};
|
|
8
|
+
exports.default = visitor;
|
|
9
|
+
//# sourceMappingURL=remove-password.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remove-password.js","sourceRoot":"","sources":["../../../src/sanitize/visitors/remove-password.ts"],"names":[],"mappings":";;AAEA,MAAM,OAAO,GAAY,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;IAC1D,IAAI,SAAS,EAAE,IAAI,KAAK,UAAU,EAAE;QAClC,MAAM,CAAC,GAAG,CAAC,CAAC;KACb;AACH,CAAC,CAAC;AAEF,kBAAe,OAAO,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const content_types_1 = require("../../content-types");
|
|
4
|
+
const visitor = ({ schema, key, attribute }, { remove }) => {
|
|
5
|
+
if (!attribute) {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
const isPrivate = attribute.private === true || (0, content_types_1.isPrivateAttribute)(schema, key);
|
|
9
|
+
if (isPrivate) {
|
|
10
|
+
remove(key);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
exports.default = visitor;
|
|
14
|
+
//# sourceMappingURL=remove-private.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remove-private.js","sourceRoot":"","sources":["../../../src/sanitize/visitors/remove-private.ts"],"names":[],"mappings":";;AAAA,uDAAyD;AAGzD,MAAM,OAAO,GAAY,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;IAClE,IAAI,CAAC,SAAS,EAAE;QACd,OAAO;KACR;IAED,MAAM,SAAS,GAAG,SAAS,CAAC,OAAO,KAAK,IAAI,IAAI,IAAA,kCAAkB,EAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAEhF,IAAI,SAAS,EAAE;QACb,MAAM,CAAC,GAAG,CAAC,CAAC;KACb;AACH,CAAC,CAAC;AAEF,kBAAe,OAAO,CAAC"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
const contentTypeUtils = __importStar(require("../../content-types"));
|
|
27
|
+
const ACTIONS_TO_VERIFY = ['find'];
|
|
28
|
+
const { CREATED_BY_ATTRIBUTE, UPDATED_BY_ATTRIBUTE } = contentTypeUtils.constants;
|
|
29
|
+
exports.default = (auth) => async ({ data, key, attribute, schema }, { remove, set }) => {
|
|
30
|
+
if (!attribute) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const isRelation = attribute.type === 'relation';
|
|
34
|
+
if (!isRelation) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const handleMorphRelation = async () => {
|
|
38
|
+
const newMorphValue = [];
|
|
39
|
+
for (const element of data[key]) {
|
|
40
|
+
const scopes = ACTIONS_TO_VERIFY.map((action) => `${element.__type}.${action}`);
|
|
41
|
+
const isAllowed = await hasAccessToSomeScopes(scopes, auth);
|
|
42
|
+
if (isAllowed) {
|
|
43
|
+
newMorphValue.push(element);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
// If the new value is empty, remove the relation completely
|
|
47
|
+
if (newMorphValue.length === 0) {
|
|
48
|
+
remove(key);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
set(key, newMorphValue);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
const handleRegularRelation = async () => {
|
|
55
|
+
const scopes = ACTIONS_TO_VERIFY.map((action) => `${attribute.target}.${action}`);
|
|
56
|
+
const isAllowed = await hasAccessToSomeScopes(scopes, auth);
|
|
57
|
+
// If the authenticated user don't have access to any of the scopes, then remove the field
|
|
58
|
+
if (!isAllowed) {
|
|
59
|
+
remove(key);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
const isCreatorRelation = [CREATED_BY_ATTRIBUTE, UPDATED_BY_ATTRIBUTE].includes(key);
|
|
63
|
+
// Polymorphic relations
|
|
64
|
+
if (contentTypeUtils.isMorphToRelationalAttribute(attribute)) {
|
|
65
|
+
await handleMorphRelation();
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
// Creator relations
|
|
69
|
+
if (isCreatorRelation && schema.options.populateCreatorFields) {
|
|
70
|
+
// do nothing
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
// Regular relations
|
|
74
|
+
await handleRegularRelation();
|
|
75
|
+
};
|
|
76
|
+
const hasAccessToSomeScopes = async (scopes, auth) => {
|
|
77
|
+
for (const scope of scopes) {
|
|
78
|
+
try {
|
|
79
|
+
await strapi.auth.verify(auth, { scope });
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return false;
|
|
87
|
+
};
|
|
88
|
+
//# sourceMappingURL=remove-restricted-relations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remove-restricted-relations.js","sourceRoot":"","sources":["../../../src/sanitize/visitors/remove-restricted-relations.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sEAAwD;AAGxD,MAAM,iBAAiB,GAAG,CAAC,MAAM,CAAC,CAAC;AACnC,MAAM,EAAE,oBAAoB,EAAE,oBAAo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,0FAA0F;QAC1F,IAAI,CAAC,SAAS,EAAE;YACd,MAAM,CAAC,GAAG,CAAC,CAAC;SACb;IACH,CAAC,CAAC;IAEF,MAAM,iBAAiB,GAAG,CAAC,oBAAoB,EAAE,oBAAoB,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;IAErF,wBAAwB;IACxB,IAAI,gBAAgB,CAAC,4BAA4B,CAAC,SAAS,CAAC,EAAE;QAC5D,MAAM,mBAAmB,EAAE,CAAC;QAC5B,OAAO;KACR;IAED,oBAAoB;IACpB,IAAI,iBAAiB,IAAI,MAAM,CAAC,OAAO,CAAC,qBAAqB,EAAE;QAC7D,aAAa;QACb,OAAO;KACR;IAED,oBAAoB;IACpB,MAAM,qBAAqB,EAAE,CAAC;AAChC,CAAC,CAAC;AAEJ,MAAM,qBAAqB,GAAG,KAAK,EAAE,MAAgB,EAAE,IAAa,EAAE,EAAE;IACtE,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE;QAC1B,IAAI;YACF,MAAM,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;YAC1C,OAAO,IAAI,CAAC;SACb;QAAC,MAAM;YACN,SAAS;SACV;KACF;IAED,OAAO,KAAK,CAAC;AACf,CAAC,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const fp_1 = require("lodash/fp");
|
|
4
|
+
exports.default = (restrictedFields = null) => ({ key, path: { attribute: path } }, { remove }) => {
|
|
5
|
+
// Remove all fields
|
|
6
|
+
if (restrictedFields === null) {
|
|
7
|
+
remove(key);
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
// Ignore invalid formats
|
|
11
|
+
if (!(0, fp_1.isArray)(restrictedFields)) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
// Remove if an exact match was found
|
|
15
|
+
if (restrictedFields.includes(path)) {
|
|
16
|
+
remove(key);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
// Remove nested matches
|
|
20
|
+
const isRestrictedNested = restrictedFields.some((allowedPath) => path?.toString().startsWith(`${allowedPath}.`));
|
|
21
|
+
if (isRestrictedNested) {
|
|
22
|
+
remove(key);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=restricted-fields.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"restricted-fields.js","sourceRoot":"","sources":["../../../src/sanitize/visitors/restricted-fields.ts"],"names":[],"mappings":";;AAAA,kCAAoC;AAGpC,kBAAe,CAAC,mBAAoC,IAAI,EAAW,EAAE,CACnE,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;IACjD,oBAAoB;IACpB,IAAI,gBAAgB,KAAK,IAAI,EAAE;QAC7B,MAAM,CAAC,GAAG,CAAC,CAAC;QACZ,OAAO;KACR;IAED,yBAAyB;IACzB,IAAI,CAAC,IAAA,YAAO,EAAC,gBAAgB,CAAC,EAAE;QAC9B,OAAO;KACR;IAED,qCAAqC;IACrC,IAAI,gBAAgB,CAAC,QAAQ,CAAC,IAAc,CAAC,EAAE;QAC7C,MAAM,CAAC,GAAG,CAAC,CAAC;QACZ,OAAO;KACR;IAED,wBAAwB;IACxB,MAAM,kBAAkB,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,EAAE,CAC/D,IAAI,EAAE,QAAQ,EAAE,CAAC,UAAU,CAAC,GAAG,WAAW,GAAG,CAAC,CAC/C,CAAC;IACF,IAAI,kBAAkB,EAAE;QACtB,MAAM,CAAC,GAAG,CAAC,CAAC;KACb;AACH,CAAC,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
const fp_1 = require("lodash/fp");
|
|
27
|
+
const contentTypes = __importStar(require("./content-types"));
|
|
28
|
+
const { CREATED_BY_ATTRIBUTE, UPDATED_BY_ATTRIBUTE } = contentTypes.constants;
|
|
29
|
+
exports.default = ({ user, isEdition = false }) => (data) => {
|
|
30
|
+
if (isEdition) {
|
|
31
|
+
return (0, fp_1.assoc)(UPDATED_BY_ATTRIBUTE, user.id, data);
|
|
32
|
+
}
|
|
33
|
+
return (0, fp_1.assign)(data, {
|
|
34
|
+
[CREATED_BY_ATTRIBUTE]: user.id,
|
|
35
|
+
[UPDATED_BY_ATTRIBUTE]: user.id,
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=set-creator-fields.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"set-creator-fields.js","sourceRoot":"","sources":["../src/set-creator-fields.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kCAA0C;AAC1C,8DAAgD;AAEhD,MAAM,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,GAAG,YAAY,CAAC,SAAS,CAAC;AAW9E,kBAAe,CAAC,EAAE,IAAI,EAAE,SAAS,GAAG,KAAK,EAAW,EAAE,EAAE,CACtD,CAAC,IAAY,EAAE,EAAE;IACf,IAAI,SAAS,EAAE;QACb,OAAO,IAAA,UAAK,EAAC,oBAAoB,EAAE,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;KACnD;IAED,OAAO,IAAA,WAAM,EAAC,IAAI,EAAE;QAClB,CAAC,oBAAoB,CAAC,EAAE,IAAI,CAAC,EAAE;QAC/B,CAAC,oBAAoB,CAAC,EAAE,IAAI,CAAC,EAAE;KAChC,CAAC,CAAC;AACL,CAAC,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
declare const nameToSlug: (name: string, options?: {
|
|
2
|
+
separator: string;
|
|
3
|
+
}) => string;
|
|
4
|
+
declare const nameToCollectionName: (name: string) => string;
|
|
5
|
+
declare const toRegressedEnumValue: (value: string) => string;
|
|
6
|
+
declare const getCommonBeginning: (...strings: string[]) => string;
|
|
7
|
+
declare const getCommonPath: (...paths: string[]) => string;
|
|
8
|
+
declare const escapeQuery: (query: string, charsToEscape: string, escapeChar?: string) => string;
|
|
9
|
+
declare const stringIncludes: (arr: unknown[], val: unknown) => boolean;
|
|
10
|
+
declare const stringEquals: (a: unknown, b: unknown) => boolean;
|
|
11
|
+
declare const isCamelCase: (value: string) => boolean;
|
|
12
|
+
declare const isKebabCase: (value: string) => boolean;
|
|
13
|
+
declare const startsWithANumber: (value: string) => boolean;
|
|
14
|
+
declare const joinBy: (joint: string, ...args: string[]) => string;
|
|
15
|
+
declare const toKebabCase: (value: string) => string;
|
|
16
|
+
export { nameToSlug, nameToCollectionName, getCommonBeginning, getCommonPath, escapeQuery, stringIncludes, stringEquals, isCamelCase, isKebabCase, toKebabCase, toRegressedEnumValue, startsWithANumber, joinBy, };
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.joinBy = exports.startsWithANumber = exports.toRegressedEnumValue = exports.toKebabCase = exports.isKebabCase = exports.isCamelCase = exports.stringEquals = exports.stringIncludes = exports.escapeQuery = exports.getCommonPath = exports.getCommonBeginning = exports.nameToCollectionName = exports.nameToSlug = void 0;
|
|
30
|
+
const lodash_1 = __importStar(require("lodash"));
|
|
31
|
+
const fp_1 = require("lodash/fp");
|
|
32
|
+
const slugify_1 = __importDefault(require("@sindresorhus/slugify"));
|
|
33
|
+
const nameToSlug = (name, options = { separator: '-' }) => (0, slugify_1.default)(name, options);
|
|
34
|
+
exports.nameToSlug = nameToSlug;
|
|
35
|
+
const nameToCollectionName = (name) => (0, slugify_1.default)(name, { separator: '_' });
|
|
36
|
+
exports.nameToCollectionName = nameToCollectionName;
|
|
37
|
+
const toRegressedEnumValue = (value) => (0, slugify_1.default)(value, {
|
|
38
|
+
decamelize: false,
|
|
39
|
+
lowercase: false,
|
|
40
|
+
separator: '_',
|
|
41
|
+
});
|
|
42
|
+
exports.toRegressedEnumValue = toRegressedEnumValue;
|
|
43
|
+
const getCommonBeginning = (...strings) => lodash_1.default.takeWhile(strings[0], (char, index) => strings.every((string) => string[index] === char)).join('');
|
|
44
|
+
exports.getCommonBeginning = getCommonBeginning;
|
|
45
|
+
const getCommonPath = (...paths) => {
|
|
46
|
+
const [segments, ...otherSegments] = paths.map((it) => lodash_1.default.split(it, '/'));
|
|
47
|
+
return lodash_1.default.join(lodash_1.default.takeWhile(segments, (str, index) => otherSegments.every((it) => it[index] === str)), '/');
|
|
48
|
+
};
|
|
49
|
+
exports.getCommonPath = getCommonPath;
|
|
50
|
+
const escapeQuery = (query, charsToEscape, escapeChar = '\\') => {
|
|
51
|
+
return query
|
|
52
|
+
.split('')
|
|
53
|
+
.reduce((escapedQuery, char) => charsToEscape.includes(char)
|
|
54
|
+
? `${escapedQuery}${escapeChar}${char}`
|
|
55
|
+
: `${escapedQuery}${char}`, '');
|
|
56
|
+
};
|
|
57
|
+
exports.escapeQuery = escapeQuery;
|
|
58
|
+
const stringIncludes = (arr, val) => arr.map(String).includes(String(val));
|
|
59
|
+
exports.stringIncludes = stringIncludes;
|
|
60
|
+
const stringEquals = (a, b) => String(a) === String(b);
|
|
61
|
+
exports.stringEquals = stringEquals;
|
|
62
|
+
const isCamelCase = (value) => /^[a-z][a-zA-Z0-9]+$/.test(value);
|
|
63
|
+
exports.isCamelCase = isCamelCase;
|
|
64
|
+
const isKebabCase = (value) => /^([a-z][a-z0-9]*)(-[a-z0-9]+)*$/.test(value);
|
|
65
|
+
exports.isKebabCase = isKebabCase;
|
|
66
|
+
const startsWithANumber = (value) => /^[0-9]/.test(value);
|
|
67
|
+
exports.startsWithANumber = startsWithANumber;
|
|
68
|
+
const joinBy = (joint, ...args) => {
|
|
69
|
+
const trim = (0, fp_1.trimChars)(joint);
|
|
70
|
+
const trimEnd = (0, fp_1.trimCharsEnd)(joint);
|
|
71
|
+
const trimStart = (0, fp_1.trimCharsStart)(joint);
|
|
72
|
+
return args.reduce((url, path, index) => {
|
|
73
|
+
if (args.length === 1)
|
|
74
|
+
return path;
|
|
75
|
+
if (index === 0)
|
|
76
|
+
return trimEnd(path);
|
|
77
|
+
if (index === args.length - 1)
|
|
78
|
+
return url + joint + trimStart(path);
|
|
79
|
+
return url + joint + trim(path);
|
|
80
|
+
}, '');
|
|
81
|
+
};
|
|
82
|
+
exports.joinBy = joinBy;
|
|
83
|
+
const toKebabCase = (value) => (0, lodash_1.kebabCase)(value);
|
|
84
|
+
exports.toKebabCase = toKebabCase;
|
|
85
|
+
//# sourceMappingURL=string-formatting.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string-formatting.js","sourceRoot":"","sources":["../src/string-formatting.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAAsC;AACtC,kCAAoE;AACpE,oEAA4C;AAE5C,MAAM,UAAU,GAAG,CAAC,IAAY,EAAE,OAAO,GAAG,EAAE,SAAS,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,IAAA,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KAAK,CAAC,CAAC;IACpC,MAAM,SAAS,GAAG,IAAA,mBAAc,EAAC,KAAK,CAAC,CAAC;IAExC,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE;QACtC,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,IAAI,CAAC;QACnC,IAAI,KAAK,KAAK,CAAC;YAAE,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC;QACtC,IAAI,KAAK,KAAK,IAAI,CAAC,MAAM,GAAG,CAAC;YAAE,OAAO,GAAG,GAAG,KAAK,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;QACpE,OAAO,GAAG,GAAG,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC,EAAE,EAAE,CAAC,CAAC;AACT,CAAC,CAAC;AAiBA,wBAAM;AAfR,MAAM,WAAW,GAAG,CAAC,KAAa,EAAE,EAAE,CAAC,IAAA,kBAAS,EAAC,KAAK,CAAC,CAAC;AAYtD,kCAAW"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const lodash_1 = require("lodash");
|
|
3
|
+
const regex = /\$\{[^()]*\}/g;
|
|
4
|
+
const excludeConfigPaths = ['info.scripts'];
|
|
5
|
+
/**
|
|
6
|
+
* Allow dynamic config values through the native ES6 template string function.
|
|
7
|
+
*/
|
|
8
|
+
const templateConfiguration = (obj, configPath = '') => {
|
|
9
|
+
// Allow values which looks like such as an ES6 literal string without parenthesis inside (aka function call).
|
|
10
|
+
// Exclude config with conflicting syntax (e.g. npm scripts).
|
|
11
|
+
return Object.keys(obj).reduce((acc, key) => {
|
|
12
|
+
if ((0, lodash_1.isPlainObject)(obj[key]) && !(0, lodash_1.isString)(obj[key])) {
|
|
13
|
+
acc[key] = templateConfiguration(obj[key], `${configPath}.${key}`);
|
|
14
|
+
}
|
|
15
|
+
else if ((0, lodash_1.isString)(obj[key]) &&
|
|
16
|
+
!excludeConfigPaths.includes(configPath.substr(1)) &&
|
|
17
|
+
obj[key].match(regex) !== null) {
|
|
18
|
+
// eslint-disable-next-line prefer-template, no-eval
|
|
19
|
+
acc[key] = eval('`' + obj[key] + '`');
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
acc[key] = obj[key];
|
|
23
|
+
}
|
|
24
|
+
return acc;
|
|
25
|
+
}, {});
|
|
26
|
+
};
|
|
27
|
+
module.exports = templateConfiguration;
|
|
28
|
+
//# sourceMappingURL=template-configuration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"template-configuration.js","sourceRoot":"","sources":["../src/template-configuration.ts"],"names":[],"mappings":";AAAA,mCAAiD;AAEjD,MAAM,KAAK,GAAG,eAAe,CAAC;AAC9B,MAAM,kBAAkB,GAAG,CAAC,cAAc,CAAC,CAAC;AAE5C;;GAEG;AACH,MAAM,qBAAqB,GAAG,CAAC,GAAwB,EAAE,UAAU,GAAG,EAAE,EAAE,EAAE;IAC1E,8GAA8G;IAC9G,6DAA6D;IAC7D,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;QAC1C,IAAI,IAAA,sBAAa,EAAC,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAA,iBAAQ,EAAC,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE;YAClD,GAAG,CAAC,GAAG,CAAC,GAAG,qBAAqB,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,GAAG,UAAU,IAAI,GAAG,EAAE,CAAC,CAAC;SACpE;aAAM,IACL,IAAA,iBAAQ,EAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAClB,CAAC,kBAAkB,CAAC,QAAQ,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;YAClD,GAAG,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,IAAI,EAC9B;YACA,oDAAoD;YACpD,GAAG,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC;SACvC;aAAM;YACL,GAAG,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;SACrB;QAED,OAAO,GAAG,CAAC;IACb,CAAC,EAAE,EAAyB,CAAC,CAAC;AAChC,CAAC,CAAC;AAEF,iBAAS,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create a strict interpolation RegExp based on the given variables' name
|
|
3
|
+
*/
|
|
4
|
+
declare const createStrictInterpolationRegExp: (allowedVariableNames: string[], flags: string) => RegExp;
|
|
5
|
+
/**
|
|
6
|
+
* Create a loose interpolation RegExp to match as many groups as possible
|
|
7
|
+
*/
|
|
8
|
+
declare const createLooseInterpolationRegExp: (flags: string) => RegExp;
|
|
9
|
+
export { createStrictInterpolationRegExp, createLooseInterpolationRegExp };
|
package/dist/template.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createLooseInterpolationRegExp = exports.createStrictInterpolationRegExp = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Create a strict interpolation RegExp based on the given variables' name
|
|
6
|
+
*/
|
|
7
|
+
const createStrictInterpolationRegExp = (allowedVariableNames, flags) => {
|
|
8
|
+
const oneOfVariables = allowedVariableNames.join('|');
|
|
9
|
+
// 1. We need to match the delimiters: <%= ... %>
|
|
10
|
+
// 2. We accept any number of whitespaces characters before and/or after the variable name: \s* ... \s*
|
|
11
|
+
// 3. We only accept values from the variable list as interpolation variables' name: : (${oneOfVariables})
|
|
12
|
+
return new RegExp(`<%=\\s*(${oneOfVariables})\\s*%>`, flags);
|
|
13
|
+
};
|
|
14
|
+
exports.createStrictInterpolationRegExp = createStrictInterpolationRegExp;
|
|
15
|
+
/**
|
|
16
|
+
* Create a loose interpolation RegExp to match as many groups as possible
|
|
17
|
+
*/
|
|
18
|
+
const createLooseInterpolationRegExp = (flags) => new RegExp(/<%=([\s\S]+?)%>/, flags);
|
|
19
|
+
exports.createLooseInterpolationRegExp = createLooseInterpolationRegExp;
|
|
20
|
+
//# sourceMappingURL=template.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"template.js","sourceRoot":"","sources":["../src/template.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,MAAM,+BAA+B,GAAG,CAAC,oBAA8B,EAAE,KAAa,EAAE,EAAE;IACxF,MAAM,cAAc,GAAG,oBAAoB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAEtD,iDAAiD;IACjD,uGAAuG;IACvG,0GAA0G;IAC1G,OAAO,IAAI,MAAM,CAAC,WAAW,cAAc,SAAS,EAAE,KAAK,CAAC,CAAC;AAC/D,CAAC,CAAC;AAOO,0EAA+B;AALxC;;GAEG;AACH,MAAM,8BAA8B,GAAG,CAAC,KAAa,EAAE,EAAE,CAAC,IAAI,MAAM,CAAC,iBAAiB,EAAE,KAAK,CAAC,CAAC;AAErD,wEAA8B"}
|