first commit

This commit is contained in:
2026-07-17 21:48:37 +05:30
commit f85599dac5
124 changed files with 10775 additions and 0 deletions
+72
View File
@@ -0,0 +1,72 @@
import type { InboxItem, InboxKind, InboxState, Message, Ticket, TicketPriority, TicketState } from "@lynkd/messaging-inbox-sdk";
/**
* Map IIOS API shapes → this app's SDK types. Written defensively because the
* exact field names live in the IIOS codebase; adjust as you wire real responses.
* (Keep the UI contract = SDK types; do all translation here in the BFF.)
*/
const ts = (v: any): number => {
if (typeof v === "number") return v;
if (typeof v === "string") { const t = Date.parse(v); if (!Number.isNaN(t)) return t; }
return Date.now();
};
export function toMessage(m: any, channelId: string): Message {
const text =
m.content ??
m.body ??
(Array.isArray(m.parts) ? m.parts.find((p: any) => (p.kind ?? p.partType) === "TEXT")?.bodyText : undefined) ??
"";
return {
id: String(m.id ?? m.messageId ?? m.interactionId),
channelId,
authorId: String(m.senderActorId ?? m.actorId ?? m.authorId ?? m.source?.externalId ?? "unknown"),
ts: ts(m.sentAt ?? m.occurredAt ?? m.createdAt ?? m.ts),
body: String(text),
parentId: m.parentInteractionId ?? m.parentId ?? null,
reactions: [],
deliveryState: "sent",
};
}
const inboxKind = (k: any): InboxKind => {
const up = String(k ?? "").toUpperCase();
const known: InboxKind[] = ["NEEDS_REPLY", "MENTION", "REACTION", "THREAD_REPLY", "SAVED", "APP", "SUPPORT_UPDATE", "MEETING_FOLLOWUP"];
return (known.includes(up as InboxKind) ? up : "NEEDS_REPLY") as InboxKind;
};
export function toInboxItem(i: any): InboxItem {
return {
id: String(i.id),
kind: inboxKind(i.kind),
state: (String(i.state ?? "OPEN").toUpperCase() as InboxState),
title: String(i.title ?? i.subject ?? "Inbox item"),
preview: String(i.preview ?? i.snippet ?? ""),
channelId: i.conversationId ?? i.threadId ?? undefined,
messageId: i.messageId ?? undefined,
actorId: i.actorId ?? i.createdByActorId ?? undefined,
ts: ts(i.createdAt ?? i.ts),
dueAt: i.dueAt ? ts(i.dueAt) : undefined,
priority: i.priority ? (String(i.priority).toLowerCase() as InboxItem["priority"]) : "normal",
};
}
export function toTicket(t: any): Ticket {
return {
id: String(t.id),
ref: String(t.ref ?? t.id),
subject: String(t.subject ?? ""),
requesterId: String(t.requesterActorId ?? t.requesterId ?? "unknown"),
assigneeId: t.assigneeActorId ?? t.assigneeId ?? undefined,
state: (String(t.state ?? "NEW").toUpperCase() as TicketState),
priority: (String(t.priority ?? "NORMAL").toUpperCase() as TicketPriority),
channelId: t.threadId ?? t.conversationId ?? undefined,
category: t.klass ?? t.category ?? undefined,
createdTs: ts(t.createdAt),
updatedTs: ts(t.updatedAt ?? t.createdAt),
slaBreached: !!t.slaBreached,
tags: t.tags ?? undefined,
messages: Array.isArray(t.messages) ? t.messages.map((m: any) => toMessage(m, `t_${t.id}`)) : [],
};
}