diff --git a/teressa-copeland-homes/src/lib/db/schema.ts b/teressa-copeland-homes/src/lib/db/schema.ts index 9a53c16..a993125 100644 --- a/teressa-copeland-homes/src/lib/db/schema.ts +++ b/teressa-copeland-homes/src/lib/db/schema.ts @@ -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", {