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
+29
-13
@@ -6,7 +6,9 @@
|
||||
// keeps the request handler trivial and idempotent.
|
||||
|
||||
import { type ActionFunctionArgs } from "react-router";
|
||||
import { findConnectionByWebhookSubscription, recordWebhookEvent } from "~/modules/calendar/db/calendar.db.server";
|
||||
import { resolveCalendarWebhookRlsIdentity } from "@hivegrid/db/rls-resolvers.server";
|
||||
import { runWithRlsContext } from "@hivegrid/db/rls-context.server";
|
||||
import { getGoogleWebhookConnection, recordWebhookEvent } from "~/modules/calendar/db/calendar.db.server";
|
||||
|
||||
const OK = new Response(null, { status: 200 });
|
||||
|
||||
@@ -22,22 +24,36 @@ export const action = async ({ request }: ActionFunctionArgs) => {
|
||||
return OK;
|
||||
}
|
||||
|
||||
const connection = await findConnectionByWebhookSubscription(channelId);
|
||||
// The channel token is the connection id (set at subscribe time). Verify it
|
||||
// matches the resolved connection — a mismatch is a spoofed/stale channel.
|
||||
if (!connection || connection.id !== channelToken) {
|
||||
let identity: Awaited<ReturnType<typeof resolveCalendarWebhookRlsIdentity>>;
|
||||
try {
|
||||
identity = await resolveCalendarWebhookRlsIdentity(channelId, channelToken);
|
||||
} catch {
|
||||
return OK;
|
||||
}
|
||||
if (!identity) {
|
||||
return OK;
|
||||
}
|
||||
|
||||
// `sync` is Google's initial handshake ping (no change) — nothing to enqueue.
|
||||
if (resourceState && resourceState !== "sync") {
|
||||
await recordWebhookEvent({
|
||||
tenantId: connection.tenantId,
|
||||
connectionId: connection.id,
|
||||
notificationPayload: { channelId, resourceState, resourceId: request.headers.get("x-goog-resource-id") },
|
||||
externalResourceState: resourceState,
|
||||
await runWithRlsContext({ tenantId: identity.tenantId, userId: identity.userId }, async () => {
|
||||
const connection = await getGoogleWebhookConnection({
|
||||
tenantId: identity.tenantId,
|
||||
userId: identity.userId,
|
||||
connectionId: identity.resourceId,
|
||||
channelId,
|
||||
channelToken,
|
||||
});
|
||||
}
|
||||
if (!connection) return;
|
||||
|
||||
// `sync` is Google's initial handshake ping (no change) — nothing to enqueue.
|
||||
if (resourceState && resourceState !== "sync") {
|
||||
await recordWebhookEvent({
|
||||
tenantId: connection.tenantId,
|
||||
connectionId: connection.id,
|
||||
notificationPayload: { channelId, resourceState, resourceId: request.headers.get("x-goog-resource-id") },
|
||||
externalResourceState: resourceState,
|
||||
});
|
||||
}
|
||||
});
|
||||
return OK;
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user