import { HttpError } from "../errors";
import { all, run } from "../db";
import { googleChatDigest, googleChatMessage, genericPayload, slackDigest, slackMessage } from "./format";
import { isSuccess, outboundFetch } from "./outbound";
import type { OutboundResult } from "./outbound";
import { signPayload } from "./signatures";
import { parseConfig, openCredentials } from "./store";
import type { IntegrationRow } from "./store";
import type { EventSummary } from "./summarize";
import { handleLinearEvent } from "./linear";
import { handleGithubEvent } from "./github-sync";
export type DeliverInput = {
deliveryId: string;
repoId: string | null;
event: string;
payload: Record<string, unknown>;
summary: EventSummary | null;
digest?: EventSummary[];
digestLabel?: string;
};
const HTTP_SERVER_ERROR = 500;
const SLACK_RETRYABLE = new Set([
"ratelimited",
"internal_error",
"fatal_error",
"service_unavailable",
"request_timeout",
]);
const SLACK_POST_MESSAGE = "https://slack.com/api/chat.postMessage";
async function signedPost(
url: string,
body: Record<string, unknown>,
signingSecret: string,
input: DeliverInput,
extra: Record<string, string> = {},
): Promise<OutboundResult> {
const text = JSON.stringify(body);