open-agreements
Version:
Open-source legal template filling CLI and library
51 lines • 2.8 kB
TypeScript
export interface TemplateValidationResult {
templateId: string;
valid: boolean;
errors: string[];
warnings: string[];
}
/**
* Extract text content from a DOCX file by unzipping and reading word/document.xml.
* Concatenates <w:t> text within each <w:p> paragraph, then joins paragraphs with
* newlines to prevent false {tag} matches across element boundaries.
* Exported for consumers that need the same fill-token sniff this validator
* runs (e.g. the smoke test's manual-fill detection).
*/
export declare function extractDocxText(docxPath: string): string;
/**
* Enforce the `statutory_compliance_representation` contract against the rendered
* template text. This is the load-bearing guard that the decided `confirm=`
* behavior actually shipped — three checks per field:
*
* 1. The clause renders the highlighted `[CONFIRM before signing: …; see <url>]`
* bracket gated on `{IF !<field>}`. Presence of a bare `{IF !field}` is NOT
* sufficient (the legacy `when=field omitted="…"` mechanism also emits one),
* so the negated conditional MUST be immediately followed by the literal
* bracket.
* 2. The URL and note inside the bracket EQUAL the field's metadata
* `authority_url` / `confirm_note`. These now have a single authoring source
* (metadata.yaml — the directive no longer restates them), so this is no
* longer an author-drift check between two hand-edited files. It is an
* integrity check between metadata.yaml and the COMMITTED rendered artifact:
* `validateTemplate` scans the committed `template.docx`, so a stale DOCX (or
* `.template.generated.json`) — e.g. a metadata edit shipped without
* regenerating — is caught here, as are hand-authored JSON templates that
* carry `confirm`/`authority_url`/`confirm_note` directly. Equality, not
* substring: a value with an extra suffix must fail.
* 3. The clause body always renders — i.e. the affirmative `{IF <field>}` form
* is absent. A `confirm=` clause only ever emits `{IF !<field>}`; a legacy
* `when=<field>` clause wraps its body in `{IF <field>}`. Asserting the
* affirmative form is absent proves the body is unconditional and closes the
* spoof where an `omitted="[CONFIRM …]"` string mimics the bracket.
*/
export declare function checkStatutoryComplianceReps(searchableText: string, fields: {
name: string;
statutory_compliance_representation?: boolean;
authority_url?: string;
confirm_note?: string;
}[], errors: string[]): void;
/**
* Validate that a template's metadata fields match the placeholders in its DOCX file.
*/
export declare function validateTemplate(templateDir: string, templateId: string): TemplateValidationResult;
//# sourceMappingURL=template.d.ts.map