feat(core): add calculated fields and gated JavaScript evaluation#73
Open
lattln wants to merge 3 commits into
Open
feat(core): add calculated fields and gated JavaScript evaluation#73lattln wants to merge 3 commits into
lattln wants to merge 3 commits into
Conversation
Add JavaScript-based field calculations and rule conditions behind a two-layer opt-in security model. * Add `calculation` support to standard field definitions * Recalculate calculated fields when dependent responses change * Add JavaScript expressions as a supported condition type * Require both the schema and host application to enable JavaScript execution * Propagate JavaScript permissions through rules, effects, and validation * Keep display fields presentational by removing response-oriented properties * Add builder controls for calculations and JavaScript conditions * Pass JavaScript permissions through the renderer initialization flow * Update adapters for the revised field and condition types * Add dangerous JavaScript documentation and calculation test schemas * Split field-type documentation into individual pages
Collaborator
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This pull request adds JavaScript-based field calculations and JavaScript rule conditions to eSheet.
Calculated fields automatically update when questionnaire responses change. JavaScript execution is protected by a two-layer opt-in model. The schema must explicitly enable dangerous JavaScript, and the host application must separately allow it. If either setting is disabled, calculations and JavaScript conditions are not evaluated.
This change also separates display fields from standard response fields so presentational content cannot define questions, validation requirements, or calculations.
What Changed
calculationproperty to standard field definitionsjsas a supported rule condition typeHow to Test
Start the eSheet development environment.
Load a schema that includes:
dangerouslyAllowJS: truecalculationexpressionconditionType: "js"Enable JavaScript execution through the builder or renderer host configuration.
Change a response referenced by the calculation.
Verify the calculated field updates with the expected value.
Change responses referenced by the JavaScript condition.
Verify the associated rule effect is applied correctly.
Disable JavaScript permission at the host level.
Verify calculations and JavaScript conditions no longer execute.
Re-enable host permission and remove
dangerouslyAllowJSfrom the schema.Verify JavaScript execution remains disabled.
Add or render a display field.
Verify display fields remain presentational and do not support questions, required validation, responses, or calculations.
Run the existing test, lint, type-check, and build commands for the monorepo.
Security Considerations
JavaScript execution requires both of the following:
dangerouslyAllowJS: trueNeither setting enables JavaScript independently. Schemas that use this feature must be treated as trusted code because expressions are evaluated at runtime.
Breaking Changes
Display fields no longer inherit from the standard base field definition. Properties intended for response-based fields, including
question,required, andcalculation, are no longer supported on display fields.No breaking changes are expected for standard questionnaire fields that do not rely on the previous display field type structure.