Files
zooqueenandHanzo Dev 70be050994 sqlite: drop the two query arguments it rejects
Same failure as skipDuplicates, confirmed the same way against a database
built from this schema: Prisma does not ignore these on sqlite, it rejects
the call.

  mode: "insensitive" — broke document search and listing, dataroom search,
    and the two download-by-email lookups. Plain `contains` goes through LIKE,
    which sqlite already treats case-insensitively for ascii, so dropping the
    argument keeps the behaviour. `equals` does NOT: sqlite compares with `=`
    case-sensitively, so the two lookups that matched a visitor's address that
    way now narrow with `contains` and settle it with an exact comparison —
    verify.ts was already doing that comparison, by-email.ts was not.

    One of these was invisible to tsc: the documents where clause is assembled
    from spreads into a variable, so nothing checked it against Prisma's type
    and only the runtime rejected it.

  array_contains — every webhook delivery was throwing instead of fanning out.
    Three copies of the same query, now one `subscribers()` that matches the
    trigger against the list. `Webhook.triggers` is another postgres String[]
    that became Json, so it is narrowed like the rest.

99 errors -> 11, no file worse than it was.

Co-authored-by: Hanzo Dev <[email protected]>
2026-08-09 11:56:11 -07:00

81 lines
1.9 KiB
TypeScript

import prisma from "@/lib/prisma";
import { log } from "@/lib/utils";
import { sendWebhooks } from "@/lib/webhook/send-webhooks";
import { subscribers } from "@/lib/webhook/subscribers";
export async function sendDocumentCreatedWebhook({
teamId,
data,
}: {
teamId: string;
data: any;
}) {
try {
const { document_id: documentId } = data;
if (!documentId || !teamId) {
throw new Error("Missing required parameters");
}
// check if team is on paid plan
const team = await prisma.team.findUnique({
where: { id: teamId },
select: { plan: true },
});
if (team?.plan === "free" || team?.plan === "pro") {
// team is not on paid plan, so we don't need to send webhooks
return;
}
// Get webhooks for team
const webhooks = await subscribers(teamId, "document.created");
if (!webhooks || (webhooks && webhooks.length === 0)) {
// No webhooks for team, so we don't need to send webhooks
return;
}
// Get document information
const document = await prisma.document.findUnique({
where: { id: documentId, teamId },
});
if (!document) {
throw new Error("Document not found");
}
// Prepare document data for webhook
const documentData = {
id: document.id,
name: document.name,
contentType: document.contentType,
teamId: document.teamId,
createdAt: document.createdAt.toISOString(),
};
// Prepare webhook payload
const webhookData = {
document: documentData,
};
// Send webhooks
if (webhooks.length > 0) {
await sendWebhooks({
webhooks,
trigger: "document.created",
data: webhookData,
});
}
return;
} catch (error) {
log({
message: `Error sending webhooks for document created: ${error}`,
type: "error",
mention: true,
});
return;
}
}