Refresh HiveGrid Cloud reference snapshot

This commit is contained in:
david committed 2026-08-03 15:31:14 +02:00
1 parent 5e99e14772
commit 7f88026f79
5955 files changed
+1177325 -188362

No files matched your search

@@ -46,15 +46,25 @@ export async function getConnectionForTenant(tenantId: string, connectionId: str
}) as unknown as Promise<CalendarConnectionListRow | null>;
}
/**
* Resolve the connection a Google push channel belongs to. The webhook entrypoint
* has NO tenant context (Google 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.
*/
export async function findConnectionByWebhookSubscription(subscriptionId: string): Promise<{ id: string; tenantId: string; userId: string } | null> {
/** Exact full-row re-read after the narrow bootstrap resolver selected context. */
export async function getGoogleWebhookConnection(input: {
tenantId: string;
userId: string;
connectionId: string;
channelId: string;
channelToken: string;
}): Promise<{ id: string; tenantId: string; userId: string } | null> {
return db.calendarConnection.findFirst({
where: { webhookSubscriptionId: subscriptionId, archivedAt: null },
where: {
id: input.connectionId,
tenantId: input.tenantId,
userId: input.userId,
provider: "google",
status: "active",
archivedAt: null,
webhookSubscriptionId: input.channelId,
AND: { id: input.channelToken },
},
select: { id: true, tenantId: true, userId: true },
});
}
@@ -10,10 +10,9 @@ import { resolveRepoPath } from "~/utils/testing/repoPaths";
const appRoot = resolveRepoPath("apps/web/app");
const mutationRoutes = [
"routes/app.$tenant/settings.integrations.calendar._index.tsx",
"routes/app.$tenant/settings.integrations.calendar.$id.tsx",
];
const CALENDAR_DETAIL_ROUTE = "routes/app.$tenant/settings/integrations/calendar.$id.tsx";
const mutationRoutes = ["routes/app.$tenant/settings/integrations/calendar._index.tsx", CALENDAR_DETAIL_ROUTE];
describe("calendar route authorization boundary", () => {
test("guards permission + CSRF before parsing the form body", () => {
@@ -33,7 +32,7 @@ describe("calendar route authorization boundary", () => {
});
test("detail route owner-checks the connection before mutating", () => {
const source = fs.readFileSync(path.join(appRoot, "routes/app.$tenant/settings.integrations.calendar.$id.tsx"), "utf8");
const source = fs.readFileSync(path.join(appRoot, CALENDAR_DETAIL_ROUTE), "utf8");
const ownerAt = source.indexOf("requireConnectionOwner(ctx, connection.userId)");
const formDataAt = source.indexOf("await request.formData()");
expect(ownerAt).toBeGreaterThanOrEqual(0);
@@ -9,11 +9,11 @@
// block the connect.
import { decryptTenantField, encryptTenantField } from "@hivegrid/db/crypto/tenant-envelope.server";
import { getRlsExecutionContext } from "@hivegrid/db/rls-context.server";
import { db } from "~/utils/db.server";
import { googleCalendarAdapter, CalendarNotConfiguredError } from "./adapters/GoogleCalendarAdapter.server";
import type { CalendarCreds } from "./adapters/CalendarAdapter";
import { signCalendarOAuthState, verifyCalendarOAuthState } from "./oauthState.server";
import { GOOGLE_OAUTH_CALLBACK_PATH } from "../routes/calendarRoutePaths";
export class CalendarConnectError extends Error {
readonly code: "not_configured" | "invalid_state" | "exchange_failed";
@@ -45,6 +45,10 @@ export async function completeOAuthCallback(input: { code: string; state: string
throw new CalendarConnectError("invalid_state");
}
const { tenantId, userId, tenantSlug } = verified.payload;
const rlsContext = getRlsExecutionContext();
if (rlsContext?.tenantId !== tenantId || rlsContext.userId !== userId) {
throw new CalendarConnectError("invalid_state");
}
let exchange: Awaited<ReturnType<typeof googleCalendarAdapter.exchangeCode>>;
try {