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

@@ -6,6 +6,8 @@ import TableSimple from "~/components/ui/tables/TableSimple";
import { redactDiagnosticJsonString } from "~/utils/redaction";
import { useLocaleFormatters } from "~/locale/format";
import type { IGetMessagesData } from "../services/.server/NotificationService";
import Constants from "~/application/Constants";
import { getTotalPages } from "~/utils/helpers/RowPaginationHelper";
export function sanitizeNotificationPayloadForDisplay(payload: unknown) {
const value = typeof payload === "string" ? payload : JSON.stringify(payload ?? null);
@@ -28,9 +30,9 @@ export default function NotificationMessagesTable({ items, withPagination = true
? undefined
: {
page: (items?.page ?? 0) + 1,
pageSize: items?.pageSize ?? 0,
pageSize: items?.pageSize ?? Constants.DEFAULT_PAGE_SIZE,
totalItems: items?.totalCount ?? 0,
totalPages: Math.ceil((items?.totalCount ?? 0) / (items?.pageSize ?? 0)),
totalPages: getTotalPages(items?.totalCount, items?.pageSize),
}
}
headers={[
@@ -1,12 +1,14 @@
import { Link } from "react-router";
import { t as i18nT } from "i18next";
import { requestScopedT as i18nT } from "~/locale/request-scoped-t";
import UserBadge from "~/components/core/users/UserBadge";
import CheckIcon from "~/components/ui/icons/CheckIcon";
import XIcon from "~/components/ui/icons/XIcon";
import TableSimple from "~/components/ui/tables/TableSimple";
import { useLocaleFormatters } from "~/locale/format";
import type { IGetSubscribersData } from "../services/.server/NotificationService";
import Constants from "~/application/Constants";
import { adminPath } from "~/utils/app/CanonicalUrlUtils";
import { getTotalPages } from "~/utils/helpers/RowPaginationHelper";
export default function NotificationSubscribersTable({ items }: { items: IGetSubscribersData | null }) {
const formatters = useLocaleFormatters();
@@ -16,9 +18,9 @@ export default function NotificationSubscribersTable({ items }: { items: IGetSub
items={items?.data ?? []}
pagination={{
page: (items?.page ?? 0) + 1,
pageSize: items?.pageSize ?? 0,
pageSize: items?.pageSize ?? Constants.DEFAULT_PAGE_SIZE,
totalItems: items?.totalCount ?? 0,
totalPages: Math.ceil((items?.totalCount ?? 0) / (items?.pageSize ?? 0)),
totalPages: getTotalPages(items?.totalCount, items?.pageSize),
}}
headers={[
{
@@ -6,10 +6,12 @@ import XIcon from "~/components/ui/icons/XIcon";
import TableSimple from "~/components/ui/tables/TableSimple";
import { NotificationChannelDto, NotificationChannels } from "../services/NotificationChannels";
import type { IGetTemplatesData } from "../services/.server/NotificationService";
import Constants from "~/application/Constants";
import { getTotalPages } from "~/utils/helpers/RowPaginationHelper";
export default function NotificationTemplatesTable({
items,
onDelete,
onDelete: _onDelete,
onSendPreview,
}: {
items: IGetTemplatesData | null;
@@ -42,9 +44,9 @@ export default function NotificationTemplatesTable({
items={NotificationChannels}
pagination={{
page: (items?.page ?? 0) + 1,
pageSize: items?.pageSize ?? 0,
pageSize: items?.pageSize ?? Constants.DEFAULT_PAGE_SIZE,
totalItems: items?.totalCount ?? 0,
totalPages: Math.ceil((items?.totalCount ?? 0) / (items?.pageSize ?? 0)),
totalPages: getTotalPages(items?.totalCount, items?.pageSize),
}}
headers={[
{
@@ -0,0 +1,72 @@
// @vitest-environment node
import { beforeEach, describe, expect, it, vi } from "vitest";
const mocks = vi.hoisted(() => ({
buildNotificationJob: vi.fn((input) => ({ queueName: "notifications", jobName: "send-notification", payload: input })),
enqueueJob: vi.fn(async () => ({ id: "notification-job" })),
createQueue: vi.fn(() => ({ close: vi.fn(async () => undefined) })),
getRolesByName: vi.fn(),
getAdminUsersInRoles: vi.fn(),
getUsersRolesInTenant: vi.fn(),
}));
vi.mock("@hivegrid/queue", () => ({
buildNotificationJob: mocks.buildNotificationJob,
enqueueJob: mocks.enqueueJob,
queueNames: { notifications: "notifications" },
resolveRedisConnectionOptions: vi.fn(() => ({ host: "redis.test", port: 6379 })),
}));
vi.mock("@hivegrid/queue/runtime", () => ({ createQueue: mocks.createQueue }));
vi.mock("@hivegrid/db/notifications.server", () => ({
createNotificationDelivery: vi.fn(),
redactNotificationDiagnosticText: (message: string) => message,
}));
vi.mock("~/utils/db/permissions/roles.db.server", () => ({ getRolesByName: mocks.getRolesByName }));
vi.mock("~/utils/db/permissions/userRoles.db.server", () => ({ getUsersRolesInTenant: mocks.getUsersRolesInTenant }));
vi.mock("~/utils/db/users.db.server", () => ({ getAdminUsersInRoles: mocks.getAdminUsersInRoles }));
import NotificationService from "./NotificationService";
describe("NotificationService source-key enqueue idempotency", () => {
beforeEach(() => {
vi.clearAllMocks();
mocks.getRolesByName.mockResolvedValue([{ id: "role_admin", type: "admin" }]);
mocks.getAdminUsersInRoles.mockResolvedValue([
{
id: "admin_1",
email: "admin@example.test",
firstName: "Admin",
lastName: "User",
phone: null,
defaultTenantId: "tenant_1",
},
]);
mocks.getUsersRolesInTenant.mockResolvedValue([]);
});
it("derives the same PII-safe BullMQ idempotency key for a replayed event notification", async () => {
const input = {
channel: "admin-accounts" as const,
tenantId: "tenant_1",
notification: {
message: "Account created",
data: { sourceKey: "application-event:evt_0123456789abcdef0123456789abcdef01234567" },
},
};
await NotificationService.sendToRoles(input);
await NotificationService.sendToRoles(input);
expect(mocks.enqueueJob).toHaveBeenCalledTimes(2);
const options = mocks.enqueueJob.mock.calls.map(([, , enqueueOptions]) => enqueueOptions);
expect(options[0]).toEqual(
expect.objectContaining({
tenantId: "tenant_1",
idempotencyKey: expect.stringMatching(/^notification-[a-f0-9]{64}$/u),
})
);
expect(options[0]?.idempotencyKey).toBe(options[1]?.idempotencyKey);
expect(options[0]?.idempotencyKey).not.toContain("tenant_1");
expect(options[0]?.idempotencyKey).not.toContain("admin_1");
});
});
@@ -8,6 +8,7 @@ import { NotificationMessageDto } from "../../dtos/NotificationMessageDto";
import { NotificationSubscriberDto } from "../../dtos/NotificationSubscriberDto";
import { NotificationTemplateDto } from "../../dtos/NotificationTemplateDto";
import { NotificationChannel, NotificationChannels } from "../NotificationChannels";
import { createHash } from "node:crypto";
type NotificationQueue = TypedQueue<typeof queueNames.notifications>;
@@ -181,18 +182,43 @@ function getNotificationSourceKey(channel: string, notification: INotification):
return requestId ? `${channel}:request:${requestId}` : undefined;
}
function buildNotificationQueueIdempotencyKey({
tenantId,
userId,
channel,
sourceKey,
}: {
tenantId: string;
userId: string;
channel: string;
sourceKey: string;
}): string {
const digest = createHash("sha256")
.update(tenantId)
.update("\0")
.update(userId)
.update("\0")
.update(channel)
.update("\0")
.update(sourceKey)
.digest("hex");
return `notification-${digest}`;
}
function createSkippedNotificationDelivery({
targetTenantId,
to,
channel,
reason,
lastError,
sourceKey,
}: {
targetTenantId: string;
to: INotificationUser;
channel: string;
reason: string;
lastError: string;
sourceKey?: string;
}) {
return createNotificationDelivery({
tenantId: targetTenantId,
@@ -200,6 +226,7 @@ function createSkippedNotificationDelivery({
channel: "in-app",
category: mapNotificationChannelToCategory(channel),
messageKey: channel,
sourceKey,
status: "SKIPPED",
lastError,
payloadMetadata: {
@@ -256,6 +283,7 @@ async function send({
return;
}
const sourceKey = getNotificationSourceKey(channel, notification);
try {
const queued = await withNotificationQueue(process.env as RedisConnectionEnv, async (queue) => {
const descriptor = buildNotificationJob({
@@ -265,7 +293,7 @@ async function send({
channel: "in-app",
category: mapNotificationChannelToCategory(channel),
messageKey: channel,
sourceKey: getNotificationSourceKey(channel, notification),
sourceKey,
metadata: {
source: "legacy-notification-service",
...(notification.action?.url ? { actionUrl: notification.action.url } : {}),
@@ -279,7 +307,19 @@ async function send({
attachments: notification.attachments,
},
});
return enqueueJob(queue, descriptor, { tenantId: targetTenantId });
return enqueueJob(queue, descriptor, {
tenantId: targetTenantId,
...(sourceKey
? {
idempotencyKey: buildNotificationQueueIdempotencyKey({
tenantId: targetTenantId,
userId: to.id,
channel,
sourceKey,
}),
}
: {}),
});
});
if (!queued && required) {
throw new Error("Notification queue is not configured.");
@@ -291,6 +331,7 @@ async function send({
channel,
reason: "queue-not-configured",
lastError: "Notification queue is not configured.",
sourceKey,
});
}
return queued;
@@ -308,6 +349,7 @@ async function send({
channel,
reason: "queue-enqueue-failed",
lastError: redactedMessage,
sourceKey,
});
}
}
@@ -1,7 +1,7 @@
import { DefaultAdminRoles } from "~/application/dtos/shared/DefaultAdminRoles";
import { DefaultAppRoles } from "~/application/dtos/shared/DefaultAppRoles";
const NotificationChannelTypes = [
export const NotificationChannelTypes = [
"admin-accounts",
"admin-users",
"admin-subscriptions",
@@ -15,7 +15,7 @@ const NotificationChannelTypes = [
"roles",
"my-rows",
] as const;
export type NotificationChannel = typeof NotificationChannelTypes[number];
export type NotificationChannel = (typeof NotificationChannelTypes)[number];
export interface NotificationChannelDto {
name: NotificationChannel;