Automatically applies server-side validation rules to records during the data import process using reusable JavaScript functions defined at the App level.
storedConstraint()
function itself does not accept any configuration parameters. The plugin’s behavior is configured entirely within the Flatfile platform.
Configuration is managed in two places in Flatfile:
(value, key, { record }) => { if (!/\S+@\S+\.\S+/.test(value)) { record.addError(key, 'Invalid email format.') } }
validator
(string): The name of the App-level constraint to apply (e.g., “is-valid-email”)config
(object, optional): An arbitrary configuration object that gets passed to your validation function. This allows you to make a single stored constraint adaptable to different contextstype: 'stored'
constraint. When such constraints are present, the plugin will automatically trigger on every data submission (commit:created
event) for all sheets and execute the corresponding validation logic.
deps
object containing helpful libraries. This example shows a constraint using the validator
library to check for a valid email format.
storedConstraint()
plugin is registered in your listenertype: 'stored'
validator
name in the Sheet constraint exactly matches the name of a Stored Constraint defined in your Appeval()
to execute the function strings stored in your App constraints. This means the constraint logic is executed dynamically. Ensure that only trusted administrators can create or edit stored constraint functions to avoid security risks.commit:created
event, which runs server-side after a user submits their data.try...catch
block around the execution of each constraint. If a constraint function throws an unhandled exception, the error is logged to the server-side console, and processing continues with the next record or field.record.addError(fieldKey, 'Your error message')
. The plugin does not automatically convert thrown exceptions into record errors.