/** * THE WIRE CONTRACT of `POST /v1/import/messages` — the shapes of * `crates/cotton-rules/src/import/envelope.rs` as serde serialises them * (camelCase), field by field; its validator runs in the rules module. A * batch that breaks the contract is refused before anything is read, naming * the first problem in the Rust's own words. */import { rule } from"../rules/index.ts";importtype { HandleKind } from"./handles.ts";exporttypeDirection = "in" | "out";exportinterfaceEnvelopeReaction { emoji: string;/** Canonical phone (digits, no `+`) or the literal `"owner"`. */ actor: string; at?: string;}/** One attachment: a key the Mac already PUT, and what it is. */exportinterfaceEnvelopeMedia { key: string; contentType: string; name?: string; sizeBytes?: number; width?: number; height?: number; contact?: unknown; durationMs?: number; playbackKey?: string; playbackContentType?: string;/** A sealed file's key (base64url), carried only inside a sealed row (L8). */ fileKey?: string;/** What it is where the MIME type does not say (`voice`); from the outbox row the Mac sent. */ kind?: string;/** A voice note's peaks, each 0..1. */ waveform?: number[];/** A picture's or a video's small preview (base64 JPEG). */ preview?: string;}exportinterfaceEnvelopeMessage { phone?: string; email?: string; senderLabel?: string; displayName?: string; direction: Direction; body: string; media?: EnvelopeMedia[]; sentAt: string; externalId: string; replyToExternalId?: string; reactions?: EnvelopeReaction[]; meta?: Record<string, unknown>;}exportinterfaceEnvelopeHandle { kind: HandleKind; value: string;}exportinterfaceEnvelopeThreadParticipant { label: string; phone?: string; email?: string; personId?: string; handle?: EnvelopeHandle;}exportinterfaceEnvelopeThread { kind: "group"; title: string; externalKey: string; participants: EnvelopeThreadParticipant[];}exportinterfaceImportBatch { workspaceId: string; channel: string; thread?: EnvelopeThread; dm?: EnvelopeThreadParticipant; messages: EnvelopeMessage[]; newThreadId?: string;}exportconst MAX_BATCH_MESSAGES = 500;/** The problems cotton-rules' `validate_envelope_message` names, in its words. */exportfunction validateEnvelopeMessage(value: unknown, at: string, context: "dm" | "group"): string[] {return rule<string[]>("envelope.message", { value, at, context });}/** The problems cotton-rules' `validate_import_batch` names, in its words. */exportfunction validateImportBatch(value: unknown): string[] {return rule<string[]>("envelope.batch", value);}/** * The first reason a batch cannot be imported: the validator's first problem, * else what serde refuses deserialising it into the Rust's `ImportBatch` * (an attachment field it does not know, a handle that is no handle). Null for * a batch the import engine reads whole. */exportfunction batchProblem(value: unknown): string | null {return rule<string | null>("envelope.check", value);}