Skip to content

Commit 4243f12

Browse files
committed
refactor(channels): keep ingress helpers private
1 parent 694c1a4 commit 4243f12

4 files changed

Lines changed: 26 additions & 20 deletions

File tree

‎extensions/mattermost/src/mattermost/monitor-auth.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export function isMattermostSenderAllowed(params: {
9090
return match.allowed;
9191
}
9292

93-
export function mapMattermostChannelTypeToChatType(channelType?: string | null): ChatType {
93+
function mapMattermostChannelTypeToChatType(channelType?: string | null): ChatType {
9494
const normalized = channelType?.trim().toUpperCase();
9595
if (!normalized) {
9696
return "direct";
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
// Mattermost test support covers monitor.channel kind plugin behavior.
22
import { describe, expect, it } from "vitest";
3-
import { mapMattermostChannelTypeToChatType } from "./monitor-auth.js";
3+
import { resolveMattermostTrustedChatKind } from "./monitor-auth.js";
44

5-
describe("mapMattermostChannelTypeToChatType", () => {
5+
describe("resolveMattermostTrustedChatKind", () => {
66
it("maps direct and group dm channel types", () => {
7-
expect(mapMattermostChannelTypeToChatType("D")).toBe("direct");
8-
expect(mapMattermostChannelTypeToChatType("g")).toBe("group");
7+
expect(resolveMattermostTrustedChatKind({ channelType: "D" })).toBe("direct");
8+
expect(resolveMattermostTrustedChatKind({ channelType: "g" })).toBe("group");
99
});
1010

1111
it("maps private channels to group", () => {
12-
expect(mapMattermostChannelTypeToChatType("P")).toBe("group");
13-
expect(mapMattermostChannelTypeToChatType(" p ")).toBe("group");
12+
expect(resolveMattermostTrustedChatKind({ channelType: "P" })).toBe("group");
13+
expect(resolveMattermostTrustedChatKind({ channelType: " p " })).toBe("group");
1414
});
1515

1616
it("keeps public channels and unknown typed values as channel", () => {
17-
expect(mapMattermostChannelTypeToChatType("O")).toBe("channel");
18-
expect(mapMattermostChannelTypeToChatType("x")).toBe("channel");
17+
expect(resolveMattermostTrustedChatKind({ channelType: "O" })).toBe("channel");
18+
expect(resolveMattermostTrustedChatKind({ channelType: "x" })).toBe("channel");
1919
});
2020

2121
it("treats missing channel type as direct", () => {
22-
expect(mapMattermostChannelTypeToChatType(undefined)).toBe("direct");
23-
expect(mapMattermostChannelTypeToChatType(null)).toBe("direct");
24-
expect(mapMattermostChannelTypeToChatType("")).toBe("direct");
22+
expect(resolveMattermostTrustedChatKind({ channelType: undefined })).toBe("direct");
23+
expect(resolveMattermostTrustedChatKind({ channelType: null })).toBe("direct");
24+
expect(resolveMattermostTrustedChatKind({ channelType: "" })).toBe("direct");
2525
});
2626
});

‎extensions/whatsapp/src/inbound/durable-receive.test.ts‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// WhatsApp durable ingress drain adapter: completion, retry, and lane serialization.
2+
import { createHash } from "node:crypto";
23
import fs from "node:fs/promises";
34
import os from "node:os";
45
import path from "node:path";
@@ -9,11 +10,16 @@ import {
910
deserializeWhatsAppDurableInboundMessage,
1011
serializeWhatsAppDurableInboundMessage,
1112
} from "./durable-payload.js";
12-
import {
13-
createWhatsAppDurableInboundMessageId,
14-
createWhatsAppIngressMonitor,
15-
type WhatsAppDurableInboundPayload,
16-
} from "./durable-receive.js";
13+
import { createWhatsAppIngressMonitor } from "./durable-receive.js";
14+
15+
type WhatsAppDurableInboundPayload = {
16+
message: ReturnType<typeof serializeWhatsAppDurableInboundMessage>;
17+
upsertType?: string;
18+
skipStaleAppend?: boolean;
19+
skipRecentOutboundEcho?: boolean;
20+
receivedAt: number;
21+
receiveOrder?: number;
22+
};
1723

1824
const REMOTE_JID = "[email protected]";
1925

@@ -34,7 +40,7 @@ function message(id: string, remoteJid = REMOTE_JID): WAMessage {
3440
}
3541

3642
function eventId(id: string, remoteJid = REMOTE_JID): string {
37-
return createWhatsAppDurableInboundMessageId({ remoteJid, id });
43+
return createHash("sha256").update(`${remoteJid}\n${id}`).digest("hex");
3844
}
3945

4046
function payload(id: string, remoteJid = REMOTE_JID): WhatsAppDurableInboundPayload {

‎extensions/whatsapp/src/inbound/durable-receive.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export type WhatsAppReadReceiptTarget = {
2828
participant?: string;
2929
};
3030

31-
export type WhatsAppDurableInboundPayload = {
31+
type WhatsAppDurableInboundPayload = {
3232
message: SerializedWhatsAppDurableInboundMessage;
3333
upsertType?: string;
3434
skipStaleAppend?: boolean;
@@ -54,7 +54,7 @@ function hashNamespacePart(value: string): string {
5454
return createHash("sha256").update(value).digest("hex").slice(0, 24);
5555
}
5656

57-
export function createWhatsAppDurableInboundMessageId(params: {
57+
function createWhatsAppDurableInboundMessageId(params: {
5858
remoteJid: string;
5959
id: string;
6060
}): string {

0 commit comments

Comments
 (0)