chore(deadcode): remove unused outbound json builder

This commit is contained in:
Vincent Koc
2026-06-20 14:40:55 +08:00
parent bb7150de94
commit da35f8b4d1
2 changed files with 4 additions and 139 deletions

View File

@@ -1,11 +1,6 @@
// Covers direct/gateway outbound summary formatting and JSON delivery payload
// projections.
// Covers direct/gateway outbound summary formatting.
import { describe, expect, it, vi } from "vitest";
import {
buildOutboundDeliveryJson,
formatGatewaySummary,
formatOutboundDeliverySummary,
} from "./format.js";
import { formatGatewaySummary, formatOutboundDeliverySummary } from "./format.js";
const getChannelPluginMock = vi.hoisted(() =>
vi.fn((channel: string) => {
@@ -78,80 +73,6 @@ describe("formatOutboundDeliverySummary", () => {
});
});
describe("buildOutboundDeliveryJson", () => {
it.each([
{
input: {
channel: "alpha" as const,
to: "123",
result: { channel: "alpha" as const, messageId: "m1", chatId: "c1" },
mediaUrl: "https://example.com/a.png",
},
expected: {
channel: "alpha",
via: "direct",
to: "123",
messageId: "m1",
mediaUrl: "https://example.com/a.png",
chatId: "c1",
},
},
{
input: {
channel: "directchat" as const,
to: "+1",
result: { channel: "directchat" as const, messageId: "w1", toJid: "jid" },
},
expected: {
channel: "directchat",
via: "direct",
to: "+1",
messageId: "w1",
mediaUrl: null,
toJid: "jid",
},
},
{
input: {
channel: "pager" as const,
to: "+1",
result: { channel: "pager" as const, messageId: "s1", timestamp: 123 },
},
expected: {
channel: "pager",
via: "direct",
to: "+1",
messageId: "s1",
mediaUrl: null,
timestamp: 123,
},
},
{
input: {
channel: "richchat" as const,
to: "channel:1",
via: "gateway" as const,
result: {
messageId: "g1",
channelId: "1",
meta: { thread: "2" },
},
},
expected: {
channel: "richchat",
via: "gateway",
to: "channel:1",
messageId: "g1",
mediaUrl: null,
channelId: "1",
meta: { thread: "2" },
},
},
])("builds delivery JSON for %j", ({ input, expected }) => {
expect(buildOutboundDeliveryJson(input)).toEqual(expected);
});
});
describe("formatGatewaySummary", () => {
it.each([
{

View File

@@ -1,5 +1,5 @@
// Outbound delivery formatting produces human CLI summaries and JSON payloads
// for direct and gateway send results.
// Outbound delivery formatting produces human CLI summaries for direct and
// gateway send results.
import { getChatChannelMeta } from "../../channels/chat-meta.js";
import { getChannelPlugin } from "../../channels/plugins/index.js";
import type { ChannelId } from "../../channels/plugins/types.public.js";
@@ -24,17 +24,6 @@ export type OutboundDeliveryJson = {
meta?: Record<string, unknown>;
};
type OutboundDeliveryMeta = {
messageId?: string;
chatId?: string;
channelId?: string;
roomId?: string;
conversationId?: string;
timestamp?: number;
toJid?: string;
meta?: Record<string, unknown>;
};
const resolveChannelLabel = (channel: string) => {
const pluginLabel = getChannelPlugin(channel as ChannelId)?.meta.label;
if (pluginLabel) {
@@ -77,51 +66,6 @@ export function formatOutboundDeliverySummary(
return base;
}
/**
* Builds the JSON delivery payload returned by direct or gateway sends.
*/
export function buildOutboundDeliveryJson(params: {
channel: string;
to: string;
result?: OutboundDeliveryMeta | OutboundDeliveryResult;
via?: "direct" | "gateway";
mediaUrl?: string | null;
}): OutboundDeliveryJson {
const { channel, to, result } = params;
const messageId = result?.messageId ?? "unknown";
const payload: OutboundDeliveryJson = {
channel,
via: params.via ?? "direct",
to,
messageId,
mediaUrl: params.mediaUrl ?? null,
};
if (result && "chatId" in result && result.chatId !== undefined) {
payload.chatId = result.chatId;
}
if (result && "channelId" in result && result.channelId !== undefined) {
payload.channelId = result.channelId;
}
if (result && "roomId" in result && result.roomId !== undefined) {
payload.roomId = result.roomId;
}
if (result && "conversationId" in result && result.conversationId !== undefined) {
payload.conversationId = result.conversationId;
}
if (result && "timestamp" in result && result.timestamp !== undefined) {
payload.timestamp = result.timestamp;
}
if (result && "toJid" in result && result.toJid !== undefined) {
payload.toJid = result.toJid;
}
if (result && "meta" in result && result.meta !== undefined) {
payload.meta = result.meta;
}
return payload;
}
/**
* Formats the human-readable gateway delivery summary for CLI output.
*/