MCPcopy Create free account
hub / github.com/parse-community/parse-dashboard / getValidScripts

Function getValidScripts

src/lib/ScriptUtils.js:17–53  ·  view source on GitHub ↗
(scripts, className, field)

Source from the content-addressed store, hash-verified

15 * @returns {Object} - { validScripts: Array, validator: Function|null }
16 */
17export function getValidScripts(scripts, className, field) {
18 let validator = null;
19 const validScripts = (scripts || []).filter(script => {
20 if (script.classes?.includes(className)) {
21 return true;
22 }
23 for (const scriptClass of script?.classes || []) {
24 if (scriptClass?.name !== className) {
25 continue;
26 }
27 const fields = scriptClass?.fields || [];
28 if (scriptClass?.fields.includes(field) || scriptClass?.fields.includes('*')) {
29 return true;
30 }
31 for (const currentField of fields) {
32 if (Object.prototype.toString.call(currentField) === '[object Object]') {
33 if (currentField.name === field) {
34 if (typeof currentField.validator === 'string') {
35 // SAFETY: eval() is used here on validator strings from trusted admin-controlled
36 // dashboard configuration only (not user input). These validators are used solely
37 // for UI validation logic to enable/disable script menu items. This is an accepted
38 // tradeoff in this trusted admin context. If requirements change, consider replacing
39 // with Function constructor or a safer expression parser.
40 validator = eval(currentField.validator);
41 } else {
42 validator = currentField.validator;
43 }
44 return true;
45 }
46 }
47 }
48 }
49 return false;
50 });
51
52 return { validScripts, validator };
53}
54
55/**
56 * Checks if a script response is a ScriptResponse with a form definition.

Callers 2

Calls

no outgoing calls

Tested by

no test coverage detected