Skip to content

feat: form actions can be written in typescript - #164

Draft
romain-pm wants to merge 1 commit into
mainfrom
feat/ts-form-actions
Draft

feat: form actions can be written in typescript#164
romain-pm wants to merge 1 commit into
mainfrom
feat/ts-form-actions

Conversation

@romain-pm

Copy link
Copy Markdown
Contributor

Summary

Form actions can now be written in TypeScript. The three built-in email/forward actions are converted to TS implementations in formidable-elements; save-to-JCR stays in Java. Existing forms and action configurations keep working unchanged.

Why

Formidable's action SPI was Java/OSGi-only, while the rest of the module family is moving to JavaScript modules. With the JSServerExtensionInvoker SDK landing in javascript-modules-engine 1.3.0, consumer modules can define their own JS extension types — this PR uses it so site developers (and Formidable itself) can author actions in TypeScript without a Java bundle.

Changes

  • JS dispatch bridge: new JsFormActionDispatcher consuming the formidable-form-action registry type (keyed by node type); FormSubmissionPipeline falls back to it when no Java FormAction matches. Java handlers win on conflict; no handler at all still yields FMDB-008 with progress counters.
  • Graceful degradation: the SDK reference is optional end-to-end (optional DS reference + resolution:=optional manifest import) — on a pre-1.3.0 engine, formidable deploys and Java actions keep working.
  • Security stays in Java: new exported FormActionSupport service (SSRF-checked forwardSubmission — target URL never exposed to JS —, capped buildEmailAttachments, upload-size accessor).
  • TS actions + wrapper: registerFormAction wrapper ({ok, status, message} wire contract, Java FormActionException statuses preserved) and TS ports of emailNotification, emailContent, forward in formidable-elements/src/server/; TemplateInterpolator/FieldEscaper logic ported with vitest coverage.
  • CND ownership: the 3 action node types (+icons, +en/fr labels) move to formidable-elements, next to their handlers (see updated docs/cnd-module-ownership.md); fmdbmix:formAction and fmdb:save2jcrAction stay in the engine.
  • Samples & tests: raw-contract TS sample actions in formidable-test-module-samples-tsx, new Cypress spec (tests/cypress/e2e/actions/70-ts-form-actions.cy.ts), Mailpit added to the e2e docker-compose, new/retargeted engine unit tests.

Validation

  • mvn clean install green across all 8 modules (engine: 155 unit tests; elements: tsc + eslint + 14 vitest)
  • Server bundles verified to contain the registered actions; engine manifest carries the optional sdk;version="[1.3,2)" import
  • Cypress e2e (needs the docker environment with the SDK-enabled engine)
  • Manual verification on a local Jahia (emails via Mailpit, forward via echo endpoint, both locales)

Documentation

  • docs/how-to-create-form-action.md: new TypeScript section (wrapper usage, raw registry contract, FormActionSupport)
  • docs/cnd-module-ownership.md: action-type ownership rule updated

Dependency / draft status

⚠️ Depends on javascript-modules feature/js-server-extensions-sdk (exports org.jahia.modules.javascript.modules.engine.sdk from javascript-modules-engine:1.3.0-SNAPSHOT). CI cannot compile formidable-engine until that branch is merged and a snapshot is published — keeping this PR draft until then. Once 1.3.0 is released, also consider pinning <jahia-depends>javascript-modules-engine=1.3.0</jahia-depends>.

The submission pipeline now falls back to JavaScript handlers registered
under the 'formidable-form-action' registry type (JSServerExtensionInvoker
SDK, javascript-modules-engine >= 1.3.0) when no Java FormAction matches.
The built-in email notification, email content and forward actions are now
TypeScript implementations in formidable-elements (node types moved along);
save-to-JCR stays in Java. Security-sensitive logic (forward target
resolution, SSRF checks, attachment building) remains in Java behind the
new exported FormActionSupport service. On a pre-SDK engine, formidable
still deploys and Java actions keep working.
@github-actions

Copy link
Copy Markdown
Contributor

🦜 Chachalog

formidable minor
  • Added support for writing custom form actions in TypeScript, alongside Java. The built-in
    email and data-forwarding actions are now TypeScript implementations; forms and existing
    action configurations keep working unchanged.

Create a new entry online or run npx chachalog@0.5.2 prompt to create a new entry locally.

@github-actions

Copy link
Copy Markdown
Contributor

📝 Documentation Guidelines

Thank you for contributing to our documentation! To ensure your contributions meet our standards, please review these resources:

This comment is posted automatically when changes are detected in the docs/ folder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant