- Fix integration data cache: check pending promise before TTL to prevent returning undefined on concurrent cold-cache access - Add concurrent-miss test (two parallel callers, one fetch) - SVG sanitizer: extract <svg> from DOMPurify output to strip residual HTML wrapper - Narrow safeRevalidateTag catch: log unexpected errors, silence only known "outside request scope" messages - Run oxfmt across all packages (206 files formatted)
36 lines
1.4 KiB
TypeScript
36 lines
1.4 KiB
TypeScript
import { getIntegrationKindsByCategory } from "@homarr/definitions";
|
|
import { notificationsRequestHandler } from "@homarr/request-handler/notifications";
|
|
|
|
import type { IntegrationAction } from "../../middlewares/integration";
|
|
import { createManyIntegrationMiddleware } from "../../middlewares/integration";
|
|
import { integrationQueryKey, settleIntegrationQueries } from "../../settle-integrations";
|
|
import { createTRPCRouter, publicProcedure } from "../../trpc";
|
|
|
|
const createNotificationsIntegrationMiddleware = (action: IntegrationAction) =>
|
|
createManyIntegrationMiddleware(action, ...getIntegrationKindsByCategory("notifications"));
|
|
|
|
export const notificationsRouter = createTRPCRouter({
|
|
getNotifications: publicProcedure
|
|
.unstable_concat(createNotificationsIntegrationMiddleware("query"))
|
|
.query(async ({ ctx }) => {
|
|
return await settleIntegrationQueries(
|
|
ctx.integrations,
|
|
async (integration) => {
|
|
const innerHandler = notificationsRequestHandler.handler(integration, {});
|
|
const { data, timestamp } = await innerHandler.getDataAsync();
|
|
|
|
return {
|
|
integration: {
|
|
id: integration.id,
|
|
name: integration.name,
|
|
kind: integration.kind,
|
|
updatedAt: timestamp,
|
|
},
|
|
data,
|
|
};
|
|
},
|
|
{ queryKey: integrationQueryKey("notifications", "getNotifications") },
|
|
);
|
|
}),
|
|
});
|