Update hivegrid-cloud reference to latest main
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e98d38e716
commit
7b21524c86
3781 files changed
+373484
-225607
No files matched your search
+79
-2
@@ -5,6 +5,7 @@ import {
|
||||
getNotificationDeliveryDiagnostics,
|
||||
getNotificationStreamSnapshot,
|
||||
getUserNotificationPreferences,
|
||||
markAllInAppNotificationDeliveriesRead,
|
||||
markInAppNotificationDeliveryRead,
|
||||
markNotificationDeliveryStatus,
|
||||
NOTIFICATION_DELIVERY_LAST_ERROR_MAX_LENGTH,
|
||||
@@ -398,6 +399,46 @@ describe("notification delivery boundary", () => {
|
||||
).rejects.toThrow("Notification delivery read scope did not match exactly one delivery.");
|
||||
});
|
||||
|
||||
it("bulk-clears every unread in-app delivery within the current tenant/user scope", async () => {
|
||||
const client = createNotificationsClient();
|
||||
vi.mocked(client.notificationDelivery.updateMany).mockResolvedValueOnce({ count: 3 });
|
||||
const readAt = new Date("2026-05-08T13:00:00.000Z");
|
||||
|
||||
const cleared = await markAllInAppNotificationDeliveriesRead(
|
||||
{
|
||||
tenantId: " tenant_1 ",
|
||||
userId: " user_1 ",
|
||||
readAt,
|
||||
},
|
||||
client,
|
||||
);
|
||||
|
||||
expect(client.notificationDelivery.updateMany).toHaveBeenCalledWith({
|
||||
where: { tenantId: "tenant_1", userId: "user_1", channel: "IN_APP", status: "SENT" },
|
||||
data: { status: "READ", readAt },
|
||||
});
|
||||
expect(cleared).toBe(3);
|
||||
});
|
||||
|
||||
it("tolerates a bulk clear that matches no unread deliveries", async () => {
|
||||
const client = createNotificationsClient();
|
||||
vi.mocked(client.notificationDelivery.updateMany).mockResolvedValueOnce({ count: 0 });
|
||||
|
||||
await expect(
|
||||
markAllInAppNotificationDeliveriesRead({ tenantId: "tenant_1", userId: "user_1" }, client),
|
||||
).resolves.toBe(0);
|
||||
});
|
||||
|
||||
it("rejects a bulk clear without tenant or user scope before writing", async () => {
|
||||
const client = createNotificationsClient();
|
||||
|
||||
await expect(
|
||||
markAllInAppNotificationDeliveriesRead({ tenantId: " ", userId: "user_1" }, client),
|
||||
).rejects.toThrow("Notification delivery bulk read scope is required.");
|
||||
|
||||
expect(client.notificationDelivery.updateMany).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("queries newest-first diagnostics with indexed tenant/user/status/channel/category filters", async () => {
|
||||
const client = createNotificationsClient();
|
||||
|
||||
@@ -566,6 +607,8 @@ describe("notification stream snapshot boundary", () => {
|
||||
updatedAt: "2026-05-08T12:05:00.000Z",
|
||||
sentAt: "2026-05-08T12:01:00.000Z",
|
||||
readAt: "2026-05-08T12:06:00.000Z",
|
||||
deeplink: null,
|
||||
lastError: null,
|
||||
},
|
||||
{
|
||||
id: "delivery_1",
|
||||
@@ -581,6 +624,8 @@ describe("notification stream snapshot boundary", () => {
|
||||
updatedAt: "2026-05-08T11:05:00.000Z",
|
||||
sentAt: null,
|
||||
readAt: null,
|
||||
deeplink: null,
|
||||
lastError: null,
|
||||
},
|
||||
],
|
||||
});
|
||||
@@ -733,17 +778,21 @@ describe("notification stream snapshot boundary", () => {
|
||||
sentAt: null,
|
||||
readAt: null,
|
||||
providerMessageId: "provider-secret-id",
|
||||
payloadMetadata: { token: "secret-token", body: "raw-body" },
|
||||
payloadMetadata: { token: "secret-token", body: "raw-body", deeplink: "/acme/announcements/a1" },
|
||||
authorization: "Bearer secret-token",
|
||||
body: "raw-body",
|
||||
headers: { cookie: "secret" },
|
||||
unknownField: "do-not-serialize",
|
||||
lastError: "token=secret-token failed",
|
||||
},
|
||||
]);
|
||||
|
||||
const snapshot = await getNotificationStreamSnapshot({ tenantId: "tenant_1", userId: "user_1" }, client);
|
||||
const serialized = JSON.stringify(snapshot);
|
||||
|
||||
// AK-P3 DoD 4: only the validated app-relative deeplink scalar and the
|
||||
// redacted error ride along — payloadMetadata itself never enters the
|
||||
// stream, and secrets must never appear serialized.
|
||||
expect(snapshot.items[0]).toEqual({
|
||||
id: "delivery_1",
|
||||
cursor: "2026-05-08T12:01:00.000Z:delivery_1",
|
||||
@@ -758,6 +807,8 @@ describe("notification stream snapshot boundary", () => {
|
||||
updatedAt: "2026-05-08T12:01:00.000Z",
|
||||
sentAt: null,
|
||||
readAt: null,
|
||||
deeplink: "/acme/announcements/a1",
|
||||
lastError: "token=[redacted] failed",
|
||||
});
|
||||
expect(serialized).not.toContain("provider-secret-id");
|
||||
expect(serialized).not.toContain("secret-token");
|
||||
@@ -765,6 +816,32 @@ describe("notification stream snapshot boundary", () => {
|
||||
expect(serialized).not.toContain("unknownField");
|
||||
expect(serialized).not.toContain("payloadMetadata");
|
||||
});
|
||||
|
||||
it("drops unsafe deeplink candidates from the stream", async () => {
|
||||
const client = createNotificationsClient();
|
||||
vi.mocked(client.notificationDelivery.findMany).mockResolvedValue([
|
||||
{
|
||||
id: "delivery_evil",
|
||||
tenantId: "tenant_1",
|
||||
userId: "user_1",
|
||||
channel: "IN_APP",
|
||||
category: "default",
|
||||
messageKey: "announcement.created",
|
||||
status: "SENT",
|
||||
attemptsMade: 1,
|
||||
createdAt: new Date("2026-05-08T12:00:00.000Z"),
|
||||
updatedAt: new Date("2026-05-08T12:01:00.000Z"),
|
||||
sentAt: null,
|
||||
readAt: null,
|
||||
payloadMetadata: { deeplink: "https://evil.example/phish" },
|
||||
},
|
||||
]);
|
||||
|
||||
const snapshot = await getNotificationStreamSnapshot({ tenantId: "tenant_1", userId: "user_1" }, client);
|
||||
|
||||
expect(snapshot.items[0]?.deeplink).toBeNull();
|
||||
expect(JSON.stringify(snapshot)).not.toContain("evil.example");
|
||||
});
|
||||
});
|
||||
|
||||
describe("notification package exports", () => {
|
||||
@@ -785,7 +862,7 @@ describe("notification package exports", () => {
|
||||
});
|
||||
|
||||
it("exposes the notification boundary subpath export", async () => {
|
||||
const notificationBoundary = await import("@toolctrl/db/notifications.server");
|
||||
const notificationBoundary = await import("@hivegrid/db/notifications.server");
|
||||
|
||||
expect(notificationBoundary).toEqual(
|
||||
expect.objectContaining({
|
||||
|
||||
Reference in new issue
Block a user