* Validates parameters on the client side before sending to the execute endpoint
(
params: Record<string, any>,
schema: {
type: string
properties: Record<string, any>
required?: string[]
}
)
| 1924 | * Validates parameters on the client side before sending to the execute endpoint |
| 1925 | */ |
| 1926 | function validateClientSideParams( |
| 1927 | params: Record<string, any>, |
| 1928 | schema: { |
| 1929 | type: string |
| 1930 | properties: Record<string, any> |
| 1931 | required?: string[] |
| 1932 | } |
| 1933 | ) { |
| 1934 | if (!schema || schema.type !== 'object') { |
| 1935 | throw new Error('Invalid schema format') |
| 1936 | } |
| 1937 | |
| 1938 | // Internal parameters that should be excluded from validation |
| 1939 | const internalParamSet = new Set([ |
| 1940 | '_context', |
| 1941 | '_toolSchema', |
| 1942 | 'workflowId', |
| 1943 | 'envVars', |
| 1944 | 'workflowVariables', |
| 1945 | 'blockData', |
| 1946 | 'blockNameMapping', |
| 1947 | ]) |
| 1948 | |
| 1949 | // Check required parameters |
| 1950 | if (schema.required) { |
| 1951 | for (const requiredParam of schema.required) { |
| 1952 | if (!(requiredParam in params)) { |
| 1953 | throw new Error(`Required parameter missing: ${requiredParam}`) |
| 1954 | } |
| 1955 | } |
| 1956 | } |
| 1957 | |
| 1958 | // Check parameter types (basic validation) |
| 1959 | for (const [paramName, paramValue] of Object.entries(params)) { |
| 1960 | // Skip validation for internal parameters |
| 1961 | if (internalParamSet.has(paramName)) { |
| 1962 | continue |
| 1963 | } |
| 1964 | |
| 1965 | const paramSchema = schema.properties[paramName] |
| 1966 | if (!paramSchema) { |
| 1967 | throw new Error(`Unknown parameter: ${paramName}`) |
| 1968 | } |
| 1969 | |
| 1970 | // Basic type checking |
| 1971 | const type = paramSchema.type |
| 1972 | if (type === 'string' && typeof paramValue !== 'string') { |
| 1973 | throw new Error(`Parameter ${paramName} should be a string`) |
| 1974 | } |
| 1975 | if (type === 'number' && typeof paramValue !== 'number') { |
| 1976 | throw new Error(`Parameter ${paramName} should be a number`) |
| 1977 | } |
| 1978 | if (type === 'boolean' && typeof paramValue !== 'boolean') { |
| 1979 | throw new Error(`Parameter ${paramName} should be a boolean`) |
| 1980 | } |
| 1981 | if (type === 'array' && !Array.isArray(paramValue)) { |
| 1982 | throw new Error(`Parameter ${paramName} should be an array`) |
| 1983 | } |
no outgoing calls
no test coverage detected