feat(08-01): extend SignatureFieldData with type discriminant and helper exports
- Add SignatureFieldType union type with 6 literals (client-signature, initials, text, checkbox, date, agent-signature) - Add optional type field to SignatureFieldData interface (backward-compat; v1.0 docs have no type) - Export getFieldType() helper that coalesces field.type ?? 'client-signature' - Export isClientVisibleField() predicate that returns false for agent-signature only
This commit is contained in:
@@ -1,6 +1,14 @@
|
||||
import { jsonb, pgEnum, pgTable, text, timestamp } from "drizzle-orm/pg-core";
|
||||
import { relations } from "drizzle-orm";
|
||||
|
||||
export type SignatureFieldType =
|
||||
| 'client-signature'
|
||||
| 'initials'
|
||||
| 'text'
|
||||
| 'checkbox'
|
||||
| 'date'
|
||||
| 'agent-signature';
|
||||
|
||||
export interface SignatureFieldData {
|
||||
id: string;
|
||||
page: number; // 1-indexed
|
||||
@@ -8,6 +16,25 @@ export interface SignatureFieldData {
|
||||
y: number; // PDF user space, bottom-left origin, points
|
||||
width: number; // PDF points (default: 144 — 2 inches)
|
||||
height: number; // PDF points (default: 36 — 0.5 inches)
|
||||
type?: SignatureFieldType; // Optional — v1.0 documents have no type; fallback = 'client-signature'
|
||||
}
|
||||
|
||||
/**
|
||||
* Safe field type reader — always returns a SignatureFieldType, never undefined.
|
||||
* v1.0 documents have no `type` on their JSONB fields; this coalesces to 'client-signature'.
|
||||
* ALWAYS use this instead of reading field.type directly.
|
||||
*/
|
||||
export function getFieldType(field: SignatureFieldData): SignatureFieldType {
|
||||
return field.type ?? 'client-signature';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true for field types that should be visible in the client signing session.
|
||||
* agent-signature fields are embedded during document preparation and must never
|
||||
* surface to the client as required unsigned fields.
|
||||
*/
|
||||
export function isClientVisibleField(field: SignatureFieldData): boolean {
|
||||
return getFieldType(field) !== 'agent-signature';
|
||||
}
|
||||
|
||||
export const users = pgTable("users", {
|
||||
|
||||
Reference in New Issue
Block a user