Reorganize repo structure and standards references

This commit is contained in:
david committed 2026-06-29 05:03:42 +02:00
1 parent 3cb93a81be
commit be2054274d
5885 files changed
+2588 -195

No files matched your search

@@ -0,0 +1,45 @@
import { describe, expect, it } from "vitest";
import fs from "node:fs";
import path from "node:path";
import { sanitizeNotificationPayloadForDisplay } from "./NotificationMessagesTable";
describe("NotificationMessagesTable", () => {
it("redacts sensitive notification payload fields before display", () => {
const payload = JSON.stringify({
token: "secret-token",
authorization: "Bearer abc123",
nested: { email: "user@example.com", message: "ok" },
});
const redacted = sanitizeNotificationPayloadForDisplay(payload);
expect(redacted).not.toContain("secret-token");
expect(redacted).not.toContain("Bearer abc123");
expect(redacted).toContain("[REDACTED]");
expect(redacted).toContain("user@example.com");
});
it("stringifies object payloads before redaction", () => {
const redacted = sanitizeNotificationPayloadForDisplay({
token: "secret-token",
nested: { authorization: "Bearer abc123", message: "ok" },
});
expect(redacted).not.toContain("secret-token");
expect(redacted).not.toContain("Bearer abc123");
expect(redacted).toContain("[REDACTED]");
expect(redacted).toContain("ok");
});
it("keeps notification table dates on locale-aware formatters", () => {
const componentsRoot = path.resolve(process.cwd(), "apps/web/app/modules/notifications/components");
const source = ["NotificationMessagesTable.tsx", "NotificationSubscribersTable.tsx"]
.map((file) => fs.readFileSync(path.join(componentsRoot, file), "utf8"))
.join("\n");
expect(source).toContain("useLocaleFormatters");
expect(source).toContain("formatters.relativeDate");
expect(source).not.toContain("DateUtils");
});
});
@@ -0,0 +1,72 @@
import { useTranslation } from "react-i18next";
import CheckIcon from "~/components/ui/icons/CheckIcon";
import XIcon from "~/components/ui/icons/XIcon";
import ShowPayloadModalButton from "~/components/ui/json/ShowPayloadModalButton";
import TableSimple from "~/components/ui/tables/TableSimple";
import { redactDiagnosticJsonString } from "~/utils/redaction";
import { useLocaleFormatters } from "~/locale/format";
import type { IGetMessagesData } from "../services/.server/NotificationService";
export function sanitizeNotificationPayloadForDisplay(payload: unknown) {
const value = typeof payload === "string" ? payload : JSON.stringify(payload ?? null);
return redactDiagnosticJsonString(value);
}
export default function NotificationMessagesTable({ items, withPagination = true }: { items: IGetMessagesData | null; withPagination?: boolean }) {
const { t } = useTranslation();
const formatters = useLocaleFormatters();
const channelLabel = (channel: string) =>
t(`notifications.center.channels.${channel.toLowerCase().replace(/[-\s]/g, "_")}`, { defaultValue: t("notifications.center.channels.unknown") });
const templateLabel = (templateIdentifier: string) =>
t(`notifications.admin.messageTemplates.${templateIdentifier}`, { defaultValue: t("notifications.admin.messages.unknownTemplate") });
return (
<TableSimple
items={items?.data ?? []}
pagination={
!withPagination
? undefined
: {
page: (items?.page ?? 0) + 1,
pageSize: items?.pageSize ?? 0,
totalItems: items?.totalCount ?? 0,
totalPages: Math.ceil((items?.totalCount ?? 0) / (items?.pageSize ?? 0)),
}
}
headers={[
{
name: "createdAt",
title: t("notifications.admin.messages.createdAt"),
value: (i) => (
<div className="flex flex-col">
<div>{formatters.date(i.createdAt, { dateStyle: "medium" })}</div>
<div className="text-xs">{formatters.relativeDate(i.createdAt)}</div>
</div>
),
},
{ name: "templateIdentifier", title: t("notifications.admin.messages.template"), value: (i) => templateLabel(i.templateIdentifier) },
{ name: "channel", title: t("notifications.admin.messages.channel"), value: (i) => channelLabel(i.channel) },
{
name: "seen",
title: t("notifications.admin.messages.seen"),
value: (i) => <div>{i.seen ? <CheckIcon className="text-theme-500 h-4 w-4" /> : <XIcon className="text-muted-foreground h-4 w-4" />}</div>,
},
{
name: "read",
title: t("notifications.admin.messages.read"),
value: (i) => <div>{i.read ? <CheckIcon className="text-theme-500 h-4 w-4" /> : <XIcon className="text-muted-foreground h-4 w-4" />}</div>,
},
{
name: "payload",
title: t("notifications.admin.messages.payload"),
value: (i) => (
<pre className="max-w-sm truncate">
<ShowPayloadModalButton payload={sanitizeNotificationPayloadForDisplay(i.payload)} />
</pre>
),
},
{ name: "provider", title: t("notifications.admin.messages.provider"), value: () => t("notifications.admin.provider.novu") },
]}
></TableSimple>
);
}
@@ -0,0 +1,56 @@
import { Link } from "react-router";
import { t as i18nT } from "i18next";
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 { adminPath } from "~/utils/app/CanonicalUrlUtils";
export default function NotificationSubscribersTable({ items }: { items: IGetSubscribersData | null }) {
const formatters = useLocaleFormatters();
return (
<TableSimple
items={items?.data ?? []}
pagination={{
page: (items?.page ?? 0) + 1,
pageSize: items?.pageSize ?? 0,
totalItems: items?.totalCount ?? 0,
totalPages: Math.ceil((items?.totalCount ?? 0) / (items?.pageSize ?? 0)),
}}
headers={[
{
name: "subscriber",
title: i18nT("notifications.admin.subscribers.columns.subscriber"),
value: (i) => (
<div>
{!i.email ? (
<div>-</div>
) : (
<Link to={adminPath("notifications/messages?subscriberId=" + i.subscriberId, { mode: "host-aware" })}>
<UserBadge
item={{
id: i.subscriberId,
email: i.email,
firstName: i.firstName,
lastName: i.lastName,
}}
/>
</Link>
)}
</div>
),
},
{ name: "createdAt", title: i18nT("notifications.admin.subscribers.columns.createdAt"), value: (i) => formatters.relativeDate(i.createdAt) },
{ name: "updatedAt", title: i18nT("notifications.admin.subscribers.columns.updatedAt"), value: (i) => formatters.relativeDate(i.updatedAt) },
{
name: "deleted",
title: i18nT("notifications.admin.subscribers.columns.deleted"),
value: (i) => <div>{i.deleted ? <CheckIcon className="text-theme-500 h-4 w-4" /> : <XIcon className="text-muted-foreground h-4 w-4" />}</div>,
},
]}
></TableSimple>
);
}
@@ -0,0 +1,168 @@
import clsx from "clsx";
import { useTranslation } from "react-i18next";
import CheckIcon from "~/components/ui/icons/CheckIcon";
import ExclamationTriangleIcon from "~/components/ui/icons/ExclamationTriangleIcon";
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";
export default function NotificationTemplatesTable({
items,
onDelete,
onSendPreview,
}: {
items: IGetTemplatesData | null;
onDelete: (id: string) => void;
onSendPreview: (item: NotificationChannelDto) => void;
}) {
const { t } = useTranslation();
const channelLabel = (item: NotificationChannelDto) =>
t(`notifications.admin.channelLabels.${item.name}`, {
defaultValue: item.name.replace(/[-_.]+/g, " ").replace(/\b\w/g, (letter) => letter.toUpperCase()),
});
const channelDescription = (item: NotificationChannelDto) =>
t(item.descriptionKey, {
defaultValue: item.name.replace(/[-_.]+/g, " "),
});
const roleLabel = (role: string) => t(`notifications.admin.roleLabels.${role}`, { defaultValue: role.replace(/([a-z0-9])([A-Z])/g, "$1 $2") });
function getCreated(i: NotificationChannelDto) {
return items?.data?.find((f) => f.name === i.name);
}
function isValid(item: NotificationChannelDto, templates: IGetTemplatesData | null) {
const existing = templates?.data?.find((f) => f.name === item.name);
if (!existing || !existing.steps || existing.steps.length === 0) {
return false;
}
return true;
}
return (
<TableSimple
items={NotificationChannels}
pagination={{
page: (items?.page ?? 0) + 1,
pageSize: items?.pageSize ?? 0,
totalItems: items?.totalCount ?? 0,
totalPages: Math.ceil((items?.totalCount ?? 0) / (items?.pageSize ?? 0)),
}}
headers={[
{
name: "name",
title: t("notifications.admin.templates.name"),
value: (i) => (
<>
{!isValid(i, items) ? (
<div className="flex items-center space-x-1 text-red-600">
<ExclamationTriangleIcon className="h-5 w-5 text-red-600" />
<div>{channelLabel(i)}</div>
</div>
) : (
<div>{channelLabel(i)}</div>
)}
</>
),
},
{
name: "description",
title: t("notifications.admin.templates.description"),
className: "w-full",
value: (i) => (
<div className="text-muted-foreground max-w-xs overflow-x-auto">
<div className={clsx(!isValid(i, items) && "text-red-600")}>{channelDescription(i)}</div>
</div>
),
},
{
name: "roles",
title: t("notifications.admin.templates.roles"),
value: (i) => <div className="text-muted-foreground">{i.roles?.map((role) => roleLabel(role)).join(", ") || t("shared.notSet")}</div>,
},
{
name: "send",
title: t("shared.preview"),
value: (i) => (
<div>
<button
type="button"
className={clsx(
"font-medium",
getCreated(i)?.active ? "border-theme-300 border-b border-dashed hover:border-dotted" : "cursor-not-allowed opacity-90"
)}
onClick={() => onSendPreview(i)}
>
{t("shared.send")}
</button>
</div>
),
},
{
name: "active",
title: t("notifications.admin.templates.active"),
value: (i) => (
<div>{getCreated(i)?.active ? <CheckIcon className="text-theme-500 h-4 w-4" /> : <XIcon className="text-muted-foreground h-4 w-4" />}</div>
),
},
{
name: "hasSteps",
title: t("notifications.admin.templates.hasSteps"),
value: (i) => (
<div>{(getCreated(i)?.steps ?? []).length > 0 ? <CheckIcon className="text-theme-500 h-4 w-4" /> : <XIcon className="h-4 w-4 text-red-600" />}</div>
),
},
// {
// name: "tags",
// title: "Tags",
// value: (i) =>
// getCreated(i)
// ?.tags.map((f) => f)
// .join(", "),
// },
{
name: "_id",
title: t("notifications.admin.templates.provider"),
value: (i) => (
<>
{getCreated(i)?._id ? (
<a
href={`https://web.novu.co/templates/edit/${getCreated(i)?._id}`}
target="_blank"
rel="noreferrer"
className="hover:border-dotter hover:border-theme-300 border-border border-b border-dashed"
>
{t("notifications.admin.templates.openProvider")}
</a>
) : (
<a
href={"https://web.novu.co/templates/create"}
target="_blank"
rel="noreferrer"
className="hover:border-dotter hover:border-theme-300 border-border border-b border-dashed"
>
{t("shared.create")}
</a>
)}
</>
),
},
// {
// name: "delete",
// title: "Delete",
// value: (i) => (
// <div className="flex items-center justify-center">
// {i._id !== undefined && (
// <button
// type="button"
// onClick={() => onDelete(i._id ?? "")}
// className="mr-2 flex h-4 w-4 items-center justify-center text-muted-foreground hover:text-red-600"
// >
// <TrashIcon className="h-4 w-4" />
// </button>
// )}
// </div>
// ),
// },
]}
></TableSimple>
);
}