/** * Authoritative Ticket Sync Engine * * Governance Rules: * 1. Jira is the source of truth for ticket existence * 2. Markdown is never allowed to "invent" a Jira issue key * 3. If an .md exists but the Jira issue does not exist (404), create a brand-new Jira issue * 4. Before any MD is created, the Jira issue must already exist * 5. MD → Jira validation: treat MD keys as hints only, validate existence */ import type { JiraConfig, JiraIssue } from "@/types"; /** * Sync direction */ export type SyncDirection = "jira-to-md" | "md-to-jira" | "bidirectional"; /** * Local ticket from markdown file */ export interface LocalTicket { path: string; title: string; description: string; markdownContent: string; projectKey: string; maybeIssueKey?: string; canonicalId?: string; frontmatter?: Record; lastModified?: Date; } /** * Sync result for a single ticket */ export interface TicketSyncResult { ticketKey: string; action: "created" | "linked" | "updated" | "skipped" | "failed"; jiraCreated: boolean; mdCreated: boolean; mdUpdated: boolean; error?: string; oldKey?: string; } /** * Overall sync operation result */ export interface AuthoritativeSyncResult { success: boolean; direction: SyncDirection; scanned: number; created: number; linked: number; updated: number; skipped: number; failed: number; events: SyncEvent[]; results: TicketSyncResult[]; } /** * Audit event for sync operations */ export interface SyncEvent { type: "MD_KEY_INVALID_CREATED_NEW_JIRA" | "ATLASSIAN_CREATED" | "MD_CREATED" | "MD_UPDATED" | "SYNC_ERROR"; timestamp: string; ticketKey?: string; oldKey?: string; filePath?: string; message: string; details?: Record; } /** * Options for authoritative sync */ export interface AuthoritativeSyncOptions { direction?: SyncDirection; projectKey?: string; workspaceId?: string; baseDir?: string; dryRun?: boolean; epicKey?: string; issueType?: string; labels?: string[]; /** Jira client to use */ client?: import("@/server/jira/jiraClient").JiraClient; } /** * Ensure Jira issue exists (create if needed) * * This is the canonical function for ensuring a Jira issue exists before * creating any markdown file. All code paths that create MD files should * call this first. */ export declare function ensureJiraIssueExists(localTicket: LocalTicket, config: JiraConfig, options: AuthoritativeSyncOptions): Promise<{ issueKey: string; created: boolean; issue: JiraIssue; }>; /** * Write markdown ticket file (only after Jira issue exists) * * This function enforces the governance rule: MD files are only created * AFTER the Jira issue exists. It will throw an error if issue.key is missing. */ export declare function writeMarkdownTicket(issue: JiraIssue, localTicket: LocalTicket, baseDir: string, epicKey?: string): Promise<{ created: boolean; updated: boolean; path: string; }>; /** * Canonical sync function - single source of truth */ export declare function syncTickets(config: JiraConfig, options?: AuthoritativeSyncOptions): Promise; //# sourceMappingURL=authoritative-sync.d.ts.map