Contract Engine
Portable variable engine without tariff_*
Portable core under src/lib/contract-engine/. Host apps (HR, performance, leases) plug domain data in — the core never hard-codes tariff_* or user_rasa_*.
Pieces
| Module | Role |
|---|---|
types.ts | VariableProvider, overlays, signer roles |
placeholders.ts | Repair TinyMCE/RTL broken {{…}}, extract names |
replace-variables.ts | Substitute + RTL isolation for Jalali dates / indicators |
registry.ts | VariableRegistry — definitions + providers |
providers.ts | createPersonVariableProvider, static, computed |
generation-overlays.ts | Modal fields (price, dates, description) |
Resolve flow
- Author HTML template with
{{person_name_family}},{{contract_price}}, … - Generate modal collects overlay keys (
HR_GENERATION_OVERLAYS). VariableRegistry.resolveAll(html, ctx, forcedKeys)merges providers + overlays.replaceVariables(html, map)→ frozen HTML + JSON cache onHrContract.templateVariables/contentHtml.- Unsigned DOCX/PDF downloads regenerate from that frozen
contentHtml(nothing written underhr-contracts/unsigned/). Signed + QR PDFs are persisted only after Emzagar completes a sign session.
Adding a new domain variable
- Add to
src/constants/hr-document-variables.ts. - Map it in
createPersonVariableProvider(or a new provider). - If it must be typed in the generate modal, add to
HR_GENERATION_OVERLAYS.
What was left out of the extract (on purpose)
tariff_*resolvers /UserTariff- Upload-date payroll batching
- Assessment / collector reports
- Full Chromium PDF / DOCX pipelines (wire
docx+ puppeteer like performance-web when needed)