Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
+28
-9
@@ -8,7 +8,9 @@
|
||||
// ack'd (204/200) so Pub/Sub does not retry-storm us — nothing is persisted.
|
||||
|
||||
import { type ActionFunctionArgs } from "react-router";
|
||||
import { findMailboxByEmailAddress, recordEmailWebhookEvent } from "~/modules/emailInbox/db/emailInbox.db.server";
|
||||
import { resolveGmailMailboxRlsIdentities } from "@hivegrid/db/rls-resolvers.server";
|
||||
import { runWithRlsContext } from "@hivegrid/db/rls-context.server";
|
||||
import { getGmailWebhookMailbox, recordEmailWebhookEvent } from "~/modules/emailInbox/db/emailInbox.db.server";
|
||||
|
||||
const OK = new Response(null, { status: 200 });
|
||||
|
||||
@@ -50,16 +52,33 @@ export const action = async ({ request }: ActionFunctionArgs) => {
|
||||
return OK;
|
||||
}
|
||||
|
||||
const mailbox = await findMailboxByEmailAddress("gmail", payload.emailAddress);
|
||||
if (!mailbox) {
|
||||
const emailAddress = payload.emailAddress.trim().toLowerCase();
|
||||
if (!emailAddress || emailAddress.length > 320) {
|
||||
return OK;
|
||||
}
|
||||
await recordEmailWebhookEvent({
|
||||
tenantId: mailbox.tenantId,
|
||||
mailboxId: mailbox.id,
|
||||
provider: "gmail",
|
||||
notificationPayload: { emailAddress: payload.emailAddress, historyId: String(payload.historyId ?? ""), pubsubMessageId: body.message?.messageId ?? null },
|
||||
});
|
||||
let identities: Awaited<ReturnType<typeof resolveGmailMailboxRlsIdentities>>;
|
||||
try {
|
||||
identities = await resolveGmailMailboxRlsIdentities("gmail", emailAddress);
|
||||
} catch {
|
||||
return OK;
|
||||
}
|
||||
for (const identity of identities) {
|
||||
await runWithRlsContext({ tenantId: identity.tenantId, userId: identity.userId }, async () => {
|
||||
const mailbox = await getGmailWebhookMailbox({
|
||||
tenantId: identity.tenantId,
|
||||
ownerUserId: identity.userId,
|
||||
mailboxId: identity.resourceId,
|
||||
emailAddress,
|
||||
});
|
||||
if (!mailbox) return;
|
||||
await recordEmailWebhookEvent({
|
||||
tenantId: mailbox.tenantId,
|
||||
mailboxId: mailbox.id,
|
||||
provider: "gmail",
|
||||
notificationPayload: { emailAddress, historyId: String(payload.historyId ?? ""), pubsubMessageId: body.message?.messageId ?? null },
|
||||
});
|
||||
});
|
||||
}
|
||||
return OK;
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user