Implement share viewer (task 31)
- Makes actorId nullable in activity_log (migration 0010) with onDelete: set null so audit history survives user deletion; adds logShareActivity for anonymous mutations - Adds resolveShareToken return of householdId for downstream validation - Adds renderSharedView to EntityTypeRegistration; each module implements loadForShare (no-session bare queries) and renderSharedView - Calendar: CalendarSharedView (upcoming 90-day events) and EventSharedView (title/time/location/notes) - Lists: ListSharedView (client component with optimistic toggles via toggleShareListItem server action in lists/server/share-actions.ts) - Notes: NoteSharedView (title + body + updated date) - /app/s/[token]/page.tsx: resolves token, dispatches to loadForShare + renderSharedView, friendly error for invalid/expired tokens, noindex - Middleware /s/* exemption confirmed present (no change needed) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
d5deee9a46
commit
39aa5704f9
@@ -18,3 +18,20 @@ export async function logActivity(input: {
|
||||
payload: input.payload ?? null,
|
||||
});
|
||||
}
|
||||
|
||||
export async function logShareActivity(input: {
|
||||
householdId: string;
|
||||
entityType: string;
|
||||
entityId: string;
|
||||
action: string;
|
||||
payload?: Record<string, unknown>;
|
||||
}): Promise<void> {
|
||||
await db.insert(activityLog).values({
|
||||
householdId: input.householdId,
|
||||
entityType: input.entityType,
|
||||
entityId: input.entityId,
|
||||
actorId: null,
|
||||
action: input.action,
|
||||
payload: input.payload ?? null,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -12,6 +12,6 @@ export type {
|
||||
} from "./module";
|
||||
export { registerModule, getRegistry, getEntityType, getWidget, getQuickAdds } from "./registry";
|
||||
export type { QuickAddItem, SerializedQuickAddItem } from "./registry";
|
||||
export { logActivity } from "./activity";
|
||||
export { logActivity, logShareActivity } from "./activity";
|
||||
export { createShareLink, resolveShareToken, revokeShareLink } from "./share";
|
||||
export type { ShareLinkCapabilities, CreateShareLinkResult } from "./share";
|
||||
|
||||
@@ -6,7 +6,7 @@ export type ActivityLogEntry = {
|
||||
householdId: string;
|
||||
entityType: string;
|
||||
entityId: string;
|
||||
actorId: string;
|
||||
actorId: string | null;
|
||||
action: string;
|
||||
payload: Record<string, unknown> | null;
|
||||
createdAt: Date;
|
||||
@@ -69,6 +69,11 @@ export type EntityTypeRegistration = {
|
||||
search?: SearchAdapter;
|
||||
resolveUrl: (id: string) => string;
|
||||
loadForShare?: (id: string) => Promise<unknown>;
|
||||
renderSharedView?: (props: {
|
||||
data: unknown;
|
||||
capabilities: { read: boolean; write: boolean };
|
||||
token: string;
|
||||
}) => ReactNode;
|
||||
renderActivity?: (entry: ActivityLogEntry) => string;
|
||||
};
|
||||
|
||||
|
||||
@@ -97,8 +97,7 @@ export const activityLog = pgTable(
|
||||
entityType: text("entity_type").notNull(),
|
||||
entityId: uuid("entity_id").notNull(),
|
||||
actorId: uuid("actor_id")
|
||||
.notNull()
|
||||
.references(() => users.id, { onDelete: "cascade" }),
|
||||
.references(() => users.id, { onDelete: "set null" }),
|
||||
action: text("action").notNull(),
|
||||
payload: jsonb("payload").$type<Record<string, unknown> | null>(),
|
||||
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
||||
|
||||
@@ -61,7 +61,12 @@ export async function createShareLink(
|
||||
|
||||
export async function resolveShareToken(
|
||||
rawToken: string,
|
||||
): Promise<{ entityType: string; entityId: string; capabilities: ShareLinkCapabilities } | null> {
|
||||
): Promise<{
|
||||
entityType: string;
|
||||
entityId: string;
|
||||
capabilities: ShareLinkCapabilities;
|
||||
householdId: string;
|
||||
} | null> {
|
||||
const tokenHash = hashToken(rawToken);
|
||||
|
||||
const [link] = await db
|
||||
@@ -78,6 +83,7 @@ export async function resolveShareToken(
|
||||
entityType: link.entityType,
|
||||
entityId: link.entityId,
|
||||
capabilities: link.capabilities,
|
||||
householdId: link.householdId,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user