// Synthetic seeds use the schema-90 address table and the same deterministic // identity as cotton_store::protocol::derived_id::person_handle_id. import { derivedId } from "./link-id.mjs"; export function pushPersonHandle(push, workspaceId, personId, kind, raw, createdAt, updatedAt = createdAt) { const value = raw.trim(); if (!value) return; let normalised; if (kind === "phone") { const digits = value.replace(/[\s\-().]/g, "").replace(/^\+/, ""); normalised = /^\d{8,15}$/.test(digits) ? digits : value.toLowerCase().replace(/\s/g, ""); } else if (kind === "email") { normalised = value.toLowerCase().replace(/\s/g, ""); } else if (kind === "instagram") { normalised = value.replace(/^@/, "").toLowerCase(); } else { throw new Error(`The synthetic address seed has no ${kind} normalizer`); } const id = derivedId("cotton_person_handles", [workspaceId, kind, normalised]); push("cotton_person_handles", id, { id, workspace_id: workspaceId, person_id: personId, kind, value, normalised, source: "manual", verified_at: null, position: 0, created_at: createdAt, updated_at: updatedAt, }); }