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
+37
-24
@@ -1,9 +1,8 @@
|
||||
// VA-P23 · email-inbox DB access (thin Prisma wrappers). Reads are tenant-scoped
|
||||
// and — for read_own callers — owner-scoped (M09 Block I). Token ciphertext
|
||||
// columns are NEVER selected into these read shapes; only the connect/refresh
|
||||
// services touch them. The two webhook lookups at the bottom are the DOCUMENTED
|
||||
// cross-tenant exceptions (provider pushes carry no tenant context) — mirrors
|
||||
// calendar.db.server.findConnectionByWebhookSubscription.
|
||||
// services touch them. Provider webhooks bootstrap only through narrow database
|
||||
// resolvers; the lookups at the bottom are exact re-reads inside that RLS context.
|
||||
|
||||
import { db } from "~/utils/db.server";
|
||||
|
||||
@@ -330,32 +329,46 @@ export async function getProviderMessageRefs(
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the mailbox a Microsoft Graph notification belongs to. The webhook
|
||||
* entrypoint has NO tenant context (Microsoft calls a fixed URL), so this is a
|
||||
* deliberate cross-tenant lookup by the stored subscription id; the caller then
|
||||
* scopes every follow-up to the returned tenantId and MUST verify clientState.
|
||||
*/
|
||||
export async function findMailboxByWebhookSubscription(
|
||||
subscriptionId: string,
|
||||
): Promise<{ id: string; tenantId: string; ownerUserId: string; webhookClientState: string | null } | null> {
|
||||
/** Exact Gmail full-row re-read after a narrow bootstrap identity is selected. */
|
||||
export async function getGmailWebhookMailbox(input: {
|
||||
tenantId: string;
|
||||
ownerUserId: string;
|
||||
mailboxId: string;
|
||||
emailAddress: string;
|
||||
}): Promise<{ id: string; tenantId: string; ownerUserId: string } | null> {
|
||||
return db.emailIntegrationMailbox.findFirst({
|
||||
where: { webhookSubscriptionId: subscriptionId, archivedAt: null },
|
||||
select: { id: true, tenantId: true, ownerUserId: true, webhookClientState: true },
|
||||
where: {
|
||||
id: input.mailboxId,
|
||||
tenantId: input.tenantId,
|
||||
ownerUserId: input.ownerUserId,
|
||||
provider: "gmail",
|
||||
emailAddress: { equals: input.emailAddress, mode: "insensitive" },
|
||||
status: "active",
|
||||
archivedAt: null,
|
||||
},
|
||||
select: { id: true, tenantId: true, ownerUserId: true },
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the mailbox a Gmail Pub/Sub push belongs to. Gmail pushes carry only
|
||||
* `{emailAddress, historyId}` — a deliberate cross-tenant lookup by address
|
||||
* (mirrors the calendar webhook exception; endpoint auth = shared token).
|
||||
*/
|
||||
export async function findMailboxByEmailAddress(
|
||||
provider: "gmail" | "microsoft",
|
||||
emailAddress: string,
|
||||
): Promise<{ id: string; tenantId: string; ownerUserId: string } | null> {
|
||||
/** Exact Microsoft full-row re-read with both provider-issued secrets. */
|
||||
export async function getMicrosoftWebhookMailbox(input: {
|
||||
tenantId: string;
|
||||
ownerUserId: string;
|
||||
mailboxId: string;
|
||||
subscriptionId: string;
|
||||
clientState: string;
|
||||
}): Promise<{ id: string; tenantId: string; ownerUserId: string } | null> {
|
||||
return db.emailIntegrationMailbox.findFirst({
|
||||
where: { provider, emailAddress: emailAddress.toLowerCase(), archivedAt: null },
|
||||
where: {
|
||||
id: input.mailboxId,
|
||||
tenantId: input.tenantId,
|
||||
ownerUserId: input.ownerUserId,
|
||||
provider: "microsoft",
|
||||
webhookSubscriptionId: input.subscriptionId,
|
||||
webhookClientState: input.clientState,
|
||||
status: "active",
|
||||
archivedAt: null,
|
||||
},
|
||||
select: { id: true, tenantId: true, ownerUserId: true },
|
||||
});
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user