24 lines
1.3 KiB
TypeScript
24 lines
1.3 KiB
TypeScript
// R-P1b regression fix: since the app-wide RLS cutover
|
|
// (20260713190000_appwide_rls_cutover) NotificationDelivery is FORCE ROW LEVEL
|
|
// SECURITY. The worker's default client is the RLS-scoped proxy from
|
|
// @hivegrid/db, which only binds the tenant GUC when an async RLS context is
|
|
// active. The maintenance sweeps deliberately fire notify() OUTSIDE their
|
|
// withTenantRLS() read transactions (slow I/O), so without a bound context the
|
|
// tenant-scoped insert fails the policy WITH CHECK and delivery silently stops
|
|
// (the handlers only log e.g. "tasks.reminder.notify-failed").
|
|
//
|
|
// This wrapper binds the tenant context for exactly the notify() write —
|
|
// the same pattern apps/worker/src/jobs/portal-lifecycle-bootstrap.ts uses for
|
|
// its sweep. Every worker-side notify() call for a tenant-scoped delivery must
|
|
// go through it (or run inside an equivalent bound context/transaction).
|
|
import { runWithRlsContext } from "@hivegrid/db/rls-context.server";
|
|
import { notify, type NotificationClient, type NotificationInput, type NotificationPreference } from "@hivegrid/foundation";
|
|
|
|
export async function notifyWithTenantRlsContext(
|
|
input: NotificationInput,
|
|
client: NotificationClient,
|
|
preferences: readonly NotificationPreference[] = []
|
|
): Promise<unknown> {
|
|
return runWithRlsContext({ tenantId: input.tenantId }, () => notify(input, client, preferences));
|
|
}
|